/// 设置窗体上对象的Text值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> protected virtual void SetEntity(EntityInterface entity) { Type type = entity.GetType(); foreach (Control control in panelContent.Controls) { SetControlValue(control, entity, type); } }
/// <summary> /// 删除实体类 /// </summary> /// <param name="entity"></param> public void EntityRemove(EntityInterface entity) { try { AssertLogin(); entity.SystemService = this; entity.Remove(); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取窗体上的对象 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> protected virtual void GetEntity(EntityInterface entity) { Type type = entity.GetType(); foreach (Control control in panelContent.Controls) { Type controlType = control.GetType().GetInterface(typeof(ITableControl).ToString()); if (controlType != null) { ITableControl tableControl = (ITableControl)control; type.InvokeMember(tableControl.ControlName, BindingFlags.SetProperty, null, entity, new object[] { tableControl.ControlText }); } } }
/// <summary> /// 更新实体类 /// </summary> /// <param name="entity"></param> public EntityInterface EntityUpdate(EntityInterface entity) { try { AssertLogin(); entity.SystemService = this; entity.Update(); return entity; } catch (Exception ex) { throw ex; } }
private void GetControlValue(Control controlItem,EntityInterface entity,Type type) { Type controlType = controlItem.GetType().GetInterface(typeof(ITableControl).ToString()); if (controlType != null) { ITableControl tableControl = (ITableControl)controlItem; Type proType = entity.GetType().GetProperty(tableControl.ControlName).PropertyType; type.InvokeMember(tableControl.ControlName, BindingFlags.SetProperty, null, entity, new object[] { Convert.ChangeType(tableControl.ControlText, proType) }); } foreach (Control control in controlItem.Controls) { GetControlValue(control, entity, type); } }
private void SetControlValue(Control controlItem, EntityInterface entity, Type type) { Type controlType = controlItem.GetType().GetInterface(typeof(ITableControl).ToString()); if (controlType != null) { ITableControl tableControl = (ITableControl)controlItem; object obj = type.InvokeMember(tableControl.ControlName, BindingFlags.GetProperty, null, entity, null); if (obj != null) tableControl.ControlText = obj.ToString(); } foreach (Control control in controlItem.Controls) { SetControlValue(control, entity, type); } }