数据收集用户界面解决方案2--示例应用
2005-08-26 10:10
441 查看
接上文。此文主要是关于如何应用的问题
大致问题都差不多,那么我们可以来看一下,界面FrmAddBase及其子类(不同数据收集窗体)是如何工作的。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using JadeSoft.Common;
using System.Reflection;
namespace JadeSoft.Logistics.SystemInfo.UI
{
/// <summary>
/// FrmDeptAdd 的摘要说明。
/// </summary>
public class FrmAddBase : System.Windows.Forms.Form
{
/// <summary>
/// 当用户点击工具栏成功处理为基类里的方法后,需要通知子类执行的事件
/// </summary>
public event AfterToolClick OnAfterToolClick;
internal Infragistics.Win.UltraWinToolbars.UltraToolbarsManager ultraToolbarsManager1;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Left;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Right;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Top;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Bottom;
private System.Windows.Forms.ImageList toolImgs;
internal Infragistics.Win.UltraWinStatusBar.UltraStatusBar ultraStatusBar1;
internal System.Windows.Forms.ErrorProvider errProvider;
private System.ComponentModel.IContainer components;
protected Type _EntityType;//要控件的实体类型描述
protected IEntity _Entity; //实体对象
protected EntityController _EntityController; //实体控制器
public FrmAddBase()
{
InitializeComponent();
}
/// <summary>
/// 更新一个对象时使用的构造器
/// </summary>
/// <param name="commonEntity"></param>
public FrmAddBase(IEntity commonEntity):this()
{
_Entity=commonEntity;
_EntityType=commonEntity.GetType();
}
/// <summary>
/// 新建一个对象时使用的构造器
/// </summary>
/// <param name="EntityType"></param>
public FrmAddBase(Type EntityType):this()
{
_EntityType=EntityType;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("MainMenu");
Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool1 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("mnuFile");
Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar2 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("MainTool");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblNew");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblSave");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool3 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tlbExit");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool4 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblNew");
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool5 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tlbExit");
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool2 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("mnuFile");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool6 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblNew");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool7 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblSave");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool8 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tlbExit");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool9 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblSave");
Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmAddBase));
Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel1 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel2 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel3 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
this.ultraToolbarsManager1 = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(this.components);
this.toolImgs = new System.Windows.Forms.ImageList(this.components);
this._FrmDeptAdd_Toolbars_Dock_Area_Left = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._FrmDeptAdd_Toolbars_Dock_Area_Right = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._FrmDeptAdd_Toolbars_Dock_Area_Top = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this.ultraStatusBar1 = new Infragistics.Win.UltraWinStatusBar.UltraStatusBar();
this.errProvider = new System.Windows.Forms.ErrorProvider();
((System.ComponentModel.ISupportInitialize)(this.ultraToolbarsManager1)).BeginInit();
this.SuspendLayout();
//
// ultraToolbarsManager1
//
this.ultraToolbarsManager1.DesignerFlags = 0;
this.ultraToolbarsManager1.DockWithinContainer = this;
this.ultraToolbarsManager1.ImageListSmall = this.toolImgs;
this.ultraToolbarsManager1.ShowFullMenusDelay = 500;
this.ultraToolbarsManager1.Style = Infragistics.Win.UltraWinToolbars.ToolbarStyle.VisualStudio2005;
ultraToolbar1.DockedColumn = 0;
ultraToolbar1.DockedRow = 0;
ultraToolbar1.IsMainMenuBar = true;
ultraToolbar1.Text = "MainMenu";
ultraToolbar1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
popupMenuTool1});
ultraToolbar2.DockedColumn = 0;
ultraToolbar2.DockedRow = 1;
ultraToolbar2.Settings.AllowCustomize = Infragistics.Win.DefaultableBoolean.False;
ultraToolbar2.Settings.FillEntireRow = Infragistics.Win.DefaultableBoolean.True;
ultraToolbar2.Text = "MainTool";
buttonTool3.InstanceProps.IsFirstInGroup = true;
ultraToolbar2.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool1,
buttonTool2,
buttonTool3});
this.ultraToolbarsManager1.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] {
ultraToolbar1,
ultraToolbar2});
appearance1.Image = 0;
buttonTool4.SharedProps.AppearancesSmall.Appearance = appearance1;
buttonTool4.SharedProps.Caption = "新增";
appearance2.Image = 6;
buttonTool5.SharedProps.AppearancesSmall.Appearance = appearance2;
buttonTool5.SharedProps.Caption = "退出";
popupMenuTool2.SharedProps.Caption = "文件";
buttonTool8.InstanceProps.IsFirstInGroup = true;
popupMenuTool2.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool6,
buttonTool7,
buttonTool8});
appearance3.Image = 12;
buttonTool9.SharedProps.AppearancesSmall.Appearance = appearance3;
buttonTool9.SharedProps.Caption = "保存";
this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool4,
buttonTool5,
popupMenuTool2,
buttonTool9});
this.ultraToolbarsManager1.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.ultraToolbarsManager1_ToolClick);
//
// toolImgs
//
this.toolImgs.ImageSize = new System.Drawing.Size(16, 16);
this.toolImgs.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("toolImgs.ImageStream")));
this.toolImgs.TransparentColor = System.Drawing.Color.Transparent;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Left
//
this._FrmDeptAdd_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.Location = new System.Drawing.Point(0, 50);
this._FrmDeptAdd_Toolbars_Dock_Area_Left.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Left";
this._FrmDeptAdd_Toolbars_Dock_Area_Left.Size = new System.Drawing.Size(0, 284);
this._FrmDeptAdd_Toolbars_Dock_Area_Left.ToolbarsManager = this.ultraToolbarsManager1;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Right
//
this._FrmDeptAdd_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.Location = new System.Drawing.Point(504, 50);
this._FrmDeptAdd_Toolbars_Dock_Area_Right.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Right";
this._FrmDeptAdd_Toolbars_Dock_Area_Right.Size = new System.Drawing.Size(0, 284);
this._FrmDeptAdd_Toolbars_Dock_Area_Right.ToolbarsManager = this.ultraToolbarsManager1;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Top
//
this._FrmDeptAdd_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.Location = new System.Drawing.Point(0, 0);
this._FrmDeptAdd_Toolbars_Dock_Area_Top.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Top";
this._FrmDeptAdd_Toolbars_Dock_Area_Top.Size = new System.Drawing.Size(504, 50);
this._FrmDeptAdd_Toolbars_Dock_Area_Top.ToolbarsManager = this.ultraToolbarsManager1;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Bottom
//
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.Location = new System.Drawing.Point(0, 334);
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Bottom";
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.Size = new System.Drawing.Size(504, 0);
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.ToolbarsManager = this.ultraToolbarsManager1;
//
// ultraStatusBar1
//
this.ultraStatusBar1.Location = new System.Drawing.Point(0, 334);
this.ultraStatusBar1.Name = "ultraStatusBar1";
ultraStatusPanel1.Key = "BillState";
ultraStatusPanel1.Text = "单据状态:新增";
ultraStatusPanel1.Width = 120;
ultraStatusPanel2.Key = "SaveState";
ultraStatusPanel2.SizingMode = Infragistics.Win.UltraWinStatusBar.PanelSizingMode.Spring;
ultraStatusPanel3.DateTimeFormat = "hh:mm:ss";
ultraStatusPanel3.Style = Infragistics.Win.UltraWinStatusBar.PanelStyle.Date;
ultraStatusPanel3.Width = 70;
this.ultraStatusBar1.Panels.AddRange(new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel[] {
ultraStatusPanel1,
ultraStatusPanel2,
ultraStatusPanel3});
this.ultraStatusBar1.Size = new System.Drawing.Size(504, 23);
this.ultraStatusBar1.TabIndex = 4;
this.ultraStatusBar1.ViewStyle = Infragistics.Win.UltraWinStatusBar.ViewStyle.VisualStudio2005;
//
// errProvider
//
this.errProvider.ContainerControl = this;
//
// FrmAddBase
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(504, 357);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Left);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Right);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Top);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Bottom);
this.Controls.Add(this.ultraStatusBar1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "FrmAddBase";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "新增资料模板窗体";
this.Load += new System.EventHandler(this.FrmAddBase_Load);
((System.ComponentModel.ISupportInitialize)(this.ultraToolbarsManager1)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region 虚函数,派生类自己可以实现特定规则
/// <summary>
/// 检查界面控件数据是否符合要求,由派生类自己实现
/// </summary>
protected virtual bool CheckData()
{
return true;
}
/// <summary>
/// 在派生类中设置界面元素的值,因为有时在派生类界面保存实体对象时,还想修改一下界面上的值的可能性,同派生类自己实现
/// </summary>
protected virtual void SetUI()
{
}
#endregion
/// <summary>
/// 设错误提示
/// </summary>
/// <param name="control">要提示的控件</param>
/// <param name="ErrMsg">提示信息</param>
protected void SetErrInfo(Control control,string ErrMsg)
{
errProvider.SetError(control,ErrMsg);
this.ultraStatusBar1.Panels["SaveState"].Text=ErrMsg;
if(ErrMsg.Length!=0)
{
control.Focus();
}
}
private void CancelErrorIcon()
{
foreach(Control c in this.Controls)
{
errProvider.SetError(c,"");
}
}
/// <summary>
/// 设置当前单据操作状态
/// </summary>
/// <param name="pBillOpt"></param>
protected void SetBillStatus(BillOperator pBillOpt)
{
switch(pBillOpt)
{
case BillOperator.New:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:新增";
break;
case BillOperator.Update:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:修改";
break;
case BillOperator.Saved:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:已保存";
break;
case BillOperator.Edit:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:编辑中";
break;
}
}
private void FrmAddBase_Load(object sender, System.EventArgs e)
{
this.Closing+=new CancelEventHandler(FrmAddBase_Closing);
}
//此方法在子类需要手工调用一下。如数据实体类的属性值是某个集合中的一员(下拉列表框等选择而来)则子类窗体需先填充好数据,再调用此方法
public void DisplayUI()
{
//窗体加载时,先实例化实体控制器
if(_Entity==null) //如果实体为空,则使用反射动态新建一个实体对象
{
CreateIEntity();
SetBillStatus(BillOperator.New);
}
else
{
SetBillStatus(BillOperator.Update);
}
_EntityController=new EntityController(this);
_EntityController.BindUI( _Entity);
}
//将实体对象保存到数据库中
private bool SaveEntity()
{
if(CheckData())//如数据正确
{
SetUI();
if(_Entity.IsPersist!=JadeSoft.Common.EntityStatus.New)
{
_Entity.IsPersist=EntityStatus.Update;
}
_EntityController.UpdateEntity();
SetBillStatus(BillOperator.Saved);
MessageBox.Show("当前单据信息已成功保存",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
return true;
}
return false;
}
/// <summary>
/// 概据元数据动态创建一个对象
/// </summary>
private void CreateIEntity()
{
_Entity =(IEntity)Activator.CreateInstance(_EntityType);
_Entity.OID=System.Guid.NewGuid();//给对象分配一个新的ID
}
/// <summary>
/// 工具栏事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
try
{
switch (e.Tool.Key)
{
case "tblNew":
//如果用户界面控件的值发生改变
if(_EntityController.EntityStatusChanged())
{
DialogResult dr=MessageBox.Show("当前单据信息已改变!/r/n/r/n是否保存对当前单据的更改",this.Text,MessageBoxButtons.YesNoCancel,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button3);
if(dr==DialogResult.Cancel)
{//取消,单据不更改
return;
}
else if(dr==DialogResult.Yes)
{
//如成功保存数据
if(SaveEntity())
{
CreateIEntity();
_EntityController.BindUI(_Entity);
CancelErrorIcon();
}
}
else
{
CreateIEntity();
_EntityController.BindUI(_Entity);
CancelErrorIcon();
}
}
else
{
CreateIEntity();
_EntityController.BindUI(_Entity);
}
SetBillStatus(BillOperator.New);
if(OnAfterToolClick!=null)
OnAfterToolClick(sender,e);
break;
case "tlbExit": // ButtonTool
this.Close();
break;
case "tblSave": // 如果实体状态发生改变
if(_EntityController.EntityStatusChanged())
{
if(this.SaveEntity())
{
if(OnAfterToolClick!=null)
OnAfterToolClick(_Entity,e);
}
}
break;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void FrmAddBase_Closing(object sender, CancelEventArgs e)
{
if(_EntityController.EntityStatusChanged())
{
DialogResult dr=MessageBox.Show("当前单据信息已改变!/r/n/r/n是否保存对当前单据的更改",this.Text,MessageBoxButtons.YesNoCancel,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button3);
if(dr==DialogResult.Cancel)
{//取消,单据不更改
e.Cancel=true;
return;
}
else if(dr==DialogResult.Yes)
{
//如成功保存数据
if(!SaveEntity())
{
e.Cancel=true;
}
}
}
}
}
public delegate void AfterToolClick(object sender ,Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e);
/// <summary>
/// 单据的操作状态
/// </summary>
public enum BillOperator
{
New=0,//新增
Update=1,//更新
Saved=2, //已保存
Edit=3 //处于编辑状态
}
}
子类窗体的调用方式如下。
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using JadeSoft.Logistics.SystemInfo.BusinessFacades;
using JadeSoft.Common;
namespace JadeSoft.Logistics.SystemInfo.UI
{
public class FrmDeptAdd : JadeSoft.Logistics.SystemInfo.UI.FrmAddBase
{
#region 窗体变量
private Infragistics.Win.Misc.UltraLabel ultraLabel1;
private Infragistics.Win.Misc.UltraLabel ultraLabel2;
private Infragistics.Win.Misc.UltraLabel ultraLabel3;
private Infragistics.Win.Misc.UltraLabel ultraLabel4;
private Infragistics.Win.Misc.UltraLabel ultraLabel5;
private Infragistics.Win.Misc.UltraLabel ultraLabel6;
private Infragistics.Win.Misc.UltraLabel ultraLabel7;
private Infragistics.Win.Misc.UltraLabel ultraLabel8;
private Infragistics.Win.Misc.UltraLabel ultraLabel9;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtDeptCode;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtDeptName;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txttel;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtCreator;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtEditor;
private Infragistics.Win.UltraWinGrid.UltraCombo cboParentDept;
private Infragistics.Win.UltraWinGrid.UltraCombo cboDeptPerson;
private System.ComponentModel.IContainer components = null;
private Infragistics.Win.UltraWinEditors.UltraDateTimeEditor dtCreateTime;
private Infragistics.Win.UltraWinEditors.UltraDateTimeEditor dtEditTime;
FrmDeptDts frmOwner=null; //列表窗体指针,当此窗体新增时,要刷新列表窗体
#endregion
#region 构造器
public FrmDeptAdd(Department deptEntity ,FrmDeptDts ownerForm):base(deptEntity)
{
// 该调用是 Windows 窗体设计器所必需的。
InitializeComponent();
frmOwner=ownerForm;
}
public FrmDeptAdd(FrmDeptDts ownerForm):base(typeof(Department))
{
// 该调用是 Windows 窗体设计器所必需的。
InitializeComponent();
frmOwner=ownerForm;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region 设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
this.ultraLabel1 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel2 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel3 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel4 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel5 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel6 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel7 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel8 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel9 = new Infragistics.Win.Misc.UltraLabel();
this.txtDeptCode = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txtDeptName = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txttel = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txtCreator = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txtEditor = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.cboParentDept = new Infragistics.Win.UltraWinGrid.UltraCombo();
this.cboDeptPerson = new Infragistics.Win.UltraWinGrid.UltraCombo();
this.dtCreateTime = new Infragistics.Win.UltraWinEditors.UltraDateTimeEditor();
this.dtEditTime = new Infragistics.Win.UltraWinEditors.UltraDateTimeEditor();
((System.ComponentModel.ISupportInitialize)(this.txtDeptCode)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtDeptName)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txttel)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtCreator)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtEditor)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cboParentDept)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cboDeptPerson)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dtCreateTime)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dtEditTime)).BeginInit();
this.SuspendLayout();
//
// ultraLabel1
//
this.ultraLabel1.Location = new System.Drawing.Point(10, 64);
this.ultraLabel1.Name = "ultraLabel1";
this.ultraLabel1.Size = new System.Drawing.Size(72, 16);
this.ultraLabel1.TabIndex = 0;
this.ultraLabel1.Text = "部门编号: ";
//
// ultraLabel2
//
this.ultraLabel2.Location = new System.Drawing.Point(272, 64);
this.ultraLabel2.Name = "ultraLabel2";
this.ultraLabel2.Size = new System.Drawing.Size(72, 16);
this.ultraLabel2.TabIndex = 1;
this.ultraLabel2.Text = "部门名称:";
//
// ultraLabel3
//
this.ultraLabel3.Location = new System.Drawing.Point(272, 96);
this.ultraLabel3.Name = "ultraLabel3";
this.ultraLabel3.Size = new System.Drawing.Size(72, 16);
this.ultraLabel3.TabIndex = 2;
this.ultraLabel3.Text = "上级部门:";
//
// ultraLabel4
//
this.ultraLabel4.Location = new System.Drawing.Point(10, 96);
this.ultraLabel4.Name = "ultraLabel4";
this.ultraLabel4.Size = new System.Drawing.Size(72, 16);
this.ultraLabel4.TabIndex = 3;
this.ultraLabel4.Text = "电话:";
//
// ultraLabel5
//
this.ultraLabel5.Location = new System.Drawing.Point(10, 136);
this.ultraLabel5.Name = "ultraLabel5";
this.ultraLabel5.Size = new System.Drawing.Size(80, 16);
this.ultraLabel5.TabIndex = 4;
this.ultraLabel5.Text = "部门负责人:";
//
// ultraLabel6
//
this.ultraLabel6.Location = new System.Drawing.Point(10, 168);
this.ultraLabel6.Name = "ultraLabel6";
this.ultraLabel6.Size = new System.Drawing.Size(72, 16);
this.ultraLabel6.TabIndex = 5;
this.ultraLabel6.Text = "创建者:";
//
// ultraLabel7
//
this.ultraLabel7.Location = new System.Drawing.Point(272, 168);
this.ultraLabel7.Name = "ultraLabel7";
this.ultraLabel7.Size = new System.Drawing.Size(72, 16);
this.ultraLabel7.TabIndex = 6;
this.ultraLabel7.Text = "创建时间:";
//
// ultraLabel8
//
this.ultraLabel8.Location = new System.Drawing.Point(10, 200);
this.ultraLabel8.Name = "ultraLabel8";
this.ultraLabel8.Size = new System.Drawing.Size(72, 16);
this.ultraLabel8.TabIndex = 7;
this.ultraLabel8.Text = "修改者:";
//
// ultraLabel9
//
this.ultraLabel9.Location = new System.Drawing.Point(272, 200);
this.ultraLabel9.Name = "ultraLabel9";
this.ultraLabel9.Size = new System.Drawing.Size(72, 16);
this.ultraLabel9.TabIndex = 8;
this.ultraLabel9.Text = "修改时间:";
//
// txtDeptCode
//
appearance1.BorderColor = System.Drawing.Color.Black;
this.txtDeptCode.Appearance = appearance1;
this.txtDeptCode.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtDeptCode.Location = new System.Drawing.Point(83, 64);
this.txtDeptCode.Name = "txtDeptCode";
this.txtDeptCode.Size = new System.Drawing.Size(168, 19);
this.txtDeptCode.TabIndex = 1;
//
// txtDeptName
//
appearance2.BorderColor = System.Drawing.Color.Black;
this.txtDeptName.Appearance = appearance2;
this.txtDeptName.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtDeptName.Location = new System.Drawing.Point(336, 64);
this.txtDeptName.Name = "txtDeptName";
this.txtDeptName.Size = new System.Drawing.Size(168, 19);
this.txtDeptName.TabIndex = 2;
//
// txttel
//
appearance3.BorderColor = System.Drawing.Color.Black;
this.txttel.Appearance = appearance3;
this.txttel.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txttel.Location = new System.Drawing.Point(83, 96);
this.txttel.Name = "txttel";
this.txttel.Size = new System.Drawing.Size(168, 19);
this.txttel.TabIndex = 3;
//
// txtCreator
//
appearance4.BackColor = System.Drawing.Color.White;
appearance4.BorderColor = System.Drawing.Color.Black;
this.txtCreator.Appearance = appearance4;
this.txtCreator.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtCreator.Location = new System.Drawing.Point(83, 160);
this.txtCreator.Name = "txtCreator";
this.txtCreator.ReadOnly = true;
this.txtCreator.Size = new System.Drawing.Size(168, 19);
this.txtCreator.TabIndex = 6;
//
// txtEditor
//
appearance5.BackColor = System.Drawing.Color.White;
appearance5.BorderColor = System.Drawing.Color.Black;
this.txtEditor.Appearance = appearance5;
this.txtEditor.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtEditor.Location = new System.Drawing.Point(83, 192);
this.txtEditor.Name = "txtEditor";
this.txtEditor.ReadOnly = true;
this.txtEditor.Size = new System.Drawing.Size(168, 19);
this.txtEditor.TabIndex = 8;
//
// cboParentDept
//
this.cboParentDept.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.cboParentDept.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal;
this.cboParentDept.DisplayMember = "";
this.cboParentDept.DisplayStyle = Infragistics.Win.EmbeddableElementDisplayStyle.VisualStudio2005;
this.cboParentDept.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
this.cboParentDept.Location = new System.Drawing.Point(336, 96);
this.cboParentDept.Name = "cboParentDept";
this.cboParentDept.Size = new System.Drawing.Size(168, 19);
this.cboParentDept.TabIndex = 4;
this.cboParentDept.ValueMember = "";
this.cboParentDept.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.cboParentDept_InitializeLayout);
//
// cboDeptPerson
//
appearance6.BorderColor = System.Drawing.Color.Black;
appearance6.BorderColor3DBase = System.Drawing.Color.Black;
this.cboDeptPerson.Appearance = appearance6;
this.cboDeptPerson.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.cboDeptPerson.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal;
this.cboDeptPerson.DisplayMember = "";
this.cboDeptPerson.DisplayStyle = Infragistics.Win.EmbeddableElementDisplayStyle.VisualStudio2005;
this.cboDeptPerson.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
this.cboDeptPerson.Location = new System.Drawing.Point(83, 128);
this.cboDeptPerson.Name = "cboDeptPerson";
this.cboDeptPerson.Size = new System.Drawing.Size(168, 19);
this.cboDeptPerson.TabIndex = 5;
this.cboDeptPerson.ValueMember = "";
this.cboDeptPerson.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.cboDeptPerson_InitializeLayout);
//
// dtCreateTime
//
appearance7.BackColor = System.Drawing.Color.White;
this.dtCreateTime.Appearance = appearance7;
this.dtCreateTime.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.dtCreateTime.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never;
this.dtCreateTime.FormatProvider = new System.Globalization.CultureInfo("zh-CN");
this.dtCreateTime.FormatString = "";
this.dtCreateTime.Location = new System.Drawing.Point(336, 161);
this.dtCreateTime.MaskInput = "yyyy-mm-dd hh:mm:ss";
this.dtCreateTime.Name = "dtCreateTime";
this.dtCreateTime.ReadOnly = true;
this.dtCreateTime.Size = new System.Drawing.Size(167, 19);
this.dtCreateTime.TabIndex = 50;
//
// dtEditTime
//
appearance8.BackColor = System.Drawing.Color.White;
this.dtEditTime.Appearance = appearance8;
this.dtEditTime.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.dtEditTime.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never;
this.dtEditTime.FormatString = "";
this.dtEditTime.Location = new System.Drawing.Point(336, 193);
this.dtEditTime.MaskInput = "yyyy-mm-dd hh:mm:ss";
this.dtEditTime.Name = "dtEditTime";
this.dtEditTime.ReadOnly = true;
this.dtEditTime.Size = new System.Drawing.Size(167, 19);
this.dtEditTime.TabIndex = 49;
//
// FrmDeptAdd
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 261);
this.Controls.Add(this.dtCreateTime);
this.Controls.Add(this.dtEditTime);
this.Controls.Add(this.txtDeptCode);
this.Controls.Add(this.txtDeptName);
this.Controls.Add(this.txttel);
this.Controls.Add(this.txtCreator);
this.Controls.Add(this.txtEditor);
this.Controls.Add(this.cboDeptPerson);
this.Controls.Add(this.cboParentDept);
this.Controls.Add(this.ultraLabel1);
this.Controls.Add(this.ultraLabel2);
this.Controls.Add(this.ultraLabel3);
this.Controls.Add(this.ultraLabel4);
this.Controls.Add(this.ultraLabel5);
this.Controls.Add(this.ultraLabel6);
this.Controls.Add(this.ultraLabel7);
this.Controls.Add(this.ultraLabel8);
this.Controls.Add(this.ultraLabel9);
this.Name = "FrmDeptAdd";
this.Text = "部门资料管理体";
this.Load += new System.EventHandler(this.FrmDeptAdd_Load);
this.Controls.SetChildIndex(this.ultraLabel9, 0);
this.Controls.SetChildIndex(this.ultraLabel8, 0);
this.Controls.SetChildIndex(this.ultraLabel7, 0);
this.Controls.SetChildIndex(this.ultraLabel6, 0);
this.Controls.SetChildIndex(this.ultraLabel5, 0);
this.Controls.SetChildIndex(this.ultraLabel4, 0);
this.Controls.SetChildIndex(this.ultraLabel3, 0);
this.Controls.SetChildIndex(this.ultraLabel2, 0);
this.Controls.SetChildIndex(this.ultraLabel1, 0);
this.Controls.SetChildIndex(this.cboParentDept, 0);
this.Controls.SetChildIndex(this.cboDeptPerson, 0);
this.Controls.SetChildIndex(this.txtEditor, 0);
this.Controls.SetChildIndex(this.txtCreator, 0);
this.Controls.SetChildIndex(this.txttel, 0);
this.Controls.SetChildIndex(this.txtDeptName, 0);
this.Controls.SetChildIndex(this.txtDeptCode, 0);
this.Controls.SetChildIndex(this.dtEditTime, 0);
this.Controls.SetChildIndex(this.dtCreateTime, 0);
((System.ComponentModel.ISupportInitialize)(this.txtDeptCode)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtDeptName)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txttel)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtCreator)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtEditor)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.cboParentDept)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.cboDeptPerson)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dtCreateTime)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dtEditTime)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region 窗体加载事件
private void FrmDeptAdd_Load(object sender, System.EventArgs e)
{
InitDeptEmp();
InitDeptList();
DisplayUI();
txtCreator.Text=EmployeeManager.GetEmpNameByGuid((Guid)txtCreator.Tag);
txtEditor.Text=EmployeeManager.GetEmpNameByGuid((Guid)txtEditor.Tag);
base.OnAfterToolClick+=new AfterToolClick(FrmDeptAdd_OnAfterToolClick);
}
//覆写父类的检查数据有效动作。如果返回假,父类的操作将中断
protected override bool CheckData()
{
if(txtDeptCode.Text.Trim()=="")
{
SetErrInfo(txtDeptCode,"部门编号必填");
txtDeptCode.Focus();
return false;
}
else
{
SetErrInfo(txtDeptCode,"");
}
if(txtDeptName.Text.Trim()=="")
{
SetErrInfo(txtDeptCode,"部门名称必填");
txtDeptName.Focus();
return false;
}
else
{
SetErrInfo(txtDeptName,"");
}
if(cboParentDept.SelectedRow==null)
{
SetErrInfo(cboParentDept,"上级部门必填");
cboParentDept.Focus();
return false;
}
else
{
SetErrInfo(cboParentDept,"");
}
if(cboDeptPerson.SelectedRow==null)
{
SetErrInfo(cboDeptPerson,"部门负责人必填");
cboDeptPerson.Focus();
return false;
}
else
{
SetErrInfo(cboDeptPerson,"");
}
return true;
}
protected override void SetUI()
{
//设置单据修改人员为当前线程负责人的GUID,及当前时间.以便保存到数据库中
txtEditor.Tag=Permisser.CurrentUserGuid;
dtEditTime.DateTime=System.DateTime.Now;
}
#endregion
#region 初始化窗体界面中的下拉列表
private void InitDeptEmp()
{
EmployeeManager empManager=new EmployeeManager();
this.cboDeptPerson.DataSource=empManager.GetEmpsForDept();
this.cboDeptPerson.DisplayMember="EmpName";
this.cboDeptPerson.ValueMember="OID";
}
private void InitDeptList()
{
DeptManager dptMng=new DeptManager();
this.cboParentDept.DataSource=dptMng.GetAllDeptByRelation();
this.cboParentDept.DisplayMember="DeptName";
this.cboParentDept.ValueMember="OID";
}
private void cboParentDept_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
try
{
e.Layout.Grid.DisplayLayout.Load("CommonGrid.lyt");
e.Layout.Bands[0].Columns["OID"].Hidden=true;
e.Layout.Bands[0].Columns["DeptID"].Header.Caption="部门编号";
e.Layout.Bands[0].Columns["DeptName"].Header.Caption="部门名称";
e.Layout.Bands[0].Columns["Phone"].Header.Caption="电话";
e.Layout.Bands[0].Columns["ParentDeptName"].Header.Caption="上级部门";
e.Layout.Bands[0].Columns["EmpName"].Header.Caption="负责人";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void cboDeptPerson_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
try
{
e.Layout.Grid.DisplayLayout.Load("CommonGrid.lyt");
e.Layout.Bands[0].Columns["OID"].Hidden=true;
e.Layout.Bands[0].Columns["EmpID"].Header.Caption="员工编号";
e.Layout.Bands[0].Columns["EmpName"].Header.Caption="员工姓名";
e.Layout.Bands[0].Columns["DeptName"].Header.Caption="部门名称";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
#endregion
private void FrmDeptAdd_OnAfterToolClick(object sender,Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
Department dpt=(Department)sender;
frmOwner.UpdateDeptNode(dpt.OID.ToString(),dpt.DeptName,dpt.ParentID.ToString());
}
}
}
对于信息收集子窗体来说,做的事情就很简单了,只是做一些数据验证,然后提供了父类对数据保存前及保存后对子类函数的调用。以方便子类进行一些自定义操作。
此程序经过实际测试,运行良好,对于性能的损失也不是很大。同时解决了所有数据收集的重复操作过程。 以上代码只是初次实验代码。未经过优化。此次演示时,派生窗体的控件是事先构建好的,下次将注重解决界面控件自动生成问题。
如有意,请联系greystar@e172.com 索取原代码。
大致问题都差不多,那么我们可以来看一下,界面FrmAddBase及其子类(不同数据收集窗体)是如何工作的。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using JadeSoft.Common;
using System.Reflection;
namespace JadeSoft.Logistics.SystemInfo.UI
{
/// <summary>
/// FrmDeptAdd 的摘要说明。
/// </summary>
public class FrmAddBase : System.Windows.Forms.Form
{
/// <summary>
/// 当用户点击工具栏成功处理为基类里的方法后,需要通知子类执行的事件
/// </summary>
public event AfterToolClick OnAfterToolClick;
internal Infragistics.Win.UltraWinToolbars.UltraToolbarsManager ultraToolbarsManager1;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Left;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Right;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Top;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _FrmDeptAdd_Toolbars_Dock_Area_Bottom;
private System.Windows.Forms.ImageList toolImgs;
internal Infragistics.Win.UltraWinStatusBar.UltraStatusBar ultraStatusBar1;
internal System.Windows.Forms.ErrorProvider errProvider;
private System.ComponentModel.IContainer components;
protected Type _EntityType;//要控件的实体类型描述
protected IEntity _Entity; //实体对象
protected EntityController _EntityController; //实体控制器
public FrmAddBase()
{
InitializeComponent();
}
/// <summary>
/// 更新一个对象时使用的构造器
/// </summary>
/// <param name="commonEntity"></param>
public FrmAddBase(IEntity commonEntity):this()
{
_Entity=commonEntity;
_EntityType=commonEntity.GetType();
}
/// <summary>
/// 新建一个对象时使用的构造器
/// </summary>
/// <param name="EntityType"></param>
public FrmAddBase(Type EntityType):this()
{
_EntityType=EntityType;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("MainMenu");
Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool1 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("mnuFile");
Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar2 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("MainTool");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblNew");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblSave");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool3 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tlbExit");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool4 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblNew");
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool5 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tlbExit");
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool2 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("mnuFile");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool6 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblNew");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool7 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblSave");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool8 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tlbExit");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool9 = new Infragistics.Win.UltraWinToolbars.ButtonTool("tblSave");
Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmAddBase));
Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel1 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel2 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel3 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
this.ultraToolbarsManager1 = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(this.components);
this.toolImgs = new System.Windows.Forms.ImageList(this.components);
this._FrmDeptAdd_Toolbars_Dock_Area_Left = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._FrmDeptAdd_Toolbars_Dock_Area_Right = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._FrmDeptAdd_Toolbars_Dock_Area_Top = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this.ultraStatusBar1 = new Infragistics.Win.UltraWinStatusBar.UltraStatusBar();
this.errProvider = new System.Windows.Forms.ErrorProvider();
((System.ComponentModel.ISupportInitialize)(this.ultraToolbarsManager1)).BeginInit();
this.SuspendLayout();
//
// ultraToolbarsManager1
//
this.ultraToolbarsManager1.DesignerFlags = 0;
this.ultraToolbarsManager1.DockWithinContainer = this;
this.ultraToolbarsManager1.ImageListSmall = this.toolImgs;
this.ultraToolbarsManager1.ShowFullMenusDelay = 500;
this.ultraToolbarsManager1.Style = Infragistics.Win.UltraWinToolbars.ToolbarStyle.VisualStudio2005;
ultraToolbar1.DockedColumn = 0;
ultraToolbar1.DockedRow = 0;
ultraToolbar1.IsMainMenuBar = true;
ultraToolbar1.Text = "MainMenu";
ultraToolbar1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
popupMenuTool1});
ultraToolbar2.DockedColumn = 0;
ultraToolbar2.DockedRow = 1;
ultraToolbar2.Settings.AllowCustomize = Infragistics.Win.DefaultableBoolean.False;
ultraToolbar2.Settings.FillEntireRow = Infragistics.Win.DefaultableBoolean.True;
ultraToolbar2.Text = "MainTool";
buttonTool3.InstanceProps.IsFirstInGroup = true;
ultraToolbar2.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool1,
buttonTool2,
buttonTool3});
this.ultraToolbarsManager1.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] {
ultraToolbar1,
ultraToolbar2});
appearance1.Image = 0;
buttonTool4.SharedProps.AppearancesSmall.Appearance = appearance1;
buttonTool4.SharedProps.Caption = "新增";
appearance2.Image = 6;
buttonTool5.SharedProps.AppearancesSmall.Appearance = appearance2;
buttonTool5.SharedProps.Caption = "退出";
popupMenuTool2.SharedProps.Caption = "文件";
buttonTool8.InstanceProps.IsFirstInGroup = true;
popupMenuTool2.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool6,
buttonTool7,
buttonTool8});
appearance3.Image = 12;
buttonTool9.SharedProps.AppearancesSmall.Appearance = appearance3;
buttonTool9.SharedProps.Caption = "保存";
this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool4,
buttonTool5,
popupMenuTool2,
buttonTool9});
this.ultraToolbarsManager1.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.ultraToolbarsManager1_ToolClick);
//
// toolImgs
//
this.toolImgs.ImageSize = new System.Drawing.Size(16, 16);
this.toolImgs.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("toolImgs.ImageStream")));
this.toolImgs.TransparentColor = System.Drawing.Color.Transparent;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Left
//
this._FrmDeptAdd_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Left.Location = new System.Drawing.Point(0, 50);
this._FrmDeptAdd_Toolbars_Dock_Area_Left.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Left";
this._FrmDeptAdd_Toolbars_Dock_Area_Left.Size = new System.Drawing.Size(0, 284);
this._FrmDeptAdd_Toolbars_Dock_Area_Left.ToolbarsManager = this.ultraToolbarsManager1;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Right
//
this._FrmDeptAdd_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Right.Location = new System.Drawing.Point(504, 50);
this._FrmDeptAdd_Toolbars_Dock_Area_Right.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Right";
this._FrmDeptAdd_Toolbars_Dock_Area_Right.Size = new System.Drawing.Size(0, 284);
this._FrmDeptAdd_Toolbars_Dock_Area_Right.ToolbarsManager = this.ultraToolbarsManager1;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Top
//
this._FrmDeptAdd_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Top.Location = new System.Drawing.Point(0, 0);
this._FrmDeptAdd_Toolbars_Dock_Area_Top.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Top";
this._FrmDeptAdd_Toolbars_Dock_Area_Top.Size = new System.Drawing.Size(504, 50);
this._FrmDeptAdd_Toolbars_Dock_Area_Top.ToolbarsManager = this.ultraToolbarsManager1;
//
// _FrmDeptAdd_Toolbars_Dock_Area_Bottom
//
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText;
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.Location = new System.Drawing.Point(0, 334);
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.Name = "_FrmDeptAdd_Toolbars_Dock_Area_Bottom";
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.Size = new System.Drawing.Size(504, 0);
this._FrmDeptAdd_Toolbars_Dock_Area_Bottom.ToolbarsManager = this.ultraToolbarsManager1;
//
// ultraStatusBar1
//
this.ultraStatusBar1.Location = new System.Drawing.Point(0, 334);
this.ultraStatusBar1.Name = "ultraStatusBar1";
ultraStatusPanel1.Key = "BillState";
ultraStatusPanel1.Text = "单据状态:新增";
ultraStatusPanel1.Width = 120;
ultraStatusPanel2.Key = "SaveState";
ultraStatusPanel2.SizingMode = Infragistics.Win.UltraWinStatusBar.PanelSizingMode.Spring;
ultraStatusPanel3.DateTimeFormat = "hh:mm:ss";
ultraStatusPanel3.Style = Infragistics.Win.UltraWinStatusBar.PanelStyle.Date;
ultraStatusPanel3.Width = 70;
this.ultraStatusBar1.Panels.AddRange(new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel[] {
ultraStatusPanel1,
ultraStatusPanel2,
ultraStatusPanel3});
this.ultraStatusBar1.Size = new System.Drawing.Size(504, 23);
this.ultraStatusBar1.TabIndex = 4;
this.ultraStatusBar1.ViewStyle = Infragistics.Win.UltraWinStatusBar.ViewStyle.VisualStudio2005;
//
// errProvider
//
this.errProvider.ContainerControl = this;
//
// FrmAddBase
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(504, 357);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Left);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Right);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Top);
this.Controls.Add(this._FrmDeptAdd_Toolbars_Dock_Area_Bottom);
this.Controls.Add(this.ultraStatusBar1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "FrmAddBase";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "新增资料模板窗体";
this.Load += new System.EventHandler(this.FrmAddBase_Load);
((System.ComponentModel.ISupportInitialize)(this.ultraToolbarsManager1)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region 虚函数,派生类自己可以实现特定规则
/// <summary>
/// 检查界面控件数据是否符合要求,由派生类自己实现
/// </summary>
protected virtual bool CheckData()
{
return true;
}
/// <summary>
/// 在派生类中设置界面元素的值,因为有时在派生类界面保存实体对象时,还想修改一下界面上的值的可能性,同派生类自己实现
/// </summary>
protected virtual void SetUI()
{
}
#endregion
/// <summary>
/// 设错误提示
/// </summary>
/// <param name="control">要提示的控件</param>
/// <param name="ErrMsg">提示信息</param>
protected void SetErrInfo(Control control,string ErrMsg)
{
errProvider.SetError(control,ErrMsg);
this.ultraStatusBar1.Panels["SaveState"].Text=ErrMsg;
if(ErrMsg.Length!=0)
{
control.Focus();
}
}
private void CancelErrorIcon()
{
foreach(Control c in this.Controls)
{
errProvider.SetError(c,"");
}
}
/// <summary>
/// 设置当前单据操作状态
/// </summary>
/// <param name="pBillOpt"></param>
protected void SetBillStatus(BillOperator pBillOpt)
{
switch(pBillOpt)
{
case BillOperator.New:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:新增";
break;
case BillOperator.Update:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:修改";
break;
case BillOperator.Saved:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:已保存";
break;
case BillOperator.Edit:
this.ultraStatusBar1.Panels["BillState"].Text="单据状态:编辑中";
break;
}
}
private void FrmAddBase_Load(object sender, System.EventArgs e)
{
this.Closing+=new CancelEventHandler(FrmAddBase_Closing);
}
//此方法在子类需要手工调用一下。如数据实体类的属性值是某个集合中的一员(下拉列表框等选择而来)则子类窗体需先填充好数据,再调用此方法
public void DisplayUI()
{
//窗体加载时,先实例化实体控制器
if(_Entity==null) //如果实体为空,则使用反射动态新建一个实体对象
{
CreateIEntity();
SetBillStatus(BillOperator.New);
}
else
{
SetBillStatus(BillOperator.Update);
}
_EntityController=new EntityController(this);
_EntityController.BindUI( _Entity);
}
//将实体对象保存到数据库中
private bool SaveEntity()
{
if(CheckData())//如数据正确
{
SetUI();
if(_Entity.IsPersist!=JadeSoft.Common.EntityStatus.New)
{
_Entity.IsPersist=EntityStatus.Update;
}
_EntityController.UpdateEntity();
SetBillStatus(BillOperator.Saved);
MessageBox.Show("当前单据信息已成功保存",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
return true;
}
return false;
}
/// <summary>
/// 概据元数据动态创建一个对象
/// </summary>
private void CreateIEntity()
{
_Entity =(IEntity)Activator.CreateInstance(_EntityType);
_Entity.OID=System.Guid.NewGuid();//给对象分配一个新的ID
}
/// <summary>
/// 工具栏事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
try
{
switch (e.Tool.Key)
{
case "tblNew":
//如果用户界面控件的值发生改变
if(_EntityController.EntityStatusChanged())
{
DialogResult dr=MessageBox.Show("当前单据信息已改变!/r/n/r/n是否保存对当前单据的更改",this.Text,MessageBoxButtons.YesNoCancel,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button3);
if(dr==DialogResult.Cancel)
{//取消,单据不更改
return;
}
else if(dr==DialogResult.Yes)
{
//如成功保存数据
if(SaveEntity())
{
CreateIEntity();
_EntityController.BindUI(_Entity);
CancelErrorIcon();
}
}
else
{
CreateIEntity();
_EntityController.BindUI(_Entity);
CancelErrorIcon();
}
}
else
{
CreateIEntity();
_EntityController.BindUI(_Entity);
}
SetBillStatus(BillOperator.New);
if(OnAfterToolClick!=null)
OnAfterToolClick(sender,e);
break;
case "tlbExit": // ButtonTool
this.Close();
break;
case "tblSave": // 如果实体状态发生改变
if(_EntityController.EntityStatusChanged())
{
if(this.SaveEntity())
{
if(OnAfterToolClick!=null)
OnAfterToolClick(_Entity,e);
}
}
break;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void FrmAddBase_Closing(object sender, CancelEventArgs e)
{
if(_EntityController.EntityStatusChanged())
{
DialogResult dr=MessageBox.Show("当前单据信息已改变!/r/n/r/n是否保存对当前单据的更改",this.Text,MessageBoxButtons.YesNoCancel,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button3);
if(dr==DialogResult.Cancel)
{//取消,单据不更改
e.Cancel=true;
return;
}
else if(dr==DialogResult.Yes)
{
//如成功保存数据
if(!SaveEntity())
{
e.Cancel=true;
}
}
}
}
}
public delegate void AfterToolClick(object sender ,Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e);
/// <summary>
/// 单据的操作状态
/// </summary>
public enum BillOperator
{
New=0,//新增
Update=1,//更新
Saved=2, //已保存
Edit=3 //处于编辑状态
}
}
子类窗体的调用方式如下。
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using JadeSoft.Logistics.SystemInfo.BusinessFacades;
using JadeSoft.Common;
namespace JadeSoft.Logistics.SystemInfo.UI
{
public class FrmDeptAdd : JadeSoft.Logistics.SystemInfo.UI.FrmAddBase
{
#region 窗体变量
private Infragistics.Win.Misc.UltraLabel ultraLabel1;
private Infragistics.Win.Misc.UltraLabel ultraLabel2;
private Infragistics.Win.Misc.UltraLabel ultraLabel3;
private Infragistics.Win.Misc.UltraLabel ultraLabel4;
private Infragistics.Win.Misc.UltraLabel ultraLabel5;
private Infragistics.Win.Misc.UltraLabel ultraLabel6;
private Infragistics.Win.Misc.UltraLabel ultraLabel7;
private Infragistics.Win.Misc.UltraLabel ultraLabel8;
private Infragistics.Win.Misc.UltraLabel ultraLabel9;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtDeptCode;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtDeptName;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txttel;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtCreator;
private Infragistics.Win.UltraWinEditors.UltraTextEditor txtEditor;
private Infragistics.Win.UltraWinGrid.UltraCombo cboParentDept;
private Infragistics.Win.UltraWinGrid.UltraCombo cboDeptPerson;
private System.ComponentModel.IContainer components = null;
private Infragistics.Win.UltraWinEditors.UltraDateTimeEditor dtCreateTime;
private Infragistics.Win.UltraWinEditors.UltraDateTimeEditor dtEditTime;
FrmDeptDts frmOwner=null; //列表窗体指针,当此窗体新增时,要刷新列表窗体
#endregion
#region 构造器
public FrmDeptAdd(Department deptEntity ,FrmDeptDts ownerForm):base(deptEntity)
{
// 该调用是 Windows 窗体设计器所必需的。
InitializeComponent();
frmOwner=ownerForm;
}
public FrmDeptAdd(FrmDeptDts ownerForm):base(typeof(Department))
{
// 该调用是 Windows 窗体设计器所必需的。
InitializeComponent();
frmOwner=ownerForm;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region 设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
this.ultraLabel1 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel2 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel3 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel4 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel5 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel6 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel7 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel8 = new Infragistics.Win.Misc.UltraLabel();
this.ultraLabel9 = new Infragistics.Win.Misc.UltraLabel();
this.txtDeptCode = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txtDeptName = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txttel = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txtCreator = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.txtEditor = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
this.cboParentDept = new Infragistics.Win.UltraWinGrid.UltraCombo();
this.cboDeptPerson = new Infragistics.Win.UltraWinGrid.UltraCombo();
this.dtCreateTime = new Infragistics.Win.UltraWinEditors.UltraDateTimeEditor();
this.dtEditTime = new Infragistics.Win.UltraWinEditors.UltraDateTimeEditor();
((System.ComponentModel.ISupportInitialize)(this.txtDeptCode)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtDeptName)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txttel)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtCreator)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtEditor)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cboParentDept)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cboDeptPerson)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dtCreateTime)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dtEditTime)).BeginInit();
this.SuspendLayout();
//
// ultraLabel1
//
this.ultraLabel1.Location = new System.Drawing.Point(10, 64);
this.ultraLabel1.Name = "ultraLabel1";
this.ultraLabel1.Size = new System.Drawing.Size(72, 16);
this.ultraLabel1.TabIndex = 0;
this.ultraLabel1.Text = "部门编号: ";
//
// ultraLabel2
//
this.ultraLabel2.Location = new System.Drawing.Point(272, 64);
this.ultraLabel2.Name = "ultraLabel2";
this.ultraLabel2.Size = new System.Drawing.Size(72, 16);
this.ultraLabel2.TabIndex = 1;
this.ultraLabel2.Text = "部门名称:";
//
// ultraLabel3
//
this.ultraLabel3.Location = new System.Drawing.Point(272, 96);
this.ultraLabel3.Name = "ultraLabel3";
this.ultraLabel3.Size = new System.Drawing.Size(72, 16);
this.ultraLabel3.TabIndex = 2;
this.ultraLabel3.Text = "上级部门:";
//
// ultraLabel4
//
this.ultraLabel4.Location = new System.Drawing.Point(10, 96);
this.ultraLabel4.Name = "ultraLabel4";
this.ultraLabel4.Size = new System.Drawing.Size(72, 16);
this.ultraLabel4.TabIndex = 3;
this.ultraLabel4.Text = "电话:";
//
// ultraLabel5
//
this.ultraLabel5.Location = new System.Drawing.Point(10, 136);
this.ultraLabel5.Name = "ultraLabel5";
this.ultraLabel5.Size = new System.Drawing.Size(80, 16);
this.ultraLabel5.TabIndex = 4;
this.ultraLabel5.Text = "部门负责人:";
//
// ultraLabel6
//
this.ultraLabel6.Location = new System.Drawing.Point(10, 168);
this.ultraLabel6.Name = "ultraLabel6";
this.ultraLabel6.Size = new System.Drawing.Size(72, 16);
this.ultraLabel6.TabIndex = 5;
this.ultraLabel6.Text = "创建者:";
//
// ultraLabel7
//
this.ultraLabel7.Location = new System.Drawing.Point(272, 168);
this.ultraLabel7.Name = "ultraLabel7";
this.ultraLabel7.Size = new System.Drawing.Size(72, 16);
this.ultraLabel7.TabIndex = 6;
this.ultraLabel7.Text = "创建时间:";
//
// ultraLabel8
//
this.ultraLabel8.Location = new System.Drawing.Point(10, 200);
this.ultraLabel8.Name = "ultraLabel8";
this.ultraLabel8.Size = new System.Drawing.Size(72, 16);
this.ultraLabel8.TabIndex = 7;
this.ultraLabel8.Text = "修改者:";
//
// ultraLabel9
//
this.ultraLabel9.Location = new System.Drawing.Point(272, 200);
this.ultraLabel9.Name = "ultraLabel9";
this.ultraLabel9.Size = new System.Drawing.Size(72, 16);
this.ultraLabel9.TabIndex = 8;
this.ultraLabel9.Text = "修改时间:";
//
// txtDeptCode
//
appearance1.BorderColor = System.Drawing.Color.Black;
this.txtDeptCode.Appearance = appearance1;
this.txtDeptCode.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtDeptCode.Location = new System.Drawing.Point(83, 64);
this.txtDeptCode.Name = "txtDeptCode";
this.txtDeptCode.Size = new System.Drawing.Size(168, 19);
this.txtDeptCode.TabIndex = 1;
//
// txtDeptName
//
appearance2.BorderColor = System.Drawing.Color.Black;
this.txtDeptName.Appearance = appearance2;
this.txtDeptName.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtDeptName.Location = new System.Drawing.Point(336, 64);
this.txtDeptName.Name = "txtDeptName";
this.txtDeptName.Size = new System.Drawing.Size(168, 19);
this.txtDeptName.TabIndex = 2;
//
// txttel
//
appearance3.BorderColor = System.Drawing.Color.Black;
this.txttel.Appearance = appearance3;
this.txttel.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txttel.Location = new System.Drawing.Point(83, 96);
this.txttel.Name = "txttel";
this.txttel.Size = new System.Drawing.Size(168, 19);
this.txttel.TabIndex = 3;
//
// txtCreator
//
appearance4.BackColor = System.Drawing.Color.White;
appearance4.BorderColor = System.Drawing.Color.Black;
this.txtCreator.Appearance = appearance4;
this.txtCreator.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtCreator.Location = new System.Drawing.Point(83, 160);
this.txtCreator.Name = "txtCreator";
this.txtCreator.ReadOnly = true;
this.txtCreator.Size = new System.Drawing.Size(168, 19);
this.txtCreator.TabIndex = 6;
//
// txtEditor
//
appearance5.BackColor = System.Drawing.Color.White;
appearance5.BorderColor = System.Drawing.Color.Black;
this.txtEditor.Appearance = appearance5;
this.txtEditor.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.txtEditor.Location = new System.Drawing.Point(83, 192);
this.txtEditor.Name = "txtEditor";
this.txtEditor.ReadOnly = true;
this.txtEditor.Size = new System.Drawing.Size(168, 19);
this.txtEditor.TabIndex = 8;
//
// cboParentDept
//
this.cboParentDept.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.cboParentDept.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal;
this.cboParentDept.DisplayMember = "";
this.cboParentDept.DisplayStyle = Infragistics.Win.EmbeddableElementDisplayStyle.VisualStudio2005;
this.cboParentDept.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
this.cboParentDept.Location = new System.Drawing.Point(336, 96);
this.cboParentDept.Name = "cboParentDept";
this.cboParentDept.Size = new System.Drawing.Size(168, 19);
this.cboParentDept.TabIndex = 4;
this.cboParentDept.ValueMember = "";
this.cboParentDept.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.cboParentDept_InitializeLayout);
//
// cboDeptPerson
//
appearance6.BorderColor = System.Drawing.Color.Black;
appearance6.BorderColor3DBase = System.Drawing.Color.Black;
this.cboDeptPerson.Appearance = appearance6;
this.cboDeptPerson.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.cboDeptPerson.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal;
this.cboDeptPerson.DisplayMember = "";
this.cboDeptPerson.DisplayStyle = Infragistics.Win.EmbeddableElementDisplayStyle.VisualStudio2005;
this.cboDeptPerson.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
this.cboDeptPerson.Location = new System.Drawing.Point(83, 128);
this.cboDeptPerson.Name = "cboDeptPerson";
this.cboDeptPerson.Size = new System.Drawing.Size(168, 19);
this.cboDeptPerson.TabIndex = 5;
this.cboDeptPerson.ValueMember = "";
this.cboDeptPerson.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.cboDeptPerson_InitializeLayout);
//
// dtCreateTime
//
appearance7.BackColor = System.Drawing.Color.White;
this.dtCreateTime.Appearance = appearance7;
this.dtCreateTime.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.dtCreateTime.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never;
this.dtCreateTime.FormatProvider = new System.Globalization.CultureInfo("zh-CN");
this.dtCreateTime.FormatString = "";
this.dtCreateTime.Location = new System.Drawing.Point(336, 161);
this.dtCreateTime.MaskInput = "yyyy-mm-dd hh:mm:ss";
this.dtCreateTime.Name = "dtCreateTime";
this.dtCreateTime.ReadOnly = true;
this.dtCreateTime.Size = new System.Drawing.Size(167, 19);
this.dtCreateTime.TabIndex = 50;
//
// dtEditTime
//
appearance8.BackColor = System.Drawing.Color.White;
this.dtEditTime.Appearance = appearance8;
this.dtEditTime.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
this.dtEditTime.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never;
this.dtEditTime.FormatString = "";
this.dtEditTime.Location = new System.Drawing.Point(336, 193);
this.dtEditTime.MaskInput = "yyyy-mm-dd hh:mm:ss";
this.dtEditTime.Name = "dtEditTime";
this.dtEditTime.ReadOnly = true;
this.dtEditTime.Size = new System.Drawing.Size(167, 19);
this.dtEditTime.TabIndex = 49;
//
// FrmDeptAdd
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 261);
this.Controls.Add(this.dtCreateTime);
this.Controls.Add(this.dtEditTime);
this.Controls.Add(this.txtDeptCode);
this.Controls.Add(this.txtDeptName);
this.Controls.Add(this.txttel);
this.Controls.Add(this.txtCreator);
this.Controls.Add(this.txtEditor);
this.Controls.Add(this.cboDeptPerson);
this.Controls.Add(this.cboParentDept);
this.Controls.Add(this.ultraLabel1);
this.Controls.Add(this.ultraLabel2);
this.Controls.Add(this.ultraLabel3);
this.Controls.Add(this.ultraLabel4);
this.Controls.Add(this.ultraLabel5);
this.Controls.Add(this.ultraLabel6);
this.Controls.Add(this.ultraLabel7);
this.Controls.Add(this.ultraLabel8);
this.Controls.Add(this.ultraLabel9);
this.Name = "FrmDeptAdd";
this.Text = "部门资料管理体";
this.Load += new System.EventHandler(this.FrmDeptAdd_Load);
this.Controls.SetChildIndex(this.ultraLabel9, 0);
this.Controls.SetChildIndex(this.ultraLabel8, 0);
this.Controls.SetChildIndex(this.ultraLabel7, 0);
this.Controls.SetChildIndex(this.ultraLabel6, 0);
this.Controls.SetChildIndex(this.ultraLabel5, 0);
this.Controls.SetChildIndex(this.ultraLabel4, 0);
this.Controls.SetChildIndex(this.ultraLabel3, 0);
this.Controls.SetChildIndex(this.ultraLabel2, 0);
this.Controls.SetChildIndex(this.ultraLabel1, 0);
this.Controls.SetChildIndex(this.cboParentDept, 0);
this.Controls.SetChildIndex(this.cboDeptPerson, 0);
this.Controls.SetChildIndex(this.txtEditor, 0);
this.Controls.SetChildIndex(this.txtCreator, 0);
this.Controls.SetChildIndex(this.txttel, 0);
this.Controls.SetChildIndex(this.txtDeptName, 0);
this.Controls.SetChildIndex(this.txtDeptCode, 0);
this.Controls.SetChildIndex(this.dtEditTime, 0);
this.Controls.SetChildIndex(this.dtCreateTime, 0);
((System.ComponentModel.ISupportInitialize)(this.txtDeptCode)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtDeptName)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txttel)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtCreator)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtEditor)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.cboParentDept)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.cboDeptPerson)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dtCreateTime)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dtEditTime)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region 窗体加载事件
private void FrmDeptAdd_Load(object sender, System.EventArgs e)
{
InitDeptEmp();
InitDeptList();
DisplayUI();
txtCreator.Text=EmployeeManager.GetEmpNameByGuid((Guid)txtCreator.Tag);
txtEditor.Text=EmployeeManager.GetEmpNameByGuid((Guid)txtEditor.Tag);
base.OnAfterToolClick+=new AfterToolClick(FrmDeptAdd_OnAfterToolClick);
}
//覆写父类的检查数据有效动作。如果返回假,父类的操作将中断
protected override bool CheckData()
{
if(txtDeptCode.Text.Trim()=="")
{
SetErrInfo(txtDeptCode,"部门编号必填");
txtDeptCode.Focus();
return false;
}
else
{
SetErrInfo(txtDeptCode,"");
}
if(txtDeptName.Text.Trim()=="")
{
SetErrInfo(txtDeptCode,"部门名称必填");
txtDeptName.Focus();
return false;
}
else
{
SetErrInfo(txtDeptName,"");
}
if(cboParentDept.SelectedRow==null)
{
SetErrInfo(cboParentDept,"上级部门必填");
cboParentDept.Focus();
return false;
}
else
{
SetErrInfo(cboParentDept,"");
}
if(cboDeptPerson.SelectedRow==null)
{
SetErrInfo(cboDeptPerson,"部门负责人必填");
cboDeptPerson.Focus();
return false;
}
else
{
SetErrInfo(cboDeptPerson,"");
}
return true;
}
protected override void SetUI()
{
//设置单据修改人员为当前线程负责人的GUID,及当前时间.以便保存到数据库中
txtEditor.Tag=Permisser.CurrentUserGuid;
dtEditTime.DateTime=System.DateTime.Now;
}
#endregion
#region 初始化窗体界面中的下拉列表
private void InitDeptEmp()
{
EmployeeManager empManager=new EmployeeManager();
this.cboDeptPerson.DataSource=empManager.GetEmpsForDept();
this.cboDeptPerson.DisplayMember="EmpName";
this.cboDeptPerson.ValueMember="OID";
}
private void InitDeptList()
{
DeptManager dptMng=new DeptManager();
this.cboParentDept.DataSource=dptMng.GetAllDeptByRelation();
this.cboParentDept.DisplayMember="DeptName";
this.cboParentDept.ValueMember="OID";
}
private void cboParentDept_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
try
{
e.Layout.Grid.DisplayLayout.Load("CommonGrid.lyt");
e.Layout.Bands[0].Columns["OID"].Hidden=true;
e.Layout.Bands[0].Columns["DeptID"].Header.Caption="部门编号";
e.Layout.Bands[0].Columns["DeptName"].Header.Caption="部门名称";
e.Layout.Bands[0].Columns["Phone"].Header.Caption="电话";
e.Layout.Bands[0].Columns["ParentDeptName"].Header.Caption="上级部门";
e.Layout.Bands[0].Columns["EmpName"].Header.Caption="负责人";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void cboDeptPerson_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
try
{
e.Layout.Grid.DisplayLayout.Load("CommonGrid.lyt");
e.Layout.Bands[0].Columns["OID"].Hidden=true;
e.Layout.Bands[0].Columns["EmpID"].Header.Caption="员工编号";
e.Layout.Bands[0].Columns["EmpName"].Header.Caption="员工姓名";
e.Layout.Bands[0].Columns["DeptName"].Header.Caption="部门名称";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
#endregion
private void FrmDeptAdd_OnAfterToolClick(object sender,Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
Department dpt=(Department)sender;
frmOwner.UpdateDeptNode(dpt.OID.ToString(),dpt.DeptName,dpt.ParentID.ToString());
}
}
}
对于信息收集子窗体来说,做的事情就很简单了,只是做一些数据验证,然后提供了父类对数据保存前及保存后对子类函数的调用。以方便子类进行一些自定义操作。
此程序经过实际测试,运行良好,对于性能的损失也不是很大。同时解决了所有数据收集的重复操作过程。 以上代码只是初次实验代码。未经过优化。此次演示时,派生窗体的控件是事先构建好的,下次将注重解决界面控件自动生成问题。
如有意,请联系greystar@e172.com 索取原代码。
相关文章推荐
- 数据收集用户界面解决方案2--示例应用
- 数据收集用户界面解决方案1
- CYQ.Data 数据框架 应用示例 JSON通讯篇
- iOS 数据库篇3—SQL代码应用示例
- Android 后台发送邮件示例 (收集应用异常信息+Demo代码)
- java学习-JAVA基本排序法示例,JAVA数据类型转换 ,ArrayList用法,Calendar 简单应用
- CYQ.Data 数据框架 应用示例 JSON通讯篇
- iOS开发数据库篇—SQL代码应用示例
- 基于Greenplum Hadoop分布式平台的大数据解决方案及商业应用案例剖析视频教程
- 基于Greenplum Hadoop分布式平台的大数据解决方案及商业应用案例剖析
- chukwa在数据收集处理方面的应用
- CYQ.Data 轻量数据层之路 应用示例二 在线聊天(六)
- CYQ.Data 数据框架 应用示例 JSON通讯篇
- HreoWinGauge2.0组件集应用示例----数据输入输出
- ActiveReports 报表应用教程 (10)---交互式报表之向下钻取(详细数据按需显示解决方案)
- CYQ.Data 轻量数据层之路 应用示例三 Aop切入留言系统--操作日志(二十七)
- 基于Greenplum Hadoop分布式平台的大数据解决方案及商业应用案例剖析
- ZooKeeper教程资源收集(简介/原理/示例/解决方案)
- 千万级数据处理解决方案(收集)
- ActiveReports 报表应用教程 (10)---交互式报表之向下钻取(详细数据按需显示解决方案)