CNAS取数仪器端升级
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

183 Zeilen
9.4KB

  1. using CnasSynchronusClient;
  2. using CnasSynchrousModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace CNAS_BalanceClient
  9. {
  10. public class QuanShuiFenUIOperation
  11. {
  12. /// <summary>
  13. /// 更改全水分数据
  14. /// </summary>
  15. /// <param name="dgvQuanShuiFen">datagridview控件</param>
  16. /// <param name="balanceWeight">天平传过来的重量</param>
  17. /// <param name="laboratoryTests">数据源</param>
  18. public void UpdateQuanShuiFenData(System.Windows.Forms.DataGridView dgvQuanShuiFen, double balanceWeight, List<LaboratoryTest> laboratoryTests)
  19. {
  20. //更改内存值
  21. bool bIfUpdate = true;
  22. string strID = dgvQuanShuiFen.Rows[dgvQuanShuiFen.CurrentCell.RowIndex].Cells[0].Value.ToString();
  23. var query = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
  24. if (query.Count == 1)
  25. {
  26. switch (dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString())
  27. {
  28. case "4": //空坩埚重
  29. query[0].Empty_Crucible_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  30. dgvQuanShuiFen.CurrentRow.Cells[6].Value = CalculateOperation.GetShowDoubleValueN4(query[0].Empty_Crucible_Weight + query[0].Sample_Weight);
  31. break;
  32. case "5": //样重
  33. double MinValue = 0;
  34. double MaxValue = 0;
  35. if (query[0].Granularity == "13mm")
  36. {
  37. MinValue = 490;
  38. MaxValue = 510;
  39. }
  40. else
  41. {
  42. MinValue = 10;
  43. MaxValue = 12;
  44. }
  45. if (balanceWeight < MinValue || balanceWeight > MaxValue)
  46. {
  47. MessageBox.Show($"样重范围是{MinValue}g~{MaxValue}g.", "提示");
  48. bIfUpdate = false;
  49. }
  50. else
  51. {
  52. query[0].Sample_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  53. dgvQuanShuiFen.CurrentRow.Cells[6].Value = CalculateOperation.GetShowDoubleValueN4(query[0].Empty_Crucible_Weight + query[0].Sample_Weight);
  54. }
  55. break;
  56. case "6"://加样重
  57. //query[0].AddSample_Weight = balanceWeight;
  58. break;
  59. case "7"://烘干重
  60. if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight)
  61. {
  62. MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示");
  63. bIfUpdate = false;
  64. }
  65. else
  66. {
  67. double oldvaue = query[0].Drying_Weight;
  68. query[0].Drying_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  69. if (!UpdateARBPercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.CurrentCell.RowIndex))
  70. {
  71. query[0].Drying_Weight = CalculateOperation.GetShowDoubleValueN4(oldvaue);
  72. bIfUpdate = false;
  73. }
  74. }
  75. break;
  76. case "8"://二次烘干重
  77. if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight)
  78. {
  79. MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示");
  80. bIfUpdate = false;
  81. }
  82. else
  83. {
  84. double oldvaue = query[0].SecondDrying_Weight;
  85. query[0].SecondDrying_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  86. if (!UpdateARBPercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.CurrentCell.RowIndex))
  87. {
  88. query[0].SecondDrying_Weight = CalculateOperation.GetShowDoubleValueN4(oldvaue);
  89. bIfUpdate = false;
  90. }
  91. }
  92. break;
  93. case "9"://三次烘干重
  94. if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight)
  95. {
  96. MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示");
  97. bIfUpdate = false;
  98. }
  99. else
  100. {
  101. double oldvaue = query[0].ThirdDrying_Weight;
  102. query[0].ThirdDrying_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  103. if (!UpdateARBPercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.CurrentCell.RowIndex))
  104. {
  105. query[0].ThirdDrying_Weight = CalculateOperation.GetShowDoubleValueN4(oldvaue);
  106. bIfUpdate = false;
  107. }
  108. }
  109. break;
  110. }
  111. if (bIfUpdate)
  112. {
  113. query[0].Operator = GlobalCommonOperation.strUserName;
  114. query[0].OperaDateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  115. if (query[0].OperationType == null || query[0].OperationType == "")
  116. query[0].OperationType = "update";
  117. //更改显示值
  118. dgvQuanShuiFen.CurrentCell.Value = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  119. //if(dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()=="4"|| dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()=="5")
  120. // dgvQuanShuiFen.CurrentRow.Cells[6].Value = query[0].AddSample_Weight;
  121. }
  122. }
  123. }
  124. /// <summary>
  125. /// 更改全水分百分比
  126. /// </summary>
  127. /// <param name="dgv"></param>
  128. /// <param name="laboratoryTests"></param>
  129. /// <returns></returns>
  130. public bool UpdateARBPercentColumn(DataGridView dgv, List<LaboratoryTest> laboratoryTests, int CurrentRowIndex)
  131. {
  132. bool IfUpdate = true;
  133. string strID = dgv.Rows[CurrentRowIndex].Cells["ID"].Value.ToString();
  134. var query = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
  135. if (query.Count == 1)
  136. {
  137. if (query[0].Sample_Weight != 0 && query[0].AddSample_Weight != 0 && query[0].Drying_Weight != 0)
  138. {
  139. string strMsg = "";
  140. double percentdouble = 0;
  141. if (query[0].SecondDrying_Weight == 0)
  142. {
  143. percentdouble = CalculateOperation.CalculateMt(query[0].AddSample_Weight, query[0].Sample_Weight, new double[1] { query[0].Drying_Weight }, ref strMsg);
  144. if (percentdouble > 100 || percentdouble < 0)
  145. {
  146. MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
  147. return false;
  148. }
  149. dgv.Rows[CurrentRowIndex].Cells["Mt"].Value = percentdouble;
  150. }
  151. else if (query[0].ThirdDrying_Weight == 0)
  152. {
  153. percentdouble = CalculateOperation.CalculateMt(query[0].AddSample_Weight, query[0].Sample_Weight, new double[2] { query[0].Drying_Weight, query[0].SecondDrying_Weight }, ref strMsg);
  154. if (percentdouble > 100 || percentdouble < 0)
  155. {
  156. MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
  157. return false;
  158. }
  159. dgv.Rows[CurrentRowIndex].Cells["Mt"].Value = percentdouble;
  160. }
  161. else
  162. {
  163. percentdouble = CalculateOperation.CalculateMt(query[0].AddSample_Weight, query[0].Sample_Weight, new double[3] { query[0].Drying_Weight, query[0].SecondDrying_Weight, query[0].ThirdDrying_Weight }, ref strMsg);
  164. if (percentdouble > 100 || percentdouble < 0)
  165. {
  166. MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
  167. return false;
  168. }
  169. dgv.Rows[CurrentRowIndex].Cells["Mt"].Value = percentdouble;
  170. }
  171. query[0].Mt = Convert.ToDouble(dgv.Rows[CurrentRowIndex].Cells["Mt"].Value);
  172. }
  173. }
  174. return IfUpdate;
  175. }
  176. }
  177. }