您的位置:首页 > 其它

吉日嘎啦通用权限管理系统解读及重构升华--高度封装的编辑窗体

2010-05-31 23:06 976 查看
吉日嘎拉,一个专注于通用权限管理系统的开发狂热者,在博客园是一个有争议的人物,不过从其文章数量及内容介绍,专注肯定不是浪得虚名,一个人把东西做的专注,也就意味着更多的投入及考虑,可以作为后来者更多的借鉴。

本人获其友情赠送一套源码,用作深入分析及提炼使用,初一接触,整个体系架构还是比较庞大,如下所示。

代码

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.F5)
{
this.FormOnLoad();
}

if ((!(ActiveControl is Button)) &&
(keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Enter))
{
if (keyData == Keys.Enter)
{
System.Windows.Forms.SendKeys.Send("{TAB}");
return true;
}
if (keyData == Keys.Down)
{
System.Windows.Forms.SendKeys.Send("{TAB}");
}
else
{
SendKeys.Send("+{Tab}");
}

return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}

最后,我们看看具体的子类窗体,看新增编辑界面需要实现的代码,如下所示,其中大部分是原子级别的操作,逻辑操作已经在基类中实现了哦:

代码

public partial class FrmEditCustomer : BaseUI.BaseEditForm
{
public FrmEditCustomer()
{
InitializeComponent();
}

/// <summary>
/// 实现控件输入检查的函数
/// </summary>
/// <returns></returns>
public override bool CheckInput()
{
bool result = true;

#region 输入验证
if (this.txtName.Text.Length == 0)
{
MessageUtil.ShowTips("宾客名称不能为空");
this.txtName.Focus();
result = false;
}
else if (this.txtIDNumber.Text.Length == 0)
{
MessageUtil.ShowTips("证件号码不能为空");
this.txtIDNumber.Focus();
result = false;
}

#endregion

return result;
}

/// <summary>
/// 编辑或者保存状态下取值函数
/// </summary>
/// <param name="info"></param>
private void SetInfo(CustomerInfo info)
{
info.Address = txtAddress.Text;
info.CompanyName = txtCompany.Text;
info.IDCarType = cmbIDCarType.Text;
info.Name = txtName.Text;
info.Note = txtNote.Text;
info.IDNumber = txtIDNumber.Text;
info.Telephone = txtTelephone.Text;
info.Source = cmbSource.Text;
info.CustomerType = cmbType.Text;
info.Sex = cmbSex.Text;
}

/// <summary>
/// 数据字典加载
/// </summary>
private void InitDictItem()
{
this.cmbSource.Items.Clear();
this.cmbSource.Items.AddRange(DictItemUtil.GetCustomerSource());

this.cmbType.Items.Clear();
this.cmbType.Items.AddRange(DictItemUtil.GetCustomerType());

this.cmbIDCarType.Items.Clear();
this.cmbIDCarType.Items.AddRange(DictItemUtil.GetIDCarType());
}

/// <summary>
/// 数据显示的函数
/// </summary>
public override void DisplayData()
{
//数据字典加载(公用)
InitDictItem();

if (!string.IsNullOrEmpty(ID))
{
//编辑状态下的数据显示
CustomerInfo info = BLLFactory<Customer>.Instance.FindByID(ID);
if (info != null)
{
#region 显示客户信息
txtAddress.Text = info.Address;
txtCompany.Text = info.CompanyName;
txtName.Text = info.Name;
txtNote.Text = info.Note;
txtIDNumber.Text = info.IDNumber;
txtTelephone.Text = info.Telephone;
cmbSource.Text = info.Source;
cmbType.Text = info.CustomerType;
cmbSex.Text = info.Sex;
cmbIDCarType.Text = info.IDCarType;
lblCreateDate.Text = info.RegistrationDate.ToString();

#endregion
}
}
else
{
//新增状态的数据显示
lblCreateDate.Text = DateTime.Now.ToString();
}
}

/// <summary>
/// 新增状态下的数据保存
/// </summary>
/// <returns></returns>
public override bool SaveAddNew()
{
CustomerInfo info = new CustomerInfo();
SetInfo(info);
info.RegistrationDate = DateTime.Now;
bool succeed = BLLFactory<Customer>.Instance.Insert(info);
return succeed;
}

/// <summary>
/// 编辑状态下的数据保存
/// </summary>
/// <returns></returns>
public override bool SaveUpdated()
{
CustomerInfo info = BLLFactory<Customer>.Instance.FindByID(ID);
if (info != null)
{
SetInfo(info);
bool succeed = BLLFactory<Customer>.Instance.Update(info, info.ID.ToString());
return succeed;
}
return false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐