void windowsUIButtonPanel_ButtonClick(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e) { switch (e.Button.Properties.Caption) { case "添加记录": m_addProductionPlanForm = (m_addProductionPlanForm == null || m_addProductionPlanForm.IsDisposed) ? new AddForm4(this) : m_addProductionPlanForm; m_addProductionPlanForm.Show(); break; case "批量导入": ImportExcel(); Console.WriteLine("批量导入"); break; case "删除": DeleteSelect(); break; case "刷新": string batchNo = DateTime.Now.ToString("yyyyMMdd"); productionPlans = m_productionPlanDao.GetDataSourceList(batchNo); gridControl.DataSource = productionPlans; break; case "上移": MoveUp(); break; case "下移": MoveDown(); break; case "全部上件": if (MessageBox.Show("确认全部上件?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { e.Button.Properties.Enabled = false; InstallAllWorkpiece(); } break; case "漏读": if (MessageBox.Show("确认出现漏读?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { short result = opcClient.ReadDataFromOpcServer(m_xmlSettings.Count); opcClient.WriteDataToOpcServer(m_xmlSettings.Count, (ushort)(result + 1)); } break; } }
public ProductionPlanControl() { InitializeComponent(); m_productionPlanDao = new ProductionPlanDao(); m_productionPlanList = new BindingList <Models.ProductionPlan>(); productionPlans = new List <Models.ProductionPlan>(); m_productionInfoDao = new ProductionInfoDao(); opcClient = new OpcClient(); string batchNo = DateTime.Now.ToString("yyyyMMdd"); productionPlans = m_productionPlanDao.GetDataSourceList(batchNo); gridControl.DataSource = productionPlans; Dictionary <object, string> dicButtons = new Dictionary <object, string>(); dicButtons.Add("Up", "上件"); dicButtons.Add("Stop", "暂停"); //dicButtons.Add("Finish", "结束上件"); RepositoryItemButtonEdit ribe = ItemOperation.CreateRepositoryItemButtonEdit(dicButtons); ribe.ButtonClick += new ButtonPressedEventHandler(this.ribe_ButtonClick); //绑定事件 this.gridView.Columns["Operating"].ColumnEdit = ribe; m_xmlSettings = new XMLSettings(); m_xmlSettings.ReadXMLSettings(); if (opcClient.WriteDataToOpcServer(m_xmlSettings.Count, (ushort)0)) { opcClient.WriteDataToOpcServer(new Models.ProductionPlan { BatchNo = "0", WorkpieceType = "0", PrimerColor = "0", PigmentedCoatingColor = "0", VarnishColor = "0", WorkpieceNo = "0", PrimerFirm = "0", PrimerCraft = "0", PigmentedCoatingFirm = "0", PigmentedCoatingCraft = "0", VarnishFirm = "0", VarnishCraft = "0", TotalNum = 0 }); } Task t1 = Task.Run(() => { byte data = 0; while (data < 128) { try { opcClient.WriteDataToOpcServer(m_xmlSettings.Heartbeat, data); data++; if (data == 128) { data = 0; } } catch (Exception ex) { LogManager.WriteLog(LogFile.Warning, $"t1:{ex.Message}"); } } }); Task t2 = Task.Run(() => { while (true) { try { short tagInitializationNo202 = Convert.ToInt16(opcClient.ReadData(m_xmlSettings.TagInitializationNo202).Value); short tagInitializationNo203 = Convert.ToInt16(opcClient.ReadData(m_xmlSettings.TagInitializationNo203).Value); if (tagInitializationNo202 >= tagInitializationNo203) { int value = tagInitializationNo202 <= 454 ? 454 : tagInitializationNo202; opcClient.WriteStrDataToOpcServer(m_xmlSettings.TagInitializationNo203, $"{value}"); } } catch (Exception ex) { LogManager.WriteLog(LogFile.Warning, $"t2:{ex.Message}"); } } }); }