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.
1673 lines
60 KiB
1673 lines
60 KiB
2 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel;
|
||
|
using System.Configuration;
|
||
|
using System.Data;
|
||
|
using System.Drawing;
|
||
|
using System.Linq;
|
||
|
using System.Reflection;
|
||
|
using System.Text;
|
||
|
using System.Threading;
|
||
|
using System.Web.Services;
|
||
|
using System.Windows.Forms;
|
||
|
using foda;
|
||
|
using FacOneZPStation.WebReference;
|
||
|
using grproLib;
|
||
|
using InjectionPC;
|
||
|
using MESClassLibrary.BLL.BasicInfo;
|
||
|
using MESClassLibrary.BLL.Log;
|
||
|
using MESClassLibrary.BLL.Painting;
|
||
|
using MESClassLibrary.BLL.ZPPlan;
|
||
|
using MESClassLibrary.DAL;
|
||
|
using MESClassLibrary.EFModel;
|
||
|
using MESClassLibrary.Model;
|
||
|
using OPCAutomation;
|
||
|
|
||
|
namespace FacOneZPStation
|
||
|
{
|
||
|
public partial class FrmZP : Form
|
||
|
{
|
||
|
public FrmZP()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
|
||
|
#region 变量
|
||
|
|
||
|
private string strHostIP;
|
||
|
private string strHostName;
|
||
|
private OPCServer opcServer;
|
||
|
private OPCGroups opcGroups;
|
||
|
private OPCGroup opcGroup1;
|
||
|
private OPCItems opcItems1;
|
||
|
private OPCItem[] opcItemm1;
|
||
|
|
||
|
private OPCGroup opcGroup2;
|
||
|
private OPCItems opcItems2;
|
||
|
private OPCItem[] opcItemm2;
|
||
|
private string[] ItemIDs;
|
||
|
object ItemValues;
|
||
|
object Qualities;
|
||
|
object TimeStamps;
|
||
|
public bool Connected = false;
|
||
|
|
||
|
public bool IsOK = false;
|
||
|
public static string planID = "";
|
||
|
public string ID = "";
|
||
|
public static string PartNo = "";
|
||
|
public int stateOK = 0;
|
||
|
|
||
|
private string stationID = "";
|
||
|
private int step = 0, maxStep = 0,currentStep=0;
|
||
|
private bool IsLast = false, IsPhoto = false;
|
||
|
int IsHigh = 0;
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
private void FrmZP_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var serverUrl = "http://10.60.101.59:8013/";
|
||
|
var updateXmlFileName = "ZPUpdate.xml";
|
||
|
var updater = new AutoUpdater();
|
||
|
if (updater.CheckUpdateLoad(serverUrl, updateXmlFileName))
|
||
|
{
|
||
|
Environment.Exit(0);
|
||
|
}
|
||
|
|
||
|
Control.CheckForIllegalCrossThreadCalls = false;
|
||
|
|
||
|
|
||
|
timer1.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["InterVal"]);
|
||
|
labErrMessage.Text = "";
|
||
|
Thread t = new Thread(new ThreadStart(TimeGo));
|
||
|
t.Start();
|
||
|
labStationNo.Text = ConfigurationManager.AppSettings["StationNo"];
|
||
|
|
||
|
StationBLL sbll = new StationBLL();
|
||
|
DataTable sdt = sbll.SearchInfoByNo(labStationNo.Text);
|
||
|
if (sdt != null && sdt.Rows.Count > 0)
|
||
|
{
|
||
|
stationID = sdt.Rows[0]["StationID"].ToString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
stationID = "";
|
||
|
}
|
||
|
|
||
|
initPlan();
|
||
|
|
||
|
ControlButton(labPartNo.Text, currentStep + maxStep - 1);
|
||
|
textBox1.Text = "";
|
||
|
textBox2.Text = "";
|
||
|
textBox1.Enabled = true;
|
||
|
textBox2.Enabled = false;
|
||
|
textBox1.Focus();
|
||
|
|
||
|
#region 判断当前工位是否有拍照
|
||
|
|
||
|
ZPBomBLL bbll = new ZPBomBLL();
|
||
|
DataTable dt2 = bbll.SearchStep(labPartNo.Text, labStationNo.Text);
|
||
|
if (dt2 != null && dt2.Rows.Count > 0)
|
||
|
{
|
||
|
for (int i = 0; i < dt2.Rows.Count; i++)
|
||
|
{
|
||
|
if (Convert.ToInt32(dt2.Rows[i]["IsPhoto"]) == 1)
|
||
|
{
|
||
|
IsPhoto = true;
|
||
|
break;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
IsPhoto = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
maxStep = 0;
|
||
|
IsPhoto = false;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
if (IsPhoto)
|
||
|
{
|
||
|
#region 加载opc
|
||
|
|
||
|
ZPTagBLL bll = new ZPTagBLL();
|
||
|
if (CreateServer())
|
||
|
{
|
||
|
if (ConnectServer(strHostIP, "Kepware.KEPServerEX.V6"))
|
||
|
{
|
||
|
Connected = true;
|
||
|
|
||
|
#region 创建组
|
||
|
|
||
|
opcGroups = opcServer.OPCGroups;
|
||
|
opcGroup1 = opcGroups.Add("Read");
|
||
|
opcGroup2 = opcGroups.Add("Write");
|
||
|
SetGroupProperty(opcGroup1, 500);
|
||
|
SetGroupProperty(opcGroup2, 500);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 创建项Read
|
||
|
|
||
|
opcItems1 = opcGroup1.OPCItems;
|
||
|
opcItems1.DefaultIsActive = true;
|
||
|
|
||
|
DataTable dt = bll.SearchRead(labStationNo.Text);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
opcItemm1 = new OPCItem[dt.Rows.Count];
|
||
|
for (int i = 0; i < dt.Rows.Count; i++)
|
||
|
{
|
||
|
opcItemm1[i] = opcItems1.AddItem(dt.Rows[i]["TagName"].ToString(), i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 创建项Write
|
||
|
|
||
|
opcItems2 = opcGroup2.OPCItems;
|
||
|
opcItems2.DefaultIsActive = true;
|
||
|
|
||
|
DataTable dt1 = bll.SearchWrite(labStationNo.Text);
|
||
|
if (dt1 != null && dt1.Rows.Count > 0)
|
||
|
{
|
||
|
opcItemm2 = new OPCItem[dt1.Rows.Count];
|
||
|
for (int i = 0; i < dt1.Rows.Count; i++)
|
||
|
{
|
||
|
opcItemm2[i] = opcItems2.AddItem(dt1.Rows[i]["TagName"].ToString(), i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
opcGroup1.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(opcGroup1_DataChange);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
LoadStep();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#region 刷新时间
|
||
|
|
||
|
private void TimeGo()
|
||
|
{
|
||
|
System.Timers.Timer timer = new System.Timers.Timer();
|
||
|
timer.Interval = 1000;
|
||
|
timer.Enabled = true;
|
||
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
|
||
|
}
|
||
|
|
||
|
private void timer_Tick(object sender, EventArgs e)
|
||
|
{
|
||
|
labTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
Thread.Sleep(500);
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
public void initPlan()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ZPPlanBLL bll = new ZPPlanBLL();
|
||
|
ZPBomBLL bbll = new ZPBomBLL();
|
||
|
|
||
|
labStationNo.Text = ConfigurationManager.AppSettings["StationNo"];
|
||
|
|
||
|
DataTable dt = bll.GetProductingPlan(labStationNo.Text);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
planID = dt.Rows[0]["ID"].ToString();
|
||
|
labOrderNo.Text = dt.Rows[0]["OrderNo"].ToString();
|
||
|
labPartNo.Text = dt.Rows[0]["PartNo"].ToString();
|
||
|
PartNo = labPartNo.Text;
|
||
|
labPName.Text = dt.Rows[0]["ProductName"].ToString();
|
||
|
labNum.Text = dt.Rows[0]["ProductCount"] + "/" + dt.Rows[0]["OrderCount"];
|
||
|
labBadCount.Text = dt.Rows[0]["BadCount"].ToString();
|
||
|
this.Tag = dt.Rows[0]["CreateTime"].ToString();
|
||
|
IsHigh = dt.Rows[0]["IsHigh"].ToString() == "1" ? 1 : 0;
|
||
|
|
||
|
labErrMessage.Text = "";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
labOrderNo.Text = "";
|
||
|
labPartNo.Text = ""; ;
|
||
|
labPName.Text = ""; ;
|
||
|
labNum.Text = "0/0";
|
||
|
labBadCount.Text = "0";
|
||
|
|
||
|
this.Tag = "";
|
||
|
labErrMessage.Text = "没有生产计划,请联系计划员!";
|
||
|
}
|
||
|
|
||
|
Program.partNo1 = labPartNo.Text;
|
||
|
|
||
|
#region 获取当前工位的总步骤数
|
||
|
|
||
|
DataTable dt3 = bbll.SearchStep(labPartNo.Text, labStationNo.Text);
|
||
|
if (dt3 != null && dt3.Rows.Count > 0)
|
||
|
{
|
||
|
maxStep = dt3.Rows.Count;
|
||
|
currentStep = Convert.ToInt32(dt3.Rows[0]["Step"]);
|
||
|
textBox1.Enabled = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
maxStep = 0;
|
||
|
IsOK = false;
|
||
|
//MessageBox.Show("该产品在本工位没有步骤!", "提示", MessageBoxButtons.OK);
|
||
|
textBox1.Enabled = false;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据产品判断当前工位是不是最后一步,是则显示打印标签等按钮
|
||
|
/// </summary>
|
||
|
/// <param name="partNo"></param>
|
||
|
private void ControlButton(string partNo, int step)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ZPBomBLL bll = new ZPBomBLL();
|
||
|
|
||
|
bool flag = bll.IsLast(partNo, step);
|
||
|
if (!flag || string.IsNullOrEmpty(partNo))
|
||
|
{
|
||
|
button1.Visible = false;
|
||
|
button2.Visible = false;
|
||
|
button5.Visible = false;
|
||
|
button6.Visible = false;
|
||
|
button7.Visible = false;
|
||
|
IsLast = false;
|
||
|
timer1.Enabled = false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
button1.Visible = true;
|
||
|
button2.Visible = true;
|
||
|
button5.Visible = true;
|
||
|
button6.Visible = true;
|
||
|
button7.Visible = true;
|
||
|
IsLast = true;
|
||
|
timer1.Enabled = false;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void LoadStep()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ZPStepRecordBLL bll = new ZPStepRecordBLL();
|
||
|
ZPBomBLL bbll = new ZPBomBLL();
|
||
|
|
||
|
#region 获取当前步骤
|
||
|
|
||
|
DataTable dt = bll.SearchStepByStation(labStationNo.Text, planID, textBox1.Text.Trim());
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
step = dt.Rows.Count;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
step = 0;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
if (maxStep == 0)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (step >= maxStep)
|
||
|
{
|
||
|
step = 0;
|
||
|
textBox1.Text = "";
|
||
|
textBox2.Text = "";
|
||
|
textBox1.Enabled = true;
|
||
|
textBox2.Enabled = false;
|
||
|
textBox1.Focus();
|
||
|
}
|
||
|
|
||
|
#region 获取下一步的信息
|
||
|
|
||
|
DataTable dt2 = bbll.SearchInfoByStep(labStationNo.Text, labPartNo.Text, currentStep+ step );
|
||
|
if (dt2 != null && dt2.Rows.Count > 0)
|
||
|
{
|
||
|
if (Convert.ToInt32(dt2.Rows[0]["IsPhoto"]) == 1)
|
||
|
{
|
||
|
#region 给相机发信号
|
||
|
|
||
|
opcItemm2[1].Write(Convert.ToInt32(dt2.Rows[0]["ProgramNo"])); //程序号
|
||
|
opcItemm2[0].Write(1); //相机启动信号
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
labErrMessage.Text = "拍照";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
labErrMessage.Text = "扫描" + dt2.Rows[0]["MaterialNo"];
|
||
|
if (step == 0)
|
||
|
{
|
||
|
textBox1.Enabled = true;
|
||
|
textBox2.Enabled = false;
|
||
|
textBox1.Text = "";
|
||
|
textBox2.Text = "";
|
||
|
textBox1.Focus();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
textBox1.Enabled = false;
|
||
|
textBox2.Enabled = true;
|
||
|
textBox2.Text = "";
|
||
|
textBox2.Focus();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
labErrMessage.Text = "";
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private bool CreateServer()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
opcServer = new OPCServer();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 连接到服务器
|
||
|
/// </summary>
|
||
|
/// <param name="strHostIP"></param>
|
||
|
/// <param name="strHostName"></param>
|
||
|
/// <returns></returns>
|
||
|
private bool ConnectServer(string strHostIP, string strHostName)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
opcServer.Connect(strHostName, strHostIP);
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
private void SetGroupProperty(OPCGroup opcGroup, int updateRate)
|
||
|
{
|
||
|
opcGroup.IsActive = true;
|
||
|
opcGroup.DeadBand = 0;
|
||
|
opcGroup.UpdateRate = updateRate;
|
||
|
opcGroup.IsSubscribed = true;
|
||
|
}
|
||
|
|
||
|
void opcGroup1_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues,
|
||
|
ref Array Qualities, ref Array TimeStamps)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
for (int i = 1; i <= NumItems; i++)
|
||
|
{
|
||
|
int handle = Convert.ToInt32(ClientHandles.GetValue(i).ToString().Trim());
|
||
|
string value = ItemValues.GetValue(i).ToString();
|
||
|
string address = opcItemm1[(Convert.ToInt32(ClientHandles.GetValue(i)))].ItemID;
|
||
|
int isOK = 0;
|
||
|
|
||
|
if (handle == 0)
|
||
|
{
|
||
|
if (value.ToLower() == "true")
|
||
|
{
|
||
|
ZPStepRecordBLL bll = new ZPStepRecordBLL();
|
||
|
ZPRecordBLL rbll = new ZPRecordBLL();
|
||
|
ZPBomBLL bombll = new ZPBomBLL();
|
||
|
tb_ZPStepRecord md = new tb_ZPStepRecord();
|
||
|
tb_ZPRecord rmd = new tb_ZPRecord();
|
||
|
ScanRecordBLL sbll = new ScanRecordBLL();
|
||
|
tb_ScanRecord smd = new tb_ScanRecord();
|
||
|
|
||
|
#region 读取结果值
|
||
|
|
||
|
isOK = ReadSingleValueFromOPC2(1);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 给相机发送读结果完成
|
||
|
|
||
|
opcItemm2[2].Write(1);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
if (isOK == 1)
|
||
|
{
|
||
|
|
||
|
if (step < maxStep)
|
||
|
{
|
||
|
#region 存步骤信息
|
||
|
|
||
|
md.BarCode = textBox1.Text.Trim();
|
||
|
md.StationID = stationID;
|
||
|
md.Step = currentStep + step;
|
||
|
md.IsOK = 1;
|
||
|
md.CreateTime = DateTime.Now;
|
||
|
md.PlanID = planID;
|
||
|
|
||
|
bll.AddInfo(md);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 存本体扫描记录
|
||
|
|
||
|
smd.BarCode = textBox1.Text.Trim();
|
||
|
smd.CreateTime = DateTime.Now;
|
||
|
smd.StationID = stationID;
|
||
|
|
||
|
sbll.AddInfo(smd);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
|
||
|
if (step == maxStep && IsLast)
|
||
|
{
|
||
|
#region 存装配记录
|
||
|
|
||
|
rmd.OneBarCode = textBox1.Text.Trim();
|
||
|
rmd.PlanID = planID;
|
||
|
|
||
|
rbll.AddInfo(rmd);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
textBox1.Text = "";
|
||
|
textBox2.Text = "";
|
||
|
textBox1.Focus();
|
||
|
}
|
||
|
LoadStep();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void textBox1_KeyDown(object sender, KeyEventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (e.KeyCode == Keys.Enter)
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(textBox1.Text))
|
||
|
{
|
||
|
labErrMessage.Text = "扫描本体";
|
||
|
MessageBox.Show("本体条码为空!", "提示", MessageBoxButtons.OK);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
ZPStepRecordBLL bll = new ZPStepRecordBLL();
|
||
|
ZPRecordBLL rbll=new ZPRecordBLL();
|
||
|
ZPBomBLL bombll=new ZPBomBLL();
|
||
|
BarCodeBLL barbll = new BarCodeBLL();
|
||
|
ScanRecordBLL sbll = new ScanRecordBLL();
|
||
|
StockInBLL inbll=new StockInBLL();
|
||
|
PaintColorBLL pcbll=new PaintColorBLL();
|
||
|
ProductBLL pbll = new ProductBLL();
|
||
|
InspectResultBLL irbll=new InspectResultBLL();
|
||
|
tb_ZPStepRecord md=new tb_ZPStepRecord();
|
||
|
tb_ZPRecord rmd=new tb_ZPRecord();
|
||
|
tb_ScanRecord smd=new tb_ScanRecord();
|
||
|
string barCode = "",paintCode="";
|
||
|
|
||
|
int IsBox = 0; //0是箱单1是单个条码
|
||
|
|
||
|
#region 判断是一维码还是二维码
|
||
|
|
||
|
if (textBox1.Text.Trim().Contains('.')) //二维码
|
||
|
{
|
||
|
string[] aa = textBox1.Text.Split('.');
|
||
|
Program.partNo = aa[0];
|
||
|
|
||
|
#region 根据二维码查找一维码
|
||
|
|
||
|
DataTable dt4 = barbll.searchBarCode(textBox1.Text.Trim(), 2);
|
||
|
if (dt4 != null && dt4.Rows.Count > 0)
|
||
|
{
|
||
|
barCode = dt4.Rows[0]["OneBarCode"].ToString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("条码有误,请重新扫描!", "提示", MessageBoxButtons.OK);
|
||
|
textBox1.SelectAll();
|
||
|
textBox1.Focus();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
barCode = textBox1.Text.Trim();
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 判断之前工位步骤是否都完成,无需校验
|
||
|
|
||
|
//if (!string.IsNullOrEmpty(barCode))
|
||
|
//{
|
||
|
// int bStep = bll.CompleteStep(textBox1.Text.Trim());
|
||
|
// if (bStep < currentStep - 1)
|
||
|
// {
|
||
|
// labErrMessage.Text = "在此之前有未完成的步骤";
|
||
|
// IsOK = false;
|
||
|
// MessageBox.Show("在此之前有未完成的步骤!", "提示", MessageBoxButtons.OK);
|
||
|
// textBox1.SelectAll();
|
||
|
// textBox1.Focus();
|
||
|
// return;
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
DataTable fdt = bll.SearchStepByStation(labStationNo.Text, planID, textBox1.Text.Trim());
|
||
|
if (fdt != null && fdt.Rows.Count > 0)
|
||
|
{
|
||
|
step = fdt.Rows.Count;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
step = 0;
|
||
|
}
|
||
|
|
||
|
if (step >= maxStep)
|
||
|
{
|
||
|
MessageBox.Show("条码" + barCode + "在本工位已生产完成!", "提示", MessageBoxButtons.OK);
|
||
|
textBox1.Text = "";
|
||
|
textBox1.Focus();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
#region 根据入库或质检表查找对应的颜色,如果没有,查质检信息的最后一条信息,拼接颜色
|
||
|
|
||
|
DataTable pdt = inbll.SearchColorByBarCode(barCode);
|
||
|
if (pdt != null && pdt.Rows.Count > 0)
|
||
|
{
|
||
|
paintCode = pdt.Rows[0]["paintCode"].ToString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DataTable irdt = irbll.SearchColorByBarCode(barCode);
|
||
|
if (irdt != null && irdt.Rows.Count > 0)
|
||
|
{
|
||
|
paintCode = pcbll.paintColor(barCode.Substring(0, 10), irdt.Rows[0]["remark1"].ToString());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
#region 判断是否为塑件,如果是塑件,paintcode为塑件零件号
|
||
|
|
||
|
if (barCode.Length > 0)
|
||
|
{
|
||
|
DataTable sdt = pbll.SearchInfoByStock(barCode.Substring(0, 10));
|
||
|
if (sdt != null && sdt.Rows.Count > 0)
|
||
|
{
|
||
|
paintCode = sdt.Rows[0]["PartNo"].ToString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
if (CheckPart(bombll, paintCode, sbll, bll, md, smd, rmd, rbll)) return;
|
||
|
|
||
|
//MessageBox.Show("条码" + barCode + "没有颜色信息!", "提示", MessageBoxButtons.OK);
|
||
|
//textBox1.Text = "";
|
||
|
//textBox1.Focus();
|
||
|
//return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private bool CheckPart(ZPBomBLL bombll, string paintCode, ScanRecordBLL sbll, ZPStepRecordBLL bll, tb_ZPStepRecord md,
|
||
|
tb_ScanRecord smd, tb_ZPRecord rmd, ZPRecordBLL rbll)
|
||
|
{
|
||
|
int IsBox;
|
||
|
|
||
|
#region 校验是否和计划匹配
|
||
|
|
||
|
DataTable dt = bombll.IsMath(ConfigurationManager.AppSettings["StationNo"], labPartNo.Text.Trim(), paintCode,
|
||
|
currentStep);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
#region 是否需要检验单个条码
|
||
|
|
||
|
IsBox = Convert.ToInt32(dt.Rows[0]["IsScanCode"]);
|
||
|
if (IsBox == 0)
|
||
|
{
|
||
|
//TODO 无需校验
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//TODO 校验条码是否用过
|
||
|
|
||
|
if (sbll.IsScan(textBox1.Text.Trim(), stationID) > 0)
|
||
|
{
|
||
|
MessageBox.Show("此条码条码使用过,请更换物料!", "提示", MessageBoxButtons.OK);
|
||
|
textBox1.SelectAll();
|
||
|
textBox1.Text = "";
|
||
|
textBox1.Focus();
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
#region 判断当前物料是否在本工位是否扫描过
|
||
|
|
||
|
if (bll.isScan(textBox1.Text.Trim(), stationID, currentStep) == 0)
|
||
|
{
|
||
|
#region 存步骤信息
|
||
|
|
||
|
md.BarCode = textBox1.Text.Trim();
|
||
|
md.StationID = stationID;
|
||
|
md.Step = currentStep + step;
|
||
|
md.IsOK = 1;
|
||
|
md.CreateTime = DateTime.Now;
|
||
|
md.PlanID = planID;
|
||
|
|
||
|
bll.AddInfo(md);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
if (step == maxStep && IsLast)
|
||
|
{
|
||
|
#region 存扫描记录
|
||
|
|
||
|
smd.BarCode = textBox1.Text.Trim();
|
||
|
smd.CreateTime = DateTime.Now;
|
||
|
smd.StationID = stationID;
|
||
|
|
||
|
sbll.AddInfo(smd);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 存装配记录
|
||
|
|
||
|
rmd.OneBarCode = textBox1.Text.Trim();
|
||
|
rmd.PlanID = planID;
|
||
|
|
||
|
rbll.AddInfo(rmd);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
LoadStep();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
labErrMessage.Text = "本体和计划不匹配";
|
||
|
MessageBox.Show("本体和计划不匹配!", "提示", MessageBoxButtons.OK);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
private void textBox2_KeyDown(object sender, KeyEventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (e.KeyCode == Keys.Enter)
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(textBox2.Text))
|
||
|
{
|
||
|
|
||
|
MessageBox.Show("条码为空!", "提示", MessageBoxButtons.OK);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
ZPStepRecordBLL bll = new ZPStepRecordBLL();
|
||
|
ZPRecordBLL rbll = new ZPRecordBLL();
|
||
|
ZPBomBLL bombll = new ZPBomBLL();
|
||
|
ScanRecordBLL sbll = new ScanRecordBLL();
|
||
|
tb_ZPStepRecord md = new tb_ZPStepRecord();
|
||
|
tb_ZPRecord rmd = new tb_ZPRecord();
|
||
|
tb_ScanRecord smd = new tb_ScanRecord();
|
||
|
|
||
|
int IsBox = 0; //1是箱单0是单个条码
|
||
|
string code = "";
|
||
|
|
||
|
#region 判断当前步骤校验是箱单还是单个条码
|
||
|
|
||
|
DataTable dt = bombll.SearchInfoByStep(labStationNo.Text, labPartNo.Text, currentStep + step);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
IsBox = dt.Rows[0]["IsScanCode"].ToString() == "0" ? 1 : 0;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
if (IsBox == 1)
|
||
|
{
|
||
|
//TODO 无需校验
|
||
|
string[] a = textBox2.Text.Trim().Split('.');
|
||
|
code = a[0];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//TODO 校验条码是否用过
|
||
|
|
||
|
if (sbll.IsScan(textBox2.Text.Trim(),"") > 0)
|
||
|
{
|
||
|
MessageBox.Show("物料条码使用过,请更换物料!", "提示", MessageBoxButtons.OK);
|
||
|
textBox2.SelectAll();
|
||
|
textBox2.Text = "";
|
||
|
textBox2.Focus();
|
||
|
return;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
code = textBox2.Text.Trim();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DataTable dt1 = bombll.IsMath(labStationNo.Text, labPartNo.Text, code, currentStep + step);
|
||
|
if (dt1 != null && dt1.Rows.Count > 0)
|
||
|
{
|
||
|
//TODO 是单个条码的记录扫描记录
|
||
|
|
||
|
#region 存扫描记录
|
||
|
|
||
|
smd.BarCode = textBox2.Text.Trim();
|
||
|
smd.CreateTime = DateTime.Now;
|
||
|
smd.StationID = stationID;
|
||
|
|
||
|
sbll.AddInfo(smd);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 存步骤日志
|
||
|
|
||
|
md.BarCode = textBox1.Text.Trim();
|
||
|
md.StationID = stationID;
|
||
|
md.KeyBarCode = textBox2.Text.Trim();
|
||
|
md.CreateTime = DateTime.Now;
|
||
|
md.IsOK = 1;
|
||
|
md.Step = currentStep + step;
|
||
|
md.PlanID = planID;
|
||
|
|
||
|
bll.AddInfo(md);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
//currentStep += 1;
|
||
|
|
||
|
if (step == maxStep && IsLast)
|
||
|
{
|
||
|
|
||
|
#region 存装配记录
|
||
|
|
||
|
rmd.OneBarCode = textBox1.Text.Trim();
|
||
|
rmd.PlanID = planID;
|
||
|
|
||
|
rbll.AddInfo(rmd);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
LoadStep();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("物料与计划不匹配!", "提示", MessageBoxButtons.OK);
|
||
|
textBox2.SelectAll();
|
||
|
textBox2.Text = "";
|
||
|
textBox2.Focus();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public int ReadSingleValueFromOPC2(int i)
|
||
|
{
|
||
|
object ItemValues;
|
||
|
object Qualities;
|
||
|
object TimeStamps;
|
||
|
|
||
|
opcItemm2[i].Read(1, out ItemValues, out Qualities, out TimeStamps);
|
||
|
|
||
|
if ((ItemValues != null) && (Qualities.ToString() != "Good"))
|
||
|
{
|
||
|
return Convert.ToInt32(ItemValues.ToString());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 上一计划
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button3_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ZPPlanBLL bll = new ZPPlanBLL();
|
||
|
|
||
|
DataTable dt = bll.GetPlan(labStationNo.Text, 1, this.Tag.ToString());
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
planID = dt.Rows[0]["ID"].ToString();
|
||
|
labOrderNo.Text = dt.Rows[0]["OrderNo"].ToString();
|
||
|
labPartNo.Text = dt.Rows[0]["PartNo"].ToString();
|
||
|
labPName.Text = dt.Rows[0]["ProductName"].ToString();
|
||
|
labNum.Text = dt.Rows[0]["ProductCount"].ToString() + "/" + dt.Rows[0]["OrderCount"].ToString();
|
||
|
labBadCount.Text = dt.Rows[0]["BadCount"].ToString();
|
||
|
this.Tag = dt.Rows[0]["CreateTime"].ToString();
|
||
|
ControlButton(labPartNo.Text, currentStep+maxStep-1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("无上一计划!", "提示", MessageBoxButtons.OK);
|
||
|
return;
|
||
|
}
|
||
|
LoadStep();
|
||
|
ControlButton(labPartNo.Text, currentStep + maxStep - 1);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 下一计划
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button4_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ZPPlanBLL bll = new ZPPlanBLL();
|
||
|
ZPBomBLL bbll = new ZPBomBLL();
|
||
|
|
||
|
DataTable dt = bll.GetPlan(labStationNo.Text, 2, this.Tag.ToString());
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
planID = dt.Rows[0]["ID"].ToString();
|
||
|
labOrderNo.Text = dt.Rows[0]["OrderNo"].ToString();
|
||
|
labPartNo.Text = dt.Rows[0]["PartNo"].ToString();
|
||
|
labPName.Text = dt.Rows[0]["ProductName"].ToString();
|
||
|
labNum.Text = dt.Rows[0]["ProductCount"].ToString() + "/" + dt.Rows[0]["OrderCount"].ToString();
|
||
|
labBadCount.Text = dt.Rows[0]["BadCount"].ToString();
|
||
|
this.Tag = dt.Rows[0]["CreateTime"].ToString();
|
||
|
//ControlButton(labPartNo.Text, currentStep+maxStep-1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("无下一计划!", "提示", MessageBoxButtons.OK);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
#region 获取当前工位的总步骤数
|
||
|
|
||
|
DataTable dt3 = bbll.SearchStep(labPartNo.Text, labStationNo.Text);
|
||
|
if (dt3 != null && dt3.Rows.Count > 0)
|
||
|
{
|
||
|
maxStep = dt3.Rows.Count;
|
||
|
currentStep = Convert.ToInt32(dt3.Rows[0]["Step"]);
|
||
|
textBox1.Enabled = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
maxStep = 0;
|
||
|
IsOK = false;
|
||
|
//MessageBox.Show("该产品在本工位没有步骤!", "提示", MessageBoxButtons.OK);
|
||
|
textBox1.Enabled = false;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
LoadStep();
|
||
|
ControlButton(labPartNo.Text, currentStep + maxStep - 1);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 打印标签
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button1_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ZPRecordBLL bll = new ZPRecordBLL();
|
||
|
ProductBLL pbll = new ProductBLL();
|
||
|
ZPPlanBLL planbll = new ZPPlanBLL();
|
||
|
ZPBoxBLL boxbll = new ZPBoxBLL();
|
||
|
StationBLL sbll=new StationBLL();
|
||
|
ZPRecordModel md = new ZPRecordModel();
|
||
|
ZPPlanModel zmd = new ZPPlanModel();
|
||
|
ZPBoxModel boxmd = new ZPBoxModel();
|
||
|
|
||
|
string stockNo = "", partNo = "", partName = "", barCode = "", onebarCode = "", batch = "", oldbarCode = "", oldonebarCode = "", filename = "", reportName = "";
|
||
|
DateTime time;
|
||
|
int packCount = 0;
|
||
|
string old_box = "", new_box = "";
|
||
|
|
||
|
#region 查询存货代码
|
||
|
|
||
|
DataTable dt = pbll.SearchInfoByPartNo(labPartNo.Text.Trim());
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
stockNo = dt.Rows[0]["StockNo"].ToString();
|
||
|
packCount = Convert.ToInt32(dt.Rows[0]["PackCount"]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
stockNo = "";
|
||
|
packCount = 0;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
time = GetDateTime();
|
||
|
|
||
|
if (time.Hour >= 8 && time.Hour < 20)
|
||
|
{
|
||
|
batch = time.ToString("yyMMdd");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (time.Hour >= 0 && time.Hour < 8)
|
||
|
{
|
||
|
batch = time.AddDays(-1).ToString("yyMMdd");
|
||
|
}
|
||
|
else if (time.Hour >= 20 && time.Hour <= 23)
|
||
|
{
|
||
|
batch = time.ToString("yyMMdd");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#region 查询当前产品是否有未打印的标签
|
||
|
|
||
|
DataTable dt1 = bll.SearchPrint(planID);
|
||
|
if (dt1 != null && dt1.Rows.Count > 0)
|
||
|
{
|
||
|
md.ID = dt1.Rows[0]["ID"].ToString();
|
||
|
time = GetDateTime();
|
||
|
partNo = labPartNo.Text.Trim();
|
||
|
partName = labPName.Text.Trim();
|
||
|
|
||
|
DataTable dt2 = bll.SearchBarCode(stockNo, batch);
|
||
|
if (dt2 != null && dt2.Rows.Count > 0)
|
||
|
{
|
||
|
oldonebarCode = dt2.Rows[0]["OneBarCode1"].ToString();
|
||
|
oldbarCode = dt2.Rows[0]["BarCode"].ToString();
|
||
|
|
||
|
onebarCode = oldonebarCode.Substring(0, oldonebarCode.Length - 4) + (Convert.ToInt32(oldonebarCode.Substring(oldonebarCode.Length - 4, 4)) + 1).ToString().PadLeft(4, '0');
|
||
|
barCode = oldbarCode.Substring(0, oldbarCode.Length - 4) + (Convert.ToInt32(oldbarCode.Substring(oldbarCode.Length - 4, 4)) + 1).ToString().PadLeft(4, '0');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
onebarCode = stockNo + batch + "0001";
|
||
|
barCode = labPartNo.Text.Trim() + "." + batch + ".0001";
|
||
|
}
|
||
|
|
||
|
#region 打印标签
|
||
|
|
||
|
filename = System.AppDomain.CurrentDomain.BaseDirectory + "zp.grf";
|
||
|
DataTable headTable = new DataTable();
|
||
|
headTable.Columns.Add("time");
|
||
|
headTable.Columns.Add("partNo");
|
||
|
headTable.Columns.Add("PartName");
|
||
|
headTable.Columns.Add("OneBarCode");
|
||
|
DataRow row = headTable.NewRow();
|
||
|
row["time"] = time.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
row["partNo"] = partNo;
|
||
|
row["PartName"] = partName;
|
||
|
row["OneBarCode"] = onebarCode;
|
||
|
|
||
|
reportName = ConfigurationManager.AppSettings["printName"].ToString();
|
||
|
headTable.Rows.Add(row);
|
||
|
|
||
|
ReportHelper rp = new ReportHelper(filename, headTable, null, (int)GRPaperOrientation.grpoDefault, 1, reportName);
|
||
|
|
||
|
rp.Report.Print(false);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 更新数据
|
||
|
|
||
|
md.IsOK = 1;
|
||
|
md.PrintType = 0;
|
||
|
md.PrintTime = time;
|
||
|
md.OneBarCode1 = onebarCode;
|
||
|
md.BarCode = barCode;
|
||
|
|
||
|
bll.UpdatePrint(md);
|
||
|
|
||
|
zmd.ID = planID;
|
||
|
planbll.updateQty(zmd);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 查询是否够满箱,够则打印箱单 20210412增加
|
||
|
|
||
|
DataTable sumdt = bll.GetCountByPartNo(labPartNo.Text.Trim() + '.' + batch);
|
||
|
if (sumdt != null && sumdt.Rows.Count > 0)
|
||
|
{
|
||
|
if (Convert.ToInt32(sumdt.Rows[0]["qty"].ToString()) >= packCount)
|
||
|
{
|
||
|
#region 生成箱单
|
||
|
|
||
|
DataTable boxdt = boxbll.SearchBoxByPartNo(labPartNo.Text.Trim());
|
||
|
if (boxdt != null && boxdt.Rows.Count > 0)
|
||
|
{
|
||
|
old_box = boxdt.Rows[0]["BoxNo"].ToString();
|
||
|
new_box = old_box.Substring(0, old_box.Length - 6) + (Convert.ToInt32(old_box.Substring(old_box.Length - 6, 6)) + 1).ToString().PadLeft(6, '0');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
new_box = labPartNo.Text.Trim() + '.' + batch + ".000001";
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 打印箱单
|
||
|
|
||
|
filename = System.AppDomain.CurrentDomain.BaseDirectory + "box.grf";
|
||
|
DataTable headTable1 = new DataTable();
|
||
|
headTable1.Columns.Add("BoxNo");
|
||
|
headTable1.Columns.Add("PartName");
|
||
|
headTable1.Columns.Add("PartNo");
|
||
|
headTable1.Columns.Add("Batch");
|
||
|
headTable1.Columns.Add("PackCount");
|
||
|
DataRow row1 = headTable1.NewRow();
|
||
|
row1["BoxNo"] = new_box;
|
||
|
row1["PartName"] = partName;
|
||
|
row1["PartNo"] = partNo;
|
||
|
row1["Batch"] = batch;
|
||
|
row1["PackCount"] = packCount;
|
||
|
|
||
|
reportName = ConfigurationManager.AppSettings["printName1"].ToString();
|
||
|
headTable1.Rows.Add(row1);
|
||
|
|
||
|
ReportHelper rp1 = new ReportHelper(filename, headTable1, null, (int)GRPaperOrientation.grpoDefault, 1, reportName);
|
||
|
|
||
|
rp1.Report.Print(false);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 插入箱单
|
||
|
|
||
|
boxmd.ID = Guid.NewGuid().ToString();
|
||
|
boxmd.BoxNo = new_box;
|
||
|
boxmd.PartNo = partNo;
|
||
|
boxmd.Flag = 0;
|
||
|
|
||
|
boxbll.AddInfo(boxmd);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 半成品绑定箱单
|
||
|
|
||
|
bll.UpdateBox(partNo, new_box);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
//initPlan();
|
||
|
initProduct();
|
||
|
|
||
|
LoadStep();
|
||
|
|
||
|
#region 调用wms入库接口
|
||
|
|
||
|
LogHelper.WriteSysLogBase("条码号:" + onebarCode + "工位:" + labStationNo.Text + ",调用WMS装配合格入库接口", MethodBase.GetCurrentMethod().Name);
|
||
|
WMSWebService ws=new WMSWebService();
|
||
|
string lineID = "";
|
||
|
|
||
|
#region 根据工位编号查询产线ID
|
||
|
|
||
|
DataTable sdt = sbll.SearchInfoByNo(labStationNo.Text);
|
||
|
if (sdt != null && sdt.Rows.Count > 0)
|
||
|
{
|
||
|
lineID = sdt.Rows[0]["LineName"].ToString();
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
ws.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"];
|
||
|
bool aa= ws.WMSInterfaceStockIn(onebarCode, partNo, DateTime.Now.ToString("yyyyMMdd"), 1, lineID);
|
||
|
if (!aa)
|
||
|
{
|
||
|
DialogResult r= MessageBox.Show("调用WMS接口失败,是否重新调用!", "提示", MessageBoxButtons.YesNo);
|
||
|
if (r == DialogResult.Yes)
|
||
|
{
|
||
|
for (int i = 0; i < 3; i++)
|
||
|
{
|
||
|
if (ws.WMSInterfaceStockIn(onebarCode, partNo, DateTime.Now.ToString("yyyyMMdd"), 1, lineID))
|
||
|
{
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("当前计划没有可以打印的标签!", "提示", MessageBoxButtons.OK);
|
||
|
textBox1.SelectAll();
|
||
|
textBox1.Text = "";
|
||
|
textBox1.Focus();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
textBox1.SelectAll();
|
||
|
textBox1.Text = "";
|
||
|
textBox1.Focus();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void initProduct()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ZPPlanBLL bll = new ZPPlanBLL();
|
||
|
|
||
|
labStationNo.Text = ConfigurationManager.AppSettings["StationNo"].ToString();
|
||
|
|
||
|
DataTable dt = bll.GetProductingPlan1(labStationNo.Text, labOrderNo.Text);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
planID = dt.Rows[0]["ID"].ToString();
|
||
|
labNum.Text = dt.Rows[0]["ProductCount"].ToString() + "/" + dt.Rows[0]["OrderCount"].ToString();
|
||
|
labBadCount.Text = dt.Rows[0]["BadCount"].ToString();
|
||
|
this.Tag = dt.Rows[0]["CreateTime"].ToString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
initPlan();
|
||
|
}
|
||
|
|
||
|
Program.partNo1 = labPartNo.Text;
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 补打标签
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button2_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string barCode = "", filename = "", partNo = "", partName = "", reportName = "", planID = "", oneBarCode = "", oneBarCode1 = "";
|
||
|
ZPRecordBLL bll = new ZPRecordBLL();
|
||
|
ZPPlanBLL planbll = new ZPPlanBLL();
|
||
|
DateTime time;
|
||
|
int IsOK = 0;
|
||
|
ZPRecordModel md = new ZPRecordModel();
|
||
|
|
||
|
time = GetDateTime();
|
||
|
|
||
|
DialogResult result = MessageBox.Show("确定要补打条码?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
|
||
|
if (result == DialogResult.OK)
|
||
|
{
|
||
|
FrmBuDa frm = new FrmBuDa();
|
||
|
frm.OkBtnClick += (arg1) =>
|
||
|
{
|
||
|
#region 打印标签
|
||
|
|
||
|
filename = AppDomain.CurrentDomain.BaseDirectory + "zp.grf";
|
||
|
DataTable headTable = new DataTable();
|
||
|
headTable.Columns.Add("time");
|
||
|
headTable.Columns.Add("partNo");
|
||
|
headTable.Columns.Add("PartName");
|
||
|
headTable.Columns.Add("OneBarCode");
|
||
|
DataRow row = headTable.NewRow();
|
||
|
row["time"] = time.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
|
||
|
DataTable dt = bll.SearchInfo(arg1);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
planID = dt.Rows[0]["PlanID"].ToString();
|
||
|
IsOK = Convert.ToInt32(dt.Rows[0]["IsOK"].ToString());
|
||
|
barCode = dt.Rows[0]["BarCode"].ToString();
|
||
|
oneBarCode = dt.Rows[0]["OneBarCode"].ToString();
|
||
|
oneBarCode1 = dt.Rows[0]["OneBarCode1"].ToString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
planID = "";
|
||
|
}
|
||
|
|
||
|
DataTable dt1 = planbll.SearchPlanInfo(planID);
|
||
|
if (dt1 != null && dt1.Rows.Count > 0)
|
||
|
{
|
||
|
row["partNo"] = dt1.Rows[0]["PartNo"].ToString();
|
||
|
row["PartName"] = dt1.Rows[0]["ProductName"].ToString();
|
||
|
}
|
||
|
row["OneBarCode"] = oneBarCode1;
|
||
|
|
||
|
reportName = ConfigurationManager.AppSettings["printName"].ToString();
|
||
|
headTable.Rows.Add(row);
|
||
|
|
||
|
ReportHelper rp = new ReportHelper(filename, headTable, null, (int)GRPaperOrientation.grpoDefault, 1, reportName);
|
||
|
|
||
|
rp.Report.Print(false);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
md.ID = Guid.NewGuid().ToString();
|
||
|
md.IsOK = 1;
|
||
|
md.PrintType = 1;
|
||
|
md.PrintTime = time;
|
||
|
md.OneBarCode1 = oneBarCode1;
|
||
|
md.BarCode = barCode;
|
||
|
md.OneBarCode = arg1;
|
||
|
md.planID = planID;
|
||
|
|
||
|
bll.AddBudaInfo(md);
|
||
|
|
||
|
};
|
||
|
frm.ShowDialog();
|
||
|
textBox1.Text = "";
|
||
|
textBox1.SelectAll();
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private 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 = 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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 不合格
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button5_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
timer1.Enabled = true;
|
||
|
textBox1.SelectAll();
|
||
|
FrmChooseDamnPosition frm = new FrmChooseDamnPosition();
|
||
|
|
||
|
frm.Show();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void timer1_Tick(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
initProduct();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 手动打印箱单
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button6_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
DateTime time;
|
||
|
string batch = "", partNo = "", partName = "", old_box = "", new_box = "", filename = "", reportName = ""; ;
|
||
|
|
||
|
ZPRecordBLL bll = new ZPRecordBLL();
|
||
|
ProductBLL pbll = new ProductBLL();
|
||
|
ZPPlanBLL planbll = new ZPPlanBLL();
|
||
|
ZPBoxBLL boxbll = new ZPBoxBLL();
|
||
|
ZPRecordModel md = new ZPRecordModel();
|
||
|
ZPPlanModel zmd = new ZPPlanModel();
|
||
|
ZPBoxModel boxmd = new ZPBoxModel();
|
||
|
|
||
|
time = GetDateTime();
|
||
|
|
||
|
if (time.Hour >= 8 && time.Hour < 20)
|
||
|
{
|
||
|
batch = time.ToString("yyMMdd");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (time.Hour >= 0 && time.Hour < 8)
|
||
|
{
|
||
|
batch = time.AddDays(-1).ToString("yyMMdd");
|
||
|
}
|
||
|
else if (time.Hour >= 20 && time.Hour <= 23)
|
||
|
{
|
||
|
batch = time.ToString("yyMMdd");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
partNo = labPartNo.Text.Trim();
|
||
|
partName = labPName.Text.Trim();
|
||
|
|
||
|
#region 20210412增加
|
||
|
|
||
|
DataTable sumdt = bll.GetCountByPartNo(labPartNo.Text.Trim() + '.' + batch);
|
||
|
if (sumdt != null && sumdt.Rows.Count > 0)
|
||
|
{
|
||
|
#region 生成箱单
|
||
|
|
||
|
DataTable boxdt = boxbll.SearchBoxByPartNo(labPartNo.Text.Trim());
|
||
|
if (boxdt != null && boxdt.Rows.Count > 0)
|
||
|
{
|
||
|
old_box = boxdt.Rows[0]["BoxNo"].ToString();
|
||
|
new_box = old_box.Substring(0, old_box.Length - 6) + (Convert.ToInt32(old_box.Substring(old_box.Length - 6, 6)) + 1).ToString().PadLeft(6, '0');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
new_box = labPartNo.Text.Trim() + '.' + batch + ".000001";
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 打印箱单
|
||
|
|
||
|
filename = System.AppDomain.CurrentDomain.BaseDirectory + "box.grf";
|
||
|
DataTable headTable1 = new DataTable();
|
||
|
headTable1.Columns.Add("BoxNo");
|
||
|
headTable1.Columns.Add("PartName");
|
||
|
headTable1.Columns.Add("PartNo");
|
||
|
headTable1.Columns.Add("Batch");
|
||
|
headTable1.Columns.Add("PackCount");
|
||
|
DataRow row1 = headTable1.NewRow();
|
||
|
row1["BoxNo"] = new_box;
|
||
|
row1["PartName"] = partName;
|
||
|
row1["PartNo"] = partNo;
|
||
|
row1["Batch"] = batch;
|
||
|
row1["PackCount"] = sumdt.Rows[0]["qty"];
|
||
|
|
||
|
reportName = ConfigurationManager.AppSettings["printName1"];
|
||
|
headTable1.Rows.Add(row1);
|
||
|
|
||
|
ReportHelper rp1 = new ReportHelper(filename, headTable1, null, (int)GRPaperOrientation.grpoDefault, 1, reportName);
|
||
|
|
||
|
rp1.Report.Print(false);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 插入箱单
|
||
|
|
||
|
boxmd.ID = Guid.NewGuid().ToString();
|
||
|
boxmd.BoxNo = new_box;
|
||
|
boxmd.PartNo = partNo;
|
||
|
boxmd.Flag = 1;
|
||
|
|
||
|
boxbll.AddInfo(boxmd);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 半成品绑定箱单
|
||
|
|
||
|
bll.UpdateBox(partNo, new_box);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("都已装箱,无需打印箱单!", "提示", MessageBoxButtons.OK);
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 补打箱单
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void button7_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string filename = "", boxNo = "", reportName = "", PackCount = "", partNo = "";
|
||
|
ZPRecordBLL bll = new ZPRecordBLL();
|
||
|
ZPPlanBLL planbll = new ZPPlanBLL();
|
||
|
ZPBoxBLL boxbll = new ZPBoxBLL();
|
||
|
ZPBoxModel md = new ZPBoxModel();
|
||
|
|
||
|
DialogResult result = MessageBox.Show("确定要补打条码?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
|
||
|
if (result == DialogResult.OK)
|
||
|
{
|
||
|
FrmBuDa frm = new FrmBuDa();
|
||
|
frm.OkBtnClick += (arg1) =>
|
||
|
{
|
||
|
#region 根据条码查找对应的箱单
|
||
|
|
||
|
DataTable dt = bll.SearchInfo(arg1);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
planID = dt.Rows[0]["PlanID"].ToString();
|
||
|
boxNo = dt.Rows[0]["BoxNo"].ToString();
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrEmpty(boxNo))
|
||
|
{
|
||
|
MessageBox.Show("此零件未装箱或不存在,无需打印箱单!", "提示", MessageBoxButtons.OK);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
string[] aa = boxNo.Split('.');
|
||
|
|
||
|
DataTable dt2 = boxbll.SearchCountByBoxNo(boxNo);
|
||
|
if (dt2 != null && dt2.Rows.Count > 0)
|
||
|
{
|
||
|
PackCount = dt2.Rows[0]["Qty"].ToString();
|
||
|
}
|
||
|
|
||
|
filename = System.AppDomain.CurrentDomain.BaseDirectory + "box.grf";
|
||
|
DataTable headTable1 = new DataTable();
|
||
|
headTable1.Columns.Add("BoxNo");
|
||
|
headTable1.Columns.Add("PartName");
|
||
|
headTable1.Columns.Add("PartNo");
|
||
|
headTable1.Columns.Add("Batch");
|
||
|
headTable1.Columns.Add("PackCount");
|
||
|
DataRow row1 = headTable1.NewRow();
|
||
|
|
||
|
|
||
|
DataTable dt1 = planbll.SearchPlanInfo(planID);
|
||
|
if (dt1 != null && dt1.Rows.Count > 0)
|
||
|
{
|
||
|
row1["partNo"] = dt1.Rows[0]["PartNo"].ToString();
|
||
|
row1["PartName"] = dt1.Rows[0]["ProductName"].ToString();
|
||
|
partNo = dt1.Rows[0]["PartNo"].ToString();
|
||
|
}
|
||
|
row1["PackCount"] = PackCount;
|
||
|
row1["Batch"] = aa[1];
|
||
|
row1["BoxNo"] = boxNo;
|
||
|
|
||
|
reportName = ConfigurationManager.AppSettings["printName1"];
|
||
|
headTable1.Rows.Add(row1);
|
||
|
|
||
|
ReportHelper rp1 = new ReportHelper(filename, headTable1, null, (int)GRPaperOrientation.grpoDefault, 1, reportName);
|
||
|
|
||
|
rp1.Report.Print(false);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 插入箱单
|
||
|
|
||
|
md.ID = Guid.NewGuid().ToString();
|
||
|
md.BoxNo = boxNo;
|
||
|
md.PartNo = partNo;
|
||
|
md.Flag = 1;
|
||
|
|
||
|
boxbll.AddInfo(md);
|
||
|
|
||
|
#endregion
|
||
|
};
|
||
|
frm.ShowDialog();
|
||
|
textBox1.Text = "";
|
||
|
textBox1.SelectAll();
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void labTime_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
Environment.Exit(0);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|