--1.灵活消费子系统初始菜单表
INSERT INTO dbo.ST_MenuInfo(Menu_ID,System_No,Menu_No,Menu_Name,Menu_Hint,Para_ID,Call_Mode,Form_Name,ShortKey,
                        Menu_Index,Image_Index,Separator,InToolBar,Remark)
SELECT * FROM (SELECT 101[Menu_ID],'LH'[System_No],'LH_06'[Menu_No],'系统管理'[Menu_Name],NULL[Menu_Hint],-1[Para_ID],NULL[Call_Mode],
                      NULL[Form_Name],NULL[ShortKey],'1'[Menu_Index],NULL[Image_Index],NULL[Separator],0[InToolBar],NULL[Remark]
                UNION ALL SELECT 102,'LH','LH_0601','终端机状态','终端机状态',101,'1','TfrmMocState',NULL,'1',1,'1',0,NULL
                UNION ALL SELECT 103,'LH','LH_0602','退出系统','退出系统',101,'5','Exit',NULL,'2',0,'0',0,NULL
                UNION ALL SELECT 104,'LH','LH_01','基本资料',NULL,-1,NULL,NULL,NULL,'2',NULL,NULL,0,NULL
                UNION ALL SELECT 105,'LH','LH_0101','区域/场所设置','区域/场所设置',104,'2','TfrmAreaSite',NULL,'1',2,'1',0,NULL
                UNION ALL SELECT 106,'LH','LH_0102','商品设置','商品设置',104,'2','TfrmLHWareInfo',NULL,'2',4,'0',0,NULL
                UNION ALL SELECT 107,'LH','LH_0107','打折类型设置','打折类型设置',104,'2','TfrmDiscount',NULL,'3',4,'1',0,NULL
                UNION ALL SELECT 108,'LH','LH_0103','卡类设置','卡类设置',104,'2','TfrmCardTypeInfo',NULL,'4',5,'0',0,NULL
                UNION ALL SELECT 109,'LH','LH_0104','键值设置','键值设置',104,'2','TfrmKeyInfo',NULL,'5',5,'0',0,NULL
                UNION ALL SELECT 110,'LH','LH_0105','终端机设置','终端机设置',104,'2','TfrmMocSet',NULL,'6',5,'0',0,NULL
                UNION ALL SELECT 111,'LH','LH_02','出纳操作',NULL,-1,NULL,NULL,NULL,'3',NULL,NULL,0,NULL
                UNION ALL SELECT 112,'LH','LH_0201','消费纠错','消费纠错',111,'2','TfrmCorrectConsume',NULL,'1',8,'0',0,NULL
                UNION ALL SELECT 113,'LH','LH_0202','手工补消费','手工补消费',111,'2','TfrmSupplyConsume',NULL,'2',9,'0',0,NULL
                UNION ALL SELECT 114,'LH','LH_0203','U盘导入消费','U盘导入消费',111,'2','TfrmImportConsume',NULL,'3',10,'0',0,NULL
                UNION ALL SELECT 115,'LH','LH_03','消费明细',NULL,-1,NULL,NULL,NULL,'4',NULL,NULL,0,NULL
                UNION ALL SELECT 116,'LH','LH_0301','正常消费明细表','正常消费明细表',115,'1','TfrmNormalConsumeRpt',NULL,'1',12,'0',0,NULL
                UNION ALL SELECT 117,'LH','LH_0302','消费纠错明细表','消费纠错明细表',115,'1','TfrmCorrectConsumeRpt',NULL,'2',12,'0',0,NULL
                UNION ALL SELECT 118,'LH','LH_0303','手工补消费明细表','手工补消费明细表',115,'1','TfrmSupplyConsumeRpt',NULL,'3',12,'1',0,NULL
                UNION ALL SELECT 119,'LH','LH_0304','品种消费明细表','品种消费明细表',115,'1','TfrmWareConsumeRpt',NULL,'4',14,'0',0,NULL
                UNION ALL SELECT 120,'LH','LH_0305','时长消费明细表','时长消费明细表',115,'1','TfrmTimeConsumeRpt',NULL,'5',15,'0',0,NULL
                UNION ALL SELECT 121,'LH','LH_0306','金额消费明细表','金额消费明细表',115,'1','TfrmMoneyConsumeRpt',NULL,'6',16,'0',0,NULL
                UNION ALL SELECT 122,'LH','LH_04','消费汇总',NULL,-1,NULL,NULL,NULL,'5',NULL,NULL,0,NULL
                UNION ALL SELECT 123,'LH','LH_0401','人员消费综合表','人员消费综合表',122,'1','TfrmPersonSumRpt',NULL,'1',17,'1',0,NULL
                UNION ALL SELECT 124,'LH','LH_0402','品种消费汇总表(人员)','品种消费汇总表(人员)',122,'1','TfrmPsnWareSumRpt',NULL,'2',18,'0',0,NULL
                UNION ALL SELECT 125,'LH','LH_0403','品种消费汇总表(商品)','品种消费汇总表(商品)',122,'1','TfrmWareSumRpt',NULL,'3',19,'1',0,NULL
                UNION ALL SELECT 126,'LH','LH_0404','时长消费汇总表(人员)','时长消费汇总表(人员)',122,'1','TfrmPsnTimeSumRpt',NULL,'4',20,'0',0,NULL
                UNION ALL SELECT 127,'LH','LH_0405','时长消费汇总表(机器)','时长消费汇总表(机器)',122,'1','TfrmTimeSumRpt',NULL,'5',21,'1',0,NULL
                UNION ALL SELECT 128,'LH','LH_0406','消费汇总表(人员)','消费汇总表(人员)',122,'1','TfrmPsnMoneySumRpt',NULL,'6',22,'0',0,NULL
                UNION ALL SELECT 129,'LH','LH_0407','消费汇总表(机器)','消费汇总表(机器)',122,'1','TfrmMoneySumRpt',NULL,'7',23,'0',0,NULL
                UNION ALL SELECT 130,'LH','LH_0408','商品汇总表(机器)','商品汇总表(机器)',122,'1','TfrmMocWareSumRpt',NULL,'8',24,'0',0,NULL
                UNION ALL SELECT 131,'LH','LH_0409','部门消费综合表','部门消费综合表',122,'1','TfrmDeptSumRpt',NULL,'1',17,'0',0,NULL
							) A
 WHERE A.Menu_ID NOT IN (SELECT Menu_ID FROM dbo.ST_MenuInfo)
GO

--1.1.初始化小金额应用场合用途编码
INSERT INTO dbo.ST_Dictionary(Table_Name,Table_ChsName,Dict_Id,Dict_Value,Is_SysCol)
SELECT * FROM (SELECT 'BM_AREAUSE'[Table_Name],'水控场合用途'[Table_ChsName],'1'[Dict_Id],'洗澡堂(水控)'[Dict_Value],1[Is_SysCol]
                UNION ALL SELECT 'BM_AREAUSE','水控场合用途','2','洗衣房',1
                UNION ALL SELECT 'BM_AREAUSE','水控场合用途','3','开水房',1
                UNION ALL SELECT 'BM_AREAUSE','水控场合用途','4','饮水机',1
                UNION ALL SELECT 'BM_AREAUSE','水控场合用途','5','绿化草地',1
                UNION ALL SELECT 'BM_AREAUSE','水控场合用途','6','工业用水',1
                --UNION ALL SELECT 'BM_AREAUSE','水控场合用途','7','小卖部(商品)',1
                --UNION ALL SELECT 'BM_AREAUSE','水控场合用途','8','机房',1
                --UNION ALL SELECT 'BM_AREAUSE','水控场合用途','9','卡拉OK(各种娱乐场所)',1
                --UNION ALL SELECT 'BM_AREAUSE','水控场合用途','10','美食城',1
              ) A
 WHERE A.Dict_ID NOT IN (SELECT Dict_ID FROM dbo.ST_Dictionary WHERE Table_Name='BM_AREAUSE')
GO

--2.增加系统权限值列表
--2.1增加每个模块的默认权限值
--3.增加角色权限默认管理员组

--4.初始列配置信息

--初始化业务应用数据
IF NOT EXISTS(SELECT Sect_No FROM XF_Section WHERE Sect_No='0001')
   INSERT INTO XF_Section(Sect_No,Sect_Name,Remark)
   VALUES('0001','公司',NULL)
GO

IF NOT EXISTS(SELECT Area_No FROM XF_Area WHERE Area_No='LH01')
  INSERT INTO XF_Area(Area_No,Sect_No,Area_Name,Remark)
  VALUES('LH01','0001','便利店',NULL)
GO

IF NOT EXISTS(SELECT MOC_No FROM ST_MOC WHERE MOC_No='LH0001')
   INSERT INTO ST_MOC(MOC_No,MOC_Name,System_No,Area_No,MOC_Type,IP_Addr,Addr485,COM_No,Consume_Mode,
      Limit_Fund,Limit_Deal,Is_FirstInput,Is_Discount,Is_Correct,Is_UseSubsidy,Is_OrderCtrl,KQ_MocType,Comm_Content,Comm_Status,KQ_UseType)
    VALUES('LH0001','消费机1','LH','LH01','MOC','','002','COM1',3,99999,65535,0,1,1,1,0,2,'空闲',0,0)
GO

--2009.2.25记录整理优化
IF NOT EXISTS(SELECT Param_Code FROM ST_SysParam WHERE Param_Code='Repeat.BeginTime')   
   INSERT INTO ST_SysParam(Param_Code,Param_Name,Param_Value)
   SELECT 'Repeat.BeginTime','Repeat.BeginTime',CONVERT(VARCHAR(50), ISNULL(MAX(Consume_Time),GETDATE()), 121) 
     FROM XF_Consume
GO

IF NOT EXISTS(SELECT Param_Code FROM ST_SysParam WHERE Param_Code='Fake.BeginTime')
   INSERT INTO ST_SysParam(Param_Code,Param_Name,Param_Value)
   SELECT 'Fake.BeginTime','Fake.BeginTime',CONVERT(VARCHAR(50), ISNULL(MAX(Consume_Time),GETDATE()), 121) 
     FROM XF_Consume
GO

--更新子系统创建日期
UPDATE dbo.ST_SubSystem SET DBCreateDate=CONVERT(VARCHAR(10),GETDATE(),121),DBVersion = '3.2.0'
WHERE  System_No = 'LH'
GO
