| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661 |
- using System;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- using 贴标机标签打印.CustomControl.GroupBoxWithBorder;
- using 贴标机标签打印.PublicMethod;
- using System.Text.RegularExpressions;
- using System.Text;
- using LabelManager2;
- using System.Collections.Generic;
- namespace 贴标机标签打印
- {
- public partial class 贴标机条码打印 : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- DataTable dt;
- StringBuilder sql = new StringBuilder();
- /*CodeSoft新建打印机引擎*/
- ApplicationClass lbl;
- /*单盘打印文件*/
- Document SingleDoc;
- /*中盒打印文件*/
- Document MidDoc;
- /*外箱打印文件*/
- Document OutBoxDoc;
- string PI_ID;
- //当前扫描的项目
- int CurrentIndex = 0;
- //当前扫描的所在行
- int CurrentRowIndex = 0;
- //需要重绘的Cell的RowIndx
- int CellRowIndex = -2;
- /*正则表达式用于项目匹配*/
- Regex reg;
- /*标识一行采集是否通过*/
- bool CollectPass = true;
- /*用于存放采集项目的Grid信息*/
- Dictionary<string, Dictionary<string, string>> SiItem;
- //使用二位数组进行排序
- ArrayList<ArrayList<string>> Data;
- ArrayList<string> GetData;
- public 贴标机条码打印()
- {
- InitializeComponent();
- }
- protected override void WndProc(ref System.Windows.Forms.Message m)
- {
- //拦截双击标题栏、移动窗体的系统消息
- if (m.Msg != 0xA3)
- {
- base.WndProc(ref m);
- }
- }
- private void 贴标机条码打印_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- dh = new DataHelper();
- pi_inoutno.Focus();
- //将本地读取的打印机设置进Combox,并选中默认打印机
- sg_code.Caller = "LabelMachine";
- sg_code.FormName = Name;
- sg_code.SetValueField = new string[] { "sg_code" };
- pr_code.Caller = "LabelMachine";
- pr_code.FormName = Name;
- pr_code.SetValueField = new string[] { "pr_code", "pib_id" };
- ChooseAll.ChooseAll(LabelInf);
- Point pt = new Point();
- int ScreenHeight = Screen.GetWorkingArea(pt).Width;
- //如果分辨率大的设置的字体对应的变大
- if (ScreenHeight > 1366)
- {
- foreach (Control ctl in Controls)
- {
- if (ctl is CheckBox || ctl is Label || ctl is RadioButton)
- {
- ctl.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
- }
- if (ctl is GroupBoxWithBorder)
- {
- GroupBoxWithBorder gb = ctl as GroupBoxWithBorder;
- for (int i = 0; i < gb.Controls.Count; i++)
- {
- if (gb.Controls[i] is CheckBox || gb.Controls[i] is Label || gb.Controls[i] is RadioButton)
- {
- gb.Controls[i].Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
- }
- }
- }
- }
- }
- //设置获取当前屏幕大小自动全屏但是保留任务栏
- Rectangle ScreenArea = Screen.GetWorkingArea(this);
- Top = 0;
- Left = 0;
- Width = ScreenArea.Width;
- Height = ScreenArea.Height;
- asc.controlAutoSize(this);
- //实例化打印进程
- try
- {
- lbl = new ApplicationClass();
- }
- catch (Exception)
- {
- MessageBox.Show("未安装CodeSoft软件或者版本错误");
- }
- }
- private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void GenerateBarCode_Click(object sender, EventArgs e)
- {
- 生成条码 form = new 生成条码(pi_inoutno.Text);
- form.FormClosed += LoadGridData;
- BaseUtil.SetFormCenter(form);
- form.ShowDialog();
- }
- private void CollectionSetting_Click(object sender, EventArgs e)
- {
- 采集策略 form = new 采集策略(sg_code.Text);
- form.FormClosed += sg_code_UserControlTextChanged;
- BaseUtil.SetFormCenter(form);
- form.ShowDialog();
- }
- private void LabelMaintain_Click(object sender, EventArgs e)
- {
- 客户标签维护 form = new 客户标签维护();
- BaseUtil.SetFormCenter(form);
- form.ShowDialog();
- }
- /// <summary>
- /// 保存明细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SaveGrid_Click(object sender, EventArgs e)
- {
- DataTable savedt = LabelInf.DataSource as DataTable;
- if (LabelInf.DataSource != null && savedt.GetChanges() != null)
- {
- dh.UpDateTableByCondition((LabelInf.DataSource as DataTable).GetChanges(), "ProdioBarCode", "pib_id");
- }
- }
- //放大镜选择后出发的事件
- 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();
- }
- Data = 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 {
- Data.Add(GetData);
- //添加完一次数据需要一个新的List
- GetData = new ArrayList<string>();
- }
- }
- if (Data.ToArray().Length > 0)
- {
- if ((Data.ToArray()[0] as ArrayList<string>).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("采集的数据不能为空");
- }
- //如果勾选了自动采集
- if (AutoMatch.Checked)
- {
- CollectData();
- }
- else {
- if (pib_id.Text != "")
- {
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() == pib_id.Text)
- {
- CurrentRowIndex = LabelInf.Rows[i].Cells["pib_id1"].RowIndex;
- }
- }
- }
- else {
- BaseUtil.ShowError("非自动匹配时必须选择指定的行");
- }
- CollectData();
- }
- }
- }
- private void ComSetting_Click(object sender, EventArgs e)
- {
- 参数及端口配置 form = new 参数及端口配置();
- BaseUtil.SetFormCenter(form);
- form.ShowDialog();
- }
- /// <summary>
- /// 采集数据
- /// </summary>
- private void CollectData()
- {
- Data = new ArrayList<ArrayList<string>>();
- GetData = new ArrayList<string>();
- //用于保存采集策略的具体信息
- SiItem = new Dictionary<string, Dictionary<string, string>>();
- //是否通过,一行采集结束时会通过此参数进行验证
- CollectPass = true;
- 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 {
- Data.Add(GetData);
- //添加完一次数据需要一个新的List
- GetData = new ArrayList<string>();
- }
- Dictionary<string, string> item = new Dictionary<string, string>();
- for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
- {
- item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
- }
- SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
- }
- //采集项目的数组
- object[] ItemData = (Data.ToArray()[CurrentIndex] as ArrayList<string>).ToArray();
- //分隔符不为空的时候
- if (sg_separator.Text != "")
- {
- //用户采集的数据的分割数组
- string[] CollectData = Input.Text.Split(sg_separator.Text.ToCharArray());
- //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
- if (ItemData.Length == 1)
- {
- //将筛选之后的值赋给Cell
- SetDataToCell(CollectData, ItemData[0].ToString().ToUpper());
- }
- //如果本次采集的数据分割后和当前的采集项目个数不一样提示用户错误
- else if (CollectData.Length == ItemData.Length)
- {
- for (int i = 0; i < ItemData.Length; i++)
- {
- //将筛选之后的值赋给Cell
- Console.WriteLine("ITEM:" + CollectData[i]);
- Console.WriteLine("Data"+ ItemData[i].ToString());
- SetDataToCell(CollectData, ItemData[i].ToString().ToUpper());
- }
- }
- else {
- BaseUtil.ShowError("所采集的数据个数和采集项目不符");
- }
- }
- else {
- if (Data.ToArray().Length != Si_ItemDGV.RowCount)
- {
- BaseUtil.ShowError("所选采集策略和当前采集项目不符合,含有同顺序采集项时必须维护分隔符!");
- }
- }
- Console.WriteLine(CurrentIndex);
- CurrentIndex = CurrentIndex + 1;
- if (CurrentIndex == Data.ToArray().Length)
- {
- if (CollectPass)
- {
- LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
- //CollectedCount.Text = (int.Parse(CollectedCount.Text) + 1).ToString();
- }
- else {
- //如果自动采集采集未成功需要移动到下一行
- if (AutoMatch.Checked)
- {
- //如果已经到了最后一行则不移动
- CurrentRowIndex = CurrentRowIndex + 1 == LabelInf.RowCount ? CurrentRowIndex : CurrentRowIndex + 1;
- }
- }
- //当前项目已采集完成,重置采集项目
- CurrentIndex = 0;
- if (AutoMatch.Checked)
- {
- 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>
- /// 自定义函数 将匹配之后的值设置到Cell中
- /// </summary>
- /// <param name="data"></param>
- /// <param name="kind"></param>
- private void SetDataToCell(string[] data, string kind)
- {
- for (int i = 0; i < data.Length; i++)
- {
- switch (kind.ToString().ToUpper())
- {
- case "DATECODE":
- LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = MatchStr(data[i], "DATECODE");
- break;
- case "LOTNO":
- LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = MatchStr(data[i], "LOTNO");
- break;
- case "MPN":
- if (LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"].Value.ToString() != MatchStr(data[i], "MPN"))
- {
- CellRowIndex = CurrentRowIndex;
- LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"].Selected = true;
- CollectPass = false;
- MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
- }
- break;
- case "QTY":
- //如果采集的数量不相等的话
- if (LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"].Value.ToString() != MatchStr(data[i], "QTY"))
- {
- CellRowIndex = CurrentRowIndex;
- LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"].Selected = true;
- CollectPass = false;
- MessageLog.AppendText(">>数量不匹配\n", Color.Red);
- }
- break;
- default:
- break;
- }
- }
- }
- /// <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"] != "")
- {
- //长度不为空的时候按照指定的长度去取数据
- 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"]));
- }
- }
- break;
- case "索引字符":
- 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(int.Parse(SiItem[item]["si_indexstring"]));
- }
- }
- break;
- default:
- break;
- }
- if (SiItem[item]["si_expression"] != "")
- {
- reg = new Regex(SiItem[item]["si_expression"]);
- str = reg.Match(str).Value;
- }
- return str;
- }
- //关闭窗口前提示用户确认
- private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
- {
- string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (close.ToString() != "Yes")
- {
- e.Cancel = true;
- }
- else {
- //防止未安装打印程序时报错导致窗体无法关闭
- try
- {
- lbl.Application.Quit();
- }
- 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)
- {
- string pi_cardcode = dt.Rows[0]["pi_cardcode"].ToString();
- PI_ID = dt.Rows[0]["pi_id"].ToString();
- LoadGridData(sender, e);
- sql.Clear();
- sql.Append("select cl_labelcode,cl_labelurl,cl_isdefault from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
- sql.Append("where pi_cardcode='" + pi_cardcode + "' and pi_inoutno='" + pi_inoutno.Text + "' and cl_labeltype='单盘'");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- SingleLabelCombox.DataSource = dt;
- SingleLabelCombox.DisplayMember = "cl_labelcode";
- SingleLabelCombox.ValueMember = "cl_labelurl";
- sql.Clear();
- sql.Append("select cl_labelcode,cl_labelurl,cl_isdefault from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
- sql.Append("where pi_cardcode='" + pi_cardcode + "' and pi_inoutno='" + pi_inoutno.Text + "' and cl_labeltype='中盒'");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- MidLabelCombox.DataSource = dt.Copy();
- MidLabelCombox.DisplayMember = "cl_labelcode";
- MidLabelCombox.ValueMember = "cl_labelurl";
- sql.Clear();
- sql.Append("select cl_labelcode,cl_labelurl,cl_isdefault from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
- sql.Append("where pi_cardcode='" + pi_cardcode + "' and pi_inoutno='" + pi_inoutno.Text + "' and cl_labeltype='外箱'");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- OutBoxCombox.DataSource = dt.Copy();
- OutBoxCombox.DisplayMember = "cl_labelcode";
- OutBoxCombox.ValueMember = "cl_labelurl";
- }
- else {
- MessageBox.Show("当前出入库单号不存在!");
- }
- }
- }
- private void SingleLabelPrint_Click(object sender, EventArgs e)
- {
- SingleDoc = lbl.Documents.Open(SingleLabelCombox.SelectedValue.ToString());
- SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
- SingleDoc.PrintDocument();
- }
- private void MidLabelPrint_Click(object sender, EventArgs e)
- {
- MidDoc = lbl.Documents.Open(MidLabelCombox.SelectedValue.ToString());
- MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
- MidDoc.PrintDocument();
- }
- private void OutBoxLabelPrint_Click(object sender, EventArgs e)
- {
- OutBoxDoc = lbl.Documents.Open(OutBoxCombox.SelectedValue.ToString());
- OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
- OutBoxDoc.PrintDocument();
- }
- 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("尚未勾选需要删除的明细");
- }
- }
- /// <summary>
- /// 自定义函数 加载明细行的数据,多处使用添加进函数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LoadGridData(object sender, EventArgs e)
- {
- sql.Clear();
- sql.Append("select pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pr_brand,pr_vendprodcode,");
- sql.Append("pib_lotno,pib_datecode,pib_qty,pib_barcode,pib_outboxcode1 ,pib_outboxcode2,");
- sql.Append("pib_ifpick, pib_ifprint from prodiodetail left join prodiobarcode on pib_piid=pd_piid and ");
- sql.Append("pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on ");
- sql.Append("pr_code=pib_prodcode where pd_piid='" + PI_ID + "' order by pd_id ,pib_id");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- BaseUtil.FillDgvWithDataTable(LabelInf, dt);
- //有数据的话默认取第一条的品牌去取采集策略
- TotalCount.Text = LabelInf.RowCount.ToString();
- if (LabelInf.RowCount > 0)
- {
- string 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;
- }
- }
- CellRowIndex = -2;
- }
- /// <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;
- }
- //重绘制定的Cell,表示采集的数据不匹配
- if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && e.RowIndex == CellRowIndex)
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Red, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.White, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && e.RowIndex == CellRowIndex)
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Red, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.White, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- }
- }
- private void pr_code_SearchIconClick(object sender, EventArgs e)
- {
- pr_code.Condition = " pib_inoutno='" + pi_inoutno.Text + "'";
- }
- private void OutBoxLabelPackage_Click(object sender, EventArgs e)
- {
- SingleDoc = lbl.Documents.Open(@"\\WIN-EIQKLDB7074\CodeSoft打印\Document21.lab");
- SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
- SingleDoc.PrintDocument();
- }
- private void pr_code_UserControlTextChanged(object sender, EventArgs e)
- {
- //用户在重新勾选后重置采集项目的索引
- CurrentIndex = 0;
- }
- }
- }
|