/// <summary> /// 判断对象修改后于原数据对比返回 DataTable(KEYNAME,VALUE,NEWVALUE) 2015-08-16 唐锋 /// </summary> /// <param name="obj">原对象数据</param> /// <param name="newObj">更新后对象数据</param> /// <param name="ArrayParams">不需要对比属性</param> public static DataTable ObjectCompareObjectReturnDataTable(object obj, object newObj, params string[] ArrayParams) { DataTable dt = new DataTable(); dt.Columns.Add("KEYNAME", Type.GetType("System.String")); dt.Columns.Add("VALUE", Type.GetType("System.String")); dt.Columns.Add("NEWVALUE", Type.GetType("System.String")); if (obj == null && newObj == null) { return(null); } Type dataObjype = newObj.GetType(); PropertyInfo[] dataObjypePropertiesArray = dataObjype.GetProperties(); foreach (PropertyInfo dataObjProperty in dataObjypePropertiesArray) { //判断是否需要对比 for (int i = 0; i < ArrayParams.Length; i++) { if (dataObjProperty.Name.ToUpper().Trim() == ArrayParams[i].ToUpper().Trim()) { break; } } object objKeyValue = AutoBinder.GetPropertyValue(obj, dataObjProperty.Name); object newObjKeyValue = AutoBinder.GetPropertyValue(newObj, dataObjProperty.Name); objKeyValue = objKeyValue == null ? "" : objKeyValue; //newObjKeyValue = newObjKeyValue == null ? "" : newObjKeyValue; //等于 ### 的字段是不需要更新 if (newObjKeyValue != null) { if (newObjKeyValue.ToString() != "") { objKeyValue = string.IsNullOrEmpty(objKeyValue.ToString()) ? ConstValues.SpecialCharacter.EmptyValuesFillChar : objKeyValue; if (objKeyValue.ToString() != newObjKeyValue.ToString()) { dt.Rows.Add(new object[] { dataObjProperty.Name, objKeyValue, newObjKeyValue }); } } } } return(dt); }
/// <summary> /// 将对象的值填充至对象 /// </summary> /// <param name="obj">数据对象</param> /// <param name="dataObj">转值至对象</param> public static object BindObjectToObject(object obj, object dataObj) { return(AutoBinder.BindObjectToObjectWithNoNullValues(obj, dataObj, ConstValues.SpecialCharacter.EmptyValuesFillChar)); }