Beispiel #1
0
        public void PrintLabel_2(string filepatch, List <Dictionary <string, object> > LsDic)
        {
            LabelManager2.ApplicationClass lbl = new LabelManager2.ApplicationClass();
            lbl.Documents.Open(filepatch, false);// 调用设计好的label文件
            Document doc = lbl.ActiveDocument;

            SendMsg(mLogMsgType.Incoming, "清空模板变量...");
            try
            {
                for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
                {
                    doc.Variables.FormVariables.Item(doc.Variables.FormVariables.Item(i + 1).Name).Value = "";
                }
                SendMsg(mLogMsgType.Normal, string.Format("传送打印信息...."));
                foreach (Dictionary <string, object> lsD in LsDic)
                {
                    foreach (KeyValuePair <string, object> kvp in lsD)
                    {
                        try
                        {
                            doc.Variables.FormVariables.Item(kvp.Key).Value = kvp.Value.ToString(); //给参数传值
                            if (kvp.Key == "TR_SN")
                            {
                                String Tr_Sn_Prefix = kvp.Value.ToString().Substring(0, 6);
                                if (kvp.Value.ToString().Contains("X"))
                                {
                                    Tr_Sn_Prefix = kvp.Value.ToString().Substring(0, 7);
                                }
                                doc.Variables.FormVariables.Item("TR_SN_PREFIX").Value = Tr_Sn_Prefix;                                                                                           //TR_SN前缀
                                doc.Variables.Counters.Item("COUNT1").BaseType         = LabelManager2.enumCounterBase.lppxBaseDecimal;                                                          //修改公式为10进制
                                doc.Variables.Counters.Item("COUNT1").Value            = kvp.Value.ToString().Substring(Tr_Sn_Prefix.Length, kvp.Value.ToString().Length - Tr_Sn_Prefix.Length); //填充开始流水号
                                doc.Variables.Counters.Item("COUNT1").MaxValue         = "9999999";
                            }
                        }
                        catch (Exception ex)
                        {
                            SendMsg(mLogMsgType.Warning, string.Format("填充打印变量失败:{0}->{1},错误信息:", kvp.Key, kvp.Value.ToString()) + ex.Message);
                        }
                    }
                    doc.PrintDocument(1);
                }
                SendMsg(mLogMsgType.Incoming, string.Format("打印信息已输出,唯一条码[{0}]~~[{1}]", LsDic[0]["TR_SN"], LsDic[LsDic.Count - 1]["TR_SN"]));
            }
            catch (Exception ex)
            {
                SendMsg(mLogMsgType.Error, ex.Message);
            }
            finally
            {
                doc.Close();
                lbl.Quit();
            }
        }
Beispiel #2
0
        private void PrintLabel(string filepatch, List <Dictionary <string, object> > LsDic)
        {
            LabelManager2.ApplicationClass lbl = new LabelManager2.ApplicationClass();
            lbl.Documents.Open(filepatch, false);// 调用设计好的label文件
            Document doc = lbl.ActiveDocument;

            try
            {
                for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
                {
                    doc.Variables.FormVariables.Item(doc.Variables.FormVariables.Item(i + 1).Name).Value = "";
                }
                foreach (Dictionary <string, object> dic in LsDic)
                {
                    foreach (KeyValuePair <string, object> kvp in dic)
                    {
                        try
                        {
                            doc.Variables.FormVariables.Item(kvp.Key).Value = kvp.Value.ToString(); //给参数传值
                            if (kvp.Key == "TR_SN")
                            {
                                String Tr_Sn_Prefix = kvp.Value.ToString().Substring(0, 6);
                                if (kvp.Value.ToString().Contains("X"))
                                {
                                    Tr_Sn_Prefix = kvp.Value.ToString().Substring(0, 7);
                                }
                                doc.Variables.FormVariables.Item("TR_SN_PREFIX").Value = Tr_Sn_Prefix;                                                                                           //TR_SN前缀
                                doc.Variables.Counters.Item("COUNT1").BaseType         = LabelManager2.enumCounterBase.lppxBaseDecimal;                                                          //修改公式为10进制
                                doc.Variables.Counters.Item("COUNT1").Value            = kvp.Value.ToString().Substring(Tr_Sn_Prefix.Length, kvp.Value.ToString().Length - Tr_Sn_Prefix.Length); //填充开始流水号
                                doc.Variables.Counters.Item("COUNT1").MaxValue         = "9999999";
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(string.Format("填充打印变量失败:{0}->{1},错误信息:", kvp.Key, kvp.Value.ToString()) + ex.Message);
                        }
                    }
                    doc.PrintDocument(1);
                }
            }
            catch (Exception ex)
            {
                ShowHint(ex.Message, Color.Red);
            }
            finally
            {
                doc.Close();
                lbl.Quit();
            }
        }
Beispiel #3
0
        //打印
        private void button4_Click(object sender, EventArgs e)
        {
            this.dataGridView1.EndEdit();

            LabelManager2.ApplicationClass print = new LabelManager2.ApplicationClass();
            string path = System.Windows.Forms.Application.StartupPath + @"\WhCode.Lab";

            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                MessageBox.Show("先在系统设置中设置套版路径");
                return;
            }

            try
            {
                print.Documents.Open(path, false);
                print.Dialogs.Item(LabelManager2.enumDialogType.lppxPrinterSelectDialog).Show();

                Document doc = print.ActiveDocument;
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells["check"].Value != null && CommFun.Obj2Bool(row.Cells["check"].Value))//选中
                    {
                        doc.Variables.Item("Wh_No").Value   = CommFun.Obj2Str(row.Cells["wHNoDataGridViewTextBoxColumn"].Value);
                        doc.Variables.Item("Wh_Name").Value = CommFun.Obj2Str(row.Cells["wHNameDataGridViewTextBoxColumn"].Value);
                        doc.Variables.Item("Wh_Man").Value  = CommFun.Obj2Str(row.Cells["wHManDataGridViewTextBoxColumn"].Value);
                        doc.PrintLabel(1, 1, 1, 1, 0, "");
                    }
                }

                doc.FormFeed();
            }
            catch (Exception ex)
            {
                MessageBox.Show("打印失败:" + ex.Message);
            }
            finally
            {
                print.Quit();
                SetValue("");
            }
        }
Beispiel #4
0
        //用codesoft打印
        private void button1_Click_1(object sender, EventArgs e)
        {
            LabelManager2.ApplicationClass labApp = null;
            LabelManager2.Document         doc    = null;
            string labFileName = System.Windows.Forms.Application.StartupPath + @"\emp.Lab";

            try
            {
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("没有找到标签模版");
                    return;
                }
                labApp = new LabelManager2.ApplicationClass();
                labApp.Documents.Open(labFileName, false);    // 调用设计好的label文件
                doc = labApp.ActiveDocument;



                //下面这些是给模板的变量传值进去
                doc.Variables.FormVariables.Item("name").Value   = "zhangsan";
                doc.Variables.FormVariables.Item("card").Value   = "054545";
                doc.Variables.FormVariables.Item("class").Value  = "class121212";
                doc.Variables.FormVariables.Item("cardid").Value = "5454545";

                //下面这行是打印份数的定义
                doc.PrintDocument(1);
            }
            catch (Exception ex)
            {
                MessageBox.Show("出錯啦,原因如下:\n\r" + ex.Message, "出錯啦");
            }
            finally
            {
                labApp.Documents.CloseAll(true);
                labApp.Quit();    //退出
                labApp = null;
                doc    = null;
                GC.Collect(0);
            }
        }
Beispiel #5
0
        //打印
        private void button2_Click(object sender, EventArgs e)
        {
            DataGridViewRow dgvrow = dataGridView1.SelectedRows[0];
            string          cell0  = dgvrow.Cells[0].Value.ToString(); //物理卡号
            string          cell1  = dgvrow.Cells[1].Value.ToString(); //name
            string          cell2  = dgvrow.Cells[2].Value.ToString();
            string          cell3  = dgvrow.Cells[3].Value.ToString(); //class
            string          cell4  = dgvrow.Cells[4].Value.ToString();
            string          cell5  = dgvrow.Cells[5].Value.ToString(); //工卡
            string          cell6  = dgvrow.Cells[6].Value.ToString();
            string          cell7  = dgvrow.Cells[7].Value.ToString();

            /**
             * 串口打印
             * sp.Open();
             * jb = jb.Replace("NAME",cell1).Replace("CLASS",cell3).Replace("GONGKA",cell5).Replace("CARDID",cell0);
             * sp.Write(jb);
             * sp.Close();
             */

            /**
             *
             * 并口打印
             *
             * WriteLPT write = new WriteLPT();
             * write.OpenPort("LPT1", 9600, 0, 8, 1);
             * jb = jb.Replace("NAME", "NAME:"+cell1).Replace("CLASS", "CLASS:"+cell3).Replace("GONGKA", "GONGKA:"+cell5).Replace("CARDID", cell0);
             * write.WritePort(jb);
             * write.ClosePort();
             */

            LabelManager2.ApplicationClass labApp = null;
            LabelManager2.Document         doc    = null;
            string labFileName = System.Windows.Forms.Application.StartupPath + @"\emp2.Lab";

            //string labFileName =  @"d:\lab\emp2.Lab";

            try
            {
                if (!File.Exists(labFileName))
                {
                    MessageBox.Show("没有找到标签模版");
                    return;
                }
                labApp = new LabelManager2.ApplicationClass();
                labApp.Documents.Open(labFileName, false);// 调用设计好的label文件
                doc = labApp.ActiveDocument;



                //下面这些是给模板的变量传值进去
                doc.Variables.FormVariables.Item("Var0").Value = "姓名:" + cell1;
                doc.Variables.FormVariables.Item("Var1").Value = "工卡:" + cell5;
                doc.Variables.FormVariables.Item("Var2").Value = "班组:" + cell3;
                doc.Variables.FormVariables.Item("Var3").Value = cell0;



                //下面这行是打印份数的定义
                doc.PrintDocument(1);
            }
            catch (Exception ex)
            {
                MessageBox.Show("出錯啦,原因如下:\n\r" + ex.Message, "出錯啦");
            }
            finally
            {
                labApp.Documents.CloseAll(true);
                labApp.Quit();//退出
                labApp = null;
                doc    = null;
                GC.Collect(0);
            }

            PlayYesSound();
        }