1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020 |
- 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<string, string> CollectData;
- bool AllCollect = 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 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();
- }
- /// <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), "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<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("采集的数据不能为空");
- }
- CollectInputData();
- }
- }
- /// <summary>
- /// 设置自动匹配的数据的行号
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
- }
- /// <summary>
- /// 采集数据
- /// </summary>
- private void CollectInputData()
- {
- 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);
- }
- //采集项目的数组
- ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
- //分隔符不为空的时候 //采集的项和Grid的数目不等
- //用户采集的数据的分割数组
- CollectData = new Dictionary<string, string>();
- 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 + "关闭");
- }
- /// <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 Dictionary<string, string> 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);
- }
- //
- /// <summary>
- /// 设置外箱号
- /// </summary>
- /// <param name="BatchCollect">是否批量采集</param>
- 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;
- }
- }
- }
- }
- /// <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 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
- {
- }
- }
- }
- }
- /// <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 (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<string, bool> outboxcode1 = new Dictionary<string, bool>();
- //判断所有盒号为该盒的是否勾选已采集
- 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<string> Outboxcode = new List<string>();
- //如果未勾选箱号则对勾选的数据的箱号进行整合
- 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<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("尚未勾选需要删除的明细");
- }
- }
- private void OutBoxLabelPrint_Click(object sender, EventArgs e)
- {
- thread = new Thread(OutBoxPrint);
- stw = new SetLoadingWindow(thread, "正在打印外箱");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- }
- /// <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)
- {
- //如果是富为则使用特殊的查询语句
- 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;
- }
- }
- }
- /// <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)
- {
- 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)
- {
- 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();
- }
- /// <summary>
- /// 勾选的时候自动打印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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)
- {
- }
- }
- }
|