CNAS取数仪器端升级
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

394 linhas
17KB

  1. using CnasSynchronousCommon;
  2. using CnasSynchronusClient;
  3. using CnasSynchrousModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Windows.Forms;
  11. using System.Xml.Serialization;
  12. namespace CNAS_BalanceClient
  13. {
  14. public class BalanceMainOperation
  15. {
  16. ILaboratoryTestOpera iopera;
  17. /// <summary>
  18. /// 根据当前切换的tab页,切换当前数据类型标识
  19. /// </summary>
  20. /// <param name="e"></param>
  21. /// <param name="CurrentDataType"></param>
  22. public void UpdateCurrentDataType(System.Windows.Forms.TabControlEventArgs e, ref string CurrentDataType)
  23. {
  24. //ARB 全水分;Moisture 水分;Ash 灰分;Volatile 挥发分;Crucible 坩埚;Heat 发热量:Sulfur 测硫;Hydrogen 测氢
  25. switch (e.TabPage.Name)
  26. {
  27. case "tabpAllWater":
  28. CurrentDataType = "ARB";
  29. break;
  30. case "tabpWater":
  31. CurrentDataType = "Moisture";
  32. break;
  33. case "tabpAsh":
  34. CurrentDataType = "Ash";
  35. break;
  36. case "tabpVoliate":
  37. CurrentDataType = "Volatile";
  38. break;
  39. case "tabpCrucible":
  40. CurrentDataType = "Crucible";
  41. break;
  42. case "tabpHeat":
  43. CurrentDataType = "Heat";
  44. break;
  45. case "tabpSulfur":
  46. CurrentDataType = "Sulfur";
  47. break;
  48. case "tabpHydrogen":
  49. CurrentDataType = "Hydrogen";
  50. break;
  51. }
  52. }
  53. /// <summary>
  54. /// 根据类型绑定datagridview
  55. /// </summary>
  56. /// <param name="dgv"></param>
  57. /// <param name="laboratoryTests"></param>
  58. /// <param name="currentDataType"></param>
  59. public void BindData(System.Windows.Forms.DataGridView dgv, List<LaboratoryTest> laboratoryTests, string currentDataType)
  60. {
  61. dgv.DataSource = new BindingList<LaboratoryTest>();
  62. var query = laboratoryTests.Where(s => s.DataType == currentDataType && s.OperationType != "delete").ToList<LaboratoryTest>();
  63. dgv.DataSource = new BindingList<LaboratoryTest>(query);
  64. }
  65. /// <summary>
  66. /// 绑定坩埚数据源
  67. /// </summary>
  68. /// <param name="dgv"></param>
  69. /// <param name="laboratoryTests"></param>
  70. /// <param name="currentDataType"></param>
  71. public void BindCrucibleData(DataGridView dgv, List<LaboratoryTest> laboratoryTests, string currentDataType)
  72. {
  73. dgv.DataSource = new BindingList<LaboratoryTest>();
  74. var query = laboratoryTests.Where(s => s.DataType == currentDataType &&(s.Crucible_Number==null||s.Crucible_Number=="")&& s.OperationType != "delete").ToList<LaboratoryTest>();
  75. dgv.DataSource = new BindingList<LaboratoryTest>(query);
  76. }
  77. /// <summary>
  78. /// 删除当前选中行
  79. /// </summary>
  80. /// <param name="dgv"></param>
  81. public void DeleteData(System.Windows.Forms.DataGridView dgv, List<LaboratoryTest> laboratoryTests, string currentDataType)
  82. {
  83. //当前选中行
  84. if (dgv.CurrentCell == null) return;
  85. if (dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value == null) return;
  86. string strID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString(); //要求每个dgv的第一列必须为ID字段
  87. var queryitem = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
  88. if (queryitem.Count == 1)
  89. {
  90. queryitem[0].OperationType = "delete";
  91. dgv.Rows.Remove(dgv.CurrentRow);
  92. }
  93. }
  94. /// <summary>
  95. /// 增加新数据(全水分/水分/灰分/挥发分/...)
  96. /// </summary>
  97. /// <param name="strCode"></param>
  98. /// <param name="strType"></param>
  99. /// <returns></returns>
  100. public ReturnValue<LaboratoryTest> AddNewData(string strCode, string strType)
  101. {
  102. ReturnValue<LaboratoryTest> returnValue = new ReturnValue<LaboratoryTest>();
  103. if (strCode == "" || strType == "")
  104. {
  105. returnValue.StrErrorMsg = string.Format("参数为空,{0}", strCode == "" ? "样品编码" : "化验类型");
  106. return null;
  107. }
  108. //ARB 全水分;Moisture 水分;Ash 灰分;Volatile 挥发分;Crucible 坩埚;Heat 发热量:Sulfur 测硫;Hydrogen 测氢
  109. switch (strType)
  110. {
  111. case "ARB":
  112. iopera = new QuanShuiFenOpera();
  113. returnValue = iopera.CreateLaboratoryTestData(strCode);
  114. break;
  115. case "Moisture":
  116. iopera = new ShuiFenOpera();
  117. returnValue = iopera.CreateLaboratoryTestData(strCode);
  118. break;
  119. case "Ash":
  120. iopera = new HuiFenOpera();
  121. returnValue = iopera.CreateLaboratoryTestData(strCode);
  122. break;
  123. case "Volatile":
  124. iopera = new HuiFaFenOpera();
  125. returnValue = iopera.CreateLaboratoryTestData(strCode);
  126. break;
  127. case "Crucible|Heat":
  128. iopera = new CrucibleHeatOpera();
  129. returnValue = iopera.CreateLaboratoryTestData(strCode);
  130. break;
  131. case "Crucible|Sulfur":
  132. iopera = new CrucibleSulfurOpera();
  133. returnValue = iopera.CreateLaboratoryTestData(strCode);
  134. break;
  135. case "Crucible|Hydrogen":
  136. iopera = new CrucibleHydrogenOpera();
  137. returnValue = iopera.CreateLaboratoryTestData(strCode);
  138. break;
  139. }
  140. return returnValue;
  141. }
  142. /// <summary>
  143. /// 获取自动编码
  144. /// </summary>
  145. /// <param name="laboratoryTests"></param>
  146. /// <returns></returns>
  147. public string GetAutoCode(List<LaboratoryTest> laboratoryTests)
  148. {
  149. string strCode= "T";
  150. string strNewCode = DateTime.Now.ToString("yyyyMMdd") + "01";
  151. if (laboratoryTests.Count > 0)
  152. {
  153. var query = laboratoryTests.OrderByDescending(s => s.Auto_Code).ToList<LaboratoryTest>();
  154. string strMaxCode = query[0].Auto_Code;
  155. if (strMaxCode != "")
  156. {
  157. long maxIndex = Convert.ToInt64(strMaxCode.Substring(1, strMaxCode.Length - 1));
  158. if (maxIndex >= Convert.ToInt64(strNewCode))
  159. strCode += (maxIndex + 1).ToString();
  160. else
  161. strCode += strNewCode;
  162. }
  163. else
  164. strCode += strNewCode;
  165. }
  166. else
  167. {
  168. strCode += strNewCode;
  169. }
  170. return strCode;
  171. }
  172. /// <summary>
  173. /// 绘制序号列
  174. /// </summary>
  175. /// <param name="dgv"></param>
  176. /// <param name="e"></param>
  177. public void DrawFirstColumnIndex(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)
  178. {
  179. Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
  180. e.RowBounds.Location.Y,
  181. dgv.RowHeadersWidth - 4,
  182. e.RowBounds.Height);
  183. TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
  184. dgv.RowHeadersDefaultCellStyle.Font,
  185. rectangle,
  186. dgv.RowHeadersDefaultCellStyle.ForeColor,
  187. TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  188. }
  189. /// <summary>
  190. /// 提交编辑列
  191. /// </summary>
  192. /// <param name="dgv"></param>
  193. /// <param name="laboratoryTests"></param>
  194. /// <param name="e"></param>
  195. public void CommitEditColumn(DataGridView dgv, List<LaboratoryTest> laboratoryTests, DataGridViewCellEventArgs e)
  196. {
  197. if (dgv.CurrentCell == null) return;
  198. if (dgv.CurrentCell.Value == null) return;
  199. if (e.ColumnIndex == 2) //仪器编号
  200. {
  201. string strInputValue = dgv.CurrentCell.Value.ToString();
  202. string strCurrentID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString();
  203. var query = laboratoryTests.Where(s => s.GUID == strCurrentID).ToList<LaboratoryTest>();
  204. if (query.Count == 1)
  205. {
  206. query[0].Instrument_Number = strInputValue;
  207. if (query[0].OperationType == null || query[0].OperationType == "")
  208. query[0].OperationType = "update";
  209. }
  210. }
  211. if (e.ColumnIndex == 3) //坩埚编号
  212. {
  213. string strInputValue = dgv.CurrentCell.Value.ToString();
  214. string strCurrentID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString();
  215. var query = laboratoryTests.Where(s => s.GUID == strCurrentID).ToList<LaboratoryTest>();
  216. if (query.Count == 1)
  217. {
  218. query[0].Crucible_Number = strInputValue;
  219. if (query[0].OperationType == null || query[0].OperationType == "")
  220. query[0].OperationType = "update";
  221. }
  222. }
  223. if (e.ColumnIndex == 12) //颗粒度
  224. {
  225. string strInputValue = dgv.CurrentCell.Value.ToString();
  226. string strCurrentID = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString();
  227. var query = laboratoryTests.Where(s => s.GUID == strCurrentID).ToList<LaboratoryTest>();
  228. if (query.Count == 1)
  229. {
  230. query[0].Granularity = strInputValue;
  231. if (query[0].OperationType == null || query[0].OperationType == "")
  232. query[0].OperationType = "update";
  233. }
  234. }
  235. }
  236. /// <summary>
  237. /// 把天平端数据更改到显示端和存储端
  238. /// </summary>
  239. /// <param name="dgvQuanShuiFen"></param>
  240. /// <param name="lstWeightColumnIndex"></param>
  241. /// <param name="balanceWeight"></param>
  242. /// <param name="laboratoryTests"></param>
  243. public void UpdateQuanShuiFenBalanceWeight(System.Windows.Forms.DataGridView dgvQuanShuiFen, List<string> lstWeightColumnIndex, double balanceWeight, List<LaboratoryTest> laboratoryTests,string strType)
  244. {
  245. lstWeightColumnIndex = new List<string>() { "4", "5", "7", "8", "9" }; //全水分的这些列从天平端获取
  246. if (lstWeightColumnIndex.Contains(dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()))
  247. {
  248. string strCurrentValue = dgvQuanShuiFen.CurrentCell.Value.ToString();
  249. if (strCurrentValue != ""&&strCurrentValue!="0")
  250. {
  251. if (MessageBox.Show("单元格已经存在数据,继续将覆盖这个数据,是否继续?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  252. {
  253. switch (strType)
  254. {
  255. case "ARB":
  256. new QuanShuiFenUIOperation().UpdateQuanShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  257. break;
  258. case "Moisture":
  259. new ShuiFenUIOperation().UpdateShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  260. break;
  261. case "Ash":
  262. new HuiFenUIOperation().UpdateHuifenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  263. break;
  264. }
  265. }
  266. }
  267. else
  268. {
  269. switch (strType)
  270. {
  271. case "ARB":
  272. new QuanShuiFenUIOperation().UpdateQuanShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  273. break;
  274. case "Moisture":
  275. new ShuiFenUIOperation().UpdateShuiFenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  276. break;
  277. case "Ash":
  278. new HuiFenUIOperation().UpdateHuifenData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  279. break;
  280. }
  281. }
  282. }
  283. }
  284. /// <summary>
  285. /// 将天平传输的重量插入数据中
  286. /// </summary>
  287. /// <param name="dgvQuanShuiFen"></param>
  288. /// <param name="lstWeightColumnIndex"></param>
  289. /// <param name="balanceWeight"></param>
  290. /// <param name="laboratoryTests"></param>
  291. public void UpdateVolatileBalanceWeight(System.Windows.Forms.DataGridView dgvQuanShuiFen, List<string> lstWeightColumnIndex, double balanceWeight, List<LaboratoryTest> laboratoryTests)
  292. {
  293. lstWeightColumnIndex = new List<string>() { "4", "5", "7" }; //全水分的这些列从天平端获取
  294. if (lstWeightColumnIndex.Contains(dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()))
  295. {
  296. string strCurrentValue = dgvQuanShuiFen.CurrentCell.Value.ToString();
  297. if (strCurrentValue != "" && strCurrentValue != "0")
  298. {
  299. if (MessageBox.Show("单元格已经存在数据,继续将覆盖这个数据,是否继续?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
  300. {
  301. new HuiFaFenUIOperation().UpdateVolatileData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  302. }
  303. }
  304. else
  305. {
  306. new HuiFaFenUIOperation().UpdateVolatileData(dgvQuanShuiFen, balanceWeight, laboratoryTests);
  307. }
  308. }
  309. }
  310. /// <summary>
  311. /// 检查输入百分比大小是否是100内小数
  312. /// </summary>
  313. /// <param name="strInput"></param>
  314. /// <returns></returns>
  315. public bool CheckInputPercent(string strInput)
  316. {
  317. bool bIfSuccess = true;
  318. double value = 0;
  319. if (double.TryParse(strInput, out value))
  320. {
  321. if (value < 0 || value > 100)
  322. {
  323. MessageBox.Show("输入值范围为0~100", "提示");
  324. bIfSuccess = false;
  325. }
  326. }
  327. else
  328. {
  329. MessageBox.Show("输入值范围为0~100的数字", "提示");
  330. bIfSuccess = false;
  331. }
  332. return bIfSuccess;
  333. }
  334. /// <summary>
  335. /// 获取当前选中项的GUID集合
  336. /// </summary>
  337. /// <param name="dgv"></param>
  338. /// <returns></returns>
  339. public List<string> GetSelectItemID(DataGridView dgv)
  340. {
  341. List<string> lstSelectID = new List<string>();
  342. for (int j = 0; j < dgv.SelectedRows.Count; j++)
  343. {
  344. string strID = dgv.SelectedRows[j].Cells[0].Value.ToString();
  345. lstSelectID.Add(strID);
  346. }
  347. return lstSelectID;
  348. }
  349. /// <summary>
  350. /// 将天平传输来的重量插入坩埚架数据中
  351. /// </summary>
  352. /// <param name="DstCurrentLeftGrids"></param>
  353. /// <param name="dgvCrucibleShelf"></param>
  354. /// <param name="defaultdouble"></param>
  355. /// <param name="currentCrucibleDataType"></param>
  356. /// <param name="laboratoryTests"></param>
  357. public void UpdateCrucibleBalanceWeight(Dictionary<string,DataGridView> DstCurrentLeftGrids,DataGridView dgvCrucibleShelf, double defaultdouble,string currentCrucibleDataType,List<LaboratoryTest> laboratoryTests)
  358. {
  359. new CrucibleUIOperation().UpdateCrucibleBalanceWeight(DstCurrentLeftGrids, dgvCrucibleShelf, defaultdouble, currentCrucibleDataType, laboratoryTests);
  360. }
  361. /// <summary>
  362. /// 新增一组坩埚架数据
  363. /// </summary>
  364. /// <param name="DictCrucuibleGrids"></param>
  365. /// <param name="dgvCrucibleShelf"></param>
  366. /// <param name="currentCrucibleDataType"></param>
  367. /// <param name="strTypeTitle"></param>
  368. /// <param name="laboratoryTests"></param>
  369. public void AddCrucibleShelfData(Dictionary<string,DataGridView> DictCrucuibleGrids,DataGridView dgvCrucibleShelf, string currentCrucibleDataType,string strTypeTitle,List<LaboratoryTest> laboratoryTests)
  370. {
  371. new CrucibleUIOperation().AddCrucibleShelfData(DictCrucuibleGrids, dgvCrucibleShelf, currentCrucibleDataType, strTypeTitle, laboratoryTests);
  372. }
  373. }
  374. }