//private string _strTemplet = @"<Shapes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><arrlistShapeEle/><BarcodePageSettings><arrModelShapes><string>方形</string><string>圆角矩形</string><string>椭圆形</string><string>CD</string></arrModelShapes><ModelShapes>圆角矩形</ModelShapes><BarcodePaperLayout><strError/><BarcodePaperSize><Height>1169</Height><PaperName>A4</PaperName><RawKind>9</RawKind><Width>827</Width></BarcodePaperSize><NumberOfLine>2</NumberOfLine><NumberOfColumn>2</NumberOfColumn><Top>2</Top><Left>2</Left><Right>2</Right><Bottom>2</Bottom><ModelWidth>102</ModelWidth><ModelHeight>146.5</ModelHeight><CustomModelSize>false</CustomModelSize><HorizontalInterval>2</HorizontalInterval><VerticalInterval>0</VerticalInterval><CornerRadius>2</CornerRadius><CustomDistance>true</CustomDistance></BarcodePaperLayout></BarcodePageSettings><arrlistKeyValue/><Zoom>0.97</Zoom></Shapes>"
        public FrmBarcodeEdit()
        {
            InitializeComponent();

            //新建的话也得有个打开啊。
            string strFileName = Application.StartupPath + "\\BarcodeModel\\templet.barcode";

            /**
            //如果不存在这个文件就新建一个,并且写入默认的
            if (!File.Exists(strFileName))
            {
                if (!Directory.Exists(Application.StartupPath + "\\BarcodeModel"))
                {
                    Directory.CreateDirectory(Application.StartupPath + "\\BarcodeModel");
                }
                using (Stream stream = new FileStream(strFileName, FileMode.Create))
                {
                    using (StreamWriter sw=new StreamWriter(stream))
                    {
                        //sw.Write(_strTemplet);
                    }
                }

            }
             * */

            if (File.Exists(strFileName))
            {
                userControlCanvas1.Loader(strFileName);

            }

            shapesFileData = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName);

            //我自己的初始化自己的初始化中有放大到屏幕,这个容易出问题。,所以如下两个是吧设置工具和画布大小的放在这里来。
            //myInit();
            //设置工具可以操作画布的。
            userControlToolBox1.setCanvas(userControlCanvas1);
            //设置画布的尺寸同布局大小
            canvasResie();

            ClsBarcodePrint c = new ClsBarcodePrint();//只是一个启动计时器的

            if (ClsBarcodePrint.strPrinterName == "")
            {
                ClsBarcodePrint.strPrinterName = c.myPrintDocument.PrinterSettings.PrinterName;//默认打印机
            }

            toolStripLabelPrintingName.Text = ClsBarcodePrint.strPrinterName;//默认打印机
        }
        //我用定时器来管理打印顺序,并且做出相应事件的。
        private static void timeCallBackPrintManaget(Object state)
        {
            //判断是否打印的依据是打印机为空闲,且队列不为空。且不能是正在打印,因为那个会引发冲突
             if (//(PrinterCheck.GetPrinterStatus(strPrinterName) == PrinterCheck.PrinterStatus.空闲)&&
                  (arrlistPrint.Count > 0) && (!isprintDocument_PrintPage))
             {
                 ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();

                 try
                 {
                     //获取第一项,并删除第一项。不清楚原因,但有时候会打印双份,我这里先清除在打印。
                     queuePrintItem qtm = (queuePrintItem)arrlistPrint[0];
                     arrlistPrint.RemoveAt(0);
                     myBarcodePrint.PrintBarcode(qtm);

                 }
                 catch (Exception ex)
                 {
                     ClsErrorFile.WriteLine(ex);
                     //Console.Error.WriteLine(ex.Message);
                 }

             }
        }
        private void printBarcode(int intPages)
        {
            ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();

            //如下的这个有些破坏了封装性,我用这个只是为了打印结束后判断是否自动打印。
            //myBarcodePrint.myPrintDocument.EndPrint += new PrintEventHandler(myPrintDocument_EndPrint);

            //如下如下是将变量深拷贝

            //如下这个只是复制一个值变量再传递
            ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝
            if (userControlCanvas1.myShapes.arrlistKeyValue != null)
            {
                foreach (clsKeyValue myKeyValue in userControlCanvas1.myShapes.arrlistKeyValue)
                {
                    clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value);
                    arrlist.Add(kv);
                }

            }

            //创建打印信息。
            queuePrintItem printDetails = new queuePrintItem();
            printDetails.strTableName = strTableName;
            printDetails.ShapesFileName = (shapesFileData).Value;
            printDetails.IsFull = chkIsFull.Checked;
            queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages();
            queuePrintItemRowAndPages1.arrlistRow = arrlist;
            queuePrintItemRowAndPages1.intPages = intPages;
            printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1);
            myBarcodePrint.addPrintDetails  (printDetails);
        }
        private void myInit()
        {
            //设置工具可以操作画布的。
            userControlToolBox1.setCanvas(userControlCanvas1);

            //设置画布的尺寸同布局大小
            canvasResie();

            userControlCanvas1.ZoomPaperToScreen();

            ClsBarcodePrint c = new ClsBarcodePrint();//只是一个启动计时器的

            if (ClsBarcodePrint.strPrinterName == "")
            {
                ClsBarcodePrint.strPrinterName = c.myPrintDocument.PrinterSettings.PrinterName;//默认打印机
            }

            toolStripLabelPrintingName.Text = ClsBarcodePrint.strPrinterName;//默认打印机
        }
Example #5
0
        void ClsBarcodePrint_barcodePrinted(object sender, ClsBarcodePrint.printedEventArgs e)
        {
            timer2.Enabled = true;//因为数据库有延迟,所以用这个定时器来延迟查询更新

            //row new NotImplementedException();
        }
        /// <summary>
        /// 测试打印
        /// </summary>
        private void TestPrint()
        {
            //如下这个只是复制一个值变量再传递
            ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝
            if (userControlCanvas1.myShapes.arrlistKeyValue != null)
            {
                foreach (clsKeyValue myKeyValue in userControlCanvas1.myShapes.arrlistKeyValue)
                {
                    clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value);
                    arrlist.Add(kv);
                }

            }

            userControlCanvas1.Saver(Application.StartupPath + "\\barcodeEditTestPrint.barcode");

            //测试的话只打印一页就可以了。
            ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();

            queuePrintItem printDetails = new queuePrintItem();
            printDetails.strTableName = "Test";
            printDetails.ShapesFileName = Application.StartupPath + "\\barcodeEditTestPrint.barcode";
            printDetails.IsFull = chkIsFull.Checked;
            queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages();
            queuePrintItemRowAndPages1.arrlistRow = arrlist;
            queuePrintItemRowAndPages1.intPages = 1;
            printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1);

            myBarcodePrint.addPrintDetails(printDetails);
        }
Example #7
0
        private void btnTestPrint_Click(object sender, EventArgs e)
        {
            try
            {
                //timer1.Enabled = false;//这个好像是没有必要

                ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝
                if (arrlistSellectRow != null)
                {
                    foreach (clsKeyValue myKeyValue in arrlistSellectRow)
                    {
                        clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value);
                        arrlist.Add(kv);
                    }
                }
                //测试的话只打印一页就可以了。
                ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();

                queuePrintItem printDetails = new queuePrintItem();
                printDetails.strTableName = strCurrentTableName;//当前表
                //如下是取得模板的路径
                string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value;

                //还得判断是否是相对路径,我的简单判断方法是是否有冒号":"
                if (strPathName.IndexOf(":") < 0)
                {
                    //还有得判断首字符是不是"\\",如果不是就加上
                    if (strPathName.Substring(0) == "\\")
                    {
                        strPathName = Application.StartupPath + strPathName;
                    }
                    else
                    {
                        strPathName = Application.StartupPath + "\\" + strPathName;
                    }
                }

                printDetails.ShapesFileName = strPathName;
                printDetails.IsFull = chkIsFull.Checked;
                queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages();
                queuePrintItemRowAndPages1.arrlistRow = arrlist;
                queuePrintItemRowAndPages1.intPages = 1;
                printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1);

                //queuePrintItem printDetails = new queuePrintItem("Test", ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value, arrlist, 1);
                // 添加到保存信息中。
                myBarcodePrint.addPrintDetails(printDetails);

            }
            catch (Exception ex)
            {
                ClsErrorFile.WriteLine("测试打印出现异常",ex);
                //throw;
            }
        }
Example #8
0
        /// <summary>
        /// 根据用户要求的的实际数量打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            int intPages = getCurrentPrintPages();//这个数量是钉死的

            if (chkIsMulti.Checked)
            {
                //创建打印信息。
                queuePrintItem printDetails = new queuePrintItem();
                printDetails.strTableName = strCurrentTableName;
                //如下是取得模板的路径
                string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value;
                //还得判断是否是相对路径,我的简单判断方法是是否有冒号":"
                if (strPathName.IndexOf(":") < 0)
                {
                    //还有得判断首字符是不是"\\",如果不是就加上
                    if (strPathName.Substring(0) == "\\")
                    {
                        strPathName = Application.StartupPath + strPathName;
                    }
                    else
                    {
                        strPathName = Application.StartupPath + "\\" + strPathName;
                    }
                }

                printDetails.ShapesFileName = strPathName;//设置目录

                printDetails.IsFull = chkIsFull.Checked;

                try
                {
                    //得根据选中的行迭代
                    if (dataGridView1.SelectedRows.Count>0)
                    {
                        foreach (DataGridViewRow item in dataGridView1.SelectedRows)
                        {
                            ArrayList arrlist = new ArrayList();

                            //如下是构造数据的
                            for (int i = 0; i < dataGridView1.ColumnCount; i++)
                            {
                                clsKeyValue keyvalue = new clsKeyValue(dataGridView1.Columns[i].Name, item.Cells[i].Value.ToString());
                                arrlist.Add(keyvalue);

                            }
                            //如下就是构造打印了。

                            queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages();
                            queuePrintItemRowAndPages1.arrlistRow = arrlist;
                            queuePrintItemRowAndPages1.intPages = intPages;
                            printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1);

                            //queuePrintItem printDetails = new queuePrintItem(strCurrentTableName, ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value, arrlist, intPages);

                        }

                    }
                    else
                    {

                        queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages();
                        queuePrintItemRowAndPages1.arrlistRow = null;
                        queuePrintItemRowAndPages1.intPages = intPages;
                        printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1);

                    }

                    ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();
                    myBarcodePrint.addPrintDetails(printDetails);

                }
                catch (System.Exception ex)
                {
                    ClsErrorFile.WriteLine(ex);
                }

            }
            else
            {

                //只有大于零才打印
                if (intPages > 0)
                {
                    printBarcode(intPages);

                }

            }

            /**如下的会产生问题,比如说在读取打印数量后已经抛出来一场,但结果还是打印了。
             *
            timer1.Enabled = false;
            int intPages = 0;

            try
            {
                if (txtCurrentPrintPage.Text != "")
                {
                    intPages = Convert.ToInt32(txtCurrentPrintPage.Text);
                    printBarcode(intPages);
                }
                else
                {

                    MessageBox.Show("请输入本次要打印的页数");
                    return;
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show("不能取得打印数量,原因是" + ex.Message);
            }
             * */
        }
Example #9
0
        /// <summary>
        /// 按损耗打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint2_Click(object sender, EventArgs e)
        {
            //如果是选择多行,每一项都得判断有多少数据的
            if (chkIsMulti.Checked)
            {
                try
                {
                    queuePrintItem printDetails = new queuePrintItem();
                    printDetails.strTableName = strCurrentTableName;
                    //如下是取得模板的路径
                    string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value;
                    //还得判断是否是相对路径,我的简单判断方法是是否有冒号":"
                    if (strPathName.IndexOf(":") < 0)
                    {
                        //还有得判断首字符是不是"\\",如果不是就加上
                        if (strPathName.Substring(0) == "\\")
                        {
                            strPathName = Application.StartupPath + strPathName;
                        }
                        else
                        {
                            strPathName = Application.StartupPath + "\\" + strPathName;
                        }
                    }

                    printDetails.ShapesFileName = strPathName;
                    printDetails.IsFull = chkIsFull.Checked;

                    //得根据选中的行迭代DataGridViewTextBoxCell
                    foreach (DataGridViewRow item in dataGridView1.SelectedRows)
                    {
                        ArrayList arrlist = new ArrayList();
                        int intPages = 0;//默认打印0页

                        //如下是构造数据的
                        for (int i = 0; i < dataGridView1.ColumnCount; i++)
                        {
                            clsKeyValue keyvalue = new clsKeyValue(dataGridView1.Columns[i].Name, item.Cells[i].Value.ToString());
                            arrlist.Add(keyvalue);

                            //判断哪个是数量
                            if (dataGridView1.Columns[i].Name == comboBoxQtyOfWantToPrinted.Text)
                            {
                                try
                                {
                                    intPages = Convert.ToInt32(item.Cells[i].Value.ToString());
                                }
                                catch (System.Exception ex)
                                {
                                    MessageBox.Show("读取不到数量,请在“要打印数量”后选择一项作为数量,这个是自动读取的,错误原因是:"+ex.Message);
                                    ClsErrorFile.WriteLine("读取不到数量,请在“要打印数量”后选择一项作为数量,这个是自动读取的,错误原因是:" + ex.Message);
                                    return;
                                }
                            }

                        }
                        //如下就是构造打印了。

                        //创建打印信息。

                        queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages();
                        queuePrintItemRowAndPages1.arrlistRow = arrlist;
                        queuePrintItemRowAndPages1.intPages = intPages;
                        printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1);

                    }

                    ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();
                    myBarcodePrint.addPrintDetails(printDetails);

                }
                catch (System.Exception ex)
                {
                    ClsErrorFile.WriteLine(ex);
                }
            }
            else
            {
                int intPages = getQtyOfWantToPrinted();//取得打印数量,加上损耗

                if (intPages > 0)
                {
                    timer1.Enabled = false;
                    printBarcode(intPages);
                }

            }

            /**
             * 如下的会产生问题,比如说在读取打印数量时已经跑出异常了,但是还是系统还是崩溃了,所以加上如上判断

            try
            {
                float fltSunHao = Convert.ToSingle(txtSunHao.Text)/100;
                int intPages = Convert.ToInt32(txtQtyOfWantToPrinted.Text);
                intPages += ((int)(intPages * fltSunHao));
                printBarcode(intPages);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
             * */
        }
Example #10
0
        private void printBarcode(int intPages)
        {
            ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();

            //如下的这个有些破坏了封装性,我用这个只是为了打印结束后判断是否自动打印。
            //myBarcodePrint.myPrintDocument.EndPrint += new PrintEventHandler(myPrintDocument_EndPrint);

            //如下是添加到打印队列
            ArrayList arrlist = new ArrayList();//用这个是因为 arrlistSellectRow 也是静态变量,读取的时候会读取到不是想要的值,这里用深拷贝
            if (arrlistSellectRow != null)
            {
                foreach (clsKeyValue myKeyValue in arrlistSellectRow)
                {
                    clsKeyValue kv = new clsKeyValue(myKeyValue.Key, myKeyValue.Value);
                    arrlist.Add(kv);
                }

            }

            //创建打印信息。
            queuePrintItem printDetails = new queuePrintItem();
            printDetails.strTableName = strCurrentTableName;
            //如下是取得模板的路径
            string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value;
            //还得判断是否是相对路径,我的简单判断方法是是否有冒号":"
            if (strPathName.IndexOf(":") < 0)
            {
                //还有得判断首字符是不是"\\",如果不是就加上
                if (strPathName.Substring(0) == "\\")
                {
                    strPathName = Application.StartupPath + strPathName;
                }
                else
                {
                    strPathName = Application.StartupPath + "\\" + strPathName;
                }
            }

            printDetails.ShapesFileName = strPathName;
            printDetails.IsFull = chkIsFull.Checked;
            queuePrintItemRowAndPages queuePrintItemRowAndPages1 = new queuePrintItemRowAndPages();
            queuePrintItemRowAndPages1.arrlistRow = arrlist;
            queuePrintItemRowAndPages1.intPages = intPages;
            printDetails.addQueuePrintItemRowAndPages(queuePrintItemRowAndPages1);

            //queuePrintItem printDetails = new queuePrintItem(strCurrentTableName, ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value, arrlist, intPages);
            myBarcodePrint.addPrintDetails(printDetails);
        }
Example #11
0
        private void comboBoxBarcodeModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxBarcodeModel.SelectedItem != null)
            {

                string strPathName = ((clsKeyValue)comboBoxBarcodeModel.SelectedItem).Value;
                //还得判断是否是相对路径,我的简单判断方法是是否有冒号":"
                if (strPathName.IndexOf(":") < 0)
                {
                    //还有得判断首字符是不是"\\",如果不是就加上
                    if (strPathName.Substring(0) == "\\")
                    {
                        strPathName = Application.StartupPath + strPathName;
                    }
                    else
                    {
                        strPathName = Application.StartupPath + "\\" + strPathName;
                    }
                }

                ClsBarcodePrint myBarcodePrint = new ClsBarcodePrint();

                //如下是画布设置
                userControlCanvas1.Loader(strPathName);

                //根据纸张的大小选择放大率
                //calculateCanvas();

                //userControlCanvas1.setArrKeyValue(arrlisttemp);

                userControlCanvas1.ZoomPaperToScreen();

                userControlCanvas1.Refresh();

                //picCanvas.Image = myBarcodePrint.xmlToBarcodeImage(clsBarcodePrint.populateVariable(xmlDoc, frmMain.arrlistSellectRow));
            }

            //dataGridViewChangedCell();
        }