Browse Source

注塑打码,优化了系统时间.

master
ruoxing.wang 3 months ago
parent
commit
935d3ecff7
  1. 1
      InjectionPC/FrmBarCodeNew.Designer.cs
  2. 318
      InjectionPC/FrmBarCodeNew.cs
  3. 12
      InjectionPC/FrmLogin.cs
  4. 2
      InjectionSearch/FrmBarCodeSearchNew.cs
  5. 31
      MESClassLibrary/DAL/BasicDAL.cs

1
InjectionPC/FrmBarCodeNew.Designer.cs

@ -559,7 +559,6 @@
this.textBox3.TabIndex = 1; this.textBox3.TabIndex = 1;
this.textBox3.UseSystemPasswordChar = true; this.textBox3.UseSystemPasswordChar = true;
this.textBox3.Click += new System.EventHandler(this.textBox3_Click); this.textBox3.Click += new System.EventHandler(this.textBox3_Click);
this.textBox3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyDown);
// //
// label22 // label22
// //

318
InjectionPC/FrmBarCodeNew.cs

@ -72,31 +72,35 @@ namespace InjectionPC
initProduct(); initProduct();
initBarCode(); initBarCode();
DateTime aa = GetDateTime(); SetBatchText();
if (aa.Hour >= 8 && aa.Hour < 20) ////DateTime aa = GetDateTime();
{ //DateTime aa = BasicDAL.GetServerTime();
Program.Shift = "A班";
Program.ProductDate = aa.ToString("yyyy-MM-dd"); //if (aa.Hour >= 8 && aa.Hour < 20)
} //{
else // Program.Shift = "A班";
{ // Program.ProductDate = aa.ToString("yyyy-MM-dd");
Program.Shift = "B班"; //}
if (aa.Hour >= 0 && aa.Hour < 8) //else
{ //{
Program.ProductDate =aa.AddDays(-1).ToString("yyyy-MM-dd"); // Program.Shift = "B班";
//Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); // if (aa.Hour >= 0 && aa.Hour < 8)
} // {
else // Program.ProductDate =aa.AddDays(-1).ToString("yyyy-MM-dd");
{ // //Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
Program.ProductDate = aa.ToString("yyyy-MM-dd"); // }
//Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); // else
} // {
} // Program.ProductDate = aa.ToString("yyyy-MM-dd");
comboBox1.Text = Program.Shift; // //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) if (IsStart == false)
{ {
timer1.Enabled = false; timer1.Enabled = false;
@ -206,33 +210,11 @@ namespace InjectionPC
DataTable pdt3 = null; DataTable pdt3 = null;
SetBatchText();
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; //LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
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"));
try try
{ {
PingReply reply = p1.Send(Program.IP); //发送主机名或Ip地址 PingReply reply = p1.Send(Program.IP); //发送主机名或Ip地址
@ -841,13 +823,13 @@ namespace InjectionPC
timer1.Interval = Program.interVal; timer1.Interval = Program.interVal;
timer1.Start(); timer1.Start();
} }
void ReloadProduceDate() //void ReloadProduceDate()
{ //{
if (DateTime.Parse(Program.ProductDate).ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd")) // if (DateTime.Parse(Program.ProductDate).ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
{ // {
FrmLogin.SetProductDate(); // FrmLogin.SetProductDate();
} // }
} //}
private void label12_Click(object sender, EventArgs e) private void label12_Click(object sender, EventArgs e)
{ {
@ -964,7 +946,7 @@ namespace InjectionPC
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
#region 生成条码 #region 生成条码
SetBatchText();
ProductBLL pbll = new ProductBLL(); 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);
}
/// <summary> /// <summary>
/// 补打条码 /// 补打条码
/// </summary> /// </summary>
@ -1356,45 +1332,37 @@ namespace InjectionPC
} }
public DateTime GetDateTime() //public DateTime GetDateTime()
{ //{
string sql = ""; // string sql = "";
DateTime time; // DateTime time;
DataTable dt; // DataTable dt;
try // try
{ // {
sql = @"select convert(char(23),getdate(),121) as time"; // 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() // 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 ReportFetchRecord()
{
}
/// <summary> /// <summary>
/// 切换一下计划 /// 切换一下计划
@ -1515,64 +1483,6 @@ namespace InjectionPC
//Process.Start(@"C:\windows\system32\osk.exe"); //Process.Start(@"C:\windows\system32\osk.exe");
ShowInputPanel(); 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) private void button1_Click(object sender, EventArgs e)
{ {
if (textBox3.Text.Trim() != ConfigurationManager.AppSettings["Psw"]) if (textBox3.Text.Trim() != ConfigurationManager.AppSettings["Psw"])
@ -1585,13 +1495,13 @@ namespace InjectionPC
{ {
panel3.Visible = false; panel3.Visible = false;
textBox3.Text = ""; textBox3.Text = "";
string code = "",productName="", reportName=""; string code = "", productName = "", reportName = "";
BarCodeModel md = new BarCodeModel(); BarCodeModel md = new BarCodeModel();
BarCodeBLL bll = new BarCodeBLL(); BarCodeBLL bll = new BarCodeBLL();
ProductBLL pbll = new ProductBLL(); ProductBLL pbll = new ProductBLL();
try try
{ {
if (code_g=="") if (code_g == "")
{ {
MessageBox.Show("请选择要补打的条码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("请选择要补打的条码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return; return;
@ -1645,7 +1555,7 @@ namespace InjectionPC
row["StationNo"] = Program.station; row["StationNo"] = Program.station;
row["OneBarCode"] = md.OneBarCode; row["OneBarCode"] = md.OneBarCode;
row["BarCode"] = code_g; row["BarCode"] = code_g;
row["ProductName"] = productName+";"; row["ProductName"] = productName + ";";
row["IsImport"] = md.Import; row["IsImport"] = md.Import;
if (productName.Contains("右")) 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);
}
/// <summary>
/// 设置班组和批次
/// </summary>
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);
}
} }
} }

12
InjectionPC/FrmLogin.cs

@ -13,6 +13,7 @@ using System.Runtime.InteropServices;
using MESClassLibrary.BLL.BasicInfo; using MESClassLibrary.BLL.BasicInfo;
using MESClassLibrary.Model; using MESClassLibrary.Model;
using MESClassLibrary.BLL.Log; using MESClassLibrary.BLL.Log;
using MESClassLibrary.DAL;
namespace InjectionPC namespace InjectionPC
{ {
@ -114,19 +115,20 @@ namespace InjectionPC
public static void SetProductDate() public static void SetProductDate()
{ {
Program.interVal = Convert.ToInt32(ConfigurationManager.AppSettings["InterVal"].ToString()); 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.Shift = "A班";
Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd"); Program.ProductDate = serverTime.ToString("yyyy-MM-dd");
} }
else else
{ {
Program.Shift = "B班"; 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() private bool OpenDb()

2
InjectionSearch/FrmBarCodeSearchNew.cs

@ -311,7 +311,7 @@ namespace InjectionSearch
//sdt.Dispose(); //sdt.Dispose();
#endregion #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) if (result == DialogResult.OK)
{ {
#region 生成条码 #region 生成条码

31
MESClassLibrary/DAL/BasicDAL.cs

@ -53,7 +53,7 @@ namespace MESClassLibrary.DAL
/// <param name="type">类型</param> /// <param name="type">类型</param>
/// <param name="len">流水号长度</param> /// <param name="len">流水号长度</param>
/// <returns></returns> /// <returns></returns>
public static string GetBillNo(string type, int len) static string GetBillNo(string type, int len)
{ {
string sql = $"exec p_GetBillNo '{type}'"; string sql = $"exec p_GetBillNo '{type}'";
@ -88,5 +88,34 @@ namespace MESClassLibrary.DAL
return GetSjBarCodeSerialNo(stockNo, batch); 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;
}
}
} }
} }

Loading…
Cancel
Save