Exemple #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();
            }
        }
Exemple #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();
            }
        }
Exemple #3
0
        /// <summary>
        /// 打开模板文件
        /// </summary>
        /// <returns></returns>
        private void OpenLabFile()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title            = "选择模板文件";
            ofd.Filter           = "(*.lab)|*.lab";
            ofd.InitialDirectory = System.Windows.Forms.Application.StartupPath;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                this.lbi_path.Text = ofd.FileName;
                lbl     = new LabelManager2.ApplicationClass();
                mLibdoc = lbl.Documents.Open(ofd.FileName, false);
            }
            else
            {
                return;
            }
            return;
        }
Exemple #4
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("");
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
0
        public void myPrint(string strFile, DataTable dt)
        {
            for (int i = 1; i < dt.Rows.Count; i++)
            {
                //for (int j = 0; j < dt.Columns.Count; j++)

                //{
                string[] str;
                str = dt.Rows[i][4].ToString().Split(';');
                for (int j = 0; j < str.Length - 1; j++)
                {
                    //str[j] = str[j].Substring(str[j].IndexOf(':'), str[j].Length-1);
                    str[j] = str[j].Split(':')[1];
                }
                //}

                LabelManager2.ApplicationClass lbl = new LabelManager2.ApplicationClass();

                lbl.Documents.Open(strFile, false);//比较费时间
                LabelManager2.Document labeldoc = lbl.ActiveDocument;

                labeldoc.Variables.FormVariables.Item("变量2").Value = str[0];
                labeldoc.Variables.FormVariables.Item("变量3").Value = str[1];
                labeldoc.Variables.FormVariables.Item("变量4").Value = str[2];
                labeldoc.Variables.FormVariables.Item("变量5").Value = str[3];
                labeldoc.Variables.FormVariables.Item("变量6").Value = str[4];
                labeldoc.Variables.FormVariables.Item("变量7").Value = "";
                labeldoc.Variables.FormVariables.Item("变量8").Value = "";
                labeldoc.Variables.FormVariables.Item("变量9").Value = "";
                labeldoc.PrintDocument(); //打印一次

                labeldoc.FormFeed();
            }
            string sss = "";



            MessageBox.Show("\"打印条码\"完成!");
        }
Exemple #7
0
        public static IPrintHelperEx CreatePrintHelper(string printName, string printPort, string content)
        {
            IPrintHelperEx printHelper = null;
            //string strKey = printName + content;
            string strKey          = printName;
            string strTemplatePath = content.Replace("codesoft://", string.Empty);
            string path            = content.Replace("codesoft://", string.Empty);

            if (DicPrintDocuments.ContainsKey(strKey) == false)
            {
                LabelManager2.IApplication lbl = null;
                LabelManager2.IDocument    doc = null;
                try
                {
                    lbl = new LabelManager2.ApplicationClass();
                    if (doc == null)
                    {
                        if (Path.IsPathRooted(path) == false)
                        {
                            string directoryName = System.AppDomain.CurrentDomain.BaseDirectory;
                            path = Path.GetFullPath(Path.Combine(directoryName, path));
                        }
                        lbl.Documents.Open(path);
                        if (lbl == null)
                        {
                            throw new Exception(string.Format("打开模板文件({0})失败。", path));
                        }
                        doc = lbl.ActiveDocument;
                    }

                    if (doc == null)
                    {
                        throw new Exception(string.Format("打开模板文件({0})失败。", path));
                    }

                    string defaultPrinterName = doc.Printer.Name;
                    //defaultPrinterName = printName;

                    if (defaultPrinterName != printName && doc.Printer.SwitchTo(printName, printPort, false) == false)
                    {
                        LabelManager2.Strings vars = lbl.PrinterSystem().Printers(LabelManager2.enumKindOfPrinters.lppxAllPrinters);
                        string printerNames        = string.Empty;
                        for (int i = 1; i <= vars.Count; i++)
                        {
                            printerNames += vars.Item(i) + ";";
                        }
                        throw new Exception(string.Format("打印机({0})不存在。系统中存在的打印机列表 {1}。", printName, printerNames));
                    }

                    printHelper = new CodeSoftPrintHelperEx(strKey, doc, lbl);
                    printHelper.PrintTemplatePath = strTemplatePath;
                    if (doc != null)
                    {
                        lock (thisLock)
                        {
                            DicPrintDocuments.Add(strKey, printHelper);
                        }
                    }
                }
                finally
                {
                }
            }
            else
            {
                printHelper = DicPrintDocuments[strKey];
                if (printHelper.PrintTemplatePath != strTemplatePath)
                {
                    IDocument doc = printHelper.PrintApplication.Documents.Open(path);
                    printHelper.PrintDocument     = doc;
                    printHelper.PrintTemplatePath = strTemplatePath;
                    lock (thisLock)
                    {
                        DicPrintDocuments[strKey] = printHelper;
                    }
                }
            }
            return(printHelper);
        }
Exemple #8
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();
        }