private void CreateMainTask() { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("模拟业务", () => { if (!this.IsStartSimulator) { return; } // 心跳 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJSignal>() + " set TagValue=@TagValue where TagName=@TagName", new { TagName = GlobalVars.EquHeartbeatName, TagValue = DateTime.Now.ToString() }); // 更新采样计划 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJPlan>() + " set DataFlag=1 where DataFlag=0"); // 控制命令 EquPDCYJCmd pDCYJCmd = dber.Entity <EquPDCYJCmd>("where DataFlag=0 order by CreateDate desc"); if (pDCYJCmd != null) { CmdHandle(pDCYJCmd); autoResetEvent.WaitOne(); } // 卸样命令 EquPDCYJUnloadCmd pDCYJUnloadCmd = dber.Entity <EquPDCYJUnloadCmd>("where DataFlag=0 order by CreateDate desc"); if (pDCYJUnloadCmd != null) { CmdHandle(pDCYJUnloadCmd); autoResetEvent.WaitOne(); } }, 3000); }
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); } }