private void BindInfoProperty(PropertyInfo property) { Type propertyType = property.PropertyType; if (propertyType == typeof(Guid)) { return; } DataMemberAttribute dataMember = property.GetCustomAttributes(typeof(DataMemberAttribute), false) .FirstOrDefault() as DataMemberAttribute; if (dataMember == null) { return; } NotMappedAttribute notMapped = property.GetCustomAttributes(typeof(NotMappedAttribute), false) .FirstOrDefault() as NotMappedAttribute; if (notMapped != null) { return; } DisplayNameAttribute display = property.GetCustomAttributes(typeof(DisplayNameAttribute), false) .FirstOrDefault() as DisplayNameAttribute; MaxLengthAttribute maxLength = property.GetCustomAttributes(typeof(MaxLengthAttribute), false) .FirstOrDefault() as MaxLengthAttribute; if (display == null) { return; } if (propertyType == typeof(string)) { //字符串 TextBox textBox = EditControls.FirstOrDefault(c => c.Name == typeof(TextBox).Name + property.Name) as TextBox; if (textBox != null) { object value = property.GetValue(goodsAdditional, null); textBox.Text = value != null?value.ToString() : ""; } } //日期 else if (propertyType == typeof(DateTime)) { DateTimePicker dateTimePicker = EditControls.FirstOrDefault(c => c.Name == typeof(DateTimePicker).Name + property.Name) as DateTimePicker; if (dateTimePicker != null) { object value = property.GetValue(goodsAdditional, null); DateTime date = DateTime.Parse(value.ToString()).Date; if (date > dateTimePicker.MinDate && date < dateTimePicker.MaxDate) { dateTimePicker.Value = DateTime.Parse(value.ToString()); } } } }
private void CellectProperty(PropertyInfo property) { Type propertyType = property.PropertyType; if (propertyType == typeof(Guid)) { return; } DataMemberAttribute dataMember = property.GetCustomAttributes(typeof(DataMemberAttribute), false) .FirstOrDefault() as DataMemberAttribute; if (dataMember == null) { return; } NotMappedAttribute notMapped = property.GetCustomAttributes(typeof(NotMappedAttribute), false) .FirstOrDefault() as NotMappedAttribute; if (notMapped != null) { return; } DisplayNameAttribute display = property.GetCustomAttributes(typeof(DisplayNameAttribute), false) .FirstOrDefault() as DisplayNameAttribute; MaxLengthAttribute maxLength = property.GetCustomAttributes(typeof(MaxLengthAttribute), false) .FirstOrDefault() as MaxLengthAttribute; if (display == null) { return; } if (propertyType == typeof(string)) { //字符串 TextBox textBox = EditControls.FirstOrDefault(c => c.Name == typeof(TextBox).Name + property.Name) as TextBox; if (textBox != null) { property.SetValue(goodsAdditional, textBox.Text.Trim(), null); } } //日期 else if (propertyType == typeof(DateTime)) { DateTimePicker dateTimePicker = EditControls.FirstOrDefault(c => c.Name == typeof(DateTimePicker).Name + property.Name) as DateTimePicker; if (dateTimePicker != null) { property.SetValue(goodsAdditional, dateTimePicker.Value, null); } } }