Update existing reports, removing mileage drill down
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.SqlTypes;
|
||||
@@ -143,21 +144,38 @@ namespace MileageTraker.Web.Utility
|
||||
: propertyMember.Name;
|
||||
}
|
||||
|
||||
public static object GetValue(this PropertyInfo propertyMember, object obj)
|
||||
|
||||
public static string GetNullDisplayText(this PropertyInfo propertyMember, object obj)
|
||||
{
|
||||
var value = propertyMember.GetValue(obj, null);
|
||||
var displayAttr =
|
||||
propertyMember.GetCustomAttributes(typeof (DisplayFormatAttribute), true).FirstOrDefault() as DisplayFormatAttribute;
|
||||
var displayAttr = GetDisplayAttribute(propertyMember);
|
||||
|
||||
if (displayAttr != null)
|
||||
{
|
||||
if (value == null && !String.IsNullOrEmpty(displayAttr.NullDisplayText))
|
||||
return displayAttr.NullDisplayText;
|
||||
|
||||
if (!String.IsNullOrEmpty(displayAttr.DataFormatString))
|
||||
return String.Format(displayAttr.DataFormatString, value);
|
||||
}
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetDataFormatString(this PropertyInfo propertyMember, object obj)
|
||||
{
|
||||
var value = propertyMember.GetValue(obj, null);
|
||||
var displayAttr = GetDisplayAttribute(propertyMember);
|
||||
|
||||
if (displayAttr != null)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(displayAttr.DataFormatString))
|
||||
return displayAttr.DataFormatString;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static DisplayFormatAttribute GetDisplayAttribute(PropertyInfo propertyMember)
|
||||
{
|
||||
var displayAttr =
|
||||
propertyMember.GetCustomAttributes(typeof (DisplayFormatAttribute), true).FirstOrDefault() as DisplayFormatAttribute;
|
||||
return displayAttr;
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetPropertyNames(this Type type)
|
||||
@@ -293,6 +311,25 @@ namespace MileageTraker.Web.Utility
|
||||
select mg.Key).ToList()
|
||||
}).ToDictionary(arg => arg.Item1, arg => arg.Item2List);
|
||||
}
|
||||
|
||||
public static bool IsNonStringEnumerable(this Type type)
|
||||
{
|
||||
if (type == null || type == typeof(string))
|
||||
return false;
|
||||
return typeof(IEnumerable).IsAssignableFrom(type);
|
||||
}
|
||||
|
||||
public static bool IsHiddenFromModel(this MemberInfo propertyMember)
|
||||
{
|
||||
var hiddenInputAttribute =
|
||||
propertyMember.GetCustomAttributes(typeof(HiddenInputAttribute), true).FirstOrDefault() as HiddenInputAttribute;
|
||||
|
||||
if (hiddenInputAttribute != null)
|
||||
{
|
||||
return !hiddenInputAttribute.DisplayValue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//public static IEnumerable<SelectListItem> ToSelectList<T>(
|
||||
// this IEnumerable<T> enumerable,
|
||||
|
||||
+26
-22
@@ -38,7 +38,8 @@ namespace MileageTraker.Web.Utility
|
||||
{
|
||||
return
|
||||
typeof (T).GetProperties()
|
||||
.Where(p => !p.PropertyType.IsCollection())
|
||||
.Where(p => !p.PropertyType.IsNonStringEnumerable())
|
||||
.Where(p => !p.IsHiddenFromModel())
|
||||
.Where(p => !p.Name.Contains("PreviousLog"))
|
||||
.ToList();
|
||||
}
|
||||
@@ -92,36 +93,39 @@ namespace MileageTraker.Web.Utility
|
||||
(item, r) =>
|
||||
GetProperties().Zip(CustomExtensions.GetNumbers().Skip(startCol),
|
||||
(p, c) => {
|
||||
var value = p.GetValue(item);
|
||||
var value = p.GetValue(item);
|
||||
|
||||
string formatString = null;
|
||||
string formatString = null;
|
||||
|
||||
if (value is decimal) // assume that it's currency
|
||||
formatString = "#,##0.00";
|
||||
if (value is decimal) // assume that it's currency
|
||||
formatString = "#,##0.00";
|
||||
|
||||
if (value is DateTime && p.Name == "Date")
|
||||
formatString = @"MM/DD/YYYY";
|
||||
else if (value is DateTime)
|
||||
formatString = @"MM/DD/YYYY hh:mm:ss";
|
||||
if (value is DateTime && p.Name.Contains("Date"))
|
||||
formatString = @"MM/DD/YYYY";
|
||||
else if (value is DateTime)
|
||||
formatString = @"MM/DD/YYYY hh:mm:ss";
|
||||
|
||||
if (p.Name == "GasPurchased") // format to the .000 place
|
||||
formatString = "#,##0.000";
|
||||
if (p.Name == "GasPurchased") // format to the .000 place
|
||||
formatString = "#,##0.000";
|
||||
|
||||
int intValue; // write int-looking values as numbers
|
||||
if (value is string && int.TryParse((string) value, out intValue))
|
||||
value = intValue;
|
||||
int intValue; // write int-looking values as numbers
|
||||
if (value is string && int.TryParse((string) value, out intValue))
|
||||
value = intValue;
|
||||
|
||||
double doubleValue; // write double-looking values as numbers
|
||||
if (value is string && double.TryParse((string) value, out doubleValue))
|
||||
value = doubleValue;
|
||||
double doubleValue; // write double-looking values as numbers
|
||||
if (value is string && double.TryParse((string) value, out doubleValue))
|
||||
value = doubleValue;
|
||||
|
||||
if (value is MileageLogTypeWrapper)
|
||||
value = ((MileageLogTypeWrapper) value).Enum.GetDisplayName();
|
||||
if (value is MileageLogTypeWrapper)
|
||||
value = ((MileageLogTypeWrapper) value).Enum.GetDisplayName();
|
||||
|
||||
var cell = formatString != null ? new Cell(value, formatString) : new Cell(value);
|
||||
worksheet.Cells[r, c] = cell;
|
||||
if (value == null)
|
||||
value = p.GetNullDisplayText(item);
|
||||
|
||||
return (string) null;
|
||||
var cell = formatString != null ? new Cell(value, formatString) : new Cell(value);
|
||||
worksheet.Cells[r, c] = cell;
|
||||
|
||||
return (string) null;
|
||||
}).ToList()).ToList();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user