您的位置:首页 > 编程语言

Database2Sharp重要更新之生成Winform框架界面代码

2011-09-05 22:49 621 查看
Database2Sharp是一款代码生成工具和数据库文档生成工具,该工具一直伴随着我及我的粉丝们经历过各种各样的项目开发,在实际开发中能带来效率的提高及编程的快乐。不过自上个6.0版本以来,我一直忙于各种项目及研究中,很少继续把新的思想整合进去,最近在做我的Winform开发框架的整理工作,觉得应该改进这段时间来发现的问题,并融入已经逐渐完善的Winform开发框架基础上来,于是经过几天的努力,把该代码生成工具的一些缺陷修复并增加了Winform界面代码生成的功能(以前一直只是生成底层及Web界面层),并重新命名版本号为7.0。以后再继续完善后,在此大版本上再继续升级吧。 View Code using System;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

using WHC.Dictionary;
using WHC.OrderWater.Commons;

using WHC.TestProject.BLL;
using WHC.TestProject.Entity;

namespace WHC.TestProject.UI
{
public partial class FrmEditItemDetail : BaseEditForm
{
public FrmEditItemDetail()
{
InitializeComponent();
}

/// <summary>
/// 实现控件输入检查的函数
/// </summary>
/// <returns></returns>
public override bool CheckInput()
{
bool result = true;//默认是可以通过

#region MyRegion

if (this.txtItemNo.Text.Trim().Length == 0)
{
MessageUtil.ShowTips("请输入备件编号");
this.txtItemNo.Focus();
result = false;
}
else if (this.txtItemName.Text.Trim().Length == 0)
{
MessageUtil.ShowTips("请输入备件名称");
this.txtItemName.Focus();
result = false;
}
else if (this.txtManufacture.Text.Trim().Length == 0)
{
MessageUtil.ShowTips("请输入供货商");
this.txtManufacture.Focus();
result = false;
}
#endregion

return result;
}

/// <summary>
/// 初始化数据字典
/// </summary>
private void InitDictItem()
{
//初始化代码
}

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

if (!string.IsNullOrEmpty(ID))
{
#region 显示客户信息
ItemDetailInfo info = BLLFactory<ItemDetail>.Instance.FindByID(ID);
if (info != null)
{
txtItemNo.Text = info.ItemNo;
txtItemName.Text = info.ItemName;
txtManufacture.Text = info.Manufacture;
txtMapNo.Text = info.MapNo;
txtSpecification.Text = info.Specification;
txtMaterial.Text = info.Material;
txtItemBigType.Text = info.ItemBigType;
txtItemType.Text = info.ItemType;
txtUnit.Text = info.Unit;
txtPrice.Text = info.Price;
txtSource.Text = info.Source;
txtStoragePos.Text = info.StoragePos;
txtUsagePos.Text = info.UsagePos;
txtNote.Text = info.Note;
txtWareHouse.Text = info.WareHouse;
txtDept.Text = info.Dept;
}
#endregion
//this.btnOK.Enabled = Portal.gc.HasFunction("ItemDetail/Edit");
}
else
{
//this.btnOK.Enabled = Portal.gc.HasFunction("ItemDetail/Add");
}
}

/// <summary>
/// 编辑或者保存状态下取值函数
/// </summary>
/// <param name="info"></param>
private void SetInfo(ItemDetailInfo info)
{
info.ItemNo = txtItemNo.Text;
info.ItemName = txtItemName.Text;
info.Manufacture = txtManufacture.Text;
info.MapNo = txtMapNo.Text;
info.Specification = txtSpecification.Text;
info.Material = txtMaterial.Text;
info.ItemBigType = txtItemBigType.Text;
info.ItemType = txtItemType.Text;
info.Unit = txtUnit.Text;
info.Price = txtPrice.Text;
info.Source = txtSource.Text;
info.StoragePos = txtStoragePos.Text;
info.UsagePos = txtUsagePos.Text;
info.Note = txtNote.Text;
info.WareHouse = txtWareHouse.Text;
info.Dept = txtDept.Text;
}

/// <summary>
/// 新增状态下的数据保存
/// </summary>
/// <returns></returns>
public override bool SaveAddNew()
{
ItemDetailInfo info = new ItemDetailInfo();
SetInfo(info);

try
{
#region 新增数据
//检查是否还有其他相同关键字的记录
bool exist = BLLFactory<ItemDetail>.Instance.IsExistKey("ItemNo", info.ItemNo);
if (exist)
{
MessageUtil.ShowTips("指定的【备件编号】已经存在,不能重复添加,请修改");
return false;
}
bool succeed = BLLFactory<ItemDetail>.Instance.Insert(info);
if (succeed)
{
//可添加其他关联操作

return true;
}
#endregion
}
catch (Exception ex)
{
LogHelper.Error(ex);
MessageUtil.ShowError(ex.Message);
}
return false;
}

/// <summary>
/// 编辑状态下的数据保存
/// </summary>
/// <returns></returns>
public override bool SaveUpdated()
{
//检查不同ID是否还有其他相同关键字的记录
bool exist = BLLFactory<ItemDetail>.Instance.CheckExist(this.txtItemNo.Text, ID);
if (exist)
{
MessageUtil.ShowTips("指定的【备件编号】已经存在,不能重复添加,请修改");
return false;
}
ItemDetailInfo info = BLLFactory<ItemDetail>.Instance.FindByID(ID);
if (info != null)
{
SetInfo(info);

try
{
#region 更新数据
bool succeed = BLLFactory<ItemDetail>.Instance.Update(info, info.ID.ToString());
if (succeed)
{
//可添加其他关联操作

return true;
}
#endregion
}
catch (Exception ex)
{
LogHelper.Error(ex);
MessageUtil.ShowError(ex.Message);
}
}
return false;
}
}
}
DevExpress界面效果图



Database2Sharp代码生成工具已经上传到服务器,需要该代码生成工具的,请到下载地址(http://www.iqidi.com/download/Database2SharpSetup.rar )下载。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐