Esempio n. 1
0
    private static void CardJobWithStatus(
        BidiSplWrap bidiSpl,
        CommandLineOptions commandLineOptions,
        PrinterOptionsValues printerOptionsValues)
    {
        if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus)
        {
            throw new Exception(
                      commandLineOptions.printerName + " is not ready. status: " + printerOptionsValues._printerStatus);
        }

        int printerJobID = Util.StartJob(
            bidiSpl,
            string.Empty);  // hopperID

        string printerStatusXML = bidiSpl.GetPrinterData(strings.PRINTER_MESSAGES);
        PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);

        DisplayPrinterStatusValues(printerStatusValues);

        bidiSpl.SetPrinterData(strings.ENDJOB);

        Util.PollForJobCompletion(bidiSpl, printerJobID);
    }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            String printerName = comboBox1.Text;

            GetPrinterProperties(printerName);

            ///printing is activated here

            BidiSplWrap bidiSpl      = null;
            int         printerJobID = 0;

            try
            {
                bidiSpl = new BidiSplWrap();
                String BindResponse = bidiSpl.BindDevice(printerName);
                textBox2.Text += Environment.NewLine + BindResponse;
                string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION);
                textBox2.Text += Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine;

                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);


                if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus)
                {
                    throw new Exception(printerName + " is not ready. status: " + printerOptionsValues._printerStatus);
                }
                else
                {
                    string hopperID = string.Empty;

                    printerJobID = Util.StartJob(
                        bidiSpl,
                        false,
                        hopperID);

                    Application.DoEvents();

                    Util.PrintTextAndGraphics(bidiSpl, printerName, textBox1.Text);
                    Application.DoEvents();
                    if (0 != printerJobID)
                    {
                        // wait for the print spooling to finish and then issue an EndJob():
                        Util.WaitForWindowsJobID(bidiSpl, printerName);
                        bidiSpl.SetPrinterData(strings.ENDJOB);
                    }

                    Application.DoEvents();
                    Util.PollForJobCompletion(bidiSpl, printerJobID);
                }
            }
            catch (BidiException ee)
            {
                textBox2.Text += Environment.NewLine + ee.Message;
                Util.CancelJob(bidiSpl, ee.PrinterJobID, ee.ErrorCode);
            }
            catch (Exception ee)
            {
                textBox2.Text += Environment.NewLine + ee.Message;

                if (0 != printerJobID)
                {
                    Util.CancelJob(bidiSpl, printerJobID, 0);
                }
            }
            finally
            {
                bidiSpl.UnbindDevice();
            }
        }