在ReportViewer的情况下检查打印机状态

时间:2016-02-18 07:33:25

标签: c# printing reportviewer status

我有一个问题,希望大家帮忙。

我在reportViewer的事件打印中编写代码打印,但不检查状态打印。

示例:如果打印机关闭,单击按钮打印并选择打印机,然后单击确定。虽然确切地知道打印机已关闭,但仍会发送打印作业但仍处于待处理状态..

我不知道在reportview事件中编写代码的内容是为了能够在打印前检查打印机的状态。

希望大家指导。 这是代码

    private void rptInHoaDon_Print(object sender, Microsoft.Reporting.WinForms.ReportPrintEventArgs e)
    {
        ManagementScope scope = new ManagementScope(@"\root\cimv2");
        scope.Connect();

        string printerName = "";
        // Choose Printers from WMI Object Collections
        string query = string.Format("SELECT * FROM Win32_Printer ");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

        //ManagementObjectCollection coll = searcher.Get();
        foreach (ManagementObject printer in searcher.Get())
        {
            printerName = printer["Name"].ToString().ToLower();
            if (printerName.Equals(@"OOTOYA"))
            {
                //MessageBox.Show("Printer = " + printer["Name"]+" - " + printer["WorkOffline"]);
                if (printer["WorkOffline"].ToString().ToLower().Equals("false"))
                {
                    try
                    {
                        List<PrintSystemJobInfo> jobInfos = new List<PrintSystemJobInfo>();
                        LocalPrintServer server = new LocalPrintServer();
                        while (true)
                        {
                            foreach (var jobInfo in server.DefaultPrintQueue.GetPrintJobInfoCollection())
                            {
                                SpotTroubleUsingJobAttributes(jobInfo);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show( ex.ToString());
                    }
                }
                else
                {
                    MessageBox.Show("The printer is turned off");
                    //job.Dispose();
                }
            }
        }
    }

列出项目

0 个答案:

没有答案