--0.門禁系統初始化菜單
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 145[Menu_ID],'MJ'[System_No],'MJ_01'[Menu_No],'系統管理'[Menu_Name],NULL[Menu_Hint],-1[Para_ID],NULL[Call_Mode],
                      NULL[Form_Name],NULL[ShortKey],'1'[Menu_Index],-1[Image_Index],NULL[Separator],0[InToolBar],NULL[Remark]
                UNION ALL SELECT 146,'MJ','MJ_0101','系統參數','系統參數',145,'2','TfrmAcsParam',NULL,'1',42,'1',0,NULL
                UNION ALL SELECT 147,'MJ','MJ_0102','退出系統','退出系統',145,'5','Exit',NULL,'2',0,'0',0,NULL
                UNION ALL SELECT 148,'MJ','MJ_03','門禁管理',NULL,-1,NULL,NULL,NULL,'2',-1,NULL,0,NULL
                UNION ALL SELECT 149,'MJ','MJ_0301','控制器設置','控制器設置',148,'2','TfrmController',NULL,'1',44,'0',0,NULL
                UNION ALL SELECT 150,'MJ','MJ_0302','門屬性設置','門屬性設置',148,'2','TfrmDoor',NULL,'3',45,'1',0,NULL
                UNION ALL SELECT 151,'MJ','MJ_0303','人員設置','人員設置',148,'1','TfrmAcsPerson',NULL,'4',46,'1',0,NULL
	        	UNION ALL SELECT 452,'MJ','MJ_0306','門權限設置','門權限設置',148,'1','TfrmAscDoor',NULL,'7',45,'1',0,NULL
                UNION ALL SELECT 152,'MJ','MJ_0304','超級卡或密碼','超級卡或密碼',148,'2','TfrmCardAndPwd',NULL,'5',47,'0',0,NULL
                UNION ALL SELECT 153,'MJ','MJ_02','時段管理',NULL,-1,NULL,NULL,NULL,'3',-1,NULL,0,NULL
                UNION ALL SELECT 154,'MJ','MJ_0201','門開關時段設置','門開關時段設置',153,'2','TfrmDoorPeriod',NULL,'1',-1,'0',0,NULL
                UNION ALL SELECT 155,'MJ','MJ_0202','門特殊時段設置','門特殊時段設置',153,'2','TfrmDoorSpecial',NULL,'2',-1,'1',0,NULL
                UNION ALL SELECT 156,'MJ','MJ_0203','人進出時段設置','人進出時段設置',153,'2','TfrmPersonPeriod',NULL,'3',-1,'0',0,NULL
                UNION ALL SELECT 157,'MJ','MJ_0204','人特殊時段設置','人特殊時段設置',153,'2','TfrmPersonSpecial',NULL,'4',-1,'1',0,NULL
                UNION ALL SELECT 158,'MJ','MJ_04','控制管理',NULL,-1,NULL,NULL,NULL,'4',-1,NULL,0,NULL
                UNION ALL SELECT 159,'MJ','MJ_0401','控制器聯動設置','控制器聯動設置',158,'2','TfrmLinkage',NULL,'1',-1,'0',0,NULL
                UNION ALL SELECT 160,'MJ','MJ_0402','報警輸出設置','報警輸出設置',158,'2','TfrmAlarmOutput',NULL,'2',-1,'1',0,NULL
                UNION ALL SELECT 161,'MJ','MJ_0403','多門互鎖設置','多門互鎖設置',158,'2','TfrmDoorInterlock',NULL,'3',-1,'0',0,NULL
                UNION ALL SELECT 162,'MJ','MJ_0404','緊急群組設置','緊急群組設置',158,'2','TfrmUrgencyGroup',NULL,'4',-1,'0',0,NULL
                UNION ALL SELECT 163,'MJ','MJ_05','遠程監控',NULL,-1,NULL,NULL,NULL,'5',-1,NULL,0,NULL
                UNION ALL SELECT 164,'MJ','MJ_0501','門禁控制台','門禁控制台',163,'1','TfrmConsole',NULL,'1',48,'1',0,NULL
                UNION ALL SELECT 165,'MJ','MJ_0502','擴展點設置','擴展點設置',148,'2','TfrmDotState',NULL,'2',49,'0',0,NULL
                UNION ALL SELECT 166,'MJ','MJ_0503','電子地圖設計','電子地圖設計',163,'1','TfrmMap',NULL,'2',50,'0',0,NULL
                UNION ALL SELECT 167,'MJ','MJ_0504','地圖實時監控','地圖實時監控',163,'1','TfrmMapWatch',NULL,'3',51,'0',0,NULL
                UNION ALL SELECT 168,'MJ','MJ_06','門禁查詢',NULL,-1,NULL,NULL,NULL,'6',-1,NULL,0,NULL
                UNION ALL SELECT 169,'MJ','MJ_0601','門禁正常刷卡記錄','門禁正常刷卡記錄',168,'1','TfrmNormal',NULL,'1',52,'0',0,NULL
                UNION ALL SELECT 170,'MJ','MJ_0602','門禁異常刷卡記錄','門禁異常刷卡記錄',168,'1','TfrmAbnormal',NULL,'2',-1,'1',0,NULL
                UNION ALL SELECT 171,'MJ','MJ_0603','報警設備事件記錄','報警設備事件記錄',168,'1','TfrmAlarm',NULL,'3',-1,'0',0,NULL
                UNION ALL SELECT 172,'MJ','MJ_07','系統維護',NULL,-1,NULL,NULL,NULL,'7',-1,NULL,0,NULL
                UNION ALL SELECT 173,'MJ','MJ_0701','清理過期數據','清理過期數據',172,'2','TfrmDataClean',NULL,'1',-1,'1',0,NULL
                UNION ALL SELECT 174,'MJ','MJ_0702','擴展功能設置','擴展功能設置',172,'2','TfrmExtend',NULL,'2',53,'0',0,NULL
                UNION ALL SELECT 197,'MJ','MJ_0405','首卡開門設置','首卡開門設置',158,2,'TfrmDoorFirstCardOpen',NULL,5,-1,1,0,NULL
                UNION ALL SELECT 198,'MJ','MJ_0406','多卡開門設置','多卡開門設置',158,2,'TfrmDoorMultiCardOpen',NULL,6,-1,0,0,NULL
                UNION ALL SELECT 199,'MJ','MJ_0407','管理卡設置','管理卡設置',158,2,'TfrmManaCardSetup',NULL,7,-1,0,0,NULL
	              UNION ALL SELECT 450,'MJ','MJ_0408','會議管理','會議管理',158,2,'TfrmMjMeeting',NULL,8,-1,0,0,NULL
                UNION ALL SELECT 200,'MJ','MJ_0205','進出權限方案管理','進去權限方案管理',153,'2','TfrmSolution',NULL,'5',43,'0',0,NULL
                UNION ALL SELECT 451,'MJ','MJ_0305','刷卡添加用戶','刷卡添加用戶',148,2,'TfrmBrushCardPerson',NULL,6,-1,0,0,NULL
                UNION ALL SELECT 650,'MJ','MJ_0409','DVS聯動','DVS聯動',158,1,'TfrmDVSMJScroll',NULL,9,-1,0,0,NULL
							) A
 WHERE A.Menu_ID NOT IN (SELECT Menu_ID FROM dbo.ST_MenuInfo)
GO

--1.初始化功能擴展數據
INSERT INTO dbo.MJ_ExtendFunc(Menu_No,Menu_Name,Is_Menu,Is_Use)
SELECT A.* FROM (SELECT 'Is_APB'[Menu_No],'防尾隨'[Menu_Name],1[Is_Menu],0[Is_Use]
								UNION ALL SELECT 'Is_HiddenBack ','防潛回',1,0
								UNION ALL SELECT 'Is_PwdKeyBoard','密碼鍵盤',1,0
								UNION ALL SELECT 'MJ_0401','控制器聯動設置',0,0
								UNION ALL SELECT 'MJ_0402','報警輸出設置',0,0
								UNION ALL SELECT 'MJ_0403','多門互鎖設置',0,0
								UNION ALL SELECT 'MJ_0404','緊急群組設置',0,0
								UNION ALL SELECT 'Allow_HoldNumber ','允許容納人數',1,0
								UNION ALL SELECT 'Is_ReadCardAttend','讀卡器用于設置考勤',1,0
								UNION ALL SELECT 'MJ_0405' ,'首卡開門設置',0,0
								UNION ALL SELECT 'MJ_0406','多卡開門設置',0,0
								UNION ALL SELECT 'MJ_0407','管理卡設置',0,0
								UNION ALL SELECT 'MJ_0408','會議管理',0,0
                UNION ALL SELECT 'MJ_0409','DVS聯動',0,0
							) A
WHERE A.Menu_No NOT IN(SELECT Menu_No FROM dbo.MJ_ExtendFunc)
GO	

--2.初始化資源參數表數據
DELETE FROM dbo.MJ_ResParam
GO

INSERT INTO dbo.MJ_ResParam(Ctrl_Type,Ctrl_Name,Res_Type,Idx_No,Res_Name,Res_Number,Is_Extend)
  /**/SELECT '1','一控一','0','1','門','1',0
  UNION ALL SELECT '1','一控一','1','1','輸入點','1',1
  UNION ALL SELECT '1','一控一','2','1','輸出點','1',1
  /**/
  UNION ALL SELECT '2','一控二','0','1','門','2',0
  UNION ALL SELECT '2','一控二','1','1','輸入點','2',1
  UNION ALL SELECT '2','一控二','2','1','輸出點','2',1
  /*一控四*/
  UNION ALL SELECT '4','一控四','0','1','門','4',0
  UNION ALL SELECT '4','一控四','1','1','輸入點','4',1
  UNION ALL SELECT '4','一控四','2','1','輸出點','4',1
  /*一控八*/
  UNION ALL SELECT '8','一控八','0','1','門','8',0
  UNION ALL SELECT '8','一控八','1','1','輸入點','8',1
  UNION ALL SELECT '8','一控八','2','1','輸出點','8',1
GO

--3.初始化功能擴展數據
INSERT INTO dbo.MJ_SysParam(Param_Code,Param_Name,Param_Value)
SELECT A.* FROM (SELECT 'PHOTO_DOORIN'[Param_Code],'進門是否顯示照片'[Param_Name],'1'[Param_Value]
								UNION ALL SELECT 'PHOTO_DOOROUT','出門是否顯示照片','1'								
								UNION ALL SELECT 'IS_AUTOCLEAR','是否自動清理過期數據','0'
								UNION ALL SELECT 'NORMAL_DAYS','正常刷卡保留天數','7'
								UNION ALL SELECT 'ABNORM_DAYS','異常刷卡保留天數','15'
								UNION ALL SELECT 'ALARM_DAYS','報警事件保留天數','15'
								UNION ALL SELECT 'CLEAR_DAYS','清理數據保留天數','30'
								UNION ALL SELECT 'CLEAR_DATE','清理過期數據日期','2006-07-15'
								UNION ALL SELECT 'ACSSERVER','門禁通信服務器','127.0.0.1'
								UNION ALL SELECT 'ACSPORT','通訊端口號','4003'
								UNION ALL SELECT 'CARDTOWIGAND26','是否需要將卡號轉換為微耕26格式','0'
								UNION ALL SELECT 'ISUSECARD_SN','是否采用IC卡序列號做門禁卡號','0'
								UNION ALL SELECT 'LAST_READCARD','最后一次門禁讀頭讀到卡號','0'
                UNION ALL SELECT 'DVSPhotoStoreDir','DVS聯動存儲位置',''
                UNION ALL SELECT 'Is_APB','防尾隨','1'
					      UNION ALL SELECT 'Is_HiddenBack','防潛回','1'
					 ) A
WHERE A.Param_Code NOT IN(SELECT Param_Code FROM dbo.MJ_SysParam)
GO

INSERT INTO MJ_EventInfo(Event_Type,Event_Code,Event_Name,Record_Color,Info_Style)
 SELECT A.* FROM
   (SELECT 0 [Event_Type],0[Event_Code],'刷卡開門'[Event_Name],1[Record_Color],'S1'[Info_Style]
     UNION ALL SELECT	0,1,'密碼開門',1,'S2'
     UNION ALL SELECT	0,2,'卡+密碼開門',1,'S1'
     UNION ALL SELECT	0,3,'按鈕開門',2,'S2'
     UNION ALL SELECT	0,4,'非普通模式開門',2,'S1'
     UNION ALL SELECT	0,5,'超級卡開門',1,'S2'
     UNION ALL SELECT	0,6,'遠程控制開門',2,'S2'
     UNION ALL SELECT	0,7,'聯動開門',2,'S2'
     UNION ALL SELECT	0,8,'門常開到點開門',2,'S2'
     UNION ALL SELECT	0,9,'多卡開門',1,'S2'
     UNION ALL SELECT	0,10,'首卡常開',1,'S4'
     UNION ALL SELECT	0,11,'首卡+密碼常開',1,'S4'
     UNION ALL SELECT	0,12,'遠程控制門常開',2,'S2'
     UNION ALL SELECT	0,13,'超級密碼開門',1,'S2'
     UNION ALL SELECT	1,16,'解除報警',0,'S2'
     UNION ALL SELECT	1,17,'強制打開報警',4,'S3'
     UNION ALL SELECT	1,18,'門開超時報警',4,'S3'
     UNION ALL SELECT	1,19,'脅迫報警',4,'S3'
     UNION ALL SELECT	1,20,'非法卡報警',3,'S5'
     UNION ALL SELECT	1,21,'無權限報警',3,'S5'
     UNION ALL SELECT	1,22,'無時段報警',3,'S5'
     UNION ALL SELECT	1,23,'尾隨報警',4,'S3'
     UNION ALL SELECT	1,24,'潛回報警',4,'S3'
     UNION ALL SELECT	1,25,'密碼錯誤',3,'S2'
     UNION ALL SELECT	1,26,'人數不足報警',4,'S3'
     UNION ALL SELECT	1,27,'人數超限報警',4,'S3'
     UNION ALL SELECT	1,28,'不需要刷卡',3,'S2'
     UNION ALL SELECT	1,29,'門互鎖無法開門',3,'S2'

     UNION ALL SELECT	2,32,'關門',2,'S2'
     UNION ALL SELECT	2,33,'門常閉',2,'S2'
     UNION ALL SELECT	2,34,'遠程控制關門',2,'S2'
     UNION ALL SELECT	2,35,'遠程控制門常閉',2,'S2'
     UNION ALL SELECT	2,36,'聯動關門',2,'S2'
     UNION ALL SELECT	3,47,'考勤刷卡',2,'S2'
   
     UNION ALL SELECT	4,64,'輸入點1報警',2,'S3'
     UNION ALL SELECT	4,65,'輸入點2報警',2,'S3'
     UNION ALL SELECT	4,66,'輸入點3報警',2,'S3'
     UNION ALL SELECT	4,67,'輸入點4報警',2,'S3'
     UNION ALL SELECT	4,68,'輸入點5報警',2,'S3'
     UNION ALL SELECT	4,69,'輸入點6報警',2,'S3'
     UNION ALL SELECT	4,70,'輸入點7報警',2,'S3'
     UNION ALL SELECT	4,71,'輸入點8報警',2,'S3'
     UNION ALL SELECT	4,72,'輸出點1報警',2,'S3'
     UNION ALL SELECT	4,73,'輸出點2報警',2,'S3'
     UNION ALL SELECT	4,74,'輸出點3報警',2,'S3'
     UNION ALL SELECT	4,75,'輸出點4報警',2,'S3'
     UNION ALL SELECT	4,76,'輸出點5報警',2,'S3'
     UNION ALL SELECT	4,77,'輸出點6報警',2,'S3'
     UNION ALL SELECT	4,78,'輸出點7報警',2,'S3'
     UNION ALL SELECT	4,79,'輸出點8報警',2,'S3'
   ) A
 WHERE NOT EXISTS(SELECT Event_Code FROM MJ_EventInfo 
                   WHERE MJ_EventInfo.Event_Type=A.Event_Type AND MJ_EventInfo.Event_Code=A.Event_Code)
GO	

IF NOT EXISTS(SELECT DoorTime_No FROM MJ_DoorSwitchTime WHERE DoorTime_No=1)
  INSERT INTO MJ_DoorSwitchTime(DoorTime_No,DoorTime_Name,SpecTime_Info)
    VALUES(1,'任意開關時段',0)
GO

IF NOT EXISTS(SELECT DoorTime_No FROM MJ_DoorSwitchTimeSub WHERE DoorTime_No=1)
  INSERT INTO MJ_DoorSwitchTimeSub(DoorTime_No,Start_Time,End_Time,Door_State)
    VALUES(1,'00:00','23:59',2)
GO

IF NOT EXISTS(SELECT PsnTime_No FROM MJ_PsnInOutTime WHERE PsnTime_No=1)
  INSERT INTO MJ_PsnInOutTime(PsnTime_No,PsnTime_Name,Start_Date,End_Date,Rule_Type,Cycle_Total,SpecTime_Info)
    VALUES(1,'任意進出時段',CONVERT(VARCHAR(10),GETDATE(),121),'2031-12-31',1,1,0)
GO

IF NOT EXISTS(SELECT PsnTime_No FROM MJ_PsnInOutTimeSub WHERE PsnTime_No=1 and TimeSect_ID=1)
  INSERT INTO MJ_PsnInOutTimeSub(PsnTime_No,Group_No,TimeSect_ID,Start_Time,End_Time)
    VALUES(1,'A1',1,'00:00','23:59')
GO

IF NOT EXISTS(SELECT PsnTime_No FROM MJ_PsnInOutTimeSub WHERE PsnTime_No=1 and TimeSect_ID=-1)
  INSERT INTO MJ_PsnInOutTimeSub(PsnTime_No,Group_No,TimeSect_ID,Start_Time,End_Time)
    VALUES(1,'A1',-1,'1','')
GO

--4.增加系統權限值列表
--4.1增加每個模塊的默認權限值

--5.增加角色權限默認管理員組

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