/**************************************************************************************************
         * Function Name: OpenConnectionToPrinter
         *
         * Purpose: Gets a handle to the printer driver for the selected printer.
         *
         * Parameters: None
         *
         * Returns:  True = Handle retrieved
         *          False = Failed to open a handle to the printer driver
         *
         * History:
         * Date             Who             Comment
         * 12/9/2010        ACT             Function creation.
         ***************************************************************************************************/
        private bool OpenConnectionToPrinter()
        {
            try
            {
                string errMsg = string.Empty;

                if (cboPrn.Text.Length <= 0)
                {
                    MessageBox.Show("No printer selected");
                    return(false);
                }

                _thePrinterSDK.Open(cboPrn.Text, out errMsg);

                if (errMsg == string.Empty)
                {
                    return(true);
                }
                MessageBox.Show("Unable to open device [" + cboPrn.Text + "]. " + errMsg);
            }
            catch (Exception ex)
            {
                MessageBox.Show("OPenConnectionToPrinter threw exception; Unable to open device: " + ex.Message);
            }
            return(false);
        }
Пример #2
0
        /**************************************************************************************************
         * Function Name: OpenConnectionToPrinter
         *
         * Purpose: Gets a handle to the printer driver for the selected printer.
         *
         * Parameters: None
         *
         * Returns:  True = Successfully got handle
         *          False = Failed to get a handle to the printer driver
         *
         * History:
         * Date             Who             Comment
         * 08/13/2011        SP             Function creation.
         ***************************************************************************************************/
        private bool OpenConnectionToPrinter()
        {
            try
            {
                string errMsg = string.Empty;

                _thePrinterSDK.Open(cboPrinterSelection.Text, out errMsg);

                if (errMsg == string.Empty)
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show("Unable to open device [" + cboPrinterSelection.Text + "]. " + errMsg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("OpenConnectionToPrinter threw exception: " + ex.Message);
            }
            return(false);
        }
Пример #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;
                }
            }
        }