Пример #1
0
        private void PrintReciept(Object sender, PrintPageEventArgs e)
        {
            Graphics graphics = e.Graphics;
            Font     font     = new Font("Courier New", 10);

            float fontHeight = font.GetHeight();

            int    startX = 250;
            int    startY = 0;
            int    Offset = 20;
            int    fontwidth = 10;
            String ItemName, CatName = "";
            String ItemSize        = "";
            String ItemPrice       = "";
            String ItemQuantity    = "";
            int    stringCollLenth = 0;
            String Concat          = "";

            String[]        Split     = { "", "" };
            List <String[]> SplitAddr = new List <string[]>();

            PrintDocument Reciept = new PrintDocument();

            StringFormat Rformat = new StringFormat(StringFormatFlags.DirectionRightToLeft);

            graphics.DrawString("Serial: " + NewOrder.Order_GetOrderID(), new Font("Courier New", 8),
                                new SolidBrush(Color.Black), startX - 160, startY + Offset);

            Offset = Offset + 20;

            graphics.DrawString("مرحبا بكم في مطعم" + "\n" + "    شيخ البلد", new Font("Courier New", 14, FontStyle.Bold),
                                new SolidBrush(Color.Black), startX - 10, startY + Offset, Rformat);

            Offset = Offset + 50;

            graphics.DrawString("أبو مهند", new Font("Courier New", 10, FontStyle.Bold),
                                new SolidBrush(Color.Black), startX - 75, startY + Offset, Rformat);

            Offset = Offset + 60;

            graphics.DrawString("Order #:" + NewOrder.Order_GetOrderSubID(),
                                new Font("Courier New", fontwidth),
                                new SolidBrush(Color.Black), startX - 240, startY + Offset);
            Offset = Offset + 20;
#if DELIVERY
            graphics.DrawString("Tel: " + NewOrder.Order_GetCustTel(),
                                new Font("Courier New", fontwidth),
                                new SolidBrush(Color.Black), startX - 240, startY + Offset);
            Offset = Offset + 20;


            graphics.DrawString("خدمة توصيل",
                                new Font("Courier New", fontwidth),
                                new SolidBrush(Color.Black), startX + 20, startY + Offset, Rformat);
            Offset = Offset + 30;

            graphics.DrawString("اسم العميل : " + MyCustomer.GetName(),
                                new Font("Courier New", fontwidth),
                                new SolidBrush(Color.Black), startX + 20, startY + Offset, Rformat);

            Offset = Offset + 30;

            int    level           = 0;
            String WholeString     = "";
            int    OffsetAfterAddr = 0;
            if (MyCustomer.GetAddr().Length > 40)
            {
                SplitAddr.Add(SplitString(MyCustomer.GetAddr()));
                while ((SplitAddr[SplitAddr.Count - 1])[0].Length > 40)
                {
                    level++;
                    for (int lvlindex = 0; lvlindex < level; lvlindex++)
                    {
                        SplitAddr.Add(SplitString((SplitAddr[lvlindex])[0]));
                        SplitAddr.Add(SplitString((SplitAddr[lvlindex])[1]));
                    }
                }
                if (level == 0)
                {
                    WholeString += "\n" + (SplitAddr[0])[0] + "\n" + (SplitAddr[0])[1];

                    OffsetAfterAddr += (2 * 10);
                }
                else
                {
                    for (int Strings = (level * 2); Strings > 0; Strings--)
                    {
                        if ((SplitAddr[Strings])[0].Length > 15)
                        {
                            WholeString += "\n" + (SplitAddr[SplitAddr.Count - Strings])[0] + "\n" + (SplitAddr[SplitAddr.Count - Strings])[1];

                            OffsetAfterAddr += (2 * 10);
                        }
                        else
                        {
                            WholeString += "\n" + (SplitAddr[SplitAddr.Count - Strings])[0] + (SplitAddr[SplitAddr.Count - Strings])[1];

                            OffsetAfterAddr += 10;
                        }
                    }
                }
                graphics.DrawString("العنوان : " + WholeString,
                                    new Font("Courier New", 8),
                                    new SolidBrush(Color.Black), startX + 20, startY + Offset, Rformat);

                Offset += OffsetAfterAddr;
            }
            else
            {
                graphics.DrawString("العنوان : " + MyCustomer.GetAddr(),
                                    new Font("Courier New", 8),
                                    new SolidBrush(Color.Black), startX + 20, startY + Offset, Rformat);
            }

            Offset = Offset + 50;
#endif

            graphics.DrawString("Date/Time  " + NewOrder.Order_GetTimeStmp(),
                                new Font("Courier New", 8),
                                new SolidBrush(Color.Black), startX - 240, startY + Offset);

            Offset = Offset + 40;

            graphics.DrawString("طلب                       الكمية   سعر",
                                new Font("Courier New", 8),
                                new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);

            Offset = Offset + 10;

            graphics.DrawString("--------------------------------------", new Font("Courier New", 8),
                                new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);
            Offset = Offset + 10;

            string SpaceMargin = "   ";

            for (int i = 0; i < this.dataSet2.Tables[0].Rows.Count; i++)
            {
                ItemName     = this.dataSet2.Tables[0].Rows[i].ItemArray[1].ToString();
                ItemPrice    = this.dataSet2.Tables[0].Rows[i].ItemArray[3].ToString();
                ItemSize     = this.dataSet2.Tables[0].Rows[i].ItemArray[2].ToString();
                ItemQuantity = this.dataSet2.Tables[0].Rows[i].ItemArray[0].ToString();
                CatName      = this.dataSet2.Tables[1].Rows[i].ItemArray[1].ToString();

                Concat = CatName + " - " + ItemName + " - " + ItemSize;

                stringCollLenth = Concat.Length;

                if (Convert.ToDouble(ItemPrice) >= 10)
                {
                    SpaceMargin = "  ";
                }
                else if (Convert.ToDouble(ItemPrice) >= 100)
                {
                    SpaceMargin = " ";
                }
                else
                {
                    SpaceMargin = "   ";
                }
                if (stringCollLenth > 14)
                {
                    Split = SplitString(Concat);
                    graphics.DrawString(Split[0], new Font("Courier New", 8),
                                        new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);

                    graphics.DrawString(ItemPrice + SpaceMargin + "|" + SpaceMargin + ItemQuantity, new Font("Courier New", 8),
                                        new SolidBrush(Color.Black), startX - 245, startY + Offset);

                    Offset = Offset + 10;

                    graphics.DrawString(Split[1], new Font("Courier New", 8),
                                        new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);
                    Offset = Offset + 15;
                }
                else
                {
                    graphics.DrawString(Concat, new Font("Courier New", 8),
                                        new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);

                    graphics.DrawString(ItemPrice + SpaceMargin + "|" + SpaceMargin + ItemQuantity, new Font("Courier New", 8),
                                        new SolidBrush(Color.Black), startX - 245, startY + Offset);

                    Offset = Offset + 15;
                }
            }

            graphics.DrawString("--------------------------------------", new Font("Courier New", 8),
                                new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);

            Offset = Offset + 15;
#if DELIVERY
            graphics.DrawString("خدمة التوصيل", new Font("Courier New", fontwidth),
                                new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);

            graphics.DrawString(NewOrder.Order_GetDeliveryCharge().ToString(), new Font("Courier New", fontwidth),
                                new SolidBrush(Color.Black), startX - 245, startY + Offset);

            Offset = Offset + 15;
#endif

            graphics.DrawString("--------------------------------------", new Font("Courier New", 8),
                                new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);

            Offset = Offset + 15;

            graphics.DrawString("الإجمالي", new Font("Courier New", fontwidth, FontStyle.Bold),
                                new SolidBrush(Color.Black), startX + 15, startY + Offset, Rformat);

            graphics.DrawString(NewOrder.Order_GetOrderTotal().ToString(), new Font("Courier New", fontwidth, FontStyle.Bold),
                                new SolidBrush(Color.Black), startX - 245, startY + Offset);

            Offset = Offset + 40;

            graphics.DrawString("شكرا لزيارتكم مطعم" + "\n" + "    شيخ البلد", new Font("Courier New", 10, FontStyle.Bold),
                                new SolidBrush(Color.Black), startX - 40, startY + Offset, Rformat);

            Offset = Offset + 45;

            graphics.DrawString("خدمة التوصيل", new Font("Courier New", 10),
                                new SolidBrush(Color.Black), startX - 60, startY + Offset, Rformat);

            Offset = Offset + 30;

            graphics.DrawString("16748", new Font("Courier New", 20, FontStyle.Bold),
                                new SolidBrush(Color.Black), startX - 155, startY + Offset);
        }