using System; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Windows.Forms; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.WinForm.Controls; namespace Dongke.IBOSS.PRD.Client.PMModule { public partial class F_PM_0103_1 : FormDialog { public F_PM_0103_1() { InitializeComponent(); } public DataGridView BarCodeGrid { get; set; } public List ERROR_LIST { get; set; } private void tsbtnClose_Click(object sender, System.EventArgs e) { ERROR_LIST = null; this.DialogResult = DialogResult.Cancel; this.Close(); } private void tsbtnClearCondition_Click(object sender, System.EventArgs e) { this.txtBarCodes.Clear(); } private void tsbtnBindss_Click(object sender, System.EventArgs e) { if (this.BarCodeGrid == null || string.IsNullOrWhiteSpace(this.txtBarCodes.Text)) { return; } try { string[] barcode_lines = this.txtBarCodes.Lines; string barcode = null; string goodscode = null; bool bindFlag = false; ERROR_LIST = new List(); DataTable dt = this.BarCodeGrid.DataSource as DataTable; foreach (string item in barcode_lines) { if (string.IsNullOrWhiteSpace(item)) { continue; } if (item.Contains("\t")) { string[] ss = item.Split('\t'); barcode = ss[0]; goodscode = ss[1]; } else if (item.Contains("@")) { string[] ss = item.Split('@'); barcode = ss[0]; goodscode = ss[1]; } else { barcode = item; goodscode = null; } if (barcode?.Length != 11 || !long.TryParse(barcode, out long logbarcode)) { ERROR_LIST.Add(item); continue; } if (dt?.Select($"barcode='{barcode}'")?.Length > 0) { ERROR_LIST.Add(item); continue; } bindFlag = false; foreach (DataGridViewRow row in this.BarCodeGrid.Rows) { if (row.Cells["BarCode"].ReadOnly) { continue; } string bc = row.Cells["BarCode"].Value + ""; string sf = row.Cells["ScrapFlag"].Value + ""; string gf = row.Cells["GroutingFlag"].Value + ""; string gc = row.Cells["GoodsCode"].Value + ""; if (!string.IsNullOrWhiteSpace(bc) || gf != "1" || sf != "0") { continue; } if (!string.IsNullOrWhiteSpace(goodscode) && goodscode != gc) { continue; } bindFlag = true; row.Cells["BarCode"].Value = barcode; (row.DataBoundItem as DataRowView)?.EndEdit(); break; } if (!bindFlag) { ERROR_LIST.Add(item); } } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void tsbtnClearBarCode_Click(object sender, EventArgs e) { if (this.BarCodeGrid == null) { return; } try { //DataTable dd = this.BarCodeGrid.DataSource as DataTable; foreach (DataGridViewRow row in this.BarCodeGrid.Rows) { if (!row.Cells["BarCode"].ReadOnly) { row.Cells["BarCode"].Value = DBNull.Value; (row.DataBoundItem as DataRowView)?.EndEdit(); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }