} // constructor public List <LoanStatsReportEntry> Generate() { var oResult = new List <LoanStatsReportEntry>(); foreach (KeyValuePair <int, List <LoanStatsDataEntry> > pair in Data) { int nCustomerID = pair.Key; foreach (LoanStatsDataEntry lse in pair.Value) { var lre = new LoanStatsReportEntry(); oResult.Add(lre); lre.IsFirstLoan = lse.IsLoanIssued ? ((lse.IsFirstLoan ? "" : "not ") + "first") : ""; lre.ClientLoanOrderNo = lse.LoanSeqNo; lre.TypeOfLoan = lse.ApprovedType; lre.CustomerSelection = lse.IsLoanTypeSelectionAllowed ? 1 : 0; lre.DiscountPlan = lse.DiscountPlanName; lre.Offline = lse.IsOffline ? "offline" : "online"; lre.LoanID = lse.IsLoanIssued ? lse.LoanID : (int?)null; lre.ClientID = lse.CustomerID; lre.ClientName = lse.CustomerName; lre.DateFirstApproved = lse.FirstDecisionDate; lre.DateLastApproved = lse.LastDecisionDate.Date; lre.NewOrOldClient = lse.IsNewClient ? "new" : "old"; lre.LoanOffered = lse.ApprovedSum; lre.InterestRate = lse.ApprovedRate; lre.LoanIssued = lse.IsLoanIssued ? lse.LoanAmount : (decimal?)null; lre.IsLoanIssued = lse.IsLoanIssued ? "yes" : "no"; lre.LoanIssueDate = lse.IsLoanIssued ? lse.IssueDate : (DateTime?)null; lre.LoanDuration = lse.IsLoanIssued ? lse.LoanTerm : (int?)null; lre.CreditScore = lse.CreditScore; lre.TotalAnnualTurnover = lse.AnnualTurnover; lre.Medal = ((object)lse.Medal).ToString().ToLower(); SortedDictionary <int, int> oMarketplaceCount = CustomerMarketplaces.ContainsKey(lse.CustomerID) ? CustomerMarketplaces[lse.CustomerID].Count(lse.FirstDecisionDate) : LoanStatsMarketplaces.Count(); foreach (KeyValuePair <int, int> mpc in oMarketplaceCount) { lre.MarketplaceCount[mpc.Key] = mpc.Value; } lre.PaypalTotal = CustomerPaypalTotals.ContainsKey(lse.CustomerID) ? CustomerPaypalTotals[lse.CustomerID].Calculate(lse.FirstDecisionDate) : 0; lre.Gender = lse.Gender.ToString().ToLower(); lre.YearOfBirth = lse.BirthDate.Year; switch (lse.MaritalStatus) { case MaritalStatus.Married: lre.FamilyStatus = 1; break; case MaritalStatus.Single: lre.FamilyStatus = 0; break; case MaritalStatus.Divorced: lre.FamilyStatus = 2; break; case MaritalStatus.Widowed: lre.FamilyStatus = 3; break; case MaritalStatus.LivingTogether: lre.FamilyStatus = 4; break; case MaritalStatus.Separated: lre.FamilyStatus = 5; break; case MaritalStatus.Other: lre.FamilyStatus = 0; break; default: throw new ArgumentOutOfRangeException( "MaritalStatus", (object)lse.MaritalStatus, "Unsupported marital status." ); } // switch if (lse.IsHomeOwner) { lre.HomeOwnership = 1; } else { switch (lse.PropertyStatusDescription.ToLower()) { case "social house": lre.HomeOwnership = 3; break; case "renting": lre.HomeOwnership = 0; break; case "living with parents": lre.HomeOwnership = 2; break; default: lre.HomeOwnership = null; break; } // switch } switch (lse.TypeOfBusiness) { case TypeOfBusiness.Entrepreneur: case TypeOfBusiness.SoleTrader: lre.TypeOfBusiness = 0; break; case TypeOfBusiness.LLP: case TypeOfBusiness.Limited: lre.TypeOfBusiness = 2; break; case TypeOfBusiness.PShip3P: case TypeOfBusiness.PShip: lre.TypeOfBusiness = 1; break; default: throw new ArgumentOutOfRangeException(); } // switch lre.SourceRef = lse.ReferenceSource; lre.Category1 = ""; // TODO lre.Category2 = ""; // TODO lre.Category3 = ""; // TODO lre.Region = CustomerRegions.ContainsKey(nCustomerID) ? CustomerRegions[nCustomerID] : ""; lre.LastCashRequestID = lse.RequestIDHistory[lse.RequestIDHistory.Count - 1]; } // for each entry } // for each customer return(oResult); } // Generate
} // Xls private void FillRow(ExcelWorksheet sheet, int nRowNumber, LoanStatsReportEntry lre) { sheet.Cells["A" + nRowNumber].Value = lre.IsFirstLoan; sheet.Cells["B" + nRowNumber].Value = lre.ClientLoanOrderNo; sheet.Cells["C" + nRowNumber].Value = lre.TypeOfLoan; sheet.Cells["D" + nRowNumber].Value = lre.CustomerSelection; sheet.Cells["E" + nRowNumber].Value = lre.DiscountPlan; sheet.Cells["F" + nRowNumber].Value = lre.Offline; sheet.Cells["G" + nRowNumber].Value = lre.LoanID; // sheet.Cells["H" + nRowNumber].Value = lre.LastCashRequestID; sheet.Cells["I" + nRowNumber].Value = lre.ClientID; sheet.Cells["J" + nRowNumber].Value = lre.ClientName; sheet.Cells["K" + nRowNumber].Value = lre.DateFirstApproved; sheet.Cells["L" + nRowNumber].Value = lre.DateLastApproved; sheet.Cells["M" + nRowNumber].Value = lre.NewOrOldClient; sheet.Cells["N" + nRowNumber].Value = lre.LoanOffered; sheet.Cells["P" + nRowNumber].Value = lre.InterestRate; sheet.Cells["Q" + nRowNumber].Value = lre.LoanIssued; sheet.Cells["R" + nRowNumber].Value = lre.IsLoanIssued; sheet.Cells["T" + nRowNumber].Value = lre.LoanIssueDate; sheet.Cells["X" + nRowNumber].Value = lre.LoanDuration; sheet.Cells["Y" + nRowNumber].Value = lre.CreditScore; sheet.Cells["AB" + nRowNumber].Value = lre.TotalAnnualTurnover; sheet.Cells["AC" + nRowNumber].Value = lre.Medal; sheet.Cells["AK" + nRowNumber].Value = lre.PaypalTotal; sheet.Cells["AL" + nRowNumber].Value = lre.Gender; sheet.Cells["AO" + nRowNumber].Value = lre.YearOfBirth; sheet.Cells["AQ" + nRowNumber].Value = lre.FamilyStatus; sheet.Cells["FN" + nRowNumber].Value = lre.HomeOwnership; sheet.Cells["FO" + nRowNumber].Value = lre.TypeOfBusiness; sheet.Cells["GC" + nRowNumber].Value = lre.SourceRef; sheet.Cells["GD" + nRowNumber].Value = lre.Category1; sheet.Cells["GE" + nRowNumber].Value = lre.Category2; sheet.Cells["GF" + nRowNumber].Value = lre.Category3; sheet.Cells["GG" + nRowNumber].Value = lre.Region; int nColumn = sheet.Cells["GH" + nRowNumber].Start.Column; foreach (KeyValuePair <int, int> pair in lre.MarketplaceCount) { int nMarketplaceTypeID = pair.Key; int nCount = pair.Value; string sMarketplaceType = LoanStatsMarketplaces.MarketplaceTypes[nMarketplaceTypeID].ToLower(); if (sMarketplaceType.StartsWith("ebay")) { sheet.Cells["AE" + nRowNumber].Value = nCount; } else if (sMarketplaceType.StartsWith("amazon")) { sheet.Cells["AF" + nRowNumber].Value = nCount; } else if (sMarketplaceType.StartsWith("ekm")) { sheet.Cells["AG" + nRowNumber].Value = nCount; } else if (sMarketplaceType.StartsWith("volusion")) { sheet.Cells["AH" + nRowNumber].Value = nCount; } else if (sMarketplaceType.StartsWith("play")) { sheet.Cells["AI" + nRowNumber].Value = nCount; } else if (sMarketplaceType.StartsWith("pay pal")) { sheet.Cells["AJ" + nRowNumber].Value = nCount; } else { sheet.Cells[nRowNumber, nColumn].Value = nCount; ++nColumn; } // if } // for each sheet.Cells["K" + nRowNumber + ":L" + nRowNumber].Style.Numberformat.Format = "dd-mmm-yy"; sheet.Cells["T" + nRowNumber].Style.Numberformat.Format = "dd-mmm-yy"; sheet.Cells["P" + nRowNumber].Style.Numberformat.Format = "0.00%"; sheet.Cells["N" + nRowNumber].Style.Numberformat.Format = "#,##0"; sheet.Cells["Q" + nRowNumber].Style.Numberformat.Format = "#,##0"; sheet.Cells["AB" + nRowNumber].Style.Numberformat.Format = "#,##0"; sheet.Cells["AK" + nRowNumber].Style.Numberformat.Format = "#,##0"; } // FillRow