一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

504 lines
21 KiB

1 week ago
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using grproLib;
using PaintingPC.Model;
using PaintingPC.WebReference;
namespace PaintingPC
{
public delegate void buttonClick(object sender, EventArgs e);
public partial class FrmChainUp1 : Form
{
Interface1 ii = new Function();
//buttonClick bck;
//string CartypeID = "";
//string CartypeName = "";
//string ColorID = "";
//string ColorName = "";
public FrmChainUp1()
{
InitializeComponent();
}
public FrmChainUp1(string cartypeID, string cartypeName, string colorID, string colorName, buttonClick click,string productName,string color)
{
//CartypeID = cartypeID;
//CartypeName = cartypeName;
//ColorID = colorID;
//ColorName = colorName;
//bck = click;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//this.Close();
//bck(sender, e);
Environment.Exit(0);
}
private void FrmChainUp1_Load(object sender, EventArgs e)
{
//SqlParameter[] param = new SqlParameter[1];
//param[0] = new SqlParameter("@value", SqlDbType.VarChar);
//param[0].Value = "60000000582202060104";
//DataTable dtC = SqH.QueryDataSet(CommandType.StoredProcedure, "P_SYSTEM_FindData", param).Tables[0];
//if (dtC != null && dtC.Rows.Count > 0)
//{
// string aa = dtC.Rows[0]["columnname"].ToString();
//}
UpdateSoftware();
comboBox1.SelectedIndex = 0;
Control.CheckForIllegalCrossThreadCalls = false;
//if (!string.IsNullOrWhiteSpace(CartypeName) && !string.IsNullOrWhiteSpace(ColorName))
//{
// //label2.Text = CartypeName + " - " + ColorName;
//}
btOK.Visible = ConfigurationManager.AppSettings["IsShowOK"] == "1" ? true : false;
label3.Text = Function.GetWorkClass();
Task task1 = Task.Run(() =>
{
SetPageNum();
});
DataTable dt = Function.GetChainCountLabel();
if (dt != null && dt.Rows.Count > 0)
{
ii.IInitPanel(panel7, 200, 170, dt, "colDes", "num", dLbLable_Click,"","");
}
textBox1.Focus();
timer1.Enabled = true;
timer1.Start();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (ConfigurationManager.AppSettings["IsShowOK"] != "1")
{
if (e.KeyCode == Keys.Enter)
{
TextBox txt = (TextBox) textBox1;
string barcode = txt.Text.Trim();
string carTypeName = "";
//label6.Text = Function.GetProductInfo(barcode);
string[] str = Function.GetProductInfo(barcode).Split(',');
label6.Text = str[0] + ',' + str[1];
if (!string.IsNullOrWhiteSpace(label6.Text))
{
string[] ss = label6.Text.Split(',');
if (ss.Length >= 1)
{
if (string.IsNullOrWhiteSpace(ss[0]))
{
FrmMessage message = new FrmMessage("无颜色信息,请重新扫描", System.Drawing.Color.Yellow);
message.Owner = this; // 设置Form2的所有者为Form1
message.ShowDialog();
textBox1.SelectAll();
return;
//MessageBox.Show("无颜色信息,请重新扫描");
//textBox1.SelectAll();
//return;
}
}
else
{
MessageBox.Show("条码有误,请重新扫描");
textBox1.SelectAll();
return;
}
}
if (Function.ChainHaveScan(barcode))
{
FrmMessage message = new FrmMessage("已经扫描过,不允许再次扫描",System.Drawing.Color.White);
message.ShowDialog();
textBox1.SelectAll();
return;
//MessageBox.Show("已经扫描过,不允许再次扫描");
//textBox1.SelectAll();
//return;
}
#region 获取最后一次判定结果并存储质检结果
string InspectResult = "";
InspectModel model1 = new InspectModel();
model1.barcode = Function.UniteBarCodeToOne(barcode);
//model1.position = ConfigurationManager.AppSettings["Position"];
model1.stationNo = ConfigurationManager.AppSettings["Station"];
model1.workClass = label3.Text;
model1.InspectTimes = (Function.GetInspectTimes(barcode) + 1).ToString();
//string []weizhi= Function.GetSide(barcode).Split(';');
DataTable dt = Function.GetLastResult(barcode);
if (dt != null && dt.Rows.Count > 0)
{
string a = dt.Rows[0]["inspectResult"].ToString();
InspectResult = "[" + a.Substring(1, a.Length - 2) + "合格" + "]";
model1.productOption = dt.Rows[0]["productOption"].ToString();
model1.position = dt.Rows[0]["position"].ToString();
model1.side = dt.Rows[0]["side"].ToString();
}
else
{
InspectResult = "[合格]";
model1.productOption = "1";
string[] info = Function.GetProductInfo(barcode).Split(',');
string[] side = Function.GetSide(model1.barcode, info[2]).Split(';');
model1.position = "下线一检 " + side[0] + " " + side[1];
model1.side = side[0];
}
model1.inspectResult = InspectResult;
model1.productInfo = label6.Text;
Function.InsertInspect(model1);
#endregion
string color = str[0];
carTypeName = Function.carTypeName(barcode.Substring(0, 10), str[2]);
#region 判断是否为北京现代产品
//if (Function.IsHyundai(Function.UniteBarCodeToOne(barcode)))
//{
// #region 打印合格签
// string filename = Application.StartupPath + @"\barcode.grf";
// string productName = "",
// customerNo = "",
// carModelCode = "",
// colorCodeB = "",
// templateName = "",
// fr = "",
// seq = "",
// reportName = "", partNo="",tempCode="";
// Function.GetHyundyPrintInfo(barcode.Substring(0, 10), str[2], out productName, out customerNo,
// out carModelCode, out colorCodeB, out templateName, out fr,out partNo);
// seq = Function.GetSequence();
// DataTable headTable = new DataTable();
// headTable.Columns.Add("P");
// headTable.Columns.Add("Color");
// headTable.Columns.Add("StockNo");
// headTable.Columns.Add("PartNo");
// headTable.Columns.Add("ProductName");
// headTable.Columns.Add("BarCode");
// headTable.Columns.Add("carModelCode");
// headTable.Columns.Add("templateName");
// DataRow row = headTable.NewRow();
// row["P"] = "P" + comboBox1.Text.Trim();
// row["Color"] = color;
// row["StockNo"] = barcode.Substring(0, 10);
// row["PartNo"] = partNo;
// row["ProductName"] = productName;
// if (partNo== "86612-BU510PSB")
// {
// tempCode = "C3PS" + DateTime.Now.ToString("yyMMdd") + seq.PadLeft(4, '0');
// }
// else if (partNo == "86612-BU700EB")
// {
// tempCode = "C2EB" + DateTime.Now.ToString("yyMMdd") + seq.PadLeft(4, '0');
// }
// else
// {
// tempCode = "P" + DateTime.Now.ToString("yyMMdd") + seq.PadLeft(4, '0') + customerNo + fr + colorCodeB;
// }
// row["BarCode"] = tempCode;
// row["carModelCode"] = carModelCode;
// row["templateName"] = templateName;
// headTable.Rows.Add(row);
// reportName = ConfigurationManager.AppSettings["PrinterName"];
// ReportHelper rp = new ReportHelper(filename, headTable, null,
// (int) GRPaperOrientation.grpoDefault, 1, reportName);
// rp.Report.Print(false);
// #endregion
// Function.SaveSeq(barcode, "",tempCode, seq.PadLeft(4, '0'));
//}
#endregion
Function.SaveChainUp(barcode, "", carTypeName, "", color, "0", str[1]);
SetPageNum();
DataTable dt1 = Function.GetChainCountLabel();
if (dt1 != null && dt1.Rows.Count > 0)
{
ii.IInitPanel(panel7, 200, 170, dt1, "colDes", "num", dLbLable_Click, str[1], color);
}
#region 调用WMS合格入库接口
try
{
//WMSWebService webService = new WMSWebService();
//webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"];
//webService.WMSSprayingForApp(textBox1.Text.Trim());
}
catch (Exception ex)
{
LogHelper.WriteErrLogBase("喷涂入库调用WMS接口:" + ex, MethodBase.GetCurrentMethod().Name);
}
#endregion
textBox1.SelectAll();
}
}
}
catch (Exception ex)
{
textBox1.SelectAll();
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
}
}
private void SetPageNum()
{
label4.Text = Function.GetChainCountAll();
label5.Text = Function.GetChainCountDown();
}
void dLbLable_Click(object sender, EventArgs e)
{ }
private void timer1_Tick(object sender, EventArgs e)
{
SetPageNum();
}
private void UpdateSoftware()
{
var serverUrl = "http://10.60.101.59:8013/";
var updateXmlFileName = "PaintingUpdateXGL.xml";
var updater = new AutoUpdater();
if (updater.CheckUpdateLoad(serverUrl, updateXmlFileName))
{
Environment.Exit(0);
}
}
private void btOK_Click(object sender, EventArgs e)
{
try
{
TextBox txt = (TextBox)textBox1;
string barcode = txt.Text.Trim();
string carTypeName = "";
string[] str = Function.GetProductInfo(barcode).Split(',');
label6.Text = str[0] + ',' + str[1];
//label6.Text = Function.GetProductInfo(barcode);
if (!string.IsNullOrWhiteSpace(label6.Text))
{
string[] ss = label6.Text.Split(',');
if (ss.Length >= 1)
{
if (string.IsNullOrWhiteSpace(ss[0]))
{
//MessageBox.Show("无颜色信息,不允许扫描");
//textBox1.SelectAll();
//return;
FrmMessage message = new FrmMessage("无颜色信息,请重新扫描", System.Drawing.Color.Yellow);
message.Owner = this; // 设置Form2的所有者为Form1
message.ShowDialog();
textBox1.SelectAll();
return;
}
}
}
if (Function.ChainHaveScan(barcode))
{
//MessageBox.Show("已经扫描过,不允许再次扫描");
//textBox1.SelectAll();
//return;
FrmMessage message = new FrmMessage("已经扫描过,不允许再次扫描", System.Drawing.Color.White);
message.Owner = this; // 设置Form2的所有者为Form1
message.ShowDialog();
textBox1.SelectAll();
return;
}
#region 获取最后一次判定结果并存储质检结果
string InspectResult = "";
InspectModel model1 = new InspectModel();
model1.barcode = Function.UniteBarCodeToOne(barcode);
model1.position = ConfigurationManager.AppSettings["Position"];
model1.stationNo = ConfigurationManager.AppSettings["Station"];
model1.workClass = label3.Text;
model1.InspectTimes = (Function.GetInspectTimes(barcode) + 1).ToString();
DataTable dt = Function.GetLastResult(barcode);
if (dt != null && dt.Rows.Count > 0)
{
string a = dt.Rows[0]["inspectResult"].ToString();
InspectResult = "[" + a.Substring(1, a.Length - 2) + "合格" + "]";
model1.productOption = dt.Rows[0]["productOption"].ToString();
model1.side = dt.Rows[0]["side"].ToString();
}
else
{
InspectResult = "[合格]";
model1.productOption = "1";
string[] info = Function.GetProductInfo(barcode).Split(',');
model1.side = Function.GetSide(barcode, info[2]);
}
model1.inspectResult = InspectResult;
model1.productInfo = label6.Text;
Function.InsertInspect(model1);
#endregion
string[] cols = label6.Text.Split(',');
string color = cols[0];
carTypeName = Function.carTypeName(barcode.Substring(0,10), str[2]);
#region 判断是否为北京现代产品
if (Function.IsHyundai(Function.UniteBarCodeToOne(barcode)))
{
//#region 打印合格签
//string filename = Application.StartupPath + @"\barcode.grf";
//string productName = "",
// customerNo = "",
// carModelCode = "",
// colorCodeB = "",
// templateName = "",
// fr = "",
// seq = "",
// reportName = "", partNo = "", tempCode = "";
//Function.GetHyundyPrintInfo(barcode.Substring(0, 10), str[2], out productName, out customerNo,
// out carModelCode, out colorCodeB, out templateName, out fr, out partNo);
//seq = Function.GetSequence();
//DataTable headTable = new DataTable();
//headTable.Columns.Add("P");
//headTable.Columns.Add("Color");
//headTable.Columns.Add("StockNo");
//headTable.Columns.Add("PartNo");
//headTable.Columns.Add("ProductName");
//headTable.Columns.Add("BarCode");
//headTable.Columns.Add("carModelCode");
//headTable.Columns.Add("templateName");
//DataRow row = headTable.NewRow();
//row["P"] = "P" + comboBox1.Text.Trim();
//row["Color"] = color;
//row["StockNo"] = barcode.Substring(0, 10);
//row["PartNo"] = partNo;
//row["ProductName"] = productName;
//if (partNo == "86612-BU510PSB")
//{
// tempCode = "C3PS" + DateTime.Now.ToString("yyMMdd") + seq.PadLeft(4, '0');
//}
//else if (partNo == "86612-BU700EB")
//{
// tempCode = "C2EB" + DateTime.Now.ToString("yyMMdd") + seq.PadLeft(4, '0');
//}
//else
//{
// tempCode = "P" + DateTime.Now.ToString("yyMMdd") + seq.PadLeft(4, '0') + customerNo + fr + colorCodeB;
//}
//row["BarCode"] = tempCode;
//row["carModelCode"] = carModelCode;
//row["templateName"] = templateName;
//headTable.Rows.Add(row);
//reportName = ConfigurationManager.AppSettings["PrinterName"];
//ReportHelper rp = new ReportHelper(filename, headTable, null,
// (int)GRPaperOrientation.grpoDefault, 1, reportName);
//rp.Report.Print(false);
//#endregion
//Function.SaveSeq(barcode, "", tempCode, seq.PadLeft(4, '0'));
}
#endregion
string[] xx = label6.Text.Split(',');
Function.SaveChainUp(barcode, "", carTypeName, "", color, "0", xx[1]);
SetPageNum();
DataTable dt1 = Function.GetChainCountLabel();
if (dt1 != null && dt1.Rows.Count > 0)
{
ii.IInitPanel(panel7, 200, 170, dt1, "colDes", "num", dLbLable_Click, xx[1],color);
}
#region 调用WMS合格入库接口
try
{
//WMSWebService webService = new WMSWebService();
//webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"];
//webService.WMSSprayingForApp(textBox1.Text.Trim());
}
catch (Exception ex)
{
LogHelper.WriteErrLogBase("喷涂入库调用WMS接口:" + ex, MethodBase.GetCurrentMethod().Name);
}
#endregion
textBox1.SelectAll();
}
catch (Exception ex)
{
textBox1.SelectAll();
LogHelper.WriteErrLogBase(ex.ToString(),MethodBase.GetCurrentMethod().Name);
}
}
public void UpdateTextState()
{
// 这里可以安全地访问Form1上的控件
textBox1.SelectAll();
textBox1.Focus();
}
}
}