diff --git a/InjectionPC/FrmBarCodeNew.Designer.cs b/InjectionPC/FrmBarCodeNew.Designer.cs index f74d325..33f169e 100644 --- a/InjectionPC/FrmBarCodeNew.Designer.cs +++ b/InjectionPC/FrmBarCodeNew.Designer.cs @@ -559,7 +559,6 @@ this.textBox3.TabIndex = 1; this.textBox3.UseSystemPasswordChar = true; this.textBox3.Click += new System.EventHandler(this.textBox3_Click); - this.textBox3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyDown); // // label22 // diff --git a/InjectionPC/FrmBarCodeNew.cs b/InjectionPC/FrmBarCodeNew.cs index c62620c..2525716 100644 --- a/InjectionPC/FrmBarCodeNew.cs +++ b/InjectionPC/FrmBarCodeNew.cs @@ -72,31 +72,35 @@ namespace InjectionPC initProduct(); initBarCode(); - DateTime aa = GetDateTime(); + SetBatchText(); - if (aa.Hour >= 8 && aa.Hour < 20) - { - Program.Shift = "A班"; - Program.ProductDate = aa.ToString("yyyy-MM-dd"); - } - else - { - Program.Shift = "B班"; - if (aa.Hour >= 0 && aa.Hour < 8) - { - Program.ProductDate =aa.AddDays(-1).ToString("yyyy-MM-dd"); - //Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); - } - else - { - Program.ProductDate = aa.ToString("yyyy-MM-dd"); - //Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); - } - } - comboBox1.Text = Program.Shift; + ////DateTime aa = GetDateTime(); + //DateTime aa = BasicDAL.GetServerTime(); + + //if (aa.Hour >= 8 && aa.Hour < 20) + //{ + // Program.Shift = "A班"; + // Program.ProductDate = aa.ToString("yyyy-MM-dd"); + //} + //else + //{ + // Program.Shift = "B班"; + // if (aa.Hour >= 0 && aa.Hour < 8) + // { + // Program.ProductDate =aa.AddDays(-1).ToString("yyyy-MM-dd"); + // //Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); + // } + // else + // { + // Program.ProductDate = aa.ToString("yyyy-MM-dd"); + // //Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); + // } + //} + //comboBox1.Text = Program.Shift; + + //textBox1.Text = Program.ProductDate.Substring(2, 2) + Program.ProductDate.Substring(5, 2) + + // Program.ProductDate.Substring(8, 2); - textBox1.Text = Program.ProductDate.Substring(2, 2) + Program.ProductDate.Substring(5, 2) + - Program.ProductDate.Substring(8, 2); if (IsStart == false) { timer1.Enabled = false; @@ -183,7 +187,7 @@ namespace InjectionPC }, null); } - + private void timer1_Tick(object sender, EventArgs e) { BarCodeBLL Barbll = new BarCodeBLL(); @@ -206,33 +210,11 @@ namespace InjectionPC DataTable pdt3 = null; - - DateTime aa = GetDateTime(); - - if (aa.Hour >= 8 && aa.Hour < 20) - { - Program.Shift = "A班"; - Program.ProductDate = aa.ToString("yyyy-MM-dd"); - } - else - { - Program.Shift = "B班"; - if (aa.Hour >= 0 && aa.Hour < 8) - { - Program.ProductDate = aa.AddDays(-1).ToString("yyyy-MM-dd"); - //Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); - } - else - { - Program.ProductDate = aa.ToString("yyyy-MM-dd"); - //Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); - } - } - - comboBox1.Text = Program.Shift; - textBox1.Text = Program.ProductDate.Substring(2, 2) + Program.ProductDate.Substring(5, 2) + - Program.ProductDate.Substring(8, 2); - LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + SetBatchText(); + + + + //LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); try { PingReply reply = p1.Send(Program.IP); //发送主机名或Ip地址 @@ -841,13 +823,13 @@ namespace InjectionPC timer1.Interval = Program.interVal; timer1.Start(); } - void ReloadProduceDate() - { - if (DateTime.Parse(Program.ProductDate).ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd")) - { - FrmLogin.SetProductDate(); - } - } + //void ReloadProduceDate() + //{ + // if (DateTime.Parse(Program.ProductDate).ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd")) + // { + // FrmLogin.SetProductDate(); + // } + //} private void label12_Click(object sender, EventArgs e) { @@ -964,7 +946,7 @@ namespace InjectionPC if (result == DialogResult.OK) { #region 生成条码 - + SetBatchText(); ProductBLL pbll = new ProductBLL(); //查询零件号 @@ -1338,12 +1320,6 @@ namespace InjectionPC } - private static bool IsNumeric(string str) - { - System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9]\d*$"); - return reg1.IsMatch(str); - } - /// /// 补打条码 /// @@ -1356,45 +1332,37 @@ namespace InjectionPC } - public DateTime GetDateTime() - { - string sql = ""; - DateTime time; - DataTable dt; - try - { - sql = @"select convert(char(23),getdate(),121) as time"; - - dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0]; - if (dt != null && dt.Rows.Count > 0) - { - //time = Convert.ToDateTime(dt.Rows[0]["time"].ToString()); - time = DateTime.ParseExact(dt.Rows[0]["time"].ToString(), "yyyy-MM-dd HH:mm:ss.fff", - System.Globalization.CultureInfo.CurrentCulture); - - } - else - { - time = DateTime.Now; - } - return time; - } - catch (Exception ex) - { - LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); - return DateTime.Now; - } - } - - private void ReportInitialize() - { - - } - - private void ReportFetchRecord() - { - - } + //public DateTime GetDateTime() + //{ + // string sql = ""; + // DateTime time; + // DataTable dt; + // try + // { + // sql = @"select convert(char(23),getdate(),121) as time"; + + // dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0]; + // if (dt != null && dt.Rows.Count > 0) + // { + // //time = Convert.ToDateTime(dt.Rows[0]["time"].ToString()); + // time = DateTime.ParseExact(dt.Rows[0]["time"].ToString(), "yyyy-MM-dd HH:mm:ss.fff", + // System.Globalization.CultureInfo.CurrentCulture); + + // } + // else + // { + // time = DateTime.Now; + // } + // return time; + // } + // catch (Exception ex) + // { + // LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); + // return DateTime.Now; + // } + //} + + /// /// 切换一下计划 @@ -1515,64 +1483,6 @@ namespace InjectionPC //Process.Start(@"C:\windows\system32\osk.exe"); ShowInputPanel(); } - - private const Int32 WM_SYSCOMMAND = 274; - - private const UInt32 SC_CLOSE = 61536; - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - - private static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - - private static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - - private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - - private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - - private static extern int RegisterWindowMessage(string lpString); - - - - //显示屏幕键盘 - - public static int ShowInputPanel() - { - - try - { - - dynamic file = "C:\\Program Files\\Common Files\\microsoft shared\\ink\\TabTip.exe"; - - if (!System.IO.File.Exists(file)) - - return -1; - - Process.Start(file); - - //return SetUnDock(); //不知SetUnDock()是什么,所以直接注释返回1 - - return 1; - - } - - catch (Exception) - { - - return 255; - - } - - } - private void button1_Click(object sender, EventArgs e) { if (textBox3.Text.Trim() != ConfigurationManager.AppSettings["Psw"]) @@ -1585,13 +1495,13 @@ namespace InjectionPC { panel3.Visible = false; textBox3.Text = ""; - string code = "",productName="", reportName=""; + string code = "", productName = "", reportName = ""; BarCodeModel md = new BarCodeModel(); BarCodeBLL bll = new BarCodeBLL(); ProductBLL pbll = new ProductBLL(); try { - if (code_g=="") + if (code_g == "") { MessageBox.Show("请选择要补打的条码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; @@ -1645,7 +1555,7 @@ namespace InjectionPC row["StationNo"] = Program.station; row["OneBarCode"] = md.OneBarCode; row["BarCode"] = code_g; - row["ProductName"] = productName+";"; + row["ProductName"] = productName + ";"; row["IsImport"] = md.Import; if (productName.Contains("右")) { @@ -1714,10 +1624,102 @@ namespace InjectionPC } } - private void textBox3_KeyDown(object sender, KeyEventArgs e) + + private const Int32 WM_SYSCOMMAND = 274; + + private const UInt32 SC_CLOSE = 61536; + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + + private static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + + private static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + + private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + + private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + + private static extern int RegisterWindowMessage(string lpString); + + + + //显示屏幕键盘 + + public static int ShowInputPanel() { - + + try + { + + dynamic file = "C:\\Program Files\\Common Files\\microsoft shared\\ink\\TabTip.exe"; + + if (!System.IO.File.Exists(file)) + + return -1; + + Process.Start(file); + + //return SetUnDock(); //不知SetUnDock()是什么,所以直接注释返回1 + + return 1; + + } + + catch (Exception) + { + + return 255; + + } + + } + + + private static bool IsNumeric(string str) + { + System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9]\d*$"); + return reg1.IsMatch(str); + } + /// + /// 设置班组和批次 + /// + void SetBatchText() + { + // DateTime aa = GetDateTime(); + DateTime aa = BasicDAL.GetServerTime(); + + if (aa.Hour >= 8 && aa.Hour < 20) + { + Program.Shift = "A班"; + Program.ProductDate = aa.ToString("yyyy-MM-dd"); + } + else + { + Program.Shift = "B班"; + if (aa.Hour >= 0 && aa.Hour < 8) + { + Program.ProductDate = aa.AddDays(-1).ToString("yyyy-MM-dd"); + //Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); + } + else + { + Program.ProductDate = aa.ToString("yyyy-MM-dd"); + //Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); + } + } + comboBox1.Text = Program.Shift; + textBox1.Text = Program.ProductDate.Substring(2, 2) + Program.ProductDate.Substring(5, 2) + + Program.ProductDate.Substring(8, 2); } + } } diff --git a/InjectionPC/FrmLogin.cs b/InjectionPC/FrmLogin.cs index bc493ca..baa6eb9 100644 --- a/InjectionPC/FrmLogin.cs +++ b/InjectionPC/FrmLogin.cs @@ -13,6 +13,7 @@ using System.Runtime.InteropServices; using MESClassLibrary.BLL.BasicInfo; using MESClassLibrary.Model; using MESClassLibrary.BLL.Log; +using MESClassLibrary.DAL; namespace InjectionPC { @@ -114,19 +115,20 @@ namespace InjectionPC public static void SetProductDate() { Program.interVal = Convert.ToInt32(ConfigurationManager.AppSettings["InterVal"].ToString()); - if (DateTime.Now.Hour >= 8 && DateTime.Now.Hour < 20) + DateTime serverTime = BasicDAL.GetServerTime(); + if (serverTime.Hour >= 8 && serverTime.Hour < 20) { Program.Shift = "A班"; - Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); + Program.ProductDate = serverTime.ToString("yyyy-MM-dd"); } else { Program.Shift = "B班"; - if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 8) + if (serverTime.Hour >= 0 && serverTime.Hour < 8) { - Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); + Program.ProductDate = serverTime.AddDays(-1).ToString("yyyy-MM-dd"); } - Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); + Program.ProductDate = serverTime.ToString("yyyy-MM-dd"); } } private bool OpenDb() diff --git a/InjectionSearch/FrmBarCodeSearchNew.cs b/InjectionSearch/FrmBarCodeSearchNew.cs index 787edc4..9cc5ad9 100644 --- a/InjectionSearch/FrmBarCodeSearchNew.cs +++ b/InjectionSearch/FrmBarCodeSearchNew.cs @@ -311,7 +311,7 @@ namespace InjectionSearch //sdt.Dispose(); #endregion - DialogResult result = MessageBox.Show("确定手工打印条码?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); + DialogResult result = MessageBox.Show($"确定手工打印批次为[{textBox3.Text}]的[{textBox4.Text}]个条码?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == DialogResult.OK) { #region 生成条码 diff --git a/MESClassLibrary/DAL/BasicDAL.cs b/MESClassLibrary/DAL/BasicDAL.cs index a3032bd..60e0e15 100644 --- a/MESClassLibrary/DAL/BasicDAL.cs +++ b/MESClassLibrary/DAL/BasicDAL.cs @@ -53,7 +53,7 @@ namespace MESClassLibrary.DAL /// 类型 /// 流水号长度 /// - public static string GetBillNo(string type, int len) + static string GetBillNo(string type, int len) { string sql = $"exec p_GetBillNo '{type}'"; @@ -88,5 +88,34 @@ namespace MESClassLibrary.DAL return GetSjBarCodeSerialNo(stockNo, batch); } } + public static DateTime GetServerTime() + { + string sql = ""; + DateTime time; + DataTable dt; + try + { + sql = @"select convert(char(23),getdate(),121) as time"; + + dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0]; + if (dt != null && dt.Rows.Count > 0) + { + //time = Convert.ToDateTime(dt.Rows[0]["time"].ToString()); + time = DateTime.ParseExact(dt.Rows[0]["time"].ToString(), "yyyy-MM-dd HH:mm:ss.fff", + System.Globalization.CultureInfo.CurrentCulture); + + } + else + { + time = DateTime.Now; + } + return time; + } + catch (Exception ex) + { + LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); + return DateTime.Now; + } + } } }