Exemplo n.º 1
0
        private void ProcessJob(PrintQueue queue, string jobID, string reportID, string jobDescription, Dictionary <string, string> parameters)
        {
            _progress.Report(new MonitorMessage(String.Format(Strings.ProcessPrintJobNotify, queue.QueueName, jobID)));
            const string fileIdKey = "FILEID";

            byte[] data = null;

            if (reportID == String.Empty)
            {
                if (parameters.ContainsKey(fileIdKey))
                {
                    data = GetFileID(parameters[fileIdKey]);
                }
                else
                {
                    _progress.Report(new MonitorMessage(String.Format(Strings.FileIdMissingWarning, queue.QueueName, jobID), MonitorMessage.MonitorStates.Warning));
                }
            }
            else
            {
                data = GetReportPdf(reportID, parameters);
            }

            if (data != null)
            {
                if (queue.RawMode)
                {
                    if (IsPdf(data))
                    {
                        _progress.Report(new MonitorMessage(String.Format(Strings.PdfWrongModeWarning, queue.QueueName, jobID), MonitorMessage.MonitorStates.Warning));
                    }
                    else
                    {
                        PrintRaw(queue, jobDescription, data);
                    }
                }
                else
                {
                    if (IsPdf(data))
                    {
                        PrintPdf(jobDescription, queue, data);
                    }
                    else
                    {
                        _progress.Report(new MonitorMessage(String.Format(Strings.PdfWrongFileFormatWarning, queue.QueueName, jobID), MonitorMessage.MonitorStates.Warning));
                    }
                }
            }

            DeleteJobFromQueue(jobID);
        }
        private void addPrintQueue_Click(object sender, EventArgs e)
        {
            var newQueue = new PrintQueue();

            newQueue.QueueName   = NewQueueName;
            newQueue.PrinterName = new PrinterSettings().PrinterName;
            newQueue.PaperSize   = PrintQueue.PrinterDefault;
            newQueue.PaperSource = PrintQueue.PrinterDefault;
            newQueue.Orientation = PrintQueue.PrinterOrientation.Automatic;

            _queues.Add(newQueue);
            queueList.Items.Add(newQueue);
            queueList.SelectedItem = newQueue;
            SetControlsState();

            queueName.Focus();
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            Uri validatedUri;

            if (!Uri.TryCreate(acumaticaUrlTextBox.Text, UriKind.Absolute, out validatedUri))
            {
                MessageBox.Show(Strings.UrlMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                acumaticaUrlTextBox.Focus();
                return;
            }

            if (String.IsNullOrEmpty(loginTextBox.Text))
            {
                MessageBox.Show(Strings.LoginMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                loginTextBox.Focus();
                return;
            }

            if (String.IsNullOrEmpty(passwordTextBox.Text))
            {
                MessageBox.Show(Strings.PasswordMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                passwordTextBox.Focus();
                return;
            }

            if (_queues.Count == 0 && String.IsNullOrEmpty(acumaticaScaleIDTextBox.Text))
            {
                MessageBox.Show(Strings.PrintQueueOrScaleConfigurationMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 1;
                return;
            }

            if (!String.IsNullOrEmpty(acumaticaScaleIDTextBox.Text) && (scalesDropDown.SelectedItem == null || (scalesDropDown.SelectedItem as ScaleDevice).VendorId == 0))
            {
                MessageBox.Show(String.Format(Strings.DeviceMissingPrompt, acumaticaScaleIDTextBox.Text), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 2;
                scalesDropDown.Focus();
                return;
            }

            PrintQueue unnamedQueue = _queues.FirstOrDefault(q => q.QueueName == NewQueueName);

            if (unnamedQueue != null)
            {
                MessageBox.Show(Strings.QueueNameMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex  = 1;
                queueList.SelectedItem = unnamedQueue;
                queueName.Focus();
                return;
            }

            var screen = new ScreenApi.Screen();

            screen.Url = acumaticaUrlTextBox.Text + "/Soap/.asmx";
            try
            {
                screen.Login(loginTextBox.Text, passwordTextBox.Text);
                try
                {
                    screen.Logout();
                }
                catch { } //Ignore all errors in logout.
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format(Strings.ScreenWebServiceConnexionError, ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                acumaticaUrlTextBox.Focus();
                return;
            }

            Properties.Settings.Default.AcumaticaUrl = acumaticaUrlTextBox.Text;
            Properties.Settings.Default.Login        = loginTextBox.Text;
            Properties.Settings.Default.Password     = Settings.EncryptString(Settings.ToSecureString(passwordTextBox.Text));
            Properties.Settings.Default.Queues       = JsonConvert.SerializeObject(_queues);
            Properties.Settings.Default.ScaleID      = acumaticaScaleIDTextBox.Text;

            if (scalesDropDown.SelectedItem == null)
            {
                Properties.Settings.Default.ScaleDeviceVendorId  = 0;
                Properties.Settings.Default.ScaleDeviceProductId = 0;
            }
            else
            {
                var s = (ScaleDevice)scalesDropDown.SelectedItem;
                Properties.Settings.Default.ScaleDeviceVendorId  = s.VendorId;
                Properties.Settings.Default.ScaleDeviceProductId = s.ProductId;
            }

            Properties.Settings.Default.Save();

            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 4
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((JobID != null ? JobID.GetHashCode() : 0) * 397) ^ (PrintQueue != null ? PrintQueue.GetHashCode() : 0));
     }
 }
Exemplo n.º 5
0
        private void PrintPdf(string jobDescription, PrintQueue queue, byte[] pdfReport)
        {
            _progress.Report(new MonitorMessage(String.Format(Strings.PrintPdfNotify, queue.QueueName, queue.PrinterName)));
            var pdfPrint = new PdfPrint("Acumatica", "g/4JFMjn6KtGjMEKn2ZY1H6+hSqKUHU+273JkSGKwP0=");

            pdfPrint.PrinterName = queue.PrinterName;

            // Retrieve paper size, source and orientation
            var printerSettings = new System.Drawing.Printing.PrinterSettings();

            printerSettings.PrinterName = queue.PrinterName;

            if (queue.PaperSize != PrintQueue.PrinterDefault)
            {
                bool paperSizeSet = false;
                foreach (PaperSize paperSize in printerSettings.PaperSizes)
                {
                    if (paperSize.RawKind == queue.PaperSize)
                    {
                        pdfPrint.PaperSize = paperSize;
                        paperSizeSet       = true;
                        break;
                    }
                }

                if (!paperSizeSet)
                {
                    _progress.Report(new MonitorMessage(String.Format(Strings.PaperSizeMissingWarning, queue.PrinterName, queue.PaperSize), MonitorMessage.MonitorStates.Warning));
                }
            }

            if (queue.PaperSource != PrintQueue.PrinterDefault)
            {
                bool paperSourceSet = false;
                foreach (PaperSource paperSource in printerSettings.PaperSources)
                {
                    if (paperSource.RawKind == queue.PaperSource)
                    {
                        pdfPrint.PaperSource = paperSource;
                        paperSourceSet       = true;
                        break;
                    }
                }

                if (!paperSourceSet)
                {
                    _progress.Report(new MonitorMessage(String.Format(Strings.PaperSourceMissingWarning, queue.PrinterName, queue.PaperSource), MonitorMessage.MonitorStates.Warning));
                }
            }

            if (queue.Orientation == PrintQueue.PrinterOrientation.Automatic)
            {
                pdfPrint.IsAutoRotate = true;
            }
            else if (queue.Orientation == PrintQueue.PrinterOrientation.Landscape)
            {
                pdfPrint.IsLandscape = true;
            }
            else if (queue.Orientation == PrintQueue.PrinterOrientation.Portrait)
            {
                pdfPrint.IsLandscape = false;
            }

            pdfPrint.Print(pdfReport, new PdfWatermark(), jobDescription);
        }
Exemplo n.º 6
0
 private void PrintRaw(PrintQueue queue, string jobDescription, byte[] rawData)
 {
     _progress.Report(new MonitorMessage(String.Format(Strings.PrintRawDataNotify, queue.QueueName, queue.PrinterName)));
     RawPrinterHelper.SendRawBytesToPrinter(queue.PrinterName, jobDescription, rawData);
 }
Exemplo n.º 7
0
        private void PrintPdf(PrintQueue queue, byte[] pdfReport)
        {
            _progress.Report(new MonitorMessage(String.Format(Strings.PrintPdfNotify, queue.QueueName, queue.PrinterName)));
            var pdfPrint = new PdfPrint("demoCompany", "demoKey");

            pdfPrint.PrinterName = queue.PrinterName;

            // Retrieve paper size, source and orientation
            var printerSettings = new System.Drawing.Printing.PrinterSettings();

            printerSettings.PrinterName = queue.PrinterName;

            if (queue.PaperSize != PrintQueue.PrinterDefault)
            {
                bool paperSizeSet = false;
                foreach (PaperSize paperSize in printerSettings.PaperSizes)
                {
                    if (paperSize.RawKind == queue.PaperSize)
                    {
                        pdfPrint.PaperSize = paperSize;
                        paperSizeSet       = true;
                        break;
                    }
                }

                if (!paperSizeSet)
                {
                    _progress.Report(new MonitorMessage(String.Format(Strings.PaperSizeMissingWarning, queue.PrinterName, queue.PaperSize), MonitorMessage.MonitorStates.Warning));
                }
            }

            if (queue.PaperSource != PrintQueue.PrinterDefault)
            {
                bool paperSourceSet = false;
                foreach (PaperSource paperSource in printerSettings.PaperSources)
                {
                    if (paperSource.RawKind == queue.PaperSource)
                    {
                        pdfPrint.PaperSource = paperSource;
                        paperSourceSet       = true;
                        break;
                    }
                }

                if (!paperSourceSet)
                {
                    _progress.Report(new MonitorMessage(String.Format(Strings.PaperSourceMissingWarning, queue.PrinterName, queue.PaperSource), MonitorMessage.MonitorStates.Warning));
                }
            }

            if (queue.Orientation == PrintQueue.PrinterOrientation.Automatic)
            {
                pdfPrint.IsAutoRotate = true;
            }
            else if (queue.Orientation == PrintQueue.PrinterOrientation.Landscape)
            {
                pdfPrint.IsLandscape = true;
            }
            else if (queue.Orientation == PrintQueue.PrinterOrientation.Portrait)
            {
                pdfPrint.IsLandscape = false;
            }

            pdfPrint.Print(pdfReport);
        }