using LabelManager2; using Seagull.BarTender.Print; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Drawing.Printing; using System.Linq; using System.Media; using System.Threading; using System.Windows.Forms; using static System.Runtime.CompilerServices.RuntimeHelpers; namespace UAS_BARCODEIO { public partial class 入库条码规则解析 : Form { ApplicationClass lbl; DataHelper dh = new DataHelper(); Document SingleDoc; Document OutDoc; DataTable Dbfind; //自适应屏幕 AutoSizeFormClass asc = new AutoSizeFormClass(); public 入库条码规则解析() { InitializeComponent(); } delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托 void bindingsource(DataGridView dgv, DataTable dt) { //dgv.AutoGenerateColumns = false; //dgv.DataSource = null; //dgv.DataSource = dt; if (dgv.InvokeRequired) { dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt }); } else { dgv.AutoGenerateColumns = false; dgv.DataSource = dt; } } private void Form1_Load(object sender, EventArgs e) { es_custcode.TableName = "CS_EXPORTSETTING "; es_custcode.SelectField = "es_custcode # 品牌"; es_custcode.FormName = Name; es_custcode.DBTitle = "解析规则查询"; es_custcode.SetValueField = new string[] { "es_custcode" }; es_custcode.Condition = ""; es_custcode.DbChange += nr_rule_DBChange; SystemInf.dh = dh; try { lbl = new ApplicationClass(); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } SingleDoc = lbl.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\BARCODE.lab"); OutDoc = lbl.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\BOXCODE.lab"); asc.controllInitializeSize(this); asc.controlAutoSize(this); PrintDocument print = new PrintDocument(); string sDefault = print.PrinterSettings.PrinterName;//默认打印机名 foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称 { PrinterList.Items.Add(sPrint); if (sPrint == sDefault) PrinterList.SelectedIndex = PrinterList.Items.IndexOf(sPrint); } } private void nr_rule_DBChange(object sender, EventArgs e) { Dbfind = es_custcode.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); } private void pi_inoutnokeydown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { LoadGridData(); } } private void LoadGridData() { string sql = "select pd_inqty,pd_prodcode,pr_detail,pr_orispeccode,pr_spec,bi_inqty,pr_brand from " + "(select max(pd_prodcode)pd_prodcode,sum(pd_inqty)pd_inqty from prodiodetail left join product on pd_prodcode=pr_code where pd_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand)" + " left join (select max(bi_prodcode)bi_prodcode,nvl(sum(bi_inqty),0)bi_inqty from barcodeio left join product on pr_code=bi_prodcode " + "where bi_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand) on pd_prodcode=bi_prodcode left join product on pr_code=pd_prodcode order by pr_code"; DataTable dt = (DataTable)dh.ExecuteSql(sql, "select"); BaseUtil.FillDgvWithDataTable(Prodiodetail, dt); if (Prodiodetail.Rows.Count > SelectIndex) { Prodiodetail.Rows[SelectIndex].Selected = true; } } private void Barcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { DataTable dt = (DataTable)dh.ExecuteSql("select esd_caption,esd_enable,el_type from cs_exportsettingdetail left join CS_EXPORTSETTING" + " on es_id=esd_esid where es_custcode='" + es_custcode.Text + "'", "select"); if (dt.Rows.Count == 0) { Play("NG"); MessageBox.Show("无条码解析规则"); return; } string split = dt.Rows[0]["el_type"].ToString(); string[] str = Barcode.Text.Split(split.ToCharArray()[0]); //分割后的字符串数组需要大于设置的参数解析 if (str.Length < dt.Rows.Count) { Play("NG"); MessageBox.Show("解析参数与解析规则不匹配"); return; } for (int i = 0; i < dt.Rows.Count; i++) { string name = dt.Rows[i]["esd_caption"].ToString(); string index = dt.Rows[i]["esd_enable"].ToString(); switch (name) { case "LOTNO": LOTNO.Text = str[int.Parse(index) - 1]; break; case "DC": DC.Text = str[int.Parse(index) - 1]; break; case "PROD": pr_orispeccode3.Text = str[int.Parse(index) - 1]; break; case "QTY": INQTY.Text = str[int.Parse(index) - 1]; break; case "SCCODE": SCCODE.Text = str[int.Parse(index) - 1]; break; default: break; } } string madedate; string outqty; string lotno; string spec; LogicHandler.GetWeekData(DC.Text, INQTY.Text, es_custcode.Text.ToUpper(), pr_orispeccode3.Text, LOTNO.Text, out madedate, out outqty, out lotno, out spec); DC.Text = madedate; INQTY.Text = outqty; LOTNO.Text = lotno; pr_orispeccode3.Text = spec; Barcode.Clear(); GenBarCode.PerformClick(); Play("OK"); } } bool AutoSized = false; private void 入库条码规则解析_AutoSizeChanged(object sender, EventArgs e) { if (!AutoSized) { asc.controlAutoSize(this); AutoSized = true; } } private void Prodiodetail_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position)); if (e.ColumnIndex > 0 && e.RowIndex >= 0) { if (Prodiodetail.Columns[e.ColumnIndex].Name == "pd_prodcode") { SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255)); if (Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString() != Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString()) e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds); else e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds); Rectangle border = e.CellBounds; border.Width -= 1; e.Graphics.DrawRectangle(Pens.White, border); e.PaintContent(e.CellBounds); e.Handled = true; } } } private void Prodiodetail_SelectionChanged(object sender, EventArgs e) { if (Prodiodetail.SelectedRows.Count > 0) { DataGridViewSelectedRowCollection dsc = Prodiodetail.SelectedRows; Prodiodetail.Rows[dsc[0].Index].Selected = true; if (dsc[0].Index - 2 >= 0) Prodiodetail.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2; else Prodiodetail.FirstDisplayedScrollingRowIndex = dsc[0].Index; } } private void GenBarCode_Click(object sender, EventArgs e) { string sql = "select pr_zxbzs,pd_piid,pd_piclass,pd_inqty,pd_prodcode,pr_detail,pr_spec,nvl(bi_inqty,0)bi_inqty from " + "(select max(pd_piid)pd_piid,max(pd_piclass)pd_piclass,max(pd_prodcode)pd_prodcode,sum(pd_inqty)pd_inqty from prodiodetail left join product on pr_code=pd_prodcode where pd_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand)" + " left join (select max(bi_prodcode)bi_prodcode,nvl(sum(bi_inqty),0)bi_inqty from barcodeio left join product on pr_code=bi_prodcode " + "where bi_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand) on pd_prodcode=bi_prodcode left join product on pr_code=pd_prodcode " + "where pr_code='" + PR_CODE.Text + "'"; DataTable dt = (DataTable)dh.ExecuteSql(sql, "select"); if (dt.Rows.Count == 0) { Play("NG"); MessageBox.Show("物料不在对应入库单中" + pi_inoutno.Text); return; } if (pr_orispeccode2.Text != pr_orispeccode3.Text) { Play("NG"); MessageBox.Show("解析型号和单据型号不对应"); return; } ZXBZ.Text = dt.Rows[0]["pr_zxbzs"].ToString(); int pdinqty = int.Parse(dt.Rows[0]["pd_inqty"].ToString()); int barqty = int.Parse(dt.Rows[0]["bi_inqty"].ToString()); int Minpackage = 0; string pi_id = dt.Rows[0]["pd_piid"].ToString(); string pd_piclass = dt.Rows[0]["pd_piclass"].ToString(); //本次入库数 int NowInqty = int.Parse(INQTY.Text); if (!int.TryParse(ZXBZ.Text, out Minpackage)) { Play("NG"); MessageBox.Show("最小包装数错误,料号" + PR_CODE.Text); return; } if (int.Parse(INQTY.Text) > pdinqty - barqty) { Play("NG"); MessageBox.Show("物料采集后超出入库单数量" + PR_CODE.Text); return; } string outboxcode = ""; if (GenBoxCode.Checked) { string[] param = new string[] { PR_CODE.Text, "", outboxcode }; dh.CallProcedure("SP_GETBOX", ref param); outboxcode = param[2].Replace("BOX:", ""); } //生成条码数量 int barcount = NowInqty % Minpackage == 0 ? NowInqty / Minpackage : (NowInqty / Minpackage) + 1; List bi_inqty = new List(); List bi_barcode = new List(); List bi_vendbarcode = new List(); List bi_madedate = new List(); List bi_sccode = new List(); for (int i = 0; i < barcount; i++) { string barcode = ""; int OneUnit = 0; string[] param = new string[] { PR_CODE.Text, "", barcode }; dh.CallProcedure("SP_GETBARCODE", ref param); barcode = param[2].Replace("BARCODE:", ""); //如果最后有尾数的话 if (i == barcount - 1) { if (NowInqty % Minpackage == 0) { OneUnit = Minpackage; } else { OneUnit = NowInqty % Minpackage; } } else { OneUnit = Minpackage; } bi_inqty.Add(OneUnit.ToString()); bi_barcode.Add(barcode); bi_vendbarcode.Add(LOTNO.Text); bi_madedate.Add(DC.Text); bi_sccode.Add(SCCODE.Text); } sql = "insert into barcodeio(BI_ID, BI_BARCODE, BI_PIID, BI_PICLASS, BI_INOUTNO, BI_PDNO, BI_PDID, BI_PRODCODE, BI_INQTY,bi_vendbarcode, " + "BI_MADEDATE, BI_PRODID, BI_STATUS, BI_ORDERCODE, BI_INMAN, BI_INDATE,BI_OUTBOXCODE,bi_sccode)select barcodeio_seq.nextval,:bi_barcode,'" + pi_id + "'," + "'" + pd_piclass + "','" + pi_inoutno.Text + "',0,0,'" + PR_CODE.Text + "',:bi_inqty,:bi_vendbarcode,to_date(:bi_madedate,'yyyy-mm-dd'),pr_id,0,'','管理员',sysdate,'" + outboxcode + "',:bi_sccode " + " from product where pr_code='" + PR_CODE.Text + "'"; dh.BatchInsert(sql, new string[] { "bi_inqty", "bi_barcode", "bi_vendbarcode", "bi_madedate" , "bi_sccode" }, bi_barcode.ToArray(), bi_inqty.ToArray(), bi_vendbarcode.ToArray(), bi_madedate.ToArray(),bi_sccode.ToArray()); LoadGridData(); LoadBarcodeioData(PR_CODE.Text); } private void LoadBarcodeioData(string pr_code) { string sql = "select 0 CheckBox,bi_sccode,bi_barcode,bi_inqty,bi_datecode,bi_outboxcode,bi_vendbarcode,to_char(bi_madedate,'yyyy-mm-dd')bi_madedate,pr_detail,pr_spec,bi_prodcode,pr_orispeccode from barcodeio left join product on bi_prodcode=pr_code where bi_inoutno='" + pi_inoutno.Text + "' and bi_prodcode='" + pr_code + "'"; DataTable dt = (DataTable)dh.ExecuteSql(sql, "select"); BaseUtil.FillDgvWithDataTable(BarcodeIO, dt); } private void PrintBarCode_Click(object sender, EventArgs e) { for (int i = 0; i < BarcodeIO.Rows.Count; i++) { if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True") { for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++) { if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "BARCODE") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_barcode"].Value.ToString(); } if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_madedate"].Value.ToString(); } if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "LOTNO") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_vendbarcode"].Value.ToString(); } if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "QTY") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_inqty1"].Value.ToString(); } if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRCODE") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_prodcode"].Value.ToString(); } if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRSPEC") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["pr_spec1"].Value.ToString(); } if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRDETAIL") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["pr_detail1"].Value.ToString(); } if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "ORISPEC") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["pr_orispeccode"].Value.ToString(); } } SingleDoc.Printer.SwitchTo(PrinterList.Text); SingleDoc.PrintDocument(); } } } private void Prodiodetail_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString() != "") { } } int SelectIndex = 0; private void Prodiodetail_CellClick(object sender, DataGridViewCellEventArgs e) { if (Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString() != "") { LoadBarcodeioData(Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString()); Console.WriteLine(Prodiodetail.Rows[e.RowIndex].Cells["pr_brand"].Value.ToString()); es_custcode.Text = Prodiodetail.Rows[e.RowIndex].Cells["pr_brand"].Value.ToString(); PR_CODE.Text = Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString(); pr_orispeccode2.Text = Prodiodetail.Rows[e.RowIndex].Cells["pr_orispeccode1"].Value.ToString(); LoadBarcodeioData(Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString()); SelectIndex = e.RowIndex; } } private void ChooseAll_Click(object sender, EventArgs e) { for (int i = 0; i < BarcodeIO.Rows.Count; i++) { BarcodeIO.Rows[i].Cells["CheckBox"].Value = true; } } private void PrintBox_Click(object sender, EventArgs e) { List outboxcode = new List(); for (int i = 0; i < BarcodeIO.Rows.Count; i++) { if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True") { if (!outboxcode.Contains(BarcodeIO.Rows[i].Cells["bi_outboxcode"].FormattedValue)) { outboxcode.Add(BarcodeIO.Rows[i].Cells["bi_outboxcode"].Value.ToString()); } } } string[] box = outboxcode.ToArray(); for (int i = 0; i < box.Length; i++) { string sql = "select bi_outboxcode,sum(bi_inqty)bi_inqty,max(bi_datecode)bi_datecode,max(bi_vendbarcode)bi_vendbarcode,max(to_char(bi_madedate,'yyyy-mm-dd'))bi_madedate," + "max(pr_detail)pr_detail,max(pr_spec)pr_spec,max(bi_prodcode)bi_prodcode,max(pr_orispeccode)pr_orispeccode,max(pr_detail)pr_detail from barcodeio left join product on bi_prodcode=pr_code where bi_outboxcode='" + box[i] + "' group by bi_outboxcode"; DataTable dt = (DataTable)dh.ExecuteSql(sql, "select"); for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++) { if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "BARCODE") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_outboxcode"].ToString(); } if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_madedate"].ToString(); } if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "LOTNO") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_vendbarcode"].ToString(); } if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "QTY") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_inqty"].ToString(); } if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRCODE") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_prodcode"].ToString(); } if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRSPEC") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["pr_spec"].ToString(); } if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRDETAIL") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["pr_detail"].ToString(); } if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "ORISPEC") { if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null) OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["pr_orispeccode"].ToString(); } } OutDoc.Printer.SwitchTo(PrinterList.Text); OutDoc.PrintDocument(); } } private void PrintStockBarCode_Click(object sender, EventArgs e) { 库存条码打印 form = new 库存条码打印(); form.ShowDialog(); } private void DeletaBarcode_Click(object sender, EventArgs e) { for (int i = 0; i < BarcodeIO.Rows.Count; i++) { if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True") { dh.ExecuteSql("delete from barcodeio where bi_barcode='" + BarcodeIO.Rows[i].Cells["bi_barcode"].Value.ToString() + "'", "delete"); } } LoadBarcodeioData(PR_CODE.Text); } Thread thread; string FileName = ""; public void Play(string Type) { if (Type == "OK") { FileName = System.Windows.Forms.Application.StartupPath + @"\Resources\Sound\8378.wav"; thread = new Thread(PlaySound); thread.Start(); } else { FileName = System.Windows.Forms.Application.StartupPath + @"\Resources\Sound\5185.wav"; thread = new Thread(PlaySound); thread.Start(); } } private void PlaySound() { //要加载COM组件:Microsoft speech object Library if (!System.IO.File.Exists(FileName)) { return; } try { SoundPlayer player = new SoundPlayer(); player.SoundLocation = FileName; player.Load(); player.Play(); } catch (Exception e) { MessageBox.Show(e.Message); } } } }