运行效果:
使用代码生成器(GZCodeGenerate)生成tb_EmpLeave的Model
生成器源代码下载地址:
https://github.com/GarsonZhang/GZCodeGenerate/
生成方式见上一节:
GZFramwork数据库层《一》普通表增删改查
新增一个自定义控件:ucTableUnitDocNo
后台代码同上一节ucTableUnit除了实例化bllBusiness不一样外其他都一样(红色背景标注)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using GZFramworkDB.BLL; using GZFramworkDB.Model; using GZFramworkDB.Main.MyControls; namespace GZFramworkDB.Main { public partial class ucTableUnitDocNo : UserControl,IData { bllBusiness bll; public ucTableUnitDocNo() { InitializeComponent(); bll = new bllBusiness(typeof(tb_EmpLeave), "AL", 4); } public void DoSearch() { gridControl1.DataSource = bll.GetSummaryData(); gridView1.BestFitColumns();//自动列宽 } DataTable dtSource { get { if (gridControl1.DataSource == null) return null; return gridControl1.DataSource as DataTable; } } //新增 public void DoAdd() { if (dtSource != null) dtSource.Rows.Add(); } //主键删除,立即删除,无需提交 public void DoDeleteKey() { DataRow dr = gridView1.GetFocusedDataRow(); if (dr != null) { string Keyvalue = dr[bll.SummaryKey].ToString(); if (bll.Delete(Keyvalue) == true) { dtSource.Rows.Remove(dr); } } } //缓存表删除,需要提交生效 public void DoDeleteTable() { gridView1.DeleteSelectedRows(); } //提交 public void DoUpdate() { bll.Update(dtSource); } } }
修改Main.cs:
添加事件:
//单据单表测试 private void menu_TableUnitDocNo_Click(object sender, EventArgs e) { foreach (Control col in pan_MyControls.Controls) { col.Visible = false; } TableUnitDocNo.Visible = true; uc = TableUnitDocNo; }
运行效果:
说明:
单号默认自动过滤包含4,7等数字,
可以修改存储过程:sys_GetDataSN
时间: 2024-11-05 14:37:33