public EmailClass fillSaleTempData(Invoice invoice, List <ItemTransfer> invoiceItems, List <PayedInvclass> mailpayedList, SysEmails email, Agent toAgent, List <SetValues> setvlist) { string invheader = ""; string invfooter = ""; string invbody = ""; string invitemtable = ""; string invitemrow = ""; string paytable = ""; string payrow = ""; string taxdiv = ""; string deliverydiv = ""; //payrow.tmp // paytable.tmp EmailClass mailtosend = new EmailClass(); ReportCls reportclass = new ReportCls(); mailtosend.from = email.email; mailtosend.smtpclient = email.smtpClient; mailtosend.port = (int)email.port; mailtosend.password = Encoding.UTF8.GetString(Convert.FromBase64String(email.password)); mailtosend.isSSl = (bool)email.isSSL; mailtosend.AddTolist(toAgent.email); string cashTr = ""; string sumP = ""; string deservedcash = ""; // data ReportCls repm = new ReportCls(); List <MailimageClass> imgs = new List <MailimageClass>(); MailimageClass img = new MailimageClass(); decimal disval = repm.calcpercentval(invoice.discountType, invoice.discountValue, invoice.total); decimal manualdisval = repm.calcpercentval(invoice.manualDiscountType, invoice.manualDiscountValue, invoice.total); invoice.discountValue = disval + manualdisval; invoice.discountType = "1"; bool isArabic = ReportCls.checkLang(); if (isArabic) { invheader = repm.ReadFile(@"EmailTemplates\ordertemplate\ar\invheader.tmp"); invfooter = repm.ReadFile(@"EmailTemplates\ordertemplate\ar\invfooter.tmp"); deliverydiv = repm.ReadFile(@"EmailTemplates\saletemplate\ar\deliverydiv.tmp"); if (invoice.invType == "s" || invoice.invType == "pw" || invoice.invType == "p") { invbody = repm.ReadFile(@"EmailTemplates\saletemplate\ar\invbody.tmp"); invitemtable = repm.ReadFile(@"EmailTemplates\saletemplate\ar\invitemtable.tmp"); invitemrow = repm.ReadFile(@"EmailTemplates\saletemplate\ar\invitemrow.tmp"); paytable = repm.ReadFile(@"EmailTemplates\saletemplate\ar\paytable.tmp"); payrow = repm.ReadFile(@"EmailTemplates\saletemplate\ar\payrow.tmp"); taxdiv = repm.ReadFile(@"EmailTemplates\saletemplate\ar\taxdiv.tmp"); } else if (invoice.invType == "or" || invoice.invType == "ors") { invbody = repm.ReadFile(@"EmailTemplates\saleordertemplate\ar\invbody.tmp"); invitemtable = repm.ReadFile(@"EmailTemplates\saleordertemplate\ar\invitemtable.tmp"); invitemrow = repm.ReadFile(@"EmailTemplates\saleordertemplate\ar\invitemrow.tmp"); } else if (invoice.invType == "q" || invoice.invType == "qs") { invbody = repm.ReadFile(@"EmailTemplates\quotationtemplate\ar\invbody.tmp"); invitemtable = repm.ReadFile(@"EmailTemplates\quotationtemplate\ar\invitemtable.tmp"); invitemrow = repm.ReadFile(@"EmailTemplates\quotationtemplate\ar\invitemrow.tmp"); } } else { // en invheader = repm.ReadFile(@"EmailTemplates\ordertemplate\en\invheader.tmp"); invfooter = repm.ReadFile(@"EmailTemplates\ordertemplate\en\invfooter.tmp"); deliverydiv = repm.ReadFile(@"EmailTemplates\saletemplate\en\deliverydiv.tmp"); if (invoice.invType == "s" || invoice.invType == "pw" || invoice.invType == "p") { invbody = repm.ReadFile(@"EmailTemplates\saletemplate\en\invbody.tmp"); invitemtable = repm.ReadFile(@"EmailTemplates\saletemplate\en\invitemtable.tmp"); invitemrow = repm.ReadFile(@"EmailTemplates\saletemplate\en\invitemrow.tmp"); paytable = repm.ReadFile(@"EmailTemplates\saletemplate\en\paytable.tmp"); payrow = repm.ReadFile(@"EmailTemplates\saletemplate\en\payrow.tmp"); taxdiv = repm.ReadFile(@"EmailTemplates\saletemplate\en\taxdiv.tmp"); } else if (invoice.invType == "or" || invoice.invType == "ors") { invbody = repm.ReadFile(@"EmailTemplates\saleordertemplate\en\invbody.tmp"); invitemtable = repm.ReadFile(@"EmailTemplates\saleordertemplate\en\invitemtable.tmp"); invitemrow = repm.ReadFile(@"EmailTemplates\saleordertemplate\en\invitemrow.tmp"); } else if (invoice.invType == "q" || invoice.invType == "qs") { invbody = repm.ReadFile(@"EmailTemplates\quotationtemplate\en\invbody.tmp"); invitemtable = repm.ReadFile(@"EmailTemplates\quotationtemplate\en\invitemtable.tmp"); invitemrow = repm.ReadFile(@"EmailTemplates\quotationtemplate\en\invitemrow.tmp"); } else { invbody = repm.ReadFile(@"EmailTemplates\saletemplate\en\invbody.tmp"); invitemtable = repm.ReadFile(@"EmailTemplates\saletemplate\en\invitemtable.tmp"); invitemrow = repm.ReadFile(@"EmailTemplates\saletemplate\en\invitemrow.tmp"); paytable = repm.ReadFile(@"EmailTemplates\saletemplate\en\paytable.tmp"); payrow = repm.ReadFile(@"EmailTemplates\saletemplate\en\payrow.tmp"); } } //header info invheader = invheader.Replace("[[companyname]]", MainWindow.companyName.Trim()); invheader = invheader.Replace("[[phone]]", MainWindow.Phone.Trim()); invheader = invheader.Replace("[[Email]]", MainWindow.Email.Trim()); invheader = invheader.Replace("[[fax]]", MainWindow.Fax.Trim()); invheader = invheader.Replace("[[address]]", MainWindow.Address.Trim()); invheader = invheader.Replace("[[trphone]]", MainWindow.resourcemanagerreport.GetString("trPhone").Trim() + ": "); invheader = invheader.Replace("[[trfax]]", MainWindow.resourcemanagerreport.GetString("trFax").Trim() + ": "); invheader = invheader.Replace("[[traddress]]", MainWindow.resourcemanagerreport.GetString("trAddress").Trim() + ": "); //BODY // string title = "Purchase Order"; string title = setvlist.Where(x => x.notes == "title").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "title").FirstOrDefault().value.ToString(); mailtosend.subject = title.Trim(); invheader = invheader.Replace("[[title]]", title.Trim()); invbody = invbody.Replace("[[thankstitle]]", title); // string thankstext = "Please provide to us,with a price list,along with your terms and conditions of sale, applicable discounts, shipping dates and additional sales and corporate policies. Should the information you provide be acceptable and competitive. "; string thankstext = setvlist.Where(x => x.notes == "text1").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "text1").FirstOrDefault().value.ToString(); invbody = invbody.Replace("[[thankstext]]", thankstext); if (invoice.invoiceId > 0) { if ((invoice.invType == "s" || invoice.invType == "sd" || invoice.invType == "sbd" || invoice.invType == "sb" || invoice.invType == "p" || invoice.invType == "pw")) { decimal sump = mailpayedList.Sum(x => x.cash).Value; decimal deservd = (decimal)invoice.totalNet - sump; cashTr = MainWindow.resourcemanagerreport.GetString("trCashType"); sumP = reportclass.DecTostring(sump); deservedcash = reportclass.DecTostring(deservd); invbody = invbody.Replace("[[payedsum]]", sumP); invbody = invbody.Replace("[[deservedcash]]", deservedcash); // paytable // foreach string datapayrows = ""; string paymethod = ""; payrow = payrow.Replace("[[currency]]", MainWindow.Currency); foreach (PayedInvclass row in mailpayedList) { string rowhtml = payrow; rowhtml = rowhtml.Replace("[[cashpayrow]]", reportclass.DecTostring(row.cash)); paymethod = row.processType == "cash" ? cashTr : row.cardName; rowhtml = rowhtml.Replace("[[paymethodrow]]", paymethod); datapayrows += rowhtml; } paytable = paytable.Replace("[[payrow]]", datapayrows); // end foreach invbody = invbody.Replace("[[paytable]]", paytable); } invbody = invbody.Replace("[[invoicecode]]", invoice.invNumber); invbody = invbody.Replace("[[invoicedate]]", repm.DateToString(invoice.invDate)); //invbody = invbody.Replace("[[invoicetotal]]", invoice.total.ToString()); invbody = invbody.Replace("[[invoicetotal]]", repm.DecTostring(invoice.total)); //invbody = invbody.Replace("[[invoicediscount]]", invoice.discountValue.ToString()); if (invoice.discountType == "2") { if (isArabic) { invbody = invbody.Replace("[[invoicediscount]]", "% " + repm.DecTostring(invoice.discountValue)); } else { invbody = invbody.Replace("[[invoicediscount]]", repm.DecTostring(invoice.discountValue) + " %"); } } else { if (isArabic) { invbody = invbody.Replace("[[invoicediscount]]", MainWindow.Currency + " " + repm.DecTostring(invoice.discountValue)); } else { invbody = invbody.Replace("[[invoicediscount]]", repm.DecTostring(invoice.discountValue) + " " + MainWindow.Currency); } } //invbody = invbody.Replace("[[invoicetax]]", invoice.tax.ToString()); if (invoice.tax == 0 || invoice.tax == null) { invbody = invbody.Replace("[[invoicetax]]", repm.DecTostring(invoice.tax)); invbody = invbody.Replace("[[trinvoicetax]]", MainWindow.resourcemanagerreport.GetString("trTax").Trim()); invbody = invbody.Replace("[[taxdiv]]", ""); } else { taxdiv = taxdiv.Replace("[[invoicetax]]", repm.DecTostring(invoice.tax)); taxdiv = taxdiv.Replace("[[trinvoicetax]]", MainWindow.resourcemanagerreport.GetString("trTax").Trim()); invbody = invbody.Replace("[[taxdiv]]", taxdiv); } //shipping cost section if ((invoice.invType == "s" || invoice.invType == "or" || invoice.invType == "q" || invoice.invType == "qs" || invoice.invType == "ors")) { if (invoice.shippingCost > 0) { deliverydiv = deliverydiv.Replace("[[shippingcost]]", repm.DecTostring(invoice.shippingCost)); deliverydiv = deliverydiv.Replace("[[totaldeserved]]", repm.DecTostring(invoice.totalNet)); invbody = invbody.Replace("[[totalnet]]", repm.DecTostring(invoice.totalNet - invoice.shippingCost)); invbody = invbody.Replace("[[deliverydiv]]", deliverydiv); } else { invbody = invbody.Replace("[[deliverydiv]]", ""); invbody = invbody.Replace("[[totalnet]]", repm.DecTostring(invoice.totalNet)); } } else { invbody = invbody.Replace("[[totalnet]]", repm.DecTostring(invoice.totalNet)); invbody = invbody.Replace("[[deliverydiv]]", ""); } // end shippingcost } // invoiceItems.trQuantity trQTR invitemtable = invitemtable.Replace("[[tritems]]", MainWindow.resourcemanagerreport.GetString("trItem").Trim()); invitemtable = invitemtable.Replace("[[trunit]]", MainWindow.resourcemanagerreport.GetString("trUnit").Trim()); invitemtable = invitemtable.Replace("[[trprice]]", MainWindow.resourcemanagerreport.GetString("trPrice").Trim()); invitemtable = invitemtable.Replace("[[trquantity]]", MainWindow.resourcemanagerreport.GetString("trQTR").Trim()); invitemtable = invitemtable.Replace("[[trtotalrow]]", MainWindow.resourcemanagerreport.GetString("trTotal").Trim()); invbody = invbody.Replace("[[trinvoicecode]]", MainWindow.resourcemanagerreport.GetString("trInvoiceNumber").Trim() + ": "); invbody = invbody.Replace("[[trinvoicedate]]", MainWindow.resourcemanagerreport.GetString("trDate").Trim() + ": "); // invbody = invbody.Replace("[[trinvoicetotal]]", MainWindow.resourcemanagerreport.GetString("trSum").Trim() + ": "); invbody = invbody.Replace("[[trinvoicetotal]]", MainWindow.resourcemanagerreport.GetString("trSum").Trim()); invbody = invbody.Replace("[[currency]]", MainWindow.Currency); // invbody = invbody.Replace("[[trinvoicediscount]]", MainWindow.resourcemanagerreport.GetString("trDiscount").Trim()); invbody = invbody.Replace("[[trtotalnet]]", MainWindow.resourcemanagerreport.GetString("trTotal").Trim()); // string invoicenote = "Thank you for your cooperation. We have also enclosed our procurement specifications and conditions for your review <br/> Sincerely"; string invoicenote = setvlist.Where(x => x.notes == "text2").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "text2").FirstOrDefault().value.ToString(); invbody = invbody.Replace("[[invoicenote]]", invoicenote); string link1 = setvlist.Where(x => x.notes == "link1text").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "link1text").FirstOrDefault().value.ToString(); string link2 = setvlist.Where(x => x.notes == "link2text").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "link2text").FirstOrDefault().value.ToString(); string link3 = setvlist.Where(x => x.notes == "link3text").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "link3text").FirstOrDefault().value.ToString(); invfooter = invfooter.Replace("[[support]]", link1); invfooter = invfooter.Replace("[[returnpolicy]]", link2); invfooter = invfooter.Replace("[[aboutus]]", link3); string link1url = setvlist.Where(x => x.notes == "link1url").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "link1url").FirstOrDefault().value.ToString(); string link2url = setvlist.Where(x => x.notes == "link2url").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "link2url").FirstOrDefault().value.ToString(); string link3url = setvlist.Where(x => x.notes == "link3url").FirstOrDefault() is null ? "" : setvlist.Where(x => x.notes == "link3url").FirstOrDefault().value.ToString(); invfooter = invfooter.Replace("[[supporturl]]", link1url); invfooter = invfooter.Replace("[[returnpolicyurl]]", link2url); invfooter = invfooter.Replace("[[aboutusurl]]", link3url); invfooter = invfooter.Replace("[[year]]", DateTime.Now.Year.ToString()); // invitemtable // foreach string datarows = ""; foreach (ItemTransfer row in invoiceItems) { string rowhtml = invitemrow; row.price = decimal.Parse(SectionData.DecTostring(row.price)); rowhtml = rowhtml.Replace("[[col1]]", row.itemName.Trim()); rowhtml = rowhtml.Replace("[[col2]]", row.unitName.Trim()); rowhtml = rowhtml.Replace("[[col3]]", row.price.ToString()); rowhtml = rowhtml.Replace("[[col4]]", row.quantity.ToString()); rowhtml = rowhtml.Replace("[[col5]]", (row.quantity * row.price).ToString()); // rowhtml = rowhtml.Replace("[[col4]]", (row.quantity * row.price).ToString()); datarows += rowhtml; } invitemtable = invitemtable.Replace("[[invitemrow]]", datarows); // end foreach invbody = invbody.Replace("[[invitemtable]]", invitemtable); string mailbody = invheader + invbody + invfooter; AlternateView htmlView = AlternateView.CreateAlternateViewFromString(mailbody, null, "text/html"); string testpath = repm.GetPath(@"EmailTemplates\mail.html"); // if (!File.Exists(testpath)) { // Create a file to write to. string createText = mailbody; File.WriteAllText(testpath, createText); } else { File.Delete(testpath); // Create a file to write to. string createText = mailbody; File.WriteAllText(testpath, createText); } img.path = repm.GetLogoImagePath(); img.imageId = "logo"; imgs.Add(img); img = new MailimageClass(); img.path = repm.GetPath(@"EmailTemplates\images\image-2.gif"); img.imageId = "image-2"; imgs.Add(img); foreach (MailimageClass row in imgs) { htmlView.LinkedResources.Add(mailtosend.Linkimage(@row.path, row.imageId)); } // mailtosend.htmlView = htmlView; return(mailtosend); }