Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
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);
            }
             * */
        }
Esempio n. 5
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;
            }
             * */
        }
Esempio n. 6
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);
        }