1.1:创建表结构
新建三张商品关联的表,表模型如下:
创建SQL语句略
1.2:生成表Model(生成方法见上一节)
1.3:生成tb_ProductType的单结构界面然后添加到项目中
1.4:修改GZVIP.Dictionary模块中DictionaryMain类,新增产品类型功能
public class DictionaryMain : ModuleFunctionManage { public DictionaryMain() { FunPools.AddFunction(typeof(frm_Level), "等级管理", "Level"); FunPools.AddFunction(typeof(frm_ProductType), "产品类型", "ProductType"); } }
Image添加如下三个图片如下
相应修改frm_ProductType界面
运行重新加载字典管理DLL结果如下:
至此:商品类型添加完毕
接下来生成商品管理
2.1生成tb_Product表的但结构界面并附加到项目
对界面做一些简单设置:
切换到后台代码修改Load代码(红色部分):
private void frm_Product_Load(object sender, EventArgs e) { _SummaryView = gv_Summary; gv_Summary.OptionsView.ColumnAutoWidth = false; //_bll = new bllBusiness(typeof(tb_Product),"P",4); _bll = new bllBusiness<tb_Product>("P", 4, typeof(tb_ProductPrice)); //添加只读列 base.AddControlsOnlyRead(txtCreateUser,txtCreateDate,txtLastUpdateUser,txtLastUpdateDate); //只有新增状态下才可用 base.AddControlsOnAddKey(); this.BoundDatasource(); }
修改DoBoundEditData方法
//绑定明细编辑页的数据 public override void DoBoundEditData() { //base.DoBoundEditData(); LibraryTools.DoBindingEditorPanel(layoutControl1, EditData.Tables[_bll.SummaryTableName], "txt"); gc_Detail.DataSource = EditData.Tables[tb_ProductPrice._TableName]; }
编辑数据编辑页增加按钮和删除按钮两个按钮的点击事件
//明细表增加 private void btn_DetailAdd_Click(object sender, EventArgs e) { //新增一条记录,并设置商品编号 DataRow dr = EditData.Tables[tb_ProductPrice._TableName].Rows.Add(); dr[tb_ProductPrice.ProductID] = txtProductID.EditValue; } //明细表删除 private void btn_DetailDelete_Click(object sender, EventArgs e) { if (gv_Detail.FocusedRowHandle < 0) return; if (Msg.AskQuestion("确定要删除选中的价格记录吗?") == false) return; gv_Detail.DeleteSelectedRows(); }
修改DictionaryMain类
public class DictionaryMain : ModuleFunctionManage { public DictionaryMain() { FunPools.AddFunction(typeof(frm_Level), "等级管理", "Level"); FunPools.AddFunction(typeof(frm_ProductType), "商品类型", "ProductType"); FunPools.AddFunction(typeof(frm_Product), "商品管理", "Product"); } }
2.2添加产品类别绑定
修改GZVIP.BLL.DastaCache类,增加ProductType只读属性
/// <summary> /// 产品类别 /// </summary> public DataTable ProductType { get { DataTable dt = CommonData.FindFromCache(tb_ProductType._TableName); if (dt == null) { dt = bllDataCommon.GetAllDataTable(tb_ProductType._TableName, Loginer.CurrentLoginer.SystemDBName , tb_ProductType.ProductTypeID, tb_ProductType.ProductTypeName); AddToCache(dt.Copy()); } return dt; } }
修改GZVIP.Library.BouindData类,增加BoundProductType()静态方法
/// <summary> /// 绑定商品类别 /// </summary> /// <param name="lue"></param> /// <param name="displayCombination"></param> /// <param name="ADDNULL"></param> public static void BoundProductType(LookUpEdit lue, bool displayCombination, bool ADDNULL) { lue.Properties.Columns.Clear(); InitializeControl(lue, new string[] { "编号", "名称" }, new string[] { tb_ProductType.ProductTypeID, tb_ProductType.ProductTypeName }); lue.Properties.Columns[0].Width = 40; lue.Properties.Columns[1].Width = 160; lue.Properties.PopupWidth = 200; DataTable dt = DataCache.Cache.ProductType.Copy(); if (ADDNULL) dt = Common.ADDNULL(dt); string displayMember = tb_ProductType.ProductTypeName; if (displayCombination) { Common.AddColumns(dt, tb_ProductType.ProductTypeID, tb_ProductType.ProductTypeName); displayMember = Common.DefNewColName; } DataBinder.BindingLookupEditDataSource(lue, dt, displayMember, tb_ProductType.ProductTypeID); } /// <summary> /// 绑定商品类别 /// </summary> /// <param name="lue"></param> /// <param name="displayCombination"></param> /// <param name="ADDNULL"></param> public static void BoundProductType(CheckedComboBoxEdit lue, bool displayCombination, bool ADDNULL) { DataTable dt = DataCache.Cache.ProductType.Copy(); if (ADDNULL) dt = Common.ADDNULL(dt); string displayMember = tb_ProductType.ProductTypeName; if (displayCombination) { Common.AddColumns(dt, tb_ProductType.ProductTypeID, tb_ProductType.ProductTypeName); displayMember = Common.DefNewColName; } DataBinder.BindingCheckedComboBoxSource(lue, dt, displayMember, tb_ProductType.ProductTypeID); }
在frm_Product的Load事件中添加数据源绑定
private void frm_Product_Load(object sender, EventArgs e) { _SummaryView = gv_Summary; gv_Summary.OptionsView.ColumnAutoWidth = false; //_bll = new bllBusiness(typeof(tb_Product),"P",4); _bll = new bllBusiness<tb_Product>("P", 4, typeof(tb_ProductPrice)); //添加只读列 base.AddControlsOnlyRead(txtCreateUser,txtCreateDate,txtLastUpdateUser,txtLastUpdateDate); //只有新增状态下才可用 base.AddControlsOnAddKey(); this.BoundDatasource(); } private void BoundDatasource() { DataBinderTools.Bound.BoundUserName(lue_UserName); DataBinderTools.Bound.BoundUserName(txtCreateUser); DataBinderTools.Bound.BoundUserName(txtLastUpdateUser); DataBinderTools.Bound.BoundProductType(txt_ProductType, false, true); DataBinderTools.Bound.BoundProductType(txtProductTypeID, true, true); }
重写ValidateBeforSave方法,用于保存前验证
//保存前数据验证 protected override bool ValidateBeforSave() { bool Validate = true & CommonTools.IsNotEmpBaseEdit(txtProductName, "产品名称不能为空!") & CommonTools.IsNotEmpBaseEdit(txtProductTypeID, "产品类别编号不能为空!") & CommonTools.IsNotEmpBaseEdit(txtProductPrice, "默认价格不能为空!"); //if (Validate == false) return; if (Validate == true) EditData.Tables[tb_Product._TableName].Rows[0][tb_Product.ProductTypeName] = (txtProductTypeID.GetSelectedDataRow() as DataRowView).Row[tb_ProductType.ProductTypeName]; return Validate; }
重写SetControlAccessable方法,修改状态改变的时候
/// <summary> /// 设置按钮可用状态,如果已经在ControlOnlyReads或SetControlAccessable中添加,这里不需要重新设置 /// </summary> /// <param name="Edit"></param> protected override void SetControlAccessable(bool Edit) { //LibraryTools.SetControlAccessable(tp_Edit, Edit); base.SetControlAccessable(Edit); gv_Detail.OptionsBehavior.Editable = Edit; }
完成以后运行重新加载模块,测试功能
添加商品到此完结
关于GZFramwork快速开发框架
作者:GarsonZhang QQ:382237285
唯一QQ交流群:288706356
欢迎提出您的宝贵意见
时间: 2024-11-06 09:43:54