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 ShuiFenUIOperation { /// /// 更改水分数据 /// /// /// /// public void UpdateShuiFenData(System.Windows.Forms.DataGridView dgvShuiFen, double balanceWeight, List laboratoryTests) { //更改内存值 bool bIfUpdate = true; string strID = dgvShuiFen.Rows[dgvShuiFen.CurrentCell.RowIndex].Cells[0].Value.ToString(); var query = laboratoryTests.Where(s => s.GUID == strID).ToList(); if (query.Count == 1) { switch (dgvShuiFen.CurrentCell.ColumnIndex.ToString()) { case "4": //空坩埚重 query[0].Empty_Crucible_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight); dgvShuiFen.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); dgvShuiFen.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"://烘干重 if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight) { MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示"); bIfUpdate = false; } else { double oldvaue = query[0].Drying_Weight; query[0].Drying_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight); if (!UpdateMoisturePercentColumn(dgvShuiFen, laboratoryTests, dgvShuiFen.CurrentCell.RowIndex)) { query[0].Drying_Weight = CalculateOperation.GetShowDoubleValueN4(oldvaue); bIfUpdate = false; } }; break; case "8"://二次烘干重 if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight) { MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示"); bIfUpdate = false; } else { double oldvaue = query[0].SecondDrying_Weight; query[0].SecondDrying_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight); if (!UpdateMoisturePercentColumn(dgvShuiFen, laboratoryTests, dgvShuiFen.CurrentCell.RowIndex)) { query[0].SecondDrying_Weight = CalculateOperation.GetShowDoubleValueN4(oldvaue); bIfUpdate = false; } } break; case "9"://三次烘干重 if (query[0].AddSample_Weight != 0 && balanceWeight > query[0].AddSample_Weight) { MessageBox.Show("烘干重不能大于加样重,请调整后再传入。", "提示"); bIfUpdate = false; } else { double oldvaue = query[0].ThirdDrying_Weight; query[0].ThirdDrying_Weight = CalculateOperation.GetShowDoubleValueN4(balanceWeight); if (!UpdateMoisturePercentColumn(dgvShuiFen, laboratoryTests, dgvShuiFen.CurrentCell.RowIndex)) { query[0].ThirdDrying_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"; //更改显示值 dgvShuiFen.CurrentCell.Value = CalculateOperation.GetShowDoubleValueN4(balanceWeight); } } } /// /// 更改水分百分比 /// /// /// /// public bool UpdateMoisturePercentColumn(DataGridView dgvShuiFen, List laboratoryTests, int CurrentRowIndex) { bool IfUpdate = true; string strID = dgvShuiFen.Rows[CurrentRowIndex].Cells[0].Value.ToString(); var query = laboratoryTests.Where(s => s.GUID == strID).ToList(); if (query.Count == 1) { if (query[0].Sample_Weight != 0 && query[0].AddSample_Weight != 0 && query[0].Drying_Weight != 0) { double percentdouble = 0; if (query[0].SecondDrying_Weight == 0) { percentdouble = CalculateOperation.CalculateDecrement(query[0].AddSample_Weight, new double[1] { query[0].Drying_Weight }); dgvShuiFen.Rows[CurrentRowIndex].Cells["DecrementValue1"].Value = percentdouble; } else if (query[0].ThirdDrying_Weight == 0) { percentdouble = CalculateOperation.CalculateDecrement(query[0].AddSample_Weight, new double[2] { query[0].Drying_Weight, query[0].SecondDrying_Weight }); dgvShuiFen.Rows[CurrentRowIndex].Cells["DecrementValue1"].Value = percentdouble; } else { percentdouble = CalculateOperation.CalculateDecrement(query[0].AddSample_Weight, new double[3] { query[0].Drying_Weight, query[0].SecondDrying_Weight, query[0].ThirdDrying_Weight }); dgvShuiFen.Rows[CurrentRowIndex].Cells["DecrementValue1"].Value = percentdouble; } query[0].DecrementValue = Convert.ToDouble(dgvShuiFen.Rows[CurrentRowIndex].Cells["DecrementValue1"].Value); } } return IfUpdate; } } }