|
|
using Estsh.Client.Base;
|
|
|
using Estsh.Client.Common.HttpClientUtil;
|
|
|
using Estsh.Client.Common.ServiceUtil;
|
|
|
using Estsh.Client.Common.Util;
|
|
|
using log4net;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using System.Collections;
|
|
|
using System.Configuration;
|
|
|
using System.Data;
|
|
|
using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.Text;
|
|
|
|
|
|
namespace Estsh.Client
|
|
|
{
|
|
|
public partial class FrmMain : Form
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// admin
|
|
|
/// </summary>
|
|
|
private int _userID;
|
|
|
private string _userNo;
|
|
|
private int _factoryID;
|
|
|
//private string _hostIP;
|
|
|
private List<dynamic> _OrderData = null;
|
|
|
private string _stationType = string.Empty;
|
|
|
private string _sn = "";
|
|
|
private String ReceiveBuffer = "";
|
|
|
private string _OldSN = string.Empty;
|
|
|
private IConfiguration _config;
|
|
|
private static string LabelPath =
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\LabelFile");
|
|
|
|
|
|
//最后一个写入的RFID内容
|
|
|
private string _LastRFID = string.Empty;
|
|
|
|
|
|
//第一次开启程序时提示信息
|
|
|
private bool justOpenProgram = true;
|
|
|
|
|
|
//private RF182C _RF182C = null;
|
|
|
private bool initializeRFIDState = false;
|
|
|
public string TAGState = string.Empty;
|
|
|
public bool RFID_TAGState = false;
|
|
|
public bool blWriteRFID = false;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录日志
|
|
|
/// </summary>
|
|
|
public static readonly ILog _loggerInfo = LogManager.GetLogger("MES.Logging.Info");
|
|
|
public static readonly ILog _loggerTrace = LogManager.GetLogger("MES.Logging.Trace");
|
|
|
public static readonly ILog _loggerError = LogManager.GetLogger("MES.Logging.Error");
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工位编号
|
|
|
/// </summary>
|
|
|
private int _terminalID;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 放空码,固定30位
|
|
|
/// </summary>
|
|
|
private const string BLANK_CODE = "999999999999999999999999999999";
|
|
|
|
|
|
private string barcodeLast = "";
|
|
|
|
|
|
private int currentStatus = 0;
|
|
|
|
|
|
/// <summary>
|
|
|
/// HttpClient请求帮助类
|
|
|
/// </summary>
|
|
|
private HttpClientHelper httpClient = null;
|
|
|
/// <summary>
|
|
|
/// 业务逻辑处理对象
|
|
|
/// </summary>
|
|
|
private MesApp app = null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行的上下文
|
|
|
/// 临时的缓存变量都放在这里
|
|
|
/// </summary>
|
|
|
private Hashtable _context = new Hashtable();
|
|
|
|
|
|
//扭矩枪IP地址
|
|
|
private string _TorqueIP = "";
|
|
|
private string _TorqueIP2 = "";
|
|
|
|
|
|
|
|
|
//PASS间隔限制工位集合
|
|
|
private string _passIntervalLimit = string.Empty;
|
|
|
|
|
|
//PASS扫描间隔
|
|
|
private int _passIntervalValue = 2000;
|
|
|
|
|
|
//PASS上一次成功扫描时间
|
|
|
public static DateTime _lastPassDatetime;
|
|
|
|
|
|
public FrmMain()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
|
|
|
|
|
|
//private static CodesoftPrinter m_csPrinter = null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 显示执行信息
|
|
|
/// </summary>
|
|
|
/// <param name="msg">显示的信息内容</param>
|
|
|
public void ShowMessage(string msg)
|
|
|
{
|
|
|
this.labErrorMessage.Text = msg;
|
|
|
}
|
|
|
public void ShowMessage(string msg, Color col)
|
|
|
{
|
|
|
//余姚蜂鸣
|
|
|
if (col == Color.Red)
|
|
|
{
|
|
|
OPC_FM();
|
|
|
}
|
|
|
this.labErrorMessage.Text = msg;
|
|
|
this.labErrorMessage.ForeColor = col;
|
|
|
|
|
|
}
|
|
|
|
|
|
public FrmMain(int factoryID, int userID, string userNo)
|
|
|
: this()
|
|
|
{
|
|
|
_factoryID = factoryID;
|
|
|
_userID = userID;
|
|
|
_userNo = userNo;
|
|
|
//_hostIP = hostIP;
|
|
|
|
|
|
httpClient = new HttpClientHelper();
|
|
|
httpClient.userId = _userID;
|
|
|
httpClient.userNo = _userNo;
|
|
|
|
|
|
app = new MesApp(httpClient, _userID, _userNo);
|
|
|
|
|
|
//try
|
|
|
//{
|
|
|
// m_csPrinter = new CodesoftPrinter();
|
|
|
//}
|
|
|
//catch (Exception ex)
|
|
|
//{ }
|
|
|
|
|
|
// 从配置文件中加载工位编号
|
|
|
//_terminalID = Convert.ToInt32(ConfigurationManager.AppSettings["TerminalID"]);
|
|
|
//_terminalID = Convert.ToInt32(_config.AppSettings.Settings["TerminalID"].Value);
|
|
|
_config = ServiceProviderHelper.GetService<IConfiguration>();
|
|
|
//_terminalID = Convert.ToInt32(_config.GetSection("TerminalID").Value);
|
|
|
|
|
|
if (app == null)
|
|
|
{
|
|
|
MessageBox.Show("初始化系统连接失败,请检查服务器地址设置是否正确!");
|
|
|
WriteErrorLog("初始化系统连接失败,请检查服务器地址设置是否正确!", null);
|
|
|
this.Close();
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (!LocalCache.localData.ContainsKey("TerminalID"))
|
|
|
{
|
|
|
FrmReTerminal frmTerminal = new FrmReTerminal(app, _terminalID);
|
|
|
if (frmTerminal.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
_terminalID = Convert.ToInt32(frmTerminal.Input);
|
|
|
frmTerminal.Close();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_terminalID = Convert.ToInt32(LocalCache.localData["TerminalID"].ToString());
|
|
|
}
|
|
|
|
|
|
var TerminalData = app.GetTerminalInfo(_terminalID);
|
|
|
|
|
|
if (TerminalData == null)
|
|
|
{
|
|
|
MessageBox.Show(string.Format("加载工位信息失败,请检查工位编号是否正确! {0}", _terminalID));
|
|
|
WriteErrorLog(string.Format("加载工位信息失败,请检查工位编号是否正确! {0}", _terminalID), null);
|
|
|
this.Close();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
lblTerminalName.Text = TerminalData["terminal_name"].ToString();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据工位参数判断是否要自动按照生产队列加载条码
|
|
|
/// </summary>
|
|
|
private void AutoLoadSN()
|
|
|
{
|
|
|
_OrderData = app.GetOrderData(_terminalID);
|
|
|
List<dynamic> HistoryOrderData = app.GetHistoryOrderData(_terminalID);
|
|
|
|
|
|
if (httpClient.CheckDataValid(_OrderData))
|
|
|
{
|
|
|
//查询到数据停止刷新数据
|
|
|
RefrenshProdData.Enabled = false;
|
|
|
if (labErrorMessage.Text == "所有任务单已全部完成!")
|
|
|
{
|
|
|
ShowMessage("请扫描产品过程条码!", Color.Green);
|
|
|
}
|
|
|
|
|
|
CountRead();
|
|
|
|
|
|
#region 加载已完成队列
|
|
|
List<dynamic> AllOrderData = HistoryOrderData.ToList();
|
|
|
try
|
|
|
{
|
|
|
AllOrderData.AddRange(_OrderData);
|
|
|
|
|
|
dgvProdList.AutoGenerateColumns = false;
|
|
|
dgvProdList.DataSource = AllOrderData;
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
// 把历史数据的背景色设置为绿色
|
|
|
if (httpClient.CheckDataValid(HistoryOrderData))
|
|
|
{
|
|
|
for (; i < HistoryOrderData.Count; i++)
|
|
|
{
|
|
|
dgvProdList.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
|
|
|
}
|
|
|
dgvProdList.Rows[0].Selected = false;
|
|
|
}
|
|
|
|
|
|
if (_OrderData.Count > 0)
|
|
|
{
|
|
|
string type = _OrderData[0]["model_type"].ToString().ToUpper().Trim();
|
|
|
|
|
|
if (type == "N")
|
|
|
{
|
|
|
// 把当前生产的数据背景色设置为黄色
|
|
|
dgvProdList.Rows[i].DefaultCellStyle.BackColor = Color.CornflowerBlue;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// 把当前生产的数据背景色设置为黄色
|
|
|
dgvProdList.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
|
|
|
}
|
|
|
}
|
|
|
dgvProdList.Update();
|
|
|
}
|
|
|
catch// (System.Exception ex)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
dgvProdList.AutoGenerateColumns = false;
|
|
|
if (_OrderData.Count > 0)
|
|
|
{
|
|
|
txtCarNo.Text = _OrderData[0]["number"].ToString();
|
|
|
txtSerialNumber.Text = _OrderData[0]["serial_number"].ToString();
|
|
|
txtPartLocation.Text = _OrderData[0]["enum_desc"].ToString();
|
|
|
txtModelName.Text = _OrderData[0]["model_name"].ToString();
|
|
|
txtPartSpec.Text = _OrderData[0]["part_spec"].ToString();
|
|
|
if (_OrderData[0]["edi_id"].ToString() != "0")
|
|
|
{
|
|
|
txtCSN.Visible = true;
|
|
|
lblCSN.Visible = true;
|
|
|
txtCSN.Text = _OrderData[0]["edi_id"].ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
txtCSN.Visible = false;
|
|
|
lblCSN.Visible = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//RefrenshProdData.Enabled = true;
|
|
|
|
|
|
LoadStepParameter();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ShowMessage("所有任务单已全部完成!", Color.Green);
|
|
|
txtSN.Focus();
|
|
|
|
|
|
dgvProdList.AutoGenerateColumns = false;
|
|
|
dgvProdList.DataSource = _OrderData;
|
|
|
|
|
|
RefrenshProdData.Enabled = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新队列
|
|
|
/// </summary>
|
|
|
private void RefreshQueue()
|
|
|
{
|
|
|
_OrderData = app.GetOrderData(_terminalID);
|
|
|
List<dynamic> HistoryOrderData = app.GetHistoryOrderData(_terminalID);
|
|
|
|
|
|
if (_OrderData.Count == 0)
|
|
|
{
|
|
|
RefrenshProdData.Enabled = true;
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 加载已完成队列
|
|
|
List<dynamic> AllOrderData = HistoryOrderData.ToList();
|
|
|
try
|
|
|
{
|
|
|
AllOrderData.AddRange(_OrderData);
|
|
|
|
|
|
|
|
|
dgvProdList.AutoGenerateColumns = false;
|
|
|
dgvProdList.DataSource = AllOrderData;
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
// 把历史数据的背景色设置为绿色
|
|
|
if (httpClient.CheckDataValid(HistoryOrderData))
|
|
|
{
|
|
|
for (; i < HistoryOrderData.Count; i++)
|
|
|
{
|
|
|
dgvProdList.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
|
|
|
}
|
|
|
dgvProdList.Rows[0].Selected = false;
|
|
|
}
|
|
|
|
|
|
if (_OrderData.Count > 0)
|
|
|
{
|
|
|
// 把当前生产的数据背景色设置为黄色
|
|
|
dgvProdList.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
|
|
|
}
|
|
|
|
|
|
|
|
|
dgvProdList.Update();
|
|
|
}
|
|
|
catch// (System.Exception ex)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
if (_OrderData.Count > 0)
|
|
|
{
|
|
|
txtCarNo.Text = _OrderData[0]["number"].ToString();
|
|
|
txtSerialNumber.Text = _OrderData[0]["serial_number"].ToString();
|
|
|
txtPartLocation.Text = _OrderData[0]["enum_desc"].ToString();
|
|
|
txtModelName.Text = _OrderData[0]["model_name"].ToString();
|
|
|
txtPartSpec.Text = _OrderData[0]["part_spec"].ToString();
|
|
|
txtCSN.Text = _OrderData[0]["edi_id"].ToString();
|
|
|
if (_OrderData[0]["edi_id"].ToString() != "0")
|
|
|
{
|
|
|
txtCSN.Visible = true;
|
|
|
lblCSN.Visible = true;
|
|
|
txtCSN.Text = _OrderData[0]["edi_id"].ToString();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
txtCSN.Visible = false;
|
|
|
lblCSN.Visible = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
LoadStepParameter();
|
|
|
|
|
|
}
|
|
|
|
|
|
//执行按键操作xx0
|
|
|
private void txtSN_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(txtSN.Text.Trim()))
|
|
|
return;
|
|
|
|
|
|
if (e.KeyChar != (char)13)
|
|
|
return;
|
|
|
|
|
|
labErrorMessage.Text = "";
|
|
|
|
|
|
if (txtSN.Text.Trim().ToUpper()=="BYPASS")
|
|
|
{
|
|
|
//发送OPC放行信号
|
|
|
bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
txtSN.Text = "";
|
|
|
ShowMessage("托盘放行信号已发送!", Color.Green);
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//释放加载的工步页面信息
|
|
|
//-------------------------2019-06-12------------------------------
|
|
|
if (step != null)
|
|
|
{
|
|
|
step.Dispose();
|
|
|
step = null;
|
|
|
CurrentStep.Dispose();
|
|
|
}
|
|
|
|
|
|
//mark 2019-01-24
|
|
|
try
|
|
|
{
|
|
|
string curr = app.getSerialNumberData(_OrderData[0]["serial_number"].ToString().ToUpper())[0]["current_status"].ToString();
|
|
|
if (app.validataLimit("GYRefTerminalList").Contains(_terminalID.ToString()) && ("9,1,8".Contains(curr)))
|
|
|
{
|
|
|
btnRefreshProdData_Click(null, null);
|
|
|
}
|
|
|
}
|
|
|
catch { }
|
|
|
//
|
|
|
|
|
|
_sn = txtSN.Text.Trim().ToUpper();
|
|
|
txtSN.Text = "";
|
|
|
txtSNBak.Text = _sn;
|
|
|
//poul 2019-03-21
|
|
|
if (_sn == "WRITETAG")
|
|
|
{
|
|
|
//RF182C.Write(BLANK_CODE);
|
|
|
if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "opc_ok")))
|
|
|
{
|
|
|
//发送OPC放行信号
|
|
|
bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
|
|
|
|
|
|
// 记录日志
|
|
|
WriteLog("txtSN_KeyPress()方法" + "" + ret.ToString() + " " + _sn + "放行信号发送成功!");
|
|
|
|
|
|
}
|
|
|
ShowMessage("写入空托盘成功!", Color.Green);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (_sn == "00000")
|
|
|
{
|
|
|
if (step != null)
|
|
|
{
|
|
|
step.Dispose();
|
|
|
step = null;
|
|
|
CurrentStep.Dispose();
|
|
|
|
|
|
flpSteps.Controls.Clear();
|
|
|
panControlArea.Controls.Clear();
|
|
|
panControlArea.Enabled = true;
|
|
|
}
|
|
|
|
|
|
RefreshQueue();
|
|
|
txtSN.Focus();
|
|
|
ShowMessage("任务单刷新成功!", Color.Green);
|
|
|
}
|
|
|
|
|
|
//强制放行码 passCode ="0123" ; BLANK_CODE="999999999999999999999999999999"
|
|
|
string passCode = app.prodPass();
|
|
|
if (_sn == passCode || _sn == BLANK_CODE)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "opc_ok")))
|
|
|
{
|
|
|
//发送OPC放行信号
|
|
|
bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
|
|
|
// 记录日志
|
|
|
WriteLog("txtSN_KeyPress()方法"+ ""+ret.ToString()+" "+_sn + "放行信号发送成功!");
|
|
|
|
|
|
}
|
|
|
ShowMessage("空托盘放行成功!", Color.Green);
|
|
|
txtSN.Text = string.Empty;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
List<dynamic> dt = null;
|
|
|
if (app.IsSN(_sn))
|
|
|
{
|
|
|
dt = app.snDetail(_sn);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ShowMessage("[" + _sn + "]输入错误,请扫描过程条码!", Color.Red);
|
|
|
txtSN.Text = string.Empty;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
#region 扫描间隔 2018-09-19暂时使用
|
|
|
|
|
|
|
|
|
//if (IsAllowPass())
|
|
|
//{
|
|
|
// _lastPassDatetime = DateTime.Now;
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// ShowMessage("red|扫描太快,请等待!", Color.Red);
|
|
|
// return;
|
|
|
//}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
currentStatus = 0;
|
|
|
List<dynamic> dtSerialNumberData = app.getSerialNumberData(_sn);
|
|
|
currentStatus = Convert.ToInt32(dtSerialNumberData[0]["current_status"]);
|
|
|
if (_OrderData.Count <= 0)
|
|
|
{
|
|
|
if (dtSerialNumberData.Count <= 0)
|
|
|
{
|
|
|
|
|
|
RefreshQueue();
|
|
|
txtSN.Focus();
|
|
|
ShowMessage("当前没有生产任务!", Color.Green);
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
currentStatus = Convert.ToInt32(dtSerialNumberData[0]["current_status"]);
|
|
|
if (currentStatus != 9 && currentStatus != 1 && currentStatus != 8)
|
|
|
{
|
|
|
RefreshQueue();
|
|
|
txtSN.Focus();
|
|
|
ShowMessage("当前没有生产任务!", Color.Green);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (currentStatus == 9 || currentStatus == 1 || currentStatus == 8)
|
|
|
{
|
|
|
|
|
|
if (currentStatus == 1)
|
|
|
{
|
|
|
ShowMessage("该条码未完成返工返修,请重新返工返修!", Color.Red);
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//-----------------2019-07-09 删除(2019-07-29 贵阳返工座椅回线后,下线工位跳队列异常,所以还原)
|
|
|
if (!_context.ContainsKey("serial_number"))
|
|
|
{
|
|
|
_context.Add("serial_number", _sn);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("serial_number");
|
|
|
_context.Add("serial_number", _sn);
|
|
|
}
|
|
|
|
|
|
//if (!_context.ContainsKey("terminal_id"))
|
|
|
//{
|
|
|
// _context.Add("terminal_id", _terminalID);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// _context.Remove("terminal_id");
|
|
|
// _context.Add("terminal_id", _terminalID);
|
|
|
//}
|
|
|
|
|
|
//if (!_context.ContainsKey("station_type"))
|
|
|
//{
|
|
|
// _context.Add("station_type", _stationType);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// _context.Remove("station_type");
|
|
|
// _context.Add("station_type", _stationType);
|
|
|
//}
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
ExecuteSteps(_sn);
|
|
|
//DoNextStep (true);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (_sn.ToUpper().ToString() == "PASS")
|
|
|
{
|
|
|
_sn = _OrderData[0]["serial_number"].ToString().ToUpper();
|
|
|
}
|
|
|
|
|
|
lblSerialNumber.Text = _sn;
|
|
|
//返工操作
|
|
|
if (_sn.ToUpper().ToString() == "REWORK" && _sn == "C")
|
|
|
{
|
|
|
FrmInputBoxRework frmInputBoxRework = new FrmInputBoxRework();
|
|
|
if (frmInputBoxRework.ShowDialog() != DialogResult.OK)
|
|
|
{
|
|
|
ShowMessage("返工过程条码扫描错误!", Color.Red);
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
string reworkSerialNumber = frmInputBoxRework.Input;
|
|
|
if (string.IsNullOrEmpty(reworkSerialNumber))
|
|
|
{
|
|
|
ShowMessage("返工过程条码扫描错误!", Color.Red);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (reworkSerialNumber != _OrderData[0]["serial_number"].ToString().ToUpper())
|
|
|
{
|
|
|
ShowMessage("扫描条码与当前队列第一条不匹配!", Color.Red);
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
app.SetSNStatusNG(reworkSerialNumber, 1);
|
|
|
|
|
|
app.UpdateViewBoard(_OrderData[0]["serial_number"].ToString().ToUpper(), _terminalID);
|
|
|
|
|
|
RefreshQueue();
|
|
|
txtSN.Focus();
|
|
|
ShowMessage("绑定成功!", Color.Green);
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_sn != _OrderData[0]["serial_number"].ToString().ToUpper())
|
|
|
{
|
|
|
|
|
|
ShowMessage("扫描条码与当前队列不匹配!", Color.Red);
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
//回收上一次的资源
|
|
|
//if ( step != null )
|
|
|
//{
|
|
|
// //释放加载的工步页面信息
|
|
|
// step .Dispose ();
|
|
|
// //释放完成工步的资源
|
|
|
// CurrentStep .Dispose ();
|
|
|
// step = null;
|
|
|
//}
|
|
|
|
|
|
//txtSpec.Text = _OrderData.Rows[0]["part_spec"].ToString();
|
|
|
//txtPart.Text = _OrderData.Rows[0]["enum_desc"].ToString();
|
|
|
//textModel.Text = _OrderData.Rows[0]["model_desc"].ToString();
|
|
|
}
|
|
|
|
|
|
// 只有设置为 NOT AUTO LOAD SN 时才在条码扫描后把条码加入到上下文中
|
|
|
|
|
|
//---------------------------------------2019-07-09 删除
|
|
|
//if (!_context.ContainsKey("serial_number"))
|
|
|
//{
|
|
|
// _context.Add("serial_number", _sn);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// //机器人扭矩采集工位没有完成工步这一操作(亦不会刷新SN),通过此方式刷新SN
|
|
|
// _context.Remove("serial_number");
|
|
|
// _context.Add("serial_number", _sn);
|
|
|
//}
|
|
|
//if (!_context.ContainsKey("terminal_id"))
|
|
|
//{
|
|
|
// _context.Add("terminal_id", _terminalID);
|
|
|
//}
|
|
|
|
|
|
//--------------------------------------
|
|
|
|
|
|
//检查过程条码的当前流程是否正确
|
|
|
if (GetProcessIsNecessary(_terminalID, _sn))
|
|
|
{
|
|
|
app.UpdateSNinProcessTime(_sn);
|
|
|
bool result = CheckRoute(_sn, _terminalID);
|
|
|
if (!result)
|
|
|
{
|
|
|
labErrorMessage.Text = ErrorMessage;
|
|
|
labErrorMessage.ForeColor = Color.Red;
|
|
|
txtSN.Text = string.Empty;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新进入流程时间
|
|
|
app.UpdateSNinProcessTime(_sn);
|
|
|
}
|
|
|
|
|
|
// 扫描了条码并按下回车,开始处理逻辑
|
|
|
if (!_context.ContainsKey("serial_number"))
|
|
|
{
|
|
|
_context.Add("serial_number", _sn);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("serial_number");
|
|
|
_context.Add("serial_number", _sn);
|
|
|
}
|
|
|
|
|
|
ExecuteSteps(_sn);
|
|
|
|
|
|
string stationType = app.stationType(_terminalID.ToString());
|
|
|
if (app.isExec("isExec") == "Y" ||string.IsNullOrEmpty( app.isExec("isExec")))
|
|
|
{
|
|
|
if (stationType == "C")
|
|
|
{
|
|
|
//更新条码状态为下线
|
|
|
app.updateStatus(_sn);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 所有的工步信息列表
|
|
|
/// </summary>
|
|
|
List<StepBase> _steps = new List<StepBase>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 当前正在执行的工步编号
|
|
|
/// </summary>
|
|
|
int _stepIndex = 0;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 当前正在执行的前台界面工步编号,以此判断步骤是否往下
|
|
|
/// </summary>
|
|
|
int _stepAction = 2;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否开始第一个工步操作
|
|
|
/// </summary>
|
|
|
bool isBeginWork = false;
|
|
|
bool isBeginTiming = false;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录工步的等待时间及操作时间
|
|
|
/// </summary>
|
|
|
DateTime eachWaitTime = DateTime.Now;
|
|
|
DateTime eachActionTime = DateTime.Now;
|
|
|
double waitSeconds = 0;
|
|
|
double actionSeconds = 0;
|
|
|
int RouteWaitSeconds = 0;
|
|
|
int RouteActionSeconds = 0;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工步执行步骤相关信息
|
|
|
/// </summary>
|
|
|
List<dynamic> StepData = null;
|
|
|
StepBase CurrentStep = new StepBase();
|
|
|
|
|
|
StepBase step = null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工步完成后是否释放工步页面加载信息
|
|
|
/// </summary>
|
|
|
private bool stepDispose = false;
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行本工位的逻辑
|
|
|
/// </summary>
|
|
|
/// <param name="p"></param>
|
|
|
private void ExecuteSteps(string sn)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
// 获取工步信息
|
|
|
StepData = app.GetRouteStepBySNAndTerminal(sn, _terminalID);
|
|
|
if (!httpClient.CheckDataValid(StepData))
|
|
|
{
|
|
|
ShowMessage("此工位没有配置工步,请联系相关人员!", Color.Red);
|
|
|
WriteErrorLog(string.Format("此工位没有配置工步,请联系相关人员!条码:{0},工位编号:{1}", sn, _terminalID), null);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 清除上一次的工步信息
|
|
|
try
|
|
|
{
|
|
|
_steps.Clear();
|
|
|
_stepIndex = 0;
|
|
|
_stepAction = 2;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
_stepIndex = 0;
|
|
|
_stepAction = 2;
|
|
|
}
|
|
|
|
|
|
flpSteps.Controls.Clear();
|
|
|
panControlArea.Controls.Clear();
|
|
|
panControlArea.Enabled = true;
|
|
|
|
|
|
// 筛选出带界面的工步信息
|
|
|
dynamic Rows = StepData.FirstOrDefault("action=0");
|
|
|
if (Rows != null && Rows.Length > 0)
|
|
|
{
|
|
|
#region 创建步进符号
|
|
|
Button btnStepSpec = new Button();
|
|
|
btnStepSpec.FlatStyle = FlatStyle.Popup;
|
|
|
btnStepSpec.Height = 40;
|
|
|
btnStepSpec.Width = 100;
|
|
|
btnStepSpec.Text = "步骤";
|
|
|
btnStepSpec.Font = new Font("微软雅黑", 13, FontStyle.Bold);
|
|
|
btnStepSpec.Enabled = false;
|
|
|
|
|
|
flpSteps.Controls.Add(btnStepSpec);
|
|
|
#endregion
|
|
|
|
|
|
for (int i = 0; i < Rows.Length; i++)
|
|
|
{
|
|
|
// 生成按钮并加到左侧的列表中
|
|
|
Button button = new Button();
|
|
|
|
|
|
button.Name = string.Format("btnStepTag{0}", i + 1);
|
|
|
button.FlatStyle = FlatStyle.Popup;
|
|
|
button.BackColor = Color.Green;
|
|
|
button.Font = new Font("微软雅黑", 25, FontStyle.Bold);
|
|
|
button.Height = 50;
|
|
|
button.Width = 100;
|
|
|
button.ForeColor = Color.White;
|
|
|
button.Text = (i + 1).ToString();
|
|
|
|
|
|
flpSteps.Controls.Add(button);
|
|
|
}
|
|
|
}
|
|
|
foreach (var dr in StepData)
|
|
|
{
|
|
|
string DllName = dr["dll_name"].ToString();
|
|
|
string ClassName = dr["class_name"].ToString();
|
|
|
|
|
|
if (!File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DllName)))
|
|
|
{
|
|
|
MessageBox.Show(string.Format("未找到文件 {0} !", DllName));
|
|
|
WriteErrorLog(string.Format("未找到文件 {0} !", DllName), null);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Assembly assembly = Assembly.LoadFrom(
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DllName));
|
|
|
|
|
|
if (assembly == null)
|
|
|
{
|
|
|
MessageBox.Show(
|
|
|
string.Format(
|
|
|
"加载 DLL: {0} 错误!",
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DllName)));
|
|
|
WriteErrorLog(string.Format(
|
|
|
"加载 DLL: {0} 错误!",
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DllName)), null);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
step = assembly.CreateInstance(
|
|
|
ClassName, false, BindingFlags.Default, null, null, null, null)
|
|
|
as StepBase;
|
|
|
|
|
|
if (step == null)
|
|
|
{
|
|
|
MessageBox.Show(string.Format("创建对象失败!类名:{0}", ClassName));
|
|
|
WriteErrorLog(string.Format("创建对象失败!类名:{0}", ClassName), null);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 初始化工步
|
|
|
step.InitContext(_context, httpClient, this);
|
|
|
//step.OnAction += new StepBase.ActionEventHandler(step_OnAction);
|
|
|
step.OnComplated += new StepBase.ComplateEventHandler(step_OnComplated);
|
|
|
step.OnFailed += new StepBase.ErrorEventHandler(step_OnFailed);
|
|
|
step.OnShowMessage += new StepBase.ShowMessageEventHandler(step_OnShowMessage);
|
|
|
step.OnStopStep += new StepBase.StopStepEventHandler(step_OnStopStep);
|
|
|
step.Name = dr["class_name"].ToString().Trim();
|
|
|
step.Dock = DockStyle.Fill;
|
|
|
step.action = Convert.ToInt32(dr["action"]);
|
|
|
|
|
|
// 需要交互的工步才显示
|
|
|
if (Convert.ToInt32(dr["action"]) == 0)
|
|
|
{
|
|
|
// 把工步添加到窗口
|
|
|
panControlArea.Controls.Add(step);
|
|
|
}
|
|
|
// 把工步添加到工步列表中
|
|
|
_steps.Add(step);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
MessageBox.Show(ex.ToString());
|
|
|
MessageBox.Show("创建对象失败,请检查类名是否包含命名空间,并继承自 StepBase 类!");
|
|
|
WriteErrorLog("创建对象失败,请检查类名是否包含命名空间,并继承自 StepBase 类!", ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
lblmag.Text = "";
|
|
|
// 执行第一个工步
|
|
|
// 第一个一个工步的执行
|
|
|
CurrentStep = _steps[_stepIndex];
|
|
|
|
|
|
_steps[_stepIndex++].Do();
|
|
|
|
|
|
isBeginTiming = true;
|
|
|
|
|
|
|
|
|
//开始执行设置工步1为正在执行中
|
|
|
//flpSteps.Controls[1].ForeColor = Color.Black;
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ShowMessage("系统出现异常!", Color.Red);
|
|
|
|
|
|
// 记录日志
|
|
|
WriteLog(" " + ex.ToString());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工步开始执行时调用,记录工步等待时间及操作时间
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
void step_OnAction(object sender, EventArgs e)
|
|
|
{
|
|
|
DateTime wait_time = DateTime.Now;
|
|
|
waitSeconds = wait_time.Subtract(eachWaitTime).TotalMilliseconds;
|
|
|
eachWaitTime = wait_time;
|
|
|
|
|
|
//节拍时间
|
|
|
int ct = app.GetJPHTime(_terminalID);
|
|
|
|
|
|
//修正进入倒计时后再更改颜色
|
|
|
lblActionTitle.BackColor = Color.Green;
|
|
|
lblWaitTime.BackColor = Color.Green;
|
|
|
|
|
|
RouteWaitSeconds = ct;
|
|
|
lblWaitTime.Text = ct.ToString();
|
|
|
RouteActionSeconds = ct;
|
|
|
|
|
|
timerRefrensh.Enabled = true;
|
|
|
}
|
|
|
|
|
|
|
|
|
//工步完成xx1
|
|
|
void step_OnComplated(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
DateTime action_time = DateTime.Now;
|
|
|
actionSeconds = action_time.Subtract(eachWaitTime).TotalMilliseconds;
|
|
|
eachWaitTime = action_time;
|
|
|
|
|
|
int route_id = 0, step_id = 0, seq = 0;
|
|
|
dynamic drRouteStep = StepData.FirstOrDefault("class_name = '" + CurrentStep.Name + "'");
|
|
|
if (drRouteStep.Length > 0)
|
|
|
{
|
|
|
route_id = Convert.ToInt32(drRouteStep[0]["route_id"]);
|
|
|
step_id = Convert.ToInt32(drRouteStep[0]["step_id"]);
|
|
|
seq = Convert.ToInt32(drRouteStep[0]["seq"]);
|
|
|
}
|
|
|
lock (app)
|
|
|
{
|
|
|
if (_stepIndex == _steps.Count)
|
|
|
{
|
|
|
//整个工序耗时记录
|
|
|
int subSeconds = RouteActionSeconds - Convert.ToInt32(lblWaitTime.Text);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 工步执行完成
|
|
|
if (_stepIndex == _steps.Count)
|
|
|
{
|
|
|
AllStepComplated();
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//-------------------------2017-04-14------------------------------
|
|
|
CurrentStep.Dispose();
|
|
|
//-------------------------2017-04-14------------------------------
|
|
|
|
|
|
_stepIndex++;
|
|
|
DoNextStep(true);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
// 记录日志
|
|
|
WriteLog(" " + ex.ToString());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void AllStepComplated()
|
|
|
{
|
|
|
|
|
|
|
|
|
if (GetProcessIsNecessary(_terminalID, _sn))
|
|
|
{
|
|
|
app.UpdateSNoutProcessTime(_sn);
|
|
|
bool result = RouteGO(_sn, _terminalID);
|
|
|
if (!result)
|
|
|
{
|
|
|
labErrorMessage.Text = ErrorMessage;
|
|
|
labErrorMessage.ForeColor = Color.Red;
|
|
|
txtSN.Text = string.Empty;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
snTravel();
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "opc_ok")))
|
|
|
{
|
|
|
string planCode = app.validataLimit("PlanCode");
|
|
|
string partLoc = app.getPartLocation(_sn);
|
|
|
if (planCode == "GY" && partLoc == "0A")
|
|
|
{
|
|
|
//贵阳三排是双托盘(托盘上的第一个产品完成后不发送放行信号),需要特殊处理
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//发送OPC放行信号
|
|
|
bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
}
|
|
|
|
|
|
// 记录日志
|
|
|
|
|
|
WriteLog("" + "条码:" + _sn + " 放行信号已发送!");
|
|
|
|
|
|
|
|
|
if (app.validataList("SNCutCheck") == "Y")
|
|
|
{
|
|
|
//余姚工厂使用
|
|
|
lblOPC.Text = _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + _OrderData[0]["enum_desc"].ToString() + "-" + "已放行";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lblOPC.Text = _sn + "-" + _OrderData[0]["enum_desc"].ToString() + "-" + "已放行";
|
|
|
|
|
|
}
|
|
|
lblOPC.ForeColor = Color.Green;
|
|
|
}
|
|
|
|
|
|
//更新队列
|
|
|
if (currentStatus != 9 && currentStatus != 8)
|
|
|
{
|
|
|
string _seq = _OrderData[0]["seq"].ToString();
|
|
|
bool _updateT = app.UpdateTerminalPoint(_seq, _terminalID);
|
|
|
}
|
|
|
|
|
|
//累加计数器值
|
|
|
CountAdd();
|
|
|
|
|
|
if (app.validataList("SNCutCheck") == "Y")
|
|
|
{
|
|
|
//余姚工厂使用
|
|
|
ShowMessage("流水号:[" + _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + _OrderData[0]["enum_desc"].ToString() + "]操作已完成,请继续操作!", Color.Green);
|
|
|
dddd(_sn.Substring(_sn.IndexOf("T") + 1, 12));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ShowMessage("流水号:[" + _sn + "-" + _OrderData[0]["enum_desc"].ToString() + "]操作已完成,请继续操作!", Color.Green);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//释放加载的工步页面信息
|
|
|
//-------------------------2017-04-14------------------------------
|
|
|
|
|
|
//timerRefrensh.Enabled = false;
|
|
|
_context.Clear();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
//释放工步定时器
|
|
|
CurrentStep.TickDispose();
|
|
|
}
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
txtSN.Text = string.Empty;
|
|
|
txtSN.Focus();
|
|
|
panControlArea.Controls.Clear();
|
|
|
panControlArea.Enabled = false;
|
|
|
_sn = "";
|
|
|
_steps = new List<StepBase>();
|
|
|
flpSteps.Controls.Clear();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
if (step != null)
|
|
|
{
|
|
|
step.Dispose();
|
|
|
}
|
|
|
CurrentStep.Dispose();
|
|
|
}
|
|
|
catch { }
|
|
|
|
|
|
RefreshQueue();
|
|
|
//-------------------------2017-04-14------------------------------
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
//进行下一个工步操作xx2
|
|
|
private void DoNextStep(bool isSucess)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string _stepName = CurrentStep.Name;
|
|
|
dynamic drStep = StepData.FirstOrDefault("class_name='" + _stepName.ToString() + "'");
|
|
|
if (drStep.Length > 0)
|
|
|
{
|
|
|
int next_seq = 0;
|
|
|
if (isSucess)
|
|
|
{
|
|
|
next_seq = Convert.ToInt32(drStep[0]["next_seq"]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
next_seq = Convert.ToInt32(drStep[0]["fail_seq"]);
|
|
|
}
|
|
|
dynamic drNextStep = StepData.FirstOrDefault("seq=" + next_seq + "");
|
|
|
if (drNextStep.Length > 0)
|
|
|
{
|
|
|
string class_name = drNextStep[0]["class_name"].ToString().Trim();
|
|
|
|
|
|
Predicate<StepBase> next = delegate(StepBase step)
|
|
|
{ return step.Name.Equals(class_name); };
|
|
|
|
|
|
CurrentStep = _steps.Find(next);
|
|
|
|
|
|
CurrentStep.Do();
|
|
|
|
|
|
|
|
|
//判断是否前台界面,设置步骤往下执行
|
|
|
if (_stepAction < flpSteps.Controls.Count)
|
|
|
{
|
|
|
flpSteps.Controls[_stepAction - 1].ForeColor = Color.White;
|
|
|
flpSteps.Controls[_stepAction].ForeColor = Color.Black;
|
|
|
_stepAction++;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
AllStepComplated();
|
|
|
|
|
|
#region
|
|
|
//ShowMessage("所有工步执行完成,请继续下一个操作!", Color.Green);
|
|
|
|
|
|
//WriteInfoLog("所有工步执行完成,请继续下一个操作!");
|
|
|
|
|
|
//app.UpdateSNoutProcessTime(_sn);
|
|
|
//if (GetProcessIsNecessary(_terminalID, _sn))
|
|
|
//{
|
|
|
// bool result = RouteGO(_sn, _terminalID);
|
|
|
// if (!result)
|
|
|
// {
|
|
|
// labErrorMessage.Text = ErrorMessage;
|
|
|
// labErrorMessage.ForeColor = Color.Red;
|
|
|
// txtSN.Text = string.Empty;
|
|
|
// return;
|
|
|
// }
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// snTravel();
|
|
|
//}
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "opc_ok")))
|
|
|
//{
|
|
|
|
|
|
// ////发送OPC放行信号
|
|
|
// //app.UpdatePLC("OPC_OK", _terminalID, "TRUE");
|
|
|
// ////发送OPC放行信号
|
|
|
// bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
|
|
|
// // 记录日志
|
|
|
// using (StreamWriter sw = new StreamWriter("PLC_Log-" + DateTime.Now.ToString("yyyy-MM") + ".txt", true))
|
|
|
// {
|
|
|
// sw.WriteLine(string.Format("{0}", "["
|
|
|
// + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
// + "] 条码:" + _sn + " 放行信号已发送!"));
|
|
|
// sw.Flush();
|
|
|
// sw.Close();
|
|
|
// }
|
|
|
|
|
|
// if (app.validataList("SNCutCheck") == "Y")
|
|
|
// {
|
|
|
// //余姚工厂使用
|
|
|
// lblOPC.Text = _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + _OrderData.Rows[0]["enum_desc"].ToString() + "-" + "已放行";
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// lblOPC.Text = _sn + "-" + _OrderData.Rows[0]["enum_desc"].ToString() + "-" + "已放行";
|
|
|
|
|
|
// }
|
|
|
// lblOPC.ForeColor = Color.Green;
|
|
|
//}
|
|
|
|
|
|
////工位操作计时器停止
|
|
|
//timerRefrensh.Enabled = false;
|
|
|
|
|
|
//_context.Clear();
|
|
|
|
|
|
////释放加载的工步页面信息
|
|
|
////step.Dispose();
|
|
|
|
|
|
////----------------------------------2019-07-09
|
|
|
//panControlArea.Controls.Clear();
|
|
|
//panControlArea.Enabled = false;
|
|
|
|
|
|
//txtSN.Text = string.Empty;
|
|
|
//txtSN.Focus();
|
|
|
|
|
|
////更新队列
|
|
|
//if (currentStatus != 9 || currentStatus != 8)
|
|
|
//{
|
|
|
// string _seq = _OrderData.Rows[0]["seq"].ToString();
|
|
|
// bool _updateT = app.UpdateTerminalPoint(_seq, _terminalID);
|
|
|
|
|
|
//}
|
|
|
////累加计数器值
|
|
|
//CountAdd();
|
|
|
|
|
|
////-------------------------2017-04-14------------------------------
|
|
|
//step.Dispose();
|
|
|
//CurrentStep.Dispose();
|
|
|
////-------------------------2017-04-14------------------------------
|
|
|
|
|
|
//RefreshQueue();
|
|
|
//if (app.validataList("SNCutCheck") == "Y")
|
|
|
//{
|
|
|
// //余姚工厂使用
|
|
|
// ShowMessage("流水号" + _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + _OrderData.Rows[0]["enum_desc"].ToString() + "上一个已完成,请继续操作!", Color.Green);
|
|
|
// dddd(_sn.Substring(_sn.IndexOf("T") + 1, 12));
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// ShowMessage("流水号" + _sn + "-" + _OrderData.Rows[0]["enum_desc"].ToString() + "上一个已完成,请继续操作!", Color.Green);
|
|
|
|
|
|
//}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
// 记录日志
|
|
|
WriteLog(" " + ex.ToString());
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 添加工位显示完成信息
|
|
|
/// </summary>
|
|
|
/// <param name="text"></param>
|
|
|
private void dddd(string text)
|
|
|
{
|
|
|
Label lblTitle = new Label();
|
|
|
lblTitle.Name = "lblmag";
|
|
|
lblTitle.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
|
lblTitle.Font = new System.Drawing.Font("宋体", 150F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
|
|
lblTitle.ForeColor = Color.Black;
|
|
|
lblTitle.Location = new System.Drawing.Point(0, 0);
|
|
|
lblTitle.Size = new System.Drawing.Size(709, 652);
|
|
|
//lblTitle.TabIndex = 0;
|
|
|
lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
|
|
|
|
|
lblTitle.Text = text + " 已完成";
|
|
|
|
|
|
|
|
|
panControlArea.Controls.Add(lblTitle);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 计算节拍是正数还是负数
|
|
|
/// </summary>
|
|
|
private bool minus = false;
|
|
|
private void timerRefrensh_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
int waitSeconds = Convert.ToInt32(lblWaitTime.Text);
|
|
|
if (lblWaitTime.Text != "0" && !minus)
|
|
|
{
|
|
|
lblWaitTime.Text = (waitSeconds - 1).ToString();
|
|
|
lblWaitTime.BackColor = Color.Green;
|
|
|
lblActionTitle.BackColor = Color.Green;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
minus = true;
|
|
|
lblWaitTime.Text = (waitSeconds + 1).ToString();
|
|
|
lblWaitTime.BackColor = Color.Red;
|
|
|
lblActionTitle.BackColor = Color.Red;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ShowMessage("计时器报错---" + ex.Message);
|
|
|
WriteErrorLog("计时器报错---" + ex.Message, ex);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 显示工步的信息
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="msg"></param>
|
|
|
void step_OnShowMessage(object sender, string msg)
|
|
|
{
|
|
|
// 显示工步的信息
|
|
|
string split = "|";
|
|
|
string[] array = null;
|
|
|
|
|
|
array = msg.Split(split.ToCharArray());
|
|
|
if (array.Length > 1)
|
|
|
{
|
|
|
if (array[0].ToUpper() == "RED")
|
|
|
{
|
|
|
OPC_FM();//余姚蜂鸣
|
|
|
|
|
|
|
|
|
this.labErrorMessage.ForeColor = Color.Red;
|
|
|
}
|
|
|
else if (array[0].ToUpper() == "GREEN")
|
|
|
{
|
|
|
this.labErrorMessage.ForeColor = Color.Green;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.labErrorMessage.ForeColor = Color.Black;
|
|
|
}
|
|
|
|
|
|
this.labErrorMessage.Text = array[1];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.labErrorMessage.ForeColor = Color.Black;
|
|
|
this.labErrorMessage.Text = msg;
|
|
|
}
|
|
|
|
|
|
WriteInfoLog(msg);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工步停止
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="msg"></param>
|
|
|
void step_OnStopStep(int type)
|
|
|
{
|
|
|
if (type == 1)
|
|
|
{
|
|
|
//返工处理
|
|
|
//2019-08-03Mark防止同一个条码进行两次返修
|
|
|
app.SetSNStatusNG(_context["serial_number"].ToString().ToUpper(), 1);
|
|
|
|
|
|
///2019-1-25Mark贵阳终检标记不良不更新SEQ
|
|
|
if (!app.validataLimit("GYInReworkNOseqList").Contains(_terminalID.ToString()))
|
|
|
{
|
|
|
app.UpdateViewBoard(_OrderData[0]["serial_number"].ToString().ToUpper(), _terminalID);
|
|
|
}
|
|
|
|
|
|
ShowMessage("条码【" + _context["serial_number"].ToString().ToUpper() + "】不良绑定成功!", Color.Green);
|
|
|
RefreshQueue();
|
|
|
txtSN.Focus();
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
|
|
|
step.Dispose();
|
|
|
try
|
|
|
{
|
|
|
step = null;
|
|
|
}
|
|
|
catch
|
|
|
{ }
|
|
|
CurrentStep.Dispose();
|
|
|
|
|
|
//写返工信号到PLC
|
|
|
app.UpdateOPCPointValue("OPC_ReWork", _terminalID, "TRUE");
|
|
|
|
|
|
// 记录日志
|
|
|
WriteLog(" " +_OrderData[0]["serial_number"].ToString().ToUpper() + " 写入成功!");
|
|
|
|
|
|
if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "OPC_OK")))
|
|
|
{
|
|
|
////发送OPC放行信号
|
|
|
bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
|
|
|
// 记录日志
|
|
|
|
|
|
WriteLog(" "+" 条码:" + _sn + " 放行信号已发送!");
|
|
|
|
|
|
if (app.validataList("SNCutCheck") == "Y")
|
|
|
{
|
|
|
//余姚工厂使用
|
|
|
lblOPC.Text = _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + "已放行";
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lblOPC.Text = _sn + "-" + "已放行";
|
|
|
|
|
|
}
|
|
|
lblOPC.ForeColor = Color.Green;
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
if (type == 2) //余姚
|
|
|
{
|
|
|
|
|
|
RefreshQueue();
|
|
|
txtSN.Focus();
|
|
|
ShowMessage("条码【" + _OrderData[0]["serial_number"].ToString().ToUpper() + "】不良绑定成功!", Color.Green);
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
|
|
|
step.Dispose();
|
|
|
try
|
|
|
{
|
|
|
step = null;
|
|
|
}
|
|
|
catch { }
|
|
|
CurrentStep.Dispose();
|
|
|
panControlArea.Controls.Clear();
|
|
|
panControlArea.Enabled = true;
|
|
|
|
|
|
if (app.validataList("SNCutCheck") == "Y")
|
|
|
{
|
|
|
//余姚工厂使用
|
|
|
lblOPC.Text = _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + "已放行";
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lblOPC.Text = _sn + "-" + "已放行";
|
|
|
|
|
|
}
|
|
|
lblOPC.ForeColor = Color.Green;
|
|
|
return;
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "OPC_OK")))
|
|
|
//{
|
|
|
// ////发送OPC放行信号
|
|
|
// bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
|
|
|
// // 记录日志
|
|
|
// using (StreamWriter sw = new StreamWriter("PLC_Log-" + DateTime.Now.ToString("yyyy-MM") + ".txt", true))
|
|
|
// {
|
|
|
// sw.WriteLine(string.Format("{0}", "["
|
|
|
// + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
// + "] 条码:" + _context["serial_number"].ToString() + " 放行信号已发送!"));
|
|
|
// sw.Flush();
|
|
|
// sw.Close();
|
|
|
// }
|
|
|
// if (app.validataList("SNCutCheck") == "Y")
|
|
|
// {
|
|
|
// //余姚工厂使用
|
|
|
// lblOPC.Text = _context["serial_number"].ToString().Substring(_context["serial_number"].ToString().IndexOf("T") + 1, 12) + "-" + "已放行";
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// lblOPC.Text = _context["serial_number"].ToString() + "-" + "已放行";
|
|
|
|
|
|
// }
|
|
|
// lblOPC.ForeColor = Color.Green;
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工步完成事件
|
|
|
/// </summary>
|
|
|
void step_OnFailed(object sender, EventArgs e)
|
|
|
{
|
|
|
// 预留方法,暂不使用
|
|
|
//throw new NotImplementedException();
|
|
|
DoNextStep(false);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 解锁
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnJumpStep_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (_OrderData.Count <= 0)
|
|
|
{
|
|
|
ShowMessage("当前没有生产队列,不能进行解锁操作!", Color.Red);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ShowMessage("请输入密码!", Color.Green);
|
|
|
FrmPassword frmPassword = new FrmPassword();
|
|
|
|
|
|
if (frmPassword.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
string SysPWD = app.GetJupStepPassword(_terminalID);
|
|
|
|
|
|
if (frmPassword.Password.Trim() != SysPWD.Trim())
|
|
|
{
|
|
|
ShowMessage("密码输入错误!", Color.Red);
|
|
|
txtSN.Focus();
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// 插入解锁记录
|
|
|
_sn = _OrderData[0]["serial_number"].ToString();
|
|
|
app.InsertUnlock(_terminalID.ToString(), _sn);
|
|
|
|
|
|
AllStepComplated();
|
|
|
|
|
|
ShowMessage("条码:" + _sn + "任务单已经跳过此工位!", Color.Green);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 主窗体界面
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void FrmMain_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
lblVersion.Text = "V" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
|
lblWaitTime.Text = "0";
|
|
|
WriteInfoLog("程序启动!");
|
|
|
btnUser.Text = app.GetUserInfo(_userNo)[0]["emp_no"].ToString() + "\n\r" + app.GetUserInfo(_userNo)[0]["emp_name"].ToString();
|
|
|
|
|
|
if (string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "OPC_ReadSN")))
|
|
|
{
|
|
|
ReadSN.Enabled = false;
|
|
|
}
|
|
|
_stationType = app.stationType(_terminalID.ToString());
|
|
|
|
|
|
if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "StartWriteRFID")))
|
|
|
{
|
|
|
bunWrite.Enabled = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
bunWrite.Enabled = false;
|
|
|
}
|
|
|
RefreshQueue();
|
|
|
//RefrenshProdData.Enabled = true;
|
|
|
//RefrenshProdData.Start();
|
|
|
|
|
|
|
|
|
//---------------------2019-07-09 删除
|
|
|
//if (!_context.ContainsKey("station_type"))
|
|
|
//{
|
|
|
// _context.Add("station_type", _stationType);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// _context.Remove("station_type");
|
|
|
// _context.Add("station_type", _stationType);
|
|
|
//}
|
|
|
|
|
|
//--------------------------------------------------
|
|
|
|
|
|
#region 2019-01-04 开启使用
|
|
|
//DataTable RFIDIP = app.GetRFIDIP(_terminalID, "RFID_IP");
|
|
|
|
|
|
//if (RFIDIP != null && RFIDIP.Rows.Count > 0)
|
|
|
//{
|
|
|
// string paramName = RFIDIP.Rows[0]["param_value"].ToString();
|
|
|
// string[] str = paramName.Split(':');
|
|
|
|
|
|
// string rfidIP = str[0].ToString();
|
|
|
// int port = Convert.ToInt32(str[1]);
|
|
|
// _RF182C = new RF182C();
|
|
|
// bool connectionStatus = _RF182C.Connect(rfidIP, port);
|
|
|
// if (connectionStatus == true)
|
|
|
// {
|
|
|
// bool initializeState = _RF182C.Initialization();
|
|
|
// if (initializeState == true)
|
|
|
// {
|
|
|
// lblRFIDState.Text = "RFID连接成功";
|
|
|
// lblRFIDState.ForeColor = Color.Green;
|
|
|
|
|
|
|
|
|
// initializeRFIDState = true;
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// lblRFIDState.Text = "RFID连接失败";
|
|
|
// lblRFIDState.ForeColor = Color.Red;
|
|
|
|
|
|
// initializeRFIDState = false;
|
|
|
// }
|
|
|
|
|
|
// if (!_context.ContainsKey("initializeRFIDState"))
|
|
|
// {
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// _context.Remove("initializeRFIDState");
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// lblRFIDState.Text = "RFID连接失败";
|
|
|
// lblRFIDState.ForeColor = Color.Red;
|
|
|
// initializeRFIDState = false;
|
|
|
|
|
|
// if (!_context.ContainsKey("initializeRFIDState"))
|
|
|
// {
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// _context.Remove("initializeRFIDState");
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
#endregion
|
|
|
tsmFullScreen_Click(null, null);
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 记录日志信息
|
|
|
/// <summary>
|
|
|
/// 写入日志信息
|
|
|
/// </summary>
|
|
|
/// <param name="message"></param>
|
|
|
private void WriteInfoLog(string message)
|
|
|
{
|
|
|
if (_loggerInfo.IsInfoEnabled)
|
|
|
{
|
|
|
_loggerInfo.Info(message);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void WriteTraceLog(string message)
|
|
|
{
|
|
|
if (_loggerTrace.IsWarnEnabled)
|
|
|
{
|
|
|
_loggerTrace.Warn(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void WriteErrorLog(string message, Exception ex)
|
|
|
{
|
|
|
if (_loggerError.IsErrorEnabled)
|
|
|
{
|
|
|
_loggerError.Error(message, ex);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
private void ServerDateTime_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
//lblDateTime.Text = "系统当前时间:" + app.GetServerTime().ToString("yyyy-MM-dd HH:mm");
|
|
|
try
|
|
|
{
|
|
|
|
|
|
#region 2019-01-04 开启使用
|
|
|
if (initializeRFIDState == true)
|
|
|
{
|
|
|
//_RF182C.ParseBuffer();
|
|
|
|
|
|
//if (_RF182C.TagState == true)
|
|
|
//{
|
|
|
// lblTagState.Text = "检测到TAG";
|
|
|
// lblTagState.ForeColor = Color.Green;
|
|
|
|
|
|
// RFID_TAGState = true;
|
|
|
|
|
|
// if (!_context.ContainsKey("TAGState"))
|
|
|
// {
|
|
|
// _context.Add("TAGState", RFID_TAGState);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// _context.Remove("TAGState");
|
|
|
// _context.Add("TAGState", RFID_TAGState);
|
|
|
// }
|
|
|
|
|
|
|
|
|
// DataTable RFIDOperationType = app.GetRFIDOperationType(_terminalID, "RFID_IP");
|
|
|
// string perationType = "";
|
|
|
// if (RFIDOperationType.Rows.Count > 0)
|
|
|
// {
|
|
|
// perationType = RFIDOperationType.Rows[0]["operation_type"].ToString();
|
|
|
// }
|
|
|
// if (perationType.ToUpper().ToString() == "READ")
|
|
|
// {
|
|
|
// RF182C.read();
|
|
|
|
|
|
// if (barcodeLast != RF182C.BarCode)
|
|
|
// {
|
|
|
// if (!string.IsNullOrEmpty(RF182C.BarCode))
|
|
|
// {
|
|
|
// barcodeLast = RF182C.BarCode;
|
|
|
// txtSN.Text = RF182C.BarCode;
|
|
|
// txtSN_KeyPress(null, new KeyPressEventArgs((char)13));
|
|
|
// txtSN.Text = "";
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// //ShowMessage("读取条码失败!", Color.Red);
|
|
|
// txtSN.Text = "";
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// return;
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// //barcodeLast = ""; 未检测到到TAG,读取条码清空
|
|
|
// lblTagState.Text = "未检测到TAG";
|
|
|
// lblTagState.ForeColor = Color.Yellow;
|
|
|
// RFID_TAGState = false;
|
|
|
|
|
|
// if (!_context.ContainsKey("TAGState"))
|
|
|
// {
|
|
|
// _context.Add("TAGState", RFID_TAGState);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// _context.Remove("TAGState");
|
|
|
// _context.Add("TAGState", RFID_TAGState);
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//给生产线PLC发送心跳信号
|
|
|
bool PLCHeartbeat = app.heartBeat(_terminalID.ToString() + "PLCHeartbeat");
|
|
|
if (PLCHeartbeat && "100003,100012,".Contains(_terminalID.ToString()))
|
|
|
{
|
|
|
app.sendHeartBeat(_terminalID.ToString() + "PLCHeartbeat");
|
|
|
}
|
|
|
|
|
|
//读取托盘到位信号
|
|
|
TAGState = app.ReadyPlc("OPC_TAGState", _terminalID).ToString().ToUpper();
|
|
|
|
|
|
if (TAGState == "TRUE")
|
|
|
{
|
|
|
lblTagState.Text = "检测到TAG";
|
|
|
lblTagState.ForeColor = Color.Green;
|
|
|
if (!_context.ContainsKey("TAGState"))
|
|
|
{
|
|
|
_context.Add("TAGState", TAGState);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("TAGState");
|
|
|
_context.Add("TAGState", TAGState);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lblTagState.Text = "未检测到TAG";
|
|
|
lblTagState.ForeColor = Color.Red;
|
|
|
|
|
|
if (!_context.ContainsKey("TAGState"))
|
|
|
{
|
|
|
_context.Add("TAGState", TAGState);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("TAGState");
|
|
|
_context.Add("TAGState", TAGState);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
//ServerDateTime .Enabled = false;
|
|
|
TAGState = "False";
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 读取RFID条码
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void ReadSN_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
ReadSN.Enabled = false;
|
|
|
string planCode = app.validataLimit("PlanCode");
|
|
|
string partLoc = app.getPartLocation(_sn);
|
|
|
if (planCode == "GY" && partLoc == "0B") //贵阳三排是双托盘(托盘上的第二个产品不需要读取RFID),需要特殊处理
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "OPC_ReadSN")))
|
|
|
//{
|
|
|
bool TAGStates = false;
|
|
|
if (!string.IsNullOrEmpty(TAGState.ToString()))
|
|
|
{
|
|
|
TAGStates = Convert.ToBoolean(TAGState.ToString());
|
|
|
}
|
|
|
|
|
|
if (TAGStates == false)
|
|
|
{
|
|
|
//ShowMessage("托盘未到位!", Color.Red);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string SN = app.ReadyPlc("OPC_ReadSN", _terminalID).ToString().Trim().ToUpper();
|
|
|
if (!string.IsNullOrEmpty(SN))
|
|
|
{
|
|
|
if (_OldSN != SN)
|
|
|
{
|
|
|
|
|
|
_OldSN = SN;
|
|
|
txtSN.Text = SN;
|
|
|
//执行回车
|
|
|
txtSN_KeyPress(null, new KeyPressEventArgs((char)13));
|
|
|
|
|
|
txtSN.Text = "";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
txtSN.Text = "";
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//ShowMessage("读取条码失败!", Color.Red);
|
|
|
//return;
|
|
|
}
|
|
|
}
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// return;
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
// 记录日志
|
|
|
|
|
|
WriteLog(" " + ex.ToString());
|
|
|
return;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
ReadSN.Enabled = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新队列
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void RefrenshProdData_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
RefrenshProdData.Enabled = false;
|
|
|
RefrenshProdData.Stop();
|
|
|
|
|
|
if (step == null)
|
|
|
{
|
|
|
txtSN.Focus();
|
|
|
txtSN.SelectAll();
|
|
|
}
|
|
|
|
|
|
AutoLoadSN();
|
|
|
|
|
|
//RefrenshProdData.Enabled = false;
|
|
|
//RefrenshProdData.Stop();
|
|
|
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
RefrenshProdData.Enabled = true;
|
|
|
RefrenshProdData.Start();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 添加上下文参数
|
|
|
/// </summary>
|
|
|
private void LoadStepParameter()
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
bool ShowABTest = app.GetTerminalParams(_terminalID, "ShowABTest") == "Y";
|
|
|
bool ShowCharge = app.GetTerminalParams(_terminalID, "ShowCharge") == "Y";
|
|
|
|
|
|
|
|
|
// 添加上下文参数
|
|
|
|
|
|
|
|
|
|
|
|
if (!_context.ContainsKey("station_type"))
|
|
|
{
|
|
|
_context.Add("station_type", _stationType);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("station_type");
|
|
|
_context.Add("station_type", _stationType);
|
|
|
}
|
|
|
|
|
|
//if (!_context.ContainsKey("m_csPrinter"))
|
|
|
//{
|
|
|
// _context.Add("m_csPrinter", m_csPrinter);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// _context.Remove("m_csPrinter");
|
|
|
// _context.Add("m_csPrinter", m_csPrinter);
|
|
|
//}
|
|
|
|
|
|
//if (!_context.ContainsKey("serial_number"))
|
|
|
//{
|
|
|
// _context.Add("serial_number", _sn);
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// _context.Remove("serial_number");
|
|
|
// _context.Add("serial_number", _sn);
|
|
|
//}
|
|
|
|
|
|
if (!_context.ContainsKey("terminal_id"))
|
|
|
{
|
|
|
_context.Add("terminal_id", _terminalID);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("terminal_id");
|
|
|
_context.Add("terminal_id", _terminalID);
|
|
|
}
|
|
|
|
|
|
if (!_context.ContainsKey("ShowABTest"))
|
|
|
{
|
|
|
_context.Add("ShowABTest", ShowABTest.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("ShowABTest");
|
|
|
_context.Add("ShowABTest", ShowABTest.ToString());
|
|
|
}
|
|
|
|
|
|
if (!_context.ContainsKey("ShowCharge"))
|
|
|
{
|
|
|
_context.Add("ShowCharge", ShowCharge.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("ShowCharge");
|
|
|
_context.Add("ShowCharge", ShowCharge.ToString());
|
|
|
}
|
|
|
|
|
|
if (!_context.ContainsKey("TAGState"))
|
|
|
{
|
|
|
_context.Add("TAGState", TAGState);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("TAGState");
|
|
|
_context.Add("TAGState", TAGState);
|
|
|
}
|
|
|
|
|
|
if (!_context.ContainsKey("initializeRFIDState"))
|
|
|
{
|
|
|
_context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("initializeRFIDState");
|
|
|
_context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
}
|
|
|
|
|
|
//添加mes_step_params中配置的数据
|
|
|
List<dynamic> StepParams = app.GetStepParams();
|
|
|
|
|
|
foreach (var dr in StepParams)
|
|
|
{
|
|
|
|
|
|
|
|
|
if (!_context.ContainsKey(dr["param_name"].ToString()))
|
|
|
{
|
|
|
_context.Add(dr["param_name"].ToString(), dr["param_value"].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove(dr["param_name"].ToString());
|
|
|
_context.Add(dr["param_name"].ToString(), dr["param_value"].ToString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_OrderData.Count > 0)
|
|
|
{
|
|
|
if (!_context.ContainsKey("serial_number"))
|
|
|
{
|
|
|
_context.Add("serial_number", _OrderData[0]["serial_number"].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("serial_number");
|
|
|
_context.Add("serial_number", _OrderData[0]["serial_number"].ToString());
|
|
|
}
|
|
|
|
|
|
if (_stationType == "A")
|
|
|
{
|
|
|
txtSN.Text = _context["serial_number"].ToString();
|
|
|
txtSN_KeyPress(null, new KeyPressEventArgs((char)13));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string planCode = app.validataLimit("PlanCode");
|
|
|
string partLoc = app.getPartLocation(_context["serial_number"].ToString());
|
|
|
if (planCode == "GY" && partLoc == "0B") //贵阳三排是双托盘(托盘上的第二个产品自动触发扫描),需要特殊处理
|
|
|
{
|
|
|
txtSN.Text = _context["serial_number"].ToString();
|
|
|
txtSN_KeyPress(null, new KeyPressEventArgs((char)13));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void txtSN_Enter(object sender, EventArgs e)
|
|
|
{
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.BackColor = Color.PeachPuff;
|
|
|
}
|
|
|
|
|
|
private void txtSN_Leave(object sender, EventArgs e)
|
|
|
{
|
|
|
txtSN.BackColor = Color.White;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 计数
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnPrdCount_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
txtSN.SelectAll();
|
|
|
txtSN.Focus();
|
|
|
|
|
|
//让用户确认
|
|
|
if (MessageBox.Show(string.Format(" 确定初始计数器吗? "), "信息提示",
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
labPrdCount.Text = "0";
|
|
|
|
|
|
try
|
|
|
{
|
|
|
StreamWriter sw = new StreamWriter("InPdlineCount.txt");
|
|
|
sw.Write("0");
|
|
|
sw.Flush();
|
|
|
sw.Close();
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
ShowMessage("计数器更新错误,未知!", Color.Red);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 计数器更新
|
|
|
/// </summary>
|
|
|
private void CountRead()
|
|
|
{
|
|
|
//try
|
|
|
//{
|
|
|
// if (File.Exists("InPdlineCount.txt"))
|
|
|
// {
|
|
|
// FileStream fs = new FileStream(@"InPdlineCount.txt", FileMode.Open);
|
|
|
// StreamReader sr = new StreamReader(fs);
|
|
|
|
|
|
// string content = sr.ReadToEnd(); //一次性读取全部数据
|
|
|
// btnPrdCount.Text = content;
|
|
|
// fs.Close();
|
|
|
// sr.Close();
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// btnPrdCount.Text = "0";
|
|
|
// }
|
|
|
//}
|
|
|
//catch
|
|
|
//{
|
|
|
// btnPrdCount.Text = "0";
|
|
|
// ShowMessage("计数器更新错误,未知!");
|
|
|
//}
|
|
|
|
|
|
//mark 2019-01-24
|
|
|
try
|
|
|
{
|
|
|
//获取班别
|
|
|
string ShiftID = app.getShiftID();
|
|
|
int dataQty = 0;
|
|
|
if (ShiftID == "1001")
|
|
|
{
|
|
|
dataQty = 0;
|
|
|
}
|
|
|
else if (ShiftID == "1002")
|
|
|
{
|
|
|
dataQty = 1;
|
|
|
}
|
|
|
|
|
|
labPrdCount.Text = app.getActualQty(dataQty, ShiftID, _terminalID);
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
labPrdCount.Text = "0";
|
|
|
ShowMessage("计数器更新错误,未知!", Color.Red);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 计数器更新
|
|
|
/// </summary>
|
|
|
private void CountAdd()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//获取班别
|
|
|
string ShiftID = app.getShiftID();
|
|
|
int dataQty = 0;
|
|
|
if (ShiftID == "1001")
|
|
|
{
|
|
|
dataQty = 0;
|
|
|
}
|
|
|
else if (ShiftID == "1002")
|
|
|
{
|
|
|
dataQty = 1;
|
|
|
}
|
|
|
|
|
|
labPrdCount.Text = app.getActualQty(dataQty, ShiftID, _terminalID);
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
labPrdCount.Text = "0";
|
|
|
ShowMessage("计数器更新错误,未知!", Color.Red);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 补打
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnReprint_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
FrmPassword frmPassword = new FrmPassword();
|
|
|
|
|
|
if (frmPassword.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
string SysPWD = app.GetSNReprintPassword();
|
|
|
|
|
|
if (frmPassword.Password.Trim() == SysPWD.Trim())
|
|
|
{
|
|
|
FrmReprint frmReprint = new FrmReprint(app);
|
|
|
frmReprint.ShowDialog();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("密码错误!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 全屏显示
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void tsmFullScreen_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (this.WindowState != FormWindowState.Maximized)
|
|
|
{
|
|
|
//this.ShowInTaskbar = false;
|
|
|
//this.FormBorderStyle = FormBorderStyle.None;
|
|
|
this.WindowState = FormWindowState.Maximized;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 退出全屏
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void tsmQuitFullScreen_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (this.WindowState == FormWindowState.Maximized)
|
|
|
{
|
|
|
this.ShowInTaskbar = true;
|
|
|
this.FormBorderStyle = FormBorderStyle.Sizable;
|
|
|
// 把窗体设置为与屏幕一样大
|
|
|
this.Bounds = Screen.PrimaryScreen.Bounds;
|
|
|
this.WindowState = FormWindowState.Normal;
|
|
|
|
|
|
// 重新加载数据,否则DataGridView的背景色着色会丢失
|
|
|
//LoadData();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 处理按键
|
|
|
/// </summary>
|
|
|
/// <param name="msg"></param>
|
|
|
/// <param name="keyData"></param>
|
|
|
/// <returns></returns>
|
|
|
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
|
|
|
{
|
|
|
int WM_KEYDOWN = 256;
|
|
|
int WM_SYSKEYDOWN = 260;
|
|
|
|
|
|
if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
|
|
|
{
|
|
|
switch (keyData)
|
|
|
{
|
|
|
// ESC 退出全屏
|
|
|
case Keys.Escape:
|
|
|
tsmQuitFullScreen_Click(null, null);
|
|
|
break;
|
|
|
// F5 全屏
|
|
|
case Keys.F5:
|
|
|
tsmFullScreen_Click(null, null);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 任务单刷新
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnRefreshProdData_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (step != null)
|
|
|
{
|
|
|
step.Dispose();
|
|
|
step = null;
|
|
|
CurrentStep.Dispose();
|
|
|
|
|
|
flpSteps.Controls.Clear();
|
|
|
panControlArea.Controls.Clear();
|
|
|
panControlArea.Enabled = true;
|
|
|
}
|
|
|
barcodeLast = "";
|
|
|
RefreshQueue();
|
|
|
txtSN.Focus();
|
|
|
ShowMessage("任务单刷新成功!", Color.Green);
|
|
|
ReadSN.Enabled = true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 退出系统
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnEXIT_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
string printName = "lppa";
|
|
|
KillProcess(printName); //关闭打印进程
|
|
|
|
|
|
|
|
|
if (MessageBox.Show("确定退出系统?", "提示",
|
|
|
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
|
|
|
{
|
|
|
System.Environment.Exit(System.Environment.ExitCode);
|
|
|
this.Dispose(false);
|
|
|
this.Close();
|
|
|
}
|
|
|
|
|
|
txtSN.Focus();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 错误信息
|
|
|
/// </summary>
|
|
|
public string ErrorMessage { get; private set; }
|
|
|
|
|
|
#region 流程管控
|
|
|
/// <summary>
|
|
|
/// 检查过程条码的当前流程是否正确
|
|
|
/// </summary>
|
|
|
/// <param name="sn">过程条码</param>
|
|
|
/// <param name="terminalID">工位 ID</param>
|
|
|
/// <returns>流程是否正确</returns>
|
|
|
public bool CheckRoute(string sn, int terminalID)
|
|
|
{
|
|
|
ErrorMessage = string.Empty;
|
|
|
|
|
|
var SNRow = GetSerialNumberData(sn);
|
|
|
|
|
|
if (SNRow == null)
|
|
|
{
|
|
|
ErrorMessage = "条码 " + sn + " 不存在";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int routeID = Convert.ToInt32(SNRow["route_id"].ToString());
|
|
|
|
|
|
if (routeID == 0)
|
|
|
{
|
|
|
ErrorMessage = "未查询到 " + sn + " 对应的流程";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int status = Convert.ToInt32(SNRow["current_status"]);
|
|
|
|
|
|
if (status == 1)
|
|
|
{
|
|
|
ErrorMessage = "条码 " + sn + " 属于不良品";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int ProcessID = GetProcessID(terminalID);
|
|
|
|
|
|
if (ProcessID == 0)
|
|
|
{
|
|
|
ErrorMessage = "未查询到 " + terminalID + " 对应的制程编号";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int LastProcessID = GetRouteLastProcessID(routeID);
|
|
|
|
|
|
if (LastProcessID == 0)
|
|
|
{
|
|
|
ErrorMessage = "获取流程 " + routeID + " 的最后一站失败";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int FirstProcessID = GetRouteFirstProcessID(routeID);
|
|
|
|
|
|
if (FirstProcessID == 0)
|
|
|
{
|
|
|
ErrorMessage = "获取流程 " + routeID + " 的第一站失败";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 上线
|
|
|
if (ProcessID == FirstProcessID)
|
|
|
{
|
|
|
if (SNRow["process_id"].ToString() != "0")
|
|
|
{
|
|
|
ErrorMessage = "条码已经上线," + sn;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 条码的当前制程
|
|
|
int CurrentProcessID = Convert.ToInt32(SNRow["process_id"]);
|
|
|
|
|
|
if (!CheckRouteProcessID(routeID, ProcessID, CurrentProcessID))
|
|
|
{
|
|
|
string CurrentProcessName = GetProcessName(CurrentProcessID);
|
|
|
|
|
|
if (CurrentProcessID == 0)
|
|
|
CurrentProcessName = "待上线";
|
|
|
|
|
|
ErrorMessage = "流程错误,最后工站: " + CurrentProcessName;
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 下线
|
|
|
if (ProcessID == LastProcessID)
|
|
|
{
|
|
|
if (SNRow["next_process"].ToString() == "0" && SNRow["process_id"].ToString() != "0")
|
|
|
{
|
|
|
ErrorMessage = "条码已经下线," + sn;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 良品,走到下一个流程
|
|
|
/// </summary>
|
|
|
/// <param name="sn">过程条码</param>
|
|
|
/// <param name="terminalID">工站编号</param>
|
|
|
/// <returns>执行结果</returns>
|
|
|
public bool RouteGO(string sn, int terminalID)
|
|
|
{
|
|
|
var SNRow = GetSerialNumberData(sn);
|
|
|
|
|
|
if (SNRow == null)
|
|
|
{
|
|
|
ErrorMessage = "条码 " + sn + " 不存在";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int routeID = Convert.ToInt32(SNRow["route_id"].ToString());
|
|
|
|
|
|
if (routeID == 0)
|
|
|
{
|
|
|
ErrorMessage = "未查询到 " + sn + " 对应的流程";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int status = Convert.ToInt32(SNRow["current_status"]);
|
|
|
|
|
|
if (status == 1)
|
|
|
{
|
|
|
ErrorMessage = "条码 " + sn + " 属于不良品";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int ProcessID = GetProcessID(terminalID);
|
|
|
|
|
|
if (ProcessID == 0)
|
|
|
{
|
|
|
ErrorMessage = "未查询到 " + terminalID + " 对应的制程编号";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int LastProcessID = GetRouteLastProcessID(routeID);
|
|
|
|
|
|
if (LastProcessID == 0)
|
|
|
{
|
|
|
ErrorMessage = "获取流程 " + routeID + " 的最后一站失败";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int FirstProcessID = GetRouteFirstProcessID(routeID);
|
|
|
|
|
|
if (FirstProcessID == 0)
|
|
|
{
|
|
|
ErrorMessage = "获取流程 " + routeID + " 的第一站失败";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 上线
|
|
|
if (ProcessID == FirstProcessID)
|
|
|
{
|
|
|
if (SNRow["process_id"].ToString() != "0")
|
|
|
{
|
|
|
ErrorMessage = "条码已经上线," + sn;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return SNGo(sn, terminalID, routeID, ProcessID, 0);
|
|
|
}
|
|
|
|
|
|
// 条码的当前制程
|
|
|
int CurrentProcessID = Convert.ToInt32(SNRow["process_id"]);
|
|
|
|
|
|
if (!CheckRouteProcessID(routeID, ProcessID, CurrentProcessID))
|
|
|
{
|
|
|
string CurrentProcessName = GetProcessName(CurrentProcessID);
|
|
|
|
|
|
if (CurrentProcessID == 0)
|
|
|
CurrentProcessName = "待上线";
|
|
|
|
|
|
ErrorMessage = "流程错误,最后工站: " + CurrentProcessName;
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 下线
|
|
|
if (ProcessID == LastProcessID)
|
|
|
{
|
|
|
if (SNRow["next_process"].ToString() == "0" && SNRow["process_id"].ToString() != "0")
|
|
|
{
|
|
|
ErrorMessage = "条码已经下线," + sn;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return SNGo(sn, terminalID, routeID, ProcessID, 2);
|
|
|
}
|
|
|
|
|
|
// 下一站
|
|
|
return SNGo(sn, terminalID, routeID, ProcessID, 1);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新条码相关的数据
|
|
|
/// </summary>
|
|
|
/// <param name="sn">条码</param>
|
|
|
/// <param name="terminalID">工站编号</param>
|
|
|
/// <param name="routeID">流程编号</param>
|
|
|
/// <param name="ProcessID">制程编号</param>
|
|
|
/// <param name="status">状态, 0=上线,1=下一站,2=下线</param>
|
|
|
/// <returns>是否更新成功</returns>
|
|
|
private bool SNGo(string sn, int terminalID, int routeID, int ProcessID, int status)
|
|
|
{
|
|
|
|
|
|
List<string> SqlStrings = new List<string>();
|
|
|
List<Dictionary<string, object>> Parameters = new List<Dictionary<string, object>>();
|
|
|
|
|
|
string Sql;
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
// 更新条码状态
|
|
|
Sql = GetSqlForUpdateSNStatus(sn, terminalID, routeID, ProcessID, status == 2);
|
|
|
|
|
|
if (string.IsNullOrEmpty(Sql))
|
|
|
return false;
|
|
|
|
|
|
SqlStrings.Add(Sql);
|
|
|
Parameters.Add(Params);
|
|
|
|
|
|
// 插入历史记录
|
|
|
SqlStrings.Add("insert into g_sn_travel select * from g_sn_status where serial_number=@sn");
|
|
|
Params.Add("@sn", sn);
|
|
|
Parameters.Add(Params);
|
|
|
|
|
|
if (status != 1)
|
|
|
{
|
|
|
int WorkorderID = GetWorkorderIDBySN(sn);
|
|
|
|
|
|
if (WorkorderID == -1)
|
|
|
return false;
|
|
|
|
|
|
// 更新工单的上线时间
|
|
|
SqlStrings.Add(GetSqlForUpdateWorkorder(WorkorderID, status == 0));
|
|
|
Params = new Dictionary<string, object>(1);
|
|
|
Params.Add("@workorder_id", WorkorderID);
|
|
|
Parameters.Add(Params);
|
|
|
}
|
|
|
|
|
|
// 由事务批次执行方式改为单个 SQL 执行,解决偶发性死锁的问题
|
|
|
for (int i = 0; i < SqlStrings.Count; i++)
|
|
|
{
|
|
|
httpClient.Execute(SqlStrings[i], Parameters[i]);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取更新工单的 SQL 语句(带有 @workorder_id 变量,需要填充)
|
|
|
/// </summary>
|
|
|
/// <param name="workorderID">工单编号</param>
|
|
|
/// <param name="inPDLine">true=上线时间,false=下线时间</param>
|
|
|
/// <returns>UPDATE SQL 语句</returns>
|
|
|
private string GetSqlForUpdateWorkorder(int workorderID, bool inPDLine)
|
|
|
{
|
|
|
Dictionary<string, object> Values = new Dictionary<string, object>();
|
|
|
DateTime time = app.GetServerTime();
|
|
|
|
|
|
// 上线
|
|
|
if (inPDLine)
|
|
|
{
|
|
|
Values.Add("in_pdline_ymd", time.ToString("yyyy-MM-dd"));
|
|
|
Values.Add("in_pdline_hms", time.ToString("HH:mm:ss"));
|
|
|
}
|
|
|
else // 下线
|
|
|
{
|
|
|
Values.Add("out_pdline_ymd", time.ToString("yyyy-MM-dd"));
|
|
|
Values.Add("out_pdline_hms", time.ToString("HH:mm:ss"));
|
|
|
}
|
|
|
|
|
|
return app.Update("g_workorder", Values, " where ruid=@workorder_id", false);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据过程条码查询对应的工单编号
|
|
|
/// </summary>
|
|
|
/// <param name="sn">过程条码</param>
|
|
|
/// <returns>工单编号</returns>
|
|
|
private int GetWorkorderIDBySN(string sn)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select c.ruid from g_sn_status a, g_workorder_detail b, g_workorder c " +
|
|
|
"where a.wo_detail_id=b.ruid and b.workorder_id=c.ruid and a.serial_number=@sn";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@sn", sn);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
{
|
|
|
StringBuilder SqlStringBuilder = new StringBuilder(1024);
|
|
|
SqlStringBuilder.Append("select b.ruid from g_sn_status a, g_workorder_base b ");
|
|
|
SqlStringBuilder.Append("where a.workorder=b.workorder_no and a.serial_number=@sn ");
|
|
|
|
|
|
dt = httpClient.GetEntityList(SqlStringBuilder.ToString(), Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
{
|
|
|
ErrorMessage = "根据过程条码查询工单编号失败, " + sn;
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return Convert.ToInt32(dt[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取更新过程条码的 SQL 语句(带有 @sn 变量,需要填充)
|
|
|
/// </summary>
|
|
|
/// <param name="sn">过程条码</param>
|
|
|
/// <param name="terminalID">工站编号</param>
|
|
|
/// <param name="routeID">流程编号</param>
|
|
|
/// <param name="ProcessID">制程编号</param>
|
|
|
/// <param name="isOutPDLine">下线标志,下线时 next_process = 0</param>
|
|
|
/// <returns>UPDATE SQL 语句</returns>
|
|
|
private string GetSqlForUpdateSNStatus(string sn, int terminalID, int routeID, int ProcessID, bool isOutPDLine)
|
|
|
{
|
|
|
List<dynamic> TerminalData = GetTerminalData(terminalID);
|
|
|
|
|
|
if (!CheckDataTableInvalid(TerminalData))
|
|
|
{
|
|
|
ErrorMessage = "UpdateSNStatus(), 获取工站数据失败";
|
|
|
return string.Empty;
|
|
|
}
|
|
|
|
|
|
Dictionary<string, object> Values = new Dictionary<string, object>();
|
|
|
|
|
|
Values.Add("pdline_id", Convert.ToInt32(TerminalData[0]["pdline_id"].ToString()));
|
|
|
Values.Add("stage_id", Convert.ToInt32(TerminalData[0]["stage_id"].ToString()));
|
|
|
Values.Add("terminal_id", terminalID);
|
|
|
Values.Add("process_id", ProcessID);
|
|
|
Values.Add("in_process_time", GetOutProcessTime(sn));
|
|
|
Values.Add("out_process_time", app.GetServerTime().ToString());
|
|
|
|
|
|
if (isOutPDLine)
|
|
|
Values.Add("next_process", 0);
|
|
|
else
|
|
|
Values.Add("next_process", GetRouteNextProcessID(routeID, ProcessID));
|
|
|
|
|
|
return app.Update("g_sn_status", Values, " where serial_number=@sn", false);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取工站数据
|
|
|
/// </summary>
|
|
|
/// <param name="terminalID">工站编号</param>
|
|
|
/// <returns>工站数据</returns>
|
|
|
private List<dynamic> GetTerminalData(int terminalID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select * from sys_terminal where terminal_id=@terminal_id";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@terminal_id", terminalID);
|
|
|
|
|
|
return httpClient.GetEntityList(SqlString, Params);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取过程条码的出站时间
|
|
|
/// </summary>
|
|
|
/// <param name="sn">过程条码</param>
|
|
|
/// <returns>出站时间</returns>
|
|
|
private string GetOutProcessTime(string sn)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select out_process_time from g_sn_status where serial_number=@sn";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@sn", sn);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return string.Empty;
|
|
|
|
|
|
return dt[0][0].ToString();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取流程中下一站的 ID
|
|
|
/// </summary>
|
|
|
/// <param name="routeID">流程编号</param>
|
|
|
/// <param name="processID">当前站的 process id</param>
|
|
|
/// <returns>下一站的 process id</returns>
|
|
|
public int GetRouteNextProcessID(int routeID, int processID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select next_process_id from sys_route_detail where route_id=@route_id and process_id=@process_id";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@route_id", routeID);
|
|
|
Params.Add("@process_id", processID);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return 0;
|
|
|
|
|
|
return Convert.ToInt32(dt[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取过程条码的信息
|
|
|
/// </summary>
|
|
|
/// <param name="sn">过程条码</param>
|
|
|
/// <returns>过程条码信息</returns>
|
|
|
public dynamic GetSerialNumberData(string sn)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select * from g_sn_status where serial_number=@serial_number";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@serial_number", sn);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return null;
|
|
|
|
|
|
return dt[0];
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查数据表是否有效
|
|
|
/// </summary>
|
|
|
/// <param name="dt"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool CheckDataTableInvalid(List<dynamic> dt)
|
|
|
{
|
|
|
if (dt == null)
|
|
|
return false;
|
|
|
|
|
|
if (dt.Count == 0)
|
|
|
return false;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据 TerminalID 获取 ProcessID
|
|
|
/// </summary>
|
|
|
/// <param name="terminalID">Terminal ID</param>
|
|
|
/// <returns>Process ID</returns>
|
|
|
public int GetProcessID(int terminalID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select process_id from sys_terminal where terminal_id=@terminal_id";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@terminal_id", terminalID);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return 0;
|
|
|
|
|
|
return Convert.ToInt32(dt[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取流程中最后一站的 ID
|
|
|
/// </summary>
|
|
|
/// <param name="routeID">流程编号</param>
|
|
|
/// <returns>最后一站的 process id</returns>
|
|
|
public int GetRouteLastProcessID(int routeID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select top 1 next_process_id from sys_route_detail where route_id=@route_id order by seq desc";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@route_id", routeID);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return 0;
|
|
|
|
|
|
return Convert.ToInt32(dt[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取流程中第一站的 ID
|
|
|
/// </summary>
|
|
|
/// <param name="routeID">流程编号</param>
|
|
|
/// <returns>第一站的 process id</returns>
|
|
|
public int GetRouteFirstProcessID(int routeID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select top 1 next_process_id from sys_route_detail where route_id=@route_id order by seq";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@route_id", routeID);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return 0;
|
|
|
|
|
|
return Convert.ToInt32(dt[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断当前的制程是否在流程允许通过的范围内
|
|
|
/// </summary>
|
|
|
/// <param name="routeID">流程编号</param>
|
|
|
/// <param name="processID">工站对应的制程编号</param>
|
|
|
/// <param name="currentProcessID">条码对应的制程编号</param>
|
|
|
/// <returns>是否可以通过</returns>
|
|
|
public bool CheckRouteProcessID(int routeID, int processID, int currentProcessID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select process_id from sys_route_detail where route_id=@route_id and next_process_id=@process_id and result=0 order by seq";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(2);
|
|
|
|
|
|
Params.Add("@route_id", routeID);
|
|
|
Params.Add("@process_id", processID);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return false;
|
|
|
|
|
|
int PreviousProcessID = Convert.ToInt32(dt[0][0].ToString());
|
|
|
|
|
|
if (IsNecessaryProcess(routeID, PreviousProcessID))
|
|
|
{
|
|
|
if (currentProcessID == PreviousProcessID)
|
|
|
return true;
|
|
|
else
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (currentProcessID == PreviousProcessID)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return CheckRouteProcessID(routeID, PreviousProcessID, currentProcessID);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断流程中的某一制程是否为 必须经过 制程
|
|
|
/// </summary>
|
|
|
/// <param name="routeID">流程编号</param>
|
|
|
/// <param name="processID">制程编号</param>
|
|
|
/// <returns>true=必须,false=不必须</returns>
|
|
|
public bool IsNecessaryProcess(int routeID, int processID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select necessary from sys_route_detail where route_id=@route_id and next_process_id=@process_id and result=0 order by seq";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(2);
|
|
|
|
|
|
Params.Add("@route_id", routeID);
|
|
|
Params.Add("@process_id", processID);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return false;
|
|
|
|
|
|
return dt[0][0].ToString() == "Y" ? true : false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取制程名称
|
|
|
/// </summary>
|
|
|
/// <param name="processID">制程编号</param>
|
|
|
/// <returns>制程名称</returns>
|
|
|
public string GetProcessName(int processID)
|
|
|
{
|
|
|
string SqlString =
|
|
|
"select process_name from sys_process where process_id=@process_id";
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(1);
|
|
|
|
|
|
Params.Add("@process_id", processID);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(SqlString, Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return string.Empty;
|
|
|
|
|
|
return dt[0][0].ToString();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 添加过站信息
|
|
|
/// </summary>
|
|
|
public void snTravel()
|
|
|
{
|
|
|
//更新工位ID,为过站信息提供TerminalID
|
|
|
bool ret2 = app.UpdateSNTerminal(_terminalID, _sn);
|
|
|
|
|
|
//插入过站信息
|
|
|
bool ret3 = app.InsertSNTravel(_sn);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据工位ID和条码查询当前工位是否需要流程管控
|
|
|
/// </summary>
|
|
|
/// <param name="terminalID"></param>
|
|
|
/// <param name="sn"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool GetProcessIsNecessary(int terminalID, string sn)
|
|
|
{
|
|
|
StringBuilder querySen = new StringBuilder(1024);
|
|
|
querySen.AppendLine("SELECT necessary ");
|
|
|
querySen.AppendLine("FROM dbo.sys_route_detail ");
|
|
|
querySen.AppendLine("WHERE next_process_id = ( SELECT process_id ");
|
|
|
querySen.AppendLine(" FROM sys_terminal ");
|
|
|
querySen.AppendLine(" WHERE terminal_id = @terminal_id ");
|
|
|
querySen.AppendLine(" ) ");
|
|
|
querySen.AppendLine(" AND route_id = ( SELECT route_id ");
|
|
|
querySen.AppendLine(" FROM dbo.g_sn_status ");
|
|
|
querySen.AppendLine(" WHERE serial_number = @sn ");
|
|
|
querySen.AppendLine(" ) ");
|
|
|
|
|
|
Dictionary<string, object> Params = new Dictionary<string, object>(2);
|
|
|
|
|
|
Params.Add("@terminal_id", terminalID);
|
|
|
Params.Add("@sn", sn);
|
|
|
|
|
|
List<dynamic> dt = httpClient.GetEntityList(querySen.ToString(), Params);
|
|
|
|
|
|
if (!CheckDataTableInvalid(dt))
|
|
|
return false;
|
|
|
|
|
|
return dt[0][0].ToString().ToUpper() == "Y" ? true : false;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
private void dgvProdList_SelectionChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
//dgvProdList.ClearSelection();
|
|
|
txtSN.Focus();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 工步解锁
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnSkipStep_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (flpSteps.Controls.Count < 1)
|
|
|
{
|
|
|
ShowMessage("工步未加载!", Color.Red);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (_steps == null)
|
|
|
{
|
|
|
ShowMessage("工步未加载!", Color.Red);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ShowMessage("请输入密码!", Color.Green);
|
|
|
FrmPassword frmPassword = new FrmPassword();
|
|
|
|
|
|
if (frmPassword.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
string SysPWD = app.GetJupStepPassword(_terminalID);
|
|
|
|
|
|
if (frmPassword.Password.Trim() != SysPWD.Trim())
|
|
|
{
|
|
|
ShowMessage("密码输入错误!", Color.Red);
|
|
|
txtSN.Focus();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 插入解锁记录
|
|
|
string _sn = _OrderData[0]["serial_number"].ToString();
|
|
|
app.InsertUnlock(_terminalID.ToString(), _sn, "工步解锁");
|
|
|
|
|
|
ShowMessage("条码:" + _sn + "工步解锁成功!", Color.Green);
|
|
|
DoNextStep(true);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
catch { }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 重置RFID
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnResetRFID_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//_RF182C.Disconnect();
|
|
|
//DataTable RFIDIP = app.GetRFIDIP(_terminalID, "RFID_IP");
|
|
|
|
|
|
//if (RFIDIP != null && RFIDIP.Rows.Count > 0)
|
|
|
//{
|
|
|
// string paramName = RFIDIP.Rows[0]["param_value"].ToString();
|
|
|
// string[] str = paramName.Split(':');
|
|
|
|
|
|
// string rfidIP = str[0].ToString();
|
|
|
// int port = Convert.ToInt32(str[1]);
|
|
|
// _RF182C = new RF182C();
|
|
|
// bool connectionStatus = _RF182C.Connect(rfidIP, port);
|
|
|
// if (connectionStatus == true)
|
|
|
// {
|
|
|
// bool initializeState = _RF182C.Initialization();
|
|
|
// if (initializeState == true)
|
|
|
// {
|
|
|
// lblRFIDState.Text = "RFID连接成功";
|
|
|
// lblRFIDState.ForeColor = Color.Green;
|
|
|
|
|
|
|
|
|
// initializeRFIDState = true;
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// lblRFIDState.Text = "RFID连接失败";
|
|
|
// lblRFIDState.ForeColor = Color.Red;
|
|
|
|
|
|
// initializeRFIDState = false;
|
|
|
// }
|
|
|
|
|
|
// if (!_context.ContainsKey("initializeRFIDState"))
|
|
|
// {
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// _context.Remove("initializeRFIDState");
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
|
|
|
// ShowMessage("RFID重置成功!", Color.Green);
|
|
|
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// lblRFIDState.Text = "RFID连接失败";
|
|
|
// lblRFIDState.ForeColor = Color.Red;
|
|
|
// initializeRFIDState = false;
|
|
|
|
|
|
// if (!_context.ContainsKey("initializeRFIDState"))
|
|
|
// {
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// _context.Remove("initializeRFIDState");
|
|
|
// _context.Add("initializeRFIDState", initializeRFIDState);
|
|
|
// }
|
|
|
|
|
|
// ShowMessage("RFID重置失败!", Color.Red);
|
|
|
// lblRFIDState.ForeColor = Color.Red;
|
|
|
// initializeRFIDState = false;
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
ShowMessage("RFID重置失败!", Color.Red);
|
|
|
lblRFIDState.Text = "RFID连接失败";
|
|
|
lblRFIDState.ForeColor = Color.Red;
|
|
|
initializeRFIDState = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 切换工位
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void lblTerminalName_DoubleClick(object sender, EventArgs e)
|
|
|
{
|
|
|
FrmPassword frmPassword = new FrmPassword();
|
|
|
|
|
|
if (frmPassword.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
string SysPWD = app.GetSNReprintPassword();
|
|
|
|
|
|
if (frmPassword.Password.Trim() == SysPWD.Trim())
|
|
|
{
|
|
|
FrmReTerminal frmTerminal = new FrmReTerminal(app, _terminalID);
|
|
|
//frmReprint.ShowDialog();
|
|
|
if (frmTerminal.ShowDialog() == DialogResult.OK)
|
|
|
{
|
|
|
string terminalId = frmTerminal.Input;
|
|
|
|
|
|
// Todo 需要把内容写入配置,如何操作。暂时注释掉。
|
|
|
//_config.GetSection("TerminalID").Value = terminalId.ToString();
|
|
|
|
|
|
//_config.Save(ConfigurationSaveMode.Modified);
|
|
|
//ConfigurationManager.RefreshSection("appSettngs");
|
|
|
|
|
|
|
|
|
//LoadStepParameter();
|
|
|
_terminalID = Convert.ToInt32(terminalId);
|
|
|
if (!_context.ContainsKey("terminal_id"))
|
|
|
{
|
|
|
_context.Add("terminal_id", _terminalID);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_context.Remove("terminal_id");
|
|
|
_context.Add("terminal_id", _terminalID);
|
|
|
}
|
|
|
frmTerminal.Close();
|
|
|
string userNo = btnUser.Text.ToString();
|
|
|
this.Hide(); //先隐藏主窗体
|
|
|
FrmMain frmain = new FrmMain(100001, _userID, _userNo); //重新实例化此窗体
|
|
|
frmain.ShowDialog();//已模式窗体的方法重新打开
|
|
|
this.Close();//原窗体关闭
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("密码错误!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 切换用户
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btReplaceUser_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
this.Hide();
|
|
|
Login frmlogin = new Login();
|
|
|
frmlogin.ShowDialog();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 注销
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btCancel_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
if (MessageBox.Show("是否确定关闭电脑?", "提示",
|
|
|
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
|
|
|
{
|
|
|
ProcessStartInfo ps = new ProcessStartInfo();
|
|
|
ps.FileName = "shutdown.exe";
|
|
|
ps.Arguments = "-s -t 1";
|
|
|
Process.Start(ps);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
//关闭程序
|
|
|
private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
{
|
|
|
//if (null != m_csPrinter)
|
|
|
//{
|
|
|
// //m_csPrinter.Quit();
|
|
|
// m_csPrinter = null;
|
|
|
//}
|
|
|
string printName = "lppa";
|
|
|
KillProcess(printName); //关闭打印进程
|
|
|
|
|
|
System.Environment.Exit(System.Environment.ExitCode);
|
|
|
this.Dispose();
|
|
|
this.Close();
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void txtSerialNumber_DoubleClick(object sender, EventArgs e)
|
|
|
{
|
|
|
if (txtCarNo.SelectedText != "")
|
|
|
Clipboard.SetDataObject(txtCarNo.SelectedText);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 扫描间隔时间
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
private bool IsAllowPass()
|
|
|
{
|
|
|
//PASS码两次扫描时间
|
|
|
try
|
|
|
{
|
|
|
_passIntervalValue = Convert.ToInt32(app.validataLimit("PassIntervalValue"));
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
_passIntervalValue = 2000;
|
|
|
}
|
|
|
//PASS码间隔限制工位集合
|
|
|
_passIntervalLimit = app.validataLimit("PassIntervalLimit");
|
|
|
|
|
|
|
|
|
//如果不在限制的工位集合范围则返回TRUE
|
|
|
if (_passIntervalLimit.IndexOf(_terminalID.ToString() + ",") < 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks);
|
|
|
TimeSpan ts2 = new TimeSpan(_lastPassDatetime.Ticks);
|
|
|
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
|
|
|
|
|
long diffValue = Convert.ToInt64(ts.TotalMilliseconds);
|
|
|
if (diffValue >= _passIntervalValue)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 指定工位开启写入RFID 参数设置在sys_terminal_params
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void butWrite_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (blWriteRFID == true)
|
|
|
{
|
|
|
blWriteRFID = false;
|
|
|
app.UpWriteRFID(_terminalID, 1011, "N");
|
|
|
bunWrite.Text = "写入RFID (关)";
|
|
|
ShowMessage("关闭写入RFID成功!", Color.Green);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (blWriteRFID == false)
|
|
|
{
|
|
|
blWriteRFID = true;
|
|
|
app.UpWriteRFID(_terminalID, 1011, "Y");
|
|
|
bunWrite.Text = "写入RFID (开)";
|
|
|
ShowMessage("开启写入RFID成功!", Color.Green);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 关闭进程
|
|
|
/// </summary>
|
|
|
/// <param name="processName">进程名</param>
|
|
|
private void KillProcess(string processName)
|
|
|
{
|
|
|
Process[] myproc = Process.GetProcesses();
|
|
|
foreach (Process item in myproc)
|
|
|
{
|
|
|
if (item.ProcessName == processName)
|
|
|
{
|
|
|
item.Kill();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///余姚蜂鸣信号
|
|
|
/// </summary>
|
|
|
private void OPC_FM()
|
|
|
{
|
|
|
if (app.validataList("OPC_FM") == "Y")
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "OPC_FM")))
|
|
|
{
|
|
|
bool ret = app.UpdateOPCPointValue("OPC_FM", _terminalID, "TRUE");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工步解锁
|
|
|
/// </summary>
|
|
|
/// <param name="isSucess"></param>
|
|
|
private void StepUnlock(bool isSucess)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string _stepName = CurrentStep.Name;
|
|
|
dynamic drStep = StepData.FirstOrDefault("class_name='" + _stepName.ToString() + "'");
|
|
|
if (drStep.Length > 0)
|
|
|
{
|
|
|
int next_seq = 0;
|
|
|
if (isSucess)
|
|
|
{
|
|
|
next_seq = Convert.ToInt32(drStep[0]["next_seq"]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
next_seq = Convert.ToInt32(drStep[0]["fail_seq"]);
|
|
|
}
|
|
|
dynamic drNextStep = StepData.FirstOrDefault("seq=" + next_seq + "");
|
|
|
if (drNextStep.Length > 0)
|
|
|
{
|
|
|
string class_name = drNextStep[0]["class_name"].ToString().Trim();
|
|
|
|
|
|
Predicate<StepBase> next = delegate(StepBase step)
|
|
|
{ return step.Name.Equals(class_name); };
|
|
|
|
|
|
CurrentStep = _steps.Find(next);
|
|
|
|
|
|
CurrentStep.Do();
|
|
|
|
|
|
|
|
|
//判断是否前台界面,设置步骤往下执行
|
|
|
if (_stepAction < flpSteps.Controls.Count)
|
|
|
{
|
|
|
flpSteps.Controls[_stepAction - 1].ForeColor = Color.White;
|
|
|
flpSteps.Controls[_stepAction].ForeColor = Color.Black;
|
|
|
_stepAction++;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ShowMessage("所有工步执行完成,请继续下一个操作!", Color.Green);
|
|
|
|
|
|
WriteInfoLog("所有工步执行完成,请继续下一个操作!");
|
|
|
|
|
|
app.UpdateSNoutProcessTime(_sn);
|
|
|
if (GetProcessIsNecessary(_terminalID, _sn))
|
|
|
{
|
|
|
bool result = RouteGO(_sn, _terminalID);
|
|
|
if (!result)
|
|
|
{
|
|
|
labErrorMessage.Text = ErrorMessage;
|
|
|
labErrorMessage.ForeColor = Color.Red;
|
|
|
txtSN.Text = string.Empty;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
snTravel();
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(app.GetTerminalParams(_terminalID, "opc_ok")))
|
|
|
{
|
|
|
|
|
|
////发送OPC放行信号
|
|
|
//app.UpdatePLC("OPC_OK", _terminalID, "TRUE");
|
|
|
////发送OPC放行信号
|
|
|
bool ret = app.UpdateOPCPointValue("OPC_OK", _terminalID, "TRUE");
|
|
|
|
|
|
// 记录日志
|
|
|
|
|
|
WriteLog(""+"条码:" + _sn +" 放行信号已发送!");
|
|
|
|
|
|
|
|
|
if (app.validataList("SNCutCheck") == "Y")
|
|
|
{
|
|
|
//余姚工厂使用
|
|
|
lblOPC.Text = _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + _OrderData[0]["enum_desc"].ToString() + "-" + "已放行";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lblOPC.Text = _sn + "-" + _OrderData[0]["enum_desc"].ToString() + "-" + "已放行";
|
|
|
|
|
|
}
|
|
|
lblOPC.ForeColor = Color.Green;
|
|
|
}
|
|
|
|
|
|
//工位操作计时器停止
|
|
|
timerRefrensh.Enabled = false;
|
|
|
|
|
|
_context.Clear();
|
|
|
|
|
|
//释放加载的工步页面信息
|
|
|
//step.Dispose();
|
|
|
|
|
|
//----------------------------------2019-07-09
|
|
|
panControlArea.Controls.Clear();
|
|
|
panControlArea.Enabled = false;
|
|
|
|
|
|
txtSN.Text = string.Empty;
|
|
|
txtSN.Focus();
|
|
|
|
|
|
//更新队列
|
|
|
if (currentStatus != 9 || currentStatus != 8)
|
|
|
{
|
|
|
string _seq = _OrderData[0]["seq"].ToString();
|
|
|
bool _updateT = app.UpdateTerminalPoint(_seq, _terminalID);
|
|
|
|
|
|
}
|
|
|
//累加计数器值
|
|
|
CountAdd();
|
|
|
|
|
|
//-------------------------2017-04-14------------------------------
|
|
|
step.Dispose();
|
|
|
CurrentStep.Dispose();
|
|
|
//-------------------------2017-04-14------------------------------
|
|
|
|
|
|
RefreshQueue();
|
|
|
if (app.validataList("SNCutCheck") == "Y")
|
|
|
{
|
|
|
//余姚工厂使用
|
|
|
ShowMessage("流水号" + _sn.Substring(_sn.IndexOf("T") + 1, 12) + "-" + _OrderData[0]["enum_desc"].ToString() + "上一个已完成,请继续操作!", Color.Green);
|
|
|
dddd(_sn.Substring(_sn.IndexOf("T") + 1, 12));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ShowMessage("流水号" + _sn + "-" + _OrderData[0]["enum_desc"].ToString() + "上一个已完成,请继续操作!", Color.Green);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
|
|
|
WriteLog(" " +ex.ToString());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 切换扭矩枪
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void btnCutTorque_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
//FrmPassword frmPassword = new FrmPassword();
|
|
|
|
|
|
//if (frmPassword.ShowDialog() == DialogResult.OK)
|
|
|
//{
|
|
|
// string SysPWD = app.GetPwd("CutTorQue");
|
|
|
|
|
|
// if (frmPassword.Password.Trim() == SysPWD.Trim())
|
|
|
// {
|
|
|
// FrmCutTorque frmcuttorque = new FrmCutTorque(app, _terminalID, lblTerminalName.Text);
|
|
|
// frmcuttorque.ShowDialog();
|
|
|
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// MessageBox.Show("密码错误!");
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录日志
|
|
|
/// </summary>
|
|
|
/// <param name="Message"></param>
|
|
|
private void WriteLog(string Message)
|
|
|
{
|
|
|
string logPath = AppDomain.CurrentDomain.BaseDirectory + @"\\Log";
|
|
|
|
|
|
try
|
|
|
{
|
|
|
if (!System.IO.Directory.Exists(logPath))
|
|
|
{
|
|
|
System.IO.Directory.CreateDirectory(logPath);
|
|
|
}
|
|
|
string txtMsgPath = logPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
|
|
|
|
|
|
string timeStamp = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss-->");
|
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(txtMsgPath, true))
|
|
|
{
|
|
|
sw.WriteLine(timeStamp + Message.ToString());
|
|
|
sw.Flush();
|
|
|
sw.Close();
|
|
|
}
|
|
|
}
|
|
|
catch (System.Exception ex)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除七天前的日志文件
|
|
|
/// </summary>
|
|
|
/// <param name="path">日志路径</param>
|
|
|
/// <param name="day">天</param>
|
|
|
public static void DeleteWeeks(string path, int day)//day = 7
|
|
|
{
|
|
|
|
|
|
DateTime NowDate = DateTime.Now;
|
|
|
|
|
|
DirectoryInfo yourFolder = new DirectoryInfo(path);
|
|
|
|
|
|
//删除当前文件夹内文件
|
|
|
|
|
|
FileInfo[] files = yourFolder.GetFiles();
|
|
|
|
|
|
foreach (FileInfo file in files)
|
|
|
{
|
|
|
|
|
|
try
|
|
|
{
|
|
|
|
|
|
TimeSpan timespan = NowDate - file.CreationTime;
|
|
|
|
|
|
double t = timespan.TotalDays;//可以改为小时、分钟级别
|
|
|
|
|
|
if (t >= day)
|
|
|
{
|
|
|
|
|
|
File.Delete(file.FullName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//递归删除子文件夹内文件
|
|
|
|
|
|
foreach (DirectoryInfo inFolder in yourFolder.GetDirectories())
|
|
|
{
|
|
|
|
|
|
DeleteWeeks(inFolder.FullName, day);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|