コード例 #1
0
ファイル: Racun.cs プロジェクト: Ajlag/AgriculturalPharmacy
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                //var hemikalije = this.unit.Hemikalijee.GetAllHemikalijes();
                //foreach (var h in hemikalije)
                //{
                //    if (h.kolicina > 0)
                //    {
                //        cmb_artikal.Items.Add(h.ToString());
                //        h.kolicina = h.kolicina - int.Parse(textBox2.Text);
                //        }
                //    else
                //        MessageBox.Show("Artikal nemamo na stanju");
                //}
                double        ukupno  = double.Parse(txt_neto.Text);
                int           placeno = int.Parse(txt_placeno.Text);
                double        kusur   = double.Parse(txt_balans.Text);
                string        r       = "Račun :";
                string        u       = "Sve ukupno :" + ukupno;
                string        pl      = "Placeno :" + placeno;
                string        k       = "Kusur :" + kusur;
                string        na      = "Naziv artikla :";
                string        c       = "Cena";
                string        kol     = "Količina";
                string        uk      = "Ukupno";
                string        nl      = "\n";
                PrintDocument p       = new PrintDocument();
                p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
                {
                    e1.Graphics.DrawString("  " + u + "\n  " + pl + "\n  " + k + nl, new Font("Arial Bold", 11), new SolidBrush(Color.Black), new RectangleF(0, 0, 0, 0));
                    e1.Graphics.DrawString(" ____________________________________________________________________", new Font("Arial Bold", 11), new SolidBrush(Color.Black), new RectangleF(0, 5, 0, 10));

                    // e1.Graphics.DrawString(" \t" +na+ "\t" +c+"\t"+kol+"\t"+uk+"\t"+"\n"+"\n", new Font("Arial Bold", 11), new SolidBrush(Color.Black), new RectangleF(0, 0, 0,300));

                    e1.Graphics.DrawString(" " + r + " ", new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 55, 0, 0));
                    e1.Graphics.DrawString("\n " + nl + nl + "\n" + "\b" + nl, new Font("Arial Bold", 11), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
                    e1.Graphics.DrawString("\t" + na + "\t \t" + c + "\t \t" + kol + "\t \t" + uk + "\t \t" + "\n", new Font("Arial Bold", 11), new SolidBrush(Color.Black), new RectangleF(0, 55, 0, 0));


                    var startX = 0;
                    var startY = 35;
                    var Offset = 0;

                    for (int i = 0; i < listView1.Items.Count; i++)
                    {
                        int ii = 1;
                        ii++;
                        string prvi    = listView1.Items[i].SubItems[0].Text;
                        string drugi   = listView1.Items[i].SubItems[1].Text;
                        string treci   = listView1.Items[i].SubItems[2].Text;
                        string cetvrti = listView1.Items[i].SubItems[3].Text;



                        e1.Graphics.DrawString(" " + nl + nl + "\t " + prvi + "\t" + "\t" + drugi + "\t" + "\t" + treci + "\t" + "\t" + cetvrti + "\n" + "\n" + nl, new Font("Arial Bold", 11), new SolidBrush(Color.Black), startX, startY + Offset);

                        Offset = Offset + 15;
                    }

                    //    e1.Graphics.DrawString("\n " +nl+ "\n", new Font("Arial Bold", 11), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
                    //e1.Graphics.DrawString(nl+"  " +nl+nl+ u + "\n" +nl+ nl+pl+ "\n" + " " +nl+ k+nl, new Font("Arial Bold", 11), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
                };
                try
                {
                    p.Print();
                }
                catch (Exception ex)
                {
                    throw new Exception("Exception Occured While Printing", ex);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception Occured While Printing", ex);
            }
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                string prvi    = listView1.Items[i].SubItems[0].Text;
                string drugi   = listView1.Items[i].SubItems[1].Text;
                string treci   = listView1.Items[i].SubItems[2].Text;
                string cetvrti = listView1.Items[i].SubItems[3].Text;

                var novi = new Narudzbina
                {
                    naziv = prvi,
                    cena  = int.Parse(drugi),

                    kolicina = int.Parse(treci),
                    datum    = DateTime.Today
                };
                this.unit.Narudzbinaa.AddNarudzbinas(novi);
                this.unit.Complete();
            }
        }
コード例 #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();
            }
        }
コード例 #3
0
        private static string PrintBarCode(string pbc, int elarg, int ehaut, int mytaillelabel)
        {
            //Split data to get dropzone and barcode
            string[] barcodetab             = pbc.Split(';');
            string   emplacementdestination = "";

            if (barcodetab.Length > 1)
            {
                emplacementdestination = barcodetab[1];
            }
            //Add dash to the barcode
            string labelbarcode = "";

            if (barcodetab[0].Length > 13)
            {
                labelbarcode = barcodetab[0].Insert(13, "-");
            }
            else
            {
                labelbarcode = barcodetab[0];
            }

            QrCodeEncodingOptions options = new QrCodeEncodingOptions();

            options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 500,
                Height       = 500,
            };
            var writer = new BarcodeWriter();

            writer.Format  = BarcodeFormat.QR_CODE;
            writer.Options = options;

            var qr = new ZXing.BarcodeWriter();

            qr.Options = options;
            qr.Format  = ZXing.BarcodeFormat.QR_CODE;
            Image img = new Bitmap(qr.Write(barcodetab[0]));

            //QR CODE

            //print the image
            PrintDocument pd = new PrintDocument();

            pd.PrintPage += (senders, args) =>
            {
                //add logo image :
                if (File.Exists("logo.png"))
                {
                    Image logosociete = Image.FromFile("logo.png");
                    args.Graphics.DrawImage(logosociete, 10, Convert.ToInt32(ehaut * (float)0.2), 70, 30);
                }

                /*
                 */
                //insert qr code
                int tailleqrcode = Convert.ToInt32(ehaut * (float)0.8);
                args.Graphics.DrawImage(img, (elarg - tailleqrcode) / 2, Convert.ToInt32(ehaut * (float)0.2), tailleqrcode, tailleqrcode);
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment     = StringAlignment.Center;
                //args.Graphics.DrawString(bcodestring, new Font("Arial", 10), Brushes.Black, new PointF((elarg+30)/2, ehaut+30), sf);
                args.Graphics.DrawString(labelbarcode, new Font("Arial", mytaillelabel), Brushes.Black, new Rectangle(0, ehaut + 30, elarg, 0), sf);
                args.Graphics.DrawString(emplacementdestination, new Font("Arial", mytaillelabel), Brushes.Black, new Rectangle(0, ehaut + 45, elarg, 0), sf);
            };
            pd.PrinterSettings.PrinterName = Global.Selectedprinter;
            pd.Print();
            return(barcodetab[0]);
        }