public Graphics printCheck(string barcode, string head, List <ClassPrintCheck.groupProduct> lProduct, string total, string sumDiscount, List <ClassPrintCheck.Pays> LPay, decimal rendu, string footer, infoOfClient InfoOfClient, Graphics gt) { List <Rectangle> rect = new List <Rectangle>(); int x1 = 0; int y1 = 0; int W = 280 * 20; int H = 134 * 20; Rectangle FillRectangleImg = new Rectangle(x1, y1, W, H); y1 = H; H = 15 * head.Split('\n').Length * 20; String Head = head; Rectangle FillRectangleHead = new Rectangle(x1, y1, W, H); Font TextFontHead = new Font("Arial", 10); rect.Add(FillRectangleHead); String Duplicate = null; Rectangle FillRectangleDuplicate = new Rectangle(); if (this.Duplicate) { y1 = y1 + H; H = 25; Duplicate = "*** DUPLICATA ***"; FillRectangleDuplicate = new Rectangle(x1, y1, W, H); rect.Add(FillRectangleDuplicate); } y1 = y1 + H; H = 25; String Vente = "*** VENTE ***"; Rectangle FillRectangleVente = new Rectangle(x1, y1, W, H); rect.Add(FillRectangleVente); y1 = y1 + H; H = 20; ClassDrawElm de = new ClassDrawElm(); de.DrawElm(lProduct, x1, y1, out x1, out y1); H = 10; string Total__ = "__________________"; Rectangle FillRectangleTotal__ = new Rectangle(x1 + 135, y1 - 6, 150, H); rect.Add(FillRectangleTotal__); H = 20; String Total = "TOTAL :"; Rectangle FillRectangleTotal = new Rectangle(x1 + 145, y1 + 1, 70, H); String Total_ = total; Rectangle FillRectangleTotal_ = new Rectangle(x1 + 210, y1, 70, H); y1 = y1 + H; W = 280; H = 20; de.DrawPaiements(LPay, x1, y1 + 5, out x1, out y1); W = 280; H = 15; String Rendu = "Rendu :"; Rectangle FillRectangleRendu = new Rectangle(x1 + 20, y1, 140, H); Font TFontRendu = new Font("Arial", 9); rect.Add(FillRectangleRendu); String RenduVal = rendu.ToString("0.00 €"); Rectangle FillRectangleRenduVal = new Rectangle(x1 + 170, y1, 90, H); rect.Add(FillRectangleRenduVal); y1 = y1 + H; H = 25; String TitleTVA = "*** TVA ***"; Rectangle FillRectangleTitleTVA = new Rectangle(x1, y1, W, H); rect.Add(FillRectangleTitleTVA); y1 = y1 + H; de.DrawTva(x1, y1, out x1, out y1); String TitleRemise = null; String Discount = null; String Discount_ = null; Rectangle FillRectangleTitleRemise = new Rectangle(); Rectangle FillRectangleDiscount = new Rectangle(); Rectangle FillRectangleDiscount_ = new Rectangle(); if (Decimal.Parse(sumDiscount) > 0) { y1 = y1 + H; W = 280; H = 20; TitleRemise = "*** REMISE ***"; FillRectangleTitleRemise = new Rectangle(x1, y1, W, H); rect.Add(FillRectangleTitleRemise); y1 = y1 + H; W = 280; H = 20; Discount = "Total remise sur ce ticket : "; FillRectangleDiscount = new Rectangle(x1, y1, 200, H); Discount_ = sumDiscount; FillRectangleDiscount_ = new Rectangle(x1 + 200, y1, 80, H); } #region INFO OF CLIENT String DCBC_name = null; String DCBC_BiloPoints = null; String DCBC_BiloPoints_ = null; String DobavilePoints = null; String DobavilePoints_ = null; String OtnayliP = null; String OtnayliP_ = null; String OstalosPoints = null; String OstalosPoints_ = null; String TCarte = null; Rectangle FillRectangleDCBC_name = new Rectangle(); Rectangle FillRectangleDCBC_BiloPoints = new Rectangle(); Rectangle FillRectangleDCBC_BiloPoints_ = new Rectangle(); Rectangle FillRectangleDobavilePoints = new Rectangle(); Rectangle FillRectangleDobavilePoints_ = new Rectangle(); Rectangle FillRectangleOtnayliP = new Rectangle(); Rectangle FillRectangleOtnayliP_ = new Rectangle(); Rectangle FillRectangleOstalosPoints_ = new Rectangle(); Rectangle FillRectangleOstalosPoints = new Rectangle();; Rectangle FillRectangleTCarte = new Rectangle(); if (InfoOfClient != null) { y1 = y1 + H; W = 280; H = 20; TCarte = "*** CARTE FIDELITE ***"; FillRectangleTCarte = new Rectangle(x1, y1, W, H); rect.Add(FillRectangleTCarte); y1 = y1 + H; W = 280; H = 20; DCBC_name = InfoOfClient.DCBC_name + " - " + InfoOfClient.DCBC; FillRectangleDCBC_name = new Rectangle(x1, y1, W, H); y1 = y1 + H; W = 280; H = 12; DCBC_BiloPoints = "Ancien solde de points : "; FillRectangleDCBC_BiloPoints = new Rectangle(x1, y1, 180, H); DCBC_BiloPoints_ = InfoOfClient.DCBC_BiloPoints.ToString(); FillRectangleDCBC_BiloPoints_ = new Rectangle(x1 + 180, y1, 80, H); y1 = y1 + H; W = 280; H = 12; DobavilePoints = "Points fidelité acquis : "; FillRectangleDobavilePoints = new Rectangle(x1, y1, 180, H); DobavilePoints_ = InfoOfClient.DCBC_DobavilePoints.ToString(); FillRectangleDobavilePoints_ = new Rectangle(x1 + 180, y1, 80, H); /* y1 = y1 + H; * W = 280; * H = 20; * * OtnayliP = "Сколько отняли"; * FillRectangleOtnayliP = new Rectangle(x1, y1, 200, H); * OtnayliP_ = InfoOfClient.DCBC_OtnayliP.ToString(); * FillRectangleOtnayliP_ = new Rectangle(x1 + 200, y1, 80, H); */ y1 = y1 + H; W = 280; H = 12; OstalosPoints = "Nouveau solde de points : "; FillRectangleOstalosPoints = new Rectangle(x1, y1, 180, H); OstalosPoints_ = InfoOfClient.DCBC_OstalosPoints.ToString(); FillRectangleOstalosPoints_ = new Rectangle(x1 + 180, y1, 80, H); } #endregion y1 = y1 + H; W = 260; H = 40; Rectangle FillRectangleBarCodeImg = new Rectangle(x1 + 10, y1 + 5, W, H); y1 = y1 + H + 5; W = 280; H = 30; String NumeroTicket = barcode.ToString() + Environment.NewLine + ClassGlobalVar.nameTicket + " - " + DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToShortTimeString(); Rectangle FillRectangleNumeroTicket = new Rectangle(x1, y1, W, H); y1 = y1 + H; W = 280; H = 20 * footer.Split('\n').Length;; String Footer = footer; Rectangle FillRectangleFooter = new Rectangle(x1, y1, W, H); y1 = y1 + 20; Font TextFont = new Font("Arial", 9); SolidBrush TextBrush = new SolidBrush(Color.Black); StringFormat TextFormatL = new StringFormat(); TextFormatL.Alignment = StringAlignment.Near; TextFormatL.LineAlignment = StringAlignment.Center; StringFormat TextFormatR = new StringFormat(); TextFormatR.Alignment = StringAlignment.Far; TextFormatR.LineAlignment = StringAlignment.Center; StringFormat TextFormatC = new StringFormat(); TextFormatC.Alignment = StringAlignment.Center; TextFormatC.LineAlignment = StringAlignment.Center; /*Total VENTE*/ Font TFontTotal = new Font("Arial", 10, FontStyle.Bold); /*Title*/ Font TFontTitle = new Font("Arial", 12, FontStyle.Bold); StringFormat TFormatTitle = new StringFormat(); TFormatTitle.Alignment = StringAlignment.Center; TFormatTitle.LineAlignment = StringAlignment.Center; /* Arial , 8 , Bold*/ Font TFontArialBold = new Font("Arial", 8, FontStyle.Bold); StringFormat TextFormat___ = new StringFormat(); TextFormat___.Alignment = StringAlignment.Far; TextFormat___.LineAlignment = StringAlignment.Far; int nWidth = W, nHeight = y1; Bitmap b1 = new Bitmap(nWidth, nHeight); using (Graphics g = Graphics.FromImage(b1)) { g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; foreach (ClassDrawElm.elm e in de.listEl) { g.DrawString(e.text, e.font, TextBrush, e.rectangle, e.stringFormat); rect.Add(e.rectangle); } g.DrawString(TitleTVA, TFontTitle, TextBrush, FillRectangleTitleTVA, TFormatTitle); foreach (ClassDrawElm.elm e in de.listTVA) { g.DrawString(e.text, e.font, TextBrush, e.rectangle, e.stringFormat); rect.Add(e.rectangle); } foreach (ClassDrawElm.elm e in de.LPay) { g.DrawString(e.text, e.font, TextBrush, e.rectangle, e.stringFormat); rect.Add(e.rectangle); } // Pen pen = new Pen(TextBrush, 1.0F); // g.DrawRectangles(pen, rect.ToArray()); // g.DrawImage((Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + "\\images\\anahit_9.jpg")), FillRectangleImg); g.DrawString(head, TFontRendu, TextBrush, FillRectangleHead, TextFormatC); if (Duplicate != null) { g.DrawString(Duplicate, TFontTitle, TextBrush, FillRectangleDuplicate, TFormatTitle); } g.DrawString(Vente, TFontTitle, TextBrush, FillRectangleVente, TFormatTitle); g.DrawString(Total__, TFontTotal, TextBrush, FillRectangleTotal__, TextFormat___); g.DrawString(Total, TFontTotal, TextBrush, FillRectangleTotal, TextFormatL); g.DrawString(Total_, TFontTotal, TextBrush, FillRectangleTotal_, TextFormatR); if (rendu != 0.0m) { g.DrawString(Rendu, TFontRendu, TextBrush, FillRectangleRendu, TextFormatL); g.DrawString(RenduVal, TFontRendu, TextBrush, FillRectangleRenduVal, TextFormatR); } if (Decimal.Parse(sumDiscount) > 0) { g.DrawString(TitleRemise, TFontTitle, TextBrush, FillRectangleTitleRemise, TFormatTitle); g.DrawString(Discount, TFontArialBold, TextBrush, FillRectangleDiscount, TextFormatL); g.DrawString(Discount_, TFontArialBold, TextBrush, FillRectangleDiscount_, TextFormatR); } if (InfoOfClient != null) { g.DrawString(TCarte, TFontTitle, TextBrush, FillRectangleTCarte, TFormatTitle); g.DrawString(DCBC_name, TFontRendu, TextBrush, FillRectangleDCBC_name, TextFormatL); g.DrawString(DCBC_BiloPoints, TFontRendu, TextBrush, FillRectangleDCBC_BiloPoints, TextFormatL); g.DrawString(DobavilePoints, TFontRendu, TextBrush, FillRectangleDobavilePoints, TextFormatL); g.DrawString(OtnayliP, TFontRendu, TextBrush, FillRectangleOtnayliP, TextFormatL); g.DrawString(OstalosPoints, TFontRendu, TextBrush, FillRectangleOstalosPoints, TextFormatL); g.DrawString(DCBC_BiloPoints_, TFontRendu, TextBrush, FillRectangleDCBC_BiloPoints_, TextFormatL); g.DrawString(DobavilePoints_, TFontRendu, TextBrush, FillRectangleDobavilePoints_, TextFormatL); g.DrawString(OtnayliP_, TFontRendu, TextBrush, FillRectangleOtnayliP_, TextFormatL); g.DrawString(OstalosPoints_, TFontRendu, TextBrush, FillRectangleOstalosPoints_, TextFormatL); } g.DrawImage(new ClassImageBarCode().get_bc(barcode), FillRectangleBarCodeImg); g.DrawString(NumeroTicket, TFontRendu, TextBrush, FillRectangleNumeroTicket, TextFormatC); g.DrawString(Footer, TextFont, TextBrush, FillRectangleFooter, TextFormatL); } b1.Save("D:\\test.bmp"); printimage(CreateBitmapSourceFromBitmap(b1)); return(gt); }
public ClassPrintCheck(XDocument b, bool Duplicate) { this.Duplicate = Duplicate; listProduct = new List <groupProduct>(); tva = new List <string>(); foreach (var p in ClassSync.TypesPayDB.t) { XAttribute a = b.Element("check").Attribute(p.NameCourt.TrimEnd().TrimStart()); if (a != null) { string money = a.Value.Replace(".", ","); attr.Add(new Pays(p, decimal.Parse(money))); } } rendu = decimal.Parse(b.Element("check").Attribute("Rendu").Value.Replace(".", ",")); IEnumerable <XElement> xe = b.Element("check").Elements("product"); decimal sum = 0.0m; decimal sumDiscounts = 0.0m; foreach (XElement e in xe) { decimal Discount = decimal.Parse(e.Element("Discount").Value.Replace(".", ",")); decimal sumDiscount = -decimal.Parse(e.Element("sumDiscount").Value.Replace(".", ",")); string codebare = e.Element("CodeBare").Value.TrimEnd().TrimStart().Trim(); decimal qty = decimal.Parse(e.Element("qty").Value.Replace(".", ",")); string name = e.Element("Name").Value; decimal total = decimal.Parse(e.Element("total").Value.Replace(".", ",")) - sumDiscount; decimal price = decimal.Parse(e.Element("price").Value.Replace(".", ",")); string categories = ClassGroupProduct.getName(int.Parse(e.Element("grp").Value)); int tva_ = int.Parse(e.Element("tva").Value); Guid customerId = Guid.Parse(e.Element("CustumerId").Value); groupProduct.product p = new groupProduct.product(customerId, categories, codebare, name, qty, total, price, tva_, Discount, sumDiscount); #region DISCOUNT if (Discount > 0) { string discountcategories = "Remise " + p.procentDiscount + "%"; int discountIndx = listProduct.FindIndex(l => l.categories == discountcategories); if (discountIndx == -1) { groupProduct.product pn = new groupProduct.product(Guid.Empty, discountcategories, barcode, name, qty, total, price, tva_, Discount, sumDiscount); listProduct.Add(new groupProduct(discountcategories, pn)); } else { // groupProduct.product pn = new groupProduct.product(Guid.Empty, discountcategories, "", name, 1, sumDiscount, 0, tva_, Discount, sumDiscount); groupProduct.product pn = new groupProduct.product(Guid.Empty, discountcategories, barcode, name, qty, total, price, tva_, Discount, sumDiscount); int repeat = listProduct[discountIndx].products.FindIndex((l => ((l.name == name)))); if (repeat != -1) { listProduct[discountIndx].products[repeat].total += pn.sumDiscount; listProduct[discountIndx].products[repeat].price = pn.price; listProduct[discountIndx].products[repeat].TvaTotal += pn.TvaTotal; listProduct[discountIndx].products[repeat].HT += pn.HT; listProduct[discountIndx].products[repeat].sumDiscount += pn.sumDiscount; } else { listProduct[discountIndx].products.Add(pn); } } sumDiscounts -= sumDiscount; } #endregion int indx = listProduct.FindIndex(l => l.categories == p.categories); if (indx != -1) { int f = -1; f = listProduct[indx].products.FindIndex(l => ((l.customerId == p.customerId) && l.price == p.price)); if (f == -1) { listProduct[indx].products.Add(p); } else { if (listProduct[indx].products[f].categories != "Remise " + p.procentDiscount + "%") { listProduct[indx].products[f].qty += p.qty; listProduct[indx].products[f].total += p.total; listProduct[indx].products[f].price = p.price; listProduct[indx].products[f].TvaTotal += p.TvaTotal; listProduct[indx].products[f].HT += p.HT; listProduct[indx].products[f].sumDiscount += p.sumDiscount; } } } else { listProduct.Add(new groupProduct(categories, p)); } sum += total; } listProduct = listProduct.OrderBy(l => l.categories).ToList(); List <groupProduct> listProductDiscount = listProduct.FindAll(l => l.categories.IndexOf("Discount") != -1); listProduct.RemoveAll(l => l.categories.IndexOf("Discount") != -1); List <groupProduct> listProductDiscountRemise = listProduct.FindAll(l => l.categories.IndexOf("Remise") != -1); listProduct.RemoveAll(l => l.categories.IndexOf("Remise") != -1); listProduct.AddRange(listProductDiscount); listProduct.AddRange(listProductDiscountRemise); head = File.ReadAllText(pathH); footer = File.ReadAllText(pathF); barcode = b.Element("check").Attribute("barcodeCheck").Value; totals = (sum - sumDiscounts).ToString("0.00"); sumDiscount_ = sumDiscounts.ToString("0.00"); #region DiscountPoints XAttribute a0 = b.Element("check").Attribute("DCBC"); XAttribute a1 = b.Element("check").Attribute("DCBC_BiloPoints"); XAttribute a2 = b.Element("check").Attribute("DCBC_DobavilePoints"); XAttribute a3 = b.Element("check").Attribute("DCBC_OtnayliPoints"); XAttribute a4 = b.Element("check").Attribute("DCBC_OstalosPoints"); XAttribute a5 = b.Element("check").Attribute("DCBC_name"); string BCDC = (a0 != null ? a0.Value : null); if ((BCDC != null) && (BCDC != "")) { c = new infoOfClient { DCBC = a0.Value, DCBC_BiloPoints = a1.Value, DCBC_DobavilePoints = a2.Value, DCBC_OtnayliP = a3.Value, DCBC_OstalosPoints = a4.Value, DCBC_name = a5.Value }; } #endregion ClassDotLiquid.prt(barcode, head, listProduct, totals, sumDiscount_, attr, rendu, footer, c, Duplicate); }