123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- 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)
- {
- pr_code.TableName = "product";
- pr_code.SelectField = "pr_code # 物料编号 ,pr_orispeccode # 原厂型号 ,pr_brand # 品牌,pr_zxbzs # 最小包装";
- pr_code.FormName = Name;
- pr_code.DBTitle = "物料资料查询";
- pr_code.SetValueField = new string[] { "pr_code", "pr_orispeccode", "pr_brand", "pr_zxbzs" };
- pr_code.Condition = "";
- pr_code.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 + @"\BOXCODESTOCK.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 = pr_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- }
- private void pi_inoutnokeydown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- }
- }
- 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='" + pr_brand.Text + "'", "select");
- if (dt.Rows.Count == 0)
- {
- MessageBox.Show("无条码解析规则");
- Play("NG");
- return;
- }
- string split = dt.Rows[0]["el_type"].ToString();
- string[] str = Barcode.Text.Split(split.ToCharArray()[0]);
- //分割后的字符串数组需要大于设置的参数解析
- if (str.Length < dt.Rows.Count)
- {
- MessageBox.Show("无条码解析规则");
- Play("NG");
- 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":
- sc_code.Text = str[int.Parse(index) - 1];
- break;
- default:
- break;
- }
- }
- string madedate;
- string outqty;
- string lotno;
- string spec;
- LogicHandler.GetWeekData(DC.Text, INQTY.Text, pr_brand.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 GenBarCode_Click(object sender, EventArgs e)
- {
- if (pr_orispeccode.Text != pr_orispeccode3.Text)
- {
- MessageBox.Show("解析型号和单据型号不对应");
- Play("NG");
- return;
- }
- int Minpackage = 0;
- //本次入库数
- int NowInqty = int.Parse(INQTY.Text);
- if (!int.TryParse(pr_zxbzs.Text, out Minpackage))
- {
- MessageBox.Show("最小包装数错误,料号" + pr_code.Text);
- Play("NG");
- 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<string> BAR_inqty = new List<string>();
- List<string> bar_code = new List<string>();
- List<string> bar_vendbarcode = new List<string>();
- List<string> bar_madedate = new List<string>();
- List<string> bar_sccode = new List<string>();
- 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;
- }
- BAR_inqty.Add(OneUnit.ToString());
- bar_code.Add(barcode);
- bar_vendbarcode.Add(LOTNO.Text);
- bar_madedate.Add(DC.Text);
- bar_sccode.Add(sc_code.Text);
- }
- string sql = "insert into barcode(BAR_ID, bar_code, bar_prodcode, BAR_remain,bar_vendbarcode, " +
- "bar_madedate, BAR_PRODID, BAR_STATUS, BAR_CHECKMAN, BAR_INDATE,BAR_OUTBOXCODE1,bar_sccode)select barcode_seq.nextval,:bar_code," +
- "'" + pr_code.Text + "',:bar_remain,:bar_vendbarcode,to_date(:bar_madedate,'yyyy-mm-dd'),pr_id,1,'管理员',sysdate,'" + outboxcode + "',:bar_sccode " +
- " from product where pr_code='" + pr_code.Text + "'";
- dh.BatchInsert(sql, new string[] { "bar_code", "bar_remain", "bar_vendbarcode", "bar_madedate", "bar_sccode" }, bar_code.ToArray(), BAR_inqty.ToArray(), bar_vendbarcode.ToArray(), bar_madedate.ToArray(), bar_sccode.ToArray());
- LoadBarcodeioData(pr_code.Text);
- }
- private void LoadBarcodeioData(string pr_code)
- {
- string sql = "select 0 CheckBox,bar_code,bar_remain,bar_indate,BAR_OUTBOXCODE1,bar_vendbarcode,to_char(bar_madedate,'yyyy-mm-dd')bar_madedate,pr_detail,pr_spec,bar_prodcode,pr_orispeccode,bar_sccode from barcode left join product on bar_prodcode=pr_code where to_char(bar_indate,'yyyy-mm-dd')='" + bar_indate.Value.ToString("yyyy-MM-dd") + "' and bar_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["bar_madedate"].Value != null)
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bar_code"].Value.ToString();
- }
- if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bar_madedate"].Value.ToString();
- }
- if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "LOTNO")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bar_vendbarcode"].Value.ToString();
- }
- if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "QTY")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bar_remain"].Value.ToString();
- }
- if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRCODE")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bar_prodcode"].Value.ToString();
- }
- if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRSPEC")
- {
- if (BarcodeIO.Rows[i].Cells["bar_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["bar_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["bar_madedate"].Value != null)
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["pr_orispeccode4"].Value.ToString();
- }
- }
- SingleDoc.Printer.SwitchTo(PrinterList.Text);
- SingleDoc.PrintDocument();
- }
- }
- }
- 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<string> outboxcode = new List<string>();
- 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["BAR_OUTBOXCODE1"].FormattedValue))
- {
- outboxcode.Add(BarcodeIO.Rows[i].Cells["BAR_OUTBOXCODE1"].Value.ToString());
- }
- }
- }
- string[] box = outboxcode.ToArray();
- for (int i = 0; i < box.Length; i++)
- {
- string sql = "select BAR_OUTBOXCODE1,sum(BAR_remain)BAR_remain,max(bar_vendbarcode)bar_vendbarcode,max(to_char(bar_madedate,'yyyy-mm-dd'))bar_madedate," +
- "max(pr_detail)pr_detail,max(pr_spec)pr_spec,max(bar_prodcode)bar_prodcode,max(pr_orispeccode)pr_orispeccode,max(pr_detail)pr_detail from barcode left join product on bar_prodcode=pr_code where BAR_OUTBOXCODE1='" + box[i] + "' group by BAR_OUTBOXCODE1";
- 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["bar_madedate"].Value != null)
- OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["BAR_OUTBOXCODE1"].ToString();
- }
- if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bar_madedate"].ToString();
- }
- if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "LOTNO")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bar_vendbarcode"].ToString();
- }
- if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "QTY")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["BAR_remain"].ToString();
- }
- if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRCODE")
- {
- if (BarcodeIO.Rows[i].Cells["bar_madedate"].Value != null)
- OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bar_prodcode"].ToString();
- }
- if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRSPEC")
- {
- if (BarcodeIO.Rows[i].Cells["bar_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["bar_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["bar_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 QueryBarcode_Click(object sender, EventArgs e)
- {
- 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);
- }
- }
- }
- }
|