using MESClassLibrary.BLL.BasicInfo; using MESClassLibrary.BLL.Injection; using MESClassLibrary.BLL.Inspection; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace InjectionSearch { public partial class FrmBarCodeReplace : Form { private BarCodeBLL _barCodeBLL = new BarCodeBLL(); private InjectionBoxBLL _injectionBoxBLL = new InjectionBoxBLL(); private BadInjectionBLL _badInjectionBLL = new BadInjectionBLL(); private StationBLL _stationBLL = new StationBLL(); private WmsBLL wmsBLL = new WmsBLL(); public FrmBarCodeReplace(DataRow barCodeRow) { InitializeComponent(); this.StartPosition = FormStartPosition.CenterParent; lbBoxCode.Text = barCodeRow["BoxNo"].ToString(); lbOldCode.Text = barCodeRow["OneBarCode"].ToString(); } private void btnOK_Click(object sender, EventArgs e) { try { string newCode = txtNewCode.Text?.Trim(); string oldCode = lbOldCode.Text?.Trim(); string boxCode = lbBoxCode.Text?.Trim(); if (string.IsNullOrEmpty(newCode)) { MessageBox.Show("新条码不能为空."); return; } DataTable dt = _barCodeBLL.SearchBarCodeByOne(newCode);//已经过滤掉删除的了 if (dt.Rows.Count == 0) { MessageBox.Show($"输入条码{newCode}在系统中不存在."); return; } if (dt.Rows[0]["IsBad"].ToString() == "1" ) { MessageBox.Show($"输入条码{newCode}已报废,无法使用."); return; } if (!string.IsNullOrEmpty(dt.Rows[0]["BoxNo"].ToString())) { MessageBox.Show($"输入条码{newCode}已绑定箱码{dt.Rows[0]["BoxNo"].ToString()},无法使用."); return; } DataTable oldTable = _barCodeBLL.SearchBarCodeByOne(oldCode); if (oldTable.Rows.Count == 0) { MessageBox.Show($"原有条码{oldCode}在系统中不存在."); return; } string boxNo = oldTable.Rows[0]["BoxNo"].ToString(); if (string.IsNullOrEmpty(boxNo)) { MessageBox.Show($"不良条码{oldCode}未绑定箱码,无法替换."); return; } if (oldTable.Rows[0]["PartNo"].ToString()?.ToLower() != dt.Rows[0]["PartNo"].ToString()?.ToLower()) { MessageBox.Show($"新零件号{oldTable.Rows[0]["PartNo"].ToString()}与原零件号{dt.Rows[0]["PartNo"].ToString()}不一致,无法替换."); return; } //打印箱码才能替换 if( wmsBLL.IsSendPackageCode(boxCode) == false) { MessageBox.Show($"箱码{boxCode}尚未报工,无法此处替换."); return; } //WMS中间表,wmsread=1后不能替换,只能去WMS替换 if (wmsBLL.IsReadBoxInWms(boxCode) == true) { MessageBox.Show($"箱码{boxCode}已被WMS处理,因此无法替换."); return; } DialogResult result = MessageBox.Show($"确认用条码{newCode}替换原有条码{oldCode},确认将原有条码{oldCode}进行报废处理?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == DialogResult.Cancel) return; //新条码更新箱码 //旧条码清空箱码,IsBad=1 //旧条码插入tb_Bad_Injection表报废记录 //_barCodeBLL.UpdateBoxNoByID(oldTable.Rows[0]["TableName"].ToString(), boxNo, dt.Rows[0]["ID"].ToString()); //_barCodeBLL.UpdateBoxNoNull(oldTable.Rows[0]["TableName"].ToString(), oldTable.Rows[0]["ID"].ToString()); BadInjectionModel model = new BadInjectionModel(); model.ID = Guid.NewGuid().ToString(); model.OneBarCode = oldTable.Rows[0]["OneBarCode"].ToString(); model.BarCode = oldTable.Rows[0]["BarCode"].ToString(); model.StationID = oldTable.Rows[0]["StationID"].ToString(); model.BadPosition = ""; model.BadReason = "不良替换自动报废"; model.PlanID = oldTable.Rows[0]["PlanID"].ToString(); //_badInjectionBLL.Add_Info(model); string stationID = dt.Rows[0]["StationID"].ToString(); string stationNo = _stationBLL.SearchStationNameByID(stationID); _barCodeBLL.BarCodeReplace(oldTable.Rows[0]["TableName"].ToString(), dt.Rows[0]["TableName"].ToString(), boxNo, oldTable.Rows[0]["ID"].ToString(), dt.Rows[0]["ID"].ToString(), dt.Rows[0]["OneBarCode"].ToString(), dt.Rows[0]["BarCode"].ToString(), model, stationNo); MessageBox.Show($"替换成功.原条码[{oldCode}]已与箱码解绑."); this.Close(); } catch(Exception ex) { MessageBox.Show("操作失败,失败原因:" + ex.Message); } } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } } }