using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Diagnostics.Eventing.Reader; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MESClassLibrary.BLL.BasicInfo; using MESClassLibrary.BLL.Log; using MESClassLibrary.BLL.Painting; using MESClassLibrary.BLL.PunchAndWeld; using MESClassLibrary.DAL; using MESClassLibrary.Model; using OPCAutomation; namespace PunchAndWeld { public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region 变量 private string strHostIP; private string strHostName; private OPCServer opcServer; private OPCGroups opcGroups; private OPCGroup opcGroup1; private OPCItems opcItems1; private OPCItem[] opcItemm1; private OPCGroup opcGroup2; private OPCItems opcItems2; private OPCItem[] opcItemm2; private string[] ItemIDs; object ItemValues; object Qualities; object TimeStamps; public bool Connected = false; public bool IsChangeBox = false; public bool IsStart = false; public string barCode = ""; //蒙皮条码 public string radarCode = ""; //雷达支架条码 #endregion private void Form1_Load(object sender, EventArgs e) { try { PunchAdressBLL bll = new PunchAdressBLL(); PunchPlanBLL planBLL=new PunchPlanBLL(); textBox1.TabIndex = 0; textBox1.Focus(); label1.Text = ""; lbPlan.Text = ""; //lbBoxL.Visible = false; //LbBoxR.Visible = false; //txtBoxL.Visible = false; //txtBoxR.Visible = false; label7.Text = ""; label10.Text = ""; timer1.Enabled = false; timer1.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["InterVal"]); if (CreateServer()) { if (ConnectServer(strHostIP, "Kepware.KEPServerEX.V6")) { Connected = true; #region 创建组 opcGroups = opcServer.OPCGroups; opcGroup1 = opcGroups.Add("DeviceRead"); opcGroup2 = opcGroups.Add("DeviceWrite"); SetGroupProperty(opcGroup1, 500); SetGroupProperty(opcGroup2, 500); #endregion #region 创建项R opcItems1 = opcGroup1.OPCItems; opcItems1.DefaultIsActive = true; DataTable dt = bll.SearchInfo(ConfigurationManager.AppSettings["DeviceNo"], 0); if (dt != null && dt.Rows.Count > 0) { opcItemm1 = new OPCItem[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { opcItemm1[i] = opcItems1.AddItem(dt.Rows[i]["Address"].ToString(), i); } } #endregion #region 创建项W opcItems2 = opcGroup2.OPCItems; opcItems2.DefaultIsActive = true; DataTable dt1 = bll.SearchInfo(ConfigurationManager.AppSettings["DeviceNo"], 1); if (dt1 != null && dt1.Rows.Count > 0) { opcItemm2 = new OPCItem[dt1.Rows.Count]; for (int i = 0; i < dt1.Rows.Count; i++) { opcItemm2[i] = opcItems2.AddItem(dt1.Rows[i]["Address"].ToString(), i); } } #endregion opcGroup1.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange); #region 初始化页面 #region 设备状态 if (ReadSingleValueFromOPC1(2).ToLower() == "true") { lbState.Text = "等待放件状态"; } else { lbState.Text = "设备未准备OK"; } #endregion #region 运行状态 if (ReadSingleValueFromOPC1(0).ToLower() == "true") { lbFinish.Text = "运行完成"; //textBox1.Enabled = true; } else { lbFinish.Text = "正在运行"; //textBox1.Enabled = false; } #endregion #region 冲焊状态 if (ReadSingleValueFromOPC1(4).ToLower() == "true") { lbOK.Text = "NG"; } else { lbOK.Text = "OK"; } #endregion #region 设备模式 if (ReadSingleValueFromOPC2(1) == 1) { lbmode.Text = "手动"; } else if (ReadSingleValueFromOPC2(1) == 2) { lbmode.Text = "复位"; } else if (ReadSingleValueFromOPC2(1) == 3) { lbmode.Text = "自动"; } else if (ReadSingleValueFromOPC2(1) == 4) { lbmode.Text = "半自动"; } #endregion #region 当前计划和生产数 DataTable pdt = planBLL.SearchPlan(ConfigurationManager.AppSettings["DeviceNo"]); if (pdt != null && pdt.Rows.Count > 0) { lbPlan.Text = pdt.Rows[0]["ProductName"].ToString(); label7.Text = pdt.Rows[0]["CompleteCount"].ToString() + " / " + pdt.Rows[0]["PlanCount"].ToString(); } else { lbPlan.Text = ""; label1.Text = "当前设备没有生产计划!"; } #endregion #endregion } } else { MessageBox.Show("创建OPC服务失败!", "提示", MessageBoxButtons.OK); Connected = false; LogHelper.WriteLog("创建OPC服务失败!"); return; } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } /// /// 创建服务 /// /// private bool CreateServer() { try { opcServer = new OPCServer(); } catch { return false; } return true; } /// /// 连接到服务器 /// /// /// /// private bool ConnectServer(string strHostIP, string strHostName) { try { opcServer.Connect(strHostName, strHostIP); } catch { return false; } return true; } private void SetGroupProperty(OPCGroup opcGroup, int updateRate) { opcGroup.IsActive = true; opcGroup.DeadBand = 0; opcGroup.UpdateRate = updateRate; opcGroup.IsSubscribed = true; } /// /// bool型 /// /// /// public string ReadSingleValueFromOPC1(int i) { object ItemValues; object Qualities; object TimeStamps; opcItemm1[i].Read(1, out ItemValues, out Qualities, out TimeStamps); if ((ItemValues != null) && (Qualities.ToString() != "Good")) { return ItemValues.ToString(); } else { return ""; } } /// /// int 型 /// /// /// public int ReadSingleValueFromOPC2(int i) { object ItemValues; object Qualities; object TimeStamps; opcItemm1[i].Read(1, out ItemValues, out Qualities, out TimeStamps); if ((ItemValues != null) && (Qualities.ToString() != "Good")) { return Convert.ToInt32(ItemValues.ToString()); } else { return 0; } } void opcGroup1_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues,ref Array Qualities, ref Array TimeStamps) { try { PunchValueRecordBLL bll=new PunchValueRecordBLL(); PunchValueRecordModel md=new PunchValueRecordModel(); for (int i = 1; i <= NumItems; i++) { int handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim()); string value = ItemValues.GetValue(i).ToString(); string address = opcItemm1[(Convert.ToInt32(ClientHandles.GetValue(i)))].ItemID; #region 焊接完成 0 if (handle == 0) { if (value == "1" || value.ToUpper() == "TRUE") { lbFinish.Text = "运行完成"; } else { lbFinish.Text = "正在运行"; } } #endregion #region 设备模式 1 if (handle == 1) { if (value == "1") { lbmode.Text = "手动"; } else if (value == "2") { lbmode.Text = "复位"; } else if (value == "3") { lbmode.Text = "自动"; } else if (value == "4") { lbmode.Text = "半自动"; } } #endregion #region 设备状态 2 if (handle == 2) { if (value == "1" || value.ToUpper() == "TRUE") { lbState.Text = "等待放件状态"; label1.Text = "请扫描蒙皮条码"; //textBox1.Enabled = true; textBox1.Text = ""; textBox1.SelectAll(); } else { lbState.Text = "设备未准备OK"; label1.Text = ""; //textBox1.Enabled = false; } } #endregion #region 更换雷达支架 3 if (handle == 3 || handle == 4) { if (value == "1" || value.ToUpper() == "TRUE") { IsChangeBox = true; } else { IsChangeBox = false; } } #endregion #region 冲焊状态 4 if (handle == 5) { if (value == "1" || value.ToUpper() == "TRUE") { lbOK.Text = "NG"; } else { lbOK.Text = "OK"; } } #endregion md.ID = Guid.NewGuid().ToString(); md.DeviceNo = ConfigurationManager.AppSettings["DeviceNo"].ToString(); md.Address = address; md.ItemValue = value; bll.AddInfo(md); } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { try { PunchRecordBLL bll=new PunchRecordBLL(); PunchPlanBLL planBll=new PunchPlanBLL(); PunchRecordModel md=new PunchRecordModel(); PunchPlanModel pmd=new PunchPlanModel(); string partNo = "",PlanID="",color1="",color2="",color3=""; string barCode = ""; ProductBLL productBll=new ProductBLL(); BarCodeBLL barbll = new BarCodeBLL(); StockInBLL sbll=new StockInBLL(); PunchAndStationBLL pasbll=new PunchAndStationBLL(); if (e.KeyCode == Keys.Enter) { if (textBox1.Text.Trim() == "") { label1.Text = "请扫描蒙皮条码"; MessageBox.Show("请扫描蒙皮条码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.Focus(); return; } if (lbState.Text == "设备未准备OK") { label1.Text = "设备未准备OK,不能扫描蒙皮!"; MessageBox.Show("设备未准备OK,不能扫描蒙皮!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } label1.Text = ""; #region 所有设备都改成读取塑件条码,故屏蔽此段代码 wff 2020-05-22 //if (ConfigurationManager.AppSettings["DeviceNo"] == "BMPTJQSB-05-123") //{ // if (textBox1.Text.Trim().Length != 20) // { // label1.Text = "扫描的蒙皮条码有误,请重新扫描"; // MessageBox.Show("扫描的蒙皮条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // textBox1.SelectAll(); // return; // } // else // { // #region 通过存货代码查找零件号 // DataTable dt4 = productBll.SearchIsImportByStockNo(textBox1.Text.Substring(0, 10)); // if (dt4 != null && dt4.Rows.Count > 0) // { // partNo = dt4.Rows[0]["PartNo"].ToString(); // barCode = partNo + "." + textBox1.Text.Substring(10, 6) + "." + // textBox1.Text.Substring(16, 4).PadLeft(6, '0'); // } // else // { // label1.Text = "扫描的蒙皮条码有误,请重新扫描"; // MessageBox.Show("扫描的蒙皮条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // textBox1.SelectAll(); // return; // } // #endregion // } //} //else //{ // string[] aa = textBox1.Text.Split(';'); // if (aa.Length < 5) // { // label1.Text = "扫描的蒙皮条码有误,请重新扫描"; // MessageBox.Show("扫描的蒙皮条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // textBox1.SelectAll(); // return; // } // barCode = aa[0]; // string[] bb = barCode.Split('.'); // partNo = bb[0]; //} #endregion #region 新增 #region 校验数据 if (textBox1.Text.Trim().Contains('.') == false) //一维码 { if (textBox1.Text.Trim().Length != 20) { label1.Text = "扫描的蒙皮条码有误,请重新扫描"; MessageBox.Show("扫描的蒙皮条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } DataTable twodt = barbll.SearchOneBarCode(textBox1.Text.Trim(), 1); if (twodt != null && twodt.Rows.Count > 0) { barCode = textBox1.Text.Trim(); } else { label1.Text = "扫描的蒙皮条码有误,请重新扫描"; MessageBox.Show("扫描的蒙皮条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } } else //二维码,将二维码转换成一维码判断 { DataTable twodt = barbll.SearchOneBarCode(textBox1.Text.Trim(),2); if (twodt != null && twodt.Rows.Count > 0) { barCode = twodt.Rows[0]["OneBarCode"].ToString(); } else { label1.Text = "扫描的蒙皮条码有误,请重新扫描"; MessageBox.Show("扫描的蒙皮条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } } #endregion #region 根据一维码查找颜色 DataTable colordt = sbll.SearchColor(barCode); if (colordt != null && colordt.Rows.Count > 0) { partNo = colordt.Rows[0]["paintCode"].ToString(); } else { label1.Text = "扫描的蒙皮无颜色信息,请重新扫描"; MessageBox.Show("扫描的蒙皮无颜色信息,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } #endregion #endregion DataTable dt2 = planBll.SearchPlan(ConfigurationManager.AppSettings["DeviceNo"]); if (dt2 != null && dt2.Rows.Count > 0) { #region 0604注释 //if (dt2.Rows[0]["PartNo"].ToString() == partNo) //{ // PlanID = dt2.Rows[0]["ID"].ToString(); //} //else //{ // #region 发送报警 // opcItemm2[0].Write("1"); // #endregion // label1.Text = "扫描的蒙皮和计划不一致,请重新扫描蒙皮!"; // MessageBox.Show("扫描的蒙皮和计划不一致,请重新扫描蒙皮!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // textBox1.SelectAll(); // return; //} #endregion #region 判定半成品零件号是否和计划零件号匹配 DataTable isMath = pasbll.IsMath(dt2.Rows[0]["PartNo"].ToString(), partNo); if (isMath != null && isMath.Rows.Count > 0) { //匹配 PlanID = dt2.Rows[0]["ID"].ToString(); } else { #region 发送报警 opcItemm2[0].Write("1"); #endregion label1.Text = "扫描的蒙皮和计划不一致,请重新扫描蒙皮!"; MessageBox.Show("扫描的蒙皮和计划不一致,请重新扫描蒙皮!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } #endregion } else { label1.Text = "此设备没有计划,请联系计划员!"; MessageBox.Show("此设备没有计划,请联系计划员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } DataTable dt1 = bll.SearchInfo(barCode); if (dt1 != null && dt1.Rows.Count > 0) { #region 重复扫描 DialogResult result = MessageBox.Show("条码为"+ barCode+"的蒙皮已经冲孔,是否重新冲孔?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == DialogResult.OK) { FrmPassWord pass=new FrmPassWord(); pass.OkBtnClick += (arg1) => { if (!string.IsNullOrEmpty(arg1) && arg1.ToLower() == ConfigurationManager.AppSettings["password"].ToLower()) { pass.Close(); if (txtBoxL.Text.Trim() != "" && txtBoxR.Text.Trim() != "") { string[] barCode1 = txtBoxL.Text.Split('.'); string[] part1 = barCode1[0].Split('-'); color1 = part1[1].ToString(); string[] barCode2 = txtBoxR.Text.Split('.'); string[] part = barCode2[0].Split('-'); color2 = part[1].ToString(); if (partNo.Substring(partNo.Length - 4, 4) == color2) { #region 发送启动设备指令 if (partNo.Contains("DM")) //高配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } else if (partNo.Contains("DP")) //低配 { opcItemm2[3].Write("3"); opcItemm2[2].Write("1"); } else //不区分高低配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } label10.BackColor = Color.Green; timer1.Start(); #endregion } else { opcItemm2[0].Write("1"); label1.Text = "雷达支架和蒙皮不匹配!"; MessageBox.Show("雷达支架和蒙皮不匹配!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } } else { #region 发送启动设备指令 if (partNo.Contains("DM")) //高配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } else if (partNo.Contains("DP")) //低配 { opcItemm2[3].Write("3"); opcItemm2[2].Write("1"); } else //不区分高低配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } #endregion label10.BackColor = Color.Green; timer1.Start(); } #region 增加产量 pmd.ID = PlanID; planBll.UpdateDty(pmd); #endregion #region 更新计划和产量 DataTable pdt = planBll.SearchPlan(ConfigurationManager.AppSettings["DeviceNo"]); if (pdt != null && pdt.Rows.Count > 0) { lbPlan.Text = pdt.Rows[0]["ProductName"].ToString(); label7.Text = pdt.Rows[0]["CompleteCount"].ToString() + " / " + pdt.Rows[0]["PlanCount"].ToString(); } else { lbPlan.Text = ""; label1.Text = "当前设备没有生产计划!"; label7.Text = ""; } #endregion textBox1.Focus(); textBox1.SelectAll(); } else { MessageBox.Show("密码错误,请重新输入!", "提示", MessageBoxButtons.OK); } }; pass.ShowDialog(); } #endregion } else { #region 第一次扫描,判断产品和计划是否一致 if (IsChangeBox == false) { if (txtBoxL.Text.Trim() != "" && txtBoxR.Text.Trim() != "") { string[] barCode1 = txtBoxL.Text.Split('.'); string[] part1 = barCode1[0].Split('-'); color1 = part1[1].ToString(); string[] barCode2 = txtBoxR.Text.Split('.'); string[] part = barCode2[0].Split('-'); color2 = part[1].ToString(); if (partNo.Substring(partNo.Length - 4, 4) == color2) { #region 发送启动信号 if (partNo.Contains("DM")) //高配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } else if (partNo.Contains("DP")) //低配 { opcItemm2[3].Write("3"); opcItemm2[2].Write("1"); } else //不区分高低配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } #endregion label10.BackColor = Color.Green; timer1.Start(); } else { opcItemm2[0].Write("1"); label1.Text = "雷达支架和蒙皮不匹配!"; MessageBox.Show("雷达支架和蒙皮不匹配!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.SelectAll(); return; } } else { #region 发送启动信号 if (partNo.Contains("DM")) //高配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } else if (partNo.Contains("DP")) //低配 { opcItemm2[3].Write("3"); opcItemm2[2].Write("1"); } else //不区分高低配 { opcItemm2[3].Write("1"); opcItemm2[1].Write("1"); } #endregion label10.BackColor = Color.Green; timer1.Start(); } } else { #region 校验雷达支架 //lbBoxL.Visible = true; //LbBoxR.Visible = true; //txtBoxL.Visible = true; //txtBoxR.Visible = true; //txtBoxL.Focus(); #region 校验左支架 //string[] barCode1 = txtBoxL.Text.Split('.'); //if (barCode1.Length > 0) //{ // string[] part = barCode1[0].Split('-'); // if (part.Length == 2) // { // color1 = part[1].ToString(); // if (partNo.Substring(partNo.Length - 4, partNo.Length) == color1) // { // txtBoxR.Focus(); // } // else // { // #region 发送报警 // opcItemm2[0].Write("1"); // #endregion // } // } // else // { // label1.Text = "左雷达支架条码有误,请重新扫描!"; // MessageBox.Show("左雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // txtBoxL.SelectAll(); // return; // } //} //else //{ // label1.Text = "左雷达支架条码有误,请重新扫描!"; // MessageBox.Show("左雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // txtBoxL.SelectAll(); // return; //} #endregion #region 校验右支架 //string[] barCode2 = txtBoxR.Text.Split('.'); //if (barCode2.Length > 0) //{ // string[] part = barCode2[0].Split('-'); // if (part.Length == 2) // { // color2 = part[1].ToString(); // if (partNo.Substring(partNo.Length - 4, partNo.Length) == color2) // { // lbBoxL.Visible = false; // LbBoxR.Visible = false; // txtBoxL.Visible = false; // txtBoxR.Visible = false; // } // else // { // #region 发送报警 // opcItemm2[0].Write("1"); // #endregion // } // } // else // { // label1.Text = "右雷达支架条码有误,请重新扫描!"; // MessageBox.Show("右雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // txtBoxR.SelectAll(); // return; // } //} //else //{ // label1.Text = "右雷达支架条码有误,请重新扫描!"; // MessageBox.Show("右雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // txtBoxL.SelectAll(); // return; //} #endregion #endregion } #region 存入记录表 md.ID = Guid.NewGuid().ToString(); md.BarCode = barCode; bll.AddInfo(md); #endregion #region 增加产量 pmd.ID = PlanID; planBll.UpdateDty(pmd); #endregion #region 更新计划和产量 DataTable pdt = planBll.SearchPlan(ConfigurationManager.AppSettings["DeviceNo"]); if (pdt != null && pdt.Rows.Count > 0) { lbPlan.Text = pdt.Rows[0]["ProductName"].ToString(); label7.Text = pdt.Rows[0]["CompleteCount"].ToString() + " / " + pdt.Rows[0]["PlanCount"].ToString(); } else { lbPlan.Text = ""; label1.Text = "当前设备没有生产计划!"; label7.Text = ""; } #endregion label1.Text = ""; textBox1.SelectAll(); #endregion } } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private void txtBoxL_KeyDown(object sender, KeyEventArgs e) { try { string color1 = "", color2 = "", color3 = ""; if (e.KeyCode == Keys.Enter) { string[] barCode1 = txtBoxL.Text.Split('.'); if (barCode1.Length > 0) { string[] part = barCode1[0].Split('-'); if (part.Length == 2) { txtBoxR.Focus(); } else { label1.Text = "左雷达支架条码有误,请重新扫描!"; MessageBox.Show("左雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtBoxL.SelectAll(); return; } } else { label1.Text = "左雷达支架条码有误,请重新扫描!"; MessageBox.Show("左雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtBoxL.SelectAll(); return; } } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private void txtBoxR_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { string color1 = "", color2 = "", color3 = ""; string[] barCode2 = txtBoxR.Text.Split('.'); if (barCode2.Length > 0) { string[] part = barCode2[0].Split('-'); if (part.Length == 2) { color2 = part[1].ToString(); } else { label1.Text = "右雷达支架条码有误,请重新扫描!"; MessageBox.Show("右雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtBoxR.SelectAll(); return; } string[] barCode1 = txtBoxL.Text.Split('.'); string[] part1 = barCode1[0].Split('-'); color1 = part1[1].ToString(); if (color1 != color2) { label1.Text = "左右雷达支架不匹配,请重新扫描!"; MessageBox.Show("左右雷达支架不匹配,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtBoxR.SelectAll(); return; } else { textBox1.Focus(); } } else { label1.Text = "右雷达支架条码有误,请重新扫描!"; MessageBox.Show("右雷达支架条码有误,请重新扫描!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtBoxL.SelectAll(); return; } } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private void timer1_Tick(object sender, EventArgs e) { label10.BackColor = panel1.BackColor; timer1.Stop(); } } }