Ejemplo n.º 1
0
 internal static void PrintDocumentsInBatch(List<Document> documentList, Printer printer)
 {
     foreach (Document curDoc in documentList)
         ReportMngr.PrintDocument(curDoc, printer);
 }
Ejemplo n.º 2
0
        public static void PrintDocument(Document document, Printer printer)
        {

            if (document.DocType.Template == null)
                return;

            try
            {
                //Inicializando variables usadas en la impresion
                //if (m_streams == null)
                    m_streams = new Dictionary<LabelTemplate, IList<Stream>>();

                //if (m_currentPageIndex == null)
                    m_currentPageIndex = new Dictionary<LabelTemplate, int>();

                curTemplate = document.DocType.Template;
                usePrinter = printer;


                //Ejecutar la impresion global en un Hilo            
                Thread th = new Thread(new ParameterizedThreadStart(PrintDocumentThread));
                th.Start(document);


            }
            catch (Exception ex)
            {
                Util.ShowError("Report could not shown: " + ex.Message);
            }
        }
Ejemplo n.º 3
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);

                      
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private static void PrintLabelByTemplate(LabelTemplate template, List<Label> listOfLabels)
        {

            if (listOfLabels == null || listOfLabels.Count == 0)
                return;

            listLabels = listOfLabels;

            try
            {
                //Si viene una impresora definida utiliza esa, si no utiliza la del template
                if (template != null)
                    curTemplate = template;
                else
                    curTemplate = (new WMSProcessClient()).GetLabelTemplate(new LabelTemplate { Header = WmsSetupValues.ProductLabelTemplate }).First();


                usePrinter = usePrinter == null
                    ? new Printer { PrinterName = curTemplate.DefPrinter.Name, PrinterPath = curTemplate.DefPrinter.CnnString }
                    : usePrinter;
            }
            catch { throw new Exception("Printer not defined for template " + curTemplate.Name); }

            if (usePrinter == null)
                throw new Exception("Printer not defined for template " + curTemplate.Name);

            //Revisa si el label imprime por comandos y lo manda a esa ruta.
            if (template.IsPL == true)
            {
                PrintLabelByPL(template, listOfLabels, usePrinter);
                return;
            }


            try
            {
                string labelPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), 
                    WmsSetupValues.RdlTemplateDir + "\\" + template.Header);

                if (!File.Exists(labelPath))
                    throw new Exception("Label template " + template.Header + " does not exists.\n");
                

                //Definicion de Reporte
                localReport = new LocalReport();
                localReport.EnableExternalImages = true;
                localReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);
                localReport.AddTrustedCodeModuleInCurrentAppDomain("Barcode, Version=1.0.5.40001, Culture=neutral, PublicKeyToken=6dc438ab78a525b3");
                localReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
                localReport.EnableExternalImages = true;


                localReport.ReportPath = labelPath;

                DataSet ds = ProcessLabels(listOfLabels);
                localReport.DataSources.Add(new ReportDataSource("Details", ds.Tables["Details"]));


                //Proceso de Creacion de archivos 
                curTemplate = template;
                m_streams.Add(curTemplate, new List<Stream>());
                m_currentPageIndex.Add(curTemplate, 0);

                Export(localReport, curTemplate, "IMAGE");  //1 - Document, 2 -  Label


                m_currentPageIndex[curTemplate] = 0;
                Thread th = new Thread(new ParameterizedThreadStart(Print));
                th.Start(usePrinter.PrinterName);
                //Print(usePrinter.PrinterName);


            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }
Ejemplo n.º 6
0
        public static void GetPrinterList() //out IList<Printer> printerList
        {

            IList<Printer> printerList = new List<Printer>();
            string[] path;
            Printer curPrinter;

            try
            {

                using (ManagementClass printerClass = new ManagementClass("win32_printer"))
                {

                    ManagementObjectCollection printers = printerClass.GetInstances();
                    foreach (ManagementObject printer in printers)
                    {
                        curPrinter = new Printer { PrinterName = printer["Name"].ToString() };

                        if ((bool)printer["Shared"] == true)
                        {
                            path = printer["Name"].ToString().Split("\\".ToCharArray());
                            curPrinter.PrinterPath = printer["Name"].ToString().Replace(path[path.Length - 1], printer["ShareName"].ToString());

                        }
                        else
                            curPrinter.PrinterPath = printer["PortName"].ToString();


                        if ((bool)printer["Default"])
                            curPrinter.IsDefault = true;


                        printerList.Add(curPrinter);
                    }
                }


                //Add Connection Printerts
                foreach (Connection prn in App.PrinterConnectionList)
                    printerList.Add(new Printer { PrinterName = prn.Name, PrinterPath = prn.CnnString, FromServer = true });


                App.printerList = printerList;
                //return printerList;

            }
            catch { }
        }