SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Altering [dbo].[PE_Admin]'
GO
ALTER TABLE [dbo].[PE_Admin] ADD
[LastLoginErrorTime] [datetime] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_Users]'
GO
ALTER TABLE [dbo].[PE_Users] ADD
[LastLoginErrorTime] [datetime] NULL,
[LoginErrorTimes] [int] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_UserManage_Users_Update]'
GO
ALTER PROCEDURE [dbo].[PR_UserManage_Users_Update]
    (
      @UserID INT ,
      @GroupID INT ,
      @CompanyID INT ,
      @ClientID INT ,
      @UserType INT ,
      @UserName NVARCHAR(100) ,
      @UserPassword NVARCHAR(32) ,
      @LastPassword NVARCHAR(32) ,
      @Question NVARCHAR(50) ,
      @Answer NVARCHAR(50) ,
      @Email NVARCHAR(100) ,
      @Sex INT ,
      @RegTime DATETIME ,
      @JoinTime DATETIME ,
      @LoginTimes INT ,
      @LastLoginTime DATETIME ,
      @LastPresentTime DATETIME ,
      @LastLoginIP NVARCHAR(50) ,
      @LastPasswordChangedTime DATETIME ,
      @LastLockoutTime DATETIME ,
      @FailedPasswordAttemptCount INT ,
      @FirstFailedPasswordAttempTime DATETIME ,
      @FailedPasswordAnswerAttempCount INT ,
      @FirstFailedPasswordAnswerAttempTime DATETIME ,
      @Status INT ,
      @CheckNum CHAR(10) ,
      @EnableResetPassword BIT ,
      @UserCultureName NVARCHAR(10) ,
      @UserFace NVARCHAR(255) ,
      @FaceWidth INT ,
      @FaceHeight INT ,
      @Sign NTEXT ,
      @PrivacySetting INT ,
      @Balance MONEY ,
      @UserPoint INT ,
      @UserExp INT ,
      @ConsumeMoney INT ,
      @ConsumePoint INT ,
      @ConsumeExp INT ,
      @PostItems INT ,
      @PassedItems INT ,
      @RejectItems INT ,
      @DelItems INT ,
      @EndTime DATETIME ,
      @IsInheritGroupRole BIT ,
      @TrueName NVARCHAR(255) ,
      @PayPassword NVARCHAR(32) ,
      @IsShowUpgradeTipsFalse BIT ,
      @LastAddPointTime DATETIME ,
      @GetPasswordSid NVARCHAR(32) ,
      @GetPasswordTime DATETIME ,
      @HonorType INT ,
      @LastLoginErrorTime DATETIME ,
	  @LoginErrorTimes INT
    )
AS 
    UPDATE  [PE_Users]
    SET     [UserID] = @UserID ,
            [GroupID] = @GroupID ,
            [CompanyID] = @CompanyID ,
            [ClientID] = @ClientID ,
            [UserType] = @UserType ,
            [UserName] = @UserName ,
            [UserPassword] = @UserPassword ,
            [LastPassword] = @LastPassword ,
            [Question] = @Question ,
            [Answer] = @Answer ,
            [Email] = @Email ,
            [Sex] = @Sex ,
            [RegTime] = @RegTime ,
            [JoinTime] = @JoinTime ,
            [LoginTimes] = @LoginTimes ,
            [LastLoginTime] = @LastLoginTime ,
            [LastPresentTime] = @LastPresentTime ,
            [LastLoginIP] = @LastLoginIP ,
            [LastPasswordChangedTime] = @LastPasswordChangedTime ,
            [LastLockoutTime] = @LastLockoutTime ,
            [FailedPasswordAttemptCount] = @FailedPasswordAttemptCount ,
            [FirstFailedPasswordAttempTime] = @FirstFailedPasswordAttempTime ,
            [FailedPasswordAnswerAttempCount] = @FailedPasswordAnswerAttempCount ,
            [FirstFailedPasswordAnswerAttempTime] = @FirstFailedPasswordAnswerAttempTime ,
            [Status] = @Status ,
            [CheckNum] = @CheckNum ,
            [EnableResetPassword] = @EnableResetPassword ,
            [UserCultureName] = @UserCultureName ,
            [UserFace] = @UserFace ,
            [FaceWidth] = @FaceWidth ,
            [FaceHeight] = @FaceHeight ,
            [Sign] = @Sign ,
            [PrivacySetting] = @PrivacySetting ,
            [Balance] = @Balance ,
            [UserPoint] = @UserPoint ,
            [UserExp] = @UserExp ,
            [ConsumeMoney] = @ConsumeMoney ,
            [ConsumePoint] = @ConsumePoint ,
            [ConsumeExp] = @ConsumeExp ,
            [PostItems] = @PostItems ,
            [PassedItems] = @PassedItems ,
            [RejectItems] = @RejectItems ,
            [DelItems] = @DelItems ,
            [EndTime] = @EndTime ,
            [IsInheritGroupRole] = @IsInheritGroupRole ,
            [TrueName] = @TrueName ,
            [PayPassword] = @PayPassword ,
            [IsShowUpgradeTipsFalse] = @IsShowUpgradeTipsFalse ,
            [LastAddPointTime] = @LastAddPointTime ,
            [GetPasswordSid] = @GetPasswordSid ,
            [GetPasswordTime] = @GetPasswordTime ,
            [HonorType] = @HonorType,
            [LastLoginErrorTime] = @LastLoginErrorTime ,
            [LoginErrorTimes] = @LoginErrorTimes
    WHERE   [UserID] = @UserID
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_UserManage_Users_Add]'
GO
ALTER PROCEDURE [dbo].[PR_UserManage_Users_Add]
    (
      @UserID INT ,
      @GroupID INT ,
      @CompanyID INT ,
      @ClientID INT ,
      @UserType INT ,
      @UserName NVARCHAR(100) ,
      @UserPassword NVARCHAR(32) ,
      @LastPassword NVARCHAR(32) ,
      @Question NVARCHAR(50) ,
      @Answer NVARCHAR(50) ,
      @Email NVARCHAR(100) ,
      @Sex INT ,
      @RegTime DATETIME ,
      @JoinTime DATETIME ,
      @LoginTimes INT ,
      @LastLoginTime DATETIME ,
      @LastPresentTime DATETIME ,
      @LastLoginIP NVARCHAR(255) ,
      @LastPasswordChangedTime DATETIME ,
      @LastLockoutTime DATETIME ,
      @FailedPasswordAttemptCount INT ,
      @FirstFailedPasswordAttempTime DATETIME ,
      @FailedPasswordAnswerAttempCount INT ,
      @FirstFailedPasswordAnswerAttempTime DATETIME ,
      @Status INT ,
      @CheckNum CHAR(10) ,
      @EnableResetPassword BIT ,
      @UserCultureName NVARCHAR(10) ,
      @UserFace NVARCHAR(255) ,
      @FaceWidth INT ,
      @FaceHeight INT ,
      @Sign NTEXT ,
      @PrivacySetting INT ,
      @Balance MONEY ,
      @UserPoint INT ,
      @UserExp INT ,
      @ConsumeMoney INT ,
      @ConsumePoint INT ,
      @ConsumeExp INT ,
      @PostItems INT ,
      @PassedItems INT ,
      @RejectItems INT ,
      @DelItems INT ,
      @EndTime DATETIME ,
      @IsInheritGroupRole BIT ,
      @UserFriendGroup NVARCHAR(255) ,
      @TrueName NVARCHAR(255) ,
      @PayPassword NVARCHAR(32) ,
      @IsShowUpgradeTipsFalse BIT ,
      @LastAddPointTime DATETIME ,
      @GetPasswordSid NVARCHAR(32) ,
      @GetPasswordTime DATETIME ,
      @AlipayUserID NVARCHAR(16) ,
      @HonorType INT ,
      @LastLoginErrorTime DATETIME ,
	  @LoginErrorTimes INT
    )
AS 
    INSERT  INTO [PE_Users]
            ( [UserID] ,
              [GroupID] ,
              [CompanyID] ,
              [ClientID] ,
              [UserType] ,
              [UserName] ,
              [UserPassword] ,
              [LastPassword] ,
              [Question] ,
              [Answer] ,
              [Email] ,
              [Sex] ,
              [RegTime] ,
              [JoinTime] ,
              [LoginTimes] ,
              [LastLoginTime] ,
              [LastPresentTime] ,
              [LastLoginIP] ,
              [LastPasswordChangedTime] ,
              [LastLockoutTime] ,
              [FailedPasswordAttemptCount] ,
              [FirstFailedPasswordAttempTime] ,
              [FailedPasswordAnswerAttempCount] ,
              [FirstFailedPasswordAnswerAttempTime] ,
              [Status] ,
              [CheckNum] ,
              [EnableResetPassword] ,
              [UserCultureName] ,
              [UserFace] ,
              [FaceWidth] ,
              [FaceHeight] ,
              [Sign] ,
              [PrivacySetting] ,
              [Balance] ,
              [UserPoint] ,
              [UserExp] ,
              [ConsumeMoney] ,
              [ConsumePoint] ,
              [ConsumeExp] ,
              [PostItems] ,
              [PassedItems] ,
              [RejectItems] ,
              [DelItems] ,
              [EndTime] ,
              [IsInheritGroupRole] ,
              [UserFriendGroup] ,
              [TrueName] ,
              [PayPassword] ,
              [IsShowUpgradeTipsFalse] ,
              [LastAddPointTime] ,
              [GetPasswordSid] ,
              [GetPasswordTime] ,
              [Alipay_UserID] ,
              [HonorType],
			  [LastLoginErrorTime],
			  [LoginErrorTimes]
		)
    VALUES  ( @UserID ,
              @GroupID ,
              @CompanyID ,
              @ClientID ,
              @UserType ,
              @UserName ,
              @UserPassword ,
              @LastPassword ,
              @Question ,
              @Answer ,
              @Email ,
              @Sex ,
              @RegTime ,
              @JoinTime ,
              @LoginTimes ,
              @LastLoginTime ,
              @LastPresentTime ,
              @LastLoginIP ,
              @LastPasswordChangedTime ,
              @LastLockoutTime ,
              @FailedPasswordAttemptCount ,
              @FirstFailedPasswordAttempTime ,
              @FailedPasswordAnswerAttempCount ,
              @FirstFailedPasswordAnswerAttempTime ,
              @Status ,
              @CheckNum ,
              @EnableResetPassword ,
              @UserCultureName ,
              @UserFace ,
              @FaceWidth ,
              @FaceHeight ,
              @Sign ,
              @PrivacySetting ,
              @Balance ,
              @UserPoint ,
              @UserExp ,
              @ConsumeMoney ,
              @ConsumePoint ,
              @ConsumeExp ,
              @PostItems ,
              @PassedItems ,
              @RejectItems ,
              @DelItems ,
              @EndTime ,
              @IsInheritGroupRole ,
              @UserFriendGroup ,
              @TrueName ,
              @PayPassword ,
              @IsShowUpgradeTipsFalse ,
              @LastAddPointTime ,
              @GetPasswordSid ,
              @GetPasswordTime ,
              @AlipayUserID ,
              @HonorType,
			  @LastLoginErrorTime,
			  @LoginErrorTimes
	      )
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_CommonModel_DefaultPicUrl] on [dbo].[PE_CommonModel]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_CommonModel_DefaultPicUrl] ON [dbo].[PE_CommonModel] ([DefaultPicUrl] DESC)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_CommonModel_ModelID] on [dbo].[PE_CommonModel]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_CommonModel_ModelID] ON [dbo].[PE_CommonModel] ([ModelID] DESC)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_CommonModel_NodeID] on [dbo].[PE_CommonModel]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_CommonModel_NodeID] ON [dbo].[PE_CommonModel] ([NodeID] DESC)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_CommonModel_Status] on [dbo].[PE_CommonModel]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_CommonModel_Status] ON [dbo].[PE_CommonModel] ([Status] DESC)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_Nodes_NodeType] on [dbo].[PE_Nodes]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_Nodes_NodeType] ON [dbo].[PE_Nodes] ([NodeType])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_Nodes_PurviewType] on [dbo].[PE_Nodes]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_Nodes_PurviewType] ON [dbo].[PE_Nodes] ([PurviewType])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_Nodes_ShowOnList_Index] on [dbo].[PE_Nodes]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_Nodes_ShowOnList_Index] ON [dbo].[PE_Nodes] ([ShowOnList_Index])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_Nodes_ShowOnList_Parent] on [dbo].[PE_Nodes]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_Nodes_ShowOnList_Parent] ON [dbo].[PE_Nodes] ([ShowOnList_Parent])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO
