|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- 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 QuanShuiFenUIOperation
- {
- /// <summary>
- /// 更改全水分数据
- /// </summary>
- /// <param name="dgvQuanShuiFen">datagridview控件</param>
- /// <param name="balanceWeight">天平传过来的重量</param>
- /// <param name="laboratoryTests">数据源</param>
- public void UpdateQuanShuiFenData(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": //空坩埚重
- 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": //样重
- double MinValue = 0;
- double MaxValue = 0;
- if (query[0].Granularity == "13mm")
- {
- MinValue = 490;
- MaxValue = 510;
- }
- else
- {
- MinValue = 10;
- MaxValue = 12;
- }
- if (balanceWeight < MinValue || balanceWeight > MaxValue)
- {
- MessageBox.Show($"样重范围是{MinValue}g~{MaxValue}g.", "提示");
- 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"://烘干重
- 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 (!UpdateARBPercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.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 (!UpdateARBPercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.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 (!UpdateARBPercentColumn(dgvQuanShuiFen, laboratoryTests, dgvQuanShuiFen.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";
-
- //更改显示值
- dgvQuanShuiFen.CurrentCell.Value = CalculateOperation.GetShowDoubleValueN4(balanceWeight);
- //if(dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()=="4"|| dgvQuanShuiFen.CurrentCell.ColumnIndex.ToString()=="5")
- // dgvQuanShuiFen.CurrentRow.Cells[6].Value = query[0].AddSample_Weight;
- }
- }
- }
-
- /// <summary>
- /// 更改全水分百分比
- /// </summary>
- /// <param name="dgv"></param>
- /// <param name="laboratoryTests"></param>
- /// <returns></returns>
- public bool UpdateARBPercentColumn(DataGridView dgv, List<LaboratoryTest> laboratoryTests, int CurrentRowIndex)
- {
- bool IfUpdate = true;
- string strID = dgv.Rows[CurrentRowIndex].Cells["ID"].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)
- {
- string strMsg = "";
- double percentdouble = 0;
- if (query[0].SecondDrying_Weight == 0)
- {
- percentdouble = CalculateOperation.CalculateMt(query[0].AddSample_Weight, query[0].Sample_Weight, new double[1] { query[0].Drying_Weight }, ref strMsg);
- if (percentdouble > 100 || percentdouble < 0)
- {
- MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
- return false;
- }
- dgv.Rows[CurrentRowIndex].Cells["Mt"].Value = percentdouble;
- }
-
- else if (query[0].ThirdDrying_Weight == 0)
- {
- percentdouble = CalculateOperation.CalculateMt(query[0].AddSample_Weight, query[0].Sample_Weight, new double[2] { query[0].Drying_Weight, query[0].SecondDrying_Weight }, ref strMsg);
- if (percentdouble > 100 || percentdouble < 0)
- {
- MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
- return false;
- }
- dgv.Rows[CurrentRowIndex].Cells["Mt"].Value = percentdouble;
- }
- else
- {
- 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);
- if (percentdouble > 100 || percentdouble < 0)
- {
- MessageBox.Show("百分比计算结果出错,请调整数据。", "提示");
- return false;
- }
- dgv.Rows[CurrentRowIndex].Cells["Mt"].Value = percentdouble;
- }
-
- query[0].Mt = Convert.ToDouble(dgv.Rows[CurrentRowIndex].Cells["Mt"].Value);
- }
- }
- return IfUpdate;
- }
- }
- }
|