private ProcurementReport GetReportData(FormCollection collection) { if (collection == null) throw new ArgumentNullException("collection"); var report = new ProcurementReport(); var procurements = SerializableProcurement.ConvertProcurementListToSerializableProcurementList(factory.GetProcurements()); var filters = GetFilteredColumns(collection); var procurmentTypes = new List<string>(); if (collection["BusinessType"].Contains("true")) procurmentTypes.Add("Business"); if (collection["ParentType"].Contains("true")) procurmentTypes.Add("Parent"); if (collection["AdventureType"].Contains("true")) procurmentTypes.Add("Adventure"); // OMFG, what the hell was I thinking? This is _really_ f*****g inefficient, and I don't like it one bit. >8( foreach (var item in procurements.OrderBy((x) => x.ItemNumber).ToArray()) { if (procurmentTypes.Contains(item.ProcurementType) == false) procurements.Remove(item); } if (filters != null && filters.Count() > 0) { foreach (var filter in filters) { var propInfo = new SerializableProcurement().GetType().GetProperty(filter.Key); if (propInfo != null || filter.Key == "Donor") { try { foreach (SerializableProcurement item in procurements.ToArray()) { // TODO: Fix ugly special case if (filter.Key == "Donor") { if ((item.BusinessName == null || item.Donors == null) || (item.BusinessName.IndexOf(filter.Value, StringComparison.CurrentCultureIgnoreCase) == -1 && item.Donors.IndexOf(filter.Value, StringComparison.CurrentCultureIgnoreCase) == -1)) procurements.Remove(item); continue; } var value = propInfo.GetValue(item, null); if (value == null) procurements.Remove(item); else { if (value is Int32 || value is Int32?) { if ((Int32)value != Int32.Parse(filter.Value)) procurements.Remove(item); } else if (value is Int64 || value is Int64?) { if ((Int64)value != Int64.Parse(filter.Value)) procurements.Remove(item); } else if (value is decimal || value is decimal?) { if ((decimal)value != decimal.Parse(filter.Value)) procurements.Remove(item); } else if (value is double || value is double?) { if ((double)value != double.Parse(filter.Value)) procurements.Remove(item); } else { if (value.ToString().IndexOf(filter.Value, StringComparison.CurrentCultureIgnoreCase) == -1) procurements.Remove(item); } } } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } } } } report.rows = procurements; return report; }
private static void BuildReportBody(StringBuilder reportHtml, IEnumerable<string> columns, ProcurementReport report, bool includeRowNumbers) { reportHtml.AppendLine("<tbody>"); var rowCounter = 0; report.rows.ForEach(row => { rowCounter += 1; reportHtml.AppendLine("<tr>"); if (includeRowNumbers) reportHtml.AppendLine("<td>" + rowCounter.ToString() + "</td>"); foreach (var item in columns) { if (item == "Donor") { reportHtml.AppendLine("<td>"); if (row.Donors != null && string.IsNullOrEmpty(row.Donors.Trim()) == false) reportHtml.Append(row.Donors); if (string.IsNullOrEmpty(row.BusinessName) && string.IsNullOrEmpty(row.Donors)) reportHtml.AppendLine(" "); reportHtml.AppendLine("</td>"); continue; } if (item == "EstimatedValue") { reportHtml.AppendLine("<td>"); if (string.IsNullOrEmpty(row.EstimatedValue.ToString()) == false) { reportHtml.Append(row.EstimatedValue == -1 ? "priceless" : row.EstimatedValue == null ? "" : row.EstimatedValue.Value.ToString("C")); } reportHtml.AppendLine("</td>"); continue; } var propInfo = row.GetType().GetProperty(item); if (propInfo == null) continue; var value = propInfo.GetValue(row, null); reportHtml.AppendLine(FormatHtmlTableCellValueByType(value)); } reportHtml.AppendLine("</tr>"); }); reportHtml.AppendLine("</tbody>"); }