public static void SetDefaultControlProperty(Control control, ref MapperInfo mi) { if (control is TextBox) //文本框 { mi.ControlProperty = "Text"; } else if (control is Label) //文本 { mi.ControlProperty = "Text"; } else if (control is Calendar) //Calendar { mi.ControlProperty = "SelectedDate"; } else if (control is CheckBox) //复选 { mi.ControlProperty = "Checked"; } else if (control is RadioButton) //单选 { mi.ControlProperty = "Checked"; } else if (control is ListBox) //列表 { mi.ControlProperty = "Text"; } }
public MapperInfo GetWinMapping(System.Windows.Forms.Control control) { if (this.Mappings.ContainsKey(control.Name)) { return(this.Mappings[control.Name]); } MapperInfo mi2 = new MapperInfo(this, control.Name); this.Mappings.Add(mi2); return(mi2); }
public MapperInfo GetWebMapping(System.Web.UI.Control control) { if (this.Mappings.ContainsKey(control.ID)) { return(this.Mappings[control.ID]); } MapperInfo mi2 = new MapperInfo(this, control.ID); this.Mappings.Add(mi2); return(mi2); }
public static void SetDefaultControlProperty(Control control, ref MapperInfo mi) { if (control is TextBox) //文本框 { mi.ControlProperty = "Text"; } else if (control is RichTextBox) //文本 { mi.ControlProperty = "Text"; } else if (control is Label) //文本 { mi.ControlProperty = "Text"; } else if (control is LinkLabel) //文本 { mi.ControlProperty = "Text"; } else if (control is DateTimePicker) //时间选择 { mi.ControlProperty = "Value"; } else if (control is ComboBox) //下拉列表 { mi.ControlProperty = "Text"; } else if (control is CheckBox) //复选 { mi.ControlProperty = "Checked"; } else if (control is RadioButton) //单选 { mi.ControlProperty = "Checked"; } else if (control is ListBox) //列表 { mi.ControlProperty = "Text"; } else if (control is NumericUpDown) //数字下拉 { mi.ControlProperty = "Value"; } }
public void SetWebMapping(System.Web.UI.Control control, MapperInfo value) { if (this.Mappings.ContainsKey(control.ID)) { MapperInfo mi = this.Mappings[control.ID]; mi.ControlProperty = value.ControlProperty; mi.DataProperty = value.DataProperty; if (mi.ControlProperty.Trim().Length == 0) { WebHelper.SetDefaultControlProperty(control, ref mi); } mi.Format = value.Format; } else { value.ControlID = control.ID; value.DataUIMapper = this; this.Mappings.Add(value); } }
/// <summary> /// 显示数据。 /// </summary> /// <param name="control"></param> /// <param name="mi"></param> /// <param name="value"></param> public static void SetControlDisplay(object control, MapperInfo mi, object value) { System.Type type = TypeHelper.GetTypeOfProperty(control, mi.ControlProperty); PropertyInfo pi = type.GetProperty(mi.ControlProperty); if (pi.PropertyType != typeof(string)) { pi.SetValue(control, value, new object[] { }); return; } //字符串属性 if (value is string) { pi.SetValue(control, value, new object[] { }); } else if (value is DateTime) //时间 { if (mi.Format == Format.Date) { pi.SetValue(control, ((DateTime)value).ToShortDateString(), new object[] { }); } if (mi.Format == Format.Time) { pi.SetValue(control, ((DateTime)value).ToShortTimeString(), new object[] { }); } if (mi.Format == Format.DateAndTime) { pi.SetValue(control, ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss"), new object[] { }); } else { pi.SetValue(control, ((DateTime)value).ToString(), new object[] { }); } } else if (value is float) { if (mi.Format == Format.F2) { pi.SetValue(control, ((float)value).ToString("F2"), new object[] { }); } if (mi.Format == Format.MF2) { pi.SetValue(control, ((float)value).ToString("C2"), new object[] { }); } if (mi.Format == Format.F4) { pi.SetValue(control, ((float)value).ToString("F4"), new object[] { }); } if (mi.Format == Format.MF4) { pi.SetValue(control, ((float)value).ToString("C4"), new object[] { }); } if (mi.Format == Format.F6) { pi.SetValue(control, ((float)value).ToString("F6"), new object[] { }); } if (mi.Format == Format.MF6) { pi.SetValue(control, ((float)value).ToString("C6"), new object[] { }); } else { pi.SetValue(control, ((float)value).ToString(), new object[] { }); } } else if (value is double) { if (mi.Format == Format.F2) { pi.SetValue(control, ((double)value).ToString("F2"), new object[] { }); } if (mi.Format == Format.MF2) { pi.SetValue(control, ((double)value).ToString("C2"), new object[] { }); } if (mi.Format == Format.F4) { pi.SetValue(control, ((double)value).ToString("F4"), new object[] { }); } if (mi.Format == Format.MF4) { pi.SetValue(control, ((double)value).ToString("C4"), new object[] { }); } if (mi.Format == Format.F6) { pi.SetValue(control, ((double)value).ToString("F6"), new object[] { }); } if (mi.Format == Format.MF6) { pi.SetValue(control, ((double)value).ToString("C6"), new object[] { }); } else { pi.SetValue(control, ((double)value).ToString(), new object[] { }); } } else if (value is decimal) { if (mi.Format == Format.F2) { pi.SetValue(control, ((decimal)value).ToString("F2"), new object[] { }); } if (mi.Format == Format.MF2) { pi.SetValue(control, ((decimal)value).ToString("C2"), new object[] { }); } if (mi.Format == Format.F4) { pi.SetValue(control, ((decimal)value).ToString("F4"), new object[] { }); } if (mi.Format == Format.MF4) { pi.SetValue(control, ((decimal)value).ToString("C4"), new object[] { }); } if (mi.Format == Format.F6) { pi.SetValue(control, ((decimal)value).ToString("F6"), new object[] { }); } if (mi.Format == Format.MF6) { pi.SetValue(control, ((decimal)value).ToString("C6"), new object[] { }); } else { pi.SetValue(control, ((decimal)value).ToString(), new object[] { }); } } else { pi.SetValue(control, value.ToString(), new object[] { }); } }