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.Linq; using System.Diagnostics; using LabelManager2; using UAS_LabelMachine.PublicMethod; using UAS_LabelMachine.Entity; using UAS_特殊解析规则; using UAS_LabelMachine.PublicForm; using System.Threading; using System.IO; using System.Globalization; using System.IO.Ports; using UAS_LabelMachine.CustomControl; namespace UAS_LabelMachine { public partial class UAS_出货标签打印 : Form { //自适应屏幕 AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; AccessDBHelper adh; DataTable dt; StringBuilder sql = new StringBuilder(); /// /// CodeSoft新建打印机引擎 /// ApplicationClass lbl; /// /// 单盘打印文件 /// Document SingleDoc; /// /// 中盒打印文件 /// Document MidDoc; /// /// 外箱打印文件 /// Document OutBoxDoc; /// /// Loading窗口 /// SetLoadingWindow stw; /// /// 弹窗线程 /// Thread thread; /// /// 当前品牌 /// string Brand; string PI_ID; /// /// 当前扫描的所在行 /// int CurrentRowIndex = 0; /// /// 最大的出入口单号 /// int MaxOutBoxCode = 1; /// /// 正则表达式用于项目匹配 /// Regex reg; /*标识供应商物料编号采集是否通过*/ bool CollectVeProdCodePass = true; bool CollectQTYPass = true; bool logout = false; DataTable SingleLabelParam; DataTable MidLabelParam; DataTable OutLabelParam; /// /// 存放单盘的ID /// List SingleID = new List(); /// /// 单盘的打印参数 /// List SingleBoxArgument = new List(); /// /// 存放中盒的ID和盒号 /// Dictionary MidIDAndOutboxcode = new Dictionary(); /// /// 中盒的打印参数 /// List MidBoxArgument = new List(); /// /// 全部采集 /// bool AllCollect = false; /// /// 是否全选 /// bool AllChecked = false; /// /// 默认采集了指定的数据上传 /// int UploadNum = 100; /// /// 是否获取过箱号 /// bool GetPackingCode = false; string SG_Script; Dictionary Si_Item = new Dictionary(); /*需要重绘的Cell*/ Dictionary PaintCell = new Dictionary(); /// /// 是否通过选择Combox来改变打开的文件 /// bool ComBoxClickChangeLabelDoc = false; DataTable Attach; public UAS_出货标签打印(string Master) { InitializeComponent(); Text = Text + "-" + Master; } protected override void WndProc(ref Message m) { //拦截双击标题栏、移动窗体的系统消息 if (m.Msg != 0xA3) { base.WndProc(ref m); } } private void 贴标机条码打印_Load(object sender, EventArgs e) { //杀死之前全部未关闭的进程 Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa"); for (int i = 0; i < processes.Length; i++) { processes[i].Kill(); } //用计时器重置数据库链接 LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】"); dh = SystemInf.dh; adh = SystemInf.adh; CheckForIllegalCrossThreadCalls = false; pi_inoutno.Focus(); Point pt = new Point(); //禁止所有列的排序 foreach (DataGridViewColumn dgv in LabelInf.Columns) { dgv.SortMode = DataGridViewColumnSortMode.NotSortable; } int ScreenWidth = Screen.GetWorkingArea(pt).Width; //设置获取当前屏幕大小自动全屏但是保留任务栏 Rectangle ScreenArea = Screen.GetWorkingArea(this); Top = 0; Left = 0; Width = ScreenArea.Width; Height = ScreenArea.Height; MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity; OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity; asc.controllInitializeSize(this); asc.controlAutoSize(this); //实例化打印进程 try { lbl = new ApplicationClass(); } catch (Exception) { MessageBox.Show("未安装CodeSoft软件或者版本不正确"); } RefreshDBConnect.Interval = 60000; RefreshDBConnect.Start(); DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select"); DataRow[] dr = dt.Select("comtype='FrontendCheck'"); if (dr.Length > 0) { FrontendCheck.PortName = dr[0]["COM"].ToString(); FrontendCheck.Tag = "FrontendCheck"; FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString()); FrontendCheck.DataReceived += Serial_DataReceived; FrontendCheck.Open(); } dr = dt.Select("comtype='BackendCheck'"); if (dr.Length > 0) { BackendCheck.PortName = dr[0]["COM"].ToString(); BackendCheck.Tag = "BackendCheck"; BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString()); BackendCheck.DataReceived += Serial_DataReceived; BackendCheck.Open(); } } //获取串口数据 private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { SerialPortWithTag port = sender as SerialPortWithTag; int len = port.BytesToRead; byte[] readBuffer = new byte[len]; port.Read(readBuffer, 0, len); //将数据读入缓存 string msg = Encoding.ASCII.GetString(readBuffer, 0, len); //获取出入库产品编号 string LotNo = ""; string DateCode = ""; string Order = ""; string QTY = ""; string PN = ""; string OutBox = ""; string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString(); switch (port.Tag) { case "FrontendCheck": FrontCollect.Text = msg; MatchCollection matchs = reg.Matches(msg); int index = 0; foreach (var item in Si_Item) { switch (item.Value) { case "DateCode": DateCode = matchs[index].Value; break; case "LotNo": LotNo = matchs[index].Value; break; case "PN": PN = matchs[index].Value; break; case "Order": Order = matchs[index].Value; break; case "QTY": QTY = matchs[index].Value; break; case "OutBox": OutBox = matchs[index].Value; break; default: break; } index = index + 1; } adh.ExecuteSql("update prodiobarcode set pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "' where pib_id=" + pib_id, "update"); break; case "BackendCheck": BackCheck.Text = msg; break; default: break; } } catch (Exception ex) { MessageBox.Show("接收返回消息异常!具体原因:" + ex.Message, "提示信息"); } } //只执行一次窗体自适应 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); if (SingleDoc != null) SingleDoc.Close(); if (MidDoc != null) MidDoc.Close(); if (OutBoxDoc != null) OutBoxDoc.Close(); form.FormClosed += LabelFormClose; form.ShowDialog(); } private void LabelFormClose(object sender, EventArgs e) { if (GetGridOnly.Checked) GetInOutInfAndLabelFile(); else { GetGridOnly.Checked = true; GetInOutInfAndLabelFile(); GetGridOnly.Checked = false; } } //输入框Enter事件 private void Input_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (BackCheck.Text == "") { MessageBox.Show("采集的数据不能为空"); return; } CollectInputData(); } } /// /// 采集数据 /// private void CollectInputData() { //数据校验均已通过则勾选上已采集 if (CollectVeProdCodePass && CollectQTYPass) { //如果按盒号采集,所有的此盒的均更新为 DataTable dt = (DataTable)MidSource.DataSource; LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true; LogicHandler.UpdateRowPicked(LabelInf.Rows[CurrentRowIndex].Cells["pib_id"].Value); LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true; //勾选了单盘自动打印 if (SingleLabelAutoPrint.Checked) { if (SingleLabelCombox.SelectedValue != null) { AutoPrintSingleLabel(); } else { MessageBox.Show("未维护单盘标签"); return; } } //勾选了中盒自动打印 if (MidLabelAutoPrint.Checked) AutoPrintMidLabel(); } RefreshProcessData(); MessageLog.AppendText(">>扫描到数据" + BackCheck.Text + "\n", Color.Blue); //如果所采集的行的物料不一样的话,重新计算箱内容量 if (CurrentRowIndex - 1 > 0) { string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString(); string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString(); } } private void AutoPrintSingleLabel() { //用标签本身的变量作为最外层的循环条件去匹配; string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString(); StringBuilder ParamLog = new StringBuilder(); sql.Clear(); sql.Append("select * from "); for (int i = 0; i < SingleLabelParam.Rows.Count; i++) { if (i != SingleLabelParam.Rows.Count - 1) sql.Append("(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + "),"); else sql.Append("(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + ")"); } DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id), "select"); for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++) { if (dt.Columns.Contains(SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower())) SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString(); if (SingleDoc.Variables.FreeVariables.Item(i + 1).Value == "") { DataRow[] dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'"); if (dr1.Length > 0) SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString(); } } SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text); SingleDoc.PrintDocument(); LogicHandler.UpdateRowPrinted(pib_id); LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true; } // /// /// 设置外箱号 /// /// 是否批量采集 private void SetOutBoxCode2(bool BatchCollect) { if (OutboxCapacity.Value != 0) { //获取当前出入口单最大的外箱号 for (int i = 0; i < LabelInf.RowCount; i++) { string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString(); if (outboxcode.Contains("-")) { if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode) MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]); } else { if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode) MaxOutBoxCode = int.Parse(outboxcode); } } //统计最大的箱号存在多少 int MaxOutBoxCodeCount = 0; for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString()) MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1; } //如果是获取过包装单的话则不再继续追加箱号 if (!GetPackingCode) { //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1 if (BatchCollect) { if (MaxOutBoxCodeCount < OutboxCapacity.Value) LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode; else { MaxOutBoxCode = MaxOutBoxCode + 1; LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode; } } else { if (MaxOutBoxCodeCount <= OutboxCapacity.Value) LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode; else { MaxOutBoxCode = MaxOutBoxCode + 1; LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode; } } } } } //关闭窗口前提示用户确认 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 { lbl.Quit(); LogManager.DoLog("关闭程序"); } } } /// /// 获取打印标签 /// private void GetInOutInfAndLabelFile() { ComBoxClickChangeLabelDoc = false; Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select"); sql.Clear(); sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,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"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); SingleLabelCombox.DisplayMember = "cl_labelname"; SingleLabelCombox.ValueMember = "la_id"; SingleLabelCombox.DataSource = dt; if (SingleDoc != null) SingleDoc.Close(); if (!GetGridOnly.Checked) for (int i = 0; i < dt.Rows.Count; i++) { string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1]; string LabelName = dt.Rows[i]["cl_labelname"].ToString(); System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString()); FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName); if (time.ToString() != file.LastWriteTime.ToString()) BaseUtil.GetLabelUrl(LabelUrl, LabelName, time); } if (SingleLabelCombox.Text != "") { SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text); SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select"); } sql.Clear(); sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,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"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); MidLabelCombox.DisplayMember = "cl_labelname"; MidLabelCombox.ValueMember = "la_id"; MidLabelCombox.DataSource = dt; if (MidDoc != null) MidDoc.Close(); if (!GetGridOnly.Checked) for (int i = 0; i < dt.Rows.Count; i++) { string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1]; string LabelName = dt.Rows[i]["cl_labelname"].ToString(); System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString()); FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName); if (time.ToString() != file.LastWriteTime.ToString()) BaseUtil.GetLabelUrl(LabelUrl, LabelName, time); } if (MidLabelCombox.Text != "") { MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text); MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select"); } //缓存中盒参数 sql.Clear(); sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,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"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); OutBoxCombox.DisplayMember = "cl_labelname"; OutBoxCombox.ValueMember = "la_id"; OutBoxCombox.DataSource = dt; if (OutBoxDoc != null) OutBoxDoc.Close(); if (!GetGridOnly.Checked) for (int i = 0; i < dt.Rows.Count; i++) { string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1]; string LabelName = dt.Rows[i]["cl_labelname"].ToString(); System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString()); FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName); if (time.ToString() != file.LastWriteTime.ToString()) BaseUtil.GetLabelUrl(LabelUrl, LabelName, time); } if (OutBoxCombox.Text != "") { OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text); OutLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + OutBoxCombox.SelectedValue.ToString().Split('#')[0], "select"); } //缓存外箱参数 ComBoxClickChangeLabelDoc = true; } /// /// 出入库单录入框的回车事件 /// /// /// private void pi_inoutno_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { sql.Clear(); sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); if (dt.Rows.Count > 0) { pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString(); pi_date.Text = dt.Rows[0]["pi_date"].ToString(); PI_ID = dt.Rows[0]["pi_id"].ToString(); if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "") { string[] param = new string[] { PI_ID, "", "" }; dh.CallProcedure("GetCustBarcode", param); } //获取客户自定义设置 sql.Clear(); sql.Append("select cu_print_midlotno,nvl(cu_print_custprodmatchmodel,'Equal')cu_print_custprodmatchmodel,cu_print_midspec,cu_print_midpo,cu_print_midprod,cu_print_outlotno,cu_print_outspec,cu_print_outpo"); sql.Append(",cu_print_outprod,cu_print_checkonly,nvl(cu_print_papercount,0)cu_print_papercount,cu_print_regexpression from customer where cu_code='" + pi_cardcode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(this.Controls, dt); switch (dt.Rows[0]["cu_print_custprodmatchmodel"].ToString()) { case "Equal": Equal.Checked = true; break; case "Expression": Expression.Checked = true; break; default: break; } } dt = (DataTable)dh.ExecuteSql("select distinct sg_brand from prodiodetail left join product on pd_prodcode=pr_code left join scangroup on nvl(pd_brand,pr_brand)=sg_brand where pd_inoutno='" + pi_inoutno.Text + "' and sg_brand is not null", "select"); for (int i = 0; i < dt.Rows.Count; i++) { FrontCombo.DataSource = dt; FrontCombo.DisplayMember = "sg_brand"; FrontCombo.ValueMember = "sg_brand"; BackCombo.DataSource = dt; BackCombo.DisplayMember = "sg_brand"; BackCombo.ValueMember = "sg_brand"; } LoadGridData(sender, e); //重新输入单号后清除缓存 MidBoxArgument.Clear(); SingleBoxArgument.Clear(); MidIDAndOutboxcode.Clear(); SingleID.Clear(); //刷新采集进度 RefreshProcessData(); thread = new Thread(GetInOutInfAndLabelFile); stw = new SetLoadingWindow(thread, "正在获取打印标签"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】"); } else MessageBox.Show("当前出入库单号不存在!"); } } private void SingleBoxPrint() { try { if (SingleDoc.Variables.FreeVariables.Count == 0) { } } catch (Exception) { MessageBox.Show("单盘标签未维护参数"); } if (MidLabelAutoPrint.Checked) { try { if (MidDoc.Variables.FreeVariables.Count == 0) { } } catch (Exception) { MessageBox.Show("中盘标签未维护参数"); } } if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0) { //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载 MidIDAndOutboxcode.Clear(); SingleID.Clear(); //获取全部的中盒号 Dictionary outboxcode1 = new Dictionary(); //判断所有盒号为该盒的是否勾选已采集 outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true); 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["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True") { //如果不存在中盒号则进行添加 if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())) { MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()); } } } 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); } } //只要有一行没有采集满就不打印 if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString()) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false; } } //用于判断用户是否勾选了行 int CheckedRowCount = 0; for (int i = 0; i < LabelInf.RowCount; i++) { //勾选了并且未打印 if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True") { CheckedRowCount = CheckedRowCount + 1; CurrentRowIndex = i; //以标签模板的参数为基准,循环取数 try { string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(); sql.Clear(); sql.Append("select * from "); for (int j = 0; j < SingleLabelParam.Rows.Count; j++) { if (j != SingleLabelParam.Rows.Count - 1) sql.Append("(" + SingleLabelParam.Rows[j]["lp_sql"].ToString() + "),"); else sql.Append("(" + SingleLabelParam.Rows[j]["lp_sql"].ToString() + ")"); } DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id), "select"); for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++) { if (dt.Columns.Contains(SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower())) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower()].ToString(); if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "") { DataRow[] dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'"); if (dr1.Length > 0) SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString(); } } SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text); SingleDoc.PrintDocument(); LogicHandler.UpdateRowPrinted(pib_id); if (MidLabelAutoPrint.Checked) { //判断当前行的盒号和下一行不相等或者已经是最后一行了 if (i + 1 == LabelInf.RowCount || LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1 == LabelInf.RowCount ? i : i + 1].Cells["pib_outboxcode1"].Value.ToString()) { if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()]) { if (MidLabelCombox.SelectedValue != null) { MidBoxCodePrint(CurrentRowIndex); } } } } //勾选为已打印 LabelInf.Rows[i].Cells["pib_ifprint"].Value = true; } catch (Exception ex) { LogManager.DoLog(ex.Message); } } } dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray()); if (CheckedRowCount == 0) MessageBox.Show("未勾选打印明细!"); else if (CurrentRowIndex + 1 < LabelInf.Rows.Count) CurrentRowIndex = CurrentRowIndex + 1; 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_ifpick"].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(); } else MessageBox.Show("未维护单盘标签"); } private void MidBoxLabelPrint() { //未输入内容打印全部中盒 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; } } MidBoxArgument.Clear(); List MidOutBoxCode = new List(); List MidOutBoxCodeIndex = new List(); string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0]; for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++) { if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())) MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()); 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); } } for (int i = 0; i < MidOutBoxCodeIndex.Count; i++) { MidBoxCodePrint(MidOutBoxCodeIndex[i]); } MidBoxArgument.Clear(); 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; } } //找到了指定的盒号 if (FindMidLabel) MidBoxCodePrint(MidLabelRowIndex); else MessageBox.Show("该出入库单未找到该中盒号!"); } else MessageBox.Show("未维护中盒模板"); } private void MidLabelPrint_Click(object sender, EventArgs e) { if (MidLabelCombox.Text != "") { thread = new Thread(MidBoxLabelPrint); stw = new SetLoadingWindow(thread, "正在打印中盒"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); } else MessageBox.Show("未维护中盒标签"); } private void OutBoxPrint() { List Outboxcode = new List(); //如果未勾选箱号则对勾选的数据的箱号进行整合 if (OutBoxNum.Text == "") { for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True") { string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString(); //富为使用包装单的逻辑 //如果不包含该箱号则进行添加 if (!Outboxcode.Contains(outboxcode2)) Outboxcode.Add(outboxcode2); } } //按获取到的箱号列表进行打印 if (Outboxcode.ToArray().Length > 0) { try { // 循环打印外箱号 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]) { OutBoxCodePrint(h); break; } } } } catch { } } 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) OutBoxCodePrint(OutBoxLabelRowIndex); else MessageBox.Show("该出入库单未找到该外箱号!"); } catch (Exception) { } } Outboxcode.Clear(); } private void MidBoxCodePrint(int rowindex) { //获取对应行的pib_id string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString(); string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString(); sql.Clear(); sql.Append("select * from "); for (int i = 0; i < MidLabelParam.Rows.Count; i++) { if (i != MidLabelParam.Rows.Count - 1) sql.Append("(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + "),"); else sql.Append("(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + ")"); } DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode1}", pib_outboxcode1), "select"); for (int i = 0; i < MidDoc.Variables.FreeVariables.Count; i++) { if (dt.Columns.Contains(MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower())) MidDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString(); if (MidDoc.Variables.FreeVariables.Item(i + 1).Value == "") { DataRow[] dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'"); if (dr1.Length > 0) MidDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString(); } } MidDoc.Printer.SwitchTo(MidLabelPrinter.Text); MidDoc.PrintDocument(); } /// /// 执行打印外箱号 /// private void OutBoxCodePrint(int rowindex) { //获取对应行的pib_id string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString(); string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString(); sql.Clear(); sql.Append("select * from "); for (int i = 0; i < OutLabelParam.Rows.Count; i++) { if (i != OutLabelParam.Rows.Count - 1) sql.Append("(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + "),"); else sql.Append("(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + ")"); } DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode2}", pib_outboxcode2), "select"); for (int i = 0; i < OutBoxDoc.Variables.FreeVariables.Count; i++) { if (dt.Columns.Contains(OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower())) OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString(); if (OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value == "") { DataRow[] dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'"); if (dr1.Length > 0) OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString(); } } OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text); OutBoxDoc.PrintDocument(); } private void OutBoxLabelPrint_Click(object sender, EventArgs e) { if (OutBoxCombox.Text != "") { thread = new Thread(OutBoxPrint); stw = new SetLoadingWindow(thread, "正在打印外箱"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); } else MessageBox.Show("未维护外箱标签"); } /// /// 刷新采集进度 /// private void RefreshProcessData() { if (LabelInf.Rows.Count > 0) { //设置初始化的采集进度 int Count = 0; int CurrentMidBoxCollectedCount = 0; //当前盒号的总盘数 int CurrentMidBoxTotalCount = 0; //未超出当前范围的时候 for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True") Count++; //和当前编辑箱号相等行 if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) CurrentMidBoxCollectedCount++; //当前盒号一共有几盘 if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) CurrentMidBoxTotalCount++; } //设置当前的箱号和盒号 Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString(); Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString(); //设置当前总数和已采集数量 CollectedCount.Text = Count.ToString(); } } private void LoadGridData() { LoadGridData(new object(), new EventArgs()); } /// /// 自定义函数 加载明细行的数据,多处使用添加进函数 /// /// /// private void LoadGridData(object sender, EventArgs e) { AllCollect = false; dt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "select"); if (dt.Rows.Count == 0) { sql.Clear(); sql.Append("select pd_custprodcode,pib_inoutno,pd_custprodspec,nvl(pib_ifrecheck,0)pib_ifrecheck,nvl(pib_ifupload,0)pib_ifupload,nvl(pib_ifmodify,0)pib_ifmodify,pd_pocode,pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,nvl(nvl(pd_brand,pib_brand),pr_brand)pib_brand, pr_vendprodcode,"); sql.Append("pib_lotno,pib_datecode,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifpick,0)pib_ifpick,nvl(pib_ifprint,0)pib_ifprint"); sql.Append(" from prodiobarcode left join prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno and "); sql.Append(" pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode "); sql.Append("where pib_piid='" + PI_ID + "' order by to_number(pib_outboxcode1),pib_id,pd_prodcode"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); adh.SaveDataTable(dt, "prodiobarcode"); } //获取系统设置的上传数量,如参数异常则默认为100 if (!int.TryParse(adh.getFieldDataByCondition("dataextra", "uploadnum", "id=1").ToString(), out UploadNum)) { UploadNum = 100; } MidSource.DataSource = dt; BaseUtil.FillDgvWithDataTable(LabelInf, (DataTable)MidSource.DataSource); if (LabelInf.RowCount > 0) { Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString(); if (Brand != "") { dt = (DataTable)dh.ExecuteSql("select sg_script,sg_id from scangroup where sg_brand='" + Brand + "'", "select"); if (dt.Rows.Count > 0) { string sgid = dt.Rows[0]["sg_id"].ToString(); SG_Script = dt.Rows[0]["sg_script"].ToString(); reg = new Regex(SG_Script); DataTable dt1 = (DataTable)dh.ExecuteSql("select si_name,si_item,si_expression from scanitem where si_sgid='" + sgid + "' and si_enable<>0", "select"); for (int i = 0; i < dt1.Rows.Count; i++) { if (SG_Script.IndexOf(dt1.Rows[i]["si_name"].ToString()) >= 0) { Si_Item.Add(SG_Script.IndexOf(dt1.Rows[i]["si_name"].ToString()), dt1.Rows[i]["si_item"].ToString()); } } //根据索引进行排序 Si_Item = (from entry in Si_Item orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); } } } //绑定数据之后往下找到未采集的数据显示在当前采集的栏目 for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") { CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex; break; } } } /// /// 重绘Cell的颜色 /// /// /// private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position)); if (e.ColumnIndex > 0) { if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode") { SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255)); e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds); Rectangle border = e.CellBounds; border.Width -= 1; e.Graphics.DrawRectangle(Pens.White, border); e.PaintContent(e.CellBounds); e.Handled = true; } if (e.RowIndex >= 0) { //重绘制定的Cell,表示采集的数量不匹配 if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_qty"])) { SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255)); e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_qty"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds); Rectangle border = e.CellBounds; border.Width -= 1; e.Graphics.DrawRectangle(Pens.Black, border); e.PaintContent(e.CellBounds); e.Handled = true; } //表示采集的供应商物料编号不匹配 if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"])) { SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255)); e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds); Rectangle border = e.CellBounds; border.Width -= 1; e.Graphics.DrawRectangle(Pens.Black, border); e.PaintContent(e.CellBounds); e.Handled = true; } //表示采集的供应商物料编号不匹配 if (LabelInf.Columns[e.ColumnIndex].Name == "pib_brand" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_brand"])) { SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255)); e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_brand"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds); Rectangle border = e.CellBounds; border.Width -= 1; e.Graphics.DrawRectangle(Pens.Black, border); e.PaintContent(e.CellBounds); e.Handled = true; } } } } private void CusLabelPrint() { //MaxOutBoxCode = MaxOutBoxCode + 1; List CusOutBoxCode = new List(); //统计客户外箱号 if (LabelInf.Rows.Count > 0) CusOutBoxCode.Add(0); for (int i = 0; i < LabelInf.Rows.Count; i++) { if (i - 1 > 0 && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() == "True") { string cutboxcode = LabelInf.Rows[i].Cells["pib_cusoutboxcode"].Value.ToString(); string nextcutboxcode = LabelInf.Rows[i - 1].Cells["pib_cusoutboxcode"].Value.ToString(); if (cutboxcode != nextcutboxcode) CusOutBoxCode.Add(i); } } } private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { KeyEventArgs e2 = new KeyEventArgs(Keys.Enter); pi_inoutno_KeyDown(sender, e2); } private void AutoPrintMidLabel() { bool FullBox = true; //判断所有盒号未该盒的是否勾选已采集 for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString()) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") FullBox = false; } } //如果当前箱号已经装满了 if (FullBox) { if (MidLabelCombox.SelectedValue != null) { MidBoxCodePrint(CurrentRowIndex); } else MessageBox.Show("未维护中盒模板"); } } private void AllCollected_Click(object sender, EventArgs e) { if (AllCollect == false) { foreach (DataGridViewRow dr in LabelInf.Rows) dr.Cells["pib_ifpick"].Value = true; AllCollect = true; } else { foreach (DataGridViewRow dr in LabelInf.Rows) dr.Cells["pib_ifpick"].Value = false; AllCollect = false; } } 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; lbl.Quit(); 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 (SingleDoc != null) SingleDoc.Close(); if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked) { System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]); SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time)); } } } catch (Exception) { } } /// /// 切换打开的中盒文件 /// /// /// private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e) { try { if (ComBoxClickChangeLabelDoc) { if (MidDoc != null) MidDoc.Close(); if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked) { System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]); MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time)); } } } catch (Exception) { } } /// /// 切换打开的外箱文件 /// /// /// private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e) { try { if (ComBoxClickChangeLabelDoc) { if (OutBoxDoc != null) OutBoxDoc.Close(); if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked) { System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]); OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time)); } } } 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) { ExportFileDialog.Description = "选择导出的路径"; DialogResult result = ExportFileDialog.ShowDialog(); if (result == DialogResult.OK) { ExcelHandler eh = new ExcelHandler(); DataTable dt = ((DataTable)MidSource.DataSource).Copy(); for (int i = dt.Columns.Count - 1; i >= 0; i--) { for (int j = 0; j < LabelInf.Columns.Count; j++) { //去除ID列 if (dt.Columns[i].ColumnName.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifpick" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode") { dt.Columns.RemoveAt(i); break; } switch (dt.Columns[i].ColumnName.ToLower()) { case "pib_lotno": dt.Columns[i].ColumnName = "批次号"; break; case "pib_datecode": dt.Columns[i].ColumnName = "生产日期"; break; case "pib_custbarcode": dt.Columns[i].ColumnName = "最小产品包装条码"; break; default: break; } if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower()) { dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText; break; } } } eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text); string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls"); } } 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.getRowCount("employee", "1=1"); } private void ButtonSetting_Click(object sender, EventArgs e) { ListButtonMenu.BringToFront(); ListButtonMenu.Visible = true; } private void ListButtonMenu_SelectedIndexChanged(object sender, EventArgs e) { ListButtonMenu.Visible = false; switch (ListButtonMenu.SelectedItem.ToString()) { case "采集策略设置": 采集策略_NEW form = new 采集策略_NEW(); BaseUtil.SetFormCenter(form); form.ShowDialog(); break; case "附加信息设置": if (pi_cardcode.Text != "") { 附件内容打印 att = new 附件内容打印(pi_cardcode.Text); att.ShowDialog(); } else MessageBox.Show("请先获取出库单信息"); break; case "客户标签维护": 客户标签维护 form1 = new 客户标签维护(); BaseUtil.SetFormCenter(form1); if (SingleDoc != null) SingleDoc.Close(); if (MidDoc != null) MidDoc.Close(); if (OutBoxDoc != null) OutBoxDoc.Close(); form1.FormClosed += LabelFormClose; form1.ShowDialog(); break; case "客户采集规则": CustomerRule cust = new CustomerRule(); BaseUtil.SetFormCenter(cust); cust.ShowDialog(); break; case "参数配置": ParamSetting form2 = new ParamSetting(); BaseUtil.SetFormCenter(form2); form2.ShowDialog(); break; default: break; } } } }