Esempio n. 1
0
        private void FormatPage(object sender, PrintPageEventArgs e)
        {
            graphics = e.Graphics;
            Font minifont   = new Font("Arial", 5);
            Font itemfont   = new Font("Arial", 6);
            Font smallfont  = new Font("Arial", 12);
            Font mediumfont = new Font("Arial", 14);
            Font largefont  = new Font("Arial", 16);

            int Offset = 10;
            int smallinc = 10, mediuminc = 12, largeinc = 17;

            //Getting Receipt data
            List <PrintReceiptModel>     printReceiptModel = new List <PrintReceiptModel>();
            List <PrintReceiptItemModel> printReceiptItemModel = new List <PrintReceiptItemModel>();

            //Parameter pass global Customer Order Id
            PrintReceiptViewModel printReceiptViewModel = new PrintReceiptViewModel();

            List <ReportOffsetModel> reportOffsetModels = new List <ReportOffsetModel>();

            printReceiptModel     = printReceiptViewModel.GetPrintReceiptByBillId(billId);
            printReceiptItemModel = printReceiptViewModel.GetPrintReceiptItemByBillId(billId);
            reportOffsetModels    = printReceiptViewModel.GetReportOffsetByReportName("R1");

            int intClientName       = reportOffsetModels.Find(x => x.ReportColumn.Contains("ClientName")).ColumnOffset;
            int intHeader           = reportOffsetModels.Find(x => x.ReportColumn.Contains("Header")).ColumnOffset;
            int intAddress1         = reportOffsetModels.Find(x => x.ReportColumn.Contains("Address1")).ColumnOffset;
            int intAddress2         = reportOffsetModels.Find(x => x.ReportColumn.Contains("Address2")).ColumnOffset;
            int intEmail            = reportOffsetModels.Find(x => x.ReportColumn.Contains("Email")).ColumnOffset;
            int intPhone            = reportOffsetModels.Find(x => x.ReportColumn.Contains("Phone")).ColumnOffset;
            int intDate             = reportOffsetModels.Find(x => x.ReportColumn.Contains("Date")).ColumnOffset;
            int intItemHeader       = reportOffsetModels.Find(x => x.ReportColumn.Contains("Item-header")).ColumnOffset;
            int intItemFoodMenuName = reportOffsetModels.Find(x => x.ReportColumn.Contains("Item-FoodMenuName")).ColumnOffset;
            int intItemFoodMenuRate = reportOffsetModels.Find(x => x.ReportColumn.Contains("Item-FoodMenuRate")).ColumnOffset;
            int intItemFoodMenuQty  = reportOffsetModels.Find(x => x.ReportColumn.Contains("Item-FoodMenuQty")).ColumnOffset;
            int intItemPrice        = reportOffsetModels.Find(x => x.ReportColumn.Contains("Item-Price")).ColumnOffset;
            int intGROSSTotal       = reportOffsetModels.Find(x => x.ReportColumn.Contains("GROSSTotal")).ColumnOffset;
            int intVATABLE          = reportOffsetModels.Find(x => x.ReportColumn.Contains("VATABLE")).ColumnOffset;
            int intDISCOUNT         = reportOffsetModels.Find(x => x.ReportColumn.Contains("DISCOUNT")).ColumnOffset;
            int intDELIVERYCharge   = reportOffsetModels.Find(x => x.ReportColumn.Contains("DELIVERYCharge")).ColumnOffset;
            int intTOTAL            = reportOffsetModels.Find(x => x.ReportColumn.Contains("TOTAL")).ColumnOffset;
            int intPaid             = reportOffsetModels.Find(x => x.ReportColumn.Contains("Paid")).ColumnOffset;
            int intFooter           = reportOffsetModels.Find(x => x.ReportColumn.Contains("Footer")).ColumnOffset;
            int intFooter1          = reportOffsetModels.Find(x => x.ReportColumn.Contains("Footer1")).ColumnOffset;
            int intFooter2          = reportOffsetModels.Find(x => x.ReportColumn.Contains("Footer2")).ColumnOffset;
            int intFooter3          = reportOffsetModels.Find(x => x.ReportColumn.Contains("Footer3")).ColumnOffset;
            int intFooter4          = reportOffsetModels.Find(x => x.ReportColumn.Contains("Footer4")).ColumnOffset;
            int intPowerBy          = reportOffsetModels.Find(x => x.ReportColumn.Contains("PowerBy")).ColumnOffset;



            //Image image = Image.FromFile("d:\\2.jpg");

            //e.Graphics.DrawImage(image, startX + 50, startY + Offset, 100, 30);
            // e.Graphics.DrawImage(image, 50, 10 + Offset, 100, 30);

            Offset = Offset + Offset;

            graphics.DrawString(LoginDetail.ClientName, smallfont, new SolidBrush(Color.Black), intClientName, Offset);//50 + 22
            //graphics.DrawString(LoginDetail.ClientName, smallfont, new SolidBrush(Color.Black), ((LoginDetail.ClientName.Length)*2), Offset);//50 + 22

            Offset = Offset + mediuminc;
            DrawAtStartCenter(LoginDetail.Header, Offset, intHeader);

            Offset = Offset + mediuminc;
            DrawAtStartCenter(LoginDetail.Address1, Offset, intAddress1);

            Offset = Offset + mediuminc;
            DrawAtStartCenter(LoginDetail.Address2, Offset, intAddress2);

            Offset = Offset + mediuminc;
            DrawAtStartCenter("EMAIL: " + LoginDetail.Email, Offset, intEmail);

            Offset = Offset + mediuminc;
            DrawAtStartCenter("PHONE : " + LoginDetail.Phone, Offset, intPhone);

            String underLine = "---------------------------------";

            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + mediuminc + 6;
            DrawAtStart("RECEIPT NO: " + printReceiptModel[0].SalesInvoiceNumber.ToString().PadRight((intDate - printReceiptModel[0].SalesInvoiceNumber.ToString().Length) + 8) + "DATE: " + printReceiptModel[0].BillDateTime.ToString("dd/MM/yyyy HH:mm"), Offset);;

            Offset = Offset + mediuminc;
            DrawAtStart("CUSTOMER: " + printReceiptModel[0].CustomerName, Offset);

            underLine = "---------------------------------";
            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + largeinc;

            InsertHeaderStyleItem("ITEM".PadRight(intItemHeader) + "RATE          AMOUNT ", "", Offset);

            Offset = Offset + mediuminc;

            foreach (var item in printReceiptItemModel)
            {
                InsertItemList(item.FoodMenuName.ToString(), "", Offset, intItemFoodMenuName);
                Offset = Offset + smallinc;
                InsertItemList(item.FoodMenuQty.ToString("F") + " " + item.Unitname, "", Offset, intItemFoodMenuQty + (50 - (item.FoodMenuQty.ToString().Length * 4)));
                InsertItemList(item.FoodMenuRate.ToString("F"), "", Offset, intItemFoodMenuRate + (50 - (item.FoodMenuRate.ToString().Length * 4)));
                InsertItemList(item.Price.ToString("F") + " " + item.FoodVat.ToString(), "", Offset, intItemPrice + (50 - (item.Price.ToString().Length * 4)));
                Offset = Offset + smallinc;
            }
            Offset = Offset - smallinc;

            underLine = "---------------------------------";
            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + largeinc;
            InsertItem("GROSS TOTAL: ", "", Offset);
            InsertItem(printReceiptModel[0].GrossAmount.ToString("F").PadLeft(intGROSSTotal - printReceiptModel[0].GrossAmount.ToString("F").Length), "", Offset);

            Offset = Offset + smallinc;
            InsertItem("VATABLE: ", "", Offset);
            InsertItem(printReceiptModel[0].VatableAmount.ToString("F").PadLeft(intVATABLE - printReceiptModel[0].VatableAmount.ToString("F").Length), "", Offset);

            Offset = Offset + smallinc;
            InsertItem("VAT: ", "", Offset);
            InsertItem(printReceiptModel[0].TaxAmount.ToString("F").PadLeft(intVATABLE - printReceiptModel[0].TaxAmount.ToString("F").Length), "", Offset);

            Offset = Offset + smallinc;
            InsertItem("Non VAT: ", "", Offset);
            InsertItem(printReceiptModel[0].NonVatableAmount.ToString("F").PadLeft(intVATABLE - printReceiptModel[0].NonVatableAmount.ToString("F").Length), "", Offset);

            if (printReceiptModel[0].Discount.ToString("F") != "0.00")
            {
                Offset = Offset + smallinc;
                InsertItem("DISCOUNT/REDEEM: ", "", Offset);
                InsertItem(printReceiptModel[0].Discount.ToString("F").PadLeft(intVATABLE - printReceiptModel[0].Discount.ToString("F").Length), "", Offset);
            }

            if (printReceiptModel[0].ServiceCharge.ToString("F") != "0.00")
            {
                Offset = Offset + smallinc;
                InsertItem("DELIVERY CHARGE: ", printReceiptModel[0].ServiceCharge.ToString("F").PadLeft(intDELIVERYCharge - printReceiptModel[0].ServiceCharge.ToString("F").Length), Offset);
            }

            Offset = Offset + smallinc;
            InsertItem("TOTAL: ", "", Offset);
            InsertItem(printReceiptModel[0].TotalAmount.ToString("F").PadLeft(intTOTAL - printReceiptModel[0].TotalAmount.ToString("F").Length), "", Offset);

            underLine = "---------------------------------";
            DrawLine(underLine, largefont, Offset, 0);


            decimal dcLevy;

            dcLevy = ((Convert.ToDecimal(printReceiptModel[0].VatableAmount) + Convert.ToDecimal(printReceiptModel[0].NonVatableAmount)) * 2) / 100;

            Offset = Offset + largeinc;
            InsertItem("CATERING LEVY: ", "", Offset);
            InsertItem(dcLevy.ToString("F").PadLeft(intTOTAL - dcLevy.ToString("F").Length), "", Offset);

            underLine = "---------------------------------";
            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + largeinc;

            InsertItem(LoginDetail.Lastname + " " + LoginDetail.Firstname, "", Offset);
            Offset = Offset + smallinc;

            InsertItem("PAID BY: ", "", Offset);
            Offset = Offset + smallinc;

            foreach (PrintReceiptModel payment in printReceiptModel)
            {
                InsertItem(payment.PaymentMethodName, payment.BillAmount.ToString("F").PadLeft(intPaid - payment.BillAmount.ToString("F").Length), Offset);
                Offset = Offset + smallinc;
            }

            if (printReceiptModel[0].RewardAmount != 0)
            {
                underLine = "---------------------------------";
                DrawLine(underLine, largefont, Offset, 0);

                Offset = Offset + largeinc;

                InsertItem("YOU EARN " + printReceiptModel[0].RewardAmount + " POINTS", "", Offset);
                Offset = Offset + smallinc;
            }

            Offset = Offset + largeinc;
            Offset = Offset + largeinc;

            // graphics.DrawString(LoginDetail.Footer, smallfont, new SolidBrush(Color.Black), intFooter, Offset);//50 + 22
            DrawAtStartCenter(LoginDetail.Footer, Offset, intFooter);

            Offset = Offset + largeinc;

            DrawAtStartCenter(LoginDetail.Footer1, Offset, intFooter1);
            Offset = Offset + mediuminc;

            DrawAtStartCenter(LoginDetail.Footer2, Offset, intFooter2);
            Offset = Offset + mediuminc;

            DrawAtStartCenter(LoginDetail.Footer3, Offset, intFooter3);
            Offset = Offset + mediuminc;

            DrawAtStartCenter(LoginDetail.Footer4, Offset, intFooter4);
            Offset = Offset + mediuminc;
            Offset = Offset + mediuminc;

            if (LoginDetail.Powerby.Length > 0)
            {
                DrawAtStartCenter(LoginDetail.Powerby, Offset, intPowerBy);
            }
        }
        private void FormatPage(object sender, PrintPageEventArgs e)
        {
            graphics = e.Graphics;
            Font minifont = new Font("Arial", 5);
            Font itemfont = new Font("Arial", 6);
            Font smallfont = new Font("Arial", 8);
            Font mediumfont = new Font("Arial", 10);
            Font largefont = new Font("Arial", 12);
            int  Offset = 10;
            int  smallinc = 10, mediuminc = 12, largeinc = 15;

            //Getting Receipt data
            List <PrintReceiptModel>     printReceiptModel     = new List <PrintReceiptModel>();
            List <PrintReceiptItemModel> printReceiptItemModel = new List <PrintReceiptItemModel>();

            //Parameter pass global Customer Order Id
            PrintReceiptViewModel printReceiptViewModel        = new PrintReceiptViewModel();

            printReceiptModel     = printReceiptViewModel.GetPrintReceiptByBillId(billId);
            printReceiptItemModel = printReceiptViewModel.GetPrintReceiptItemByBillId(billId);

            //Image image = Image.FromFile("d:\\2.jpg");

            //e.Graphics.DrawImage(image, startX + 50, startY + Offset, 100, 30);
            // e.Graphics.DrawImage(image, 50, 10 + Offset, 100, 30);

            Offset = Offset + Offset;

            //Name
            int intPadding = 10 + ((pageWidthHeader - LoginDetail.ClientName.Length) / 2) * 3;

            graphics.DrawString(LoginDetail.ClientName, smallfont, new SolidBrush(Color.Black), intPadding, Offset);//50 + 22

            Offset = Offset + mediuminc;
            DrawAtStartCenter(LoginDetail.Header, Offset);

            Offset = Offset + mediuminc;
            DrawAtStartCenter(LoginDetail.Address1, Offset);

            Offset = Offset + mediuminc;
            DrawAtStartCenter(LoginDetail.Address2, Offset);

            Offset = Offset + mediuminc;
            DrawAtStartCenter("Email : " + LoginDetail.Email, Offset);

            Offset = Offset + mediuminc;
            DrawAtStartCenter("Phone : " + LoginDetail.Phone, Offset);

            String underLine = "-------------------------------------";

            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + mediuminc;
            DrawAtStart("Receipt Number: " + printReceiptModel[0].SalesInvoiceNumber.ToString().PadRight((20 - printReceiptModel[0].SalesInvoiceNumber.ToString().Length) + 10) + "Date: " + DateTime.Now.ToString("MM/dd/yyyy HH:mm"), Offset);;

            Offset = Offset + mediuminc;
            DrawAtStart("Customer: " + printReceiptModel[0].CustomerName, Offset);

            underLine = "-------------------------------------";
            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + largeinc;

            InsertHeaderStyleItem("ITEM                                RATE     QTY    AMOUNT ", "", Offset);

            Offset = Offset + largeinc;

            foreach (var item in printReceiptItemModel)
            {
                InsertItemList(item.FoodMenuName.ToString(), "", Offset, 5);
                InsertItemList(item.FoodMenuRate.ToString("F"), "", Offset, 60 + (50 - (item.FoodMenuRate.ToString().Length * 4)));
                InsertItemList(item.FoodMenuQty.ToString("F"), "", Offset, 90 + (50 - (item.FoodMenuQty.ToString().Length * 4)));
                InsertItemList(item.Price.ToString("F"), "", Offset, 133 + (50 - (item.Price.ToString().Length * 4)));

                // InsertItem(item.FoodMenuName.ToString().PadRight((55- (item.FoodMenuName.ToString().Length)))  + "x " +   item.FoodMenuRate.ToString("F").PadRight((25 - (item.FoodMenuRate.ToString().Length))) + item.Price.ToString("F"), "", Offset);

                Offset = Offset + smallinc;
            }
            Offset = Offset - smallinc;

            underLine = "-------------------------------------";
            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + largeinc;
            InsertItem("GROSS TOTAL: ", printReceiptModel[0].GrossAmount.ToString("F").PadLeft(30 - printReceiptModel[0].GrossAmount.ToString().Length), Offset);

            Offset = Offset + smallinc;
            InsertItem("DISCOUNT : ", printReceiptModel[0].Discount.ToString("F").PadLeft(30 - printReceiptModel[0].Discount.ToString().Length), Offset);

            Offset = Offset + smallinc;
            InsertItem("VATABLE: ", printReceiptModel[0].VatableAmount.ToString("F").PadLeft(30 - printReceiptModel[0].VatableAmount.ToString().Length), Offset);

            Offset = Offset + smallinc;
            InsertItem("SER CRH: ", printReceiptModel[0].ServiceCharge.ToString("F").PadLeft(30 - printReceiptModel[0].ServiceCharge.ToString().Length), Offset);

            Offset = Offset + smallinc;
            InsertItem("TOTAL: ", printReceiptModel[0].TotalAmount.ToString("F").PadLeft(30 - printReceiptModel[0].TotalAmount.ToString().Length), Offset);


            underLine = "-------------------------------------";
            DrawLine(underLine, largefont, Offset, 0);

            Offset = Offset + largeinc;
            InsertItem("TOTAL: ", printReceiptModel[0].PaymentMethodName.ToString().PadRight(10) + " " + printReceiptModel[0].BillAmount.ToString("F").PadLeft(10), Offset);

            Offset = Offset + largeinc;
            Offset = Offset + largeinc;

            intPadding = 10 + ((pageWidthHeader - LoginDetail.ClientName.Length) / 2) * 3;
            graphics.DrawString(LoginDetail.Footer, smallfont, new SolidBrush(Color.Black), intPadding, Offset);//50 + 22

            Offset = Offset + largeinc;

            DrawAtStartCenter(LoginDetail.Footer1, Offset);
            Offset = Offset + mediuminc;

            DrawAtStartCenter(LoginDetail.Footer2, Offset);
            Offset = Offset + mediuminc;

            DrawAtStartCenter(LoginDetail.Footer3, Offset);
            Offset = Offset + mediuminc;

            DrawAtStartCenter(LoginDetail.Footer4, Offset);
            Offset = Offset + mediuminc;


            //DrawAtStart(LoginDetail.Footer1, Offset);

            //Offset = Offset + mediuminc;
            //DrawAtStart(LoginDetail.Footer2, Offset);

            //Offset = Offset + mediuminc;
            //DrawAtStart(LoginDetail.Footer3, Offset);

            //Offset = Offset + mediuminc;
            //DrawAtStart(LoginDetail.Footer4, Offset);

            //Offset = Offset + 7;
            //underLine = "-------------------------------------";
            //DrawLine(underLine, largefont, Offset, 0);

            //Offset = Offset + mediuminc;
            //String greetings = "Thanks for visiting us.";
            //DrawSimpleString(greetings, mediumfont, Offset, 28);

            //Offset = Offset + mediuminc;
            //underLine = "-------------------------------------";
            //DrawLine(underLine, largefont, Offset, 0);

            //Offset += (2 * mediuminc);
            //string tip = "TIP: -----------------------------";
            //InsertItem(tip, "", Offset);

            //Offset = Offset + largeinc;
            //string DrawnBy = "Meganos Softwares: 0312-0459491 - OR - 0321-6228321";
            //DrawSimpleString(DrawnBy, minifont, Offset, 15);
        }