Esempio n. 1
0
        /**************************************************************************************************
         * Function Name: EjectCard
         *
         * Purpose: Orders printer to remove card from printer.
         *
         * Parameters: None
         *
         * Returns:  None
         *
         * History:
         * Date             Who             Comment
         * 12/9/2010        ACT             Function creation.
         ***************************************************************************************************/
        private void EjectCard()
        {
            try
            {
                int err = 0;

                _thePrinterSDK.EjectCard(out err);
                if (err > 0)
                {
                    MessageBox.Show("EjectCard failed: Error code = " + Convert.ToString(err));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "EjectCard exception");
            }
        }
        // Submit Button
        //     Starts the example code based on Form selections ---------------------------------------------

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            #region Variables

            bool   eject = false;
            string msg   = "";

            SampleCodeMag      mag = null;
            SampleCodeGraphics prn = null;

            #endregion

            #region Check Selections

            // Verifies that a printer has been selected
            try
            {
                if (cboPrn.SelectedIndex < 0)
                {
                    msg = "Error: A Printer has not been selected";
                    return;
                }

                // Verifies that at least one selection is made
                if (!this.cbBack.Checked && !this.cbFront.Checked && !this.cbMag.Checked)
                {
                    msg = "Error: No Selections";
                    return;
                }

                #endregion


                #region Magnetic Encoding

                if (cbMag.Checked)
                {
                    // the eject variable is set to true if neither Front or Back is selected

                    eject = (!this.cbBack.Checked && !this.cbFront.Checked);

                    // Encodes and Verifies all three Tracks

                    mag = new SampleCodeMag();
                    mag.PerformMagneticEncodeJob(this.cboPrn.Text, out msg);
                    if (msg != "")
                    {
                        return;
                    }
                    this.lblStatus.Text = "Magnetic Encoding : No Errors";
                }

                // If only magnetic encoding, eject the card
                if (!this.cbFront.Checked && !this.cbBack.Checked)
                {
                    int errValue = 0;

                    if (!RefreshConnectionToPrinter())
                    {
                        return;
                    }
                    int result = _thePrinterSDK.EjectCard(out errValue);
                    if (!CloseConnectionToPrinter())
                    {
                        return;
                    }

                    if ((result != 1) && (errValue != 0))
                    {
                        this.lblStatus.Text = "EjectCard failed. Error = " + Convert.ToString(errValue);
                    }
                }

                #endregion

                #region Printing

                else
                {
                    // Initialize the Print Side Class

                    prn = new SampleCodeGraphics();

                    // Determines the printing type

                    if (this.cbFront.Checked && !this.cbBack.Checked)
                    {
                        prn.PrintFrontSideOnly(this.cboPrn.Text, "Front Side Text", Application.StartupPath, out msg);
                        if (msg == "")
                        {
                            this.lblStatus.Text = "No Errors : Front Side Only Printing";
                        }
                    }
                    else if (this.cbFront.Checked && this.cbBack.Checked)
                    {
                        prn.PrintBothSides(this.cboPrn.Text, "Front Side Text", "Back Side Text", Application.StartupPath, out msg);
                        if (msg == "")
                        {
                            this.lblStatus.Text = "No Errors : Both Side Printing";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                MessageBox.Show(ex.ToString(), "btnSubmit_Click threw exception");
            }
            finally
            {
                if (msg != "")
                {
                    this.lblStatus.Text = msg;
                }

                mag = null;
                prn = null;
            }

            #endregion
        }
Esempio n. 3
0
        // CONTACT Sample Code ----------------------------------------------------------------------------------

        public void ContactEncode(string drvName, string _contactReader, int eject, out string msg)
        {
            ZBRPrinter printer  = null;
            int        errValue = 0;

            msg = "";
            try
            {
                printer = new ZBRPrinter();

                // Opens a connection to a printer driver
                if (!printer.Open(drvName, out msg))
                {
                    msg = "CONTACT Open Error: " + ZBRUtil.TranslateErrorCode(errValue) + "\n" + "Error Code : " + errValue.ToString();
                    return;
                }

                // Moves the card into position for encoding
                if (printer.MoveCardToSmartCardEncoder(CONTACT, out errValue) == 0)
                {
                    msg = "CONTACT StartCard Error:" + ZBRUtil.TranslateErrorCode(errValue) + "\n" + "Error Code : " + errValue.ToString();
                    return;
                }

                byte[] key = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };


                //perform the smart card encoding:
                ContactSupport contact  = new ContactSupport();
                string         cardType = "PVC,SLE4428";
                contact.ContactTest(ref cardType, _contactReader, key, true, out msg);

                if (msg.Length > 0)
                {
                    return;
                }

                if (printer.MoveSmartCardToPrintReadyPosition(CONTACT, out errValue) == 0)
                {
                    msg = "CONTACT Prnt Card Error: " + errValue.ToString();
                    return;
                }

                if (printer.EjectCard(out errValue) == 0)
                {
                    msg = "CONTACT Eject Card Error: " + errValue.ToString();
                    return;
                }
            }
            catch (Exception ex)
            {
                msg += ex.Message;
                System.Windows.Forms.MessageBox.Show(ex.ToString(), "CONTACTCode threw exception");
            }
            finally
            {
                if (printer != null)
                {
                    printer.EjectCard(out errValue);
                    if (msg.Length == 0)
                    {
                        printer.Close(out msg);
                    }
                    else
                    {
                        string tempmsg = "";
                        printer.Close(out tempmsg);
                    }
                    printer = null;
                }
            }
        }