|
- using CnasSynchronusClient;
- using CnasSynchrousModel;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
-
- namespace CNAS_BalanceClient
- {
- public class HuiFaFenUIOperation
- {
- /// <summary>
- /// 将天平传输的重量插入数据中
- /// </summary>
- /// <param name="dgvQuanShuiFen"></param>
- /// <param name="balanceWeight"></param>
- /// <param name="laboratoryTests"></param>
- public void UpdateVolatileData(System.Windows.Forms.DataGridView dgvQuanShuiFen, double balanceWeight, List<LaboratoryTest> laboratoryTests)
- {
-
- bool bIfUpdate = true;
- //更改内存值
- string strID = dgvQuanShuiFen.Rows[dgvQuanShuiFen.CurrentCell.RowIndex].Cells[0].Value.ToString();
- var query = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
- if (query.Count == 1)
- {
- switch (dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString())
- {
- case "4": //空坩埚重
- if (balanceWeight < 15 || balanceWeight > 20)
- {
- MessageBox.Show("样重范围是15g~20g", "提示");
- bIfUpdate = false;
- }
- else
- {
- query[0].Empty_Crucible_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
- dgvQuanShuiFen.CurrentRow.Cells[6].Value = CalculateOperation.GetShowDoubleValueN4(query[0].Empty_Crucible_Weight + query[0].Sample_Weight);
- }
- break;
- case "5": //样重
- if (balanceWeight < 0.9 || balanceWeight > 1.1)
- {
- MessageBox.Show("样重范围是0.9g~1.1g");
- bIfUpdate = false;
- }
- else
- {
- query[0].Sample_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
- dgvQuanShuiFen.CurrentRow.Cells[6].Value = CalculateOperation.GetShowDoubleValueN4(query[0].Empty_Crucible_Weight + query[0].Sample_Weight);
- }
- break;
- case "6"://加样重
- //query[0].AddSample_Weight = balanceWeight;
- break;
- case "7"://烘干重
- //query[0].Drying_Weight = balanceWeight;
-
- if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight)
- {
- MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示");
- bIfUpdate = false;
- }
- else
- {
- double oldvaue = query[0].BurningResidue_Weight;
- query[0].BurningResidue_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
- if (!UpdateVolatilePercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.CurrentCell.RowIndex))
- {
- query[0].BurningResidue_Weight = CalculateOperation.GetShowDoubleValueN4(oldvaue);
- bIfUpdate = false;
- }
- }
- break;
- }
- if (bIfUpdate)
- {
- query[0].Operator = GlobalCommonOperation.strUserName;
- query[0].OperaDateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- if (query[0].OperationType == null || query[0].OperationType == "")
- query[0].OperationType = "update";
-
- //更改显示值
- dgvQuanShuiFen.CurrentCell.Value = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
- }
- }
- }
-
- /// <summary>
- /// 实时更改挥发分百分比数据
- /// </summary>
- /// <param name="dgvHuiFaFen"></param>
- /// <param name="laboratoryTests"></param>
- /// <param name="currentRowIndex"></param>
- /// <returns></returns>
- public bool UpdateVolatilePercentColumn(DataGridView dgvHuiFaFen, List<LaboratoryTest> laboratoryTests, int currentRowIndex)
- {
- bool IfUpdate = true;
- string strID = dgvHuiFaFen.Rows[currentRowIndex].Cells[0].Value.ToString();
- var query = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
- if (query.Count == 1)
- {
- if (query[0].Sample_Weight != 0 && query[0].AddSample_Weight != 0 && query[0].BurningResidue_Weight != 0)
- {
- string strMsg = "";
- double percentdouble = 0;
-
- 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);
- if (percentdouble > 100 || percentdouble < 0)
- {
- MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
- return false;
- }
- dgvHuiFaFen.Rows[currentRowIndex].Cells["Vr"].Value = percentdouble;
-
- 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));
- if (percentdouble > 100 || percentdouble < 0)
- {
- MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
- return false;
- }
- dgvHuiFaFen.Rows[currentRowIndex].Cells["VAD"].Value = percentdouble;
-
- query[0].Vr = Convert.ToDouble(dgvHuiFaFen.Rows[currentRowIndex].Cells["Vr"].Value);
- query[0].Vad = Convert.ToDouble(dgvHuiFaFen.Rows[currentRowIndex].Cells["VAD"].Value);
- }
- }
- return IfUpdate;
- }
- }
- }
|