public static void SetUnboundColumnData(CustomColumnDataEventArgs e, IDynamicPropertyList propertyList, bool allowNullValue) { if (e.IsGetData) { throw new PhuLiException("Please call GetUnboundColumnData"); } if (e.IsSetData) { if (propertyList.HasProperty(e.Column.FieldName)) { if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(string)) { propertyList.SetValue(e.Column.FieldName, Convert.ToString(e.Value)); //get value from property, to reflect changes during set function e.Value = propertyList.GetValue <string>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(double)) { if (e.Value != null) { double newValue; bool parseOk = double.TryParse(e.Value.ToString(), out newValue); if (parseOk) { propertyList.SetValue(e.Column.FieldName, newValue); //get value from property, to reflect changes during set function e.Value = propertyList.GetValue <double>(e.Column.FieldName); } } } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(decimal)) { if (e.Value != null) { decimal newValue; bool parseOk = decimal.TryParse(e.Value.ToString(), out newValue); if (parseOk) { propertyList.SetValue(e.Column.FieldName, newValue); //get value from property, to reflect changes during set function e.Value = propertyList.GetValue <decimal>(e.Column.FieldName); } } } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(int)) { if (e.Value != null) { int newValue; bool parseOk = int.TryParse(e.Value.ToString(), out newValue); if (parseOk) { propertyList.SetValue(e.Column.FieldName, newValue); //get value from property, to reflect changes during set function e.Value = propertyList.GetValue <int>(e.Column.FieldName); } } } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(Quantity)) { if (e.Value != null) { var oldQty = propertyList.GetValue <Quantity>(e.Column.FieldName); Quantity newQty = Quantity.TryConvert(oldQty, e.Value); if (!allowNullValue) { if (newQty == null && oldQty != null) { newQty = Quantity.TryConvert(oldQty, 0m); } } propertyList.SetValue(e.Column.FieldName, newQty); //get value from property, to reflect changes during set function e.Value = propertyList.GetValue <Quantity>(e.Column.FieldName); } } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(DateTime) || propertyList.GetPropertyType(e.Column.FieldName) == typeof(DateTime?)) { if (e.Value != null) { DateTime newValue; bool parseOk = DateTime.TryParse(e.Value.ToString(), out newValue); if (parseOk) { propertyList.SetValue(e.Column.FieldName, newValue); //get value from property, to reflect changes during set function e.Value = propertyList.GetValue <DateTime>(e.Column.FieldName); } } } else { throw new PhuLiException( string.Format("Type [{0}] not handled. Please add this type to the function.", propertyList.GetPropertyType(e.Column.FieldName))); } } else { Debug.Assert(false, "Property doesn't exist in dynamic property list."); } } }
public static void GetUnboundColumnData(CustomColumnDataEventArgs e, IDynamicPropertyList propertyList) { if (propertyList != null) { if (e.IsGetData) { if (propertyList.HasProperty(e.Column.FieldName)) { if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(string)) { e.Value = propertyList.GetValue <string>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(double)) { e.Value = propertyList.GetValue <double>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(double?)) { e.Value = propertyList.GetValue <double?>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(decimal)) { e.Value = propertyList.GetValue <decimal>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(decimal?)) { e.Value = propertyList.GetValue <decimal?>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(int)) { e.Value = propertyList.GetValue <int>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(int?)) { e.Value = propertyList.GetValue <int?>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(DateTime)) { e.Value = propertyList.GetValue <DateTime>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(DateTime?)) { e.Value = propertyList.GetValue <DateTime?>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(Quantity)) { e.Value = propertyList.GetValue <Quantity>(e.Column.FieldName); } else if (propertyList.GetPropertyType(e.Column.FieldName) == typeof(bool)) { e.Value = propertyList.GetValue <bool>(e.Column.FieldName); } else { throw new PhuLiException( string.Format("Type [{0}] not handled. Please add this type to the function.", propertyList.GetPropertyType(e.Column.FieldName))); } } else { Debug.Assert(false, string.Format("Property [{0}] not found in list", e.Column.FieldName)); } } else if (e.IsSetData) { throw new PhuLiException("Please call SetUnboundColumnData"); } } }