Ejemplo n.º 1
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            LabelManager2.Application labelapp = null;
            LabelManager2.Document    labDoc   = null;
            string filePathName = System.Windows.Forms.Application.StartupPath + "\\Document1.lab";

            if (!File.Exists(filePathName))
            {
                MessageBox.Show("请准备好列印模板");
                return;
            }
            try
            {
                labelapp = new LabelManager2.Application();
                labelapp.Documents.Open(filePathName, false);                                                   //调用设计好的模板
                labDoc = labelapp.ActiveDocument;
                labDoc.Variables.FormVariables.Item("Date").Value = System.DateTime.Now.ToString("yyyy-MM-dd"); //往变量里面写入数据
                labDoc.PrintDocument(1);                                                                        //列印份数
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                labelapp.Documents.CloseAll(true);
                labelapp.Quit();
                labelapp = null;
                labDoc   = null;
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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("\"打印条码\"完成!");
        }
Ejemplo n.º 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();
        }