Add tailor-made function to system function and create menu

Source: Internet
Author: User

If exists (select * From tempdb. DBO. sysobjects where id = object_id (N 'tempdb .. # table') and type = 'U ')
Drop table # Table

Create Table # Table
(
[Recnum] [decimal] (28, 0) Identity (1, 1) not null,
Modulecode nvarchar (30) Collate SQL _latin1_general_cp1_ci_as null,
Functioncode nvarchar (30) Collate SQL _latin1_general_cp1_ci_as null,
Funcdescription nvarchar (30) Collate SQL _latin1_general_cp1_ci_as null,
Process_code nvarchar (30) Collate SQL _latin1_general_cp1_ci_as null,
Menu_type nvarchar (30) Collate SQL _latin1_general_cp1_ci_as null,
Menu_code nvarchar (30) Collate SQL _latin1_general_cp1_ci_as null
)

Insert into # TABLE (modulecode, functioncode, funcdescription, process_code, menu_type, menu_code)
Select 'prsf ', 'prsfrt', 'matrial reservation transfer', 'm6 _ ent', 'entry ', '123'
Union all
Select 'prsf ', 'prsfrc', 'routing process completion', 'm6 _ ent', 'entry ', '123'
Union all
Select 'prpe', 'prpemj', 'mass ecn', 'm4 _ ent', 'entry ', '60'
Union all
Select 'prpm', 'prmmj', 'mass ecn', 'm4 _ ent', 'entry ', '70'
Union all
Select 'samf', 'samfrp ', 'routing process', 'mast01', 'mast', '123'
Union all
Select 'samf', 'samfrp ', 'bom routing process settings', 'mast01', 'mast', '123'
Union all
Select 'sample', 'samples', 'collection Master', 'mast01', 'mast ', '123'
Union all
Select 'sample', 'samplessy', 'style Master', 'mast01', 'mast ', '123'
Union all
Select 'sample', 'sample', 'color Master', 'mast01', 'mast ', '123'
Union all
Select 'prpm ', 'prmju', 'job BOM Update', 'm4 _ ent', 'entry ', '80'

Declare @ seriescode nvarchar (30)
Declare @ modulecode nvarchar (30)
Declare @ functioncode nvarchar (30)
Declare @ functiondesc nvarchar (30)
Declare @ recnum int

Declare @ process_code nvarchar (30)
Declare @ menu_type nvarchar (30)
Declare @ menu_code nvarchar (30)

Declare @ lastlineno int

Set @ seriescode =''

declare function_cursor cursor for select recnum from # Table
open function_cursor
fetch next from function_cursor into @ recnum
while @ fetch_status = 0
begin
select @ modulecode = modulecode, @ functioncode = functioncode, @ functiondesc = funcdescription, @ process_code = process_code,
@ menu_type = menu_type, @ menu_code = menu_code from # table where recnum = @ recnum
-- check for function
if not exists (select * from [adfunc] Where module_code = @ modulecode and function_code = @ functioncode)
begin
Update [admodu] Set [last_line_no] = [last_line_no] + 1
where [module_code] = @ modulecode

Select @ lastlineno = last_line_no from admodu where module_code = @ modulecode

If @ lastlineno is not null
Begin
Insert [adfunc]
([Module_code], [function_no], [function_code], [description],
[Suincluded], [series_option], [series_code],
[Created_date], [created_by], [revised_date], [revised_by],
[Owner_branch], [source_branch], [icon])
Values
(@ Modulecode, @ lastlineno, @ functioncode, @ functiondesc, n'n', n'y', @ seriescode,
Getdate (), 'mis ', getdate (), 'mis', n'', n'', '16 ')

-- Coding for empower
-- If '% sys %' = 'emp' or '% sys %' = 'empt' begin
Insert [adautd]
([User_group], [module_code], [function_no], [function_code], [description],
[Suincluded], [allow_read], [allow_create], [allow_update], [allow_delete], [allow_print],
[Allow_post], [allow_all_tran])
Values
('Sysadm ', @ modulecode, @ lastlineno, @ functioncode, @ functiondesc,
'N', 'y ',
'Y', 'y ')

Insert [admnud]
([User_group], [process_code], [function_code], [description], [menu_type], [menu_code],
[Response_type], [suincluded])
Values
('Sysadm ', @ process_code, @ functioncode, @ functiondesc, @ menu_type, @ menu_code,
'Stdfunc', 'n ')
-- End
-- Coding for EPN
-- Else if '% sys %' = 'epn' begin
-- Insert [adautd]
-- ([User_group], [module_code], [function_no], [function_code], [description],
-- [Suincluded], [allow_read], [allow_create], [allow_update], [allow_delete], [allow_print],
-- [Allow_post], [allow_all_tran])
-- Values
-- ('Epn', @ modulecode, @ lastlineno, @ functioncode, @ functiondesc,
-- 'N', 'y ',
-- 'Y', 'y ')

-- Insert [admnud]
-- ([User_group], [process_code], [function_code], [description], [menu_type], [menu_code],
-- [Response_type], [susponded])
-- Values
-- ('Epn', @ process_code, @ functioncode, @ functiondesc, @ menu_type, @ menu_code,
-- 'Stdfunc', 'n ')
-- End
End
End


Fetch next from function_cursor into @ recnum

End
Close function_cursor;
Deallocate function_cursor;

Drop table # Table

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.