Esempio n. 1
0
        private Image PrintAndSave(SaleInfo saleInfo, string writeToPath,
            string clientName, string actualPoint, string payed, string cardNo, bool openPrintedCoupon, bool printOnCollect, bool printOnRedeem)
        {
            Image bitmap = Resources.Kuponi;
            using (bitmap)
            using (var graphics = Graphics.FromImage(bitmap))
            using (var font = new Font("Arial", 7, FontStyle.Regular))
            {
                //data dhe ora
                graphics.DrawString(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), font,
                    Brushes.Black, 90, 270);

                //fatura id
                graphics.DrawString(saleInfo.Id.ToString(), font, Brushes.Black, 515, 267);

                //Emri dhe mbiemri
                graphics.DrawString(clientName, font, Brushes.Black, 180, 315);

                //nr karteles
                graphics.DrawString(cardNo.ToUpper(), font, Brushes.Black, 260, 350);

                //PAGESA
                graphics.DrawString(payed, font, Brushes.Black, 580, 520);

                //PIKET VLERA MONETARE
                graphics.DrawString(saleInfo.RedeemedMonetaryValue.ToString("C", CultureInfo.GetCultureInfo("de-DE")),
                font, Brushes.Black, 580, 555);

                //TOTALI
                graphics.DrawString(saleInfo.Total.ToString("C", CultureInfo.GetCultureInfo("de-DE")),
                font, Brushes.Black, 580, 600);

                //GJENDJA E PIKEVE

                var availablePoints = Convert.ToInt32(actualPoint);

                var previousPoints = (availablePoints + saleInfo.RedeemedPoints) - saleInfo.RewardedPoints;

                graphics.DrawString(previousPoints.ToString(),
                  new Font("Arial", 7, FontStyle.Bold), Brushes.Black, 580, 770);

                //PIKE TE PERDORURA
                //-150 (1.5 euro)
                graphics.DrawString(string.Format("-{0} ({1})", saleInfo.RedeemedPoints,
                    saleInfo.RedeemedMonetaryValue.ToString("C", CultureInfo.GetCultureInfo("de-DE"))), font,
                    Brushes.Black, 580, 815);

                //PIKE TE FITUARA
                graphics.DrawString(saleInfo.RewardedPoints.ToString(), font, Brushes.Black, 580, 855);

                //GJENDJA E RE E PIKEVE

                graphics.DrawString(actualPoint,
                    new Font("Arial", 7, FontStyle.Bold), Brushes.Black, 580, 895);

                bool exists = System.IO.Directory.Exists(writeToPath);

                if (!exists)
                {
                    try
                    {
                        System.IO.Directory.CreateDirectory(writeToPath);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Nuk mund te krijohet folderi: " + writeToPath + ". Ju lutemi krijojeni ate manualisht, ne menyre qe te ruhen kuponat.");
                    }
                }
                // ruje qele printo ne default printer

                string couponFileName = string.Format("grumbullim-{0}.jpg", saleInfo.Id);

                if (saleInfo.RedeemedPoints > 0)
                {
                    couponFileName = string.Format("shfrytezim-{0}.jpg", saleInfo.Id);
                }

                var filename = Path.Combine(writeToPath, couponFileName);
                printFilename = filename;

                bitmap.Save(filename);

                if (saleInfo.RedeemedPoints != 0 && printOnRedeem)
                {
                    PrintDocument pd = new PrintDocument();
                    pd.PrintPage += PrintPageEvent;
                    pd.Print();

                    if (openPrintedCoupon)
                        Process.Start(filename);
                }
                else if (printOnCollect)
                {
                    PrintDocument pd = new PrintDocument();
                    pd.PrintPage += PrintPageEvent;
                    pd.Print();

                    if (openPrintedCoupon)
                        Process.Start(filename);
                }

                //print

            }
            return bitmap;
        }
Esempio n. 2
0
 public CouponPrinter(SaleInfo sale, string writeToPath, string clientName,
     string acctualPoints, string payed, string cardNo, bool openPrintedCoupon, bool printOnCollect, bool printOnRedeem)
 {
     WriteToPath = writeToPath;
     PrintAndSave(sale, writeToPath, clientName, acctualPoints, payed, cardNo, openPrintedCoupon, printOnCollect, printOnRedeem);
 }