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 LabelManager2; using UAS_LabelMachine.PublicMethod; using UAS_LabelMachine.Entity; using UAS_特殊解析规则; using System.Globalization; using UAS_LabelMachine.CustomControl.GroupBoxWithBorder; using UAS_LabelMachine.PublicForm; using System.Threading; namespace UAS_LabelMachine { public partial class UAS_出货标签打印 : Form { //自适应屏幕 AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; DataTable dt; StringBuilder sql = new StringBuilder(); /*CodeSoft新建打印机引擎*/ ApplicationClass lbl; /*单盘打印文件*/ Document SingleDoc; /*中盒打印文件*/ Document MidDoc; /*外箱打印文件*/ Document OutBoxDoc; SetLoadingWindow stw; Thread thread; //当前品牌 string Brand; string PI_ID; //当前扫描的项目 int CurrentItemIndex = 0; //当前扫描的所在行 int CurrentRowIndex = 0; //最大的出入口单号 int MaxOutBoxCode = 1; /*正则表达式用于项目匹配*/ Regex reg; /*标识供应商物料编号采集是否通过*/ bool CollectVeProdCodePass = true; bool CollectQTYPass = true; bool logout = false; object[] ItemData; Dictionary CollectData; bool AllCollect = false; /*用于存放采集项目的Grid信息*/ Dictionary> SiItem; /*需要重绘的Cell*/ Dictionary PaintCell = new Dictionary(); //使用二维数组进行排序 ArrayList> ScanData; ArrayList GetData; public UAS_出货标签打印() { InitializeComponent(); } protected override void WndProc(ref Message m) { //拦截双击标题栏、移动窗体的系统消息 if (m.Msg != 0xA3) { base.WndProc(ref m); } } private void 贴标机条码打印_Load(object sender, EventArgs e) { LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】"); dh = new DataHelper(); CheckForIllegalCrossThreadCalls = false; pi_inoutno.Focus(); //将本地读取的打印机设置进Combox,并选中默认打印机 if (User.UserAccountType == "admin") { PowerSetting.Visible = true; } sg_code.FormName = Name; sg_code.SetValueField = new string[] { "sg_code" }; sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符"; sg_code.TableName = "scangroup"; pr_code.FormName = Name; pr_code.SetValueField = new string[] { "pr_code", "pib_id" }; pr_code.TableName = "prodiodetail "; pr_code.SelectField = "pd_pdno # 行号,pd_prodcode # 物料编号"; ChooseAll.ChooseAll(LabelInf); CollectionUnit.Text = "盘"; Point pt = new Point(); int ScreenWidth = Screen.GetWorkingArea(pt).Width; //如果分辨率大的设置的字体对应的变大 if (ScreenWidth > 1366) { foreach (Control ctl in Controls) { if (ctl is CheckBox || ctl is Label || ctl is RadioButton) { ctl.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134); } if (ctl is GroupBoxWithBorder) { GroupBoxWithBorder gb = ctl as GroupBoxWithBorder; for (int i = 0; i < gb.Controls.Count; i++) { if (gb.Controls[i] is CheckBox || gb.Controls[i] is Label || gb.Controls[i] is RadioButton) { gb.Controls[i].Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134); } } } } } //设置获取当前屏幕大小自动全屏但是保留任务栏 Rectangle ScreenArea = Screen.GetWorkingArea(this); Top = 0; Left = 0; Width = ScreenArea.Width; Height = ScreenArea.Height; //怡海能达添加的特殊字段 if (DataHelper.DBConnectionString.Contains("sz.hi-mantech.com") || DataHelper.DBConnectionString.Contains("192.168.1.200")) { DateCode1.Visible = true; } asc.controlAutoSize(this); //实例化打印进程 try { lbl = new ApplicationClass(); } catch (Exception) { MessageBox.Show("未安装CodeSoft软件或者版本不正确"); } } private void 贴标机条码打印_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void GenerateBarCode_Click(object sender, EventArgs e) { 生成条码 form = new 生成条码(pi_inoutno.Text); form.FormClosed += LoadGridData; BaseUtil.SetFormCenter(form); form.ShowDialog(); } private void CollectionSetting_Click(object sender, EventArgs e) { 采集策略 form = new 采集策略(sg_code.Text); form.FormClosed += sg_code_UserControlTextChanged; BaseUtil.SetFormCenter(form); form.ShowDialog(); } private void LabelMaintain_Click(object sender, EventArgs e) { 客户标签维护 form = new 客户标签维护(); BaseUtil.SetFormCenter(form); form.ShowDialog(); } /// /// 保存明细 /// /// /// private void SaveGrid_Click(object sender, EventArgs e) { DataTable savedt = LabelInf.DataSource as DataTable; if (LabelInf.DataSource != null && savedt.GetChanges() != null) { dh.UpDateTableByCondition((LabelInf.DataSource as DataTable), "ProdioBarCode", "pib_id"); LoadGridData(sender, e); MessageBox.Show("保存成功!"); } } //放大镜选择后出发的事件 private void sg_code_UserControlTextChanged(object sender, EventArgs e) { //取已启用的的按照采集次序排序 dt = (DataTable)dh.ExecuteSql("select si_item,si_detno,sg_separator,si_kind,si_expression,si_index,si_indexstring,si_length from scanitem left join scangroup on si_sgid=sg_id where sg_code='" + sg_code.Text + "' and si_enable<>0 order by si_detno", "select"); BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt); if (dt.Rows.Count > 0) { sg_separator.Text = dt.Rows[0]["sg_separator"].ToString(); } //按DetNo排列之后的采集项 ScanData = new ArrayList>(); //每个采集项目的子项 GetData = new ArrayList(); //将数据添加进一个List的二维数组中 for (int i = 0; i < Si_ItemDGV.RowCount; i++) { //如果不包含这个则添加进数组 if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString())) { GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()); } //如果和后一个的采集次序相同 if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString()) { GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString()); } else { ScanData.Add(GetData); //添加完一次数据需要一个新的List GetData = new ArrayList(); } } RemindUser(); if (ScanData.ToArray().Length > 0) { object[] arr = (ScanData.ToArray()[0] as ArrayList).ToArray(); if (arr.Contains("MPN")) { AutoMatch.CheckState = CheckState.Checked; AutoMatch.Enabled = true; } else { AutoMatch.CheckState = CheckState.Unchecked; AutoMatch.Enabled = false; } } } //输入框Enter事件 private void Input_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (Input.Text == "") { BaseUtil.ShowError("采集的数据不能为空"); } CollectInputData(); } } /// /// 设置自动匹配的数据的行号 /// /// private void SetAutoMatchRow() { //采集策略的第一组数据 string[] arr = new string[ItemData.Length]; if (sg_separator.Text == "") { for (int i = 0; i < arr.Length; i++) { arr[i] = Input.Text; } } else { arr = Input.Text.Split(sg_separator.Text.ToCharArray()).ToArray(); } bool FindAutoMatch = false; for (int i = 0; i < LabelInf.RowCount; i++) { for (int j = 0; j < arr.Length; j++) { if (LabelInf.Rows[i].Cells["pr_vendprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "MPN") && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") { CurrentRowIndex = i; FindAutoMatch = true; break; } } if (FindAutoMatch) { break; } } } /// /// 采集数据 /// private void CollectInputData() { LogManager.DoLog("采集数据【" + Input.Text + "】,使用采集策略编号【" + sg_code.Text + "】"); //按DetNo排列之后的采集项 ScanData = new ArrayList>(); //每个采集项目的子项 GetData = new ArrayList(); //用于保存采集策略的具体信息 SiItem = new Dictionary>(); for (int i = 0; i < Si_ItemDGV.RowCount; i++) { //如果不包含这个则添加进数组 if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString())) { GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()); } //如果和后一个的采集次序相同 if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString()) { GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString()); } else { ScanData.Add(GetData); //添加完一次数据需要一个新的List GetData = new ArrayList(); } Dictionary item = new Dictionary(); for (int j = 0; j < Si_ItemDGV.ColumnCount; j++) { item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString()); } SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item); } //采集项目的数组 ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList).ToArray(); //分隔符不为空的时候 //采集的项和Grid的数目不等 //用户采集的数据的分割数组 CollectData = new Dictionary(); if (sg_separator.Text == "") { for (int i = 0; i < ItemData.Length; i++) { CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text); } } else { for (int i = 0; i < Input.Text.Split(sg_separator.Text.ToCharArray()).Length; i++) { CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text.Split(sg_separator.Text.ToCharArray())[i]); } } //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证 if (ItemData.Length == 1) { CollectData.Clear(); CollectData.Add(ItemData[0].ToString().ToUpper(), Input.Text); //勾选了自动匹配调用该函数 if (AutoMatch.Checked) { SetAutoMatchRow(); } //将筛选之后的值赋给Cell SetDataToCell(ref CollectData, ItemData[0].ToString().ToUpper()); } //如果本次采集的数据分割后和当前的采集项目个数不一样提示用户错误 else if (CollectData.ToArray().Length == ItemData.Length) { for (int i = 0; i < ItemData.Length; i++) { //勾选了自动匹配调用该函数 if (AutoMatch.Checked) { SetAutoMatchRow(); } //将筛选之后的值赋给Cell SetDataToCell(ref CollectData, ItemData[i].ToString().ToUpper()); } } else { BaseUtil.ShowError("所采集的数据个数和采集项目不符"); } //采集项目的索引+1 CurrentItemIndex = CurrentItemIndex + 1; //如果已经采集完了最后一个 if (CurrentItemIndex == ScanData.ToArray().Length) { //数据校验均已通过则勾选上已采集 if (CollectVeProdCodePass && CollectQTYPass) { //如果按盒号采集,所有的此盒的均更新为 if (CollectionUnit.Text == "盒") { string la_id = SingleLabelCombox.SelectedValue.ToString(); string cl_labelname = SingleLabelCombox.Text; string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString(); //获取打印的标签文件 SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname)); try { 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()) { LabelInf.Rows[i].Cells["pib_lotno"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value; LabelInf.Rows[i].Cells["pib_datecode"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value; //将采集数据正确的Cell添加到键值对中 if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pr_vendprodcode"])) { PaintCell.Remove(LabelInf.Rows[i].Cells["pr_vendprodcode"]); } PaintCell.Add(LabelInf.Rows[i].Cells["pr_vendprodcode"], true); if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pib_qty"])) { PaintCell.Remove(LabelInf.Rows[i].Cells["pib_qty"]); } PaintCell.Add(LabelInf.Rows[i].Cells["pib_qty"], true); LabelInf.Refresh(); LabelInf.Rows[i].Cells["pib_ifpick"].Value = true; //当前行的索引随循环增长 CurrentRowIndex = i; if (SingleLabelAutoPrint.Checked) { AutoPrintSingleLabel(la_id, LabelUrl); } if (MidLabelAutoPrint.Checked) { AutoPrintMidLabel(); } SetOutBoxCode2(true); } } SingleDoc.Close(); } catch (Exception) { SingleDoc.Close(); } } else if (CollectionUnit.Text == "全部") { for (int i = 0; i < LabelInf.RowCount; i++) { LabelInf.Rows[i].Cells["pib_lotno"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value; LabelInf.Rows[i].Cells["pib_datecode"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value; CurrentRowIndex = i; //将采集数据正确的Cell添加到键值对中 if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pr_vendprodcode"])) { PaintCell.Remove(LabelInf.Rows[i].Cells["pr_vendprodcode"]); } PaintCell.Add(LabelInf.Rows[i].Cells["pr_vendprodcode"], true); if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pib_qty"])) { PaintCell.Remove(LabelInf.Rows[i].Cells["pib_qty"]); } PaintCell.Add(LabelInf.Rows[i].Cells["pib_qty"], true); LabelInf.Refresh(); LabelInf.Rows[i].Cells["pib_ifpick"].Value = true; SetOutBoxCode2(true); } } else { LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true; //勾选了单盘自动打印 if (SingleLabelAutoPrint.Checked) { try { string la_id = SingleLabelCombox.SelectedValue.ToString(); string cl_labelname = SingleLabelCombox.Text; string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString(); SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname)); AutoPrintSingleLabel(la_id, LabelUrl); SingleDoc.Close(); } catch (Exception) { SingleDoc.Close(); } } //勾选了中盒自动打印 if (MidLabelAutoPrint.Checked) { AutoPrintMidLabel(); } //勾选了外箱自动打印 if (OutBoxLabelAutoPrint.Checked) { } } } //采集未通过的时候 else { //如果自动采集采集未成功需要移动到下一行 if (!AutoMatch.Checked) { SetRowIndexToCollectRow(); } } //当前项目已采集完成,重置采集项目 CurrentItemIndex = 0; //未勾选自动匹配,设置到下一个未采集的行 if (!AutoMatch.Checked) { SetRowIndexToCollectRow(); } //采集完了一行后Index+1 //CurrentRowIndex = (CurrentRowIndex + 1 == LabelInf.RowCount) ? CurrentRowIndex : CurrentRowIndex + 1; } //提醒用户需要采集的数据 RemindUser(); RefreshProcessData(); MessageLog.AppendText(">>扫描到数据" + Input.Text + "\n", Color.Blue); if (CleanInputAfterCollect.Checked) { Input.Text = ""; } } //设置行的索引到当前需要采集的行 private void SetRowIndexToCollectRow() { //获取当前需要采集的行 for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") { griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString(); pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString(); CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex; break; } } } private void AutoPrintSingleLabel(string la_id, string LabelUrl) { //获取维护的变量名称和SQL dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select"); //用标签本身的变量作为最外层的循环条件去匹配 for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++) { Console.WriteLine(j); Console.WriteLine(SingleDoc.Variables.FreeVariables.Item(j + 1).Name); Console.WriteLine(SingleDoc.Variables.FreeVariables.Item(j + 1).DisplayValue); //将维护的模板参数和模板本身的参数名称进行比对 for (int k = 0; k < dt.Rows.Count; k++) { //名称相等的时候,取SQL进行值的查询 if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString()) { //获取打印执行的SQL string sql = dt.Rows[k]["lp_sql"].ToString(); if (sql.IndexOf("{") == 0) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString(); LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value); } else { sql = sql.Substring(0, sql.IndexOf("{")); //获取对应行的pib_id string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString(); if (sql.ToLower().Contains("pib_lotno")) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString(); } else if (sql.ToLower().Contains("pib_datecode")) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString(); } else { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString(); } LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + pib_id + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value); } } else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1") { if (LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value != null) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value.ToString(); } } } } //保存参数打印 SingleDoc.Save(); SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text); SingleDoc.PrintDocument(); LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl); LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true; LogManager.DoLog("打印文件" + SingleDoc.Name + "关闭"); } /// /// 提醒用户当前采集的项目 /// private void RemindUser() { SetRowIndexToCollectRow(); if (ScanData.ToArray().Length > 0) { object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList).ToArray(); string Inf = ""; for (int i = 0; i < arr.Length; i++) { Inf += arr[i] + " "; } MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green); } } /// /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的 /// /// /// private void SetDataToCell(ref Dictionary setdata, string kind) { int length = setdata.Count; for (int j = 0; j < length; j++) { string[] data = new string[setdata.Count]; for (int i = 0; i < length; i++) { data[i] = setdata[kind]; } for (int i = 0; i < data.Length; i++) { DataGridViewCell cell = null; string Matchstr = ""; switch (kind.ToString().ToUpper()) { case "DATECODE": cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"]; Matchstr = MatchStr(data[j], "DATECODE"); setdata.Remove("DATECODE"); length--; break; case "LOTNO": cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"]; Matchstr = MatchStr(data[j], "LOTNO"); setdata.Remove("LOTNO"); length--; break; case "MPN": cell = LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"]; Matchstr = MatchStr(data[j], "MPN"); //采集的供应商号不匹配的话 if (cell.Value.ToString() != Matchstr) { CollectVeProdCodePass = false; //添加需要重绘的Cell if (PaintCell.ContainsKey(cell)) { PaintCell.Remove(cell); } PaintCell.Add(cell, false); LabelInf.Refresh(); MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red); } else { if (PaintCell.ContainsKey(cell)) { PaintCell.Remove(cell); } PaintCell.Add(cell, true); LabelInf.Refresh(); CollectVeProdCodePass = true; } setdata.Remove("MPN"); length--; break; case "QTY": cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"]; Matchstr = MatchStr(data[j], "QTY"); //如果采集的数量不相等的话 if (cell.Value.ToString() != Matchstr) { CollectQTYPass = false; //添加需要重绘的Cell if (PaintCell.ContainsKey(cell)) { PaintCell.Remove(cell); } PaintCell.Add(cell, false); LabelInf.Refresh(); MessageLog.AppendText(">>数量不匹配\n", Color.Red); } else { if (PaintCell.ContainsKey(cell)) { PaintCell.Remove(cell); } PaintCell.Add(cell, true); LabelInf.Refresh(); CollectQTYPass = true; } setdata.Remove("QTY"); length--; break; default: break; } //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集 //MPN和QTY只做比较不需要赋值 if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr) { string MatchResult = ""; if (kind != "MPN" && kind != "QTY") { cell.Value = Matchstr; MatchResult = "成功"; } else { MatchResult = "失败"; } switch (SiItem[kind]["si_kind"]) { case "索引字符": LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",使用字符" + SiItem[kind]["si_indexstring"] + ",匹配后字符串" + Matchstr); break; case "起始位置": LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",从第" + SiItem[kind]["si_index"] + "位开始匹配,匹配后字符串" + Matchstr); break; case "二次解析": LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr); break; case "全部": LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr); break; default: break; } } else { LogManager.DoLog("采集项" + kind + ",匹配结果:【成功】,匹配方式:" + SiItem[kind]["si_kind"] + ",,匹配后字符串" + Matchstr); } } } //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成 SetOutBoxCode2(false); } // /// /// 设置外箱号 /// /// 是否批量采集 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; } } //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+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; } } } } /// /// 自定义函数 根据匹配规则 /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等 /// /// /// /// /// private string MatchStr(string str, string item) { string kind = SiItem[item]["si_kind"]; //起始字符不为空的时候 switch (kind) { case "起始位置": if (SiItem[item]["si_index"] != "") { try { //长度不为空的时候按照指定的长度去取数据 if (SiItem[item]["si_length"] != "") { str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"])); } //长度为空的时候取index之后的全部数据 else { str = str.Substring(int.Parse(SiItem[item]["si_index"])); } } catch (Exception e) { LogManager.DoLog(e.Message); } } break; case "索引字符": try { if (SiItem[item]["si_indexstring"] != "") { //长度不为空的时候按照指定的长度去取数据 if (SiItem[item]["si_length"] != "") { str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"])); } //长度为空的时候取index之后的全部数据 else { str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1); } } } catch (Exception e) { LogManager.DoLog(e.Message); } break; case "二次解析": str = Analysis.AnalysisData(Brand, item, str); break; case "全部": break; default: break; } if (SiItem[item]["si_expression"] != "") { string log = "使用正则表达式" + SiItem[item]["si_expression"] + "匹配数据" + str; reg = new Regex(SiItem[item]["si_expression"]); str = reg.Match(str).Value; log += ",匹配后数据" + str; LogManager.DoLog(log); } return str; } //关闭窗口前提示用户确认 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 { //防止未安装打印程序时报错导致窗体无法关闭 try { lbl.Application.Quit(); LogManager.DoLog("关闭程序"); // System.Windows.Forms.Application.Exit(); } catch { } } } } /// /// 出入库单录入框的回车事件 /// /// /// private void pi_inoutno_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { sql.Clear(); sql.Append("select pi_id,pi_cardcode 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_ID = dt.Rows[0]["pi_id"].ToString(); LoadGridData(sender, e); //刷新采集进度 RefreshProcessData(); //设置当前的最大箱号 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 == "" ? "1" : outboxcode) > MaxOutBoxCode) { MaxOutBoxCode = int.Parse(outboxcode); } } } sql.Clear(); sql.Append("select cl_labelname,cl_isdefault,la_id 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='共用')) and cl_labeltype='单盘'"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); SingleLabelCombox.DataSource = dt; SingleLabelCombox.DisplayMember = "cl_labelname"; SingleLabelCombox.ValueMember = "la_id"; sql.Clear(); sql.Append("select cl_labelname,cl_isdefault,la_id 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='共用')) and cl_labeltype='中盒'"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); MidLabelCombox.DataSource = dt.Copy(); MidLabelCombox.DisplayMember = "cl_labelname"; MidLabelCombox.ValueMember = "la_id"; sql.Clear(); sql.Append("select cl_labelname,cl_isdefault,la_id 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='共用')) and cl_labeltype='外箱'"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); OutBoxCombox.DataSource = dt.Copy(); OutBoxCombox.DisplayMember = "cl_labelname"; OutBoxCombox.ValueMember = "la_id"; //重置采集项次 CurrentItemIndex = 0; LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】"); } else { MessageBox.Show("当前出入库单号不存在!"); } } } private void SingleBoxPrint() { try { string la_id = SingleLabelCombox.SelectedValue.ToString(); string cl_labelname = SingleLabelCombox.Text; string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString(); SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname)); //查询该模板维护的所有参数 dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select"); if (dt.Rows.Count > 0) { //获取全部的中盒号 Dictionary outboxcode1 = new Dictionary(); //判断所有盒号为该盒的是否勾选已采集 outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true); 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") { CheckedRowCount = CheckedRowCount + 1; CurrentRowIndex = i; //以标签模板的参数为基准,循环取数 for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++) { //将维护的模板参数和模板本身的参数名称进行比对 for (int k = 0; k < dt.Rows.Count; k++) { //名称相等的时候,取SQL进行值的查询 if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString()) { //获取打印执行的SQL string sql = dt.Rows[k]["lp_sql"].ToString(); if (sql.IndexOf("{") == 0) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString(); LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value); } else { sql = sql.Substring(0, sql.IndexOf("{")); //获取对应行的pib_id string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(); if (sql.ToLower().Contains("pib_lotno")) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString(); } else if (sql.ToLower().Contains("pib_datecode")) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString(); } else { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString(); } LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + pib_id + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value); } } else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1") { if (LabelInf.Rows[i].Cells["DateCode1"].Value != null) { SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["DateCode1"].Value.ToString(); } } } } //保存参数打印 SingleDoc.Save(); SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text); SingleDoc.PrintDocument(); LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl); //勾选为已打印 LabelInf.Rows[i].Cells["pib_ifprint"].Value = true; } 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) { string la_id_mid = MidLabelCombox.SelectedValue.ToString(); string cl_labelname_mid = MidLabelCombox.Text; string LabelUrl_mid = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id_mid + "' and cl_labelname='" + cl_labelname_mid + "'").ToString(); MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl_mid, cl_labelname_mid)); DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id_mid, "select"); for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++) { //将维护的模板参数和模板本身的参数名称进行比对 for (int k = 0; k < dt.Rows.Count; k++) { //名称相等的时候,取SQL进行值的查询 if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString()) { //获取对应行的pib_id string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString(); string pib_outboxcode1 = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString(); //获取打印执行的SQL string sql = dt.Rows[k]["lp_sql"].ToString(); //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1} try { string ExeSQL = ""; if (sql.Contains("pib_lotno")) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString(); } else if (sql.Contains("pib_datecode")) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString(); } else { ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1); ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1; MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString(); } LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value); } catch (Exception) { BaseUtil.ShowError("SQL维护不正确,请检查SQL语句"); } } else if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1") { if (LabelInf.Rows[i].Cells["DateCode1"].Value != null) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["DateCode1"].Value.ToString(); } } } } //保存参数打印 MidDoc.Save(); MidDoc.Printer.SwitchTo(MidLabelPrinter.Text); MidDoc.PrintDocument(); LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString()); lbl.ActiveDocument.Close(); LogManager.DoLog("打印文件" + MidDoc.Name + "关闭"); } } } } } if (CheckedRowCount == 0) { MessageBox.Show("未勾选打印明细!"); } if (SingleDoc != null) { SingleDoc.Close(); LogManager.DoLog("打印文件" + SingleDoc.Name + "关闭"); } if (MidDoc != null) { MidDoc.Close(); LogManager.DoLog("打印文件" + MidDoc.Name + "关闭"); } outboxcode1.Clear(); } else { BaseUtil.ShowError("此模板尚未维护参数"); } } catch (Exception ex) { if (SingleDoc != null) { SingleDoc.Close(); } if (MidDoc != null) { MidDoc.Close(); } LogManager.DoLog(ex.Message); } } private void SingleLabelPrint_Click(object sender, EventArgs e) { thread = new Thread(SingleBoxPrint); stw = new SetLoadingWindow(thread, "正在打印单盘"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); } private void MidLabelPrint_Click(object sender, EventArgs e) { if (MidLabelNum.Text == "") { BaseUtil.ShowError("手动打印必须填写盒号"); } bool FindMidLabel = false; if (MidLabelCombox.SelectedValue != null) { string la_id = MidLabelCombox.SelectedValue.ToString(); string cl_labelname = MidLabelCombox.Text; string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString(); MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname)); //中盒号所在的行 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; break; } } //找到了指定的盒号 if (FindMidLabel) { dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select"); try { for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++) { //将维护的模板参数和模板本身的参数名称进行比对 for (int k = 0; k < dt.Rows.Count; k++) { //名称相等的时候,取SQL进行值的查询 if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString()) { //获取对应行的pib_id string pib_id = LabelInf.Rows[MidLabelRowIndex].Cells["pib_id1"].Value.ToString(); string pib_outboxcode1 = LabelInf.Rows[MidLabelRowIndex].Cells["pib_outboxcode1"].Value.ToString(); //获取打印执行的SQL string sql = dt.Rows[k]["lp_sql"].ToString(); //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1} try { //获取打印执行的SQL if (sql.IndexOf("{") == 0) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString(); LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value); } else { string ExeSQL = ""; if (sql.Contains("pib_lotno")) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[MidLabelRowIndex].Cells["pib_lotno"].Value.ToString(); } else if (sql.Contains("pib_datecode")) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[MidLabelRowIndex].Cells["pib_datecode"].Value.ToString(); } else { ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1); ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1; MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString(); } LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value); } } catch (Exception) { BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql); } } else if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1") { if (LabelInf.Rows[MidLabelRowIndex].Cells["DateCode1"].Value != null) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[MidLabelRowIndex].Cells["DateCode1"].Value.ToString(); } } } } //保存参数打印 MidDoc.Save(); MidDoc.Printer.SwitchTo(MidLabelPrinter.Text); MidDoc.PrintDocument(); LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[MidLabelRowIndex].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl); MidDoc.Close(); LogManager.DoLog("打印文件" + MidDoc.Name + "关闭"); } catch (Exception) { MidDoc.Close(); } } else { BaseUtil.ShowError("该出入库单未找到该中盒号!"); } } 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 (outboxcode2.Contains("-")&& !Outboxcode.Contains(outboxcode2)) { int small = int.Parse(outboxcode2.Split('-')[0]); int big = int.Parse(outboxcode2.Split('-')[1]); for (int n = 0; n < big-small+1; n++) { Outboxcode.Add(outboxcode2); } } //如果不包含该箱号则进行添加 if (!Outboxcode.Contains(outboxcode2)) { Outboxcode.Add(outboxcode2); } } } if (Outboxcode.ToArray().Length > 0) { string la_id = OutBoxCombox.SelectedValue.ToString(); string cl_labelname = OutBoxCombox.Text; string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString(); OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname)); try { // 循环打印外箱号 for (int i = 0; i < Outboxcode.ToArray().Length; i++) { for (int h = 0; h < LabelInf.RowCount; h++) { //try //{ if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i]) { dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select"); for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++) { //将维护的模板参数和模板本身的参数名称进行比对 for (int k = 0; k < dt.Rows.Count; k++) { //名称相等的时候,取SQL进行值的查询 if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString()) { //如果毛重填写的是毛重或者净重 if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "GW") { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightGross.Text; LogManager.DoLog("打印参数【毛重】赋值," + WeightGross.Text); } else if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "NW") { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightNet.Text; LogManager.DoLog("打印参数【净重】赋值," + WeightNet.Text); } else { //获取对应行的pib_id string pib_id = LabelInf.Rows[h].Cells["pib_id1"].Value.ToString(); string pib_outboxcode2 = LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString(); string ExeSQL = ""; //获取打印执行的SQL string sql = dt.Rows[k]["lp_sql"].ToString(); //try //{ if (sql.Contains("pib_lotno")) { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[h].Cells["pib_lotno"].Value.ToString(); } else if (sql.Contains("pib_datecode")) { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[h].Cells["pib_datecode"].Value.ToString(); } else { ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1); ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + "'" + pib_outboxcode2 + "'"; OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString(); } LogManager.DoLog("打印参数【" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value); } } else if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1") { if (LabelInf.Rows[h].Cells["DateCode1"].Value != null) { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[h].Cells["DateCode1"].Value.ToString(); } } } } //保存参数打印 OutBoxDoc.Save(); OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text); OutBoxDoc.PrintDocument(); LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl); break; } } } OutBoxDoc.Close(); LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭"); } catch { if (OutBoxDoc != null) { OutBoxDoc.Close(); } LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭"); } } } else { bool FindMidLabel = false; string la_id = OutBoxCombox.SelectedValue.ToString(); string cl_labelname = OutBoxCombox.Text; string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString(); OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname)); 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) { dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select"); for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++) { //将维护的模板参数和模板本身的参数名称进行比对 for (int k = 0; k < dt.Rows.Count; k++) { //名称相等的时候,取SQL进行值的查询 if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString()) { //如果毛重填写的是毛重或者净重 if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "GW") { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightGross.Text; LogManager.DoLog("打印参数【毛重】赋值," + WeightGross.Text); } else if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "NW") { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightNet.Text; LogManager.DoLog("打印参数【净重】赋值," + WeightNet.Text); } else { //获取对应行的pib_id string pib_id = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_id1"].Value.ToString(); string pib_outboxcode2 = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_outboxcode2"].Value.ToString(); //获取打印执行的SQL string sql = dt.Rows[k]["lp_sql"].ToString(); //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1} try { string ExeSQL = ""; if (sql.Contains("pib_lotno")) { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_lotno"].Value.ToString(); } else if (sql.Contains("pib_datecode")) { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_datecode"].Value.ToString(); } else { ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1); ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + "'" + pib_outboxcode2 + "'"; OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString(); } LogManager.DoLog("打印参数【" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value); } catch (Exception) { LogManager.DoLog("SQL维护不正确,请检查SQL语句" + sql); BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql); } } } else if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1") { if (LabelInf.Rows[OutBoxLabelRowIndex].Cells["DateCode1"].Value != null) { OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[OutBoxLabelRowIndex].Cells["DateCode1"].Value.ToString(); } } } } //保存参数打印 OutBoxDoc.Save(); OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text); OutBoxDoc.PrintDocument(); LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl); OutBoxDoc.Close(); LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭"); } else { BaseUtil.ShowError("该出入库单未找到该外箱号!"); } } catch (Exception) { OutBoxDoc.Close(); LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭"); } } Outboxcode.Clear(); } private void CleanDetail_Click(object sender, EventArgs e) { ArrayList DeleteID = new ArrayList(); for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "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("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray()); MessageBox.Show("删除成功"); LoadGridData(sender, e); RefreshProcessData(); } } else { MessageBox.Show("尚未勾选需要删除的明细"); } } private void OutBoxLabelPrint_Click(object sender, EventArgs e) { thread = new Thread(OutBoxPrint); stw = new SetLoadingWindow(thread, "正在打印外箱"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); } /// /// 刷新采集进度 /// 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++; } } Capacity.Text = "可装" + CurrentMidBoxTotalCount.ToString() + "盘"; Installed.Text = "已装" + CurrentMidBoxCollectedCount.ToString() + "盘"; //设置当前的箱号和盒号 Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString(); Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString(); //设置当前总数和已采集数量 TotalCount.Text = LabelInf.RowCount.ToString(); CollectedCount.Text = Count.ToString(); } } /// /// 自定义函数 加载明细行的数据,多处使用添加进函数 /// /// /// private void LoadGridData(object sender, EventArgs e) { //如果是富为则使用特殊的查询语句 if (DataHelper.DBConnectionString.Contains("richwell") || DataHelper.DBConnectionString.Contains("192.168.0.88")) { sql.Clear(); sql.Append("select pd_pocode,pd_inoutno,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pr_brand,pr_vendprodcode,"); sql.Append("pib_lotno,pib_datecode,pib_qty,pib_barcode,pib_outboxcode1,pib_outboxcode2,pib_ifpick,pib_ifprint,"); sql.Append("pr_spec,pd_prodcode,pd_pocode from prodiobarcode left join prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno "); sql.Append("and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join (select pd_prodcode "); sql.Append("prcode,pd_pocode pocode,max(pd_detno) pd_detno from prodinout left join packing on packing.pi_code=prodinout.pi_packingcode "); sql.Append("left join packingdetail on packing.pi_id=pd_piid where prodinout.pi_id='" + PI_ID + "' group by pd_prodcode,pd_pocode"); sql.Append(")A on pd_pocode=A.pocode and pd_prodcode=A.PRCODE where pd_piid='" + PI_ID + "' order by a.pd_detno,pib_id"); GetOutBoxCode.Visible = true; } else { sql.Clear(); sql.Append("select pd_pocode,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pr_brand,pr_vendprodcode,"); sql.Append("pib_lotno,pib_datecode,pib_qty,pib_barcode,pib_outboxcode1,pib_outboxcode2,pib_ifpick,pib_ifprint"); sql.Append(",sa_pocode 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 pd_piid='" + PI_ID + "' order by pr_spec,pd_prodcode,pib_id"); } dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); BaseUtil.FillDgvWithDataTable(LabelInf, dt); //有数据的话默认取第一条的品牌去取采集策略 TotalCount.Text = LabelInf.RowCount.ToString(); if (LabelInf.RowCount > 0) { Brand = LabelInf.Rows[0].Cells["pr_brand"].FormattedValue.ToString(); if (Brand != "") sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + Brand + "'").ToString(); } //绑定数据之后往下找到未采集的数据显示在当前采集的栏目 for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") { griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString(); pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString(); pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString(); 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" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode1" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode2") { 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; } } } } private void pr_code_SearchIconClick(object sender, EventArgs e) { pr_code.Condition = " pd_inoutno='" + pi_inoutno.Text + "'"; } private void OutBoxLabelPackage_Click(object sender, EventArgs e) { MaxOutBoxCode = MaxOutBoxCode + 1; } private void pr_code_UserControlTextChanged(object sender, EventArgs e) { //用户在重新勾选后重置采集项目的索引 CurrentItemIndex = 0; for (int i = 0; i < LabelInf.RowCount; i++) { if (pr_code.Text == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") { CurrentRowIndex = i; break; } } } private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { KeyEventArgs e2 = new KeyEventArgs(Keys.Enter); pi_inoutno_KeyDown(sender, e2); } /// /// 采集明细切换 /// /// /// private void griddetno_KeyDown(object sender, KeyEventArgs e) { if (Keys.Enter == e.KeyData) { bool FindDetno = false; for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True") { FindDetno = true; CurrentItemIndex = 0; CurrentRowIndex = i; RemindUser(); break; } } if (!FindDetno) { BaseUtil.ShowError("不存在未采集的明细序号" + griddetno.Text); } } } 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) { try { string la_id = MidLabelCombox.SelectedValue.ToString(); string cl_labelname = MidLabelCombox.Text; string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString(); MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname)); dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select"); for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++) { //将维护的模板参数和模板本身的参数名称进行比对 for (int k = 0; k < dt.Rows.Count; k++) { //名称相等的时候,取SQL进行值的查询 if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString()) { //获取对应行的pib_id string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString(); string pib_outboxcode1 = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString(); //获取打印执行的SQL string sql = dt.Rows[k]["lp_sql"].ToString(); //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1} try { string ExeSQL = ""; if (sql.Contains("pib_lotno")) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString(); } else if (sql.Contains("pib_datecode")) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString(); } else { ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1); ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1; MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString(); } LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value); } catch (Exception) { BaseUtil.ShowError("SQL维护不正确,请检查SQL语句"); } } else if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1") { if (LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value != null) { MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value.ToString(); } } } } //保存参数打印 MidDoc.Save(); MidDoc.Printer.SwitchTo(MidLabelPrinter.Text); MidDoc.PrintDocument(); LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString()); MidDoc.Close(); LogManager.DoLog("打印文件" + MidDoc.Name + "关闭"); } catch (Exception) { MidDoc.Close(); } } else { MessageBox.Show("未维护中盒模板"); } } } private void LoginOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Login login = new Login(); logout = true; Hide(); login.ShowDialog(); Close(); } /// /// 勾选的时候自动打印 /// /// /// private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode") { string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString(); try { System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); GregorianCalendar gc = new GregorianCalendar(); int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday); if (weekOfYear < 10) { LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear; } else { LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } private void AllCollected_Click(object sender, EventArgs e) { if (AllCollect == false) { for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "False") { LabelInf.Rows[i].Cells["pib_ifpick"].Value = true; AllCollect = true; CurrentRowIndex = i; } } } else { for (int i = 0; i < LabelInf.RowCount; i++) { if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True") { LabelInf.Rows[i].Cells["pib_ifpick"].Value = false; AllCollect = false; } } } } private void PowerSetting_Click(object sender, EventArgs e) { PowerSetting pw = new PowerSetting(); BaseUtil.SetFormCenter(pw); pw.ShowDialog(); } private void GetOutBoxCode_Click(object sender, EventArgs e) { int Current = 0; sql.Clear(); sql.Append("select pd_qty,pd_cartonno,pr_zxbzs,pd_cartons from packingdetail left join packing on pd_piid=pi_id left join prodinout on "); sql.Append("pi_packingcode=packing.pi_code left join product on pd_prodcode=pr_code where pi_inoutno='" + pi_inoutno.Text + "' order by pd_detno"); dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); for (int i = 0; i < dt.Rows.Count; i++) { int pd_qty = int.Parse(dt.Rows[i]["pd_qty"].ToString()); int pr_zxbzs = int.Parse(dt.Rows[i]["pr_zxbzs"].ToString()); int pd_cartons = int.Parse(dt.Rows[i]["pd_cartons"].ToString()); for (int j = 0; j < pd_qty * pd_cartons / pr_zxbzs; j++) { LabelInf.Rows[Current].Cells["pib_outboxcode2"].Value = dt.Rows[i]["pd_cartonno"].ToString(); Current++; } } SaveGrid_Click(sender, e); } 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; this.Hide(); login.ShowDialog(); this.Close(); } } private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { } } }