|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- 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
- {
- /// <summary>
- /// 更改水分数据
- /// </summary>
- /// <param name="dgvShuiFen"></param>
- /// <param name="balanceWeight"></param>
- /// <param name="laboratoryTests"></param>
- public void UpdateShuiFenData(System.Windows.Forms.DataGridView dgvShuiFen, double balanceWeight, List<LaboratoryTest> laboratoryTests)
- {
- //更改内存值
- bool bIfUpdate = true;
- string strID = dgvShuiFen.Rows[dgvShuiFen.CurrentCell.RowIndex].Cells[0].Value.ToString();
- var query = laboratoryTests.Where(s => s.GUID == strID).ToList<LaboratoryTest>();
- 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);
- }
- }
- }
-
- /// <summary>
- /// 更改水分百分比
- /// </summary>
- /// <param name="dgvShuiFen"></param>
- /// <param name="laboratoryTests"></param>
- /// <returns></returns>
- public bool UpdateMoisturePercentColumn(DataGridView dgvShuiFen, List<LaboratoryTest> laboratoryTests, int CurrentRowIndex)
- {
- bool IfUpdate = true;
- string strID = dgvShuiFen.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].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;
- }
- }
- }
|