| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326 |
- 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_出货标签管理.CustomControl.GroupBoxWithBorder;
- using UAS_出货标签管理.PublicMethod;
- using UAS_出货标签管理.Entity;
- using UAS_特殊解析规则;
- namespace UAS_出货标签管理
- {
- public partial class 贴标机条码打印 : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- DataTable dt;
- StringBuilder sql = new StringBuilder();
- /*CodeSoft新建打印机引擎*/
- ApplicationClass lbl;
- /*单盘打印文件*/
- Document SingleDoc;
- /*中盒打印文件*/
- Document MidDoc;
- /*外箱打印文件*/
- Document OutBoxDoc;
- //当前品牌
- string Brand;
- string PI_ID;
- //当前扫描的项目
- int CurrentItemIndex = 0;
- //当前扫描的所在行
- int CurrentRowIndex = 0;
- //最大的出入口单号
- int MaxOutBoxCode = 1;
- /*正则表达式用于项目匹配*/
- Regex reg;
- /*标识供应商物料编号采集是否通过*/
- bool CollectVeProdCodePass;
- bool CollectQTYPass;
- bool logout = false;
- /*用于存放采集项目的Grid信息*/
- Dictionary<string, Dictionary<string, string>> SiItem;
- /*需要重绘的Cell*/
- Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
- //使用二位数组进行排序
- ArrayList<ArrayList<string>> ScanData;
- ArrayList<string> GetData;
- public 贴标机条码打印()
- {
- InitializeComponent();
- }
- protected override void WndProc(ref Message m)
- {
- //拦截双击标题栏、移动窗体的系统消息
- if (m.Msg != 0xA3)
- {
- base.WndProc(ref m);
- }
- }
- private void 贴标机条码打印_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- LogManager.DoLog("程序启动,登陆人员" + User.UserName);
- dh = new DataHelper();
- pi_inoutno.Focus();
- //将本地读取的打印机设置进Combox,并选中默认打印机
- 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 ScreenHeight = Screen.GetWorkingArea(pt).Width;
- //如果分辨率大的设置的字体对应的变大
- if (ScreenHeight > 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;
- 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();
- }
- /// <summary>
- /// 保存明细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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).GetChanges(), "ProdioBarCode", "pib_id");
- 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<ArrayList<string>>();
- //每个采集项目的子项
- GetData = new ArrayList<string>();
- //将数据添加进一个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<string>();
- }
- }
- RemindUser();
- if (ScanData.ToArray().Length > 0)
- {
- object[] arr = (ScanData.ToArray()[0] as ArrayList<string>).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("采集的数据不能为空");
- }
- CollectData();
- }
- }
- /// <summary>
- /// 设置自动匹配的数据的行号
- /// </summary>
- /// <returns></returns>
- private void SetAutoMatchRow()
- {
- //采集策略的第一组数据
- string[] 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;
- }
- }
- }
- /// <summary>
- /// 采集数据
- /// </summary>
- private void CollectData()
- {
- LogManager.DoLog("采集数据" + Input.Text + ",使用采集策略编号" + sg_code.Text);
- //按DetNo排列之后的采集项
- ScanData = new ArrayList<ArrayList<string>>();
- //每个采集项目的子项
- GetData = new ArrayList<string>();
- //用于保存采集策略的具体信息
- SiItem = new Dictionary<string, Dictionary<string, string>>();
- 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<string>();
- }
- Dictionary<string, string> item = new Dictionary<string, string>();
- 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);
- }
- //采集项目的数组
- object[] ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
- //分隔符不为空的时候 //采集的项和Grid的数目不等
- if (sg_separator.Text == "" && ScanData.ToArray().Length != Si_ItemDGV.RowCount)
- {
- BaseUtil.ShowError("所选采集策略和当前采集项目不符合,含有同顺序采集项时必须维护分隔符!");
- }
- else {
- //用户采集的数据的分割数组
- List<string> CollectData = Input.Text.Split(sg_separator.Text.ToCharArray()).ToList();
- //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
- if (ItemData.Length == 1)
- {
- CollectData.Clear();
- CollectData.Add(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 == "盒")
- {
- 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;
- if (SingleLabelAutoPrint.Checked)
- {
- 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(LabelUrl);
- 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++)
- {
- //将维护的模板参数和模板本身的参数名称进行比对
- 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();
- sql = sql.Substring(0, sql.IndexOf("{"));
- //获取对应行的pib_id
- string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
- }
- }
- }
- //保存参数打印
- SingleDoc.Save();
- SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
- SingleDoc.PrintDocument();
- LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
- LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
- }
- if (MidLabelAutoPrint.Checked)
- {
- AutoPrintMidLabel();
- }
- }
- }
- }
- else {
- LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
- //勾选了单盘自动打印
- if (SingleLabelAutoPrint.Checked)
- {
- 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(LabelUrl);
- 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++)
- {
- //将维护的模板参数和模板本身的参数名称进行比对
- 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[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
- LogManager.DoLog("打印参数" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
- }
- }
- }
- }
- //保存参数打印
- SingleDoc.Save();
- SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
- SingleDoc.PrintDocument();
- LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
- LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
- }
- //勾选了中盒自动打印
- 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();
- }
- //设置行的索引到当前需要采集的行
- 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;
- }
- }
- }
- /// <summary>
- /// 提醒用户当前采集的项目
- /// </summary>
- private void RemindUser()
- {
- SetRowIndexToCollectRow();
- if (ScanData.ToArray().Length > 0)
- {
- object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
- string Inf = "";
- for (int i = 0; i < arr.Length; i++)
- {
- Inf += arr[i] + " ";
- }
- MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green);
- }
- }
- /// <summary>
- /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的
- /// </summary>
- /// <param name="data"></param>
- /// <param name="kind"></param>
- private void SetDataToCell(ref List<string> setdata, string kind)
- {
- int length = setdata.ToArray().Length;
- for (int j = 0; j < length; j++)
- {
- string[] data = setdata.ToArray();
- 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(data[j]);
- length--;
- break;
- case "LOTNO":
- cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"];
- Matchstr = MatchStr(data[j], "LOTNO");
- setdata.Remove(data[j]);
- 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(data[j]);
- 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(data[j]);
- length--;
- break;
- default:
- break;
- }
- //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
- //MPN和QTY只做比较不需要赋值
- if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
- {
- if (kind != "MPN" && kind != "QTY")
- {
- cell.Value = Matchstr;
- }
- LogManager.DoLog("采集项" + kind + ",匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr);
- }
- }
- }
- //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成
- if (OutboxCapacity.Value != 0 && CurrentItemIndex == ScanData.ToArray().Length - 1)
- {
- //获取当前出入口单最大的外箱号
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
- if (int.Parse(outboxcode == "" ? "1" : 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 (MaxOutBoxCodeCount < OutboxCapacity.Value)
- {
- LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
- }
- else {
- MaxOutBoxCode = MaxOutBoxCode + 1;
- LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
- }
- }
- }
- /// <summary>
- /// 自定义函数 根据匹配规则
- /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
- /// </summary>
- /// <param name="SiItem"></param>
- /// <param name="str"></param>
- /// <param name="item"></param>
- /// <returns></returns>
- 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)
- {
- }
- }
- 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)
- {
- }
- break;
- case "二次解析":
- str = Analysis.AnalysisData(Brand, item, str);
- break;
- case "全部":
- break;
- default:
- break;
- }
- if (SiItem[item]["si_expression"] != "")
- {
- reg = new Regex(SiItem[item]["si_expression"]);
- str = reg.Match(str).Value;
- }
- 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
- {
- }
- }
- }
- }
- /// <summary>
- /// 出入库单录入框的回车事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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 (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 SingleLabelPrint_Click(object sender, EventArgs e)
- {
- 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(LabelUrl);
- //查询该模板维护的所有参数
- 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)
- {
- //打印所有的选中行
- 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")
- {
- //以标签模板的参数为基准,循环取数
- 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();
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
- LogManager.DoLog("打印参数" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
- }
- }
- }
- }
- //保存参数打印
- SingleDoc.Save();
- SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
- SingleDoc.PrintDocument();
- LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
- //勾选为已打印
- LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
- }
- }
- }
- else {
- BaseUtil.ShowError("此模板尚未维护参数");
- }
- }
- 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(LabelUrl);
- //中盒号所在的行
- 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");
- 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 = 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:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
- }
- }
- catch (Exception)
- {
- BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql);
- }
- }
- }
- }
- //保存参数打印
- MidDoc.Save();
- MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
- MidDoc.PrintDocument();
- LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[MidLabelRowIndex].Cells["pib_id1"].Value.ToString());
- }
- else {
- BaseUtil.ShowError("该出入库单未找到该中盒号!");
- }
- }
- else {
- MessageBox.Show("未维护中盒模板");
- }
- }
- private void OutBoxLabelPrint_Click(object sender, EventArgs e)
- {
- if (OutBoxNum.Text == "")
- {
- BaseUtil.ShowError("手动打印必须填写箱号");
- }
- 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(LabelUrl);
- //中盒号所在的行
- 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 = 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:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value);
- }
- catch (Exception)
- {
- LogManager.DoLog("SQL维护不正确,请检查SQL语句" + sql);
- BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql);
- }
- }
- }
- }
- }
- //保存参数打印
- OutBoxDoc.Save();
- OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
- OutBoxDoc.PrintDocument();
- LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_id1"].Value.ToString());
- }
- else {
- BaseUtil.ShowError("该出入库单未找到该外箱号!");
- }
- }
- private void CleanDetail_Click(object sender, EventArgs e)
- {
- ArrayList<string> DeleteID = new ArrayList<string>();
- 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("尚未勾选需要删除的明细");
- }
- }
- /// <summary>
- /// 刷新采集进度
- /// </summary>
- 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();
- }
- }
- /// <summary>
- /// 自定义函数 加载明细行的数据,多处使用添加进函数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LoadGridData(object sender, EventArgs e)
- {
- sql.Clear();
- sql.Append("select 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,");
- sql.Append("pib_ifpick, pib_ifprint from prodiobarcode left join prodiodetail on pib_piid=pd_piid and ");
- sql.Append("pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on ");
- sql.Append("pr_code=pib_prodcode where pd_piid='" + PI_ID + "' order by pd_id ,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;
- }
- }
- }
- /// <summary>
- /// 重绘Cell的颜色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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)
- {
- LogManager.DoLog("几个日志");
- 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);
- }
- /// <summary>
- /// 采集明细切换
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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)
- {
- 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(LabelUrl);
- 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 = 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:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
- }
- catch (Exception)
- {
- BaseUtil.ShowError("SQL维护不正确,请检查SQL语句");
- }
- }
- }
- }
- //保存参数打印
- MidDoc.Save();
- MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
- MidDoc.PrintDocument();
- LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
- }
- else {
- MessageBox.Show("未维护中盒模板");
- }
- }
- }
- private void LoginOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- Login login = new Login();
- logout = true;
- Hide();
- login.ShowDialog();
- Close();
- }
- }
- }
|