在很多系统中,数据库的CRUD(增删改查)都是非常实用的基础模块,稍复杂一些还需要主从表的CRUD。下面就是一个“一主三从”的刚开多表增删改查界面:
QuickCRUD(快速增删改查)模块界面
演示网址:https://www.delphibbs.com/QuickCRUD
主要功能特点:
- 多字段模糊查询。 在左上角的输入框内可以输入多个关键字,实现多字段模糊查询;
- 数据分页;
- 编辑数据;
- 新增数据;
- 删除数据;
- 打印表格;
- 数据排序
示例源码:https://www.delphibbs.com/media/source/QuickCRUD.zip
采用Delphi打开后,发现核心代码只有一行
dwCrud(self,FDConnection1,False,'');
只需要一行代码就可以完成如此复杂的功能。
提前需要进行数据表的设置,以明确需要哪些表,哪些字段等。数据表设置在Form1的StyleName中,为一个标准的JSON字符串,类似如下:
{
"table": "dwf_goods",
"pagesize": 5,
"rowheight": 40,
"fields": [
{
"name": "id",
"caption": "id",
"width": 50,
"align": "center",
"type": "auto"
},
{
"name": "goodsname",
"caption": "货品名称",
"width": 180,
"type": "string",
"must": 1,
"sort": 1
},
{
"name": "goodscode",
"caption": "编码",
"width": 120,
"must": 1,
"sort": 1
},
{
"name": "provider",
"caption": "供应商",
"type": "combo",
"list": [ "中兴", "华为", "迈华", "绿电" ],
"width": 180
},
{
"name": "spec",
"caption": "规格",
"type": "string",
"width": 150
},
{
"name": "unit",
"type": "combo",
"caption": "单位",
"list": [ "", "部", "个", "支", "台", "米", "辆", "套" ],
"width": 60
},
{
"name": "inprice",
"caption": "进价",
"width": 80,
"align": "right",
"type": "money",
"sort": 1
},
{
"name": "price",
"caption": "售价",
"width": 80,
"type": "money",
"align": "right",
"sort": 1
},
{
"name": "description",
"caption": "备注",
"width": 150
}
],
"slavepagesize": 5,
"slaverowheight": 30,
"slave": [
{
"caption": "详细参数",
"table": "dwf_goodsex",
"imageindex": 58,
"masterfield": "id",
"slavefield": "gid",
"edit": 1,
"new": 1,
"delete": 1,
"print": 0,
"fields": [
{
"name": "id",
"caption": "id",
"width": 80,
"align": "center",
"sort": 1,
"type": "auto"
},
{
"name": "gid",
"caption": "货品ID",
"align": "left",
"must": 1,
"type": "integer",
"width": 80
},
{
"name": "title",
"caption": "属性名称",
"must": 1,
"width": 120,
"must": 1
},
{
"name": "value",
"caption": "属性值",
"width": 180,
"must": 1
}
]
},
{
"caption": "进货记录",
"table": "dwf_inport",
"imageindex": 59,
"masterfield": "id",
"slavefield": "gid",
"edit": 0,
"new": 0,
"delete": 0,
"print": 1,
"fields": [
{
"name": "id",
"caption": "id",
"width": 80,
"sort": 1,
"align": "center",
"type": "auto"
},
{
"name": "gid",
"caption": "货品ID",
"type": "integer",
"must": 1,
"width": 140
},
{
"name": "provider",
"caption": "供应商",
"align": "left",
"must": 1,
"width": 180,
"must": 1
},
{
"name": "unit",
"caption": "单位",
"width": 60,
"type": "combo",
"list": [ "", "部", "个", "支", "台", "米", "辆", "套" ]
},
{
"name": "price",
"caption": "单价",
"type": "money",
"width": 80
},
{
"name": "num",
"caption": "数量",
"width": 80,
"type": "integer",
"must": 1
},
{
"name": "amount",
"caption": "金额",
"type": "money",
"width": 80
},
{
"name": "ware",
"caption": "仓库",
"width": 120
},
{
"name": "operator",
"caption": "操作员",
"must": 1,
"width": 100
},
{
"name": "date",
"caption": "日期",
"width": 120,
"type": "date"
},
{
"name": "remark",
"caption": "备注",
"width": 60
}
]
},
{
"caption": "销售记录",
"table": "dwf_outport",
"imageindex": 60,
"masterfield": "id",
"slavefield": "gid",
"edit": 0,
"new": 1,
"delete": 0,
"print": 1,
"fields": [
{
"name": "id",
"caption": "id",
"width": 50,
"align": "center",
"type": "auto"
},
{
"name": "gid",
"caption": "货品ID",
"type": "integer",
"width": 80
},
{
"name": "unit",
"caption": "单位",
"type": "combo",
"list": [ "", "部", "个", "支", "台", "米", "辆", "套" ],
"width": 80
},
{
"name": "price",
"caption": "单价",
"sort": 1,
"width": 80
},
{
"name": "num",
"caption": "数量",
"width": 80,
"type": "integer",
"must": 1
},
{
"name": "amount",
"caption": "金额",
"type": "money",
"width": 100
},
{
"name": "operator",
"caption": "经办人",
"width": 120,
"must": 1
},
{
"name": "date",
"caption": "日期",
"width": 200,
"type": "time"
},
{
"name": "remark",
"caption": "备注",
"width": 120
}
]
}
]
}
该配置JSON各属性的说明如下:
{
"table": "dwf_goods", //主数据表名称
"pagesize": 5, //主表每页显示记录数量
"rowheight": 40, //行高
"edit": 1, //显示“编辑”按钮,默认为1
"new": 1, //显示“新增”按钮,默认为1
"delete": 1, //显示“删除”按钮,默认为1
"print": 0, //显示“打印”按钮,默认为1
"fields": [ //主表字段列表
{
"name": "id", //字段1的名称
"caption": "id", //字段1的标题,如此项未设置,则指定为名称
"width": 50, //字段1显示宽度
"sort": 1, //字段1是否排序,默认0
"align": "center", //对齐方式
"type": "auto" //字段类型,目前有auto,string,integer,money,date,datetime,time等,默认string,后续陆续增加更多类型
},
......
{
"name": "description",
"caption": "备注",
"width": 150
}
],
"slavepagesize": 5, //从表每页显示记录数量
"slaverowheight": 30, //从表行高
"slave": [ //从表信息数组
{
"caption": "详细参数", //从表1标题
"table": "dwf_goodsex", //从表1数据表名称
"imageindex": 58, //从表1图标,序号见开发指南
"masterfield": "id", //和主表关联的主表字段
"slavefield": "gid", //和主表关联的从表字段
"edit": 1, //显示“编辑”按钮,默认为1
"new": 1, //显示“新增”按钮,默认为1
"delete": 1, //显示“删除”按钮,默认为1
"print": 0, //显示“打印”按钮,默认为1
"fields": [ //从表1字段列表
{
"name": "id", //从表1字段1名称
"caption": "id", //从表1字段1显示标题,如此项未设置,则指定为名称
"width": 80, //从表1字段1显示宽度,默认100
"align": "center", //从表1字段1对齐方式,默认center
"sort": 1, //从表1字段1是否排序,默认0
"type": "auto" //字段类型,目前有auto,string,integer,money,date,datetime,time等,默认string
},
......
{
"name": "value",
"caption": "属性值",
"width": 180,
"must": 1
}
]
},
{
"caption": "进货记录", //从表2标题
"table": "dwf_inport", //从表2数据表名称
"imageindex": 59, //从表2图标,序号见开发指南
"masterfield": "id", //和主表关联的主表字段
"slavefield": "gid", //和主表关联的从表字段
"edit": 0, //显示“编辑”按钮,默认为1
"new": 0, //显示“新增”按钮,默认为1
"delete": 0, //显示“删除”按钮,默认为1
"print": 1, //显示“打印”按钮,默认为1
"fields": [ //从表2字段列表
.......
]
}
]
}
通过类似以上的配置,就可以快速实现多表的CRUD了!
开发过程中,开发者只需要编辑好配置,就可以很快完成模块。
更多精彩功能,请关注碧树西风!欢迎转发! 欢迎交流