Ejemplo n.º 1
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);
        }