using System; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Text.RegularExpressions; using System.Text; using System.Collections.Generic; using System.Diagnostics; using UAS_LabelMachine.PublicMethod; using UAS_LabelMachine.Entity; using UAS_LabelMachine.PublicForm; using System.Threading; using FastReport; using System.Linq; using System.Reflection; using UAS_LabelMachine.CustomControl; using System.Net.Sockets; namespace UAS_LabelMachine { public partial class UAS_出货标签打印 : Form { bool ConnectToMachine = false; //自适应屏幕 AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; DataTable dt; StringBuilder sql = new StringBuilder(); /// /// 单盘打印文件 /// Report SingleReport = new Report(); /// /// 中盒打印文件 /// Report MidReport = new Report(); /// /// 外箱打印文件 /// Report OutReport = new Report(); /// /// 唛头文件打印 /// Report FootReport = new Report(); /// /// Loading窗口 /// SetLoadingWindow stw; /// /// 弹窗线程 /// Thread thread; /// /// 当前品牌 /// string PI_ID; bool logout = false; //主表数据源 DataTable LabelInfDataTable; /// /// 存放单盘的ID /// List SingleID = new List(); /// /// 是否全选 /// bool AllChecked = false; DataTable SumQty; /// /// 是否通过选择Combox来改变打开的文件 /// bool ComBoxClickChangeLabelDoc = false; //当前采集的物料编号 string CurrentPrCode = ""; //当前采集的最小包装 string CurrentZXBZ = ""; //当前采集的单位 string CurrentUnit = ""; //当前采集的总数 string CurrentPrCount = ""; //当前明细序号 string CurrentPDNO = ""; //当前的物料品牌 string CurrentBrand = ""; string NrCode = ""; string Prefix = ""; string Suffix = ""; int MaxNum = 0; int NumLength = 0; int Radix = 0; private bool EnablePrint = true; string[] PIBID; DataTable Attach; //传送贴标角度 string Angle = ""; string X = ""; string Y = ""; bool CheckPassWord = true; //贴标机采集的行数 int MachineCollectRowIndex = 0; public UAS_出货标签打印(string Master) { this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles(); InitializeComponent(); //利用反射设置DataGridView的双缓冲 Type dgvType = this.LabelInf.GetType(); PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(this.LabelInf, true, null); pi.SetValue(this.GridPrcode, true, null); (new EnvironmentSettings()).ReportSettings.ShowProgress = false; Text = Text + "-" + Master; } //protected override void WndProc(ref Message m) //{ // //拦截双击标题栏、移动窗体的系统消息 // if (m.Msg != 0xA3) // { // base.WndProc(ref m); // } //} 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 贴标机条码打印_Load(object sender, EventArgs e) { //用计时器重置数据库链接 LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】"); dh = SystemInf.dh; CheckForIllegalCrossThreadCalls = false; pi_inoutno.Focus(); Point pt = new Point(); //禁止所有列的排序 foreach (DataGridViewColumn dgv in LabelInf.Columns) { dgv.SortMode = DataGridViewColumnSortMode.NotSortable; } foreach (DataGridViewColumn dgv in GridPrcode.Columns) { dgv.SortMode = DataGridViewColumnSortMode.NotSortable; } DataTable size = new DataTable(); size.Columns.Add("size_name"); size.Columns.Add("size_value"); DataRow dr = size.NewRow(); dr[0] = "大箱"; dr[1] = "38.3*38.3*20CM"; DataRow dr1 = size.NewRow(); dr1[0] = "中箱"; dr1[1] = "38.3*19*20CM"; DataRow dr2 = size.NewRow(); dr2[0] = "小盒"; dr2[1] = "19*19*6.5CM"; DataRow dr3 = size.NewRow(); dr3[0] = "小白盒07"; dr3[1] = "19*19*9CM"; DataRow dr4 = size.NewRow(); dr4[0] = "三星盒10"; dr4[1] = "18*12*18.3CM"; DataRow dr5 = size.NewRow(); dr5[0] = "国巨40"; dr5[1] = "39*30*21CM"; DataRow dr6 = size.NewRow(); dr6[0] = "国巨25"; dr6[1] = "32*20*21CM"; DataRow dr7 = size.NewRow(); dr7[0] = "国巨14"; dr7[1] = "19.5*16*20CM"; size.Rows.Add(dr); size.Rows.Add(dr1); size.Rows.Add(dr2); size.Rows.Add(dr3); size.Rows.Add(dr4); size.Rows.Add(dr5); size.Rows.Add(dr6); size.Rows.Add(dr7); pib_size.DataSource = size; pib_size.DisplayMember = "size_name"; pib_size.ValueMember = "size_value"; int ScreenWidth = Screen.GetWorkingArea(pt).Width; //设置获取当前屏幕大小自动全屏但是保留任务栏 Rectangle ScreenArea = Screen.GetWorkingArea(this); Top = 0; Left = 0; Width = ScreenArea.Width; Height = ScreenArea.Height; //OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity; MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity; if (MidboxCapacity.Value == 0) { MidboxCapacity.Value = 10; } DCCheck.Text = Properties.Settings.Default.DCCheck.ToString(); OutBoxPrinter.Text = Properties.Settings.Default.OPrinter; MidLabelPrinter.Text = Properties.Settings.Default.MPrinter; SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter; asc.controllInitializeSize(this); asc.controlAutoSize(this); RefreshDBConnect.Interval = 60000; RefreshDBConnect.Start(); } //只执行一次窗体自适应 bool AutoSized = false; private void 贴标机条码打印_SizeChanged(object sender, EventArgs e) { if (!AutoSized) { asc.controlAutoSize(this); AutoSized = true; } } private void LabelMaintain_Click(object sender, EventArgs e) { 客户标签维护 form = new 客户标签维护(); BaseUtil.SetFormCenter(form); form.FormClosed += LabelFormClose; form.ShowDialog(); } int combined = 0; private void LabelFormClose(object sender, EventArgs e) { GetInOutInfAndLabelFile(); } int PassTenCount = 1; int PassSixTenCount = 1; //输入框Enter事件 private void Input_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (Input.Text == "") { richTextAutoBottom1.AppendText("采集的数据不能为空\n"); receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))); return; } CollectInputData(); } } /// /// 采集数据 /// private void CollectInputData() { if (Input.Text == "SC") { PrintStatus.PerformClick(); Input.Text = ""; return; } Input.Text = Input.Text.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", ""); Dictionary Data = new Dictionary(); string[] SplitData = Input.Text.Split('*'); string[] SplitData2 = Input.Text.Split('*'); if (SplitData.Length < 5) { SplitData2 = Input.Text.Split(System.Convert.ToChar(29));//< GS > SplitData2 = Regex.Split(Input.Text, "", RegexOptions.IgnoreCase); String qty; for (int i = 0; i < SplitData2.Length; i++) { Console.WriteLine(SplitData2[i]); } if (SplitData2.Length < 10) { richTextAutoBottom1.AppendText("数据格式错误,无法解析\n"); if (ConnectToMachine) { receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))); } //Input.SelectAll(); return; } else { String qtycheck = SplitData2[3].Substring(1, SplitData2[3].Length - 1).Split('/')[0]; try { qty = SplitData2[3].Substring(1, SplitData2[3].Length - 1).Split('/')[1]; } catch { qty = SplitData2[3].Substring(1, SplitData2[3].Length - 1).Split('/')[0]; } if (dh.CheckExist("product", "pr_code = '" + SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "-" + SplitData2[1].Substring(SplitData2[1].Length - 3, 3) + "'")) { Data.Add("PRCODE", SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "-" + SplitData2[1].Substring(SplitData2[1].Length - 3, 3)); } else if (dh.CheckExist("product", "pr_specvalue = '" + SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "' and pr_nexbzs_user = '" + qtycheck + "' ")) { Data.Add("PRCODE", dh.getFieldDataByCondition("product", "pr_code", "pr_specvalue = '" + SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "' and pr_nexbzs_user = '" + qtycheck + "'").ToString()); } else { Data.Add("PRCODE", ""); } } Data.Add("QTY", qty); Data.Add("DATECODE", SplitData2[4].Substring(2, SplitData2[4].Length - 2)); if (checkBox1.Checked) { Data.Add("BRAND", "P"); } else { Data.Add("BRAND", "NEX"); } Data.Add("LOTNO", SplitData2[5].Substring(2, SplitData2[5].Length - 2)); Data.Add("PO", SplitData2[5].Substring(2, SplitData2[5].Length - 2)); Data.Add("SERIAL", SplitData2[5].Substring(2, SplitData2[5].Length - 2)); } else { for (int i = 0; i < SplitData.Length; i++) { switch (i.ToString()) { case "0": Data.Add("PRCODE", SplitData[i]); break; case "1": Data.Add("QTY", SplitData[i]); break; case "2": Data.Add("DATECODE", SplitData[i]); break; case "3": Data.Add("BRAND", SplitData[i]); break; case "4": Data.Add("LOTNO", SplitData[i]); break; case "5": Data.Add("PO", SplitData[i]); break; case "6": Data.Add("SERIAL", SplitData[i]); break; default: break; } } } if (Data["PRCODE"] != CurrentPrCode) { if (!MixPrCode.Checked) { richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】不对应,请重新采集\n"); //Input.SelectAll(); if (ConnectToMachine) receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); return; } else { bool FindProd = false; for (int i = 0; i < GridPrcode.Rows.Count; i++) { string prodcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString(); string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString(); string collectnum = GridPrcode.Rows[i].Cells["collectednum"].Value.ToString(); //判断其他行是否有料可以匹配 if (prodcode == Data["PRCODE"] && decimal.Parse(outqty) > decimal.Parse(collectnum)) { GridPrcode.Rows[i].Selected = true; FindProd = true; } } if (!FindProd) { richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】没有需要采集的内容\n"); //Input.SelectAll(); if (ConnectToMachine) receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); return; } } } //校验DateCode是否过期 if (!CheckDateCode(Data["DATECODE"])) { if (ConnectToMachine) { richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n"); receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); return; } else { string close = MessageBox.Show(this.ParentForm, "物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() != "Yes") return; } } if (CheckDC.Checked) { string datecode = dh.getFieldDataByCondition("prodiobarcode", "max(case when length(pib_datecode)=4 then pib_datecode else to_char(to_date(custdate(pib_datecode),'yyyy-mm-dd'),'yyiw') end )", "PIB_CUSTCODE='" + pi_cardcode.Text + "' and pib_inoutno<>'" + pi_inoutno.Text + "' and pib_prodcode='" + Data["PRCODE"] + "'").ToString(); string datecod1 = dh.getFieldDataByCondition("dual", "case when length('" + Data["DATECODE"] + "')=4 then '" + Data["DATECODE"] + "' else to_char(to_date(custdate('" + Data["DATECODE"] + "'),'yyyy-mm-dd'),'yyiw') end", "1=1").ToString(); //客户已经出货的最大年周 string Year = datecode.Substring(0, 2); System.DateTime dt = new DateTime(int.Parse("20" + Year), 01, 01); string Week = datecode.Substring(2, 2); System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7); //当前扫码的年周 string Year1 = datecod1.Substring(0, 2); System.DateTime dt2 = new DateTime(int.Parse("20" + Year1), 01, 01); string Week1 = datecod1.Substring(2, 2); System.DateTime dt3 = dt2.AddDays(int.Parse(Week1) * 7 + 7); //当前扫码的年周 if (dt1 > dt3) { MessageBox.Show("客户出货日期最近DC【" + datecode + "】,不允许采集【" + Data["DATECODE"] + "】"); return; } } if (Data["BRAND"] != CurrentBrand) { if (ConnectToMachine) { richTextAutoBottom1.AppendText("当前采集【品牌" + Data["BRAND"] + "】不对应\n"); receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); return; } else { string close = MessageBox.Show(this.ParentForm, "当前采集【品牌" + Data["BRAND"] + "】不对应", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() != "Yes") return; } } int CodeCount = 0; //如果单位是KPCS则需要除1000 double CollectNum = 0; if (CurrentUnit == "KPCS") { try { double.Parse(CurrentZXBZ); } catch (Exception) { MessageBox.Show("请检查最小包装数"); } //如果单位是KPCS则必须是1000的整数倍 if (decimal.Parse((Convert.ToDouble((double.Parse(Data["QTY"]) / 1000).ToString("0.000")) / Convert.ToDouble(double.Parse(CurrentZXBZ).ToString("0.000"))).ToString()) % 1 != 0) { richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分\n"); //Input.SelectAll(); if (ConnectToMachine) receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); return; } CodeCount = int.Parse((double.Parse(Data["QTY"]) / 1000 / double.Parse(CurrentZXBZ)).ToString()); CollectNum = double.Parse(Data["QTY"]) / 1000; } else { if (double.Parse(Data["QTY"]) % double.Parse(CurrentZXBZ) != 0) { richTextAutoBottom1.AppendText("采集【数量】无法按照最小包装数拆分\n"); if (ConnectToMachine) receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); //Input.SelectAll(); return; } CodeCount = int.Parse((double.Parse(Data["QTY"]) / double.Parse(CurrentZXBZ)).ToString()); CollectNum = double.Parse(Data["QTY"]); } string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : ""; //获取ID PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount); //加载完数据之后进行容量的判断 string pib_outboxcode2 = ""; int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length; if (ConnectToMachine) { if (BoxNum + CodeCount > OutboxCapacity.Value && AutoSetOutBox.Checked) { string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString(); //如果没有则从开始插入 if (maxoutbox == "") { pib_outboxcode2 = "1"; } else { pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString(); } OutBoxNum.Items.Clear(); DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select"); ItemObject io = new ItemObject("新增", "新增"); OutBoxNum.Items.Add(io); io = new ItemObject("全部", "全部"); OutBoxNum.Items.Add(io); io = new ItemObject(pib_outboxcode2, pib_outboxcode2); OutBoxNum.Items.Add(io); PassSixTenCount = 1; for (int i = 0; i < dt.Rows.Count; i++) { string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString(); io = new ItemObject(piboutboxcode2, piboutboxcode2); OutBoxNum.Items.Add(io); } if (OutBoxNum.Items.Count > 2) OutBoxNum.SelectedIndex = 2; BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length; } else { if (OutBoxNum.Text == "新增") { string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString(); //如果没有则从开始插入 if (maxoutbox == "") { pib_outboxcode2 = "1"; } else { pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString(); } OutBoxNum.Items.Clear(); DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select"); ItemObject io = new ItemObject("新增", "新增"); OutBoxNum.Items.Add(io); io = new ItemObject("全部", "全部"); OutBoxNum.Items.Add(io); io = new ItemObject(pib_outboxcode2, pib_outboxcode2); OutBoxNum.Items.Add(io); PassSixTenCount = 1; for (int i = 0; i < dt.Rows.Count; i++) { string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString(); io = new ItemObject(piboutboxcode2, piboutboxcode2); OutBoxNum.Items.Add(io); } if (OutBoxNum.Items.Count > 2) OutBoxNum.SelectedIndex = 2; BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length; } else { pib_outboxcode2 = OutBoxNum.Text; } } } else { if (BoxNum + CodeCount > OutboxCapacity.Value && AutoSetOutBox.Checked) { OutBoxNum.Text = "新增"; BoxNum = 0; } if (OutBoxNum.Text == "新增") { string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString(); //如果没有则从开始插入 if (maxoutbox == "") { pib_outboxcode2 = "1"; } else { pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString(); } } else { pib_outboxcode2 = OutBoxNum.Text; } if (!AutoPrintOutBox.Checked) { if (BoxNum + CodeCount > OutboxCapacity.Value && !AutoSetOutBox.Checked) { string close = MessageBox.Show(this.ParentForm, "箱号【" + OutBoxNum.Text + "】后超数量为" + (BoxNum + CodeCount) + ",超出容量" + OutboxCapacity.Value + ",是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close != "Yes") { Input.SelectAll(); return; } } } } if (OutBoxNum.Text == "全部") { MessageBox.Show("请选择指定箱号或者新增"); return; } //计算当前采集数量 string collectqty = dh.getFieldDataByCondition("prodiobarcode", "sum(pib_qty)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString(); double CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty)); if (Convert.ToDouble((CollectQty + CollectNum).ToString("0.000")) > Convert.ToDouble(double.Parse(CurrentPrCount).ToString("0.000"))) { richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount + "\n"); if (ConnectToMachine) receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); //Input.SelectAll(); return; } GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, CodeCount); List CustBarCode = new List(); if (!(Radix > 0)) { string close = MessageBox.Show(this.ParentForm, "未维护条码规则,是否继续生成", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() != "Yes") return; } for (int i = 0; i < CodeCount; i++) { if (Radix > 0) { string serialcode = BaseUtil.DToAny(MaxNum, Radix); for (int j = serialcode.ToString().Length; j < NumLength; j++) { serialcode = "0" + serialcode; } CustBarCode.Add(Prefix + serialcode + Suffix); MaxNum = MaxNum + 1; } else { CustBarCode.Add(""); } } string rulecode = ShareRule == "" ? NrCode : ShareRule; sql.Clear(); sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,"); sql.Append("PIB_BARCODE,PIB_CUSTBARCODE,PIB_QTY,pib_brand,pib_datecode,pib_lotno,PIB_OUTBOXCODE2,pib_inman,PIB_IFPRINT,PIB_ORDERCODE,PIB_CUSTPO,pib_remark,pib_midcapatity,pib_custcode,pib_ismachine,pib_rulecode,pib_remark1) "); sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,"); sql.Append("'" + pib_barcode + "',:PIB_CUSTBARCODE,'" + CurrentZXBZ + "','" + Data["BRAND"] + "','" + Data["DATECODE"] + "','" + Data["LOTNO"] + "','" + pib_outboxcode2 + "','" + User.UserCode + "','" + (EnablePrint && SingleLabelAutoPrint.Checked ? 1 : 0).ToString() + "',pd_ordercode,pd_pocode,pd_remark,'" + MidboxCapacity.Value + "','" + pi_cardcode.Text + "','" + (ConnectToMachine ? "Y" : "N") + "','" + rulecode + "','" + remarkinfo.Text + "'"); sql.Append("from prodinout left join prodiodetail on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pi_id='" + PI_ID + "' and pd_prodcode='" + CurrentPrCode + "' and pd_pdno='" + CurrentPDNO + "'"); int rowsnum = 0; try { rowsnum = dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray()); } catch (Exception) { if (ReSetType != " ") { dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'"); } else { dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'"); } CollectInputData(); return; } LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, Input.Text, "数据插入成功"); if (rowsnum == 0) { MessageBox.Show("未成功插入数据,请核对出货单当前明细", "提示"); } //更新流水号 if (!ConnectToMachine) { if (OutBoxNum.Text == "新增") { OutBoxNum.Items.Clear(); DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select"); ItemObject io = new ItemObject("新增", "新增"); OutBoxNum.Items.Add(io); io = new ItemObject("全部", "全部"); OutBoxNum.Items.Add(io); for (int i = 0; i < dt.Rows.Count; i++) { string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString(); io = new ItemObject(piboutboxcode2, piboutboxcode2); OutBoxNum.Items.Add(io); } if (OutBoxNum.Items.Count > 2) OutBoxNum.SelectedIndex = 2; } } LoadGridData(new object(), new EventArgs()); if (LabelInf.Rows.Count > 0) { LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true; } if (SingleLabelAutoPrint.Checked) { thread = new Thread(AutoPrintSingleLabel); stw = new SetLoadingWindow(thread, "正在打印单盘标签"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); if (ConnectToMachine) receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")))); } else { if (ConnectToMachine) receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|N"))); } if (SumQty.Columns.Count == 0) { sql.Clear(); sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno "); sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno "); SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); } //采集后重新计数,自动跳到下一行 if (SumQty == null) { sql.Clear(); sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno "); sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno "); SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); } collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString()); CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty)); if (Combindetail.Checked) combined = 1; if (CombindetailTwo.Checked) combined = 2; if (CombindetailThree.Checked) combined = 3; dh.UpdateByCondition("CS$InoutPrcode", "Collectednum='" + CollectQty + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + CurrentPDNO + "' and combined=" + combined); CollectNum = 0; double OutNum = 0; if (GridPrcode.SelectedRows.Count > 0) { GridPrcode.Rows[GridPrcode.SelectedRows[0].Index].Cells["CollectedNum"].Value = CollectQty; for (int i = 0; i < GridPrcode.Rows.Count; i++) { CollectNum += float.Parse(GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString()); OutNum += float.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()); } } Console.WriteLine(DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss:ffffff")); ProcessCount.Text = CollectNum + "/" + OutNum; if (CollectNum == OutNum) { dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packed'", "pi_inoutno='" + pi_inoutno.Text + "'"); } if (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) == 0) { if (LabelInf.Rows.Count > 0) LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true; if (AutoPrintMidBox.Checked) { CheckPassWord = false; MidLabelPrint.PerformClick(); CheckPassWord = true; } } //采集达到了数量进行换行 if (CollectQty == double.Parse(CurrentPrCount)) { if (AutoPrintMidBox.Checked && (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) != 0)) { CheckPassWord = false; MidLabelPrint.PerformClick(); CheckPassWord = true; } //需要换行,当前最后一盒 DataGridViewSelectedRowCollection selectrow = GridPrcode.SelectedRows; if (selectrow.Count > 0) { if (selectrow[0].Index + 1 < GridPrcode.Rows.Count) { string outqty = GridPrcode.Rows[selectrow[0].Index + 1].Cells["pd_outqty"].Value.ToString(); string collectnum = GridPrcode.Rows[selectrow[0].Index + 1].Cells["CollectedNum"].Value.ToString(); if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum)) { GridPrcode.Rows[selectrow[0].Index + 1].Selected = true; } } } } if (AutoPrintOutBox.Checked) { if (BoxNum + CodeCount >= OutboxCapacity.Value) { CheckPassWord = false; OutBoxLabelPrint.PerformClick(); CheckPassWord = true; } } GridPrcode.Refresh(); if (!IsSum) if (!forinput.Checked) { Input.Clear(); } else { RemainTxt(); } } private void AutoPrintSingleLabel() { if (EnablePrint) { //用标签本身的变量作为最外层的循环条件去匹配; StringBuilder ParamLog = new StringBuilder(); string pibid = ""; for (int i = 0; i < PIBID.Length; i++) { if (i != PIBID.Length - 1) pibid += "'" + PIBID[i] + "',"; else pibid += "'" + PIBID[i] + "'"; } if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) SingleReport.Load(SingleLabelCombox.SelectedValue.ToString()); for (int j = 0; j < SingleReport.Parameters.Count; j++) { SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, ""); for (int k = 0; k < Attach.Rows.Count; k++) { if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name) { SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString()); } } } StringBuilder sql = new StringBuilder(); sql.Clear(); sql.Append("select * from (select pb_ywmc_user 品牌英文名称,to_char(pi_date,'yyiw')出库年周,to_char(sysdate,'yyiw')当前DateCode,pi_remark 单据备注,pi_date-1 出库前一天,pib_outboxcode2 外箱号,pd_orderdetno 订单序号,pib_totalweight 总重,pr_ywmc_user 英文名称,pib_boxweight 箱重,nvl(pib_totalweight,0)-nvl(pib_boxweight,0) 净重,pib_id 主键ID,pd_pdno 出货序号,pib_prodcode 物料编号,pr_detail 物料名称,to_char(pi_date,'yyyy-mm-dd') 送达日期,pd_custprodspec 客户型号,pd_custproddetail 客户物料名称,pi_title 客户全称,cu_shortname 客户简称,pr_spec 物料规格,pib_custbarcode 客户条码,pib_custmidboxcode 中盒条码,pib_custoutboxcode 外箱条码,pib_inoutno 出货单号,"); sql.Append("PD_HBSL_USER 出库数量,PD_HBSL_USER*1000 出库数量k,pjd_orispeccode 原厂型号,pib_datecode DateCode,(week_to_date(pib_datecode))DateCode1,pd_remark 备注,pd_remark2 备注2,pd_remark3 备注3,pib_lotno LotNo,"); sql.Append("nvl(nvl(pd_brand,pib_brand),pr_brand)品牌,pr_unit 单位, to_char(pi_date,'yyyy-mm-dd')出库日期,PIB_QTY 最小封装数量,PIB_QTY*1000 最小封装数量k,pd_pocode 客户PO,pd_custprodcode CPN客户料号,"); sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-mm-dd') 有效期一年,"); sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-mm-dd') 有效期两年,"); sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-mm-dd') 有效期三年,"); sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-iw')有效期一年_年周,"); sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-iw')有效期两年_年周,"); sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-iw')有效期三年_年周,"); sql.Append("wh_ppmc_user 中文品牌,em_code 装箱员编号,em_name 装箱员名称 from prodiobarcode left join prodinout on pib_piid=pi_id left join product on pib_prodcode=pr_code left join ProdIODetail on pd_id=PIB_PDID "); sql.Append("left join PRODJOINVENDDETAIL on pjd_brand=pib_brand and pjd_prodcode=pib_prodcode left join customer on pi_cardcode=cu_code left join productcustomer on pc_custid=cu_id and pc_prodcode=pd_prodcode "); if (pibid.IndexOf(",") > 0) { sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman left join ProductBrand on pib_brand = pb_name where pib_id in (" + pibid + ") order by pib_custbarcode)prodiosingleinfo_view"); } else { sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman left join ProductBrand on pib_brand = pb_name where pib_id=" + pibid + " order by pib_custbarcode)prodiosingleinfo_view"); } DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); SingleReport.RegisterData(dt, "prodiosingleinfo_view"); SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true; SingleReport.PrintSettings.ShowDialog = false; SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text; try { SingleReport.Print(); } catch (Exception e) { MessageBox.Show(e.Message); return; } Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text; Properties.Settings.Default.Save(); LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功"); } } //关闭窗口前提示用户确认 private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e) { //如果不是注销的话 if (!logout) { string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() != "Yes") e.Cancel = true; else { LogManager.DoLog("关闭程序"); } } } /// /// 获取打印标签 /// private void GetInOutInfAndLabelFile() { ComBoxClickChangeLabelDoc = false; sql.Clear(); sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode "); sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' "); sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode,cl_date desc"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); SingleLabelCombox.DisplayMember = "cl_labelname"; SingleLabelCombox.ValueMember = "cl_labelurl"; SingleLabelCombox.DataSource = dt; sql.Clear(); sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode "); sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' "); sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode,cl_date desc"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); MidLabelCombox.DisplayMember = "cl_labelname"; MidLabelCombox.ValueMember = "cl_labelurl"; MidLabelCombox.DataSource = dt; sql.Clear(); sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode "); sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' "); sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode,cl_date desc"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); OutBoxCombox.DisplayMember = "cl_labelname"; OutBoxCombox.ValueMember = "cl_labelurl"; OutBoxCombox.DataSource = dt; ComBoxClickChangeLabelDoc = true; } bool LoadCheck = true; /// /// 出入库单录入框的回车事件 /// /// /// private void pi_inoutno_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { LoadCheck = false; Combindetail.Checked = false; CombindetailTwo.Checked = false; CombindetailThree.Checked = false; LoadCheck = true; if (!forinput.Checked) { Input.Clear(); } else { RemainTxt(); } sql.Clear(); sql.Append("select pi_id,pi_cardcode,pi_combine_user,pi_title,to_char(pi_date,'yyyymmdd')pi_date,nvl(pi_combine_user,0)pi_combine_user,nvl(cu_controlinout,0)cu_controlinout,nvl(cu_zxyq_user,' ')cu_zxyq_user from prodinout left join customer on pi_cardcode=cu_code where pi_inoutno='" + pi_inoutno.Text + "' and pi_invostatuscode='AUDITED'"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); if (dt.Rows.Count > 0) { pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString(); pi_title.Text = dt.Rows[0]["pi_title"].ToString(); pi_date.Text = dt.Rows[0]["pi_date"].ToString(); PI_ID = dt.Rows[0]["pi_id"].ToString(); cu_controlinout.Text = dt.Rows[0]["cu_controlinout"].ToString(); cu_zxyq_user.Text = dt.Rows[0]["cu_zxyq_user"].ToString(); switch (dt.Rows[0]["pi_combine_user"].ToString()) { case "1": Combindetail.Checked = true; break; case "2": CombindetailTwo.Checked = true; break; case "3": CombindetailThree.Checked = true; break; default: break; } PassTenCount = 1; PassSixTenCount = 1; if (pi_cardcode.Text != "ZGCC") { CustomerLabel.Enabled = false; } else { CustomerLabel.Enabled = true; } DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select"); if (XY.Rows.Count == 0) { XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select"); } if (XY.Rows.Count > 0) { Angle = XY.Rows[0]["px_angle"].ToString(); X = XY.Rows[0]["px_x"].ToString(); Y = XY.Rows[0]["px_y"].ToString(); } OutBoxNum_Click(new object(), new EventArgs()); LoadPrcodeData(); //获取条码规则 GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, 1); SingleID.Clear(); Input.Focus(); ////从后往前找未采集的行 for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--) { string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString(); string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString(); if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum)) { GridPrcode.Rows[i].Selected = true; MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index; if (i - 2 >= 0) GridPrcode.FirstDisplayedScrollingRowIndex = i - 2; else GridPrcode.FirstDisplayedScrollingRowIndex = i; } } pib_indate.Text = dh.getFieldDataByCondition("prodiobarcode", "min(to_char(pib_indate,'yyyy-mm-dd'))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString(); bi_inman.Text = dh.getFieldDataByCondition("barcodeio left join employee on bi_inman=em_code", "wm_concat(distinct em_name)", "bi_piid=" + PI_ID).ToString(); pib_inman.Text = dh.getFieldDataByCondition("prodiobarcode left join employee on pib_inman=em_code", "wm_concat(distinct em_name)", "pib_piid=" + PI_ID).ToString(); Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "' and lap_inman='" + User.UserCode + "'", "select"); thread = new Thread(GetInOutInfAndLabelFile); stw = new SetLoadingWindow(thread, "正在获取打印标签"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】"); } else MessageBox.Show("当前出入库单号不存在或者未审核!", "提示"); } } private void SingleBoxPrint() { if (EnablePrint) { if (LabelInf.Rows.Count > 0) { //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载 SingleID.Clear(); //获取全部的中盒号 Dictionary outboxcode1 = new Dictionary(); //判断所有盒号为该盒的是否勾选已采集 outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true); bool NeedPassword = false; for (int i = 0; i < LabelInf.Rows.Count; i++) { if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString())) SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()); if (LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString().ToUpper() == "TRUE") { NeedPassword = true; } } if (NeedPassword) { if (PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString()) { MessageBox.Show("密码不正确,不允许操作"); return; } } if (SingleID.ToArray().Length == 0) { MessageBox.Show("选择的行未勾选采集或者已打印", "提示"); return; } for (int i = 0; i < LabelInf.RowCount; i++) { if (i + 1 < LabelInf.RowCount) { //如果本行的中盒号和下一行不相等的话 if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()) { if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())) outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true); } } } string pibid = ""; for (int i = 0; i < LabelInf.RowCount; i++) { //勾选了并且未打印 if (LabelInf.Rows[i].Cells["Choose"].FormattedValue != null && LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true") { pibid += "'" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + "',"; LabelInf.Rows[i].Cells["pib_ifprint"].Value = true; } } if (pibid != "") { if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) SingleReport.Load(SingleLabelCombox.SelectedValue.ToString()); for (int j = 0; j < SingleReport.Parameters.Count; j++) { SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, ""); for (int k = 0; k < Attach.Rows.Count; k++) { if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name) { SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString()); } } } DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid.Substring(0, pibid.Length - 1) + ")", "select"); SingleReport.RegisterData(dt, "prodiosingleinfo_view"); SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true; //保存参数打印 SingleReport.PrintSettings.ShowDialog = false; SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text; try { SingleReport.Print(); } catch (Exception e) { MessageBox.Show(e.Message); return; } Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text; Properties.Settings.Default.Save(); } else { MessageBox.Show("未勾选打印明细", "提示", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印成功"); dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray()); outboxcode1.Clear(); } else { MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示"); return; } } } private void SingleLabelPrint_Click(object sender, EventArgs e) { if (SingleLabelCombox.Text != "") { if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "") { try { int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text); int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text); if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end) { for (int i = begin - 1; i < end; i++) { LabelInf.Rows[i].Cells["Choose"].Value = true; LabelInf.Rows[i].Cells["pib_ifprint"].Value = false; } } else { MessageBox.Show("单盘打印范围错误", "提示"); return; } } catch (Exception) { MessageBox.Show("单盘打印范围错误", "提示"); return; } } thread = new Thread(SingleBoxPrint); stw = new SetLoadingWindow(thread, "正在打印单盘"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); Input.Focus(); } else { MessageBox.Show("未维护单盘标签", "提示"); LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印失败,未维护标签"); } } private void MidBoxLabelPrint() { //if (CheckPassWord && PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString()) //{ // MessageBox.Show("密码不正确,不允许操作"); // return; //} //未输入内容打印全部中盒 if (MidLabelNum.Text == "") { int begin = 0; int end = 0; if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "") { try { begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text); end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text); int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString()); int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString()); if (begin >= minmidbox && end <= maxmidbox && begin <= end) { //设置中盒打印范围的行号 for (int i = 0; i < LabelInf.Rows.Count; i++) { if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin) { begin = i; } if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end) { end = i; } } } else { MessageBox.Show("中盒打印范围错误", "提示"); return; } } catch (Exception) { MessageBox.Show("中盒打印范围错误", "提示"); return; } } List MidOutBoxCode = new List(); List MidOutBoxCodeIndex = new List(); for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++) { try { if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))) { MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())); MidOutBoxCodeIndex.Add(i); } } catch (Exception) { MessageBox.Show("请先封箱!"); return; } } try { //如果有选中行 if (SelectRowIndex >= 0 && LabelInf.Rows.Count > SelectRowIndex) { MidOutBoxCode.Clear(); MidOutBoxCodeIndex.Clear(); SelectProdcode = LabelInf.Rows[SelectRowIndex].Cells["pib_prodcode"].Value.ToString(); for (int i = SelectRowIndex; i >= 0; i--) { if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex) { LabelInf.Rows[i].Cells["pib_midifprint"].Value = true; if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))) { MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())); MidOutBoxCodeIndex.Add(i); } } else { break; } } for (int i = SelectRowIndex; i < LabelInf.Rows.Count - 1; i++) { if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex) { LabelInf.Rows[i].Cells["pib_midifprint"].Value = true; if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))) { MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())); MidOutBoxCodeIndex.Add(i); } } else { break; } } } } catch (Exception e) { MessageBox.Show(e.Message); LogManager.DoLog(e.Message + e.StackTrace); return; } try { MidBoxCodePrint(MidOutBoxCodeIndex.ToArray()); } catch (Exception e) { MessageBox.Show(e.Message); LogManager.DoLog(e.Message + e.StackTrace); return; } return; } bool FindMidLabel = false; if (MidLabelCombox.SelectedValue != null) { //中盒号所在的行 int MidLabelRowIndex = 0; //缓存中盒数据 for (int i = 0; i < LabelInf.RowCount; i++) { if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) { //找到了输入的中盒号停止循环 FindMidLabel = true; MidLabelRowIndex = i; } } int[] rowindx = new int[] { MidLabelRowIndex }; //找到了指定的盒号 if (FindMidLabel) MidBoxCodePrint(rowindx); else MessageBox.Show("该出入库单未找到该中盒号!", "提示"); } else MessageBox.Show("未维护中盒模板", "提示"); } private void MidLabelPrint_Click(object sender, EventArgs e) { if (MidLabelCombox.Text != "") { PackMidBox_Click(sender, e); thread = new Thread(MidBoxLabelPrint); stw = new SetLoadingWindow(thread, "正在打印中盒"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); } else MessageBox.Show("未维护中盒标签", "提示"); Input.Focus(); } private void OutBoxPrint() { List Outboxcode = new List(); //如果未勾选箱号则对勾选的数据的箱号进行整合 if (OutBoxNum.Text == "" || OutBoxNum.Text == "全部") { for (int i = 0; i < LabelInf.RowCount; i++) { string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString(); //富为使用包装单的逻辑 //如果不包含该箱号则进行添加 if (!Outboxcode.Contains(outboxcode2)) Outboxcode.Add(outboxcode2); } //按获取到的箱号列表进行打印 if (Outboxcode.ToArray().Length > 0) { for (int i = 0; i < Outboxcode.ToArray().Length; i++) { for (int h = 0; h < LabelInf.RowCount; h++) { if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i]) { if (!AllLabel.Checked) OutBoxCodePrint(h); else OutBoxCodePrint(h, true); break; } } } } else { MessageBox.Show("请勾选需要打印的外箱", "提示"); } } else { bool FindMidLabel = false; try { int OutBoxLabelRowIndex = 0; //查找是否存在该中盒号 for (int i = 0; i < LabelInf.RowCount; i++) { if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString()) { //找到了输入的中盒号停止循环 FindMidLabel = true; OutBoxLabelRowIndex = i; break; } } //找到了指定的盒号 if (FindMidLabel) { if (!AllLabel.Checked) OutBoxCodePrint(OutBoxLabelRowIndex); else OutBoxCodePrint(OutBoxLabelRowIndex, true); } else MessageBox.Show("该出入库单未找到该外箱号!", "提示"); } catch (Exception) { } } LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标" + OutBoxNum.Text, "打印成功"); Outboxcode.Clear(); } private void MidBoxCodePrint(int[] rowindex) { if (EnablePrint) { string pib_outboxcode1 = ""; for (int i = 0; i < rowindex.Length; i++) { if (i != rowindex.Length - 1) pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'" + ","; else pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'"; } //名称相等的时候,取SQL进行值的查询 DataTable dt; sql.Clear(); sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' "); sql.Append(" and pib_outboxcode1 in(" + pib_outboxcode1 + ")"); dh.ExecuteSql(sql.ToString(), "update"); if (MidLabelAutoPrint.Checked) { if (CurrentRowOnly.Checked) { string PDNO = ""; if (SelectRowIndex >= 0) { PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString(); } dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select"); } else { dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ")", "select"); } } else { if (CurrentRowOnly.Checked) { string PDNO = ""; if (SelectRowIndex >= 0) { PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString(); } dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外' and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select"); } else { dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外'", "select"); } } if (dt.Rows.Count > 0) { if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) MidReport.Load(MidLabelCombox.SelectedValue.ToString()); for (int j = 0; j < MidReport.Parameters.Count; j++) { MidReport.SetParameterValue(MidReport.Parameters[j].Name, ""); for (int i = 0; i < Attach.Rows.Count; i++) { if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name) { MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString()); } } } MidReport.RegisterData(dt, "prodiomidinfo_view"); MidReport.GetDataSource("prodiomidinfo_view").Enabled = true; MidReport.PrintSettings.ShowDialog = false; MidReport.PrintSettings.Printer = MidLabelPrinter.Text; MidReport.Print(); dh.UpdateByCondition("prodiobarcode", "pib_midifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1 in (" + pib_outboxcode1 + ")"); SelectRowIndex = -1; LoadGridData(new object(), new EventArgs()); LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印中盒" + pib_outboxcode1.Replace("'", ""), "打印成功"); } Properties.Settings.Default.MPrinter = MidLabelPrinter.Text; Properties.Settings.Default.Save(); } } /// /// 执行打印外箱号 /// private void OutBoxCodePrint(int rowindex) { if (EnablePrint) { if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) OutReport.Load(OutBoxCombox.SelectedValue.ToString()); for (int j = 0; j < OutReport.Parameters.Count; j++) { OutReport.SetParameterValue(OutReport.Parameters[j].Name, ""); for (int i = 0; i < Attach.Rows.Count; i++) { if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name) { OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString()); } } } string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString(); string SQL = ""; if (OnlyOneRow.Checked) { SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "' and rownum=1"; } else { SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "'"; } DataTable dt = (DataTable)dh.ExecuteSql(SQL, "select"); OutReport.RegisterData(dt, "prodiooutinfo_view"); OutReport.GetDataSource("prodiooutinfo_view").Enabled = true; OutReport.PrintSettings.ShowDialog = false; OutReport.PrintSettings.Printer = OutBoxPrinter.Text; OutReport.Print(); Properties.Settings.Default.OPrinter = OutBoxPrinter.Text; Properties.Settings.Default.Save(); dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'"); } } /// /// 执行打印外箱号 /// private void OutBoxCodePrint(int rowindex, bool AllLabel) { if (EnablePrint) { int selectedindex = OutBoxCombox.SelectedIndex; for (int i = 0; i < OutBoxCombox.Items.Count; i++) { OutBoxCombox.SelectedIndex = i; if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) OutReport.Load(OutBoxCombox.SelectedValue.ToString()); for (int j = 0; j < OutReport.Parameters.Count; j++) { OutReport.SetParameterValue(OutReport.Parameters[j].Name, ""); for (int k = 0; k < Attach.Rows.Count; k++) { if (Attach.Rows[k][0].ToString() == OutReport.Parameters[j].Name) { OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[k][1].ToString()); } } } string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString(); DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select"); OutReport.RegisterData(dt, "prodiooutinfo_view"); OutReport.GetDataSource("prodiooutinfo_view").Enabled = true; OutReport.PrintSettings.ShowDialog = false; OutReport.PrintSettings.Printer = OutBoxPrinter.Text; OutReport.Print(); } OutBoxCombox.SelectedIndex = selectedindex; Properties.Settings.Default.OPrinter = OutBoxPrinter.Text; Properties.Settings.Default.Save(); dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'"); } } private string PassCheck() { PassWordConfirm form = new PassWordConfirm(); form.StartPosition = FormStartPosition.CenterScreen; form.ShowDialog(); return form.Controls["PassWord"].Text; } private void CleanDetail_Click(object sender, EventArgs e) { if (PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString()) { MessageBox.Show("密码不正确,不允许操作"); return; } if (dh.getFieldDataByCondition("prodinout", "pi_statuscode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString() == "POSTED") { MessageBox.Show("单据" + pi_inoutno.Text + "已过账,不允许删除条码"); return; } ArrayList DeleteID = new ArrayList(); for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true") DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()); } //勾选了删除的明细之后 if (DeleteID.ToArray().Length > 0) { string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") { dh.BatchInsert("insert into prodiobarcode_delete select * from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray()); dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray()); dh.UpdateByCondition("CS$InoutPrcode", "collectednum=(select nvl(sum(pib_qty),0) from prodiobarcode where pib_inoutno=pd_inoutno and pib_pdno=pd_pdno)", "pd_inoutno='" + pi_inoutno.Text + "'"); //dh.UpdateByCondition("CS$InoutPrcode", "checknum=CollectedNum/pjd_zxbzs_user", "pd_inoutno='" + pi_inoutno.Text + "'"); LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功"); MessageBox.Show("删除成功", "提示"); if (!forinput.Checked) { Input.Clear(); } else { RemainTxt(); } LoadPrcodeData(); LoadGridData(sender, e); if (int.Parse(dh.getFieldDataByCondition("prodiobarcode", "count(1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString()) == 0) { dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'"); } else { dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packing'", "pi_inoutno='" + pi_inoutno.Text + "'"); } } } else MessageBox.Show("尚未勾选需要删除的明细", "提示"); } private void OutBoxLabelPrint_Click(object sender, EventArgs e) { //if (CheckPassWord && PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString()) //{ // MessageBox.Show("密码不正确,不允许操作"); // return; //} if (OutBoxCombox.Text != "") { Pack_Click(sender, e); if (Weight.Text != "" && Weight.Text != "0.000") { //记录整箱的重量 sql.Clear(); sql.Append("update prodiobarcode set pib_totalweight='" + Weight.Text + "',pib_size='" + pib_size.SelectedValue + "' where pib_inoutno='" + pi_inoutno.Text + "' "); sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'"); dh.ExecuteSql(sql.ToString(), "update"); } LoadGridData(sender, e); thread = new Thread(OutBoxPrint); stw = new SetLoadingWindow(thread, "正在打印外箱"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); Input.Focus(); if (AutoAfterPrint.Checked) OutBoxNum.Text = "新增"; } else MessageBox.Show("未维护外箱标签", "提示"); Input.Focus(); } /// /// 自定义函数 加载明细行的数据,多处使用添加进函数 /// /// /// private void LoadGridData(object sender, EventArgs e) { AllChecked = false; string SQL = ""; if (OutBoxNum.Text != "全部") { //LogicHandler.GetDataSQL(PI_ID, "and pib_outboxcode2='" + OutBoxNum.Text + "'", out SQL); SQL = "select to_char(pib_indate,'yyyy-mm-dd hh24:mi:ss')pib_indate,pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," + "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," + "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " + "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " + "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode"; } else { SQL = "select to_char(pib_indate,'yyyy-mm-dd hh24:mi:ss')pib_indate,pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," + "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," + "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " + "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " + "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode"; } LabelInfDataTable = (DataTable)dh.ExecuteSql(SQL, "select"); BoxCount.Text = LabelInfDataTable.Compute("sum(pib_qty)", "1=1").ToString() + "KPCS"; bindingsource(LabelInf, LabelInfDataTable); if (LabelInf.Rows.Count > 0) { LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1; } sql.Clear(); sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno "); sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno "); SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); } private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { KeyEventArgs e2 = new KeyEventArgs(Keys.Enter); pi_inoutno_KeyDown(sender, e2); } private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") { Login login = new Login(); //注销的时候需要将拼接的连接字符串置空 DataHelper.DBConnectionString = null; logout = true; this.Hide(); login.ShowDialog(); this.Close(); } } private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { } /// /// 切换打开的单盘文件 /// /// /// private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e) { try { if (ComBoxClickChangeLabelDoc) { if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) SingleReport.Load(SingleLabelCombox.SelectedValue.ToString()); } } catch (Exception) { } } /// /// 切换打开的中盒文件 /// /// /// private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e) { try { if (ComBoxClickChangeLabelDoc) { if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) MidReport.Load(MidLabelCombox.SelectedValue.ToString()); } } catch (Exception) { } } /// /// 切换打开的外箱文件 /// /// /// private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e) { try { if (ComBoxClickChangeLabelDoc) { if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView")) OutReport.Load(OutBoxCombox.SelectedValue.ToString()); } } catch (Exception) { } } private void ChooseAll_Click(object sender, EventArgs e) { if (AllChecked) { foreach (DataGridViewRow dr in LabelInf.Rows) dr.Cells[0].Value = false; AllChecked = false; } else { foreach (DataGridViewRow dr in LabelInf.Rows) dr.Cells[0].Value = true; AllChecked = true; } } private void ExportData_Click(object sender, EventArgs e) { ShowMenu.Items.Clear(); DataTable dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode='" + pi_cardcode.Text + "'", "select"); if (dt.Rows.Count == 0) dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode is null", "select"); for (int i = 0; i < dt.Rows.Count; i++) { ShowMenu.Items.Add(new ToolStripMenuItem(dt.Rows[i]["el_remark"].ToString() + "#" + dt.Rows[i]["el_type"].ToString())); } ShowMenu.Show(new Point(ExportData.Location.X, ExportData.Location.Y + 20)); } private void ShowMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { //获取类型,单盘或者外箱 string type = e.ClickedItem.Text.Split('#')[1]; ExportFileDialog.Description = "选择导出的路径"; DialogResult result = ExportFileDialog.ShowDialog(); if (result == DialogResult.OK) { ExcelHandler eh = new ExcelHandler(); DataTable Field = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTINGdetail left join CS_EXPORTSETTING on es_id=esd_esid where es_custcode='" + pi_cardcode.Text + "' and esd_enable=-1 and esd_filed is not null and el_type='" + type + "' order by esd_detno", "select"); if (Field.Rows.Count == 0) { Field = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTINGdetail left join CS_EXPORTSETTING on es_id=esd_esid where es_custcode is null and es_isdefault=-1 and esd_enable=-1 and esd_filed is not null and el_type='" + type + "' order by esd_detno", "select"); } string Fileds = ""; for (int i = 0; i < Field.Rows.Count; i++) { Fileds += Field.Rows[i]["esd_filed"].ToString() + ","; } sql.Clear(); sql.Append("select " + Fileds.Substring(0, Fileds.Length - 1) + " from ExportView where pib_inoutno='" + pi_inoutno.Text + "'"); string finnalSQL = ""; LogicHandler.GetExportDataSQL(pi_inoutno.Text, pi_cardcode.Text, type, sql.ToString(), out finnalSQL); dt = (DataTable)dh.ExecuteSql(finnalSQL, "select"); eh.ExportExcel(dt, Field, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text + type); string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + type + ".xls"); } } private void AttachInfo_Click(object sender, EventArgs e) { if (pi_cardcode.Text != "") { 附件内容打印 att = new 附件内容打印(pi_cardcode.Text); att.ShowDialog(); } else MessageBox.Show("请先获取出库单信息", "提示"); } private void MidBoxCapacity_Leave(object sender, EventArgs e) { NumericUpDown nup = (NumericUpDown)sender; switch (nup.Name) { case "MidBoxCapacity": Properties.Settings.Default.MidBoxCapacity = nup.Value; Properties.Settings.Default.Save(); break; case "OutboxCapacity": Properties.Settings.Default.OutboxCapacity = nup.Value; Properties.Settings.Default.Save(); break; default: break; } } private void RefreshDBConnect_Tick(object sender, EventArgs e) { dh.ExecuteSql("select sysdate from dual", "select"); } DataTable CSPrcode; private void LoadPrcodeData() { DataTable Prcode = (DataTable)dh.ExecuteSql("select '' pd_piid,pd_inoutno,pd_remark,pd_custprodcode,pd_pocode,pd_whcode,pd_prodcode,'0' CollectedNum,'0' UnCollectedNum,pd_outqty,pr_unit,pd_brand,pjd_zxbzs_user,pjd_id,pd_pdno,pr_spec,0 checknum from prodiodetail left join prodinout on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode left join product on pd_prodcode=pr_code where pi_id='" + PI_ID + "' order by pd_pdno", "select"); GridPrcode.DataSource = Prcode; List RemoveIndex = new List(); double CollectNum = 0; double OutNum = 0; int combined = 0; if (Combindetail.Checked) combined = 1; if (CombindetailTwo.Checked) combined = 2; if (CombindetailThree.Checked) combined = 3; if (Combindetail.Checked || CombindetailTwo.Checked || CombindetailThree.Checked) { CSPrcode = (DataTable)dh.ExecuteSql("select pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,pd_pocode,nvl(checknum,0)checknum,pd_remark from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select"); if (CSPrcode.Rows.Count == 0) { int CurrentIndex = 0; for (int i = 0; i < GridPrcode.Rows.Count; i++) { string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString(); string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString(); string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString(); if (SumQty == null) { sql.Clear(); sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno "); sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno "); SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); } string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString()); CollectNum += double.Parse(collectqty == "" ? "0" : collectqty); OutNum += double.Parse(CurrentOutQTY); GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty; } for (int i = 0; i < GridPrcode.Rows.Count; i++) { if (i + 1 < GridPrcode.Rows.Count) { string BProdCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString(); string BCustProdCode = GridPrcode.Rows[i].Cells["pd_custprodcode1"].Value.ToString(); string BWhCode = GridPrcode.Rows[i].Cells["pd_whcode"].Value.ToString(); string BPrUnit = GridPrcode.Rows[i].Cells["pr_unit"].Value.ToString(); string BPrBrand = GridPrcode.Rows[i].Cells["pd_brand"].Value.ToString(); string BPoCode = GridPrcode.Rows[i].Cells["pd_pocode1"].Value.ToString(); string BRemark = GridPrcode.Rows[i].Cells["pd_remark1"].Value.ToString(); string FProdCode = GridPrcode.Rows[i + 1].Cells["pd_prodcode"].Value.ToString(); string FCustProdCode = GridPrcode.Rows[i + 1].Cells["pd_custprodcode1"].Value.ToString(); string FPrUnit = GridPrcode.Rows[i + 1].Cells["pr_unit"].Value.ToString(); string FrBrand = GridPrcode.Rows[i + 1].Cells["pd_brand"].Value.ToString(); string FWhCode = GridPrcode.Rows[i + 1].Cells["pd_whcode"].Value.ToString(); string FPoCode = GridPrcode.Rows[i + 1].Cells["pd_pocode1"].Value.ToString(); string FRemark = GridPrcode.Rows[i + 1].Cells["pd_remark1"].Value.ToString(); if (BProdCode == FProdCode && BPrBrand == FrBrand && BCustProdCode == FCustProdCode && (CombindetailTwo.Checked && FPoCode == BPoCode || Combindetail.Checked || CombindetailThree.Checked && FRemark == BRemark && FPoCode == BPoCode)) { GridPrcode.Rows[CurrentIndex].Cells["pd_outqty"].Value = double.Parse(GridPrcode.Rows[CurrentIndex].Cells["pd_outqty"].Value.ToString()) + double.Parse(GridPrcode.Rows[i + 1].Cells["pd_outqty"].Value.ToString()); GridPrcode.Rows[CurrentIndex].Cells["CollectedNum"].Value = double.Parse(GridPrcode.Rows[CurrentIndex].Cells["CollectedNum"].Value.ToString()) + double.Parse(GridPrcode.Rows[i + 1].Cells["CollectedNum"].Value.ToString()); RemoveIndex.Add(i + 1); } else { CurrentIndex = i + 1; } } } foreach (int item in RemoveIndex.OrderByDescending(x => x)) { (GridPrcode.DataSource as DataTable).Rows.RemoveAt(item); } } else GridPrcode.DataSource = CSPrcode; } else { CSPrcode = (DataTable)dh.ExecuteSql("select pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,pd_pocode,nvl(checknum,0)checknum,pd_remark from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select"); if (CSPrcode.Rows.Count == 0) { for (int i = 0; i < GridPrcode.Rows.Count; i++) { string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString(); string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString(); string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString(); if (SumQty == null) { sql.Clear(); sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno "); sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno "); SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); } string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString()); CollectNum += double.Parse(collectqty == "" ? "0" : collectqty); OutNum += double.Parse(CurrentOutQTY); GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty; } } else GridPrcode.DataSource = CSPrcode; } dh.UpdateByCondition("prodinout", "pi_combine_user=" + combined, "pi_inoutno='" + pi_inoutno.Text + "'"); if (CSPrcode.Rows.Count == 0) { sql.Clear(); sql.Append("insert into CS$InoutPrcode (pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,"); sql.Append("CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,combined,pd_pocode,pd_remark)"); sql.Append("values ('',:pd_pdno,:pd_custprodcode,:pd_whcode,:pd_prodcode,:CollectedNum,:UnCollectedNum,:pd_outqty,:pr_unit,:pr_spec,:pd_brand,:pjd_zxbzs_user,:pjd_id,:pd_inoutno,'" + combined + "',:pd_pocode,:pd_remark)"); dh.SaveDataTable((GridPrcode.DataSource as DataTable), "CS$InoutPrcode", "pd_piid", sql.ToString()); } else { CollectNum = float.Parse(CSPrcode.Compute("sum(CollectedNum)", "1=1").ToString()); OutNum = float.Parse(CSPrcode.Compute("sum(pd_outqty)", "1=1").ToString()); } ProcessCount.Text = CollectNum + "/" + OutNum; if (GridPrcode.Rows.Count > 0) { CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString(); CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString(); CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString(); CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString(); CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString(); CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString(); GridPrcode.Rows[0].Selected = true; } } private void OutBoxNum_Click(object sender, EventArgs e) { string OutBox = OutBoxNum.Text; OutBoxNum.Items.Clear(); DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select"); ItemObject io = new ItemObject("新增", "新增"); OutBoxNum.Items.Add(io); io = new ItemObject("全部", "全部"); OutBoxNum.Items.Add(io); for (int i = 0; i < dt.Rows.Count; i++) { string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString(); io = new ItemObject(pib_outboxcode2, pib_outboxcode2); OutBoxNum.Items.Add(io); } if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "") { if (dt.Rows.Count > 0) OutBoxNum.SelectedIndex = 2; else OutBoxNum.SelectedIndex = 0; } if (OutBox != "新增" && OutBox != "") OutBoxNum.Text = OutBox; } string ShareRule; string ReSetType = ""; /// /// 获取条码规则 /// /// /// /// /// /// /// private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count) { //获取编码规则 Prefix = ""; Suffix = ""; NrCode = ""; MaxNum = 0; SerialNumLength = 0; Radix = 0; DataTable Nr = (DataTable)dh.ExecuteSql("select nvl(nr_resettype,' ')nr_resettype,nr_sharerule,nr_code,nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + pi_cardcode.Text + "' order by nrd_detno", "select"); //如果没有则取公共规则 if (Nr.Rows.Count == 0) Nr = (DataTable)dh.ExecuteSql("select nvl(nr_resettype,' ')nr_resettype,nr_sharerule,nr_code,nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select"); //用于过滤参数的正则表达式 ReSetType = ""; if (Nr.Rows.Count > 0) { ShareRule = Nr.Rows[0]["nr_sharerule"].ToString(); DataTable dt1 = (DataTable)dh.ExecuteSql("select nvl(nr_resettype,' ')nr_resettype,nr_sharerule,nr_code,nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_code='" + ShareRule + "' order by nrd_detno", "select"); if (dt1.Rows.Count > 0) { Nr = dt1; } else { if (ShareRule != "") { MessageBox.Show("共享规则" + ShareRule + "不存在"); return; } } } if (Nr.Rows.Count > 0) { switch (Nr.Rows[0]["nr_resettype"].ToString()) { case "Year": sql.Clear(); sql.Append("to_char(sysdate,'yyyy')"); break; case "Month": sql.Clear(); sql.Append("to_char(sysdate,'yyyyMM')"); break; case "Week": sql.Clear(); sql.Append("to_char(sysdate,'yyyyiw')"); break; case "Day": sql.Clear(); sql.Append("to_char(sysdate,'yyyyMMdd')"); break; case " ": sql.Clear(); sql.Append("' '"); break; default: break; } ReSetType = dh.getFieldDataByCondition("dual", sql.ToString(), "1=1").ToString(); } Regex match = new Regex("{\\w+}"); //用于存放每一项的明细的数据 string[] NrData = new string[Nr.Rows.Count]; //流水长度 Dictionary NrDic = new Dictionary(); for (int m = 0; m < Nr.Rows.Count; m++) { NrCode = Nr.Rows[m]["nr_code"].ToString(); switch (Nr.Rows[m]["nrd_type"].ToString()) { //常量直接进行拼接 case "常量": Prefix += Nr.Rows[m]["nrd_sql"].ToString(); Suffix += Nr.Rows[m]["nrd_sql"].ToString(); break; case "SQL": string SQL = Nr.Rows[m]["nrd_sql"].ToString(); DataTable Temp; //如果不包含参数替换 if (SQL.IndexOf("{") == 0) { Temp = (DataTable)dh.ExecuteSql(SQL, "select"); } else { SQL = SQL.Replace("{pd_pdno}", CurrentPDNO); //替换参数后重新执行SQL foreach (Match mch in match.Matches(SQL)) { SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'"); } Temp = (DataTable)dh.ExecuteSql(SQL, "select"); } if (Temp.Rows.Count > 0) { Prefix += Temp.Rows[0][0].ToString(); Suffix += Temp.Rows[0][0].ToString(); } break; //流水需要通过MaxNumber去取 case "流水": string maxnum = ""; if (ReSetType != " ") { maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString(); } else { maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString(); } //设置当前流水 if (maxnum == "") { if (ReSetType != " ") { maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString(); } else { maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString(); } if (maxnum == "") { maxnum = "1"; } Count = int.Parse(maxnum) + Count; dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber,rmn_type) values(RuleMaxNum_seq.nextval,'" + (NrCode == "" ? "Default" : NrCode) + "','" + Prefix + "','" + Count + "','" + ReSetType + "')", "insert"); MaxNum = int.Parse(maxnum); } else { MaxNum = int.Parse(maxnum); if (ReSetType != " ") { dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'"); } else { dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'"); } } SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString()); Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString()); Suffix = ""; break; default: break; } } } private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e) { string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString(); string checknum = GridPrcode.Rows[e.RowIndex].Cells["checknum"].Value.ToString(); string pdno = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString(); if (GridPrcode.Columns[e.ColumnIndex].Name == "pjd_zxbzs_user") { dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'"); dh.UpdateByCondition("CS$INOUTPRCODE", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "' and pd_inoutno='" + pi_inoutno.Text + "'"); } if (GridPrcode.Columns[e.ColumnIndex].Name == "checknum") { //更新复核数据 dh.UpdateByCondition("CS$InoutPrcode", "checknum='" + checknum + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined); } //删除对应物料的明细 CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString(); CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString(); CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString(); CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString(); CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString(); CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString(); GridPrcode.Rows[e.RowIndex].Selected = true; if (e.RowIndex - 2 >= 0) GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2; else GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex; LoadGridData(sender, new EventArgs()); } private void GridPrcode_SelectionChanged(object sender, EventArgs e) { if (GridPrcode.SelectedRows.Count > 0) { DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows; MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index; CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString(); CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString(); CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString(); CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString(); CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString(); CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString(); GridPrcode.Rows[dsc[0].Index].Selected = true; if (dsc[0].Index - 2 >= 0) GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2; else GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index; } } private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { } private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { GridPrcode.Rows[e.RowIndex].Selected = true; if (e.RowIndex - 2 > 0) GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2; else GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex; } } private void DCCheck_Leave(object sender, EventArgs e) { try { Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text); Properties.Settings.Default.Save(); } catch (Exception) { MessageBox.Show("DC校验时间必须是整数"); } } /// /// 校验DateCode /// /// private bool CheckDateCode(string DateCode) { try { //根据DateCode计算的日期 string Year = DateCode.Substring(0, 2); System.DateTime dt = new DateTime(int.Parse("20" + Year), 01, 01); string Week = DateCode.Substring(2, 2); System.DateTime dt1 = dt.AddDays((int.Parse(Week) -1)* 7); //减去DC校验后的日期 System.DateTime now = System.DateTime.Now; System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text)); //物料的DateCode大于限制日期即可 if (dt1 > now1 && dt1 < now) { return true; } return false; } catch (Exception) { return false; } } private void PrintFooter_Click(object sender, EventArgs e) { FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx"); DataTable dt = (DataTable)dh.ExecuteSql("select pib_outboxcode2,max(pib_id) pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' group by pib_outboxcode2 order by to_number(pib_outboxcode2)", "select"); string SQL = "select pib_outboxcode2||'/'||(select max(to_number(pib_outboxcode2)) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id="; for (int i = 0; i < dt.Rows.Count; i++) { DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + "'" + dt.Rows[i]["pib_id"].ToString() + "'", "select"); FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString()); FootReport.PrintSettings.ShowDialog = false; FootReport.PrintSettings.Printer = SingleLabelPrinter.Text; FootReport.Print(); } LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功"); } private void Input_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (!forinput.Checked) Input.SelectAll(); } } private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position)); if (e.ColumnIndex > 0 && e.RowIndex >= 0) { if (GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum") { SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255)); if (GridPrcode.Rows[e.RowIndex].Cells["CollectedNum"].Value.ToString() != GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].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 GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0 && e.ColumnIndex > 0) { string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); Clipboard.SetText(Conetent); MessageBox.Show("已复制内容" + Conetent); } } } private void Pack_Click(object sender, EventArgs e) { if (LabelInf.Rows.Count > 0) { int GetNumCount = 1; for (int i = 0; i < LabelInf.Rows.Count; i++) { if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "") { if (i + 1 < LabelInf.Rows.Count) { string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString(); string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString(); string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString(); string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString(); string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString(); string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString(); string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString(); string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString(); string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString(); string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString(); string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString(); string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString(); if (FPDCustProdCode != BPDCustProdCode || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO)) { GetNumCount = GetNumCount + 1; } } } } GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount); List OutBoxCode = new List(); List PIBID = new List(); string Str_OutBoxCode = ""; for (int i = 0; i < LabelInf.Rows.Count; i++) { if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "") { PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()); string serialcode = BaseUtil.DToAny(MaxNum, Radix); for (int k = serialcode.ToString().Length; k < NumLength; k++) { serialcode = "0" + serialcode; } if (i + 1 < LabelInf.Rows.Count) { string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString(); string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString(); string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString(); string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString(); string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString(); string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString(); string FPDNO = LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString(); string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString(); string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString(); string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString(); string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString(); string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString(); string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString(); string BPDNO = LabelInf.Rows[i + 1].Cells["pib_pdno"].Value.ToString(); if ((DiffDetno.Checked && BPDNO != FPDNO) || (DiffCPN.Checked && FPDCustProdCode != BPDCustProdCode) || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO)) { MaxNum = MaxNum + 1; } } OutBoxCode.Add(Prefix + serialcode + Suffix); Str_OutBoxCode += "'" + Prefix + serialcode + Suffix + "',"; } } if (OutBoxCode.ToArray().Length > 0) { if (!dh.CheckExist("prodiobarcode", "pib_custcode='" + pi_cardcode.Text + "' and pib_custoutboxcode in (" + Str_OutBoxCode.Substring(0, Str_OutBoxCode.Length - 1) + ")")) { dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_id=:pib_id and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBID.ToArray()); } else { if (ReSetType != " ") { dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'"); } else { dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'"); } Pack_Click(sender, e); return; } LoadGridData(sender, e); } } } private void PackMidBox_Click(object sender, EventArgs e) { DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by pib_outboxcode2", "select"); DataTable dt1 = null; int GetNumCount = 0; for (int i = 0; i < dt.Rows.Count; i++) { dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' and pib_outboxcode1 is null order by to_number(pib_id)", "select"); //如果不是10的整数倍则为尾盒 int tencount = 0; for (int j = 0; j < dt1.Rows.Count; j++) { if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()) || (dt1.Rows[j]["pd_custprodcode"].ToString() != dt1.Rows[j - 1]["pd_custprodcode"].ToString())) { GetNumCount = GetNumCount + 1; } tencount = tencount + 1; } } GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount); if (Radix > 0) { //生成中盒条码 int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString()); MaxNum = MaxNum - 1; for (int i = 0; i < dt.Rows.Count; i++) { List MidBoxCode = new List(); List PIBID = new List(); List PIBOUTBOXCODE1 = new List(); dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' and pib_outboxcode1 is null order by to_number(pib_id)", "select"); //如果不是10的整数倍则为尾盒 int tencount = 0; for (int j = 0; j < dt1.Rows.Count; j++) { if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()) || (dt1.Rows[j]["pd_custprodcode"].ToString() != dt1.Rows[j - 1]["pd_custprodcode"].ToString())) { pib_outboxcode1 = pib_outboxcode1 + 1; MaxNum = MaxNum + 1; tencount = 0; } tencount = tencount + 1; string serialcode = BaseUtil.DToAny(MaxNum, Radix); for (int k = serialcode.ToString().Length; k < NumLength; k++) { serialcode = "0" + serialcode; } MidBoxCode.Add(Prefix + serialcode + Suffix); PIBID.Add(dt1.Rows[j]["pib_id"].ToString()); PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString()); } dh.BatchInsert("update prodiobarcode set pib_custmidboxcode=:pib_custmidboxcode,pib_outboxcode1=:pib_outboxcode1 where pib_id=:pib_id and pib_custmidboxcode is null", new string[] { "pib_custmidboxcode", "pib_outboxcode1", "pib_id" }, MidBoxCode.ToArray(), PIBOUTBOXCODE1.ToArray(), PIBID.ToArray()); } } LoadGridData(sender, e); } private void PrintStatus_Click(object sender, EventArgs e) { EnablePrint = !EnablePrint; if (EnablePrint) { SetPrintStatus_label.ForeColor = Color.Green; SetPrintStatus_label.Text = "可打印"; } else { SetPrintStatus_label.ForeColor = Color.Red; SetPrintStatus_label.Text = "暂停打印"; } Input.Focus(); } private void CustomerLabel_Click(object sender, EventArgs e) { sql.Clear(); sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 "); sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr"); sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'"); dh.ExecuteSql(sql.ToString(), "select"); LoadGridData(sender, e); CustomerLabel.Enabled = false; } private void Combindetail_CheckedChanged(object sender, EventArgs e) { if (Combindetail.Checked) { CombindetailTwo.Checked = false; CombindetailThree.Checked = false; } if (LoadCheck) { LoadPrcodeData(); string response = ""; string[] param = new string[] { PI_ID, "1", response }; dh.CallProcedure("USER_PRODOUT_GROUPQTY", param); } } private void CombindetailTwo_CheckedChanged(object sender, EventArgs e) { if (CombindetailTwo.Checked) { Combindetail.Checked = false; CombindetailThree.Checked = false; } if (LoadCheck) { LoadPrcodeData(); string response = ""; string[] param = new string[] { PI_ID, "2", response }; dh.CallProcedure("USER_PRODOUT_GROUPQTY", param); } } private void CombindetailThree_CheckedChanged(object sender, EventArgs e) { if (CombindetailThree.Checked) { Combindetail.Checked = false; CombindetailTwo.Checked = false; } if (LoadCheck) { LoadPrcodeData(); string response = ""; string[] param = new string[] { PI_ID, "3", response }; dh.CallProcedure("USER_PRODOUT_GROUPQTY_TEST", param); } } string SelectProdcode = ""; int SelectRowIndex = -1; private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { LabelInf.Rows[e.RowIndex].Selected = true; SelectRowIndex = e.RowIndex; } } private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e) { OutBoxNum1 = OutBoxNum.Text; LoadGridData(sender, e); } private void LabelInf_SelectionChanged(object sender, EventArgs e) { DataGridViewSelectedRowCollection dsc = LabelInf.SelectedRows; if (dsc.Count > 0) { SelectRowIndex = dsc[0].Index; } } string OutBoxNum1 = ""; private void OutBoxNum_SelectionChangeCommitted(object sender, EventArgs e) { if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增") if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1") { MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签"); } OutBoxNum1 = OutBoxNum.Text; if (OutBoxNum1 == "新增") { PassSixTenCount = 1; PassTenCount = 1; CurrentBoxNum.Value = 0; CurrentOutBoxNum.Value = 0; } } private void Reset_Click(object sender, EventArgs e) { string close = MessageBox.Show(this.ParentForm, "清除当前已采集数据,刷新待采集数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") { dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete"); dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete"); dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'"); pi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } } private void AddNewOutBox_Click(object sender, EventArgs e) { if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增") if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1") { MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签"); } OutBoxNum1 = OutBoxNum.Text; if (OutBoxNum1 == "新增") { PassSixTenCount = 1; PassTenCount = 1; CurrentBoxNum.Value = 0; CurrentOutBoxNum.Value = 0; } OutBoxNum.Text = "新增"; } private void GetPDdata_Click(object sender, EventArgs e) { dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete"); LoadPrcodeData(); dh.UpdateByCondition("CS$InoutPrcode", "collectednum=(select nvl(sum(pib_qty),0) from prodiobarcode where pib_inoutno=pd_inoutno and pib_pdno=pd_pdno)", "pd_inoutno='" + pi_inoutno.Text + "'"); MessageBox.Show("同步出货单明细数据成功", "提示"); } private void ResetHBXH_Click(object sender, EventArgs e) { dh.ExecuteSql("update prodiodetail set PD_HBXH_USER=pd_pdno where pd_inoutno='" + pi_inoutno.Text + "'", "update"); MessageBox.Show("重置序号成功", "提示"); } private void ButtonWeigh_Click(object sender, EventArgs e) { if (Weight.Text != "" && Weight.Text != "0.000") { sql.Clear(); sql.Append("update prodiobarcode set pib_boxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' "); sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'"); dh.ExecuteSql(sql.ToString(), "update"); LoadGridData(sender, e); } else { MessageBox.Show("请先连接电子秤!"); } } Regex reg = new Regex(@"\d+.\d+"); ComInfoSet cis; private void ConnectCom_Click(object sender, EventArgs e) { cis = new ComInfoSet(); (cis.Controls["PortName"] as SerialPortCombox).SelectedValue = Properties.Settings.Default.PortName; cis.Controls["BaudRate"].Text = Properties.Settings.Default.BaudRate; cis.Controls["Confirm"].Click += UAS_出货标签打印_Click; cis.ShowDialog(); } private void UAS_出货标签打印_Click(object sender, EventArgs e) { if (Com.IsOpen && Com.PortName == cis.Controls["PortName"].Text) { MessageBox.Show("串口" + Com.PortName + "已打开"); return; } else { if (Com.IsOpen) { Com.Close(); } } int BaudRate = 0; Com.PortName = cis.Controls["PortName"].Text; if (int.TryParse(cis.Controls["BaudRate"].Text, out BaudRate)) { Com.BaudRate = BaudRate; } Properties.Settings.Default.BaudRate = BaudRate.ToString(); Properties.Settings.Default.PortName = cis.Controls["PortName"].Text; Properties.Settings.Default.Save(); Com.DataReceived += Com_DataReceived; Com.Open(); cis.Close(); } private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { try { int len = Com.BytesToRead; byte[] readBuffer = new byte[len]; Com.Read(readBuffer, 0, len); //将数据读入缓存 string value = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value; if (value != "") { Weight.Text = value; } //读不到数据的时间删掉 } catch (Exception) { return; } } private void CloseSerialPort_Click(object sender, EventArgs e) { if (Com.IsOpen) { Com.Close(); Com.DataReceived -= Com_DataReceived; } } private void ShowMenu_Total_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { ShowMenu_Total.Close(); switch (e.ClickedItem.Text) { case "清除明细": CleanDetail_Click(sender, e); break; case "标签维护": LabelMaintain_Click(sender, e); break; case "打印唛头": PrintFooter_Click(sender, e); break; case "附加信息": AttachInfo_Click(sender, e); break; case "打印状态": PrintStatus_Click(sender, e); break; case "标签自定义": CustomerLabel_Click(sender, e); break; case "同步出货数据": GetPDdata_Click(sender, e); break; case "重置单据": Reset_Click(sender, e); break; case "贴标机参数设置": MachineSetting ms = new MachineSetting(); BaseUtil.SetFormCenter(ms); ms.ShowDialog(); break; case "断开贴标机": receiveClient.Close(); sendClient.Close(); resetClient.Close(); break; case "内部标签打印": 内部标签打印 ms2 = new 内部标签打印(SingleLabelPrinter.Text); BaseUtil.SetFormCenter(ms2); ms2.ShowDialog(); break; case "贴标角度设置": if (pi_cardcode.Text != "") { 贴标角度设置 ms1 = new 贴标角度设置(pi_cardcode.Text); ms1.FormClosed += Ms1_FormClosed; BaseUtil.SetFormCenter(ms1); ms1.ShowDialog(); } else { MessageBox.Show("请先获取客户信息"); } break; } } private void Ms1_FormClosed(object sender, FormClosedEventArgs e) { DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select"); if (XY.Rows.Count == 0) { XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select"); } if (XY.Rows.Count > 0) { Angle = XY.Rows[0]["px_angle"].ToString(); X = XY.Rows[0]["px_x"].ToString(); Y = XY.Rows[0]["px_y"].ToString(); } } private void MenuManage_Click(object sender, EventArgs e) { ShowMenu_Total.Show(new Point(MenuManage.Location.X, MenuManage.Location.Y + 20)); } SqliteDBHelper sdh = SystemInf.sdh; //接受数据客户端 TcpClient receiveClient; //发送指令客户端 TcpClient sendClient; //复核数据客户端 TcpClient resetClient; NetworkStream ns; NetworkStream ns1; Thread receiveThread; Thread sendThread; int dataindex = 0; string ps_split = ""; private void Connect_Click(object sender, EventArgs e) { SingleLabelAutoPrint.Checked = true; MidLabelAutoPrint.Checked = true; CurrentRowOnly.Checked = true; AutoPrintMidBox.Checked = true; receiveClient = new TcpClient(); sendClient = new TcpClient(); resetClient = new TcpClient(); DataTable dt = (DataTable)sdh.ExecuteSql("select * from ParamSetting", "select"); if (dt.Rows.Count > 0) { try { //发起TCP连接 receiveClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_receiveport"].ToString())); sendClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_sendport"].ToString())); resetClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_resetport"].ToString())); dataindex = int.Parse(dt.Rows[0]["ps_dataindex"].ToString()); ps_split = dt.Rows[0]["ps_split"].ToString(); if (receiveClient != null) { MessageBox.Show("连接服务器成功"); ConnectToMachine = true; //获得绑定的网络数据流 ns = receiveClient.GetStream(); ns1 = sendClient.GetStream(); Control.CheckForIllegalCrossThreadCalls = false; //实例化并启动接受消息线程 receiveThread = new Thread(receive_message); receiveThread.Start(); sendThread = new Thread(send_message); sendThread.Start(); } else { MessageBox.Show("连接服务器失败"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } bool IsSum = false; private void receive_message() { while (IsOnline(receiveClient)) { try { //创建接收数据的字节流 byte[] getData = new byte[1024]; //从网络流中读取数据 ns.Read(getData, 0, getData.Length); //将字节数组转换成文本形式 string getMsg = Encoding.Default.GetString(getData); if (getMsg.Contains("ReadId")) { string msgStr = getMsg.Trim('\0').Replace("ReadId1|,|", ""); if (!msgStr.Contains("三星")) { msgStr = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value; //设置索引和内容 // msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex]; Input.Text = msgStr; IsSum = false; } else { IsSum = true; } Input_KeyDown(Input, new KeyEventArgs(Keys.Enter)); } } catch (Exception) { //接受消息发生异常 break; //并释放相关资源 //if (ns != null) // ns.Dispose(); //break; } } MessageBox.Show("网络中断"); } private void send_message() { while (IsOnline(sendClient)) { try { //创建接收数据的字节流 byte[] getData = new byte[1024]; //从网络流中读取数据 z ns1.Read(getData, 0, getData.Length); //将字节数组转换成文本形式 string getMsg = Encoding.Default.GetString(getData); if (getMsg.Contains("ReadId3")) { string msgStr = getMsg.Trim('\0').Replace("ReadId3|,|", ""); string temp = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value; string pr_code = ""; //如果不存在原厂标签的话 if (temp != "") { pr_code = temp.Split('*')[0]; } //如果允许混料的话 bool OutBoxSplit = false; if (PassSixTenCount > OutboxCapacity.Value) { string close = MessageBox.Show(this.ParentForm, "此箱号采集后超数量,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString(); if (close == "Yes") { OutBoxSplit = true; PassSixTenCount = 1; //sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0")); } else { } } if (MixPrCode.Checked) { bool SendLast = false; for (int i = 0; i < GridPrcode.Rows.Count; i++) { //获取复核的数据 int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString()); double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()); double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString()); string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString(); string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString(); if (checknum < outqty / zxbzs) { checknum = checknum + 1; GridPrcode.Rows[i].Cells["checknum"].Value = checknum; dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update"); if (i == GridPrcode.Rows.Count - 1 && checknum == outqty / zxbzs) SendLast = true; break; } } if (PassTenCount == MidboxCapacity.Value) { sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1")); PassTenCount = 0; } else { if (SendLast) { sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1")); string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString(); if (close == "Yes") { } else { } } else { if (!OutBoxSplit) sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0")); } } } else { bool SendLast = false; for (int i = 0; i < GridPrcode.Rows.Count; i++) { //获取复核的数据 int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString()); double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()); double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString()); string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString(); string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString(); string SelectPrCode = GridPrcode.Rows[MachineCollectRowIndex].Cells["pd_prodcode"].Value.ToString(); if ((MachineCollectRowIndex == i && SelectPrCode == pr_code) || ((pr_code == Prcode || pr_code == "") && SelectPrCode != pr_code) && checknum < outqty / zxbzs) { checknum = checknum + 1; GridPrcode.Rows[i].Cells["checknum"].Value = checknum; if (checknum < outqty / zxbzs) { dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update"); } else if (checknum == outqty / zxbzs) { dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update"); sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1")); checknum = 0; SendLast = true; PassTenCount = 0; string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString(); if (close == "Yes") { } else { } } break; } } //达到了中盒容量之后 if (PassTenCount == MidboxCapacity.Value) { sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1")); PassTenCount = 0; } else { //如果发送了最后一盒,则不发送继续堆叠的指令 或者需要分盒的时候 if ((!SendLast && !OutBoxSplit) || OutBoxSplit) { sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0")); } } } //中盒当前进度 CurrentBoxNum.Value = PassTenCount; PassTenCount = PassTenCount + 1; //外箱当前进度 CurrentOutBoxNum.Value = PassSixTenCount; PassSixTenCount = PassSixTenCount + 1; } //设置索引和内容 //msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex]; //Input.Text = msgStr; //Input_KeyDown(Input, new KeyEventArgs(Keys.Enter)); //} //catch (ThreadAbortException) //{ // //捕捉到线程被终止异常则表示是人为的断开TCP连接 // //不弹出错误提示 // break; } catch (Exception) { //接受消息发生异常 break; //并释放相关资源 //if (ns != null) // ns.Dispose(); //break; } } MessageBox.Show("网络中断"); } private string GetSendCode(string Code) { if (Angle != "") { Code = Code + "|,|" + Angle; } if (X != "") { Code = Code + "|,|" + X; } if (Y != "") { Code = Code + "|,|" + Y; } return Code; } /// /// 检测TCP连接是否存在还是已经中断 /// /// /// public bool IsOnline(TcpClient c) { try { bool result = !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected); return result; } catch { return false; } } private void CurrentBoxNum_ValueChanged(object sender, EventArgs e) { } private void CurrentBoxNum_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { PassTenCount = int.Parse(CurrentBoxNum.Value.ToString()) + 1; } } private void CurrentOutBoxNum_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { PassSixTenCount = int.Parse(CurrentOutBoxNum.Value.ToString()) + 1; } } private void richTextAutoBottom1_TextChanged(object sender, EventArgs e) { } private void Weight_Click(object sender, EventArgs e) { } private void groupBoxWithBorder2_Enter(object sender, EventArgs e) { } private void DCCheck_TextChanged(object sender, EventArgs e) { } private void GridPrcode_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void label18_Click(object sender, EventArgs e) { } private void MidBoxEnd_TextChanged(object sender, EventArgs e) { } private void MidBoxBegin_TextChanged(object sender, EventArgs e) { } private void label16_Click(object sender, EventArgs e) { } private void SingleBoxEnd_TextChanged(object sender, EventArgs e) { } private void SingleBoxBegin_TextChanged(object sender, EventArgs e) { } private void label12_Click(object sender, EventArgs e) { } private void label7_Click(object sender, EventArgs e) { } private void groupBoxWithBorder1_Enter(object sender, EventArgs e) { } private void Input_TextChanged(object sender, EventArgs e) { } private void LabelInf_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void pi_inoutno_TextChanged(object sender, EventArgs e) { } private void label14_Click(object sender, EventArgs e) { } private void CurrentOutBoxNum_ValueChanged(object sender, EventArgs e) { } private void label13_Click(object sender, EventArgs e) { } private void SingleLabelPrinter_Load(object sender, EventArgs e) { } private void SingleLabelAutoPrint_CheckedChanged(object sender, EventArgs e) { } private void SingleLabel_Enter(object sender, EventArgs e) { } private void CurrentRowOnly_CheckedChanged(object sender, EventArgs e) { } private void MidboxCapacity_ValueChanged(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void MidLabelNum_TextChanged(object sender, EventArgs e) { } private void label5_Click(object sender, EventArgs e) { } private void MidLabelPrinter_Load(object sender, EventArgs e) { } private void MidLabelAutoPrint_CheckedChanged(object sender, EventArgs e) { } private void MidLabel_Enter(object sender, EventArgs e) { } private void DiffDetno_CheckedChanged(object sender, EventArgs e) { } private void DiffCPN_CheckedChanged(object sender, EventArgs e) { } private void BoxCount_Click(object sender, EventArgs e) { } private void DiffLotNo_CheckedChanged(object sender, EventArgs e) { } private void DiffDC_CheckedChanged(object sender, EventArgs e) { } private void OnlyOneRow_CheckedChanged(object sender, EventArgs e) { } private void AllLabel_CheckedChanged(object sender, EventArgs e) { } private void label10_Click(object sender, EventArgs e) { } private void label6_Click(object sender, EventArgs e) { } private void OutBoxPrinter_Load(object sender, EventArgs e) { } private void OutboxCapacity_ValueChanged(object sender, EventArgs e) { } private void OutBoxLabel_Enter(object sender, EventArgs e) { } private void ButtonMidWeigh_Click(object sender, EventArgs e) { if (Weight.Text != "" && Weight.Text != "0.000") { string pib_outboxcode1 = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString(); sql.Clear(); sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' "); sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' and pib_outboxcode1='" + pib_outboxcode1 + "'"); dh.ExecuteSql(sql.ToString(), "update"); LoadGridData(sender, e); } else { MessageBox.Show("请先连接电子秤!"); } } private void RemainTxt() { string[] str = Input.Text.Split('*'); Input.Text = ""; if (str.Length >= 4) { for (int i = 0; i < 4; i++) { Input.Text += str[i] + "*"; } Input.Text.Replace("\n", "").Replace("\r", ""); Input.SelectionStart = Input.Text.Length; } } } }