using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Frame.Data.Entity; using System.Collections; using System.IO; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.DataConnect.Action; using ICSSoft.Frame.DataConnect; using ICSSoft.Frame.DataCollect; namespace ICSSoft.Frame.APP { public delegate void LotCodeChangeEventHandler(string ItemCode, string RouteCode, string OpCode); public partial class UserControlCollectBeginTop : UserControl { public event LotCodeChangeEventHandler LotCodeChange; private const string PAUSE = "暂停"; private const string CANCELPAUSE = "取消暂停"; private const string START = "开工"; private const string END = "完工"; private string Status; private string routeCode; private string EQPType; private string partCode = ""; private string partSpec = ""; #region 采集 public UserControlCollectBeginTop() { InitializeComponent(); txtUserCode.Focus(); } #region 员工条码 private void txtUserCode_KeyPress(object sender, KeyPressEventArgs e) { try { if (e.KeyChar == (char)Keys.Enter) { string UserCode = txtUserCode.Text.Trim(); string sql = "select distinct ID, UserCode,UserName from dbo.Sys_User with(nolock) where UserCode='{0}'"; sql = string.Format(sql, UserCode); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (data.Rows.Count > 0) { foreach (DataRow dr in data.Rows) { txtUserCode.Text = dr["UserCode"].ToString(); txtUserName.Text = dr["UserName"].ToString(); } txtLotNo.Focus(); SetMsg(Color.Blue, ""); } else { txtUserName.Text = ""; txtUserCode.SelectAll(); txtUserCode.Focus(); SetMsg(Color.Red, "员工条码不存在!"); } } } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } #endregion #region 产品跟踪单号 private void txtLotNo_KeyPress(object sender, KeyPressEventArgs e) { try { if (e.KeyChar == (char)Keys.Enter) { #region 20200820新增防呆 string chksql = @"select ISNULL(EATTRIBUTE6,'') AS EATTRIBUTE6 from ICSITEMLot where LotNO='{0}' AND WorkPoint='{1}'"; chksql = string.Format(chksql, txtLotNo.Text.Trim(), AppConfig.WorkPointCode); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0]; if (dt.Rows.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号不存在!!"); return; } else { if (dt.Rows[0]["EATTRIBUTE6"].ToString() == "") { ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号未绑定零件号,请先绑定再发料!!"); return; } } #endregion btnStart.Text = START; btnPauseBegin.Text = PAUSE; string LotNo = txtLotNo.Text.Trim(); string sql = @"SELECT DISTINCT a.ID, a.LOTNO, a.LOTQTY, b.MOCODE, b.ITEMCODE, a.VenderLotNO, c.INVNAME AS ItemName, d.LOTStatus, CASE d.CollectStatus WHEN 'COLLECT_BEGIN' THEN 'WG' ELSE 'KG' END AS Status FROM ICSITEMLot a WITH (nolock) LEFT JOIN ICSMO b WITH (nolock) ON a.TransNO = b.MOCODE AND a.TransLine=b.MOSEQ LEFT JOIN ICSINVENTORY c WITH (nolock) ON b.ITEMCODE = c.INVCODE LEFT JOIN ICSLOTSIMULATION d WITH(nolock) ON a.LOTNO = d.LOTNO WHERE a.LOTNO = '{0}'"; sql = string.Format(sql, LotNo); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (data.Rows.Count > 0) { foreach (DataRow dr in data.Rows) { txtLotNo.Text = dr["LOTNO"].ToString(); //txtLotNo.Tag = dr["LOTSEQ"].ToString(); //txtLotQty.Text = dr["LOTQTY"].ToString(); txtItemCode.Text = dr["ITEMCODE"].ToString(); txtItemName.Text = dr["ItemName"].ToString(); txtMoCode.Text = dr["MOCODE"].ToString(); txtVenderLotNO.Text = dr["VenderLotNO"].ToString(); Status = dr["Status"].ToString(); if (dr["Status"].ToString().Equals("WG")) btnStart.Text = END; if (dr["LOTStatus"].ToString().Equals(PAUSE)) btnPauseBegin.Text = CANCELPAUSE; if (LotCodeChange != null) { LotCodeChange(txtItemCode.Text.Trim(), routeCode, txtOpCode.Text.Trim()); } } txtOpCode.Focus(); SetMsg(Color.Blue, ""); } else { //txtLotNo.Tag = ""; //txtLotQty.Text = ""; txtItemCode.Text = ""; txtItemName.Text = ""; txtMoCode.Text = ""; txtLotNo.SelectAll(); txtLotNo.Focus(); txtInvLotFurnace.Text = ""; SetMsg(Color.Red, "产品跟踪单号不存在!"); } } } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } #endregion #region 工序条码 private void txtOpCode_KeyPress(object sender, KeyPressEventArgs e) { try { if (e.KeyChar == (char)Keys.Enter) { btnStart.Text = START; btnPauseBegin.Text = PAUSE; string OpCode = txtOpCode.Text.Trim(); string LOTNO = txtLotNo.Text.Trim(); string sql = @"SELECT DISTINCT a.ID, a.OPCODE, a.OPDESC, b.RouteCode, b.EQPCode, b.EQPName,d.LOTStatus, CASE d.CollectStatus WHEN 'COLLECT_BEGIN' THEN 'WG' ELSE 'KG' END AS Status, Type,ISNULL(b.EATTRIBUTE1,0) AS EATTRIBUTE1 FROM ICSOP a WITH (nolock) LEFT JOIN ICSMO2User b WITH(nolock) ON a.OPCODE = b.OPCODE LEFT JOIN ICSLOTSIMULATION d WITH(nolock) ON b.LOTNO = d.LOTNO and b.OPCODE=d.OPCODE LEFT JOIN ICSEquipment e WITH(nolock) ON b.EQPCode=e.EQPCode WHERE b.OPCODE = '{0}' AND b.LOTNO = '{1}'"; sql = string.Format(sql, OpCode, LOTNO); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (data.Rows.Count > 0) { SetMsg(Color.Blue, ""); foreach (DataRow dr in data.Rows) { //if (dr["EATTRIBUTE1"].ToString()=="1") //{ // txtOpName.Text = ""; // txtEQPCode.Text = ""; // txtEQPName.Text = ""; // Status = ""; // routeCode = ""; // EQPType = ""; // txtOpCode.SelectAll(); // txtOpCode.Focus(); // SetMsg(Color.Red, "委外工序不能在此界面报工!"); // return; //} txtOpCode.Text = dr["OPCODE"].ToString(); txtOpName.Text = dr["OPDESC"].ToString(); txtEQPCode.Text = dr["EQPCode"].ToString(); txtEQPName.Text = dr["EQPName"].ToString(); Status = dr["Status"].ToString(); routeCode = dr["RouteCode"].ToString(); EQPType = dr["Type"].ToString(); if (dr["Status"].ToString().Equals("WG")) btnStart.Text = END; if (dr["LOTStatus"].ToString().Equals(PAUSE)) btnPauseBegin.Text = CANCELPAUSE; } if (LotCodeChange != null) { LotCodeChange(txtItemCode.Text.Trim(), routeCode, txtOpCode.Text.Trim()); } this.txtRealEQP.SelectAll(); this.txtRealEQP.Focus(); } else { txtOpName.Text = ""; txtEQPCode.Text = ""; txtEQPName.Text = ""; Status = ""; routeCode = ""; EQPType = ""; txtOpCode.SelectAll(); txtOpCode.Focus(); SetMsg(Color.Red, "该批次工序对应的派工信息不存在!"); } } } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } #endregion #region 设备条码 private void txtEQPCode_KeyPress(object sender, KeyPressEventArgs e) { try { if (e.KeyChar == (char)Keys.Enter) { #region 20200820新增防呆 20210430去掉 // string chksql = @"select ISNULL(MTStatus,'') AS MTStatus from ICSEquipment // where EQPCode='{0}' And WorkPoint='{1}'"; // chksql = string.Format(chksql, txtRealEQP.Text.Trim(), AppConfig.WorkPointCode); // DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0]; // if (chkdt.Rows.Count != 0) // { // if (chkdt.Rows[0]["MTStatus"].ToString() == "是") // { // chksql = @"select * from ICSItemOPPrice // where ITEMCODE='{0}' AND OPCODE='{1}' // AND WorkPoint='{2}'"; // chksql = string.Format(chksql, txtItemCode.Text.Trim(), txtOpCode.Text.Trim(), AppConfig.WorkPointCode); // chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0]; // if (chkdt.Rows.Count == 0) // { // SetMsg(Color.Red, "开工设备类型为泛威时,必须维护工序价格!"); // return; // } // } // } #endregion string EQPCode = txtRealEQP.Text.Trim(); string sql = @"SELECT DISTINCT a.EQPID, a.EQPCode, a.EQPName,Type FROM ICSEquipment a WITH (nolock) WHERE a.EQPCode = '{0}'"; sql = string.Format(sql, EQPCode); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (data.Rows.Count > 0) { foreach (DataRow dr in data.Rows) { txtRealEQP.Text = dr["EQPCode"].ToString(); txtRealEQPName.Text = dr["EQPName"].ToString(); EQPType = dr["Type"].ToString(); } SetMsg(Color.Blue, ""); //if (Status.Equals("KG")) // save(); } else { txtRealEQPName.Text = ""; txtRealEQP.SelectAll(); txtRealEQP.Focus(); EQPType = ""; SetMsg(Color.Red, "设备条码不存在!"); } } } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } #endregion #region 检查输入数据 public string check() { string msg = ""; if (txtUserName.Text.Trim() == "") { msg += "请重新扫描员工条码!\n"; } if (txtMoCode.Text.Trim() == "") { msg += "请重新扫描产品跟踪单号!\n"; } if (txtOpName.Text.Trim() == "") { msg += "请重新扫描工序条码!\n"; } if (txtRealEQPName.Text.Trim() == "") { msg += "请重新扫描设备条码!\n"; } return msg; } #endregion //消息提示 private void SetMsg(Color color, string Msg) { txtMessages.Text = Msg; txtMessages.ForeColor = color; } #endregion #region 暂停开始 private void btnPauseBegin_Click(object sender, EventArgs e) { if (btnPauseBegin.Text.Trim().Equals(PAUSE)) { Pause(); } else { CancelPause(); } } private void Pause() { try { if (txtLotNo.Text.Trim() == "" || txtOpCode.Text.Trim() == "" || txtUserCode.Text.Trim() == "" || txtRealEQP.Text.Trim() == "") { SetMsg(Color.Red, "请先扫描批次信息!"); return; } #region simulation ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION(); simulationNew.MUSER = txtUserCode.Text.Trim(); simulationNew.LOTNO = txtLotNo.Text.Trim(); simulationNew.OPCODE = txtOpCode.Text.Trim(); simulationNew.EQPCODE = txtRealEQP.Text.Trim(); #endregion ICSCollectBLL.Pause(AppConfig.AppConnectString, simulationNew); SetMsg(Color.Blue, "暂停成功!"); btnPauseBegin.Text = CANCELPAUSE; } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } #endregion private void clear() { try { txtUserCode.Text = ""; txtUserName.Text = ""; txtItemCode.Text = ""; txtVenderLotNO.Text = ""; txtLotNo.Text = ""; txtMoCode.Text = ""; txtItemName.Text = ""; txtOpCode.Text = ""; txtOpName.Text = ""; txtKeyPart.Text = ""; txtEQPCode.Text = ""; txtEQPName.Text = ""; txtInvLotFurnace.Text = ""; txtRealEQP.Text = ""; txtRealEQPName.Text = ""; txtMemo.Text = ""; } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } #region 取消暂停 private void CancelPause() { try { if (txtLotNo.Text.Trim() == "" || txtOpCode.Text.Trim() == "" || txtUserCode.Text.Trim() == "" || txtRealEQP.Text.Trim() == "") { SetMsg(Color.Red, "请先扫描批次信息!"); return; } #region simulation ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION(); simulationNew.MUSER = txtUserCode.Text.Trim(); simulationNew.LOTNO = txtLotNo.Text.Trim(); simulationNew.OPCODE = txtOpCode.Text.Trim(); simulationNew.EQPCODE = txtRealEQP.Text.Trim(); #endregion ICSCollectBLL.CancelPause(AppConfig.AppConnectString, simulationNew); SetMsg(Color.Blue, "取消暂停成功!"); btnPauseBegin.Text = PAUSE; clear(); } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } #endregion #region 开工、完工 private void btnTransfer_Click(object sender, EventArgs e) { SetMsg(Color.Blue, ""); string msg = check(); if (msg != "") { SetMsg(Color.Red, msg); return; } DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在处理...请稍等..."); try { _wait.Show(); string OpCode = txtOpCode.Text.Trim(); string LOTNO = txtLotNo.Text.Trim(); string sql = @"SELECT DISTINCT a.ID, a.OPCODE, a.OPDESC, b.RouteCode, b.EQPCode, b.EQPName,d.LOTStatus, CASE d.CollectStatus WHEN 'COLLECT_BEGIN' THEN 'WG' ELSE 'KG' END AS Status, Type,ISNULL(b.EATTRIBUTE1,0) AS EATTRIBUTE1 FROM ICSOP a WITH (nolock) LEFT JOIN ICSMO2User b WITH(nolock) ON a.OPCODE = b.OPCODE LEFT JOIN ICSLOTSIMULATION d WITH(nolock) ON b.LOTNO = d.LOTNO and b.OPCODE=d.OPCODE LEFT JOIN ICSEquipment e WITH(nolock) ON b.EQPCode=e.EQPCode WHERE b.OPCODE = '{0}' AND b.LOTNO = '{1}'"; sql = string.Format(sql, OpCode, LOTNO); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (data.Rows.Count > 0) { foreach (DataRow dr in data.Rows) { if (dr["EATTRIBUTE1"].ToString() == "1") { txtOpName.Text = ""; txtEQPCode.Text = ""; txtEQPName.Text = ""; Status = ""; routeCode = ""; EQPType = ""; txtOpCode.SelectAll(); txtOpCode.Focus(); _wait.Close(); SetMsg(Color.Red, "所扫描的工序为委外工序,无法开工,请确认!"); return; } } } #region simulation ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION(); simulationNew.MUSER = txtUserCode.Text.Trim(); simulationNew.LOTNO = txtLotNo.Text.Trim(); simulationNew.OPCODE = txtOpCode.Text.Trim(); simulationNew.EQPCODE = txtRealEQP.Text.Trim(); simulationNew.RESCODE = txtInvLotFurnace.Text.Trim();//试样号 simulationNew.CHECKLOTNO = txtMemo.Text.Trim(); //备注 //simulationNew.MOCODE = simulation.MOCODE; //simulationNew.LOTSEQ = simulation.LOTSEQ; //simulationNew.LOTQTY = Convert.ToInt32(simulation.LOTQTY); //simulationNew.GOODQTY = simulation.GOODQTY; //simulationNew.NGQTY = simulation.NGQTY; //simulationNew.LOTStatus = simulation.LOTStatus; //simulationNew.MODELCODE = simulation.MODELCODE; //simulationNew.ITEMCODE = simulation.ITEMCODE; //simulationNew.FROMROUTE = simulation.FROMROUTE; //simulationNew.FROMOP = simulation.FROMOP; //simulationNew.ROUTECODE = simulation.ROUTECODE; //simulationNew.RESCODE = simulation.RESCODE; //simulationNew.CHECKLOTNO = simulation.CHECKLOTNO; //simulationNew.CARTONCODE = simulation.CARTONCODE; //simulationNew.PALLETCODE = simulation.PALLETCODE; //simulationNew.PRODUCTSTATUS = simulation.PRODUCTSTATUS; //simulationNew.LACTION = simulation.LACTION; //simulationNew.ACTIONLIST = simulation.ACTIONLIST; //simulationNew.NGTIMES = simulation.NGTIMES; //simulationNew.ISCOM = simulation.ISCOM; //simulationNew.ISHOLD = simulation.ISHOLD; //simulationNew.SHELFNO = simulation.SHELFNO; //simulationNew.MOSEQ = simulation.MOSEQ; //simulationNew.CollectStatus = simulation.CollectStatus; //simulationNew.BeginTime = simulation.BeginTime; //simulationNew.SEQ = simulation.SEQ + 1; //simulationNew.EndTime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString("HHmmss")); //simulationNew.MUSERName = AppConfig.UserName; //simulationNew.MTIME = DateTime.Now; //simulationNew.WorkPoint = AppConfig.WorkPointCode; //simulationNew.EATTRIBUTE1 = simulation.EATTRIBUTE1; #endregion if (btnStart.Text.Trim().Equals(START)) { simulationNew.EATTRIBUTE1 = "COLLECT_BEGIN"; } else { simulationNew.EATTRIBUTE1 = "COLLECT_END"; } ICSCollectBLL.Save(AppConfig.AppConnectString, simulationNew); SetMsg(Color.Blue, btnStart.Text.Trim() + "成功!"); if (btnStart.Text.Trim().Equals(START)) { btnStart.Text = END; } else { btnStart.Text = START; } _wait.Close(); } catch (Exception ex) { _wait.Close(); SetMsg(Color.Red, ex.Message); } } #endregion private void txtLotNo_Click(object sender, EventArgs e) { txtLotNo.Focus(); txtLotNo.SelectAll(); } private void txtOpCode_Click(object sender, EventArgs e) { txtOpCode.Focus(); txtOpCode.SelectAll(); } private void btnTransfer_Click_1(object sender, EventArgs e) { SetMsg(Color.Blue, ""); string msg = check(); if (msg != "") { SetMsg(Color.Red, msg); return; } try { #region simulation ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION(); simulationNew.MUSER = txtUserCode.Text.Trim(); simulationNew.LOTNO = txtLotNo.Text.Trim(); simulationNew.OPCODE = txtOpCode.Text.Trim(); simulationNew.EQPCODE = txtRealEQP.Text.Trim(); simulationNew.RESCODE = txtInvLotFurnace.Text.Trim();//试样号 simulationNew.CHECKLOTNO = txtMemo.Text.Trim(); //备注 //simulationNew.MOCODE = simulation.MOCODE; //simulationNew.LOTSEQ = simulation.LOTSEQ; //simulationNew.LOTQTY = Convert.ToInt32(simulation.LOTQTY); //simulationNew.GOODQTY = simulation.GOODQTY; //simulationNew.NGQTY = simulation.NGQTY; //simulationNew.LOTStatus = simulation.LOTStatus; //simulationNew.MODELCODE = simulation.MODELCODE; //simulationNew.ITEMCODE = simulation.ITEMCODE; //simulationNew.FROMROUTE = simulation.FROMROUTE; //simulationNew.FROMOP = simulation.FROMOP; //simulationNew.ROUTECODE = simulation.ROUTECODE; //simulationNew.RESCODE = simulation.RESCODE; //simulationNew.CHECKLOTNO = simulation.CHECKLOTNO; //simulationNew.CARTONCODE = simulation.CARTONCODE; //simulationNew.PALLETCODE = simulation.PALLETCODE; //simulationNew.PRODUCTSTATUS = simulation.PRODUCTSTATUS; //simulationNew.LACTION = simulation.LACTION; //simulationNew.ACTIONLIST = simulation.ACTIONLIST; //simulationNew.NGTIMES = simulation.NGTIMES; //simulationNew.ISCOM = simulation.ISCOM; //simulationNew.ISHOLD = simulation.ISHOLD; //simulationNew.SHELFNO = simulation.SHELFNO; //simulationNew.MOSEQ = simulation.MOSEQ; //simulationNew.CollectStatus = simulation.CollectStatus; //simulationNew.BeginTime = simulation.BeginTime; //simulationNew.SEQ = simulation.SEQ + 1; //simulationNew.EndTime = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString("HHmmss")); //simulationNew.MUSERName = AppConfig.UserName; //simulationNew.MTIME = DateTime.Now; //simulationNew.WorkPoint = AppConfig.WorkPointCode; //simulationNew.EATTRIBUTE1 = simulation.EATTRIBUTE1; #endregion ICSCollectBLL.Transfer(AppConfig.AppConnectString, simulationNew); SetMsg(Color.Blue, btnTransfer.Text.Trim() + "成功!"); } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } //上料采集 private void txtKeyPart_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != (char)Keys.Enter) { return; } //检查数据输入 SetMsg(Color.Blue, ""); string msg = check(); if (msg != "") { SetMsg(Color.Red, msg); return; } try { #region simulation ICSLOTONWIPITEM simulationNew = new ICSLOTONWIPITEM(); simulationNew.MUSER = txtUserCode.Text.Trim(); simulationNew.LOTNO = txtLotNo.Text.Trim(); simulationNew.OPCODE = txtOpCode.Text.Trim(); simulationNew.INVLOTNO = txtKeyPart.Text.Trim(); #endregion ICSCollectBLL.SaveItem(AppConfig.AppConnectString, simulationNew); SetMsg(Color.Blue, txtKeyPart.Text.Trim() + " 上料成功!"); } catch (Exception ex) { SetMsg(Color.Red, ex.Message); } } private void UserControlCollectBeginTop_Load(object sender, EventArgs e) { txtUserCode.Focus(); } } }