﻿--cd C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools
--SqlMetal /views  /server:WQ /database:SGGLDB_WH /code:C:\Model.cs /namespace:Model

--菜单新增
delete Sys_Menu where MenuId='5C07E135-C3AB-4CE4-97A2-C79970640272'
delete Sys_Menu where MenuId='B4702BFB-8CEB-46AD-BDC0-751D146FE228'
delete Sys_Menu where MenuId='34719347-E5EE-4491-9E92-B1270C187C7F'
delete Sys_Menu where MenuId='F0E06491-B1DA-4510-ABCA-D09F4B24EE50'
INSERT INTO dbo.Sys_Menu(MenuId,MenuName,Icon,Url,SortIndex,SuperMenu,MenuType,IsOffice,IsEnd,IsUsed)VALUES('5C07E135-C3AB-4CE4-97A2-C79970640272','系统划分',null,'TestRun/BeforeTestRun/DeviceRun.aspx',1,'AD6E08B6-5571-4FFB-BDBE-9E6811770BD6','Menu_TestRun',0,1,1)
INSERT INTO dbo.Sys_Menu(MenuId,MenuName,Icon,Url,SortIndex,SuperMenu,MenuType,IsOffice,IsEnd,IsUsed)VALUES('B4702BFB-8CEB-46AD-BDC0-751D146FE228','工作包设置',null,'TestRun/BeforeTestRun/SetWorkPackage.aspx',2,'AD6E08B6-5571-4FFB-BDBE-9E6811770BD6','Menu_TestRun',0,1,1)
INSERT INTO dbo.Sys_Menu(MenuId,MenuName,Icon,Url,SortIndex,SuperMenu,MenuType,IsOffice,IsEnd,IsUsed)VALUES('34719347-E5EE-4491-9E92-B1270C187C7F','工作包裁剪',null,'TestRun/BeforeTestRun/SubSysWorkPackage.aspx',3,'AD6E08B6-5571-4FFB-BDBE-9E6811770BD6','Menu_TestRun',0,1,1)
INSERT INTO dbo.Sys_Menu(MenuId,MenuName,Icon,Url,SortIndex,SuperMenu,MenuType,IsOffice,IsEnd,IsUsed)VALUES('F0E06491-B1DA-4510-ABCA-D09F4B24EE50','子系统资产导入',null,'TestRun/BeforeTestRun/SysPipingDeviceImport.aspx',4,'AD6E08B6-5571-4FFB-BDBE-9E6811770BD6','Menu_TestRun',0,1,1)
go

--==试车装置信息删除
if object_id(N'PreRun_SysDevice',N'U') is not null
drop table dbo.PreRun_SysDevice
--==工作包设置删除
if object_id(N'Work_Package',N'U') is not null
drop table dbo.Work_Package
--==子系统工作包管理删除
if object_id(N'SubSys_WorkPackage',N'U') is not null
drop table dbo.SubSys_WorkPackage
--==管道一览表删除
if object_id(N'Property_SysPiping',N'U') is not null
drop table dbo.Property_SysPiping
--==工艺设备一览表删除
if object_id(N'Technology_SysPiping',N'U') is not null
drop table dbo.Technology_SysPiping
--==子系统选择管道信息删除
if object_id(N'SubProperty_Select',N'U') is not null
drop table dbo.SubProperty_Select
--==子系统选择工艺设备信息删除
if object_id(N'SubTechnology_Select',N'U') is not null
drop table dbo.SubTechnology_Select

--==试车装置信息
if object_id(N'PreRun_SysDevice',N'U') is not null
drop table dbo.PreRun_SysDevice
CREATE TABLE dbo.PreRun_SysDevice(
	PreRunId varchar(50) NOT NULL,--主键	
	PreRunCode varchar(50) NULL,--编码
	PreRunName varchar(50) NULL,--名称
	ProjectId varchar(50) NULL,--项目主键
	PreRunLevel int NULL,--类型1:装置 2:工序 3:系统 4:子系统
	InstallationId varchar(50) NULL,--装置主键(冗余字段，方便后期关联适用)
	ProcessesId varchar(50) NULL,--工序主键(冗余字段，方便后期关联适用)
	SystemId varchar(50) NULL,--系统主键(冗余字段，方便后期关联适用)
	SubsystemId varchar(50) NULL,--子系统主键(冗余字段，方便后期关联适用)
	ParentId varchar (50) NULL,--上级主键	
	Remark nvarchar(150) NULL,--描述
	AddUser varchar(50) NULL,--添加人
	OperateTime datetime NULL,--操作日期
	Sort int NULL,--排序
 CONSTRAINT PK_PreRun_SysDevice PRIMARY KEY CLUSTERED 
(
	PreRunId 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

--==工作包设置
if object_id(N'PreRun_WorkPackage',N'U') is not null
drop table dbo.PreRun_WorkPackage
CREATE TABLE dbo.PreRun_WorkPackage(
	WorkPackId varchar(50) NOT NULL,--主键
	WorkPackCode varchar(50) NULL,--编码
	WorkPackName varchar(50) NULL,--名称
	Remark nvarchar(150) NULL,--备注
	AddUser varchar(50) NULL,--添加人
	AddTime datetime NULL,--添加日期
	Sort int NULL,--排序
 CONSTRAINT PK_PreRun_WorkPackage PRIMARY KEY CLUSTERED 
(
	WorkPackId 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

--预添加数据
delete PreRun_WorkPackage where WorkPackId='1C01150C-977E-499A-9173-95F319BEEF87'
delete PreRun_WorkPackage where WorkPackId='641DA0F4-42A7-4DE3-9A57-95A606016655'
delete PreRun_WorkPackage where WorkPackId='BEB24AE8-F66D-458B-ADFD-3810405B5EB8'
delete PreRun_WorkPackage where WorkPackId='02BC1E1E-E531-4738-B6EC-5CE5BDC47B43'
delete PreRun_WorkPackage where WorkPackId='474F94B6-E927-4E9A-A544-F8E1AE63F6FF'
delete PreRun_WorkPackage where WorkPackId='3289A3D2-0691-4AD1-BDF3-1FD784564E71'
delete PreRun_WorkPackage where WorkPackId='445B915B-3E6D-47BE-BFF4-8762695ADB20'
delete PreRun_WorkPackage where WorkPackId='73C7D1D7-6DA3-44DD-A88B-7DF0FF15AA4F'
delete PreRun_WorkPackage where WorkPackId='8845C52D-4C56-442E-9237-CE33E8FC66AA'
delete PreRun_WorkPackage where WorkPackId='B0D040D4-5867-4335-9258-75504E73987E'
delete PreRun_WorkPackage where WorkPackId='84C6DAD6-3ED8-4869-ADB4-2EDA3512DB16'
delete PreRun_WorkPackage where WorkPackId='963E658B-CB53-4FEA-BA7D-723C538B2BD5'
delete PreRun_WorkPackage where WorkPackId='598A028A-5812-40E3-9D9D-5180A36F4453'
delete PreRun_WorkPackage where WorkPackId='6D827784-6ABD-4327-ABB7-FDABAC99853F'
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('1C01150C-977E-499A-9173-95F319BEEF87','WP01','单机试车','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),1)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('641DA0F4-42A7-4DE3-9A57-95A606016655','WP02','管道冲洗','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),2)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('BEB24AE8-F66D-458B-ADFD-3810405B5EB8','WP03','管道吹扫','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),3)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('02BC1E1E-E531-4738-B6EC-5CE5BDC47B43','WP04','蒸汽吹扫','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),4)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('474F94B6-E927-4E9A-A544-F8E1AE63F6FF','WP05','化学清洗','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),5)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('3289A3D2-0691-4AD1-BDF3-1FD784564E71','WP06','烘炉','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),6)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('445B915B-3E6D-47BE-BFF4-8762695ADB20','WP07','催化剂装填','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),7)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('73C7D1D7-6DA3-44DD-A88B-7DF0FF15AA4F','WP08','分子筛装填','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),8)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('8845C52D-4C56-442E-9237-CE33E8FC66AA','WP09','电气调试','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),9)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('B0D040D4-5867-4335-9258-75504E73987E','WP10','仪表调试','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),10)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('84C6DAD6-3ED8-4869-ADB4-2EDA3512DB16','WP11','汽轮机试车','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),11)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('963E658B-CB53-4FEA-BA7D-723C538B2BD5','WP12','大机组试车','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),12)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('598A028A-5812-40E3-9D9D-5180A36F4453','WP13','气密','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),13)
INSERT INTO dbo.PreRun_WorkPackage(WorkPackId,WorkPackCode,WorkPackName,Remark,AddUser,AddTime,Sort)
VALUES('6D827784-6ABD-4327-ABB7-FDABAC99853F','WP14','清洁度检查','','C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0',GETDATE(),14)
go

--==子系统工作包管理
if object_id(N'PreRun_SubSysWorkPackage',N'U') is not null
drop table dbo.PreRun_SubSysWorkPackage
CREATE TABLE dbo.PreRun_SubSysWorkPackage(
	SubSysId varchar(50) NOT NULL,--主键
	SubSystemId varchar(50) NULL,--子系统主键
	WorkPackId varchar(50) NULL,--工作包主键
	WorkPackCode varchar(50) NULL,--工作包Code
	Remark nvarchar(150) NULL,--备注
	AddUser varchar(50) NULL,--添加人
	AddTime datetime NULL,--添加日期
	Sort int NULL,--排序
 CONSTRAINT PK_PreRun_SubSysWorkPackage PRIMARY KEY CLUSTERED 
(
	SubSysId 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

--==管道一览表
if object_id(N'PreRun_PropertySysPiping',N'U') is not null
drop table dbo.PreRun_PropertySysPiping
CREATE TABLE dbo.PreRun_PropertySysPiping(
	PropertyId varchar(50) NOT NULL,--主键
	SystemId varchar(50) NULL,--系统主键
	ProjectId varchar(50) NULL,--项目主键
	PipingCode varchar(50) NULL,--管道号
	Diameter varchar(50) NULL,--直径
	MaterialLevel varchar(50) NULL,--管道材料等级
	AdiabatType varchar(50) NULL,--绝热伴热类型
	AdiabatThickness varchar(50) NULL,--绝热伴热厚度
	MediumState varchar(50) NULL,--介质相态
	DrawingNo varchar(50) NULL,--P&ID图号
	PipingStart varchar(50) NULL,--管道起点
	PipingEnd varchar(50) NULL,--管道止点
	PipingLevel varchar(50) NULL,--压力管道级别
	NormalTemperature varchar(50) NULL,--正常条件温度
	NormalPressure varchar(50) NULL,--正常条件压力
	DesignTemperature varchar(50) NULL,--设计条件温度
	DesignPressure varchar(50) NULL,--设计条件压力
	PaintLevel varchar(50) NULL,--涂漆等级
	Remark nvarchar(150) NULL,--备注
	AddUser varchar(50) NULL,--添加人
	AddTime datetime NULL,--添加日期
	Sort int NULL,--排序
 CONSTRAINT PK_PreRun_PropertySysPiping PRIMARY KEY CLUSTERED 
(
	PropertyId 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

--==工艺设备一览表
if object_id(N'PreRun_TechnologySysPiping',N'U') is not null
drop table dbo.PreRun_TechnologySysPiping
CREATE TABLE dbo.PreRun_TechnologySysPiping(
	TechnologyId varchar(50) NOT NULL,--主键
	SystemId varchar(50) NULL,--系统主键
	ProjectId varchar(50) NULL,--项目主键
	TagNumber varchar(50) NULL,--设备位号
	NameSpecifications varchar(max) NULL,--设备名称和规格
	DrawingNo varchar(50) NULL,--图号或型号
	Materials varchar(50) NULL,--制造材料	
	NumOperate varchar(50) NULL,--数量操作
	NumStandby varchar(50) NULL,--数量备用
	WeightSingle varchar(50) NULL,--重量单重
	WeightTotal varchar(50) NULL,--重量总重
	Remark nvarchar(150) NULL,--备注
	AddUser varchar(50) NULL,--添加人
	AddTime datetime NULL,--添加日期
	Sort int NULL,--排序
 CONSTRAINT PK_PreRun_TechnologySysPiping PRIMARY KEY CLUSTERED 
(
	TechnologyId 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

--==子系统选择管道信息
if object_id(N'PreRun_SubPropertySelect',N'U') is not null
drop table dbo.PreRun_SubPropertySelect
CREATE TABLE dbo.PreRun_SubPropertySelect(
	SubPropertyId varchar(50) NOT NULL,--主键
	ProjectId varchar(50) NULL,--项目主键
	SubSystemId varchar(50) NULL,--子系统主键
	PropertyId varchar(50) NOT NULL,--管道主键
	Remark nvarchar(150) NULL,--备注
	AddUser varchar(50) NULL,--添加人
	AddTime datetime NULL,--添加日期
	Sort int NULL,--排序
 CONSTRAINT PK_PreRun_SubPropertySelect PRIMARY KEY CLUSTERED 
(
	SubPropertyId 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

--==子系统选择工艺设备信息
if object_id(N'PreRun_SubTechnologySelect',N'U') is not null
drop table dbo.PreRun_SubTechnologySelect
CREATE TABLE dbo.PreRun_SubTechnologySelect(
	SubTechnologyId varchar(50) NOT NULL,--主键
	ProjectId varchar(50) NULL,--项目主键
	SubSystemId varchar(50) NULL,--子系统主键
	TechnologyId varchar(50) NULL,--主键
	Remark nvarchar(150) NULL,--备注
	AddUser varchar(50) NULL,--添加人
	AddTime datetime NULL,--添加日期
	Sort int NULL,--排序
 CONSTRAINT PK_PreRun_SubTechnologySelect PRIMARY KEY CLUSTERED 
(
	SubTechnologyId 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