Exemple #1
0
        //Imprime en impresora mandando la lineas de comando PCL
        private static void PrintLabelByPL(LabelTemplate template, IList <Label> listLabels, Printer printer)
        {
            string templateReplaced = (new WMSServiceClient())
                                      .GetReplacedTemplateForLabels(listLabels, template, "");

            if (string.IsNullOrEmpty(templateReplaced))
            {
                Util.ShowError("Error creating Printer Template.");
                return;
            }

            PrinterControl.PrintLabels(templateReplaced, printer.PrinterPath);
        }
Exemple #2
0
        //private static LocalReport localReport = null;

        //Envia un archivo de templates a imprimir
        public static bool PrintLabels(string labelData, string printerPort)
        {
            //TODO: Módulo de impresión
            bool   result    = false;
            string printPort = printerPort;
            string filePath  = CreatePrintTemporaryFile("", labelData);

            if (!File.Exists(batFile))
            {
                throw new Exception("Setup file " + batFile + " does not exists.\n");
            }

            batFile = "\"" + batFile.Replace("\\\\", "\\") + "\""; //Comillas para que DOS lo reconozca

            try
            {
                if (File.Exists(filePath) == false)
                {
                    throw new Exception("Please setup the temporary printing file.");
                }

                ////Asynchronously start the Thread to process the Execute command request.
                Thread objThread = new Thread(new ParameterizedThreadStart(SendPrintProcess));
                ////Make the thread as background thread.
                objThread.IsBackground = true;
                ////Set the Priority of the thread.
                objThread.Priority = ThreadPriority.AboveNormal;
                ////Start the thread.
                string printCommand = "\"" + filePath + "\" \"" + printPort + "\"";
                objThread.Start(printCommand);
                //SendPrintProcess(printCommand);
            }
            catch (Exception ex)
            {
                result = true;
                Util.ShowError(ex.Message);
                //throw ex;
            }

            if (!string.IsNullOrEmpty(error))
            {
                Util.ShowError(error);
            }

            return(result);
        }
Exemple #3
0
        internal static void PrintShipmentPackLabels(Document shipment)
        {
            if (shipment == null || shipment.DocID == 0)
            {
                Util.ShowError("Shipment must be created before reprint all Labels.");
                return;
            }

            //Open View Packages
            LabelTemplate template = null;

            try
            {
                template = (new WMSServiceClient()).GetLabelTemplate(new LabelTemplate
                {
                    Header = WmsSetupValues.DefaultPackLabelTemplate
                }).First();
            }
            catch
            {
                Util.ShowError("No packing label defined.");
                return;
            }


            ProcessWindow pw = new ProcessWindow("Printing Labels ... ");
            int           x  = 0;

            try
            {
                x = (new WMSServiceClient()).PrintPackageLabels(shipment);
            }
            catch (Exception ex)
            {
                pw.Close();
                Util.ShowError("Error: " + ex.Message);
            }


            pw.Close();
        }
Exemple #4
0
        public static void EtiquetadoEquipoIndividual(String serial, String mac, String Ruta, String ipServidor, List <String> codAuxiliares, Int32 CantImpresiones, String nombreImpresora)
        {
            try
            {
                String directorio  = "\\\\" + ipServidor + "\\" + Ruta;
                String zplForLabel = LeerArchivo_Impresion(directorio);

                StringBuilder zpl = new StringBuilder();
                zpl.Append(zplForLabel);
                zpl = zpl.Replace("sr1", serial);
                zpl = zpl.Replace("mac", mac);

                int numAux = codAuxiliares.Count; //Número de codigos adicionales

                if (numAux > 0)
                {
                    for (int a = 1; a <= codAuxiliares.Count; a++)
                    {
                        zpl = zpl.Replace("cod" + a, codAuxiliares[a - 1]);
                    }
                }

                for (int b = 0; b < CantImpresiones; b++)
                {
                    // Send a printer-specific to the printer.
                    RawPrinterHelper.SendStringToPrinter(nombreImpresora, zpl.ToString());
                    Thread.Sleep(200);
                }
            }
            catch (Exception ex)
            {
                Util.ShowError("Se presento un error en la impresión de la etiqueta " + ex.Message);
            }
            //Console.WriteLine(zpl.ToString());
            //throw new NotImplementedException();
        }
Exemple #5
0
        public static void PrintLabelsInBatch(LabelTemplate defTemplate, Printer printer, IList <Label> listOfLabels)
        {
            //if (string.IsNullOrEmpty(printer))
            //{
            //    Util.ShowError("Printer not found");
            //    return;
            //}

            Thread tl;

            if (printer != null && printer.PrinterName != WmsSetupValues.DEFAULT)
            {
                usePrinter = printer;
            }


            //printerName = printer;
            //m_streams = new List<Stream>();
            m_streams          = new Dictionary <LabelTemplate, IList <Stream> >();
            m_currentPageIndex = new Dictionary <LabelTemplate, int>();


            //1. Si viene un template imprime los labes con ese template
            if (defTemplate != null)
            {
                try
                {
                    PrintLabelByTemplate(defTemplate, listOfLabels.Where(f => f.Product.PrintLabel != false).ToList());

                    //tl = new Thread(new ThreadStart(UpdateLabelPrintStatus));
                    //tl.Start();
                    UpdateLabelPrintStatus();
                }
                catch (Exception ex) { Util.ShowError(ex.Message); }

                return;
            }


            //2. Agrupa a los diferentes tipos de label y a los null y los manda por aparte.
            //Filtra los que no imprime label (double check)
            IList <LabelTemplate> templateList = new List <LabelTemplate>();

            //Si el lable es de producto busca las templates del producto.
            if (listOfLabels[0].LabelType.DocTypeID == LabelType.ProductLabel)
            {
                templateList = listOfLabels.Where(f => f.Product.DefaultTemplate != null)
                               .Select(f => f.Product.DefaultTemplate).Distinct().ToList();
            }

            string error = "";

            //Configurando el template por defecto para impresion
            LabelTemplate defLabelTemplate = App.defTemplate;


            //Para cada template mandando la impresion
            foreach (LabelTemplate template in templateList)
            {
                try
                {
                    PrintLabelByTemplate(template, listOfLabels.Where(f => f.Product.DefaultTemplate == template && f.Product.PrintLabel != false)
                                         .ToList());

                    tl = new Thread(new ThreadStart(UpdateLabelPrintStatus));
                    tl.Start();
                }
                catch (Exception ex) {
                    error += ex.Message;
                }
            }

            //Mandando las labels con template ne Null
            try
            {
                List <Label> labelsWoTemplate = null;
                if (listOfLabels[0].LabelType.DocTypeID == LabelType.ProductLabel)
                {
                    labelsWoTemplate = listOfLabels.Where(f => f.Product.DefaultTemplate == null && f.Product.PrintLabel != false).ToList();
                }
                else
                {
                    labelsWoTemplate = listOfLabels.ToList();
                }

                PrintLabelByTemplate(defLabelTemplate, labelsWoTemplate);

                tl = new Thread(new ThreadStart(UpdateLabelPrintStatus));
                tl.Start();
            }
            catch (Exception ex) { error += ex.Message; }


            //Final Error
            if (!string.IsNullOrEmpty(error))
            {
                Util.ShowError(error);
            }
        }
Exemple #6
0
 public static string GetConfigOption(string key)
 {
     try { return(App.configOptions[key]); }
     catch { Util.ShowError("Option " + key + " not defined."); }
     return("");
 }
        public ViewDocument(LabelTemplate report, int docID, string printer, bool showBtnPrint, IList<WpfFront.WMSBusinessService.Label> list)
        {
            if (report == null)
            {
                Util.ShowError("Report could not be found.");
                return;
            }

            InitializeComponent();
            printerName = printer;
            documentID = docID;
            labelList = list;



            #region Windows Form Host

            //if (showBtnPrint)
            //    btnPrintBatch.Visibility = Visibility.Visible;
            //else
            //    btnPrintBatch.Visibility = Visibility.Collapsed;

            //Create a Windows Forms Host to host a form
            WindowsFormsHost host = new WindowsFormsHost();

            //Report ddimensions
            host.HorizontalAlignment = HorizontalAlignment.Stretch;
            host.VerticalAlignment = VerticalAlignment.Stretch;

            //pivotView.Width = 900;
            //pivotView.Height = 700;

            pivotView.Margin = new System.Windows.Forms.Padding { All = 5 };

            //Add the component to the host
            host.Child = pivotView;
            gridP.Children.Add(host);

            #endregion





            try
            {
                //Report File exists
                string reportPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    WmsSetupValues.RdlTemplateDir + "\\" + report.Header);

                if (!File.Exists(reportPath))
                {
                    Util.ShowError("Report file does not exists.");
                    return;
                }

                //Rendering Report
                this.pivotView.ProcessingMode = ProcessingMode.Local;
                this.pivotView.LocalReport.ReportPath = reportPath;
                this.pivotView.LocalReport.EnableExternalImages = true;
                this.pivotView.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);
                this.pivotView.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Barcode, Version=1.0.5.40001, Culture=neutral, PublicKeyToken=6dc438ab78a525b3");
                this.pivotView.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

                DataSet ds;
                //Document
                if (documentID > 0)
                {
                    ds = ReportMngr.ProcessDocument(documentID, service, report.Header);
                    if (ds == null)
                        return;

                    pivotView.LocalReport.DataSources.Add(new ReportDataSource("Header", ds.Tables["ReportHeaderFormat"]));
                    pivotView.LocalReport.DataSources.Add(new ReportDataSource("Details", ds.Tables["ReportDetailFormat"]));
                }

                //Labels
                else if (report.LabelType.DocClass.DocClassID == SDocClass.Label)
                {
                    ds = ReportMngr.ProcessLabels(labelList);
                    pivotView.LocalReport.DataSources.Add(new ReportDataSource("Details", ds.Tables["Details"]));
                }

                /*
                // CAA [2010/06/22]
                // Nueva opción para enviar parámetros al reporte
                if (parameters != null)
                {
                    ReportParameter rp;
                    ReportParameter[] rpList= new ReportParameter[parameters.Count()];
                    int cont = 1;
                    foreach (string parameter in parameters)
                    {
                        rp = new ReportParameter("p"+cont.ToString(), parameter);
                        rpList[cont-1] = rp;
                        cont++;
                    }
                    pivotView.LocalReport.SetParameters(rpList);
                }
                 */

                //Showing
                pivotView.Show();
                pivotView.ShowFindControls = false;
                pivotView.ShowExportButton = false;
                pivotView.ShowRefreshButton = false;
                pivotView.LocalReport.Refresh();
                pivotView.RefreshReport();

            }
            catch (Exception ex)
            {
                Util.ShowError("Report could not shown: " + ex.Message);
            }


        }
        public ViewDocument(DataSet ds, String ReportName)
        {
            string flag = "";

            if (ReportName == null)
            {
                Util.ShowError("Report could not be found.");
                return;
            }

            if (ds == null)
                return;

            flag = "Initialize";

            InitializeComponent();
            printerName = "";



            #region Windows Form Host

            //if (showBtnPrint)
            //    btnPrintBatch.Visibility = Visibility.Visible;
            //else
            //    btnPrintBatch.Visibility = Visibility.Collapsed;

            //Create a Windows Forms Host to host a form
            WindowsFormsHost host = new WindowsFormsHost();

            //Report ddimensions
            host.HorizontalAlignment = HorizontalAlignment.Stretch;
            host.VerticalAlignment = VerticalAlignment.Stretch;

            //pivotView.Width = 900;
            //pivotView.Height = 700;

            pivotView.Margin = new System.Windows.Forms.Padding { All = 5 };

            //Add the component to the host
            host.Child = pivotView;
            gridP.Children.Add(host);

            #endregion

            Warning[] warnings;
            string[] streamids;
            string mimeType;
            string encoding;
            string extension;
            string idpallet = "";
            string date = DateTime.Now.ToString("ddMMyyy-HHmmss");
            try
            {
                //Report File exists
                string reportPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    WmsSetupValues.RdlTemplateDir + "\\" + ReportName);

                if (!File.Exists(reportPath))
                {
                    Util.ShowError("Archivo del reporte no existe.");
                    return;
                }

                //Rendering Report
                flag = "Rendering";
                this.pivotView.ProcessingMode = ProcessingMode.Local;
                this.pivotView.LocalReport.ReportPath = reportPath;

                try { this.pivotView.LocalReport.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted)); }
                catch { }

                this.pivotView.LocalReport.EnableExternalImages = true;
                try { this.pivotView.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence); }
                catch { }
                try { this.pivotView.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Barcode, Version=1.0.5.40001, Culture=neutral, PublicKeyToken=6dc438ab78a525b3"); }
                catch { }
                try { this.pivotView.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); }
                catch { }

                flag = "Process";
                pivotView.LocalReport.DataSources.Add(new ReportDataSource("Header", ds.Tables[0]));
                pivotView.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", ds.Tables[1]));

                idpallet = ds.Tables[1].Rows[0][4].ToString();

                //Showing
                flag = "Showing";
                pivotView.ShowFindControls = false;
                pivotView.ShowExportButton = false;
                pivotView.ShowRefreshButton = false;
                pivotView.Show();
                pivotView.LocalReport.Refresh();
                pivotView.RefreshReport();

            }// End try
            catch (Exception ex)
            {
                Util.ShowError("Error mostrando el reporte: " + flag + ", " + ex);
            }
            finally
            {
                string filePath = "";
                // Asigno el nombre del archivo e.g.  RES-A0215544, Fecha 09102015-0941009  
                //(La fecha tiene el siguiente formato "ddMMyyy-HHmmss").
                string nameFile = idpallet + ", Fecha " + date;
                try
                {
                // Especifico un nombre para la ruta.
                filePath = @"c:\Habladores";
                // Asignamos la extensión del archivo.
                nameFile += ".PDF";
                // Evaluo si la ruta ya existe para no volver a crearla.
                if (!System.IO.File.Exists(filePath))
                {
                    // Creo el directorio especificado.
                    System.IO.Directory.CreateDirectory(filePath);
                }
                // Combino la ruta con el nombre del archivo.
                filePath = System.IO.Path.Combine(filePath, nameFile);
                // Creo un arreglo de bytes para almacenar allí el archivo con la información
                // que se guardará.
                byte[] bytes = this.pivotView.LocalReport.Render("pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);

                // Creo el archivo en la ruta especificada.
                FileStream fs = new FileStream(filePath, FileMode.Create);
                fs.Write(bytes, 0, bytes.Length);
                //Cierro el objeto FileStream.
                fs.Close();
                // Libero la memoria que fue ocupada por el objeto.
                fs.Dispose();
                // mostramos la información de que se guardo satisfactoriamente el archivo y mostramos la ruta.
                Util.ShowMessage("Reporte exportado en la siguiente ruta: " + filePath);
                }
                catch (Exception e)
                {
                    Util.ShowError(e.Message);
                }
            }// End finally
        }// End ViewDocument(dataset, string)