主从表演练之采购单
一、数据库新建表
主表 tb_PO 明细表 tb_PODetail
tb_PO表SQL创建脚本
SQL 全选
CREATE TABLE [dbo].[tb_PO](
[isid] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[DocNo] [varchar](20) NOT NULL,
[DocDate] [date] NULL,
[SupplierID] [varchar](20) NULL,
[SupplierName] [nvarchar](50) NULL,
[SupplierAddress] [nvarchar](200) NULL,
[SupplierPhone] [varchar](50) NULL,
[FromAddress] [nvarchar](200) NULL,
[TotalAmount] [decimal](18, 2) NULL,
[PayType] [varchar](10) NULL,
[Remark] [nvarchar](200) NULL,
[DocType] [int] NULL,
[CreateUser] [varchar](20) NULL,
[CreateDate] [datetime] NULL,
[LastUpdateUser] [varchar](20) NULL,
[LastUpdateDate] [datetime] NULL,
CONSTRAINT [PK_TB_PO] PRIMARY KEY CLUSTERED
(
[DocNo] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'自增列' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'isid'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单据编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'DocNo'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单据日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'DocDate'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'供应商编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'SupplierID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'供应商名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'SupplierName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'供应商地址' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'SupplierAddress'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'联系电话' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'SupplierPhone'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'提货地址' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'FromAddress'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'总金额' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'TotalAmount'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'结算方式' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'PayType'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'Remark'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'状态 0:挂起 1:提交 -1:废弃' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'DocType'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'CreateUser'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'CreateDate'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'LastUpdateUser'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO', @level2type=N'COLUMN',@level2name=N'LastUpdateDate'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'采购入库单' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PO'
GO
tb_PODetail表创建SQL脚本
SQL 全选
CREATE TABLE [dbo].[tb_PODetail](
[isid] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[DocNo] [varchar](20) NULL,
[ProductID] [varchar](20) NULL,
[JZS] [int] NULL,
[Unit] [varchar](10) NULL,
[SPID] [varchar](20) NULL,
[Qty] [decimal](18, 2) NULL,
[Price] [decimal](18, 2) NULL,
[Amount] [decimal](18, 2) NULL,
[Remark] [nvarchar](200) NULL,
[CreateUser] [varchar](20) NULL,
[CreateDate] [datetime] NULL,
[LastUpdateUser] [varchar](20) NULL,
[LastUpdateDate] [datetime] NULL,
CONSTRAINT [PK_TB_PODETAIL] PRIMARY KEY CLUSTERED
(
[isid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'自增列' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'isid'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单据编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'DocNo'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'产品编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'ProductID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'件/支数' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'JZS'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'Unit'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'仓位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'SPID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'Qty'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单价' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'Price'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'金额' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'Amount'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'Remark'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'CreateUser'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'创建时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'CreateDate'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'LastUpdateUser'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail', @level2type=N'COLUMN',@level2name=N'LastUpdateDate'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'采购入库明细' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_PODetail'
GO
二、代码生成器生成代码
1)生成Model代码
tb_PO设置
tb_PODetail设置
选中要生成Model的表,然后点击下方的 添加 按钮,就能标记表为生成状态(打勾)
如果选错了,或者要取消表生成标记,右键表,弹出菜单中选择排除即可
生成的Model层代码文件
复制文件到项目Model层中
2)生成功能窗体
设置主表 选择 tb_PO
配置如下
添加明细表 选择 tb_PODetail ,然后选择添加明细按钮
明细表配置如下:
设置窗体信息:
配置如下:
生成后得到3个文件:
BLLDemo_PO为窗体业务bll层代码
复制bll层代码到项目 WinFrameworkDemo.Business 中
复制窗体代码:frmPO.cs 和 frmPO.designer.cs 到项目 WinframeworkDemo.Test 中
如果出现报错,添加缺失的命名空间即可
三、功能注册
修改 WinframeworkDemo.Test.Management.cs,添加功能 frmPo 的注册代码
C# 全选
namespace WinframeworkDemo.Test
{
public class Management : WinFramework.Library.Module
{
public Management() : base("开发演示模块", "Module_Dictionary")
{
// 注册功能
FunctionCollection.AddFunction(typeof(frmPO), "采购单", "Function_PO");
}
}
}
四、运行项目,导入模块
现在运行项目,再业务模块中是看不到我们添加的功能的,需要导入
运行项目,系统管理 → 模块维护
看到我们新增的功能后,点击操作区域中的保存按钮
更新模块信息后,要 重新登录 系统
重新登录后,就看到了我们添加的功能
五、调整界面UI
调整前,生成器生成的界面比较乱,尤其是编辑页面
我们需要手动调整一下
调整后:
六、测试增删改查功能
省略
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
YESWinform 管理员