| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- using System;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Text.RegularExpressions;
- using System.Text;
- using System.Collections.Generic;
- using System.Linq;
- using System.Diagnostics;
- using UAS_LabelMachine.PublicMethod;
- using UAS_LabelMachine.Entity;
- using System.Reflection;
- namespace UAS_LabelMachine
- {
- public partial class UAS_出货标签打印 : Form
- {
- //自适应屏幕
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- DataTable dt;
- /// <summary>
- /// 已经打印过的Vivo外箱号
- /// </summary>
- StringBuilder sql = new StringBuilder();
- /// <summary>
- /// 当前品牌
- /// </summary>
- string Brand;
- string PI_ID;
- /// <summary>
- /// 当前扫描的项目
- /// </summary>
- int CurrentItemIndex = 0;
- /// <summary>
- /// 当前扫描的所在行
- /// </summary>
- int CurrentRowIndex = 0;
- bool Checking = false;
- /// <summary>
- /// 正则表达式用于项目匹配
- /// </summary>
- Regex reg;
- /*标识供应商物料编号采集是否通过*/
- bool CollectVeProdCodePass = true;
- bool CollectQTYPass = true;
- bool logout = false;
- //每个不同序号存在的
- object[] ItemData;
- Dictionary<string, string> CollectData;
- /// <summary>
- /// 是否全选
- /// </summary>
- bool AllChecked = false;
- /*用于存放采集项目的Grid信息*/
- Dictionary<string, Dictionary<string, string>> SiItem;
- int CloumnCount = 0;
- //使用二维数组进行排序
- ArrayList<ArrayList<string>> ScanData;
- ArrayList<string> GetData;
- //用于记录上一个扫描的型号,和当前的不一致则进行弹窗提示
- string LastSpec = "";
- public UAS_出货标签打印(string Master)
- {
- this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
- this.UpdateStyles();
- InitializeComponent();
- Type dgvType = this.LabelInf.GetType();
- PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
- pi.SetValue(this.LabelInf, true, null);
- Text = Text + "-" + Master;
- }
- protected override void WndProc(ref Message m)
- {
- //拦截双击标题栏、移动窗体的系统消息
- if (m.Msg != 0xA3)
- {
- base.WndProc(ref m);
- }
- }
- private void 贴标机条码打印_Load(object sender, EventArgs e)
- {
- //杀死之前全部未关闭的进程
- Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
- for (int i = 0; i < processes.Length; i++)
- {
- processes[i].Kill();
- }
- //用计时器重置数据库链接
- LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
- dh = SystemInf.dh;
- CheckForIllegalCrossThreadCalls = false;
- CloumnCount = LabelInf.Columns.Count;
- pi_inoutno.Focus();
- //将本地读取的打印机设置进Combox,并选中默认打印机
- sg_brand.FormName = Name;
- sg_brand.SetValueField = new string[] { "sg_brand" };
- sg_brand.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
- sg_brand.TableName = "scangroup";
- sg_brand.DbChange += Sg_brand_DbChange;
- pr_code.FormName = Name;
- pr_code.SetValueField = new string[] { "pr_code" };
- pr_code.TableName = "prodiodetail left join product on pd_prodcode=pr_code";
- pr_code.SelectField = "pd_pdno # 行号,pr_code # 物料编号";
- cu_code.FormName = Name;
- cu_code.SetValueField = new string[] { "cu_code" };
- cu_code.TableName = "customer";
- cu_code.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
- Point pt = new Point();
- //禁止所有列的排序
- foreach (DataGridViewColumn dgv in LabelInf.Columns)
- {
- dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
- }
- int ScreenWidth = Screen.GetWorkingArea(pt).Width;
- //设置获取当前屏幕大小自动全屏但是保留任务栏
- Rectangle ScreenArea = Screen.GetWorkingArea(this);
- Top = 0;
- Left = 0;
- Width = ScreenArea.Width;
- Height = ScreenArea.Height;
- asc.controllInitializeSize(this);
- asc.controlAutoSize(this);
- }
- private void Sg_brand_DbChange(object sender, EventArgs e)
- {
- DataTable dt = sg_brand.ReturnData;
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- //只执行一次窗体自适应
- bool AutoSized = false;
- private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
- {
- if (!AutoSized)
- {
- asc.controlAutoSize(this);
- AutoSized = true;
- }
- }
- 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_brand.Text);
- form.WindowState = FormWindowState.Maximized;
- form.FormClosed += sg_brand_UserControlTextChanged;
- BaseUtil.SetFormCenter(form);
- form.ShowDialog();
- }
- private void LabelFormClose(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 保存明细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SaveGrid_Click(object sender, EventArgs e)
- {
- DataTable savedt = (LabelInf.DataSource as DataTable);
- savedt.EndInit();
- if (savedt != null && savedt.GetChanges() != null)
- {
- dh.CallProcedure("sp_uploadbarcode", savedt.GetChanges());
- CheckRecheckStatus();
- MessageBox.Show("保存成功!");
- }
- }
- //放大镜选择后出发的事件
- private void sg_brand_UserControlTextChanged(object sender, EventArgs e)
- {
- //取已启用的的按照采集次序排序
- DataTable dt = (DataTable)dh.ExecuteSql("select si_item,si_detno,sg_separator,si_kind,si_expression,si_expressionitem,si_index,si_indexstring,si_length from scanitem left join scangroup on si_sgid=sg_id where sg_brand='" + sg_brand.Text + "' and si_enable<>0 order by si_detno,si_innerdetno", "select");
- if (dt.Rows.Count == 0)
- {
- dt = (DataTable)dh.ExecuteSql("select si_item,si_detno,sg_separator,si_kind,si_expression,si_expressionitem,si_index,si_indexstring,si_length from scanitem left join scangroup on si_sgid=sg_id where nvl(sg_brand,' ')=' ' and si_enable<>0 order by si_detno,si_innerdetno", "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") || arr.Contains("CPN"))
- {
- 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 == "")
- {
- MessageBox.Show("采集的数据不能为空");
- return;
- }
- if (Si_ItemDGV.Rows.Count == 0)
- {
- MessageBox.Show("未维护采集策略");
- return;
- }
- 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++)
- {
- string orispeccode = LabelInf.Rows[i].Cells["pr_orispeccode"].Value.ToString();
- if ((MatchStr(arr[j].ToString(), "MPN").Contains(orispeccode) || MatchStr(arr[j].ToString(), "MPN").Trim().Replace(" ", "").Contains(orispeccode) || orispeccode == MatchStr(arr[j].ToString(), "MPN") ||( LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "CPN")|| MatchStr(arr[j].ToString(), "CPN").Contains(LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString()))) && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
- {
- if (!Checking)
- {
- CurrentRowIndex = i;
- Checking = true;
- }
- if (CurrentRowIndex - 5 > 0)
- LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
- else
- LabelInf.FirstDisplayedScrollingRowIndex = 0;
- Brand = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].FormattedValue.ToString();
- if (Brand != "")
- sg_brand.Text = Brand;
- FindAutoMatch = true;
- if ((MatchStr(arr[j].ToString(), "MPN").Contains(orispeccode) || MatchStr(arr[j].ToString(), "MPN").Trim().Replace(" ", "").Contains(orispeccode) || orispeccode == MatchStr(arr[j].ToString(), "MPN")))
- {
- if (LastSpec == "")
- {
- LastSpec = orispeccode;
- }
- if (LastSpec != orispeccode)
- {
- LastSpec = orispeccode;
- MessageBox.Show("切换扫描型号" + orispeccode);
- }
- }
- break;
- }
- }
- if (FindAutoMatch)
- break;
- }
- }
- /// <summary>
- /// 采集数据
- /// </summary>
- private void CollectInputData()
- {
- LogManager.DoLog("采集数据【" + Input.Text + "】,使用采集策略编号【" + sg_brand.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
- {
- int DataCount = Input.Text.Split(sg_separator.Text.ToCharArray()).Length;
- if (DataCount > ItemData.Length)
- {
- MessageBox.Show("采集数据大于采集项次");
- return;
- }
- else if (DataCount < ItemData.Length)
- {
- MessageBox.Show("采集数据小于采集项次");
- return;
- }
- for (int i = 0; i < DataCount; 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
- {
- MessageBox.Show("所采集的数据个数和采集项目不符");
- return;
- }
- //采集项目的索引+1
- CurrentItemIndex = CurrentItemIndex + 1;
- //如果已经采集完了最后一个
- if (CurrentItemIndex == ScanData.ToArray().Length)
- {
- //数据校验均已通过则勾选上已采集
- if (CollectVeProdCodePass && CollectQTYPass)
- {
- //如果按盒号采集,所有的此盒的均更新为
- DataTable dt = (DataTable)MidSource.DataSource;
- LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
- LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
- string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
- string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
- string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- ErrorType.Clear();
- dh.ExecuteSql("update prodiobarcode set pib_datecode='" + datecode + "',pib_lotno='" + lotno + "',pib_ifpick=-1 where pib_id='" + pib_id + "'", "update");
- CheckRecheckStatus();
- LabelInf.Invalidate();
- Checking = false;
- ProcessRemind();
- }
- //采集未通过的时候
- else
- {
- ErrorType.Clear();
- //如果自动采集采集未成功需要移动到下一行
- if (!AutoMatch.Checked)
- SetRowIndexToCollectRow();
- }
- //当前项目已采集完成,重置采集项目
- CurrentItemIndex = 0;
- //未勾选自动匹配,设置到下一个未采集的行
- if (!AutoMatch.Checked)
- SetRowIndexToCollectRow();
- }
- RemindUser();
- //提醒用户需要采集的数据
- MessageLog.AppendText(">>扫描到数据" + Input.Text + "\n", Color.Blue);
- //如果所采集的行的物料不一样的话,重新计算箱内容量
- if (CurrentRowIndex - 1 > 0)
- {
- string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString();
- string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString();
- }
- 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;
- }
- }
- }
- /// <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);
- }
- }
- private void ProcessRemind()
- {
- int Count = dh.getRowCount("prodiobarcode", "pib_piid=" + PI_ID + " and pib_ifpick<>0");
- CollectedCount.Text = Count.ToString();
- }
- List<string> ErrorType = new List<string>();
- /// <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_orispeccode"];
- Matchstr = MatchStr(data[j], "MPN");
- //采集的供应商号不匹配的话
- if (cell.Value.ToString() == Matchstr || Matchstr.Trim().Replace(" ", "").Contains(cell.Value.ToString()) || Matchstr.Contains(cell.Value.ToString()))
- {
- ErrorType.Add("OK_MPN");
- BaseUtil.PlaySound("OK.wav");
- LabelInf.Refresh();
- CollectVeProdCodePass = true;
- }
- else
- {
- ErrorType.Add("NG_MPN");
- CollectVeProdCodePass = false;
- BaseUtil.PlaySound("NG.wav");
- //添加需要重绘的Cell
- LabelInf.Refresh();
- MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
- }
- 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;
- LabelInf.Refresh();
- MessageLog.AppendText(">>数量不匹配\n", Color.Red);
- }
- else
- {
- LabelInf.Refresh();
- CollectQTYPass = true;
- }
- setdata.Remove("QTY");
- length--;
- break;
- case "CPN":
- cell = LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"];
- Matchstr = MatchStr(data[j], "CPN");
- //如果采集的数量不相等的话
- if (cell.Value.ToString() != Matchstr && !Matchstr.Contains(cell.Value.ToString()))
- {
- ErrorType.Add("NG_CPN");
- BaseUtil.PlaySound("NG.wav");
- CollectQTYPass = false;
- LabelInf.Refresh();
- MessageLog.AppendText(">>CPN不匹配\n", Color.Red);
- }
- else
- {
- ErrorType.Add("OK_CPN");
- BaseUtil.PlaySound("OK.wav");
- LabelInf.Refresh();
- CollectQTYPass = true;
- }
- setdata.Remove("CPN");
- length--;
- break;
- default:
- break;
- }
- //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
- //MPN和QTY只做比较不需要赋值
- if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
- {
- string MatchResult = "";
- if (kind != "MPN" && kind != "QTY" && kind != "CPN")
- {
- DataTable dt = (DataTable)MidSource.DataSource;
- 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);
- }
- }
- }
- /// <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.StackTrace); }
- }
- 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.StackTrace); }
- break;
- case "全部":
- break;
- default:
- break;
- }
- if (SiItem[item]["si_expression"] != "")
- {
- string log = "使用正则表达式" + SiItem[item]["si_expression"] + "匹配数据" + str;
- reg = new Regex(SiItem[item]["si_expression"]);
- try
- {
- str = reg.Matches(str)[int.Parse(SiItem[item]["si_expressionitem"].ToString()) - 1].Value;
- }
- catch (Exception)
- {
- }
- 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
- {
- LogManager.DoLog("关闭程序");
- }
- }
- }
- /// <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,to_char(pi_date,'yyyymmdd')pi_date,nvl(cu_needrecheck,0)cu_needrecheck from prodinout left join customer on cu_code=pi_cardcode where pi_invoicecode='" + pi_invoicecode.Text + "' ");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- ErrorType.Clear();
- if (dt.Rows.Count > 0)
- {
- cu_code.Text = dt.Rows[0]["pi_cardcode"].ToString();
- cu_needrecheck.Text = dt.Rows[0]["cu_needrecheck"].ToString();
- pi_date.Text = dt.Rows[0]["pi_date"].ToString();
- PI_ID = dt.Rows[0]["pi_id"].ToString();
- dt = (DataTable)dh.ExecuteSql("select 1 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "select");
- if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "" && dt.Rows.Count == 0)
- {
- string Error = "";
- string[] param = new string[] { PI_ID, "", Error };
- dh.CallProcedure("GetCustBarcode", param);
- }
- LoadGridData(sender, e);
- //设置当前的最大箱号
- CurrentItemIndex = 0;
- LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
- }
- else
- MessageBox.Show("当前出入库单号不存在或者未审核!");
- }
- }
- 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);
- }
- }
- else
- MessageBox.Show("尚未勾选需要删除的明细");
- }
- private void LoadGridData()
- {
- LoadGridData(new object(), new EventArgs());
- }
- /// <summary>
- /// 自定义函数 加载明细行的数据,多处使用添加进函数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LoadGridData(object sender, EventArgs e)
- {
- sql.Clear();
- sql.Append("select * from prodiobarcode_view1 where pib_piid='" + PI_ID + "'");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- MidSource.DataSource = dt;
- BaseUtil.FillDgvWithDataTable(LabelInf, (DataTable)MidSource.DataSource);
- //有数据的话默认取第一条的品牌去取采集策略
- TotalCount.Text = LabelInf.RowCount.ToString();
- ProcessRemind();
- if (LabelInf.RowCount > 0)
- {
- Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString();
- if (Brand != "")
- sg_brand.Text = Brand;
- }
- //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
- 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_custbarcode" || LabelInf.Columns[e.ColumnIndex].Name == "pib_barcode" || LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" || 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" || LabelInf.Columns[e.ColumnIndex].Name == "pib_brand")
- {
- 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)
- {
- if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
- {
- if (LabelInf.Columns[e.ColumnIndex].Name == "pr_orispeccode" || LabelInf.Columns[e.ColumnIndex].Name == "pd_custprodcode")
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.Black, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- }
- }
- if (e.RowIndex == CurrentRowIndex)
- {
- if (LabelInf.Columns[e.ColumnIndex].Name == "pr_orispeccode")
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- if (ErrorType.Count > 0)
- {
- if (ErrorType.Contains("OK_MPN"))
- {
- e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.Black, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- else if (ErrorType.Contains("NG_MPN"))
- {
- e.Graphics.FillRectangle(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 == "pd_custprodcode")
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- if (ErrorType.Count > 0)
- {
- if (ErrorType.Contains("OK_CPN"))
- {
- e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.Black, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- else if (ErrorType.Contains("NG_CPN"))
- {
- e.Graphics.FillRectangle(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 pr_code_UserControlTextChanged(object sender, EventArgs e)
- {
- //用户在重新勾选后重置采集项目的索引
- 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)
- {
- MessageBox.Show("不存在未采集的明细序号" + griddetno.Text);
- return;
- }
- }
- }
- private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (close.ToString() == "Yes")
- {
- Login login = new Login();
- //注销的时候需要将拼接的连接字符串置空
- DataHelper.DBConnectionString = null;
- logout = true;
- this.Hide();
- login.ShowDialog();
- this.Close();
- }
- }
- private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
- private void ChooseAll_Click(object sender, EventArgs e)
- {
- if (AllChecked)
- {
- foreach (DataGridViewRow dr in LabelInf.Rows)
- dr.Cells[0].Value = false;
- AllChecked = false;
- }
- else
- {
- foreach (DataGridViewRow dr in LabelInf.Rows)
- dr.Cells[0].Value = true;
- AllChecked = true;
- }
- }
- private void ExportData_Click(object sender, EventArgs e)
- {
- ExportFileDialog.Description = "选择导出的路径";
- DialogResult result = ExportFileDialog.ShowDialog();
- if (result == DialogResult.OK)
- {
- ExcelHandler eh = new ExcelHandler();
- DataTable dt = ((DataTable)MidSource.DataSource).Copy();
- for (int i = dt.Columns.Count - 1; i >= 0; i--)
- {
- for (int j = 0; j < LabelInf.Columns.Count; j++)
- {
- //去除ID列
- if (dt.Columns[i].ColumnName.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifpick" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
- {
- dt.Columns.RemoveAt(i);
- break;
- }
- switch (dt.Columns[i].ColumnName.ToLower())
- {
- case "pib_lotno":
- dt.Columns[i].ColumnName = "批次号";
- break;
- case "pib_datecode":
- dt.Columns[i].ColumnName = "生产日期";
- break;
- case "pib_custbarcode":
- dt.Columns[i].ColumnName = "最小产品包装条码";
- break;
- default:
- break;
- }
- if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
- {
- dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
- break;
- }
- }
- }
- eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
- string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (close.ToString() == "Yes")
- System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
- }
- }
- private void CleanBarCode_Click(object sender, EventArgs e)
- {
- string close = MessageBox.Show(this.ParentForm, "是否清除该出货单条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (close.ToString() == "Yes")
- {
- dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
- LoadGridData(sender, e);
- }
- }
- private void CollectAll_Click(object sender, EventArgs e)
- {
- int PickedCount = 0;
- for (int i = 0; i < LabelInf.Rows.Count; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
- {
- LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
- }
- else
- {
- PickedCount = PickedCount + 1;
- }
- }
- if (PickedCount == LabelInf.Rows.Count)
- {
- for (int i = 0; i < LabelInf.Rows.Count; i++)
- {
- LabelInf.Rows[i].Cells["pib_ifpick"].Value = false;
- }
- }
- }
- private void CheckRecheckStatus()
- {
- if (cu_needrecheck.Text == "0")
- {
- dh.ExecuteSql("update customer set cu_needrecheck=-1 where cu_code='" + cu_code.Text + "'", "update");
- }
- if (dh.getRowCount("prodiobarcode", "nvl(pib_ifpick,0)<>0 and pib_inoutno='" + pi_inoutno.Text + "'") == LabelInf.Rows.Count)
- {
- dh.ExecuteSql("update prodinout set pi_recheckstatus='已复核' where pi_inoutno='" + pi_inoutno.Text + "'", "update");
- }
- }
- }
- }
|