Advertisement
hecrus

Humans Getitems

Oct 10th, 2020
1,605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.20 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[crud_humans_getItems]
  2.     @filters CRUDFilterParameter READONLY,  
  3.     @sort sql_variant,
  4.     @direction nvarchar(8),
  5.     @page int,
  6.     @pageSize int,
  7.     @username nvarchar(32)
  8. AS
  9. BEGIN
  10.     -- основная процедура настройки таблицы
  11.     declare @result TABLE(
  12.         id nvarchar(max),
  13.         phone nvarchar(max),
  14.         fio nvarchar(max),
  15.         freelancer nvarchar(max),
  16.         statusID nvarchar(max)
  17.     )
  18.     -- itemID - это отдел
  19.     declare @filterItemID int
  20.     select @filterItemID = try_cast(Value as int) from @filters where [Key] = 'itemID'
  21.    
  22.      
  23.     insert into @result
  24.     select
  25.         id id,
  26.         isnull(phone, '<i>Нет телефона</i>') phone,
  27.         isnull(fio, '') fio,
  28.         iif(freelancer=1, 1, 0) freelancer,
  29.         isnull((select name from hr_statuses where id = statusID), '') statusID
  30.     from hr_humans
  31.     where (@filterItemID is null or  @filterItemID=depID)  -- если не задан itemID - то берем всех
  32.    
  33.     -- 1 SELECT - сами данные    
  34.     select * from @result
  35.     order by  
  36.         case when @sort = 'fio' and @direction = 'down' then fio end desc,
  37.         case when @sort = 'fio' and @direction = 'up' then fio end asc,
  38.         case when @sort = 'statusID' and @direction = 'down' then statusID end desc,
  39.         case when @sort = 'statusID' and @direction = 'up' then statusID end asc
  40.     OFFSET @PageSize * (@Page - 1) ROWS
  41.     FETCH NEXT @PageSize ROWS ONLY;
  42.    
  43.     -- 2 SELECT - кол-во в таблице
  44.     select count(*) from @result   
  45.  
  46.     -- 3 SELECT Дополнительные настройки таблицы
  47.     /*Select  '' Title,
  48.         '' ToolbarAdditional,
  49.         '' GroupOperationsToolbar,
  50.         '' EmptyText,
  51.         '' FastCreateLinkText, '' FastCreateDialogHeader, '' FastCreateDialogPlaceholder,
  52.         0 FastCreateSearch, 0 FastCreateTextarea,
  53.          0 HideTitleCount,
  54.          0 DisableCellTitle,
  55.          '10px' FontSize,
  56.          '{filterCode}' FilterMakeup,
  57.          1 InstantFilter,
  58.            */
  59.         --'gantt' ViewType,
  60.         -- GanttScale, GanttNavigate, GanttItemForm, GanttItemFormTitle
  61.         -- KanbanItemForm, KanbanItemFormTitle
  62.  
  63.  
  64.     -- 4 SELECT Данные для подвала страницы или данные для Ганта/Канбана (если установлен ViewType в 3 SELECT)
  65.  
  66. END
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement