123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- using BZFAStandardLib;
- using EIP_Protocol;
- using MainForm.ClassFile.ProjectClass;
- using Sunny.UI;
- using Sunny.UI.Win32;
- using System;
- using System.Collections.Generic;
- using System.Numerics;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
- namespace MainForm.FaForm
- {
- public partial class Dialog_MaterialVerify : Form
- {
- Form_Home home =new Form_Home();
- int plcNo = 1;
- string stationid = "";
- string stationCode = "";
- string strflag = "";
- string AglueCode = "F070HARJS";//A胶水
- string BglueCode = "F070HARKS";//B胶水
- string screw = "1660601000016A";//螺丝
- //OP30_MesData_t OP30PLC_MesData; //PLC的MES数据
- //OP70_MesData_t OP70PLC_MesData; //PLC的MES数据
- private Timer _inputTimer;
- public Dialog_MaterialVerify(string Code,string flag,string Material)
- {
- InitializeComponent();
- //置顶
- this.TopMost = true;
- // 设置窗口相对于父窗口居中
- this.StartPosition = FormStartPosition.CenterParent;
- this.Shown += MainForm_Shown;
- if (Code.Contains("OP30") || Code.Contains("OP31") || Code.Contains("OP32")) {
- if (flag == "Left") {
- Station.Text = "[OP31]点散热胶装备1";
- stationid = GlobalContext.s3_1_station;
- }
- if (flag == "Right") {
- Station.Text = "[OP32]点散热胶装备2";
- stationid = GlobalContext.s3_2_station;
- }
- }
- if (Code.Contains("OP80") || Code.Contains("OP81") || Code.Contains("OP82"))
- {
- if (flag == "Left")
- {
- Station.Text = "[OP81]上盖板锁螺丝1";
- }
- if (flag == "Right")
- {
- Station.Text = "[OP82]上盖板锁螺丝2";
- }
- }
- stationCode = Code;
- strflag = flag;
- Type.Text = Material;
- }
- private void Dialog_MaterialVerify_S1_Load(object sender, System.EventArgs e)
- {
- // 初始化定时器
- _inputTimer = new Timer();
- _inputTimer.Interval = 500; // 500毫秒
- _inputTimer.Tick += InputTimer_Tick;
- // 绑定 TextChanged 事件
- Barcode.TextChanged += Barcode_TextChanged;
- }
- private void OK_btn_Click(object sender, System.EventArgs e)
- {
- string strSN = SN.Text.Trim().Substring(0,9);
- if (stationCode.Contains("OP30") || stationCode.Contains("OP31") || stationCode.Contains("OP32"))
- {
- //左工位,AB胶水校验
- if (strSN != AglueCode && strflag == "Left" && Type.Text== "A胶水")
- {
- ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
- return;
- }
- if (strSN != BglueCode && strflag == "Left" && Type.Text == "B胶水")
- {
- ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
- return;
- }
- //右工位,AB胶水校验
- if (strSN != AglueCode && strflag == "Right" && Type.Text == "A胶水")
- {
- ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
- return;
- }
- if (strSN != BglueCode && strflag == "Right" && Type.Text == "B胶水")
- {
- ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
- return;
- }
- //胶水上传MES
- int res = home.MaterialVerifyPost(SN.Text.Trim(), stationid);
- if (res == 1)
- {
- string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt";
- FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} ");
- OKcloseWin();
- }
- else
- {
- //上传失败,取消窗口
- CancelcloseWin();
- }
- }
- else if(stationCode.Contains("OP80") || stationCode.Contains("OP81") || stationCode.Contains("OP82"))
- {
- if (strSN != screw && strflag == "Left")
- {
- ErrorLab.Text = $"料号[{strSN}]不匹配,请重新扫码!";
- return;
- }
- else if (strSN != screw && strflag == "Right")
- {
- ErrorLab.Text = $"料号[{strSN}]不匹配,请重新扫码!";
- return;
- }
- string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt";
- FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} ");
- OKcloseWin();
- }
- }
- private void Cancel_btn_Click(object sender, System.EventArgs e)
- {
- CancelcloseWin();
- }
- private void OKcloseWin()
- {
- Station.Text = "";
- Type.Text = "";
- SN.Text = "";
- this.DialogResult = DialogResult.OK;
- Form_Home.OpenDailogFalg = true;
- this.Close();
- }
- private void CancelcloseWin()
- {
- this.DialogResult = DialogResult.Cancel;
- Form_Home.OpenDailogFalg = true;
- this.Close();
- }
- private void MainForm_Shown(object sender, EventArgs e)
- {
- // 将焦点设置到 textBox1
- Barcode.Focus();
- }
- private void InputTimer_Tick(object sender, EventArgs e)
- {
- // 定时器触发,表示输入已经完成
- _inputTimer.Stop();
- //模拟点击
- Barcode.Focus();
- string strBarcode = Barcode.Text.Trim();
- if (!string.IsNullOrEmpty(strBarcode))
- {
- SN.Text = strBarcode.ToUpper();
- Barcode.Text = "";
- OK_btn_Click(sender,e);//模拟点击事件
- }
- }
- private void Barcode_TextChanged(object sender, EventArgs e)
- {
- // 每次文本变化时重置定时器
- _inputTimer.Stop();
- _inputTimer.Start();
- }
- }
- }
|