Пример #1
0
        public static void PrintReceiptForTransaction(string line)
        {
            JArray a = (JArray.Parse(line));
            //Console.WriteLine(a);
            var nombre = a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "printer");

            Console.WriteLine(a);
            JObject obj2 = JObject.Parse(a.First.ToString());
            string  type = (string)obj2["type"];

            //Console.WriteLine(a);El array
            //Console.WriteLine(obj2);El objeto dentro del array
            if (type == "ticket")
            {
                string imagen = a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "zone").Value.ToString();
                Font   prueba = new Font("Arial", 20, FontStyle.Regular);
                System.Drawing.Image img;
                JArray b = JArray.Parse(a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "ticket").Value.ToString());
                if (!String.IsNullOrEmpty(imagen))
                {
                    img = DrawText(imagen, prueba, Color.White, Color.Black);
                }
                else
                {
                    img = null;
                }
                foreach (JObject o2 in b.Children <JObject>())
                {
                    PrintDocument recordDoc = new PrintDocument();
                    recordDoc.DocumentName    = "Customer Receipt";
                    recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                    PrinterSettings ps = new PrinterSettings();
                    ps.PrinterName            = nombre.Value.ToString();
                    recordDoc.PrinterSettings = ps;
                    recordDoc.PrintPage      += (sender, args) => PrintReceiptPage(sender, args, o2, img, a);
                    recordDoc.Print();
                    recordDoc.Dispose();

                    bool coleta = (bool)(obj2["coleta"]);
                    if (coleta)
                    {
                        PrintDocument recordDoc2 = new PrintDocument();
                        recordDoc2.DocumentName    = "Customer Receipt";
                        recordDoc2.PrintController = new StandardPrintController(); // hides status dialog popup
                        PrinterSettings ps2 = new PrinterSettings();
                        ps2.PrinterName            = nombre.Value.ToString();
                        recordDoc2.PrinterSettings = ps2;
                        string serie = (string)(o2["serie"]);
                        string sc = (string)(o2["sc"]);
                        string station = (string)(obj2["station"]);
                        string price = (string)(obj2["price"]);
                        string iva = (string)(obj2["iva"]);
                        string total = (string)(obj2["total"]);
                        float  x = 10, y = 0, w = 255.59F, h = 0F;
                        recordDoc2.PrintPage += (sender, args) => Coleta(ref args, x, ref y, w, h, sc, serie, station, price, iva, total);
                        recordDoc2.Print();
                    }
                }
            }
            else if (type == "report")
            {
                JArray        header    = JArray.Parse(a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "header").Value.ToString());
                JArray        content   = JArray.Parse(a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "content").Value.ToString());
                string[]      h1        = header.ToObject <string[]>();
                string[]      c1        = content.ToObject <string[]>();
                PrintDocument recordDoc = new PrintDocument();
                recordDoc.DocumentName    = "Customer Receipt";
                recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                PrinterSettings ps = new PrinterSettings();
                ps.PrinterName            = nombre.Value.ToString();
                recordDoc.PrinterSettings = ps;
                recordDoc.PrintPage      += (sender, args) => PrintReport(sender, args, h1, c1, a);
                recordDoc.Print();
                recordDoc.Dispose();
            }
            else if (type == "test")
            {
                Font       bold_12   = new Font("Verdana", 12, FontStyle.Bold);
                SolidBrush drawBrush = new SolidBrush(Color.Black);
                Font       regular   = new Font("Verdana", 8, FontStyle.Regular);
                foreach (JObject b in a.Children <JObject>())
                {
                    string zone = (string)(b["zone"]);
                    string chair = (string)(b["chair"]);
                    string table = (string)(b["table"]);
                    string net_price = (string)(b["net_price"]);
                    string iva = (string)(b["iva"]);
                    string total = (string)(b["total"]);
                    string date = (string)(b["date"]);
                    string id = (string)(b["id"]);
                    float  x = 14, y = 7, w = 255.59F, h = 0F;

                    StringFormat center = new StringFormat();
                    center.Alignment = StringAlignment.Center;
                    PrintDocument recordDoc = new PrintDocument();
                    recordDoc.DocumentName    = "Customer Receipt";
                    recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                    PrinterSettings ps = new PrinterSettings();
                    ps.PrinterName            = nombre.Value.ToString();
                    recordDoc.PrinterSettings = ps;
                    recordDoc.PrintPage      += (sender, args) => imprimirTest(id, ref args, zone, chair, table, net_price, iva, total, date, regular, drawBrush, x, ref y, w, h, center);
                    recordDoc.Print();
                    recordDoc.Dispose();
                }
            }
        }
Пример #2
0
        public static void PrintReceiptForTransaction(string line)
        {
            Console.WriteLine(JArray.Parse(line));
            JArray a = (JArray.Parse(line));
            //Console.WriteLine(a);
            var     nombre = a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "printer");
            JObject obj2   = JObject.Parse(a.First.ToString());
            string  type   = (string)obj2["type"];

            //Console.WriteLine(a);El array
            //Console.WriteLine(obj2);El objeto dentro del array
            if (type == "ticket")
            {
                string imagen = a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "zone").Value.ToString();
                Font   prueba = new Font("Arial", 20, FontStyle.Regular);
                System.Drawing.Image img;
                JArray b = JArray.Parse(a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "ticket").Value.ToString());
                if (!String.IsNullOrEmpty(imagen))
                {
                    img = DrawText(imagen, prueba, Color.White, Color.Black);
                }
                else
                {
                    img = null;
                }
                foreach (JObject o2 in b.Children <JObject>())
                {
                    PrintDocument recordDoc = new PrintDocument();
                    recordDoc.DocumentName    = "Customer Receipt";
                    recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                    PrinterSettings ps = new PrinterSettings();
                    ps.PrinterName            = nombre.Value.ToString();
                    recordDoc.PrinterSettings = ps;
                    recordDoc.PrintPage      += (sender, args) => PrintReceiptPage(sender, args, o2, img, a);
                    recordDoc.Print();
                    recordDoc.Dispose();

                    bool coleta = (bool)(obj2["coleta"]);
                    if (coleta)
                    {
                        PrintDocument recordDoc2 = new PrintDocument();
                        recordDoc2.DocumentName    = "Customer Receipt";
                        recordDoc2.PrintController = new StandardPrintController(); // hides status dialog popup
                        PrinterSettings ps2 = new PrinterSettings();
                        ps2.PrinterName            = nombre.Value.ToString();
                        recordDoc2.PrinterSettings = ps2;
                        string serie = (string)(o2["serie"]);
                        string station = (string)(obj2["station"]);
                        string price = (string)(obj2["price"]);
                        string iva = (string)(obj2["iva"]);
                        string total = (string)(obj2["total"]);
                        float  x = 10, y = 0, w = 255.59F, h = 0F;
                        recordDoc2.PrintPage += (sender, args) => Coleta(ref args, x, ref y, w, h, serie, station, price, iva, total);
                        recordDoc2.Print();
                    }
                }
            }
            else if (type == "bracelet")
            {
                Font       bold_16   = new Font("Arial", 16, FontStyle.Bold);
                SolidBrush drawBrush = new SolidBrush(Color.Black);
                Font       regular   = new Font("Arial", 8, FontStyle.Regular);

                int mm   = 0;
                var hijo = a.Children <JObject>().Properties().First();
                if (hijo.Name == "width")
                {
                    mm = (int)hijo.Value;
                }
                float width = ((mm) * (0.039370F) * (100)) - 20;

                foreach (JObject o2 in a.Children <JObject>())
                {
                    float        x = 96F, y = 10, w = 960F, h = 0F;
                    string       text   = (string)(o2["text"]);
                    StringFormat center = new StringFormat();
                    center.Alignment = StringAlignment.Center;
                    //center.FormatFlags = StringFormatFlags.DirectionVertical;
                    PrintDocument recordDoc = new PrintDocument();
                    recordDoc.DocumentName    = "Customer Receipt";
                    recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                    PrinterSettings ps = new PrinterSettings();
                    ps.PrinterName            = nombre.Value.ToString();
                    recordDoc.PrinterSettings = ps;
                    recordDoc.PrintPage      += (sender, args) => imprimir(ref args, width + text, bold_16, drawBrush, x, ref y, width, h, center);
                    recordDoc.Print();
                    recordDoc.Dispose();
                }
            }
            else if (type == "credential")
            {
                int mm   = 0;
                var hijo = a.Children <JObject>().Properties().First();
                if (hijo.Name == "width")
                {
                    mm = (int)hijo.Value;
                }
                //float width = 171;
                float width = 215.433071F;
                foreach (JObject o2 in a.Children <JObject>())
                {
                    StringFormat center = new StringFormat();
                    center.Alignment = StringAlignment.Center;
                    //center.FormatFlags = StringFormatFlags.DirectionVertical;
                    PrintDocument recordDoc = new PrintDocument();
                    recordDoc.DocumentName    = "Customer Receipt";
                    recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                    PrinterSettings ps = new PrinterSettings();
                    ps.PrinterName            = nombre.Value.ToString();
                    recordDoc.PrinterSettings = ps;
                    recordDoc.PrintPage      += (sender, args) => PrintCredential(sender, args, o2, a, width);
                    recordDoc.Print();
                    recordDoc.Dispose();
                }
            }
            else if (type == "report")
            {
                JArray        header    = JArray.Parse(a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "header").Value.ToString());
                JArray        content   = JArray.Parse(a.Children <JObject>().Properties().FirstOrDefault(z => z.Name == "content").Value.ToString());
                string[]      h1        = header.ToObject <string[]>();
                string[]      c1        = content.ToObject <string[]>();
                PrintDocument recordDoc = new PrintDocument();
                recordDoc.DocumentName    = "Customer Receipt";
                recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                PrinterSettings ps = new PrinterSettings();
                ps.PrinterName            = nombre.Value.ToString();
                recordDoc.PrinterSettings = ps;
                recordDoc.PrintPage      += (sender, args) => PrintReport(sender, args, h1, c1, a);
                recordDoc.Print();
                recordDoc.Dispose();
            }
            else if (type == "test")
            {
                float      x = 4, y = 0, w = 255.59F, h = 0F;
                Font       bold_16   = new Font("Arial", 16, FontStyle.Bold);
                SolidBrush drawBrush = new SolidBrush(Color.Black);
                Font       regular   = new Font("Arial", 8, FontStyle.Regular);

                StringFormat center = new StringFormat();
                center.Alignment = StringAlignment.Center;
                PrintDocument recordDoc = new PrintDocument();
                recordDoc.DocumentName    = "Customer Receipt";
                recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                PrinterSettings ps = new PrinterSettings();
                ps.PrinterName            = nombre.Value.ToString();
                recordDoc.PrinterSettings = ps;
                recordDoc.PrintPage      += (sender, args) => imprimir(ref args, "prueba", bold_16, drawBrush, x, ref y, w, h, center);
                recordDoc.Print();
                recordDoc.Dispose();
            }
        }