`
hulunberbus
  • 浏览: 857373 次
文章分类
社区版块
存档分类
最新评论

数据收集用户界面解决方案2--示例应用

 
阅读更多

接上文。此文主要是关于如何应用的问题

大致问题都差不多,那么我们可以来看一下,界面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 索取原代码。

分享到:
评论

相关推荐

    X-Scan

    对于多数已知漏洞,我们给出了相应的漏洞描述、解决方案及详细描述链接,其它漏洞资料正在进一步整理完善中,您也可以通过本站的“安全文摘”和“安全漏洞”栏目查阅相关说明。 3.0版本提供了简单的插件开发包,...

    asp.net知识库

    一完美的关于请求的目录不存在而需要url重写的解决方案! 在C#中实现MSN消息框的功能 XmlHttp实现无刷新三联动ListBox 鼠标放在一个连接上,会显示图片(类似tooltip) 使用microsoft.web.ui.webcontrols的TabStrip与...

    X-Scan v3.1

    对于多数已知漏洞,我们给出了相应的漏洞描述、解决方案及详细描述链接,其它漏洞资料正在进一步整理完善中,您也可以通过本站的“安全文摘”和“安全漏洞”栏目查阅相关说明。 3.0版本提供了简单的插件开发包,...

    Thinking in Java(中文版 由yyc,spirit整理).chm

    A.2 微软的解决方案 A.3 J/Direct A.3.1 @dll.import引导命令 A.3.2 com.ms.win32包 A.3.3 汇集 A.3.4 编写回调函数 A.3.5 其他J/Direct特性 A.4 本原接口(RNI) A.4.1 RNI总结 A.5 Java/COM集成 A.5.1 COM基础 A....

    JAVA_Thinking in Java(中文版 由yyc,spirit整理).chm

    A.2 微软的解决方案 A.3 J/Direct A.3.1 @dll.import引导命令 A.3.2 com.ms.win32包 A.3.3 汇集 A.3.4 编写回调函数 A.3.5 其他J/Direct特性 A.4 本原接口(RNI) A.4.1 RNI总结 A.5 Java/COM集成 A.5.1 COM基础 A....

    x-SCAN -V3.3-CN.

    对于多数已知漏洞,我们给出了相应的漏洞描述、解决方案及详细描述链接,其它漏洞资料正在进一步整理完善中,您也可以通过本站的“安全文摘”和“安全漏洞”栏目查阅相关说明。 3.0及后续版本提供了简单的插件开发...

    写给大家看的面向对象编程书(第3版).[美]Matt Weisfeld(带详细书签).pdf

    8.4.3 一个电子商务解决方案 133 8.4.4 UML对象模型 133 8.5 小结 137 8.6 参考书目 137 8.7 本章使用的示例代码 138 8.7.1 TestShape示例:C#.NET 138 8.7.2 TestShape示例:VB.NET 140 第9章 构建对象 143 ...

    强大的扫描工具x-scan

    对于多数已知漏洞,我们给出了相应的漏洞描述、解决方案及详细描述链接,其它漏洞资 料正在进一步整理完善中,您也可以通过本站的“安全文摘”和“安全漏洞”栏目查阅相关说明。 3.0及后续版本提供了简单的插件...

    C#微软培训资料

    &lt;&lt;page 2&gt;&gt; page begin==================== 7.5 逻辑操作符和逻辑表达式.68 7.6 位 运 算 .69 7.7 其它特殊操作符 .72 7.8 小 结 .77 第八章 流 程 控 制 .79 8.1 条 件 语 句 .79 8.2 循 环 语 句 ....

Global site tag (gtag.js) - Google Analytics