|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Drawing;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
using Estsh.Client.Base;
|
|
|
using System.Configuration;
|
|
|
using MainProgram;
|
|
|
using MainProgram.BLL;
|
|
|
using System.IO;
|
|
|
using System.Net;
|
|
|
using System.Threading;
|
|
|
using System.Net.Sockets;
|
|
|
using Com.Estsh.MES.AssemblyInput;
|
|
|
|
|
|
|
|
|
namespace Estsh.Client.StepLibrary
|
|
|
{
|
|
|
public partial class YYOutPdlineInspection:StepBase
|
|
|
{
|
|
|
private StepLibraryAPP _app = null;
|
|
|
private List<dynamic> _CheckData = null; //绑定数据
|
|
|
private delegate void DeleGrdBind(List<dynamic> dt);
|
|
|
private int _terminalID = 0;
|
|
|
private string _sn = "";
|
|
|
|
|
|
private int Inum = 1;
|
|
|
|
|
|
//PASS间隔限制工位集合
|
|
|
private string _passIntervalLimit = string.Empty;
|
|
|
|
|
|
|
|
|
//PLC信号标识
|
|
|
private string JYFlag = string.Empty; //静音房信号
|
|
|
private string RWFlag = string.Empty; //返工信号
|
|
|
private string FXFlag = string.Empty; //放行信号
|
|
|
|
|
|
public YYOutPdlineInspection()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
// 有用户界面的工步在初始化时需要设置为不可见
|
|
|
// 开始执行此工步后再置为可见
|
|
|
this.Visible = false;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public override bool Do()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
// 置为可见并加载到最前端
|
|
|
this.Visible = true;
|
|
|
this.BringToFront();
|
|
|
|
|
|
// 从配置文件中加载工位编号
|
|
|
_terminalID = Convert.ToInt32(Context["terminal_id"].ToString());
|
|
|
_sn = Context["serial_number"].ToString();
|
|
|
|
|
|
_app = new StepLibraryAPP(httpClient);
|
|
|
string _PartNo = _app.GetPartNo(_sn);
|
|
|
string rule = _app.GetRuleNo(_PartNo);
|
|
|
string partLocation = _app.GetPartLoc(_PartNo);
|
|
|
|
|
|
PlcFlow.Enabled = true;
|
|
|
PlcFlow.Start();
|
|
|
|
|
|
|
|
|
// 执行父类的 Do 方法并返回
|
|
|
return base.Do();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
// 记录日志
|
|
|
using (StreamWriter sw = new StreamWriter("Error_Log_" + DateTime.Now.ToString("yyyyMM") + ".txt", true))
|
|
|
{
|
|
|
sw.WriteLine(string.Format("{0} {1}", "["
|
|
|
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ "] ", ex.ToString()));
|
|
|
sw.Flush();
|
|
|
sw.Close();
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ForeachPanelControls()
|
|
|
{
|
|
|
string ctrlName = "btnNGType";
|
|
|
|
|
|
for (int i = 1; i <= 16; i++)
|
|
|
{
|
|
|
ctrlName = "btnNGType" + i.ToString();
|
|
|
foreach (Control ctrl in tableLayoutPanel1.Controls)
|
|
|
{
|
|
|
if (ctrl is Button)
|
|
|
{
|
|
|
if (ctrl.Name.Equals(ctrlName))
|
|
|
ctrl.Text = "";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OutPdlineInspection_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
_sn = Context["serial_number"].ToString();
|
|
|
|
|
|
_app = new StepLibraryAPP(httpClient);
|
|
|
_terminalID = Convert.ToInt32(Context["terminal_id"].ToString());
|
|
|
|
|
|
//校验电检数据
|
|
|
_app.insertDefectData(_sn, _terminalID);
|
|
|
|
|
|
ForeachPanelControls();
|
|
|
|
|
|
|
|
|
LoadDefect();
|
|
|
|
|
|
// 工步执行完成后调用此方法
|
|
|
//Complate(this, e);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下一页
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnNextPage_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
Inum++;
|
|
|
LoadDefect();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 上一页
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnLastPage_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
Inum--;
|
|
|
LoadDefect();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 加载不良
|
|
|
/// </summary>
|
|
|
private void LoadDefect()
|
|
|
{
|
|
|
List<dynamic> DefectList = _app.getYYDefectList(_terminalID);
|
|
|
|
|
|
int CountQty = DefectList.Count; //一页有多少行
|
|
|
int PageRows = 16;
|
|
|
int PageCount = (int)Math.Ceiling((double)CountQty / (double)PageRows);//一共有多少页
|
|
|
int RowsEnd = 0;//终止行数
|
|
|
//Inum:当前页数
|
|
|
|
|
|
if (Inum < 1)
|
|
|
{
|
|
|
Inum++;
|
|
|
return;
|
|
|
}
|
|
|
else if (Inum > PageCount)
|
|
|
{
|
|
|
Inum--;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//颜色初始化
|
|
|
btnNGType1.BackColor = Color.Gainsboro;
|
|
|
btnNGType2.BackColor = Color.Gainsboro;
|
|
|
btnNGType3.BackColor = Color.Gainsboro;
|
|
|
btnNGType4.BackColor = Color.Gainsboro;
|
|
|
btnNGType5.BackColor = Color.Gainsboro;
|
|
|
btnNGType6.BackColor = Color.Gainsboro;
|
|
|
btnNGType7.BackColor = Color.Gainsboro;
|
|
|
btnNGType8.BackColor = Color.Gainsboro;
|
|
|
btnNGType9.BackColor = Color.Gainsboro;
|
|
|
btnNGType10.BackColor = Color.Gainsboro;
|
|
|
btnNGType11.BackColor = Color.Gainsboro;
|
|
|
btnNGType12.BackColor = Color.Gainsboro;
|
|
|
btnNGType13.BackColor = Color.Gainsboro;
|
|
|
btnNGType14.BackColor = Color.Gainsboro;
|
|
|
btnNGType15.BackColor = Color.Gainsboro;
|
|
|
btnNGType16.BackColor = Color.Gainsboro;
|
|
|
|
|
|
string strInum = Inum.ToString() + "/" + PageCount.ToString();
|
|
|
btnInum.Text = strInum;
|
|
|
|
|
|
ForeachPanelControls();
|
|
|
|
|
|
List<dynamic> SNDefectLDt = new DataTable();
|
|
|
SNDefectLDt = _app.getSNDefect(_sn, _terminalID);
|
|
|
|
|
|
for (int i = 1; i <= Inum * PageRows; i++)
|
|
|
{
|
|
|
int j = 0;
|
|
|
if (Inum > 1)
|
|
|
{
|
|
|
j = i + 16;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
j = i;
|
|
|
}
|
|
|
|
|
|
if (CountQty < j)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
string strDefect = DefectList[j - 1]["defect_desc"].ToString();
|
|
|
string button = "btnNGType" + i.ToString();
|
|
|
Button btn = (Button)this.GetType().GetField(button, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this);
|
|
|
btn.Text = strDefect;
|
|
|
|
|
|
|
|
|
if (SNDefectLDt.Select("defect_desc" + "='" + strDefect + "'").Length > 0)
|
|
|
{
|
|
|
btn.BackColor = Color.Red;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
btn.BackColor = Color.Gainsboro;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ShowMessage(this, "Green|请检测座椅,并选择不良项!");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 新增不良明细
|
|
|
/// </summary>
|
|
|
private void operationDefect(string sn, int terminalID, string defectName, string operationType)
|
|
|
{
|
|
|
if (operationType.ToUpper() == "ADD")
|
|
|
{
|
|
|
_app.addYYSndefect(sn, terminalID, defectName);
|
|
|
}
|
|
|
else if ((operationType.ToUpper() == "DEL"))
|
|
|
{
|
|
|
_app.delYYSndefect(sn, terminalID, defectName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 插入或修改不良项
|
|
|
/// </summary>
|
|
|
/// <param name="btnName"></param>
|
|
|
private void defectOperation(string btnName)
|
|
|
{
|
|
|
string button = btnName;
|
|
|
|
|
|
foreach (Control ctrl in tableLayoutPanel1.Controls)
|
|
|
{
|
|
|
if (ctrl is Button)
|
|
|
{
|
|
|
if (ctrl.Name.Equals(button))
|
|
|
{
|
|
|
//ctrl.Text = strDefect;
|
|
|
|
|
|
if (ctrl.BackColor == Color.Gainsboro)
|
|
|
{
|
|
|
if (_app.getDefectDetail( _terminalID,ctrl.Text.ToString()).Count > 0)
|
|
|
{
|
|
|
YYNGFacadeCheck yyNGFacadeCheck = new YYNGFacadeCheck(_app, _sn, _terminalID, ctrl.Text.ToString());
|
|
|
yyNGFacadeCheck.ShowDialog();
|
|
|
|
|
|
if (_app.getSNDefectDetail(_sn, _terminalID, ctrl.Text.ToString()).Count > 0)
|
|
|
{
|
|
|
operationDefect(_sn, _terminalID, ctrl.Text.ToString(), "ADD");
|
|
|
ctrl.BackColor = Color.Red;
|
|
|
ShowMessage(this, "Green|【" + ctrl.Text.ToString() + "】不良,新增成功!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
operationDefect(_sn, _terminalID, ctrl.Text.ToString(), "ADD");
|
|
|
ctrl.BackColor = Color.Red;
|
|
|
ShowMessage(this, "Green|【" + ctrl.Text.ToString() + "】不良,新增成功!");
|
|
|
}
|
|
|
}
|
|
|
else if (ctrl.BackColor == Color.Red)
|
|
|
{
|
|
|
if (_app.getDefectDetail(_terminalID, ctrl.Text.ToString()).Count > 0)
|
|
|
{
|
|
|
YYNGFacadeCheck yyNGFacadeCheck = new YYNGFacadeCheck(_app, _sn, _terminalID, ctrl.Text.ToString());
|
|
|
yyNGFacadeCheck.ShowDialog();
|
|
|
|
|
|
if (_app.getSNDefectDetail(_sn, _terminalID, ctrl.Text.ToString()).Count > 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
operationDefect(_sn, _terminalID, ctrl.Text.ToString(), "DEL");
|
|
|
ctrl.BackColor = Color.Gainsboro;
|
|
|
ShowMessage(this, "Green|【" + ctrl.Text.ToString() + "】不良,删除成功!");
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
operationDefect(_sn, _terminalID, ctrl.Text.ToString(), "DEL");
|
|
|
ctrl.BackColor = Color.Gainsboro;
|
|
|
ShowMessage(this, "Green|【" + ctrl.Text.ToString() + "】不良,删除成功!");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ctrl.BackColor = Color.Yellow;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void btnNGType1_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType1.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType2_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType2.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType3_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType3.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType4_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType4.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType5_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType5.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType6_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType6.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType7_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType7.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType8_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType8.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType9_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType9.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType10_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType10.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType11_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType11.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType12_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType12.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType13_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType13.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType14_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType14.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType15_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType15.Name);
|
|
|
}
|
|
|
|
|
|
private void btnNGType16_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
defectOperation(btnNGType16.Name);
|
|
|
}
|
|
|
|
|
|
private void btnRework_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
List<dynamic> SNDefectLDt = new DataTable();
|
|
|
SNDefectLDt = _app.getSNDefect(_sn, _terminalID);
|
|
|
|
|
|
if (SNDefectLDt.Count <= 0)
|
|
|
{
|
|
|
ShowMessage(this, "red|【" + _sn + "】没有添加不良项,请选择不良类型!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//余姚返工类型2
|
|
|
StopStep(2);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
List<dynamic> SNDefectLDt = new DataTable();
|
|
|
SNDefectLDt = _app.getSNDefect(_sn, _terminalID);
|
|
|
|
|
|
if (SNDefectLDt.Count > 0)
|
|
|
{
|
|
|
ShowMessage(this, "red|【" + _sn + "】有不良项,请重新确认!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//更新条码状态为下线
|
|
|
_app.updateStatus(_sn);
|
|
|
|
|
|
try
|
|
|
{
|
|
|
string tres = _app.ProdTrans(0, Context["serial_number"].ToString(), Convert.ToInt32(Context["terminal_id"].ToString()), 0, "C");
|
|
|
if (tres.ToUpper() != "OK")
|
|
|
{
|
|
|
ShowMessage(this, "red|" + tres + "");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
using (StreamWriter sw = new StreamWriter("ProdTrans-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", true))
|
|
|
{
|
|
|
sw.WriteLine(string.Format("{0} {1} {2}", "["
|
|
|
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ "] ProdTrans", Context["serial_number"].ToString(), ex));
|
|
|
sw.Flush();
|
|
|
sw.Close();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 工步执行完成后调用此方法
|
|
|
Complate(this, e);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取PLC信号
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void PlcFlow_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
//静音
|
|
|
JYFlag = _app.YYReadyPlc("OPC_ReadJY", _terminalID).ToString().ToUpper();
|
|
|
//外观不良
|
|
|
RWFlag = _app.YYReadyPlc("OPC_ReadRW", _terminalID).ToString().ToUpper();
|
|
|
//放行
|
|
|
FXFlag = _app.YYReadyPlc("OPC_OK", _terminalID).ToString().ToUpper();
|
|
|
|
|
|
if (JYFlag == "TRUE")
|
|
|
{
|
|
|
bool retSNTravel = _app.InsertSNTravel(_sn, _terminalID, 8);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void btnPhoto_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
List<dynamic> SNDefectLDt = new DataTable();
|
|
|
SNDefectLDt = _app.getSNDefect(_sn, _terminalID);
|
|
|
|
|
|
if (RWFlag.ToUpper() == "TRUE")
|
|
|
{
|
|
|
//按钮不合格
|
|
|
if (SNDefectLDt.Count <= 0)
|
|
|
{
|
|
|
ShowMessage(this, "Red|【" + _sn + "】未选不良明细!");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//按钮合格
|
|
|
|
|
|
if (SNDefectLDt.Count > 0)
|
|
|
{
|
|
|
_app.UpdateOPCPointValue("OPC_NG", _terminalID, "3");
|
|
|
ShowMessage(this, "Red|【" + _sn + "】产线不良按钮当前状态为“良品”!");
|
|
|
//return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// 实名发送
|
|
|
IPEndPoint localIpep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12345); // 本机IP,指定的端口号
|
|
|
udpcSend = new UdpClient(localIpep);
|
|
|
Thread thrSend = new Thread(SendMessage);
|
|
|
thrSend.Start(_sn);
|
|
|
|
|
|
|
|
|
ShowMessage(this, "Green|【" + _sn + "】照片拍摄中!");
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
List<dynamic> dt = _app.getPhoto(_sn, _terminalID);
|
|
|
if (dt.Count > 0)
|
|
|
{
|
|
|
|
|
|
ShowMessage(this, "Green|【" + _sn + "】拍照成功!");
|
|
|
|
|
|
if (SNDefectLDt.Count > 0)
|
|
|
{
|
|
|
if (_app.IsCurrentSN(_sn) == false)
|
|
|
{
|
|
|
_app.SetSNStatusNG(_sn,1);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新条码状态为下线
|
|
|
_app.updateStatus(_sn);
|
|
|
|
|
|
try
|
|
|
{
|
|
|
string tres = _app.ProdTrans(0, Context["serial_number"].ToString(), Convert.ToInt32(Context["terminal_id"].ToString()), 0, "C");
|
|
|
if (tres.ToUpper() != "OK")
|
|
|
{
|
|
|
ShowMessage(this, "red|" + tres + "");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
using (StreamWriter sw = new StreamWriter("ProdTrans-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", true))
|
|
|
{
|
|
|
sw.WriteLine(string.Format("{0} {1} {2}", "["
|
|
|
+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ "] ProdTrans", Context["serial_number"].ToString(), ex));
|
|
|
sw.Flush();
|
|
|
sw.Close();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//更新条码状态为下线
|
|
|
_app.updateStatus(_sn);
|
|
|
|
|
|
Complate(this, e);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ShowMessage(this, "red|【" + _sn + "】拍照失败,请重新拍照!");
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 用于UDP发送的网络服务类
|
|
|
/// </summary>
|
|
|
private UdpClient udpcSend;
|
|
|
/// <summary>
|
|
|
/// 用于UDP接收的网络服务类
|
|
|
/// </summary>
|
|
|
private UdpClient udpcRecv;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送信息
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void SendMessage(object obj)
|
|
|
{
|
|
|
string message = (string)obj;
|
|
|
byte[] sendbytes = Encoding.Unicode.GetBytes(message);
|
|
|
IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8848); // 发送到的IP地址和端口号
|
|
|
udpcSend.Send(sendbytes, sendbytes.Length, remoteIpep);
|
|
|
udpcSend.Close();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|