Vous êtes sur la page 1sur 2

USE [VikingServerNew]

GO
/****** Object: StoredProcedure [dbo].[UpdateSecurityAccessCode]
Script Date
: 14-11-2016 22:13:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
Milan Alvarado
-- Create date: 9/14/2015
-- Description: Updates SecurityAccessCode
-- =============================================
-- 10/22/15 MA Added IsDirty Bit
-- 10/26/15 MA Add Access Code specific UserCodeTypeID that can overwrite User's
default selection (Entry Code vs. Access Code)
-- 10/27/15 MA Changed 7Day Config to string
-- 12/14/15 MA Add p in front of 7day Parameters
-- 3/30/16 MA Added LCDName parameter
ALTER PROCEDURE [dbo].[UpdateSecurityAccessCode]
-- Add the parameters for the stored procedure here
@id as int,
@Code as nvarchar(15),
@Expiration as datetime,
@UserCodeTypeID as int,
@PhoneNumber1 as nvarchar(15),
@p7DayStartTime1 as time(0),
@p7DayEndTime1 as time(0),
@p7DayConfig1 as nvarchar(128),
@InputOptionTypeID1 as int,
@PhoneNumber2 as nvarchar(15),
@p7DayStartTime2 as time(0),
@p7DayEndTime2 as time(0),
@p7DayConfig2 as nvarchar(128),
@InputOptionTypeID2 as int,
@PhoneNumber3 as nvarchar(15),
@p7DayStartTime3 as time(0),
@p7DayEndTime3 as time(0),
@p7DayConfig3 as nvarchar(128),
@InputOptionTypeID3 as int,
@LCDName as nvarchar(50),
@IsDirty as bit,
@IsActive as bit
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @ID2 table (ID int)
DECLARE @DeviceID int
DECLARE @UserID int
Declare @TimeZoneConfigID1 int
Declare @TimeZoneConfigID2 int
Declare @TimeZoneConfigID3 int
-- Fetch TimeZone IDs to delete and re-insert
SELECT @TimeZoneConfigID1 = TimeZoneConfigID1, @TimeZoneConfigID2 = Time
ZoneConfigID2, @TimeZoneConfigID3 = TimeZoneConfigID3 FROM SecurityAccessCodes

WHERE id=@id;
DELETE FROM TimeZoneConfigs WHERE TimeZoneConfigs.id IN(@TimeZoneConfigI
D1,@TimeZoneConfigID2,@TimeZoneConfigID3);
exec @TimeZoneConfigID1 = [dbo].[InsertTimeZoneConfig] @p7DayStartTime1,
@p7DayEndTime1, @p7DayConfig1;
exec @TimeZoneConfigID2 = [dbo].[InsertTimeZoneConfig] @p7DayStartTime2,
@p7DayEndTime2, @p7DayConfig2;
exec @TimeZoneConfigID3 = [dbo].[InsertTimeZoneConfig] @p7DayStartTime3,
@p7DayEndTime3, @p7DayConfig3;
--Update SecurityAccessCodes set Code=@Code,
--Expiration=@Expiration,
--UserCodeTypeID=@UserCodeTypeID,
--PhoneNumber1=@PhoneNumber1,
--TimeZoneConfigID1=@TimeZoneConfigID1,
--InputOptionTypeID1=@InputOptionTypeID1,
--PhoneNumber2=@PhoneNumber2,
--TimeZoneConfigID2=@TimeZoneConfigID2,
--InputOptionTypeID2=@InputOptionTypeID2,
--PhoneNumber3=@PhoneNumber3,
--TimeZoneConfigID3=@TimeZoneConfigID3,
--InputOptionTypeID3=@InputOptionTypeID3,
--LCDName=@LCDName,
--IsDirty=@IsDirty,
--IsActive=@IsActive,
--ModifiedDate=GETDATE()
--where id=@id;
select @DeviceID=DeviceID,@UserID=UserID from SecurityAccessCodes where
id=@id;
Update SecurityAccessCodes set
IsActive=@IsActive,
IsDeleted =1,
ModifiedDate=GETDATE()
where id=@id;
Insert INTO SecurityAccessCodes (DeviceID,UserID,Code,Expiration,UserCod
eTypeID,PhoneNumber1,TimeZoneConfigID1,InputOptionTypeID1,PhoneNumber2,TimeZoneC
onfigID2,InputOptionTypeID2,PhoneNumber3,TimeZoneConfigID3,InputOptionTypeID3,LC
DName,IsActive,CreateDate)
Output Inserted.id into @ID2
Values(@DeviceID,@UserID,@Code,@Expiration,@UserCodeTypeID,@PhoneNumber1
,@TimeZoneConfigID1,@InputOptionTypeID1,@PhoneNumber2,@TimeZoneConfigID2,@InputO
ptionTypeID2,@PhoneNumber3,@TimeZoneConfigID3,@InputOptionTypeID3,@LCDName,1,GET
DATE());
SELECT @ID = id FROM @ID2 as id;
return @ID;
--return @@ROWCOUNT;
END

Vous aimerez peut-être aussi