Example #1
0
        public void printOutSlip_Backup(responseSaveVn app)
        {
            try
            {
                SerialPrinter printer = new SerialPrinter(portName: "COM3", baudRate: 38400);

                EPSON e = new EPSON();

                string fontName = "Tahoma";

                Font fontRegular       = new Font(fontName, 26, FontStyle.Regular, GraphicsUnit.Pixel);
                Font fontBoldUnderline = new Font(fontName, 26, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Pixel);
                Font fontBold          = new Font(fontName, 26, FontStyle.Bold, GraphicsUnit.Pixel);
                Font fontJumbo         = new Font(fontName, 48, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Pixel);

                byte[] ImgTitle = DrawText($"ใช้บริการโดยตู้ Kiosk {app.dateSave}", fontRegular);
                byte[] ImgEx    = DrawText(app.ex, fontBoldUnderline);
                byte[] ImgVn    = DrawText("HN : " + app.hn + "\nVN : " + app.vn, fontJumbo);
                byte[] ImgName  = DrawText($"ชื่อ : {app.ptname}", fontRegular);

                byte[] ImgPtright = DrawText($"สิทธิ : {app.ptright}", fontBoldUnderline);

                string extraTxt = "";
                if (!String.IsNullOrEmpty(app.hospCode))
                {
                    extraTxt += $"\n{app.hospCode}";
                }

                if (!String.IsNullOrEmpty(app.doctor))
                {
                    extraTxt += $"\n{app.doctor}";
                }

                byte[] ImgHn = DrawText($"อายุ {app.age}\nบัตร ปชช. : {app.idcard}\n{app.mx}{extraTxt}", fontRegular);


                printer.Write(
                    ByteSplicer.Combine(
                        e.CenterAlign(),
                        e.PrintImage(File.ReadAllBytes("Images/LogoWithName2.png"), true, false, 500),
                        e.PrintImage(ImgTitle, true),
                        e.PrintImage(ImgEx, true),
                        e.PrintImage(ImgVn, true),
                        e.PrintImage(ImgName, true),
                        e.PrintImage(ImgHn, true),
                        e.PrintImage(ImgPtright, true),
                        e.PrintLine(" "),
                        e.SetBarcodeHeightInDots(350),
                        e.SetBarWidth(BarWidth.Thin),
                        e.PrintBarcode(BarcodeType.CODE128, app.hn),
                        e.PrintLine(" "),
                        e.FeedLines(6),
                        e.FullCut()
                        )
                    );


                if (app.queueStatus == "y")
                {
                    byte[] ImgTitleQueue = DrawText("ใช้บริการโดยตู้ Kiosk\nตรวจโรคทั่วไป\n", fontRegular);
                    byte[] ImgHnVn       = DrawText($"HN : {app.hn} VN : {app.vn} \n ชื่อ : {app.ptname}", fontBold);
                    byte[] ImgDetail     = DrawText($"ประเภท : {app.ptType}", fontRegular);
                    byte[] ImgQueue      = DrawText(app.queueNumber, fontJumbo);
                    byte[] ImgQueueWait  = DrawText($"จำนวนคิวที่รอ {app.queueWait} คิว", fontRegular);
                    printer.Write(
                        ByteSplicer.Combine(
                            e.CenterAlign(),
                            e.PrintImage(File.ReadAllBytes("Images/LogoWithNameOPD.png"), true, false, 500),
                            e.PrintImage(ImgTitleQueue, true),
                            e.PrintImage(ImgHnVn, true),
                            e.PrintImage(ImgDetail, true),
                            e.PrintImage(ImgQueue, true),
                            e.PrintImage(ImgQueueWait, true),
                            e.FeedLines(6),
                            e.FullCut()
                            )
                        );
                    printer.Dispose(); // close
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #2
0
        private async void submitHn_Click(object sender, EventArgs e)
        {
            string textBoxTest = hn.Text;
            string ptRight     = "";
            string idcard      = "";

            Console.WriteLine($"Manual ค้นหาจาก HN {smConfig.searchOpcardUrl}");

            if (!Regex.IsMatch(textBoxTest, "-", RegexOptions.IgnoreCase))
            {
                notify.Text = "อนุญาตให้ใช้เฉพาะ HN";
                return;
            }

            responseOpcard resultOpcard = new responseOpcard();
            // ค้นหาและตรวจสอบ HN
            string testOpcard = await Task.Run(() => searchFromSmByHn(smConfig.searchOpcardUrl, textBoxTest));

            Console.WriteLine(testOpcard);
            if (!string.IsNullOrEmpty(testOpcard))
            {
                resultOpcard = JsonConvert.DeserializeObject <responseOpcard>(testOpcard);
                if (resultOpcard.opcardStatus == "n")
                {
                    notify.Text = resultOpcard.errorMsg;
                    //pictureBox1.Visible = false;
                    return;
                }
                idcard  = resultOpcard.idcard;
                ptRight = resultOpcard.hosPtRight;
                //hosPtRight = resultOpcard.hosPtRight;
            }

            // ค้นหาการนัดหมาย
            Console.WriteLine($"ค้นหาการนัด {smConfig.searchAppointUrl} {idcard}");
            responseAppoint resultAppoint = new responseAppoint();
            // ตรวจสอบการนัดหมาย
            string contentAppoint = await Task.Run(() => searchFromSm(smConfig.searchAppointUrl, idcard));

            string appointContent = "";
            int    appointCount   = 0;
            string appointStatus  = "";


            if (!string.IsNullOrEmpty(contentAppoint))
            {
                resultAppoint = JsonConvert.DeserializeObject <responseAppoint>(contentAppoint);
                appointStatus = resultAppoint.appointStatus;
                Console.WriteLine(resultAppoint);
                if (appointStatus == "y")
                {
                    appointContent = resultAppoint.appointContent;
                    appointCount   = int.Parse(resultAppoint.appointCount);
                    //appointRowId = result.row
                    appoint = resultAppoint.appoint;
                }
                else
                {
                    notify.Text = resultAppoint.errorMsg;
                    //pictureBox1.Visible = false;
                    return;
                }
            }


            if (resultOpcard.PtRightMain != resultOpcard.PtRightSub)
            {
                notify.Text = "แจ้งเตือน! : สิทธิหลักและสิทธิรองไม่ตรงกัน กรุณาติดต่อห้องทะเบียนเพื่อทบทวนสิทธิ\n";
                /*pictureBox1.Visible = false;*/
                return;
            }

            int appointRowId = appoint.ToArray()[0].rowId;

            /*Console.WriteLine(smConfig.createVnUrl);
             * Console.WriteLine(idcard);
             * Console.WriteLine(appointRowId);
             * Console.WriteLine(ptRight);
             * return;*/


            //Console.WriteLine("กดออก VN แพทย์คนเดียว");
            SaveVn sv = new SaveVn();

            string contentVn = await Task.Run(() => sv.save(smConfig.createVnUrl, idcard, appointRowId, ptRight));

            if (!String.IsNullOrEmpty(contentVn))
            {
                responseSaveVn appVn = JsonConvert.DeserializeObject <responseSaveVn>(contentVn);
                EpsonSlip      es    = new EpsonSlip();
                es.printOutSlip(appVn);
            }
        }
Example #3
0
        public void printOutSlip(responseSaveVn app)
        {
            try
            {
                string fontName           = "Tahoma";
                Font   fontRegular        = new Font(fontName, 16, FontStyle.Regular, GraphicsUnit.Pixel);
                Font   fontBold           = new Font(fontName, 16, FontStyle.Bold, GraphicsUnit.Pixel);
                Font   fontBoldUnderline  = new Font(fontName, 16, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Pixel);
                Font   fontSuperBold      = new Font(fontName, 28, FontStyle.Bold, GraphicsUnit.Pixel);
                Font   superBoldUnderline = new Font(fontName, 28, FontStyle.Bold | FontStyle.Underline, GraphicsUnit.Pixel);

                Font superBoldv2 = new Font(fontName, 24, FontStyle.Bold, GraphicsUnit.Pixel);

                byte[] PartialCut = { 0x0A, 0x0A, 0x0A, 0x1B, 0x69 };
                System.Globalization.CultureInfo _cultureTHInfo = new System.Globalization.CultureInfo("th-TH");
                string currDate = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss", _cultureTHInfo);

                Printer printer = new Printer(smConfig.printerName);

                printer.AlignCenter();

                printer.Image(DrawTextImg($"คิวห้องตรวจ {app.queueNumber}", superBoldv2));
                printer.NewLines(3);

                printer.Image(new Bitmap(Bitmap.FromFile("Images/small-icon.bmp")));
                printer.Image(DrawTextImg(currDate, fontRegular));
                printer.Image(DrawTextImg(app.ex, fontRegular));
                printer.Image(DrawTextImg("HN : " + app.hn, superBoldUnderline));
                printer.Image(DrawTextImg("VN : " + app.vn, superBoldUnderline));
                printer.NewLine();
                printer.Image(DrawTextImg($"ชื่อ : {app.ptname}", fontBold));
                printer.NewLine();
                printer.Image(DrawTextImg($"สิทธิ : {app.ptright}", fontBoldUnderline));
                if (!String.IsNullOrEmpty(app.hospCode))
                {
                    printer.Image(DrawTextImg(app.hospCode, fontRegular));
                }

                printer.Image(DrawTextImg($"อายุ {app.age}", fontRegular));
                printer.Image(DrawTextImg($"บัตร ปชช. : {app.idcard}", fontRegular));
                printer.Image(DrawTextImg(app.mx, fontRegular));
                printer.NewLine();
                printer.Image(DrawTextImg($"คิวซักประวัติที่ {app.fakeQueue}", fontBold));
                printer.NewLine();

                if (!String.IsNullOrEmpty(app.doctor))
                {
                    printer.Image(DrawTextImg(app.doctor, fontRegular));
                }
                else
                {
                    printer.Image(DrawTextImg("แพทย์.....................", fontRegular));
                }

                /*
                 * var writer = new BarcodeWriter
                 * {
                 *  Format = BarcodeFormat.QR_CODE,
                 *  Options = new ZXing.Common.EncodingOptions
                 *  {
                 *      Height = 160,
                 *      Width = 306
                 *  }
                 * };
                 * var qrCodeImg = writer.Write(app.hn);
                 * printer.Image(qrCodeImg);
                 */

                var writer2 = new BarcodeWriter
                {
                    Format  = BarcodeFormat.CODE_39,
                    Options = new ZXing.Common.EncodingOptions
                    {
                        Height      = 60,
                        Width       = 306,
                        PureBarcode = true
                    }
                };
                var barcodeImg = writer2.Write(app.hn);
                printer.Image(barcodeImg);
                printer.Image(DrawTextImg("ยื่นรับยาที่ช่องหมายเลข6", fontBold));
                printer.Image(new Bitmap(Bitmap.FromFile("Images/extra.bmp")));

                //printer.Image(DrawTextImg($"หากที่อยู่ของท่านมีการเปลี่ยนแปลง", fontBold));
                //printer.Image(DrawTextImg($"กรุณาแจ้งแผนกทะเบียน", fontBold));
                //printer.Image(DrawTextImg($"เพื่อประโยชน์และสิทธิ์ของท่านเอง", fontBold));
                printer.NewLines(8);
                printer.Append(PartialCut);

                //////
                if (app.queueStatus == "y")
                {
                    //printer.Image(new Bitmap(Bitmap.FromFile("Images/small-icon2.bmp")));
                    //printer.Image(DrawTextImg(currDate, fontRegular));
                    //printer.NewLine();

                    /*
                     * printer.Image(DrawTextImg("บัตรคิวซักประวัติ", fontBold));
                     * printer.NewLine();
                     * printer.Image(DrawTextImg(app.queueRoom, fontRegular));
                     * printer.NewLine();
                     * printer.Image(DrawTextImg($"HN : {app.hn}", fontSuperBold));
                     * printer.NewLine();
                     * printer.Image(DrawTextImg($"ชื่อ : {app.ptname}", fontRegular));
                     * printer.Image(DrawTextImg($"ประเภท : {app.ptType}", fontRegular));
                     * printer.NewLine();
                     * printer.Image(DrawTextImg(app.queueNumber, fontSuperBold));
                     * printer.NewLine();
                     * printer.Image(DrawTextImg($"คิวพบแพทย์ผู้ป่วยนัด", fontRegular));
                     * printer.NewLines(8);
                     * printer.Append(PartialCut);
                     */

                    //printer.Image(new Bitmap(Bitmap.FromFile("Images/small-icon2.bmp")));
                    //printer.Image(DrawTextImg(currDate, fontRegular));
                    //printer.NewLine();
                    printer.Image(DrawTextImg("คิวพบแพทย์ผู้ป่วยนัด", fontBold));
                    printer.Image(DrawTextImg(currDate, fontRegular));
                    printer.Image(DrawTextImg(app.queueNumber, fontSuperBold));
                    printer.Image(DrawTextImg(app.queueRoom + " คิวที่ " + app.runNumber, fontRegular));
                    //printer.Image(DrawTextImg($"เลขคิวห้องตรวจ {app.runNumber}", fontSuperBold, 32));
                    printer.NewLine();
                    printer.Image(DrawTextImg($"คิวซักประวัติที่ {app.fakeQueue}", fontSuperBold, 32));
                    printer.NewLine();
                    if (!String.IsNullOrEmpty(app.doctor))
                    {
                        printer.Image(DrawTextImg(app.doctor, fontRegular));
                    }
                    else
                    {
                        printer.Image(DrawTextImg("แพทย์.....................", fontRegular));
                    }
                    printer.Image(DrawTextImg($"HN : {app.hn}", fontBold));
                    printer.Image(DrawTextImg($"ชื่อ : {app.ptname}", fontRegular));
                    printer.Image(DrawTextImg($"ประเภท : {app.ptType}", fontRegular));
                    printer.Image(DrawTextImg($"จำนวนคิวที่รอ {app.queueWait} คิว", fontRegular));
                    printer.Image(DrawTextImg($"ใบคิวสำหรับผู้ป่วย โปรดเก็บไว้กับตัว", fontBold));
                    printer.NewLines(8);
                    printer.Append(PartialCut);
                }
                //////
                printer.PrintDocument();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ไม่สามารถพิมพ์ได้ " + ex.Message, "แจ้งเตือน");
                Console.WriteLine(ex.Message);
            }
        }