Пример #1
0
        //如下的方法也准备注释掉,因为不需要了。
        /**
        public  Bitmap xmlToBarcodeImage(XmlDocument xmlBarcodeModel)
        {
            //首先取得纸张的尺寸和DPI
            //再根据纸张尺寸画画布
            //在读取xml模板内容画图
            //最后返回画布就可以了

            //double dwPaparWidth = 40, fltPaperHeight = 40;//默认纸张大小
            //取得纸张尺寸如下

            XmlElement myXmlEleRoot = xmlBarcodeModel.DocumentElement;
            foreach (XmlNode myxmlNode in myXmlEleRoot.ChildNodes)
            {
                string strNodeName = myxmlNode.Name.ToLower();
                switch (strNodeName)
                {

                    case ("paper"):
                        XmlElement xmltemp = (XmlElement)myxmlNode;//用这个转换只是因为xmlNode没有GetAttribute
                       // fltPaperWidth = strAttributeValueToFloat(xmltemp,"PaperWidth");
                        //fltPaperHeight = strAttributeValueToFloat(xmltemp,"PaperHeight");

                        break;
                }
            }

            //建立画布部分

            int iW=(int)(fltPaperWidth*fltDPIX/25.4);
            int iH=(int)(fltPaperHeight*fltDPIY/25.4);
            Bitmap imageCanvas = new Bitmap(iW,iH);
            imageCanvas.SetResolution(fltDPIX, fltDPIY);

            Graphics g = Graphics.FromImage(imageCanvas);
            g.PageUnit = GraphicsUnit.Millimeter;

            //如下被认为可以清晰文字。
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;

            g.Clear(Color.White);

            //如下就是在这个画布上绘图了

            foreach (XmlNode myxmlNode in myXmlEleRoot.ChildNodes)
            {
                string strNodeName = myxmlNode.Name.ToLower();
                switch (strNodeName)
                {
                    case "shapes":

                        //如下是循环把形状的属性
                        #region

                        //如下是循环把形状的属性
                        foreach (XmlElement xmlElementShapes in myxmlNode.ChildNodes)
                        {
                            string strShapesName = xmlElementShapes.Name.ToLower();
                            FontStyle myFontStyle;
                            Font font1;
                            float   fX, fY  ,fWidth ,fHeight ;
                            SolidBrush drawBrush;
                            PointF poingStr;

                            switch (strShapesName)
                            {

                                case "statictext":
                                    //首先建立一个静态文本属性对性
                                    #region

                                    //字体风格,加粗倾斜下划线
                                    myFontStyle = new FontStyle();

                                    if (xmlElementShapes.GetAttribute("isBold").ToLower() == "true")
                                    {
                                        myFontStyle = myFontStyle | FontStyle.Bold;

                                    }
                                    if (xmlElementShapes.GetAttribute("isItalic").ToLower() == "true")
                                    {
                                        myFontStyle = myFontStyle | FontStyle.Italic;
                                    }
                                    if (xmlElementShapes.GetAttribute("isUnderLine").ToLower() == "true")
                                    {
                                        myFontStyle = myFontStyle | FontStyle.Underline;
                                    }

                                     font1 = new Font(xmlElementShapes.GetAttribute("FontName"), Convert.ToSingle(xmlElementShapes.GetAttribute("FontSize")),myFontStyle);

                                    //这样字体就读取好了,接下来读取位置。
                                     fX = strAttributeValueToFloat(xmlElementShapes,"X");
                                     fY = strAttributeValueToFloat(xmlElementShapes,"Y") ;
                                     poingStr = new PointF(fX, fY);
                                     drawBrush = new SolidBrush(Color.Black);

                                    g.DrawString(xmlElementShapes.InnerText, font1, drawBrush, poingStr);
                                    drawBrush.Dispose();
                                    font1.Dispose();

                                    break;

                                    #endregion
                                //如下是设置变量文字
                                case "variabletext":
                                    #region
                                    //变量字体跟静态字体没有什么本质区别,唯一的区别是加了后缀

                                    //字体风格,加粗倾斜下划线
                                    myFontStyle = new FontStyle();

                                    if (xmlElementShapes.GetAttribute("isBold").ToLower() == "true")
                                    {
                                        myFontStyle = myFontStyle | FontStyle.Bold;

                                    }
                                    if (xmlElementShapes.GetAttribute("isItalic").ToLower() == "true")
                                    {
                                        myFontStyle = myFontStyle | FontStyle.Italic;
                                    }
                                    if (xmlElementShapes.GetAttribute("isUnderLine").ToLower() == "true")
                                    {
                                        myFontStyle = myFontStyle | FontStyle.Underline;
                                    }

                                     font1 = new Font(xmlElementShapes.GetAttribute("FontName"), Convert.ToSingle(xmlElementShapes.GetAttribute("FontSize")), myFontStyle);

                                    //这样字体就读取好了,接下来读取位置。
                                     fX = strAttributeValueToFloat(xmlElementShapes,"X");
                                     fY = strAttributeValueToFloat(xmlElementShapes,"Y");
                                     poingStr = new PointF(fX, fY);
                                     drawBrush = new SolidBrush(Color.Black);
                                     string strSuffix = xmlElementShapes.GetAttribute("suffix");

                                    g.DrawString(xmlElementShapes.InnerText+strSuffix, font1, drawBrush, poingStr);
                                    drawBrush.Dispose();

                                    break;
                                    #endregion

                                //如下是条形码
                                case "barcode":
                                    #region

                                    //条形码可能有异常,比如说位数不符等等
                                    try
                                    {

        ;
                                        string  strEncoding = xmlElementShapes.GetAttribute("Encoding");
                                        BarcodeLib.TYPE myType =BarcodeLib.TYPE.EAN13;
                                        switch (strEncoding)
                                        {
                                            case "EAN13":
                                                myType = BarcodeLib.TYPE.EAN13;
                                                break;
                                            case "EAN8":
                                                myType = BarcodeLib.TYPE.EAN8;
                                                break;
                                            case "FIM":
                                                myType = BarcodeLib.TYPE.FIM;
                                                break;
                                            case "Codabar":
                                                myType = BarcodeLib.TYPE.Codabar;
                                                break;
                                            case "UPCA":
                                                myType = BarcodeLib.TYPE.UPCA;
                                                break;
                                            case "UPCE":
                                                myType = BarcodeLib.TYPE.UPCE;
                                                break;
                                            case "UPC_SUPPLEMENTAL_2DIGIT":
                                                myType = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_2DIGIT;
                                                break;
                                            case "UPC_SUPPLEMENTAL_5DIGIT":
                                                myType = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_5DIGIT;
                                                break;
                                            case "CODE39":
                                                myType = BarcodeLib.TYPE.CODE39;
                                                break;
                                            case "CODE39Extended":
                                                myType = BarcodeLib.TYPE.CODE39Extended;
                                                break;
                                            case "CODE128":
                                                myType = BarcodeLib.TYPE.CODE128;
                                                break;
                                            case "CODE128A":
                                                myType = BarcodeLib.TYPE.CODE128A;
                                                break;
                                            case "CODE128B":
                                                myType = BarcodeLib.TYPE.CODE128B;
                                                break;
                                            case "CODE128C":
                                                myType = BarcodeLib.TYPE.CODE128C;
                                                break;
                                            case "ISBN":
                                                myType = BarcodeLib.TYPE.ISBN;
                                                break;
                                            case "Interleaved2of5":
                                                myType = BarcodeLib.TYPE.Interleaved2of5;
                                                break;
                                            case "Standard2of5":
                                                myType = BarcodeLib.TYPE.Standard2of5;
                                                break;
                                            case "Industrial2of5":
                                                myType = BarcodeLib.TYPE.Industrial2of5;
                                                break;
                                            case "PostNet":
                                                myType = BarcodeLib.TYPE.PostNet;
                                                break;
                                            case "BOOKLAND":
                                                myType = BarcodeLib.TYPE.BOOKLAND;
                                                break;
                                            case "JAN13":
                                                myType = BarcodeLib.TYPE.JAN13;
                                                break;
                                            case "MSI_Mod10":
                                                myType = BarcodeLib.TYPE.MSI_Mod10;
                                                break;
                                            case "MSI_2Mod10":
                                                myType = BarcodeLib.TYPE.MSI_2Mod10;
                                                break;
                                            case "MSI_Mod11":
                                                myType = BarcodeLib.TYPE.MSI_Mod11;
                                                break;
                                            case "MSI_Mod11_Mod10":
                                                myType = BarcodeLib.TYPE.MSI_Mod11_Mod10;
                                                break;
                                            case "Modified_Plessey":
                                                myType = BarcodeLib.TYPE.Modified_Plessey;
                                                break;
                                            case "CODE11":
                                                myType = BarcodeLib.TYPE.CODE11;
                                                break;
                                            case "USD8":
                                                myType = BarcodeLib.TYPE.USD8;
                                                break;
                                            case "UCC12":
                                                myType = BarcodeLib.TYPE.UCC12;
                                                break;
                                            case "UCC13":
                                                myType = BarcodeLib.TYPE.UCC13;
                                                break;
                                            case "LOGMARS":
                                                myType = BarcodeLib.TYPE.LOGMARS;
                                                break;
                                            case "ITF14":
                                                myType = BarcodeLib.TYPE.ITF14;
                                                break;
                                            case "TELEPEN":
                                                myType = BarcodeLib.TYPE.TELEPEN;
                                                break;

                                        }

                                        BarcodeLib.Barcode bar = new BarcodeLib.Barcode();
                                        fX = strAttributeValueToFloat(xmlElementShapes,"X");
                                        fY = strAttributeValueToFloat(xmlElementShapes,"Y") ;
                                        poingStr = new PointF(fX, fY);
                                        fWidth = strAttributeValueToFloat(xmlElementShapes,"Width") ;
                                        fHeight = strAttributeValueToFloat(xmlElementShapes,"Height");
                                        bar.IncludeLabel = false; ;
                                        if (xmlElementShapes.GetAttribute("isIncludeLabel").ToLower() == "true")
                                        {
                                             bar.IncludeLabel = true;
                                        }

                                        int intBarCodeWidth = (int)(fWidth * g.DpiX / 25.4);
                                        int intBarCodeHeight = (int)(fHeight * g.DpiY / 25.4);

                                        Image myImage = bar.Encode(myType, xmlElementShapes.InnerText, intBarCodeWidth, intBarCodeHeight,g.DpiX,g.DpiY);
                                        g.DrawImage(myImage, poingStr);
                                        bar.Dispose();

                                    }
                                    catch (Exception e)
                                    {
                                        MessageBox.Show(e.Message);
                                    }

                                    #endregion
                                    break;
                                //如下设置其他形状

                            }
                        }
                        break;

                        #endregion

                }
            }

            //如下是如果没有注册,在左上角写上文字" BarcodeTerminator"
            if (!isZhuCe)
            {
                g.DrawString(" BarcodeTerminator", new Font("Arial", 6), new SolidBrush(Color.Black), new Point(0, 0));

            }

            return imageCanvas;

        }
         * */
        /**

        //变量替换,测试成功
        public static XmlDocument populateVariable(XmlDocument xmlDoc)
        {
            //用xpath搜索的方法来替换。
            XmlDocument myxml = xmlDoc;//赋值而已
            foreach (clsKeyValue keyvalue in frmMain.arrlistSellectRow)
            {
                XmlNodeList nodeList1 = myxml.SelectNodes("//VariableText[@variableName='" + keyvalue.Key + "']");

                foreach (XmlNode myXmlNode in nodeList1)
                {
                    myXmlNode.InnerText = keyvalue.Value;
                }
                XmlNodeList nodeList2 = myxml.SelectNodes("//Barcode[@variableName='" + keyvalue.Key + "']");

                foreach (XmlNode myXmlNode in nodeList2)
                {
                    myXmlNode.InnerText = keyvalue.Value;
                }
            }

            return myxml;

        }
         *
         * */
        private void PrintBarcode(queuePrintItem printDetails)
        {
            //首先判断是否是充满
            if (printDetails.IsFull)
            {
                //如下就是充满
                //项的情况,所以要判断
                //当个数大于0且不是正在打印中的时候才能打印
                while ((printDetails.IntCount > 0))
                {
                    //如下的才能打印
                    if (!isprintDocument_PrintPage)
                    {
                        ArrayList arrlist = ((queuePrintItemRowAndPages)printDetails.arrlistqueuePrintItemRowAndPages[0]).arrlistRow;
                        int intP = ((queuePrintItemRowAndPages)printDetails.arrlistqueuePrintItemRowAndPages[0]).intPages;
                        int i = PrintBarcode(printDetails.ShapesFileName, arrlist, intP);

                        if (i > 0)
                        {
                            //到这一步就保存打印记录了
                            //记录打印。
                            ClsDataBase myClsDataBase = new ClsDataBase();
                            myClsDataBase.commandAddPrintedRecord(printDetails.strTableName, arrlist, i);

                            OnBarcodePrinted(new printedEventArgs());//发出打印消息
                        }

                        printDetails.arrlistqueuePrintItemRowAndPages.RemoveAt(0);//删除第一项因为已经打印了
                    }

                }

            }
            else
            {
                //到这里就是非充满打印,跟充满打印不同的地方在于这个是一张一张往上打印的
                PrintBarcode2(printDetails);

            }
        }
Пример #2
0
        /// <summary>
        /// 这个方法是充满打印
        /// </summary>
        /// <param name="printDetails"></param>
        private void PrintBarcode2(queuePrintItem printDetails)
        {
            //深度拷贝,因为在打印事件中需要调用这个方法
            currentQueueItem = ClsXmlSerialization.DeepCopy<queuePrintItem>(printDetails);

            Shapes myShapes;
            //首先也是取得纸张的行数和列数
            try
            {
                myShapes = ClsXmlSerialization.Load<Shapes>(currentQueueItem.ShapesFileName);
            }
            catch (System.Exception ex)
            {
                return;//如果不能取得,那么就直接返回

            }

            int intNumOfLine = myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfLine;
            int intNumOfColumn = myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfColumn;

            while ((currentQueueItem.IntCount > 0))
            {
                //如下的才能打印
                if (!isprintDocument_PrintPage)
                {
                    //如下的就是具体构造每一个printDocument了
                    myPrintDocument = new PrintDocument();
                    myPrintDocument.DefaultPageSettings.Landscape = myShapes.BarcodePageSettings.BarcodePaperLayout.LandScape;//设置是否横向
                    int intP = ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages;
                    //设置多少张纸,这个打印份数只是一个数据的,因为如果第一个没有充满纸张,那么就没必要多份了。
                    intPrintPage = (int)(intP / (intNumOfLine * intNumOfColumn));
                    if (intPrintPage == 0)//有时候会出现不足一张的情况
                        intPrintPage = 1;

                    //根据纸张的连续等问题
                    //设置打印机
                    if (strPrinterName != "")
                    {
                        myPrintDocument.PrinterSettings.PrinterName = strPrinterName;
                    }

                    myPrintDocument.PrintController = new StandardPrintController();//这个据说可以不显示那个打印进度对框框
                    myPrintDocument.DocumentName = "打印条形码";//设置完后可在打印对话框及队列中显示(默认显示document)
                    //打印输出(过程)
                    myPrintDocument.PrintPage += new PrintPageEventHandler(myPrintDocument_PrintPage);

                    myPrintDocument.OriginAtMargins = false;//从位于可打印区域的左上角打印
                    //必须得设置自定义纸张,要不然会存在顶点问题,比如说有些条形啊打印机的打印宽度为4英寸,而实际纸张宽度不是4英寸,就会存在打印时候顶点是打印机的顶点,而不是实际纸张的顶点。
                    myPrintDocument.DefaultPageSettings.PaperSize = myShapes.BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize;//设置纸张
                    //如下是设置边距
                    /**如下的经测试会产生不可预测的偏移
                    myPrintDocument.DefaultPageSettings.Margins.Top = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Top / 0.254);
                    myPrintDocument.DefaultPageSettings.Margins.Bottom = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Bottom / 0.254);
                    myPrintDocument.DefaultPageSettings.Margins.Left = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Left / 0.254);
                    myPrintDocument.DefaultPageSettings.Margins.Right = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Right / 0.254);

                     * */
                    //每次打印
                    myPrintDocument.PrinterSettings.Copies = (short)intPrintPage;//首先就是一次性全部打印完毕,设置份数就是页数.
                    if (myPrintDocument.PrinterSettings.MaximumCopies < intPrintPage)//如果最高能打印的份数比要打印的页数少,就按照最高能打印的份数.
                        myPrintDocument.PrinterSettings.Copies = (short)myPrintDocument.PrinterSettings.MaximumCopies;

                    //如果能多份打印,就需要提前删掉那些,比如说要打印5个,每张纸可以打印2个,那么这里第一次的份数就是2,但是在打印进程中只会减少2个,会造成重复打印
                    ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages = ((queuePrintItemRowAndPages)currentQueueItem.arrlistqueuePrintItemRowAndPages[0]).intPages - (myPrintDocument.PrinterSettings.Copies - 1) * (intNumOfLine * intNumOfColumn);

                    try
                    {
                        isprintDocument_PrintPage = true;
                        myPrintDocument.Print();
                        //这里发出打印消息。
                        //isprintDocument_PrintPage = true;// 因为上一个打印进程也需要时间,所以这里先设置了。
                        myPrintDocument.Dispose();//释放

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("没有打印成功,原因:" + ex.Message);
                        isprintDocument_PrintPage = false;
                        return;
                    }

                }
            }

            //保存打印记录,这里用比较省事的方法
            ClsDataBase myClsDataBase = new ClsDataBase();
            foreach (queuePrintItemRowAndPages item in printDetails.arrlistqueuePrintItemRowAndPages)
            {
                myClsDataBase.commandAddPrintedRecord(printDetails.strTableName, item.arrlistRow, item.intPages);
                OnBarcodePrinted(new printedEventArgs());//发出打印消息

            }
        }
Пример #3
0
        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);
        }
Пример #4
0
 public void addPrintDetails(queuePrintItem printDetails)
 {
     arrlistPrint.Add(printDetails);
 }
Пример #5
0
        /// <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);
        }
Пример #6
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;
            }
        }
Пример #7
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);
            }
             * */
        }
Пример #8
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;
            }
             * */
        }
Пример #9
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);
        }