Exemple #1
0
 private void DisconnectFromPrinter(ref ZXPSampleCode z, ref Job job)
 {
     try
     {
         z.Disconnect(ref job);
     }
     catch (Exception ex)
     {
         MessageBox.Show("DisconnectFromPrinter threw exception: " + ex.Message);
     }
 }
Exemple #2
0
        private void btnConnectToPrinter_Click(object sender, EventArgs e)
        {
            ZXPSampleCode z   = null;
            Job           job = null;

            try
            {
                Cursor = Cursors.WaitCursor;

                lbStatus.Visible = true;
                lbStatus.Text    = "Connecting to printer";
                lbSamples.Items.Clear();
                Refresh();
                Application.DoEvents();

                job = new Job();

                z = new ZXPSampleCode(this.cboPrn.Text);

                if (z.Connect(ref job))
                {
                    // Loads list box with samples
                    for (int i = 0; i < _lbSamples.Length; i++)
                    {
                        this.lbSamples.Items.Add(_lbSamples[i]);
                    }

                    this.lbSamples.Text = _lbSamples[0];

                    // Displays versions

                    this.lblVersions.Text = z.GetVersions();

                    if (!z.IsZXP7)
                    {
                        // Loads card types based on type of sample type
                        _cardTypeList = new ArrayList();

                        CardTypesInit(ref z, this.cboPrn.Text);

                        cboCardTypeInit(SAMPLE_TYPE.PRINTING);
                    }
                    else
                    {
                        cboCardType.Enabled = false;
                    }

                    Text = "ZXP Sample Code " + ProductVersion;
                }
                else
                {
                    MessageBox.Show("Could not open connection to printer " + cboPrn.Text, "Warning");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("btnConnectToPrinter_Click exception: " + ex.Message);
            }
            finally
            {
                if (z != null)
                {
                    z.Disconnect(ref job);
                }
                z = null;
                lbStatus.Visible = false;
                Cursor           = Cursors.Default;
            }
        }
        // Starts the printing process
        // --------------------------------------------------------------------------------------------------

        private void btnRun_Click(object sender, EventArgs e)
        {
            Job           job = null;
            ZXPSampleCode z   = null;

            int   actionID = 0;
            short alarm    = 0;

            string msg    = string.Empty;
            string status = string.Empty;

            // Ensures that count is a number
            if (!IsInteger(this.tbCount.Text))
            {
                MessageBox.Show("Count is not an integer value");
                this.tbCount.Focus();
                return;
            }

            try
            {
                job = new Job();
                z   = new ZXPSampleCode(_deviceName);

                // Opens a connection with a ZXP printer

                z.Connect(ref job);

                _isZXP7 = z.IsZXP7;

                // Sets the card source and destination
                job.JobControl.FeederSource = FeederSourceEnum.CardFeeder;
                job.JobControl.Destination  = DestinationTypeEnum.Eject;

                int count = Convert.ToInt16(this.tbCount.Text);

                this.tbResults.AppendText(DisplayTime() + ": Start\r\n");

                if (!BuildBitmaps())
                {
                    MessageBox.Show("Unable to build bitmaps");
                    this.Close();
                }

                // Prints (count) number of cards
                for (int cardCount = 1; cardCount <= count;)
                {
                    // Checks to see if the printer is in alarm condition

                    alarm = GetAlarm(ref job, out msg);

                    if (!string.IsNullOrEmpty(msg))
                    {
                        this.tbResults.AppendText(DisplayTime() + ": " + cardCount.ToString() + ": " + msg);
                    }

                    // If the printer is not in alarm condition
                    //     starts a print job and increments cardCount

                    if (alarm == 0)
                    {
                        // Sets the card type
                        if (!_isZXP7)
                        {
                            job.JobControl.CardType = _cardType;
                        }

                        // Builds and prints the graphic layers

                        job.BuildGraphicsLayers(SideEnum.Front, PrintTypeEnum.Color, 0, 0, 0,
                                                -1, GraphicTypeEnum.BMP, _bmpFront);

                        job.BuildGraphicsLayers(SideEnum.Back, PrintTypeEnum.MonoK, 0, 0, 0,
                                                -1, GraphicTypeEnum.BMP, _bmpBack);

                        job.PrintGraphicsLayers(1, out actionID);

                        this.tbResults.AppendText(DisplayTime() + ": " + cardCount.ToString() +
                                                  ": Print Job Processed with no Errors\r\n");

                        // Waits for the job status
                        //     "cleaning_up" or "done_ok" or is in error state

                        z.JobWait(ref job, actionID, 180, out status);

                        this.tbResults.AppendText(DisplayTime() + ": " + cardCount.ToString() +
                                                  ": Job Wait Status = " + status + "\r\n");

                        cardCount++;
                    }
                }

                // Make sure the last job is truly finished

                while (true)
                {
                    z.JobWait(ref job, actionID, 180, out status);

                    if (status == "done_ok" || status.Contains("error"))
                    {
                        break;
                    }
                }
                this.tbResults.AppendText(DisplayTime() + ": Finished\r\n");
            }
            catch (Exception exc)
            {
                this.tbResults.AppendText("Exception: " + exc.Message);
            }
            finally
            {
                z.Disconnect(ref job);
                z = null;
            }
        }