public string ApplySummaryAsync(string quoteTemplate, Statement statement) { var footerTemplate = UpdateSummaryAsync(quoteTemplate, statement); return quoteTemplate.Replace(quoteTemplate, footerTemplate); }
public string ApplyHeaderAsync(string quoteTemplate, Statement statement, Customer customer, string logo) { var headerTemplate = UpdateHeaderAsync(quoteTemplate, statement, customer, logo); return quoteTemplate.Replace(quoteTemplate, headerTemplate); }
string UpdateSummaryAsync(string footerTemplate, Statement statement) { var footerBlock = new StringBuilder(footerTemplate); footerBlock = footerBlock.Replace("~STATEMENT_NUMBER~", statement.StatementNumber.ToString()); ProcessAppDifferences(statement, footerBlock); ProcessAmount(statement, footerBlock); footerBlock = footerBlock.Replace("~THANK_YOU_MESSAGE~", "Thank you for your interest!"); return footerBlock.ToString(); }
void ProcessAmount(Statement statement, StringBuilder textblock) { if (statement.TypeName == Constants.STATEMENT_TYPE_QUOTE) { textblock = textblock.Replace("~TOTAL_COST_LABEL~", "Total Cost:"); } else if (statement.TypeName == Constants.STATEMENT_TYPE_INVOICE) { textblock = textblock.Replace("~TOTAL_COST_LABEL~", "Amount Due:"); } else { Debug.Assert(false, "Unexpected statement type"); } textblock = textblock.Replace("~TOTAL_COST~", statement.Total.ToString()); }
void ProcessAppDifferences(Statement statement, StringBuilder textblock) { if (statement.TypeName == Constants.STATEMENT_TYPE_QUOTE) { textblock = textblock.Replace("~DATE_LABEL~", string.Empty); textblock = textblock.Replace("~DATE_VALUE~", DateTime.Now.ToString("d", DateTimeFormatInfo.InvariantInfo)); textblock = textblock.Replace("~SLOGAN~", @"Provided By: <br/>Quote Builder"); } else if (statement.TypeName == Constants.STATEMENT_TYPE_INVOICE) { textblock = textblock.Replace("~DATE_LABEL~", "Due Date:"); textblock = textblock.Replace("~DATE_VALUE~", (statement as Invoice).DueDate.ToString("d", DateTimeFormatInfo.InvariantInfo)); textblock = textblock.Replace("~SLOGAN~", @"Provided By: <br/>Quote Viewer"); } else { Debug.Assert(false, "Unexpected statement type"); } }
string UpdateHeaderAsync(string headerTemplate, Statement statement, Customer customer, string logo) { var headerBlock = new StringBuilder(headerTemplate); var profile = statement.Profile; var address = statement.Address; headerBlock = headerBlock.Replace("~HEADER_LOGO~", logo); headerBlock = headerBlock.Replace("~TITLE~", statement.TypeName); headerBlock = headerBlock.Replace("~PROVIDE_COMPANY_NAME~", profile.BusinessName); headerBlock = headerBlock.Replace("~PROVIDER_STREET_ADDRESS1~", profile.Address1); headerBlock = headerBlock.Replace("~PROVIDER_STREET_ADDRESS2~", profile.Address2); headerBlock = headerBlock.Replace("~PROVIDER_CITY_STATE_ZIP~", profile.Postal); headerBlock = headerBlock.Replace("~PROVIDER_PHONE~", profile.Phone); headerBlock = headerBlock.Replace("~PROVIDER_EMAIL~", profile.Email); headerBlock = headerBlock.Replace("Comments", statement.Title); ProcessAppDifferences(statement, headerBlock); headerBlock = headerBlock.Replace("~STATEMENT_NUMBER~", statement.StatementNumber.ToString()); headerBlock = headerBlock.Replace("~STATEMENT_FOR~", string.Format("{0} for", statement.TypeName)); try { //SQLiteAsyncConnection connection = new SQLiteAsyncConnection(Bizmonger.Client.Infrastructure.Constants.DATABASE_FILE_NAME); //var customerId = statement.CustomerId.ToString(); //var customerQuery = connection.Table<Bizmonger.Client.Infrastructure.DAL.Entities.Customer>(). // Where(c => c.CustomerId == customerId); //var customer = await customerQuery.FirstOrDefaultAsync(); headerBlock = headerBlock.Replace("~CLIENT_NAME~", string.Format("{0} {1}", customer.FirstName, customer.LastName)); headerBlock = headerBlock.Replace("~CLIENT_EMAIL~", customer.Email); headerBlock = headerBlock.Replace("~CLIENT_PHONE~", customer.Phone); } catch (Exception ex) { Debug.WriteLine($"Failed to query customer data:{ex.Message}"); } return headerBlock.ToString(); }