public static string GenerateString() { // Templates var classGenerationTemplates = ReadTemplates.Read(); return(classGenerationTemplates.CachedEntityObject); }
public static string GenerateString( ClassStatement classStatement ) { // Templates var classGenerationTemplates = ReadTemplates.Read(); return(classGenerationTemplates.ClassShim.Replace( "[[CLASS_NAME]]", classStatement.Name )); }
private void SendEmailConfirmation() { try { string dr = Request["dr"].ToString(); if (dr == "d") { dr = "Disconnect"; } else { dr = "Reconnect"; } UserName = Session[enumSessions.User_Name.ToString()].ToString(); UserEmail = Session[enumSessions.User_Email.ToString()].ToString(); CompanyName = GetARCName(Session[enumSessions.ARC_Id.ToString()].ToString()); using (db = new LinqToSqlDataContext()) { // ** NOn-edited ones var DrData = from d in db.DRs join ins in db.Installers on d.Installer equals ins.InstallerCompanyID.ToString() where d.UserId == Session[enumSessions.User_Id.ToString()].ToString() && d.Emailed == false && d.ISEmizonUnit == false && d.FreeTextEntry != true orderby d.DrId select new { d.Reason, d.Simno, d.Datano, d.Chipno, d.Installer, ins.CompanyName }; if (DrData.Any()) { String EmailDevicelist = "<table cellspacing='1' cellpadding='1' border='1' Width=\"60%\"><tr ><td style=\"color: #888;\"><b>Request Type</b></td><td style=\"color: #888;\"><b>Reason</b></td><td style=\"color: #888;\"><b>ESN/SIM</b></td><td style=\"color: #888;\"><b>NUA/Data</b></td><td style=\"color: #888;\"><b>Chip Number</b></td><td style=\"color: #888;\"><b>Installer</b></td></tr>"; foreach (var d in DrData) { EmailDevicelist += "<tr>"; if (dr == "Reconnect") { EmailDevicelist += "<td td style=\"color: #45b010;\">" + dr + "</td>"; //green } else if (dr == "Disconnect") { EmailDevicelist += "<td td style=\"color: #f64114;\">" + dr + "</td>"; //red } string szReason = ""; if (Request["dr"].ToString() == "r") { szReason = "n/a"; } else { szReason = d.Reason; } EmailDevicelist += "<td>" + szReason + "</td>"; EmailDevicelist += "<td>" + d.Simno + "</td>"; EmailDevicelist += "<td>" + d.Datano + "</td>"; EmailDevicelist += "<td>" + d.Chipno + "</td>"; EmailDevicelist += "<td>" + GetInstallerName(d.Installer) + "</td>"; EmailDevicelist += "</tr>"; } EmailDevicelist += "</table>"; String mailHtml = ReadTemplates.ReadMailTemplate(Server.MapPath("Template"), "EmailGrade.html"); StringBuilder objBuilder = new StringBuilder(); objBuilder.Append(mailHtml); objBuilder.Replace("{UserName}", UserName); objBuilder.Replace("{ArcName}", CompanyName); objBuilder.Replace("{UserEmail}", UserEmail); objBuilder.Replace("{DateofRequest}", DateTime.Now.ToString()); objBuilder.Replace("{Devicelist}", EmailDevicelist); string szMess = ""; if (Request["dr"].ToString() == "r") { szMess = "Reconnection Request"; } else { szMess = "Disconnection Request"; } SendEmailMessage sendEmail = new SendEmailMessage(); EmailMessage cslEmailMessage = new EmailMessage(); cslEmailMessage.From = mailFrom; cslEmailMessage.To = UserEmail + ";" + (Request["dr"].ToString() == "r" ? mailTO : string.Empty); cslEmailMessage.CC = mailCC + ";" + GetArcCcEmail(Session[enumSessions.ARC_Id.ToString()].ToString()); cslEmailMessage.BCC = ""; cslEmailMessage.Subject = szMess; cslEmailMessage.Message = Convert.ToString(objBuilder.ToString()); //adding emails to MSMQ sendEmail.SendEmailMessageToQueue(ConfigurationManager.AppSettings["QueueName"].ToString(), cslEmailMessage); } // ** Free Text ones var DrDataFreeText = from d in db.DRs join ins in db.Installers on d.Installer equals ins.InstallerCompanyID.ToString() where d.UserId == Session[enumSessions.User_Id.ToString()].ToString() && d.Emailed == false && d.ISEmizonUnit == false && d.FreeTextEntry == true orderby d.DrId select new { d.Reason, d.Simno, d.Datano, d.Chipno, d.Installer, ins.CompanyName }; if (DrDataFreeText.Any()) { String EmailDevicelistFreeText = "<table cellspacing='1' cellpadding='1' border='1' Width=\"60%\"><tr ><td style=\"color: #888;\"><b>Request Type</b></td><td style=\"color: #888;\"><b>Reason</b></td><td style=\"color: #888;\"><b>ESN/SIM</b></td><td style=\"color: #888;\"><b>NUA/Data</b></td><td style=\"color: #888;\"><b>Chip Number</b></td><td style=\"color: #888;\"><b>Installer</b></td></tr>"; foreach (var d in DrDataFreeText) { EmailDevicelistFreeText += "<tr>"; if (dr == "Reconnect") { EmailDevicelistFreeText += "<td td style=\"color: #45b010;\">" + dr + "</td>"; //green } else if (dr == "Disconnect") { EmailDevicelistFreeText += "<td td style=\"color: #f64114;\">" + dr + "</td>"; //red } string szReason = ""; if (Request["dr"].ToString() == "r") { szReason = "n/a"; } else { szReason = d.Reason; } EmailDevicelistFreeText += "<td>" + szReason + "</td>"; EmailDevicelistFreeText += "<td>" + d.Simno + "</td>"; EmailDevicelistFreeText += "<td>" + d.Datano + "</td>"; EmailDevicelistFreeText += "<td>" + d.Chipno + "</td>"; EmailDevicelistFreeText += "<td>" + GetInstallerName(d.Installer) + "</td>"; EmailDevicelistFreeText += "</tr>"; } EmailDevicelistFreeText += "</table>"; String mailHtmlFreeText = ReadTemplates.ReadMailTemplate(Server.MapPath("Template"), "EmailGrade.html"); StringBuilder objBuilderFreeText = new StringBuilder(); objBuilderFreeText.Append(mailHtmlFreeText); objBuilderFreeText.Replace("{UserName}", UserName); objBuilderFreeText.Replace("{ArcName}", CompanyName); objBuilderFreeText.Replace("{UserEmail}", UserEmail); objBuilderFreeText.Replace("{DateofRequest}", DateTime.Now.ToString()); objBuilderFreeText.Replace("{Devicelist}", EmailDevicelistFreeText); string szMessFreeText = ""; if (Request["dr"].ToString() == "r") { szMessFreeText = "Reconnection Request"; } else { szMessFreeText = "Disconnection Request"; } SendEmailMessage sendEmailFreeText = new SendEmailMessage(); EmailMessage cslEmailMessageFreeText = new EmailMessage(); cslEmailMessageFreeText.From = mailFrom; cslEmailMessageFreeText.To = UserEmail; cslEmailMessageFreeText.CC = mailTO + ";" + mailCC + ";" + GetArcCcEmail(Session[enumSessions.ARC_Id.ToString()].ToString()); cslEmailMessageFreeText.BCC = ""; cslEmailMessageFreeText.Subject = szMessFreeText; cslEmailMessageFreeText.Message = Convert.ToString(objBuilderFreeText.ToString()); //adding emails to MSMQ sendEmailFreeText.SendEmailMessageToQueue(ConfigurationManager.AppSettings["QueueName"].ToString(), cslEmailMessageFreeText); } var upData = (from data in db.DRs where data.UserId == Session[enumSessions.User_Id.ToString()].ToString() && data.Emailed == false && data.ISEmizonUnit == false select data); foreach (var r in upData) { r.Emailed = true; } db.SubmitChanges(); // ** Flag Emizon units var EmizonUnits = (from data in db.DRs where data.UserId == Session[enumSessions.User_Id.ToString()].ToString() && data.ISEmizonUnit == true select data); if (EmizonUnits.Any()) { foreach (var r in EmizonUnits) { r.AwaitingtobeProcessed = true; } db.SubmitChanges(); } } pnlForm.Visible = false; pnlConfirm.Visible = true; divuc1.Visible = false; divuc2.Visible = false; txtChipNo.Text = ""; } catch (Exception objException) { using (db = new LinqToSqlDataContext()) { db.USP_SaveErrorDetails(Request.Url.ToString(), "btnSubmit_Click", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()])); } } }
public static void SetReadTemplates() { var templatesPath = "EventHorizon.Blazor.Interop.Generator.Templates"; // Class Template var classTemplate = ReadAllText( $"{templatesPath}.ClassTemplate.txt" ); // Class Shim Template var classShimTemplate = ReadAllText( $"{templatesPath}.ClassShimTemplate.txt" ); // Cached Entity Object Template var cachedEntityObjectTemplate = ReadAllText( $"{templatesPath}.CachedEntityObjectTemplate.txt" ); // Accessor/Property Template var accessorTemplate = ReadAllText($"{templatesPath}.AccessorTemplate.txt" ); // Accessor/Property With Setter Template var accessorWithSetterTemplate = ReadAllText( $"{templatesPath}.AccessorWithSetterTemplate.txt" ); // Constructor Template var constructorTemplate = ReadAllText( $"{templatesPath}.ConstructorTemplate.txt" ); // Constructor To Base Template var constructorToBaseTemplate = ReadAllText( $"{templatesPath}.ConstructorToBaseTemplate.txt" ); // Constructor With Arguments Template var constructorWithArgumentsTemplate = ReadAllText( $"{templatesPath}.ConstructorWithArgumentsTemplate.txt" ); // Method Template var methodTemplate = ReadAllText( $"{templatesPath}.MethodTemplate.txt" ); var methodActionTemplate = ReadAllText( $"{templatesPath}.MethodActionTemplate.txt" ); var methodStaticActionTemplate = ReadAllText( $"{templatesPath}.MethodStaticActionTemplate.txt" ); var returnTypePrimitiveTemplate = ReadAllText( $"{templatesPath}.ReturnTypePrimitiveTemplate.txt" ); var returnTypeClassTemplate = ReadAllText( $"{templatesPath}.ReturnTypeClassTemplate.txt") ; var returnTypeVoidTemplate = ReadAllText( $"{templatesPath}.ReturnTypeVoidTemplate.txt" ); // Interop Templates var interopGetTemplate = ReadAllText( $"{templatesPath}.InteropGetTemplate.txt" ); var interopSetTemplate = ReadAllText( $"{templatesPath}.InteropSetTemplate.txt" ); var interopFuncTemplate = ReadAllText( $"{templatesPath}.InteropFuncTemplate.txt" ); var interopFuncArrayTemplate = ReadAllText( $"{templatesPath}.InteropFuncArrayTemplate.txt" ); var interopFuncClassTemplate = ReadAllText( $"{templatesPath}.InteropFuncClassTemplate.txt" ); var interopFuncArrayClassTemplate = ReadAllText( $"{templatesPath}.InteropFuncArrayClassTemplate.txt" ); var interopGetArrayClassTemplate = ReadAllText( $"{templatesPath}.InteropGetArrayClassTemplate.txt" ); var interopGetArrayTemplate = ReadAllText( $"{templatesPath}.InteropGetArrayTemplate.txt" ); var interopGetClassTemplate = ReadAllText( $"{templatesPath}.InteropGetClassTemplate.txt" ); var generatedTemplates = ReadTemplates.Read(); generatedTemplates.Class = classTemplate; generatedTemplates.ClassShim = classShimTemplate; generatedTemplates.CachedEntityObject = cachedEntityObjectTemplate; generatedTemplates.Accessor = accessorTemplate; generatedTemplates.AccessorWithSetter = accessorWithSetterTemplate; generatedTemplates.Constructor = constructorTemplate; generatedTemplates.ConstructorToBase = constructorToBaseTemplate; generatedTemplates.ConstructorWithArgumentsTemplate = constructorWithArgumentsTemplate; generatedTemplates.Method = methodTemplate; generatedTemplates.MethodActionTemplate = methodActionTemplate; generatedTemplates.MethodStaticActionTemplate = methodStaticActionTemplate; generatedTemplates.ReturnTypePrimitiveTemplate = returnTypePrimitiveTemplate; generatedTemplates.ReturnTypeClass = returnTypeClassTemplate; generatedTemplates.ReturnTypeVoidTemplate = returnTypeVoidTemplate; generatedTemplates.InteropFunc = interopFuncTemplate; generatedTemplates.InteropFuncClass = interopFuncClassTemplate; generatedTemplates.InteropFuncArray = interopFuncArrayTemplate; generatedTemplates.InteropFuncArrayClass = interopFuncArrayClassTemplate; generatedTemplates.InteropGetArrayClass = interopGetArrayClassTemplate; generatedTemplates.InteropGetArray = interopGetArrayTemplate; generatedTemplates.InteropGetClass = interopGetClassTemplate; generatedTemplates.InteropGet = interopGetTemplate; generatedTemplates.InteropSet = interopSetTemplate; }
public static string Generate( ClassStatement classStatement, TextFormatter textFormatter ) { var classTokenMap = new Dictionary <string, string> { { "[[INTERFACE_SECTION]]", string.Empty }, { "[[EXTENDED_CLASSES_SECTION]]", string.Empty }, { "[[WHERE_CONSTRAINT]]", string.Empty }, { "[[CLASS_GENERICS]]", string.Empty }, { "[[STATIC_ACCESSORS]]", string.Empty }, { "[[STATIC_PROPERTIES]]", string.Empty }, { "[[STATIC_METHODS]]", string.Empty }, { "[[ACCESSORS]]", string.Empty }, { "[[PROPERTIES]]", string.Empty }, { "[[CONSTRUCTOR]]", string.Empty }, { "[[METHODS]]", string.Empty }, { "[[ASSEMBLY]]", classStatement.ProjectAssembly }, { "[[CLASS_NAME]]", string.Empty }, { "[[NAMESPACE]]", string.Empty }, { "[[BASE_CONSTRUCTOR]]", string.Empty }, { "[[INTERFACE_POSTFIX]]", string.Empty }, }; // Group Parts of the Class var staticAccessors = classStatement.AccessorStatements.Where(a => a.IsStatic); var staticProperties = classStatement.PublicPropertyStatements.Where(a => a.IsStatic); var staticMethods = classStatement.PublicMethodStatements.Where(a => a.IsStatic).Distinct(); var accessors = classStatement.AccessorStatements.Where(a => !a.IsStatic); var properties = classStatement.PublicPropertyStatements.Where(a => !a.IsStatic); var constructorDetails = classStatement.ConstructorStatement; var methods = classStatement.PublicMethodStatements.Where(a => !a.IsStatic).Distinct(); // Templates var classGenerationTemplates = ReadTemplates.Read(); var classTemplate = classGenerationTemplates.Class; // Generate Tokens var namespaceReplaced = classStatement.Namespace; if (string.IsNullOrWhiteSpace(namespaceReplaced)) { namespaceReplaced = string.Empty; classTemplate = classGenerationTemplates.ClassWithNoNamespace; } classTokenMap["[[NAMESPACE]]"] = namespaceReplaced; classTokenMap["[[CLASS_NAME]]"] = classStatement.Name; classTokenMap["[[INTERFACE_SECTION]]"] = InterfaceSectionWriter.Write( classStatement, classGenerationTemplates ); classTokenMap["[[INTERFACE_POSTFIX]]"] = classStatement.IsInterface ? Constants.INTERFACE_POSTFIX : string.Empty; classTokenMap["[[CLASS_GENERICS]]"] = BuildClassGenerics( classStatement ); classTokenMap["[[JSON_CONVERTER_CLASS_GENERICS]]"] = BuildJsonConvertClassGenerics( classStatement ); classTokenMap["[[EXTENDED_CLASSES_SECTION]]"] = BuildExtendedClassesSection( classStatement ); classTokenMap["[[WHERE_CONSTRAINT]]"] = classStatement.GenericTypes.Any() ? string.Join( "", classStatement.GenericTypes.Select( genericType => $" where {genericType.Name} : CachedEntity, new()" ) ) : string.Empty; classTokenMap["[[STATIC_ACCESSORS]]"] = AccessorsSectionWriter.Write( classStatement, staticAccessors, classGenerationTemplates ); classTokenMap["[[STATIC_PROPERTIES]]"] = PropertiesSectionWriter.Write( classStatement, staticProperties, classGenerationTemplates ); classTokenMap["[[STATIC_METHODS]]"] = MethodsSectionWriter.Write( classStatement, staticMethods, classGenerationTemplates ); classTokenMap["[[ACCESSORS]]"] = AccessorsSectionWriter.Write( classStatement, accessors, classGenerationTemplates ); classTokenMap["[[PROPERTIES]]"] = PropertiesSectionWriter.Write( classStatement, properties, classGenerationTemplates ); classTokenMap["[[CONSTRUCTOR]]"] = ConstructorSectionWriter.Write( classStatement, constructorDetails, classGenerationTemplates ); classTokenMap["[[BASE_CONSTRUCTOR]]"] = BaseConstructorSectionWriter.Write( classStatement, constructorDetails, classGenerationTemplates ); classTokenMap["[[METHODS]]"] = MethodsSectionWriter.Write( classStatement, methods, classGenerationTemplates ); var classStringBuilder = new StringBuilder( classTemplate ); classStringBuilder = classTokenMap.Aggregate( classStringBuilder, (acc, token) => acc.Replace( token.Key, token.Value ) ); return(textFormatter.Format( classStringBuilder.ToString() )); }
public static void SendEmailWithPrice(string OrderNo, string mailTO, SendEmailDTO sendEmailDTO, string mailFrom, string mailCC, bool isEmailFromViewOrders, bool?hasEmizonProducts, int orderID) { try { String ProductsList = ""; bool instadd_differs = false; string subjectsuffix = string.Empty; string templatePath = "Template"; SendEmailMessage sendEmail = new SendEmailMessage(); EmailMessage cslEmailMessage = new EmailMessage(); string emizonQueuePath = ConfigurationManager.AppSettings["EmizonQueue"].ToString();//could have used AppSettings but no point as another one is using config string mailSubject = "Order Confirmation - Order Ref: " + OrderNo; if (isEmailFromViewOrders) { if (mailTO.EndsWith("@csldual.com")) { subjectsuffix = "; Email Resent"; } mailSubject = mailSubject + subjectsuffix; templatePath = "../Template"; } String mailHtml = ReadTemplates.ReadMailTemplate(System.Web.HttpContext.Current.Server.MapPath(templatePath), "EmailTemplate.html"); StringBuilder objBuilder = new StringBuilder(); objBuilder.Append(mailHtml); objBuilder.Replace("{OrderNo}", OrderNo); objBuilder.Replace("{OrderDate}", string.IsNullOrEmpty(sendEmailDTO.orderDate) ? "." : sendEmailDTO.orderDate); objBuilder.Replace("{OrderRef}", string.IsNullOrEmpty(sendEmailDTO.ARCOrderRefNo) ? "." : sendEmailDTO.ARCOrderRefNo); ARC arc = ArcBAL.GetArcInfoByUserId(new Guid(sendEmailDTO.userID)); string arcAdd = ""; if (arc != null) { arcAdd = arc.CompanyName == null ? "" : arc.CompanyName + ", "; arcAdd += arc.AddressOne + ", <br /> "; arcAdd += string.IsNullOrEmpty(arc.AddressTwo) ? "" : arc.AddressTwo + ", "; arcAdd += string.IsNullOrEmpty(arc.Town) ? "" : arc.Town + ",<br /> "; arcAdd += string.IsNullOrEmpty(arc.County) ? "" : arc.County + ", "; arcAdd += string.IsNullOrEmpty(arc.PostCode) ? "" : arc.PostCode + " <br />"; objBuilder.Replace("{Fax}", string.IsNullOrEmpty(arc.Fax) ? "." : arc.Fax); objBuilder.Replace("{Tel}", string.IsNullOrEmpty(arc.Telephone) ? "." : arc.Telephone); objBuilder.Replace("{ARC}", arcAdd); } objBuilder.Replace("{Username}", sendEmailDTO.userName); objBuilder.Replace("{UserEmail}", sendEmailDTO.userEmail); // OrderDetails LinqToSqlDataContext db = new LinqToSqlDataContext(); var products = db.USP_GetBasketProducts(Convert.ToInt32(sendEmailDTO.orderID)).ToList(); if (products != null && products.Count > 0) { string chipNos = ""; int countOption = 1; foreach (var prod in products) { int rowCount = db.USP_GetBasketProductsOnCheckOut(Convert.ToInt32(sendEmailDTO.orderID)).Where(i => i.ProductCode == prod.ProductCode.Trim()).Count(); ProductsList += "<tr><td style=\"background: #FFF7F7\">" + prod.ProductCode + "</td><td>" + prod.ProductName + "</td> <td style=\"background: #FFF7F7\">" + prod.ProductQty + "</td><td>£" + prod.Price; if (prod.ProductType == "Product") { chipNos = ""; var ChipNumbers = db.USP_GetBasketGPRSChipNumbersByProductId(Convert.ToInt32(sendEmailDTO.orderID), prod.ProductId, prod.CategoryId).ToList(); if (ChipNumbers != null) { foreach (var chipno in ChipNumbers) { chipNos += string.IsNullOrEmpty(chipno.GPRSNo) ? "" : chipno.GPRSNo + "-"; chipNos += string.IsNullOrEmpty(chipno.PSTNNo) ? "" : chipno.PSTNNo + "-"; chipNos += string.IsNullOrEmpty(chipno.GSMNo) ? "" : chipno.GSMNo + "-"; //added GSM NO(PanelID) in email chipNos += string.IsNullOrEmpty(chipno.OptionName) ? "" : chipno.OptionName; chipNos += ","; if (chipno.PSTNNo == "" && chipno.OptionName == "" && chipno.GSMNo == "" && chipNos.Length > 0 )//added GSM NO(PanelID) in email { chipNos = chipNos.Remove(chipNos.Length - 1, 1); } } if (chipNos != "") { chipNos = chipNos.Substring(0, chipNos.Length - 1); ProductsList += "</td> <td style=\"background: #FFF7F7\">" + chipNos + "</td> </td></tr>"; } else { ProductsList += "</td> <td style=\"background: #FFF7F7\">Chip Numbers : Not Provided</td></tr>"; } } if (rowCount == 1) { var dependentproducts = db.USP_GetBasketDependentProductsByProductId(Convert.ToInt32(sendEmailDTO.orderID), prod.ProductId, prod.CategoryId).ToList(); if (dependentproducts != null && dependentproducts.Count > 0) { foreach (var dp in dependentproducts) { ProductsList += "<tr><td>" + dp.ProductCode + "</td><td>" + dp.ProductName + "</td><td>" + dp.ProductQty + "</td><td>£" + dp.Price + "</tr>"; } } countOption = 0; } else if (rowCount == countOption) { var dependentproducts = db.USP_GetBasketDependentProductsByProductId(Convert.ToInt32(sendEmailDTO.orderID), prod.ProductId, prod.CategoryId).ToList(); if (dependentproducts != null && dependentproducts.Count > 0) { foreach (var dp in dependentproducts) { ProductsList += "<tr><td>" + dp.ProductCode + "</td><td>" + dp.ProductName + "</td><td>" + dp.ProductQty + "</td><td>£" + dp.Price + "</tr>"; } } } } countOption++; } } OrderDTO objorder = CSLOrderingARCBAL.BAL.OrdersBAL.GetOrderDetail(Convert.ToInt32(sendEmailDTO.orderID)); //objBuilder.Replace("{OrderTotal}", Convert.ToDecimal(lblDtlsOrderTotal.Text).ToString("c")); objBuilder.Replace("{OrderTotal}", "£" + Convert.ToDecimal(objorder.OrderTotal)); //objBuilder.Replace("{DeliveryTotal}", Convert.ToDecimal(lblDtlsDeliveryTotal.Text).ToString("c")); objBuilder.Replace("{DeliveryTotal}", "£" + Convert.ToDecimal(objorder.DeliveryCost)); //objBuilder.Replace("{VAT}", Convert.ToDecimal(lblDtlsVAT.Text).ToString("c")); objBuilder.Replace("{VAT}", "£" + Convert.ToDecimal(objorder.VATAmount)); //objBuilder.Replace("{TotalToPay}", Convert.ToDecimal(lblDtlsTotalToPay.Text).ToString("c")); objBuilder.Replace("{TotalToPay}", "£" + Convert.ToDecimal(objorder.TotalAmountToPay)); objBuilder.Replace("{DeliveryTypeName}", string.IsNullOrEmpty(sendEmailDTO.DdeliveryType) ? "" : sendEmailDTO.DdeliveryType); objBuilder.Replace("{DeliveryTypePrice}", "£" + sendEmailDTO.deliveryCost); objBuilder.Replace("{Installer}", InstallerBAL.GetAddressHTML2LineForEmail(new Guid(sendEmailDTO.installerID))); if (objorder.InstallationAddressId > 0) { instadd_differs = true; } else { instadd_differs = false; } if (instadd_differs)// || sendEmailDTO.InstallationAddId != 0) { //string InsAdd = InstallerBAL.GetAddressHTML2LineForEmail(Convert.ToInt32(Session[enumSessions.PreviousOrderId.ToString()].ToString())); string InsAdd = objorder.InstallationAddressId.HasValue ? InstallerBAL.GetAddressHTML2LineForEmail(objorder.InstallationAddressId.Value) : "Not Available"; objBuilder.Replace("{InstallerAddress}", "<td><div style=\"width: 100%; margin: 0; padding: 0;\"><table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\"><tr><td style=\"text-align: left\"> <font color=\"#888\" size=\"2\" face=\"Arial\">" + InsAdd + " </font></td></tr></table></div></td>"); objBuilder.Replace("{HeadingInstallerAdd}", "<td><h3 style=\"font-size:11px; text-align: center; margin: 0; padding: 5px auto;\">Installation Address</h3></td>"); } else { objBuilder.Replace("{InstallerAddress}", ""); objBuilder.Replace("{HeadingInstallerAdd}", ""); } objBuilder.Replace("{DeliveredTo}", OrdersBAL.GetDeliveryAddressHTML2Line(Convert.ToInt32(sendEmailDTO.orderID))); objBuilder.Replace("{SpecialInstructions}", sendEmailDTO.specialInstructions); if (isEmailFromViewOrders) { objBuilder.Append("Email Resent"); } var distinctProduct = products.Select(i => i.ProductCode).Distinct(); foreach (var pro in distinctProduct) { products = db.USP_GetBasketProducts(Convert.ToInt32(sendEmailDTO.orderID)).Where(p => p.ProductCode == pro).Take(1).ToList(); foreach (var prod in products) { if (prod.IsCSDUser == true) { ProductsList += "<tr><td>" + prod.ProductCode + "</td><td>" + prod.Message + "</td></tr>"; } } } objBuilder.Replace("{ProductList}", ProductsList); if (mailTO != "" && mailTO.Trim() != "") { string[] mailFromList = mailFrom.Split(','); string[] mailCCList = mailCC.Split(','); string emailCC = string.Empty; foreach (string email in mailCCList) { emailCC += email + ","; } if (!string.IsNullOrEmpty(emailCC)) { emailCC = emailCC.TrimEnd(','); } //PUSH TO EMIZON QUEUE if (hasEmizonProducts.HasValue && hasEmizonProducts.Value) { EmizonOrderController.AddAPIRequestToQueue(emizonQueuePath, new Emizon.APIModels.MSMQTypes.QueueOrderMessage() { From = mailFrom, To = mailTO, CC = mailCC, BCC = mailCC, Subject = mailSubject, OrderHTMLBody = objBuilder.ToString(), orderID = orderID }); } else { //Add below code to send the email message via msmq not smtp -Priya 15/06/2017 //Remove Emizon placeholder objBuilder.Replace("{EmizonData}", ""); cslEmailMessage.From = mailFrom; cslEmailMessage.To = mailTO; cslEmailMessage.CC = emailCC; cslEmailMessage.BCC = emailCC; cslEmailMessage.Subject = mailSubject; cslEmailMessage.Message = objBuilder.ToString(); sendEmail.SendEmailMessageToQueue(ConfigurationManager.AppSettings["QueueName"].ToString(), cslEmailMessage); } //End Code sending email to msmq. } ApplicationDTO appSettings = new AppSettings().GetAppValues(); List <string> lstProductCodes = new List <string>(); lstProductCodes = appSettings.ConnectionOnlyCodes.Split(',').ToList(); bool connectionProductCodeExist = false; foreach (var x in distinctProduct) { if (lstProductCodes.Exists(e => e.EndsWith(x))) { connectionProductCodeExist = true; } } StringBuilder strURL = new StringBuilder(); if (connectionProductCodeExist) { #region buildURLs List <DCCCompany> lstDCCCompany = db.DCCCompanies.ToList(); foreach (DCCCompany company in lstDCCCompany) { var tableCodes = company.Productcode.Split(',').ToList(); foreach (string s in tableCodes) { if (distinctProduct.Contains(s)) //only create a link if the product exist in the basket items. { strURL.Append(" please <a href='" + company.InstructionsUrl + "'>Click here for " + company.company_name + "</a> or "); break; // once we add } } } #endregion string mailSubjectConnectionOnly = "ARC Connection Only - Order Confirmation - Order Ref: " + OrderNo; if (isEmailFromViewOrders) { if (mailTO.EndsWith("@csldual.com")) { subjectsuffix = "; Email Resent"; } mailSubjectConnectionOnly = mailSubjectConnectionOnly + subjectsuffix; } String mailHtmlConnectionOnly = ReadTemplates.ReadMailTemplate(System.Web.HttpContext.Current.Server.MapPath(templatePath), "EmailTemplate_ConnectionOrders.html"); // String mailHtmlConnectionOnly = ReadTemplates.ReadMailTemplate(System.Web.HttpContext.Current.Server.MapPath(templatePath), "EmailTemplate_v2_ConnectionOrders.html"); StringBuilder objBuilderConnectionOnly = new StringBuilder(); objBuilderConnectionOnly.Append(mailHtmlConnectionOnly); objBuilderConnectionOnly.Replace("{InstallationURL}", strURL.ToString().TrimEnd(' ', 'o', 'r') + '.'); objBuilderConnectionOnly.Replace("{OrderNo}", OrderNo); objBuilderConnectionOnly.Replace("{OrderDate}", sendEmailDTO.orderDate); objBuilderConnectionOnly.Replace("{OrderRef}", string.IsNullOrEmpty(sendEmailDTO.ARCOrderRefNo) ? "." : sendEmailDTO.ARCOrderRefNo); objBuilderConnectionOnly.Replace("{OrderTotal}", "£" + objorder.OrderTotal); objBuilderConnectionOnly.Replace("{DeliveryTotal}", "£" + objorder.DeliveryCost); objBuilderConnectionOnly.Replace("{VAT}", "£" + objorder.VATAmount); objBuilderConnectionOnly.Replace("{TotalToPay}", "£" + objorder.TotalAmountToPay); objBuilderConnectionOnly.Replace("{DeliveryTypeName}", sendEmailDTO.DdeliveryType.ToString().TrimEnd(' ')); // objBuilderConnectionOnly.Replace("{DeliveryTypePrice}", "£" + sendEmailDTO.deliveryCost); objBuilderConnectionOnly.Replace("{Installer}", InstallerBAL.GetAddressHTML2LineForEmail(new Guid(sendEmailDTO.installerID))); if (arc != null) { objBuilderConnectionOnly.Replace("{Fax}", string.IsNullOrEmpty(arc.Fax) ? "." : arc.Fax); objBuilderConnectionOnly.Replace("{Tel}", string.IsNullOrEmpty(arc.Telephone) ? "." : arc.Telephone); objBuilderConnectionOnly.Replace("{ARC}", arcAdd); } objBuilderConnectionOnly.Replace("{Username}", sendEmailDTO.userName); objBuilderConnectionOnly.Replace("{UserEmail}", sendEmailDTO.userEmail); //comment below line if new RAc connection only template is approved if (instadd_differs) { string InsAddConnection = objorder.InstallationAddressId.HasValue ? InstallerBAL.GetAddressHTML2LineForEmail(objorder.InstallationAddressId.Value) : "Not Available"; //string InsAddConnection= InstallerBAL.GetInstallationAddressHTML2LineForEmail(Convert.ToInt32(Session[enumSessions.OrderId.ToString()].ToString())); objBuilderConnectionOnly.Replace("{InstallerAddress}", "<td><div style=\"width: 100%; margin: 0; padding: 0;\"><table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\"><tr><td style=\"text-align: left\"> <font color=\"#888\" size=\"2\" face=\"Arial\">" + InsAddConnection + " </font></td></tr></table></div></td>"); objBuilderConnectionOnly.Replace("{HeadingInstallerAdd}", "<td><h3 style=\"font-size:11px; text-align: center; margin: 0; padding: 5px auto;\">Installation Address</h3></td>"); } else { //objBuilderConnectionOnly.Replace("{InstallerAddress}", ""); // objBuilderConnectionOnly.Replace("{HeadingInstallerAdd}", ""); objBuilderConnectionOnly.Replace("{InstallerAddress}", ""); objBuilderConnectionOnly.Replace("{HeadingInstallerAdd}", ""); } // objBuilderConnectionOnly.Replace("{DeliveredTo}", OrdersBAL.GetDeliveryAddressHTML2Line(Convert.ToInt32(sendEmailDTO.orderID))); objBuilderConnectionOnly.Replace("{SpecialInstructions}", string.IsNullOrEmpty(sendEmailDTO.specialInstructions.Trim()) ? "." : sendEmailDTO.specialInstructions.Trim()); ProductsList = Regex.Replace(ProductsList, @"(?i)<(table|tr|td)(?:\s+(?:""[^""]*""|'[^']*'|[^""'>])*)?>", "<$1>"); objBuilderConnectionOnly.Replace("{ProductList}", ProductsList); LinqToSqlDataContext dbe = new LinqToSqlDataContext(); var connInstallerEmail = (from o in dbe.Orders join i in dbe.Installers on o.InstallerUnqCode equals i.UniqueCode.ToString() join ia in dbe.InstallerAddresses on i.AddressID equals ia.AddressID where o.OrderNo == OrderNo select ia.Email).Single(); if (string.IsNullOrEmpty(connInstallerEmail)) { connInstallerEmail = ConfigurationManager.AppSettings["TeleSalesEmail"].ToString(); } cslEmailMessage.From = mailFrom; cslEmailMessage.To = connInstallerEmail; cslEmailMessage.CC = mailCC; cslEmailMessage.BCC = mailCC; cslEmailMessage.Subject = mailSubjectConnectionOnly; cslEmailMessage.Message = Convert.ToString(objBuilderConnectionOnly.ToString()); sendEmail.SendEmailMessageToQueue(ConfigurationManager.AppSettings["QueueName"].ToString(), cslEmailMessage); } db.Dispose(); HttpContext.Current.ApplicationInstance.CompleteRequest(); } catch (Exception objException) { CSLOrderingARCBAL.LinqToSqlDataContext db; db = new CSLOrderingARCBAL.LinqToSqlDataContext(); db.USP_SaveErrorDetails(System.Web.HttpContext.Current.Request.Url.ToString(), "SendEmailWithPrice", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()])); } }
public void btnSubmit_Click(object sender, EventArgs e) { DropDownList ddlinstaller = (DropDownList)Installers.FindControl("ddlInstallers"); if (enablePostCodeSearch == false) { Session[enumSessions.InstallerCompanyID.ToString()] = ddlinstaller.SelectedValue; Session[enumSessions.SelectedInstaller.ToString()] = ddlinstaller.SelectedItem; } db = new LinqToSqlDataContext(); string mycheck = ""; if (Request["dr"].ToString() == "d" || Request["dr"].ToString() == "u" || Request["dr"].ToString() == "r") { if (chkConfirm.Checked) { mycheck = "true"; } else { mycheck = "false"; } } else { mycheck = "true"; } if (mycheck == "true") { lblSubmitConfirm.Visible = false; string UserEmail = ""; string CompanyName = ""; string UserName = ""; string dr = Request["dr"].ToString(); if (dr == "u") { dr = "Upgrade"; } else if (dr == "u") { dr = "Downgrade"; } else { dr = "Regrade"; } UserName = Session[enumSessions.User_Name.ToString()].ToString(); UserEmail = Session[enumSessions.User_Email.ToString()].ToString(); CompanyName = CSLOrderingARCBAL.BAL.ArcBAL.GetARCName(Session[enumSessions.ARC_Id.ToString()].ToString()); MailMessage Message = new MailMessage(); if (UserName.Length == 0) { UserName = Session["UserId"].ToString(); } string id = Session[enumSessions.User_Id.ToString()].ToString(); var Data = (from d in db.UpDowngrades where d.UserId == id && d.Emailed == false && (d.ISEmizonUnit == false || (d.ISEmizonUnit == true && Convert.ToBoolean(d.NeedsEngineer) == true)) select d); db.SubmitChanges(); if (Data.Any()) { String EmailDevicelist = "<table cellspacing='1' cellpadding='1' border='1' width=\"100%\"><tr><td style=\"color: #888;\"><b>Request Type</b></td><td style=\"color: #888;\"><b>From</b></td><td style=\"color: #888;\"><b>To</b></td><td style=\"color: #888;\"><b>Reason</b></td><td style=\"color: #888;\"><b>ESN/SIM</b></td><td style=\"color: #888;\"><b>NUA/Data</b></td><td style=\"color: #888;\"><b>Chip Number</b></td><td style=\"color: #888;\"><b>EM No</b></td><td style=\"color: #888;\"><b>Installer</b></td><td style=\"color: #888;\"><b>ARC Ref</b></td></tr>"; foreach (var ud in Data) { EmailDevicelist += "<tr>"; // EmailDevicelist += "<td>" + dr + "</td>"; if (dr == "Upgrade") { EmailDevicelist += "<td td style=\"color: #0099cc;\">" + dr + "</td>"; //blue } else if (dr == "Downgrade") { EmailDevicelist += "<td td style=\"color: #000000;\">" + dr + "</td>"; //black } else { EmailDevicelist += "<td>" + dr + "</td>"; //black } string szReason = ""; if (Request["dr"].ToString() == "u") { szReason = "n/a"; } else { szReason = ud.Reason; } EmailDevicelist += "<td>" + ud.ItemFrom + "</td>"; EmailDevicelist += "<td>" + ud.ItemTo + "</td>"; EmailDevicelist += "<td>" + szReason + "</td>"; EmailDevicelist += "<td>" + ud.Simno + "</td>"; EmailDevicelist += "<td>" + ud.Datano + "</td>"; EmailDevicelist += "<td>" + ud.Chipno + "</td>"; EmailDevicelist += "<td>" + ud.EMNo + "</td>"; string selectedInstaller = GetInstallerName(ud.Installer); if (string.IsNullOrEmpty(selectedInstaller)) { EmailDevicelist += "<td>n/a</td>"; } else { EmailDevicelist += "<td>" + selectedInstaller + "</td>"; } EmailDevicelist += "<td>" + ud.ARCRef + "</td>"; EmailDevicelist += "</tr>"; } EmailDevicelist += "</table>"; //begin sonam String mailHtml = ReadTemplates.ReadMailTemplate(Server.MapPath("Template"), "EmailGrade.html"); StringBuilder objBuilder = new StringBuilder(); objBuilder.Append(mailHtml); objBuilder.Replace("{UserName}", UserName); objBuilder.Replace("{ArcName}", CompanyName); objBuilder.Replace("{UserEmail}", UserEmail); objBuilder.Replace("{DateofRequest}", DateTime.Now.ToString()); objBuilder.Replace("{Devicelist}", EmailDevicelist); //end sonam if (string.IsNullOrEmpty((string)HttpRuntime.Cache["EmailCC"])) { ApplicationDTO appdto; AppSettings appsett = new AppSettings(); appdto = appsett.GetAppValues(); mailCC = appdto.mailCC; } else { mailCC = (string)HttpRuntime.Cache["EmailCC"]; } string subjectMessage = ""; if (Request["dr"].ToString() == "u") { subjectMessage = "Upgrade Request"; } else if (Request["dr"].ToString() == "d") { subjectMessage = "Downgrade Request"; } else { subjectMessage = "Regrade Request : Needs Engineer Visit"; } SendEmailMessage sendEmail = new SendEmailMessage(); EmailMessage cslEmailMessage = new EmailMessage(); cslEmailMessage.From = mailFrom; cslEmailMessage.To = mailTO; cslEmailMessage.CC = UserEmail + ";" + mailCC + ";" + GetArcCcEmail(Session[enumSessions.ARC_Id.ToString()].ToString()); cslEmailMessage.BCC = ""; cslEmailMessage.Subject = subjectMessage; cslEmailMessage.Message = Convert.ToString(objBuilder.ToString()); sendEmail.SendEmailMessageToQueue(ConfigurationManager.AppSettings["QueueName"].ToString(), cslEmailMessage); //End Code sending email to msmq. db = new LinqToSqlDataContext(); var upData = (from data in db.UpDowngrades where data.UserId == Session[enumSessions.User_Id.ToString()].ToString() && (data.ISEmizonUnit == false || (data.ISEmizonUnit == true && Convert.ToBoolean(data.NeedsEngineer) == true)) select data); foreach (var d in upData) { d.Emailed = true; } db.SubmitChanges(); } // ** Flag Emizon units var EmizonUnits = (from data in db.UpDowngrades where data.UserId == Session[enumSessions.User_Id.ToString()].ToString() && data.ISEmizonUnit == true && Convert.ToBoolean(data.NeedsEngineer) == false select data); if (EmizonUnits.Any()) { foreach (var r in EmizonUnits) { r.AwaitingtobeProcessed = true; } db.SubmitChanges(); } pnlForm.Visible = false; divuc1.Visible = false; divuc2.Visible = false; pnlConfirm.Visible = true; PnlAwaitingtoBeProcessed.Visible = false; } else { lblSubmitConfirm.Visible = true; } Session[enumSessions.InstallerCompanyID.ToString()] = null; Session[enumSessions.SelectedInstaller.ToString()] = null; }