using BarTenderPrint; using KeyBord; using Mesnac.Codd.Session; using Mesnac.Compressor.Data; using Mesnac.HighWay.ATC.Common; using Mesnac.HighWay.ATC.SqlSugar; using Mesnac.HighWay.ATC.SqlSugar.serviceImpl; using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Timers; using System.Windows.Forms; using Mesnac.Compressor.Entity; using static FrmPrint.Login; using static log4net.Appender.RollingFileAppender; using static System.Windows.Forms.VisualStyles.VisualStyleElement; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button; using System.Collections; using System.Runtime.InteropServices; using System.Reflection.Emit; namespace FrmPrint { public partial class Form1 : Form { [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")] public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); protected DbHandler db = new DbHandler(); DbHelper dbHelper = null; SerialEquip Com; string Port = System.Configuration.ConfigurationManager.AppSettings["Com"]; public delegate void Transit(string data); PrintManager printManager = new PrintManager(); public string UserName = "用户名"; private int timeInvel =int.Parse(System.Configuration.ConfigurationManager.AppSettings["LogOutTime"])*1000; private static INIFile iNIFile = new INIFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "App.InI"); private List productInfos; List listOnit = new List(); public Form1() { InitializeComponent(); if (!timer1.Enabled) { timer1.Interval = timeInvel; timer1.Enabled = true; } CheckForIllegalCrossThreadCalls = false; printManager.RefreshShowMessageEvent += ShowMessage; //BindClass(); //bindMachine(); getMachine(); //initUsbScanBarCode(); InitPort(); } private void Form1_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; cb_machine.DropDownStyle = ComboBoxStyle.DropDown; DateTime startTime = DateTime.Today.AddHours(1); // 结束时间设置为 23:00:00 DateTime endTime = DateTime.Today.AddHours(23); // 从开始时间开始,每次增加 1 小时,直到达到结束时间 for (DateTime currentTime = startTime; currentTime <= endTime; currentTime = currentTime.AddHours(1)) { // 将当前时间格式化为 HH:mm:ss 并添加到 ComboBox 中 comboBox1.Items.Add(currentTime.ToString("HH:mm:ss")); comboBox2.Items.Add(currentTime.ToString("HH:mm:ss")); } for (char i = 'A'; i <= 'Z'; i++) { comboBox3.Items.Add(i); } if (iNIFile.IniReadValue("SystemConfig", "UserName") != "用户名") { iNIFile.IniWriteValue("SystemConfig", "UserName", "用户名"); } if (iNIFile.IniReadValue("SystemConfig", "PrintState") != "2") { iNIFile.IniWriteValue("SystemConfig", "PrintState", "2"); } ShowMessage("系统启动成功!"); //listener.Start(); //加载默认时间 lb_UserName.Text = UserName; lb_UserName.ForeColor = Color.Red; LoadTime(); //dateTimePicker1.Visible = false; //dateTimePicker1.Visible = true; //dateTimePicker2.Visible = false; //dateTimePicker2.Visible = true; //comboBox1.Visible = false; //comboBox1.Visible = true; //comboBox2.Visible = false; //comboBox2.Visible = true; } public void ShowMessage(string strMessage) { try { LogHelper.Info(strMessage); if (this.lst_OperInfo.Items.Count > 100) { this.lst_OperInfo.Items.Clear(); } bool scroll = false; if (this.lst_OperInfo.TopIndex == this.lst_OperInfo.Items.Count - (int)(this.lst_OperInfo.Height / this.lst_OperInfo.ItemHeight)) scroll = true; this.lst_OperInfo.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + strMessage); if (scroll) this.lst_OperInfo.TopIndex = this.lst_OperInfo.Items.Count - (int)(this.lst_OperInfo.Height / this.lst_OperInfo.ItemHeight); string tempstr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": " + strMessage + "\r\n"; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); } } public void InitPort() { Com = new SerialEquip(Port); Com.OpenCom(null); Com.SerialData += Receive; } public void Receive(string Data) { try { ShowMessage(" "+ Data+"条码扫描成功!"); Thread.Sleep(1000); PrintPrepare(Data.Trim()); } catch(Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); } } private async void PrintPrepare(string Data) { if (string.IsNullOrEmpty(Data)) { return; } if (Data.Length != 20) { if (Data.Length != 11 && Data.Length != 19) { ShowMessage("请确认条码是否正确!"); return; } } //提示换班 //var date = DateTime.Now; //DateTime dt1 = DateTime.Parse(time2.Text + " "+ time4.Text); //DateTime dt2 = DateTime.Parse(time1.Text + " " + time3.Text); if (comboBox3.Text == "") { ShowMessage("请选择班组!"); return; } if (cb_machine.Text == "") { ShowMessage("请选择机种!"); return; } //if (date >= dt1) //{ // if (radioButton1.Checked) // { // ShowMessage("请切换班次!白班(08:00-20:00)夜班(20:00-08:00)"); // return; // } //} //else //{ // if (date < dt2 && date >= dt1) // { // if (radioButton2.Checked) // { // ShowMessage("请切换班次!白班(08:00-20:00)夜班(20:00-08:00)"); // return; // } // } //} Reresh(Data.Replace("\r", "")); if (iNIFile.IniReadValue("SystemConfig", "PrintState") == "1") { ShowMessage("上一个铭牌正在打印中,等待打印完成重新扫码..."); return; } #region 打印代码暂时屏蔽 //根据条码查询是否到当前工位 bool iFlag = false; //豪森工位合格查询 //if (System.Configuration.ConfigurationManager.AppSettings["SqlString"].ToString().Contains("HS")) //{ // iFlag = GetStationNGBySemiBarCode(Data.Replace("\r", "")); //} ////卓樱工位合格查询 //if (System.Configuration.ConfigurationManager.AppSettings["SqlString"].ToString().Contains("JYD_shengjie")) //{ // iFlag = await SelectPrintStation(Data.Replace("\r", "")); //} //581工位合格查询 if (System.Configuration.ConfigurationManager.AppSettings["SqlString"].ToString().Contains("581")) { //新增查询是否存在绑定信息 bool _bindFlag = await SelectBindInfo(Data.Replace("\r", "")); if (_bindFlag) { return; } //ShowMessage("正在查询产品是否合格..."); iFlag = GetStationNGByProductCode(Data.Replace("\r", "")); } if (!iFlag) { ShowMessage("查询产品结果合格."); } else { return; } //ShowMessage("正在查询产品结果是否合格..."); //查询结果是否合格 Print pt = new Print(); pt.barcode = Data; //查询当前机种信息 List TBDProductInfo = await geTbdProductInfos(cb_machine.Text); pt.Machine =int.Parse(TBDProductInfo[0].ProductID); int num = 4; if (!string.IsNullOrEmpty(TBDProductInfo[0].ToolCarNo.Trim())) { num = int.Parse(TBDProductInfo[0].ToolCarNo.Trim()); } else { ShowMessage("序列号位数有误,请检查机种信息..."); } //add by 2024-09-02 新增手动切换班次业务逻辑 pt.Shift = comboBox3.Text; //if (radioButton1.Checked) //{ // pt.Shift = "A"; //pt.starttime = time1.Text + " " + time3.Text; //int datetime = Convert.ToInt32(DateTime.Now.Hour.ToString()); //if (datetime >= 8 && datetime < 20) //{ // pt.endtime = time2.Text + " " + DateTime.Now.ToString("HH:mm:ss"); //} //else //{ // pt.endtime = DateTime.Now.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss"); //} //} //else if (radioButton2.Checked) //{ //pt.Shift = "B"; //pt.starttime = time1.Text + " " + time3.Text; //int datetime = Convert.ToInt32(DateTime.Now.Hour.ToString()); //if (datetime >= 0 && datetime < 8) //{ // pt.endtime = time2.Text + " " + DateTime.Now.ToString("HH:mm:ss"); //} //else //{ // pt.endtime = DateTime.Now.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss"); //} //} //else //{ // pt.Shift = "C"; //} pt.starttime = dateTimePicker1.Text + " " + comboBox1.Text; pt.endtime = dateTimePicker2.Text + " " + comboBox2.Text; if (iNIFile.IniReadValue("SystemConfig", "UserName") != "管理员") { LogHelper.Info("查询" + Data + "产品序列号是否存在相同记录!"); var iflag = await SelectSameBarCode(pt.barcode, pt.Shift, pt.Machine.ToString(), pt.starttime, pt.endtime); if (!iflag) { return; } else { //先根据班次时间查询最大序列号,如果不存在则从0001生成 //List baseBarcodePrintInfo = await printManager.SelectPrintInfoAsync("",pt.Shift, pt.Machine.ToString(), pt.starttime, pt.endtime); //改为存储过程查询 var max = SelectSerialNo(pt.Shift,pt.Machine.ToString(), pt.starttime, pt.endtime); if (!string.IsNullOrEmpty(max)) { //查询最大序列号生成 ShowMessage("查询当前最大序列号" + max); pt.Serialnum = Convert.ToInt32(Convert.ToInt32(max.Substring(max.Length - num, num)) + 1).ToString().PadLeft(num, '0'); ShowMessage("生成新序列号" + pt.Serialnum); } else { //序列号0001 pt.Serialnum = "1".PadLeft(num, '0'); ShowMessage("生成新序列号" + pt.Serialnum); } //if (baseBarcodePrintInfo != null && baseBarcodePrintInfo.Count > 0) //{ // //查询最大序列号生成 // var max = baseBarcodePrintInfo.Max(x => x.SerialNo); // ShowMessage("查询当前最大序列号" + max); // pt.Serialnum = Convert.ToInt32(Convert.ToInt32(max.Substring(max.Length - num, num)) + 1).ToString().PadLeft(num, '0'); // ShowMessage("生成新序列号" + pt.Serialnum); //} //else //{ // //序列号0001 // pt.Serialnum = "1".PadLeft(num, '0'); // ShowMessage("生成新序列号" + pt.Serialnum); //} } } //管理员补码 else { ShowMessage("补码功能开启,查询到当前用户名管理员"); List baseBarcodePrintInfo = await printManager.SelectPrintInfoAsync("", pt.Shift, pt.Machine.ToString(), pt.starttime, pt.endtime); if (baseBarcodePrintInfo != null && baseBarcodePrintInfo.Count > 0) { //查询最大序列号生成 var max = baseBarcodePrintInfo.Max(x => x.SerialNo); ShowMessage("查询当前最大序列号" + max); pt.Serialnum = Convert.ToInt32(Convert.ToInt32(max.Substring(max.Length - num, num)) + 1).ToString().PadLeft(num, '0'); pt.isRestart = 1; ShowMessage("生成新序列号" + pt.Serialnum); } else { //序列号0001 pt.Serialnum = "1".PadLeft(num, '0'); pt.isRestart = 1; ShowMessage("生成新序列号" + pt.Serialnum); } } //Print(pt); ThreadPool.QueueUserWorkItem(p => { Print(pt, TBDProductInfo); }); //ThreadPool.QueueUserWorkItem(new WaitCallback(Print), pt, baseBarcodePrintInfo); #endregion } private async Task SelectBindInfo(string ProductBarcode) { bool iFlag = false; try { Expression> exp = s1 => true; exp = exp.And(s1 => s1.ProductBarcode == ProductBarcode); Expression> order = (x) => x.BeginTime; List MaterialInfoList = await new BaseServices().Query(exp, order, true); if (MaterialInfoList != null && MaterialInfoList.Count > 0) { if (string.IsNullOrEmpty(MaterialInfoList[0].SemiBarcode2)) { ShowMessage(ProductBarcode + "未绑定控制器码!"); iFlag = true; return iFlag; } if (string.IsNullOrEmpty(MaterialInfoList[0].SemiBarcode_A)) { ShowMessage(ProductBarcode + "未绑定前盖码!"); iFlag = true; return iFlag; } if (string.IsNullOrEmpty(MaterialInfoList[0].SemiBarcode_B)) { ShowMessage(ProductBarcode + "未绑定静盘码!"); iFlag = true; return iFlag; } if (string.IsNullOrEmpty(MaterialInfoList[0].SemiBarcode_C)) { ShowMessage(ProductBarcode + "未绑定后盖码!"); iFlag = true; return iFlag; } } return iFlag; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); return iFlag; } } private async Task SelectPrintStation(string ProductBarcode) { bool iFlag = false; try { Expression> exp = s1 => true; exp = exp.And(s1 => s1.ProductBarcode == ProductBarcode); Expression> order = (x) => x.BeginTime; List MaterialInfoList = await new BaseServices().Query(exp, order, true); if (MaterialInfoList != null && MaterialInfoList.Count > 0) { var TSYTraceState = MaterialInfoList.OrderByDescending(x => x.BeginTime).FirstOrDefault(); if (TSYTraceState.CurrentStationID == "33") { iFlag = false; return iFlag; } else { ShowMessage(ProductBarcode + "上工位未完成,查询产品未到达条码打印工位!"); iFlag = true; return iFlag; } } else { ShowMessage(ProductBarcode + "上工位未完成,查询产品未到达条码打印工位!"); iFlag = true; return iFlag; } } catch (Exception ex) { return iFlag; } } public async Task SelectBYStationAsync(string ProductBarcode) { bool bflag = false; try { Expression> exp = s1 => true; exp = exp.And(s1 => s1.ScanBarcode == ProductBarcode); List MaterialInfoList = await new BaseServices().Query(exp); if (MaterialInfoList != null && MaterialInfoList.Count > 0) { bflag = true; } else { ShowMessage(ProductBarcode + "上工位未完成!"); bflag = false; } return bflag; } catch (Exception ex) { return bflag; } } /// /// 查询工位合格信息 /// /// /// public bool GetStationNGBySemiBarCode(string ProductBarcode) { bool iFlag = false; try { List selectAllStation = SaveBarCode(ProductBarcode); foreach (var VARIABLE in selectAllStation) { if (VARIABLE.TableName == "T_RP_StationPara_B130_1" && VARIABLE.State == "1") { selectAllStation.RemoveAll(x => x.TableName == "T_RP_StationPara_B130_2"); break; } else if (VARIABLE.TableName == "T_RP_StationPara_B130_2" && VARIABLE.State == "1") { selectAllStation.RemoveAll(x => x.TableName == "T_RP_StationPara_B130_1"); break; } } if (selectAllStation != null || selectAllStation.Count > 0) { for (int i = 0; i < selectAllStation.Count; i++) { if (selectAllStation[i].State != "1") { iFlag = true; ShowMessage(selectAllStation[i].StationName + "数据NG"); return iFlag; } } //selectAllStation = selectAllStation.FindAll(x => x.State == "2"); } return iFlag; } catch (Exception ex) { return iFlag; } } public bool GetStationNGByProductCode(string ProductBarcode) { bool iFlag = false; try { List selectAllStation = SaveBarCode(ProductBarcode,"270"); if (selectAllStation != null || selectAllStation.Count > 0) { for (int i = 0; i < selectAllStation.Count; i++) { if (selectAllStation[i].State != "1") { iFlag = true; ShowMessage(selectAllStation[i].StationName + "数据NG"); return iFlag; } } } return iFlag; } catch (Exception ex) { return iFlag; } } public string SelectSerialNo(string ShiftID, string MachineID,string starttime,string endtime) { try { string SerialNo = ""; SugarParameter[] pars = new BaseServices().GetParameters(new { ShiftID = ShiftID, MachineID = MachineID, starttime= starttime,endtime = endtime }); var dt2 = new BaseServices().UseStoredProcedure("SP_Pro_GetNewSerialNO ", pars); if (dt2 != null && dt2.Rows.Count > 0) { SerialNo = RowValue(dt2.Rows[0], "SerialNo", String.Empty); } return SerialNo; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); return null; } } public List SaveBarCode(string P_Bar_Code) { List stationQualityList = null; try { SugarParameter[] pars = new BaseServices().GetParameters(new { BarCode = P_Bar_Code }); var dt2 = new BaseServices().UseStoredProcedure("pro_AllProductionQualityInfocopy", pars); if (dt2 != null && dt2.Rows.Count > 0) { stationQualityList = new List(); StationQualityInfo stationQualityInfo = null; foreach (DataRow row in dt2.Rows) { stationQualityInfo = new StationQualityInfo(); stationQualityInfo.StationName = RowValue(row, "StationName", String.Empty); stationQualityInfo.TableName = RowValue(row, "TableName", String.Empty); stationQualityInfo.State = RowValue(row, "State", String.Empty); stationQualityList.Add(stationQualityInfo); } } return stationQualityList; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); return stationQualityList; } } public List SaveBarCode(string P_Bar_Code,string StationCode) { List stationQualityList = null; try { SugarParameter[] pars = new BaseServices().GetParameters(new { BarCode = P_Bar_Code, StationCode = StationCode }); var dt2 = new BaseServices().UseStoredProcedure("pro_AllProductionQualityInfo", pars); if (dt2 != null && dt2.Rows.Count > 0) { stationQualityList = new List(); StationQualityInfo stationQualityInfo = null; foreach (DataRow row in dt2.Rows) { stationQualityInfo = new StationQualityInfo(); stationQualityInfo.StationName = RowValue(row, "StationName", String.Empty); stationQualityInfo.TableName = RowValue(row, "TableName", String.Empty); stationQualityInfo.State = RowValue(row, "State", String.Empty); stationQualityList.Add(stationQualityInfo); } } return stationQualityList; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); return stationQualityList; } } public static string RowValue(DataRow dr, string field, string defaultValue) { if (dr.Table.Columns.Contains(field)) { if (dr[field] != null && dr[field] != DBNull.Value) { return dr[field].ToString().Trim(); } } else { ICSharpCode.Core.LoggingService.Error("DataTable中不存在[" + field + "]列!"); } return defaultValue; } /// /// 更新barcode /// /// private void Reresh(string barcode) { if (this.InvokeRequired) { this.Invoke(new Transit(Reresh), barcode); return; } this.txt_barcode.Text = barcode.ToString(); } private async Task getMachine() { try { productInfos = await geTbdProductInfos(""); foreach (var item in productInfos)//数据库中获取的原始数据 { listOnit.Add(item.ProductName);//第一列是名称 } this.cb_machine.Items.AddRange(listOnit.ToArray()); } catch (Exception ex) { Console.WriteLine(ex); } } private async Task> geTbdProductInfos(string ProductName) { try { Expression> exp = (TBDProductInfo s1) => true; if (ProductName == "") { exp = exp.And((TBDProductInfo s1) => s1.ProductName != ""); } else { exp = exp.And((TBDProductInfo s1) => s1.ProductName == ProductName); } productInfos = await new BaseServices().Query(exp); return productInfos; } catch (Exception ex) { Console.WriteLine(ex); return null; } } public DataTable GetProductList(string ProductID) { DataTable result = null; try { Expression> exp = (TBDProductInfo s1) => true; if (ProductID == "") { exp = exp.And((TBDProductInfo s1) => s1.ProductID != ""); } else { exp = exp.And((TBDProductInfo s1) => s1.ProductID == ProductID); } result = new BaseServices().QueryDatatable(exp); return result; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); return result; } } private void Print(object print, List baseBarcodePrintInfo) { lock (string.Empty) { //判断前工位是否全部合格 var pt = print as Print; if(pt==null) { return; } iNIFile.IniWriteValue("SystemConfig", "PrintState", "1"); printManager.Print(pt, baseBarcodePrintInfo); } } private async Task SelectSameBarCode(String BarCode, string ShiftID, string ProductID, string starttime, string endtime) { bool iflag = false; try { List baseBarcodePrintInfos = await printManager.SelectPrintInfoAsync(BarCode, ShiftID, ProductID.ToString(), starttime, endtime); if (baseBarcodePrintInfos != null && baseBarcodePrintInfos.Count > 0) { foreach (var item in baseBarcodePrintInfos) { ShowMessage("查询" + BarCode + "存在历史记录,序列号:" + item.SerialNo); LogHelper.Info("查询" + BarCode + "存在历史记录,序列号:" + item.SerialNo); return false; } } else { iflag = true; } return iflag; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); return iflag; } } public void BindClass() { DataTable dt = new DataTable(); dt.Columns.Add("key", typeof(string)); dt.Columns.Add("value", typeof(string)); DataRow dr = dt.NewRow(); dr[0] = "01"; dr[1] = "早班"; dt.Rows.Add(dr); DataRow dr2 = dt.NewRow(); dr2[0] = "02"; dr2[1] = "中班"; dt.Rows.Add(dr2); DataRow dr3 = dt.NewRow(); dr3[0] = "03"; dr3[1] = "晚班"; dt.Rows.Add(dr3); //this.cb_shift.DataSource = dt; //this.cb_shift.DisplayMember = "value"; //this.cb_shift.ValueMember = "key"; } private void btn_close_Click(object sender, EventArgs e) { this.Com.Comm.Close(); this.Close(); } private void btn_print_Click(object sender, EventArgs e) { //密码权限 if (btn_print.Text == "补 印") { Login login = new Login(this); login.ChangeText += new ChangeTextHandler(Change_Text); login.ShowDialog(); } if (btn_print.Text == "取消补印") { btn_print.Text = "补 印"; } } private void Change_Text(string str) { if (iNIFile.IniReadValue("SystemConfig", "UserName") != str) { iNIFile.IniWriteValue("SystemConfig", "UserName", str); } lb_UserName.Text = str; UserName = str; lb_UserName.ForeColor = Color.LightGreen; } private void LoadTime() { //int datetime = Convert.ToInt32(DateTime.Now.Hour.ToString()); //if (datetime >= 8 && datetime < 20) //{ // time1.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time3.Text = "08:00:00"; // time2.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time4.Text = "20:00:00"; // this.radioButton1.Checked = true; //} //else if (datetime >= 0 && datetime < 8) //{ // time1.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); // time3.Text = "20:00:00"; // time2.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time4.Text = "08:00:00"; // this.radioButton2.Checked = true; //} //else //{ // time1.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time3.Text = "20:00:00"; // time2.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"); // time4.Text = "08:00:00"; // this.radioButton2.Checked = true; //} //this.radioButton1.Checked = true; // 控件即将获得焦点时,将焦点转移到button1 txt_barcode.Focus(); dateTimePicker1.Text = DateTime.Now.ToString("yyyy-MM-dd"); dateTimePicker2.Text = DateTime.Now.ToString("yyyy-MM-dd"); comboBox1.SelectedIndex = 7; comboBox2.SelectedIndex = 19; } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { try { LogHelper.Info("程序退出!"); this.Com.Comm.Close(); //System.Environment.Exit(System.Environment.ExitCode); } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); } finally { this.Dispose(); this.Close(); } } private void radioButton2_CheckedChanged(object sender, EventArgs e) { //if (radioButton2.Checked == true) //{ // int datetime = Convert.ToInt32(DateTime.Now.Hour.ToString()); // if (datetime >= 8 && datetime < 20) // { // time1.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time3.Text = "08:00:00"; // time2.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time4.Text = "20:00:00"; // } // else if (datetime >= 0 && datetime < 8) // { // time1.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time3.Text = "20:00:00"; // time2.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"); // time4.Text = "08:00:00"; // } // else // { // time1.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time3.Text = "20:00:00"; // time2.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"); // time4.Text = "08:00:00"; // } //} //ShowMessage("》》》切换夜班班次!" + dateTimePicker1.Text + " " + comboBox1.Text + "至" + dateTimePicker2.Text + " " + comboBox2.Text); } private void radioButton1_CheckedChanged(object sender, EventArgs e) { //if (radioButton1.Checked == true) //{ // int datetime = Convert.ToInt32(DateTime.Now.Hour.ToString()); // if (datetime >= 8 && datetime < 20) // { // time1.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time3.Text = "08:00:00"; // time2.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time4.Text = "20:00:00"; // } // else if (datetime >= 0 && datetime < 8) // { // time1.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); // time3.Text = "08:00:00"; // time2.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time4.Text = "20:00:00"; // } // else // { // time1.Text = DateTime.Now.ToString("yyyy-MM-dd"); // time3.Text = "20:00:00"; // time2.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"); // time4.Text = "08:00:00"; // } //} //ShowMessage("》》》切换白班班次!" + dateTimePicker1.Text + " " + comboBox1.Text + "至" + dateTimePicker2.Text + " " + comboBox2.Text); } private void CollectGC() { try { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } catch (Exception ex) { } } private void timer1_Tick(object sender, EventArgs e) { try { CollectGC(); if (iNIFile.IniReadValue("SystemConfig", "UserName") != "用户名") { iNIFile.IniWriteValue("SystemConfig", "UserName", "用户名"); } this.UserName = "用户名"; lb_UserName.Text = "用户名"; lb_UserName.ForeColor = Color.Red; } catch (Exception ex) { LogHelper.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); } } List listNew = new List(); private void cb_machine_TextUpdate(object sender, EventArgs e) { //清空combobox this.cb_machine.Items.Clear(); //清空listNew listNew.Clear(); //遍历全部备查数据 foreach (var item in listOnit) { if (item.Contains(this.cb_machine.Text)) { //符合,插入ListNew listNew.Add(item); } } //combobox添加已经查到的关键词 this.cb_machine.Items.AddRange(listNew.ToArray()); //设置光标位置,否则光标位置始终保持在第一列,造成输入关键词的倒序排列 this.cb_machine.SelectionStart = this.cb_machine.Text.Length; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置。 Cursor = Cursors.Default; //自动弹出下拉框 this.cb_machine.DroppedDown = true; } private void timer2_Tick(object sender, EventArgs e) { //LoadTime(); //SetRadiobutton(); } private void cb_machine_SelectedIndexChanged(object sender, EventArgs e) { cb_machine.Visible = false; cb_machine.Visible = true; } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { // 控件即将获得焦点时,将焦点转移到button1 txt_barcode.Focus(); } //private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) //{ // comboBox1.Visible = false; // comboBox1.Visible = true; //} //private void dateTimePicker1_ValueChanged(object sender, EventArgs e) //{ // dateTimePicker1.Visible = false; // dateTimePicker1.Visible = true; //} //private void dateTimePicker2_ValueChanged(object sender, EventArgs e) //{ // dateTimePicker2.Visible = false; // dateTimePicker2.Visible = true; //} //private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) //{ // comboBox2.Visible = false; // comboBox2.Visible = true; //} } }