|
- using CnasSynchronousCommon;
- using CnasSynchronusClient;
- using CnasSynchrousModel;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- using System.Xml.Serialization;
-
- namespace CNAS_BalanceClient
- {
- public class BalanceMainOperation
- {
- ILaboratoryTestOpera iopera;
-
- /// <summary>
- /// 根据当前切换的tab页,切换当前数据类型标识
- /// </summary>
- /// <param name="e"></param>
- /// <param name="CurrentDataType"></param>
- public void UpdateCurrentDataType(System.Windows.Forms.TabControlEventArgs e, ref string CurrentDataType)
- {
- //ARB 全水分;Moisture 水分;Ash 灰分;Volatile 挥发分;Crucible 坩埚;Heat 发热量:Sulfur 测硫;Hydrogen 测氢
- switch (e.TabPage.Name)
- {
- case "tabpAllWater":
- CurrentDataType = "ARB";
- break;
- case "tabpWater":
- CurrentDataType = "Moisture";
- break;
- case "tabpAsh":
- CurrentDataType = "Ash";
- break;
- case "tabpVoliate":
- CurrentDataType = "Volatile";
- break;
- case "tabpCrucible":
- CurrentDataType = "Crucible";
- break;
- case "tabpHeat":
- CurrentDataType = "Heat";
- break;
- case "tabpSulfur":
- CurrentDataType = "Sulfur";
- break;
- case "tabpHydrogen":
- CurrentDataType = "Hydrogen";
- break;
- }
- }
-
- /// <summary>
- /// 根据类型绑定datagridview
- /// </summary>
- /// <param name="dgv"></param>
- /// <param name="laboratoryTests"></param>
- /// <param name="currentDataType"></param>
- public void BindData(System.Windows.Forms.DataGridView dgv, List<LaboratoryTest> laboratoryTests, string currentDataType)
- {
- dgv.DataSource = new BindingList<LaboratoryTest>();
-
- var query = laboratoryTests.Where(s => s.DataType == currentDataType && s.OperationType != "delete").ToList<LaboratoryTest>();
- dgv.DataSource = new BindingList<LaboratoryTest>(query);
- }
-
- /// <summary>
- /// 绑定坩埚数据源
- /// </summary>
- /// <param name="dgv"></param>
- /// <param name="laboratoryTests"></param>
- /// <param name="currentDataType"></param>
- public void BindCrucibleData(DataGridView dgv, List<LaboratoryTest> laboratoryTests, string currentDataType)
- {
- dgv.DataSource = new BindingList<LaboratoryTest>();
-
- var query = laboratoryTests.Where(s => s.DataType == currentDataType &&(s.Crucible_Number==null||s.Crucible_Number=="")&& s.OperationType != "delete").ToList<LaboratoryTest>();
- dgv.DataSource = new BindingList<LaboratoryTest>(query);
- }
- /// <summary>
- /// 删除当前选中行
- /// </summary>
- /// <param name="dgv"></param>
- public void DeleteData(System.Windows.Forms.DataGridView dgv, List<LaboratoryTest> laboratoryTests, string currentDataType)
- {
- //当前选中行
- if (dgv.CurrentCell == null) return;
- if (dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value == null) return;
- string strID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString(); //要求每个dgv的第一列必须为ID字段
-
- var queryitem = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
- if (queryitem.Count == 1)
- {
- queryitem[0].OperationType = "delete";
- dgv.Rows.Remove(dgv.CurrentRow);
- }
- }
-
- /// <summary>
- /// 增加新数据(全水分/水分/灰分/挥发分/...)
- /// </summary>
- /// <param name="strCode"></param>
- /// <param name="strType"></param>
- /// <returns></returns>
- public ReturnValue<LaboratoryTest> AddNewData(string strCode, string strType)
- {
- ReturnValue<LaboratoryTest> returnValue = new ReturnValue<LaboratoryTest>();
- if (strCode == "" || strType == "")
- {
- returnValue.StrErrorMsg = string.Format("参数为空,{0}", strCode == "" ? "样品编码" : "化验类型");
- return null;
- }
- //ARB 全水分;Moisture 水分;Ash 灰分;Volatile 挥发分;Crucible 坩埚;Heat 发热量:Sulfur 测硫;Hydrogen 测氢
- switch (strType)
- {
- case "ARB":
- iopera = new QuanShuiFenOpera();
- returnValue = iopera.CreateLaboratoryTestData(strCode);
- break;
- case "Moisture":
- iopera = new ShuiFenOpera();
- returnValue = iopera.CreateLaboratoryTestData(strCode);
- break;
- case "Ash":
- iopera = new HuiFenOpera();
- returnValue = iopera.CreateLaboratoryTestData(strCode);
- break;
- case "Volatile":
- iopera = new HuiFaFenOpera();
- returnValue = iopera.CreateLaboratoryTestData(strCode);
- break;
- case "Crucible|Heat":
- iopera = new CrucibleHeatOpera();
- returnValue = iopera.CreateLaboratoryTestData(strCode);
- break;
- case "Crucible|Sulfur":
- iopera = new CrucibleSulfurOpera();
- returnValue = iopera.CreateLaboratoryTestData(strCode);
- break;
- case "Crucible|Hydrogen":
- iopera = new CrucibleHydrogenOpera();
- returnValue = iopera.CreateLaboratoryTestData(strCode);
- break;
- }
- return returnValue;
- }
- /// <summary>
- /// 获取自动编码
- /// </summary>
- /// <param name="laboratoryTests"></param>
- /// <returns></returns>
- public string GetAutoCode(List<LaboratoryTest> laboratoryTests)
- {
- string strCode= "T";
- string strNewCode = DateTime.Now.ToString("yyyyMMdd") + "01";
- if (laboratoryTests.Count > 0)
- {
- var query = laboratoryTests.OrderByDescending(s => s.Auto_Code).ToList<LaboratoryTest>();
- string strMaxCode = query[0].Auto_Code;
- if (strMaxCode != "")
- {
- long maxIndex = Convert.ToInt64(strMaxCode.Substring(1, strMaxCode.Length - 1));
- if (maxIndex >= Convert.ToInt64(strNewCode))
- strCode += (maxIndex + 1).ToString();
- else
- strCode += strNewCode;
- }
- else
- strCode += strNewCode;
- }
- else
- {
- strCode += strNewCode;
- }
- return strCode;
- }
- /// <summary>
- /// 绘制序号列
- /// </summary>
- /// <param name="dgv"></param>
- /// <param name="e"></param>
- public void DrawFirstColumnIndex(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)
- {
- Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
- e.RowBounds.Location.Y,
- dgv.RowHeadersWidth - 4,
- e.RowBounds.Height);
-
- TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
- dgv.RowHeadersDefaultCellStyle.Font,
- rectangle,
- dgv.RowHeadersDefaultCellStyle.ForeColor,
- TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
- }
-
- /// <summary>
- /// 提交编辑列
- /// </summary>
- /// <param name="dgv"></param>
- /// <param name="laboratoryTests"></param>
- /// <param name="e"></param>
- public void CommitEditColumn(DataGridView dgv, List<LaboratoryTest> laboratoryTests, DataGridViewCellEventArgs e)
- {
- if (dgv.CurrentCell == null) return;
- if (dgv.CurrentCell.Value == null) return;
- if (e.ColumnIndex == 2) //仪器编号
- {
- string strInputValue = dgv.CurrentCell.Value.ToString();
- string strCurrentID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString();
-
- var query = laboratoryTests.Where(s => s.GUID == strCurrentID).ToList<LaboratoryTest>();
- if (query.Count == 1)
- {
- query[0].Instrument_Number = strInputValue;
- if (query[0].OperationType == null || query[0].OperationType == "")
- query[0].OperationType = "update";
- }
- }
- if (e.ColumnIndex == 3) //坩埚编号
- {
- string strInputValue = dgv.CurrentCell.Value.ToString();
- string strCurrentID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString();
-
- var query = laboratoryTests.Where(s => s.GUID == strCurrentID).ToList<LaboratoryTest>();
- if (query.Count == 1)
- {
- query[0].Crucible_Number = strInputValue;
- if (query[0].OperationType == null || query[0].OperationType == "")
- query[0].OperationType = "update";
- }
- }
- if (e.ColumnIndex == 12) //颗粒度
- {
- string strInputValue = dgv.CurrentCell.Value.ToString();
- string strCurrentID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString();
-
- var query = laboratoryTests.Where(s => s.GUID == strCurrentID).ToList<LaboratoryTest>();
- if (query.Count == 1)
- {
- query[0].Granularity = strInputValue;
- if (query[0].OperationType == null || query[0].OperationType == "")
- query[0].OperationType = "update";
- }
- }
- }
- /// <summary>
- /// 把天平端数据更改到显示端和存储端
- /// </summary>
- /// <param name="dgvQuanShuiFen"></param>
- /// <param name="lstWeightColumnIndex"></param>
- /// <param name="balanceWeight"></param>
- /// <param name="laboratoryTests"></param>
- public void UpdateQuanShuiFenBalanceWeight(System.Windows.Forms.DataGridView dgvQuanShuiFen, List<string> lstWeightColumnIndex, double balanceWeight, List<LaboratoryTest> laboratoryTests,string strType)
- {
- lstWeightColumnIndex = new List<string>() { "4", "5", "7", "8", "9" }; //全水分的这些列从天平端获取
- if (lstWeightColumnIndex.Contains(dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()))
- {
- string strCurrentValue = dgvQuanShuiFen.CurrentCell.Value.ToString();
- if (strCurrentValue != ""&&strCurrentValue!="0")
- {
- if (MessageBox.Show("单元格已经存在数据,继续将覆盖这个数据,是否继续?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
- {
- switch (strType)
- {
- case "ARB":
- new QuanShuiFenUIOperation().UpdateQuanShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- break;
- case "Moisture":
- new ShuiFenUIOperation().UpdateShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- break;
- case "Ash":
- new HuiFenUIOperation().UpdateHuifenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- break;
- }
- }
- }
- else
- {
- switch (strType)
- {
- case "ARB":
- new QuanShuiFenUIOperation().UpdateQuanShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- break;
- case "Moisture":
- new ShuiFenUIOperation().UpdateShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- break;
- case "Ash":
- new HuiFenUIOperation().UpdateHuifenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- break;
- }
- }
- }
- }
-
- /// <summary>
- /// 将天平传输的重量插入数据中
- /// </summary>
- /// <param name="dgvQuanShuiFen"></param>
- /// <param name="lstWeightColumnIndex"></param>
- /// <param name="balanceWeight"></param>
- /// <param name="laboratoryTests"></param>
- public void UpdateVolatileBalanceWeight(System.Windows.Forms.DataGridView dgvQuanShuiFen, List<string> lstWeightColumnIndex, double balanceWeight, List<LaboratoryTest> laboratoryTests)
- {
- lstWeightColumnIndex = new List<string>() { "4", "5", "7" }; //全水分的这些列从天平端获取
- if (lstWeightColumnIndex.Contains(dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()))
- {
- string strCurrentValue = dgvQuanShuiFen.CurrentCell.Value.ToString();
- if (strCurrentValue != "" && strCurrentValue != "0")
- {
- if (MessageBox.Show("单元格已经存在数据,继续将覆盖这个数据,是否继续?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
- {
- new HuiFaFenUIOperation().UpdateVolatileData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- }
- }
- else
- {
- new HuiFaFenUIOperation().UpdateVolatileData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
- }
- }
- }
-
- /// <summary>
- /// 检查输入百分比大小是否是100内小数
- /// </summary>
- /// <param name="strInput"></param>
- /// <returns></returns>
- public bool CheckInputPercent(string strInput)
- {
- bool bIfSuccess = true;
- double value = 0;
- if (double.TryParse(strInput, out value))
- {
- if (value < 0 || value > 100)
- {
- MessageBox.Show("输入值范围为0~100", "提示");
- bIfSuccess = false;
- }
- }
- else
- {
- MessageBox.Show("输入值范围为0~100的数字", "提示");
- bIfSuccess = false;
- }
- return bIfSuccess;
- }
-
- /// <summary>
- /// 获取当前选中项的GUID集合
- /// </summary>
- /// <param name="dgv"></param>
- /// <returns></returns>
- public List<string> GetSelectItemID(DataGridView dgv)
- {
- List<string> lstSelectID = new List<string>();
- for (int j = 0; j < dgv.SelectedRows.Count; j++)
- {
- string strID = dgv.SelectedRows[j].Cells[0].Value.ToString();
- lstSelectID.Add(strID);
- }
- return lstSelectID;
- }
-
- /// <summary>
- /// 将天平传输来的重量插入坩埚架数据中
- /// </summary>
- /// <param name="DstCurrentLeftGrids"></param>
- /// <param name="dgvCrucibleShelf"></param>
- /// <param name="defaultdouble"></param>
- /// <param name="currentCrucibleDataType"></param>
- /// <param name="laboratoryTests"></param>
- public void UpdateCrucibleBalanceWeight(Dictionary<string,DataGridView> DstCurrentLeftGrids,DataGridView dgvCrucibleShelf, double defaultdouble,string currentCrucibleDataType,List<LaboratoryTest> laboratoryTests)
- {
- new CrucibleUIOperation().UpdateCrucibleBalanceWeight(DstCurrentLeftGrids, dgvCrucibleShelf, defaultdouble, currentCrucibleDataType, laboratoryTests);
- }
-
- /// <summary>
- /// 新增一组坩埚架数据
- /// </summary>
- /// <param name="DictCrucuibleGrids"></param>
- /// <param name="dgvCrucibleShelf"></param>
- /// <param name="currentCrucibleDataType"></param>
- /// <param name="strTypeTitle"></param>
- /// <param name="laboratoryTests"></param>
- public void AddCrucibleShelfData(Dictionary<string,DataGridView> DictCrucuibleGrids,DataGridView dgvCrucibleShelf, string currentCrucibleDataType,string strTypeTitle,List<LaboratoryTest> laboratoryTests)
- {
- new CrucibleUIOperation().AddCrucibleShelfData(DictCrucuibleGrids, dgvCrucibleShelf, currentCrucibleDataType, strTypeTitle, laboratoryTests);
- }
-
- }
- }
|