--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 80[Menu_ID],'SF'[System_No],'SF_05'[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 81,'SF','SF_0502','退出系统','退出系统',80,'5','Exit',NULL,'1',0,'0',0,NULL
                UNION ALL SELECT 82,'SF','SF_0501','终端机状态','终端机状态',80,'1','TfrmMocState',NULL,'0',-1,'1',0,NULL
								UNION ALL SELECT 83,'SF','SF_01','基本资料',NULL,-1,NULL,NULL,NULL,'2',NULL,NULL,0,NULL
								UNION ALL SELECT 84,'SF','SF_0101','区域/食堂设置','区域/食堂设置',83,'2','TfrmAreaSite',NULL,'1',54,'0',0,NULL
								UNION ALL SELECT 136,'SF','SF_0102','菜谱设置','菜谱设置',83,'2','TfrmSFWareInfo',NULL,'2',55,'0',0,NULL
								UNION ALL SELECT 85,'SF','SF_0103','餐别设置','餐别设置',83,'2','TfrmRepast',NULL,'3',56,'0',0,NULL
								UNION ALL SELECT 86,'SF','SF_0104','卡类设置','卡类设置',83,'2','TfrmCardTypeInfo',NULL,'4',57,'0',0,NULL
								UNION ALL SELECT 87,'SF','SF_0105','键值设置','键值设置',83,'2','TfrmKeyInfo',NULL,'5',58,'0',0,NULL
								UNION ALL SELECT 88,'SF','SF_0106','终端机设置','终端机设置',83,'2','TfrmMocSetSF',NULL,'6',59,'0',0,NULL								
								UNION ALL SELECT 89,'SF','SF_02','出纳操作',NULL,-1,NULL,NULL,NULL,'3',NULL,NULL,0,NULL
								UNION ALL SELECT 90,'SF','SF_0201','消费纠错','消费纠错',89,'2','TfrmCorrectConsume',NULL,'1',60,'0',0,NULL
								UNION ALL SELECT 91,'SF','SF_0202','手工补消费','手工补消费',89,'2','TfrmSupplyConsume',NULL,'2',-1,'0',0,NULL
								UNION ALL SELECT 92,'SF','SF_0203','U盘导入消费','U盘导入消费',89,'2','TfrmImportConsume',NULL,'3',-1,'0',0,NULL
								UNION ALL SELECT 93,'SF','SF_03','消费明细',NULL,-1,NULL,NULL,NULL,'4',NULL,NULL,0,NULL
								UNION ALL SELECT 94,'SF','SF_0301','正常消费明细表','正常消费明细表',93,'1','TfrmNormalConsumeRpt',NULL,'1',62,'0',0,NULL
								UNION ALL SELECT 95,'SF','SF_0302','消费纠错明细表','消费纠错明细表',93,'1','TfrmCorrectConsumeRpt',NULL,'2',-1,'0',0,NULL
								UNION ALL SELECT 96,'SF','SF_0303','手工补消费明细表','手工补消费明细表',93,'1','TfrmSupplyConsumeRpt',NULL,'3',-1,'0',0,NULL
								UNION ALL SELECT 97,'SF','SF_04','消费汇总',NULL,-1,NULL,NULL,NULL,'5',NULL,NULL,0,NULL
								UNION ALL SELECT 98,'SF','SF_0401','部门餐别汇总表','部门餐别汇总表',97,'1','TfrmDeptRepastRpt',NULL,'1',-1,'0',0,NULL
                                                                UNION ALL SELECT 400,'SF','SF_0409','卡类餐别汇总表','卡类餐别汇总表',97,'1','TfrmCardTypeRepastRpt',NULL,'1',-1,'0',0,NULL
								UNION ALL SELECT 99,'SF','SF_0402','人员餐别汇总表','人员餐别汇总表',97,'1','TfrmPsnRepastRpt',NULL,'2',-1,'0',0,NULL
								UNION ALL SELECT 100,'SF','SF_0403','餐别日报表','餐别日报表',97,'1','TfrmRepastDayRpt',NULL,'3',64,'1',0,NULL
                                UNION ALL SELECT 192,'SF','SF_0404','人员餐别日报表','人员餐别日报表',97,'1','TfrmPsnDayRpt',NULL,'4',-1,'0',0,NULL    
                                                           
                                UNION ALL SELECT 193,'SF','SF_0405','食堂餐别汇总表','食堂餐别汇总表',97,'1','TfrmHallTotalRep',NULL,'5',-1,'0',0,NULL 
                                UNION ALL SELECT 194,'SF','SF_0406','机台餐别汇总表','机台餐别汇总表',97,'1','TfrmMocHallTotalRep',NULL,'6',-1,'0',0,NULL
                                UNION ALL SELECT 195,'SF','SF_0407','人员机台汇总表','人员机台汇总表',97,'1','TfrmPsnMocRpt',NULL,'7',-1,'0',0,NULL                                                                                            
                                UNION ALL SELECT 196,'SF','SF_0408','品种消费汇总表(商品)','品种消费汇总表(商品)',97,'1','TfrmWareSumRpt',NULL,'8',63,'0',0,NULL


							) A
 WHERE A.Menu_ID NOT IN (SELECT Menu_ID FROM dbo.ST_MenuInfo)
GO

--2.增加系统权限值列表
--2.1增加每个模块的默认权限值

--3.增加角色权限默认管理员组

--4.初始列配置信息
--初始化餐别数据
INSERT INTO dbo.SF_Repast(Repast_No,Repast_Name,Bgn_Time,End_Time,Price)
SELECT * FROM (SELECT '001'[Repast_No],'早餐'[Repast_Name],'00:00'[Bgn_Time],'23:59'[End_Time],1[Price]
                UNION ALL SELECT '002','午餐', '00:00','00:00',1
                UNION ALL SELECT '003','晚餐', '00:00','00:00',1
                UNION ALL SELECT '004','夜宵', '00:00','00:00',1
                UNION ALL SELECT '005','餐别5','00:00','00:00',1
                UNION ALL SELECT '006','餐别6','00:00','00:00',1
                UNION ALL SELECT '007','餐别7','00:00','00:00',1
              ) A
 WHERE A.Repast_No NOT IN (SELECT Repast_No FROM dbo.SF_Repast)
GO

--初始化业务应用数据
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='SF01')
   INSERT INTO XF_Area(Area_No,Sect_No,Area_Name,Remark)
   VALUES('SF01','0001','第一食堂',NULL)
GO

IF NOT EXISTS(SELECT MOC_No FROM ST_MOC WHERE MOC_No='SF0001')
   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('SF0001','售饭机1','SF','SF01','MOC','','001','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 = 'SF'
GO



