CNAS取数仪器端升级
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 line
6.6KB

  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 HuiFaFenUIOperation
  11. {
  12. /// <summary>
  13. /// 将天平传输的重量插入数据中
  14. /// </summary>
  15. /// <param name="dgvQuanShuiFen"></param>
  16. /// <param name="balanceWeight"></param>
  17. /// <param name="laboratoryTests"></param>
  18. public void UpdateVolatileData(System.Windows.Forms.DataGridView dgvQuanShuiFen, double balanceWeight, List<LaboratoryTest> laboratoryTests)
  19. {
  20. bool bIfUpdate = true;
  21. //更改内存值
  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. if (balanceWeight < 15 || balanceWeight > 20)
  30. {
  31. MessageBox.Show("样重范围是15g~20g", "提示");
  32. bIfUpdate = false;
  33. }
  34. else
  35. {
  36. query[0].Empty_Crucible_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  37. dgvQuanShuiFen.CurrentRow.Cells[6].Value = CalculateOperation.GetShowDoubleValueN4(query[0].Empty_Crucible_Weight + query[0].Sample_Weight);
  38. }
  39. break;
  40. case "5": //样重
  41. if (balanceWeight < 0.9 || balanceWeight > 1.1)
  42. {
  43. MessageBox.Show("样重范围是0.9g~1.1g");
  44. bIfUpdate = false;
  45. }
  46. else
  47. {
  48. query[0].Sample_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  49. dgvQuanShuiFen.CurrentRow.Cells[6].Value = CalculateOperation.GetShowDoubleValueN4(query[0].Empty_Crucible_Weight + query[0].Sample_Weight);
  50. }
  51. break;
  52. case "6"://加样重
  53. //query[0].AddSample_Weight = balanceWeight;
  54. break;
  55. case "7"://烘干重
  56. //query[0].Drying_Weight = balanceWeight;
  57. if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight)
  58. {
  59. MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示");
  60. bIfUpdate = false;
  61. }
  62. else
  63. {
  64. double oldvaue = query[0].BurningResidue_Weight;
  65. query[0].BurningResidue_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  66. if (!UpdateVolatilePercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.CurrentCell.RowIndex))
  67. {
  68. query[0].BurningResidue_Weight = CalculateOperation.GetShowDoubleValueN4(oldvaue);
  69. bIfUpdate = false;
  70. }
  71. }
  72. break;
  73. }
  74. if (bIfUpdate)
  75. {
  76. query[0].Operator = GlobalCommonOperation.strUserName;
  77. query[0].OperaDateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  78. if (query[0].OperationType == null || query[0].OperationType == "")
  79. query[0].OperationType = "update";
  80. //更改显示值
  81. dgvQuanShuiFen.CurrentCell.Value = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 实时更改挥发分百分比数据
  87. /// </summary>
  88. /// <param name="dgvHuiFaFen"></param>
  89. /// <param name="laboratoryTests"></param>
  90. /// <param name="currentRowIndex"></param>
  91. /// <returns></returns>
  92. public bool UpdateVolatilePercentColumn(DataGridView dgvHuiFaFen, List<LaboratoryTest> laboratoryTests, int currentRowIndex)
  93. {
  94. bool IfUpdate = true;
  95. string strID = dgvHuiFaFen.Rows[currentRowIndex].Cells[0].Value.ToString();
  96. var query = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
  97. if (query.Count == 1)
  98. {
  99. if (query[0].Sample_Weight != 0 && query[0].AddSample_Weight != 0 && query[0].BurningResidue_Weight != 0)
  100. {
  101. string strMsg = "";
  102. double percentdouble = 0;
  103. percentdouble = CalculateOperation.CalculateVr(query[0].AddSample_Weight, query[0].Sample_Weight, new double[3] { query[0].BurningResidue_Weight, query[0].SecondBurningResidue_Weight, query[0].ThirdBurningResidue_Weight }, ref strMsg);
  104. if (percentdouble > 100 || percentdouble < 0)
  105. {
  106. MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
  107. return false;
  108. }
  109. dgvHuiFaFen.Rows[currentRowIndex].Cells["Vr"].Value = percentdouble;
  110. percentdouble = CalculateOperation.CalculateVad(CalculateOperation.CalculateVr(query[0].AddSample_Weight, query[0].Sample_Weight, new double[3] { query[0].BurningResidue_Weight, query[0].SecondBurningResidue_Weight, query[0].ThirdBurningResidue_Weight }, ref strMsg), Convert.ToDouble(dgvHuiFaFen.Rows[currentRowIndex].Cells["MAD2"].Value));
  111. if (percentdouble > 100 || percentdouble < 0)
  112. {
  113. MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
  114. return false;
  115. }
  116. dgvHuiFaFen.Rows[currentRowIndex].Cells["VAD"].Value = percentdouble;
  117. query[0].Vr = Convert.ToDouble(dgvHuiFaFen.Rows[currentRowIndex].Cells["Vr"].Value);
  118. query[0].Vad = Convert.ToDouble(dgvHuiFaFen.Rows[currentRowIndex].Cells["VAD"].Value);
  119. }
  120. }
  121. return IfUpdate;
  122. }
  123. }
  124. }