private void btnSubmit_Click(object sender, EventArgs e) { List <InfBalanceRecordDetail> details = new List <InfBalanceRecordDetail>(); foreach (GridRow item in superGridControl2.PrimaryGrid.Rows) { InfBalanceRecordDetail entity = item.DataItem as InfBalanceRecordDetail; if (Convert.ToBoolean(item.Cells["clmDetailCheck"].Value)) { details.Add(entity); } } if (details.Count == 0) { MessageBoxEx.Show("请选择数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { int res = 0; SqlServerDapperDber sqlServerDapper = new SqlServerDapperDber(commonDAO.GetCommonAppletConfigString("开元天平接口数据连接字符串")); foreach (InfBalanceRecordDetail detail in details) { TPWeight weight = sqlServerDapper.Entity <TPWeight>("where S_NO=@S_NO and TP_Type=@TP_Type", new { S_NO = detail.TheBalanceRecord.AssayCode + "-" + detail.GGCode, TP_Type = detail.TheBalanceRecord.AssayType }); if (weight == null) { weight = new TPWeight(); weight.S_NO = detail.TheBalanceRecord.AssayCode + "-" + detail.GGCode; weight.TP_Type = detail.TheBalanceRecord.AssayType; weight.Weight = detail.Weight; weight.TP_NO = detail.TheBalanceRecord.MachineCode; weight.Stateop = 1; weight.SortNumber = detail.GGCode; weight.GG_NO = detail.GGCode; weight.Sample_NO = detail.TheBalanceRecord.AssayCode; weight.CreateTime = DateTime.Now; weight.Creator = detail.CreateUser; sqlServerDapper.Insert(weight); detail.SyncFlag = 1; commonDAO.SelfDber.Update(detail); res++; } else { if (MessageBoxEx.Show("该化验编码重量已提交,是否覆盖!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning) == DialogResult.OK) { weight.S_NO = detail.TheBalanceRecord.AssayCode + "-" + detail.GGCode; weight.TP_Type = detail.TheBalanceRecord.AssayType; weight.Weight = detail.Weight; weight.TP_NO = detail.TheBalanceRecord.MachineCode; weight.Stateop = 1; weight.GG_NO = detail.GGCode; weight.Sample_NO = detail.TheBalanceRecord.AssayCode; sqlServerDapper.Update(weight); res++; } } } MessageBoxEx.Show("成功提交" + res + "条数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); LoadBalanceDetailList(superGridControl2, this.CurrentAssay.Id); } catch (Exception ex) { MessageBoxEx.Show("提交失败:" + Environment.NewLine + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void CmdHandle(EquPDCYJCmd input) { Task task = new Task((state) => { EquPDCYJCmd pDCYJCmd = state as EquPDCYJCmd; OutputRunInfo(rtxtOutput, "处理命令,命令代码:" + pDCYJCmd.CmdCode + " 采样码:" + pDCYJCmd.SampleCode); if (pDCYJCmd.CmdCode == eEquInfSamplerCmd.开始采样.ToString()) { EquPDCYJPlan pDCYJPlan = dber.Entity <EquPDCYJPlan>("where SampleCode=@SampleCode", new { SampleCode = pDCYJCmd.SampleCode }); if (pDCYJPlan != null) { Thread.Sleep(3000); OutputRunInfo(rtxtOutput, "启动采样机"); // 更新系统状态为正在运行 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJSignal>() + " set TagValue=@TagValue where MachineCode=@MachineCode and TagName=@TagName", new { MachineCode = pDCYJCmd.MachineCode, TagName = eSignalDataName.设备状态.ToString(), TagValue = eEquInfSamplerSystemStatus.正在运行.ToString() }); // 更新集样罐 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJBarrel>() + " set IsCurrent=0 where MachineCode=@MachineCode and BarrelType=@BarrelType", new { MachineCode = pDCYJCmd.MachineCode, BarrelType = pDCYJPlan.GatherType }); EquPDCYJBarrel pDCYJBarrel = dber.Entity <EquPDCYJBarrel>("where MachineCode=@MachineCode and SampleCode=@SampleCode and BarrelType=@BarrelType and SampleCount<3", new { MachineCode = pDCYJCmd.MachineCode, SampleCode = pDCYJCmd.SampleCode, BarrelType = pDCYJPlan.GatherType }); if (pDCYJBarrel == null) { pDCYJBarrel = dber.Entity <EquPDCYJBarrel>("where MachineCode=@MachineCode and SampleCode='' and BarrelType=@BarrelType", new { MachineCode = pDCYJCmd.MachineCode, BarrelType = pDCYJPlan.GatherType }); if (pDCYJBarrel != null) { OutputRunInfo(rtxtOutput, "分配集样罐,罐号:" + pDCYJBarrel.BarrelNumber + " " + pDCYJBarrel.BarrelType); pDCYJBarrel.SampleCount = 1; pDCYJBarrel.SampleCode = pDCYJCmd.SampleCode; pDCYJBarrel.InFactoryBatchId = pDCYJPlan.InFactoryBatchId; pDCYJBarrel.IsCurrent = 1; pDCYJBarrel.BarrelStatus = eSampleBarrelStatus.未满.ToString(); pDCYJBarrel.UpdateTime = DateTime.Now; pDCYJBarrel.DataFlag = 0; dber.Update(pDCYJBarrel); } } else { OutputRunInfo(rtxtOutput, "分配集样罐,罐号:" + pDCYJBarrel.BarrelNumber + " " + pDCYJBarrel.BarrelType); pDCYJBarrel.SampleCount++; pDCYJBarrel.IsCurrent = 1; pDCYJBarrel.BarrelStatus = eSampleBarrelStatus.未满.ToString(); pDCYJBarrel.UpdateTime = DateTime.Now; pDCYJBarrel.DataFlag = 0; dber.Update(pDCYJBarrel); } // 更新计划 pDCYJPlan.StartTime = DateTime.Now; dber.Update(pDCYJPlan); // 更新命令 pDCYJCmd.ResultCode = eEquInfCmdResultCode.成功.ToString(); pDCYJCmd.DataFlag = 2; dber.Update(pDCYJCmd); } else { OutputRunInfo(rtxtOutput, "未找到采样计划,采样码:" + pDCYJCmd.SampleCode); pDCYJCmd.ResultCode = eEquInfCmdResultCode.失败.ToString(); pDCYJCmd.DataFlag = 1; dber.Update(pDCYJCmd); } } else if (pDCYJCmd.CmdCode == eEquInfSamplerCmd.结束采样.ToString()) { Thread.Sleep(3000); OutputRunInfo(rtxtOutput, "停止采样机"); // 更新系统状态为就绪待机 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJSignal>() + " set TagValue=@TagValue where MachineCode=@MachineCode and TagName=@TagName", new { MachineCode = pDCYJCmd.MachineCode, TagName = eSignalDataName.序状态.ToString(), TagValue = eEquInfSamplerSystemStatus.就绪待机.ToString() }); EquPDCYJPlan pDCYJPlan = dber.Entity <EquPDCYJPlan>("where SampleCode=@SampleCode", new { SampleCode = pDCYJCmd.SampleCode }); if (pDCYJPlan != null) { // 更新计划 pDCYJPlan.SampleUser = "******"; pDCYJPlan.StartTime = DateTime.Now.AddSeconds(10); pDCYJPlan.EndTime = DateTime.Now; dber.Update(pDCYJPlan); } // 更新命令 pDCYJCmd.ResultCode = eEquInfCmdResultCode.成功.ToString(); pDCYJCmd.DataFlag = 2; dber.Update(pDCYJCmd); } autoResetEvent.Set(); }, input); task.Start(); }