예제 #1
0
 private void button5_Click(object sender, EventArgs e)
 {
     UploadInfo ui = new UploadInfo();
     ui.form1 = this;
     MessageBox.Show(ui.PrintAlert(500) + "");
 }
예제 #2
0
        private void DoWork()
        {
            try
            {
                printQueue pq = new printQueue();
                Dictionary<string, int> myprinter;
                string defaultPrinterName = Printer.GetDeaultPrinterName();
                //       MessageBox.Show(defaultPrinterName);

                if (pq.CanelAllPrintJob() == false)
                {
                    MyMsgBox mb = new MyMsgBox();
                    mb.ShowMsg("打印纸已用尽!暂停服务!", 3);
                    wait.CloseScrollBar();
                    return;
                }

                myprinter = pq.GetAllPrinterQueues();
                if (0 == myprinter[defaultPrinterName])
                {
                    if (!pd.PrinterSettings.IsValid)
                    {
                        MyMsgBox mb = new MyMsgBox();
                        mb.ShowMsg("打印机不可用!暂停服务!", 3);
                        wait.CloseScrollBar();
                        return;
                    }
                    pd.Print();
                    Application.DoEvents();
                    Thread.Sleep(500);
                    myprinter = pq.GetAllPrinterQueues();
                    if (myprinter[defaultPrinterName] == 0)
                    {
                        MyMsgBox mb = new MyMsgBox();
                        mb.ShowMsg("打印纸已用尽!暂停服务!", 3);
                        wait.CloseScrollBar();
                        return;
                    }

                    for (int i = 0; i <= 60; i += 1)
                    {
                        wait.SetProgressBarPositionP(i);//设置进度条当前位置
                        System.Threading.Thread.Sleep(100);//sleep一下减缓进度条进度,实际代码中,此处应该是实际的工作
                    }

                    myprinter = pq.GetAllPrinterQueues();
                    if (myprinter[defaultPrinterName] == 0)
                    {
                        string tempId = DateTime.Now.ToString("yyyyMMddHHmmss");
                        //   long tempId = DateTime.Now.Ticks;
                        if (MD5code == "")
                        {
                            MD5code = "00000000";
                        }
                        string strSql = "insert into t_bz_coupon_print values('" + tempId + "','" + GlobalVariables.LoginUserId + "','" + pi.id + "',#" + DateTime.Now.ToString("yyyy-M-d H:m:s") + "#,'" + MD5code + "')";
                        AccessCmd cmd = new AccessCmd();
                        //    MessageBox.Show(strSql);
                        cmd.ExecuteNonQuery(strSql);
                        strSql = "update t_bz_print_total set intPrintTotal=intPrintTotal+1";
                        cmd.ExecuteNonQuery(strSql);
                        strSql = "select * from t_bz_print_total";
                        OleDbDataReader reader = cmd.ExecuteReader(strSql);
                        int printNum = 0;
                        if (reader.Read())
                        {
                            printNum = reader.GetInt32(0);
                        }

                        if (printNum >= GlobalVariables.IntCouponPrint)
                        {
                            UploadInfo ui = new UploadInfo();
                            ui.PrintAlert(printNum);
                        }
                        reader.Close();
                        cmd.Close();

                        for (int i = 60; i <= 100; i += 1)
                        {
                            wait.SetProgressBarPositionP(i);//设置进度条当前位置
                            System.Threading.Thread.Sleep(50);//sleep一下减缓进度条进度,实际代码中,此处应该是实际的工作
                        }
                    }
                    else
                    {
                        MyMsgBox mb = new MyMsgBox();
                        mb.ShowMsg("打印纸已用尽!暂停服务!", 3);
                        wait.CloseScrollBar();
                        return;
                    }
                }
                else
                {
                    MyMsgBox mb = new MyMsgBox();
                    mb.ShowMsg("打印纸已用尽!暂停服务!", 3);
                    wait.CloseScrollBar();
                    return;
                }
            }
            catch (Exception e)
            {
                ErrorLog.log(e);
                wait.CloseScrollBar();
                return;
            }
        }