/**更改子系统的名称**/
Update ST_SubSystem Set System_Name=
  Case System_No 
   when 'ST' then '卡务中心'
   when 'KQ' then '考勤管理'
   when 'SF' then '食堂管理'
   when 'KQ' then '考勤管理'
   when 'MJ' then '门禁管理'
   when 'DC' then '订餐管理'
   when 'SK' then '水控管理'
   else System_Name
  End
GO

DELETE FROM ST_Subsystem WHERE CHARINDEX(System_No,'ST,KQ,MJ,SF,DC,SK')<=0
GO

--1 更改安装系统为MJ_JJ系统 
if not Exists(Select * from st_sysparam where Param_code='SystemType')
  insert into st_sysparam(Param_Code,Param_Name,Param_Value) 
    Values('SystemType','SystemType','12')
else
  Update st_sysparam set Param_Value='12' where Param_code='SystemType'
GO

--2.在用户自定义表ST_SelfMenu插入门禁精简版的Menu_ID
INSERT INTO ST_SelfMenu(User_NO,Menu_ID)
SELECT * FROM ( SELECT 'Admin'[User_NO],1[Menu_ID] 
                  UNION ALL SELECT 'Admin',2
                  UNION ALL SELECT 'Admin',3
                  UNION ALL SELECT 'Admin',4
                  UNION ALL SELECT 'Admin',5
                  UNION ALL SELECT 'Admin',6
                  UNION ALL SELECT 'Admin',7
                  UNION ALL SELECT 'Admin',8
--                  UNION ALL SELECT 'Admin',9
--                  UNION ALL SELECT 'Admin',10
                  UNION ALL SELECT 'Admin',11
                  UNION ALL SELECT 'Admin',12
                  UNION ALL SELECT 'Admin',13
                  UNION ALL SELECT 'Admin',14
--                  UNION ALL SELECT 'Admin',15
                  UNION ALL SELECT 'Admin',16
                  UNION ALL SELECT 'Admin',17
                  UNION ALL SELECT 'Admin',18
                  UNION ALL SELECT 'Admin',19
--                  UNION ALL SELECT 'Admin',20
--                  UNION ALL SELECT 'Admin',21
--                  UNION ALL SELECT 'Admin',22
--                  UNION ALL SELECT 'Admin',23
                  UNION ALL SELECT 'Admin',24
--                  UNION ALL SELECT 'Admin',25
--                  UNION ALL SELECT 'Admin',26
--                  UNION ALL SELECT 'Admin',27
--                  UNION ALL SELECT 'Admin',28
--                  UNION ALL SELECT 'Admin',29
                  UNION ALL SELECT 'Admin',30
                  UNION ALL SELECT 'Admin',31
                  UNION ALL SELECT 'Admin',32
                  UNION ALL SELECT 'Admin',33
                  UNION ALL SELECT 'Admin',34
                  UNION ALL SELECT 'Admin',35
                  UNION ALL SELECT 'Admin',36
                  UNION ALL SELECT 'Admin',37
                  UNION ALL SELECT 'Admin',38
--                  UNION ALL SELECT 'Admin',39
--                  UNION ALL SELECT 'Admin',40
--                  UNION ALL SELECT 'Admin',41
--                  UNION ALL SELECT 'Admin',42
                  UNION ALL SELECT 'Admin',43
                  UNION ALL SELECT 'Admin',44
--                  UNION ALL SELECT 'Admin',45
--                  UNION ALL SELECT 'Admin',46
                  UNION ALL SELECT 'Admin',47
--                  UNION ALL SELECT 'Admin',48
--                  UNION ALL SELECT 'Admin',133
                  UNION ALL SELECT 'Admin',191
--以下是门禁子系统
                  UNION ALL SELECT 'Admin',145
                  UNION ALL SELECT 'Admin',146
--                  UNION ALL SELECT 'Admin',147
                  UNION ALL SELECT 'Admin',148
                  UNION ALL SELECT 'Admin',149
                  UNION ALL SELECT 'Admin',150
                  UNION ALL SELECT 'Admin',151
                  UNION ALL SELECT 'Admin',152
                  UNION ALL SELECT 'Admin',153
                  UNION ALL SELECT 'Admin',154
                  UNION ALL SELECT 'Admin',155
                  UNION ALL SELECT 'Admin',156
                  UNION ALL SELECT 'Admin',157
                  UNION ALL SELECT 'Admin',158
                  UNION ALL SELECT 'Admin',159
                  UNION ALL SELECT 'Admin',160
                  UNION ALL SELECT 'Admin',161
                  UNION ALL SELECT 'Admin',162
                  UNION ALL SELECT 'Admin',163
                  UNION ALL SELECT 'Admin',164
                  UNION ALL SELECT 'Admin',165
                  UNION ALL SELECT 'Admin',166
                  UNION ALL SELECT 'Admin',167
                  UNION ALL SELECT 'Admin',168
                  UNION ALL SELECT 'Admin',169
                  UNION ALL SELECT 'Admin',170
                  UNION ALL SELECT 'Admin',171
                  UNION ALL SELECT 'Admin',172
                  UNION ALL SELECT 'Admin',173
                  UNION ALL SELECT 'Admin',174
                  UNION ALL SELECT 'Admin',197
                  UNION ALL SELECT 'Admin',198
                  UNION ALL SELECT 'Admin',199
                  UNION ALL SELECT 'Admin',200
                  UNION ALL SELECT 'Admin',450
                  UNION ALL SELECT 'Admin',451
                  UNION ALL SELECT 'Admin',452
                  UNION ALL SELECT 'Admin',650

              )A
 WHERE A.User_NO='Admin' AND A.Menu_ID NOT IN (SELECT Menu_ID FROM dbo.ST_SelfMenu)
GO

--3、更新用户当前使用子系统标致
UPDATE ST_UserInfo SET Current_Menu='SD'