Advertisement
hecrus

Form SaveItem

Oct 24th, 2020
2,432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 4.06 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[fm_clientQuestionaries_saveItem]
  2.    @username nvarchar(256),
  3.    @itemID int,
  4.    @parameters ExtendedDictionaryParameter READONLY
  5. AS
  6. BEGIN
  7.     declare
  8.         @fieldchannel nvarchar(max) = '',
  9.         @fieldlink nvarchar(max) = '',
  10.         @fieldnegative nvarchar(max) = '',
  11.         @fieldpositive nvarchar(max) = '',
  12.         @fieldmostinteresting nvarchar(max) = '',
  13.         @fieldnotenough nvarchar(max) = '',
  14.         @fieldmoreinformation nvarchar(max) = '',
  15.         @fieldalternative nvarchar(max) = '',
  16.         @fieldpo nvarchar(max) = '',
  17.         @fieldlike nvarchar(max) = '',
  18.         @fieldemail nvarchar(max) = '',
  19.         @fieldphone nvarchar(max) = '',
  20.         @fieldaccess bit = 0
  21.        
  22.         declare @langID int
  23.     select @langID = try_cast(Value as int) from @parameters where [Key] = 'langID'
  24.  
  25.  
  26.     select @fieldchannel = value from @parameters where [key]='channel'
  27.     select @fieldlink  = value from @parameters where [key]='link'
  28.     select @fieldnegative = value from   @parameters where [key]='negative'
  29.     select @fieldpositive = value from   @parameters where [key]='positive'
  30.     select @fieldmostinteresting = value   from @parameters where [key]='mostinteresting'
  31.     select @fieldnotenough = value  from @parameters where [key]='notenough'
  32.     select @fieldmoreinformation = value   from @parameters where [key]='moreinformation'
  33.     select @fieldalternative = value  from @parameters where [key]='alternative'
  34.     select @fieldpo = value  from @parameters where [key]='po'
  35.     select @fieldlike = value  from @parameters where [key]='like'
  36.     select @fieldemail = value from @parameters where [key]='email'
  37.     select @fieldphone = value  from @parameters where [key]='phone'
  38.     select @fieldaccess = try_cast(value as bit) from @parameters where [key]='access'
  39.  
  40.     declare @percent decimal(18,2) = 0
  41.     if len(@fieldchannel) > 5 set @percent = @percent + 2
  42.     if len(@fieldlink) > 5 set @percent = @percent + 2
  43.     if len(@fieldnegative) > 5 set @percent = @percent + 2
  44.     if len(@fieldpositive) > 5 set @percent = @percent + 2
  45.     if len(@fieldmostinteresting) > 0 set @percent = @percent + 2
  46.     if len(@fieldnotenough) > 5 set @percent = @percent + 2
  47.     if len(@fieldmoreinformation) > 5 set @percent = @percent + 2
  48.     if len(@fieldalternative) > 5 set @percent = @percent + 2
  49.     if len(@fieldpo) > 5 set @percent = @percent + 2
  50.     if len(@fieldlike) > 0 set @percent = @percent + 2
  51.    
  52.     declare @userGuid uniqueidentifier
  53.     select @userGuid = try_convert(uniqueidentifier, Value) from @parameters where [key] = 'falconGuid'
  54.    
  55.     declare @percentText nvarchar(16), @sumText nvarchar(16)
  56.     select @percentText = cast(@percent as nvarchar)
  57.     select @sumText = cast(cast(60000 * @percent/100 as decimal(18,0)) as nvarchar)
  58.    
  59.     if (select count(*) from falcon_clientQuestionaries where userGuid = @userGuid and question = 'percent') > 0
  60.         update falcon_clientQuestionaries set answer = @percentText where userGuid = @userGuid and question = 'percent'
  61.     else
  62.         insert into falcon_clientQuestionaries (userGuid, question, answer) values (@userGuid, 'percent', @percentText)
  63.    
  64.     if (select count(*) from falcon_clientQuestionaries where userGuid = @userGuid and question = 'sum') > 0
  65.         update falcon_clientQuestionaries set answer = @sumText where userGuid = @userGuid and question = 'sum'
  66.     else
  67.         insert into falcon_clientQuestionaries (userGuid, question, answer) values (@userGuid, 'sum', @sumText)
  68.  
  69.    
  70.     declare @text nvarchar(max)
  71.     select @text =  iif(@langID=1, 'A discount is attached to your phone number. ' + @PercentText + '% discount for the purchase of a basic boxed solution is attached to your phone number.
  72. For additional questions, please contact via the chat on the website - at the bottom right. ', 'К номеру вашего телефона привязана скидка ' + @percentText + '% на покупку базового коробочного решения.
  73.                     По дополнительным вопросам обращайтесь пожалуйста через чат на сайте - справа внизу.' )  
  74.    
  75.     select 1 Result, @text Msg, 0 HideFormAfterSubmit
  76. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement