Esempio n. 1
0
            public void printStoredFormatWithHash(string formatPathOnPrinter, IReadOnlyDictionary <string, string> vars, IMethodResult oResult)
            {
                Logger.Write("printStoredFormatWithHash call");
                Logger.Write("formatPathOnPrinter: " + formatPathOnPrinter);
                Logger.Write("vars: ", vars);

                if (m_printer != null)
                {
                    Dictionary <int, string> _params = new Dictionary <int, string>();

                    foreach (KeyValuePair <string, string> pair in vars)
                    {
                        try
                        {
                            _params.Add(Int32.Parse(pair.Key), pair.Value);
                        }
                        catch (Exception e)
                        {
                        }
                    }

                    m_printer.GetFormatUtil().PrintStoredFormat(formatPathOnPrinter, _params);
                    oResult.set(ZebraConstants.PRINTER_STATUS_SUCCESS);
                    return;
                }

                oResult.set(ZebraConstants.PRINTER_STATUS_ERROR);
            }
Esempio n. 2
0
        /*****************************************************************************************************
        Desc: Gets variable user field information from format file stored at Zebra printer. Stores that information
         * into an array for later processing.
        ******************************************************************************************************/

        private FieldDescriptionData[] GetVarFieldNames()
        {
            String formatName = null;

            // Create an array to store variable user field information of selected format file
            FieldDescriptionData[] fieldNames = new FieldDescriptionData[] { };
            try
            {
                if (cbFormatList.SelectedItem != null)
                {
                    formatName = cbFormatList.SelectedItem.ToString();
                }
                else
                {
                    MessageBox.Show("Please select format file to be printed.");
                    return fieldNames;
                }
                
                ZebraPrinter printer = getPrinter();

                // Get the format file information
                if (printer != null)
                {                    
                    byte[] formatData = printer.GetFormatUtil().RetrieveFormatFromPrinter(formatName);
                    String formatString = Encoding.UTF8.GetString(formatData, 0, formatData.Length);
                    fieldNames = printer.GetFormatUtil().GetVariableFields(formatString);
                   
                }
                else
                {
                    MessageBox.Show("Device isn't connected.");
                    return fieldNames;
                }
            
            }
            catch (ZebraPrinterConnectionException)
            {
                MessageBox.Show("Communication Error:\r\n Check Printer is on Or Connection has been established.\r\n");
                return fieldNames;
            }
            catch (ZebraException)
            {
                MessageBox.Show("Zebra Printer Error: Can't retrieve variable field names");
                return fieldNames;
            }
            catch (Exception)
            {
                MessageBox.Show("Error in retrieving variable field names");
                return fieldNames;
            }
            return fieldNames;
        }
        private FieldDescriptionData[] GetVarFieldNames()
        {
            String formatName = formatListBox.SelectedItem.ToString();

            FieldDescriptionData[] fieldNames = new FieldDescriptionData[] { };
            try {
                ZebraPrinter printer      = getPrinter();
                byte[]       formatData   = printer.GetFormatUtil().RetrieveFormatFromPrinter(formatName);
                String       formatString = Encoding.UTF8.GetString(formatData, 0, formatData.Length);
                fieldNames = printer.GetFormatUtil().GetVariableFields(formatString);
            } catch (ZebraPrinterConnectionException) {
                updateGuiFromWorkerThread("Communication Error", Color.Red);
            }
            return(fieldNames);
        }
Esempio n. 4
0
        /*****************************************************************************************************
        Desc: This function is called when Print button is clicked. It sends print request to Zebra printer
         * with the selected format file,user input fields and format encoding type.
        ******************************************************************************************************/

        private void Print_Click(object sender, EventArgs e)
        {
            ZebraPrinter printer = null;

            //Get the list of variable user input fields
            FieldDescriptionData[] varFieldNames = GetVarFieldNames();

            try
            {
                if (zebraPrinterConnection != null && isConnected)
                {
                    printer = getPrinter();
                }
                else
                {
                    MessageBox.Show("Device isn't connected.");
                    return;
                }

                if(printer != null)
                {
                String formatName = cbFormatList.SelectedItem.ToString();

                //Store Field Name and Field Number in dictionary structure
                Dictionary<int, String> fieldNumbersAndNames = new Dictionary<int, string>();
                for (int i = 0; i < labels.Count; i++)
                {
                    int fnNumber = varFieldNames[i].FieldNumber;
                    fieldNumbersAndNames[fnNumber] = userInputVars[i].Text;
                }

                // Print choosen format label to number of times user selected.
                for (int i = 0; i < quantity.Value; i++)
                    printer.GetFormatUtil().PrintStoredFormat(formatName, fieldNumbersAndNames, "UTF-8");
                }
                else
                {
                    MessageBox.Show("Can't send print request \r\n please check printer is configured properly.");
                    return;
                }
            }
            catch(ZebraPrinterConnectionException)
            {
                MessageBox.Show("Communication Error:\r\n Check Printer is on Or Connection has been established.\r\n");
                return;
            }
            catch(ZebraException)
            {
                MessageBox.Show("Print Error:\r\n Check Printer is on Or Connection has been established.\r\n");
                return;
            }
            catch(Exception)
            {
                MessageBox.Show("Printing Error:\r\n Check all variable field values are supplied properly.\r\n");
                return;
            }

        }