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_Client]'
GO
ALTER TABLE [dbo].[PE_Client] ALTER COLUMN [IsBusiness] [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_Crm_Client_Update]'
GO
ALTER PROCEDURE [dbo].[PR_Crm_Client_Update]
    (
      @ClientID INT ,
      @ParentID INT ,
      @ClientNum NVARCHAR(20) ,
      @ClientType INT ,
      @ClientName NVARCHAR(100) ,
      @ShortedForm NVARCHAR(20) ,
      @Area INT ,
      @ClientField INT ,
      @ValueLevel INT ,
      @CreditLevel INT ,
      @Importance INT ,
      @ConnectionLevel INT ,
      @GroupID INT ,
      @SourceType INT ,
      @PhaseType INT ,
      @Remark NTEXT ,
      @UpdateTime DATETIME ,
      @Owner NVARCHAR(50) ,
      @IsBusiness INT,
	  @UpdateOwnerTime DATETIME
    )
AS 
    UPDATE  [PE_Client]
    SET     ParentID = @ParentID ,
            ClientNum = @ClientNum ,
            ClientType = @ClientType ,
            ClientName = @ClientName ,
            ShortedForm = @ShortedForm ,
            Area = @Area ,
            ClientField = @ClientField ,
            ValueLevel = @ValueLevel ,
            CreditLevel = @CreditLevel ,
            Importance = @Importance ,
            ConnectionLevel = @ConnectionLevel ,
            GroupID = @GroupID ,
            SourceType = @SourceType ,
            PhaseType = @PhaseType ,
            Remark = @Remark ,
            UpdateTime = @UpdateTime ,
            Owner = @Owner ,
            IsBusiness = @IsBusiness,
			UpdateOwnerTime = @UpdateOwnerTime
    WHERE   ClientID = @ClientID
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_Crm_Client_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Crm_Client_Add]
    (
      @ClientID INT ,
      @ParentID INT ,
      @ClientNum NVARCHAR(20) ,
      @ClientType INT ,
      @ClientName NVARCHAR(100) ,
      @ShortedForm NVARCHAR(20) ,
      @Area INT ,
      @ClientField INT ,
      @ValueLevel INT ,
      @CreditLevel INT ,
      @Importance INT ,
      @ConnectionLevel INT ,
      @GroupID INT ,
      @SourceType INT ,
      @PhaseType INT ,
      @Remark NTEXT ,
      @CreateTime DATETIME ,
      @UpdateTime DATETIME ,
      @Owner NVARCHAR(50) ,
      @IsBusiness INT,
	  @UpdateOwnerTime DATETIME
	
    )
AS 
    INSERT  INTO [PE_Client]
            ( [ClientID] ,
              [ParentID] ,
              [ClientNum] ,
              [ClientType] ,
              [ClientName] ,
              [ShortedForm] ,
              [Area] ,
              [ClientField] ,
              [ValueLevel] ,
              [CreditLevel] ,
              [Importance] ,
              [ConnectionLevel] ,
              [GroupID] ,
              [SourceType] ,
              [PhaseType] ,
              [Remark] ,
              [CreateTime] ,
              [UpdateTime] ,
              [Owner] ,
              [LastContactedTime] ,
              [IsBusiness] ,
			  [UpdateOwnerTime]
            )
    VALUES  ( @ClientID ,
              @ParentID ,
              @ClientNum ,
              @ClientType ,
              @ClientName ,
              @ShortedForm ,
              @Area ,
              @ClientField ,
              @ValueLevel ,
              @CreditLevel ,
              @Importance ,
              @ConnectionLevel ,
              @GroupID ,
              @SourceType ,
              @PhaseType ,
              @Remark ,
              @CreateTime ,
              @UpdateTime ,
              @Owner ,
              GETDATE() ,
              @IsBusiness,
			  @UpdateOwnerTime
            )
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_Nodes]'
GO
ALTER TABLE [dbo].[PE_Nodes] ADD
[EnablePhone] [bit] NULL,
[EnablePad] [bit] 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_Contents_Nodes_UpDate]'
GO
ALTER PROCEDURE [dbo].[PR_Contents_Nodes_UpDate]
    (
      @NodeId INT ,
      @NodeIdentifier NVARCHAR(50) ,
      @ParentId INT ,
      @ParentPath NTEXT ,
      @Depth INT ,
      @RootId INT ,
      @Child INT ,
      @ArrChildId NTEXT ,
      @PrevId INT ,
      @NextId INT ,
      @OrderId INT ,
      @NodeDir NVARCHAR(50) ,
      @ParentDir NTEXT ,
      @EnableSubDomain BIT ,
      @NodeName NVARCHAR(50) ,
      @Tips NVARCHAR(255) ,
      @Description NTEXT ,
      @NodePicUrl NVARCHAR(255) ,
      @MetaKeywords NVARCHAR(255) ,
      @MetaDescription NVARCHAR(255) ,
      @ShowOnMenu BIT ,
      @ShowOnPath BIT ,
      @ShowOnMap BIT ,
      @ShowOnListIndex BIT ,
      @ShowOnListParent BIT ,
      @PurviewType INT ,
      @Creater NVARCHAR(50) ,
      @InheritPurviewFromParent INT ,
      @WorkFlowId INT ,
      @HitsOfHot INT ,
      @LeastOfEliteLevel INT ,
      @OpenType INT ,
      @ItemCount INT ,
      @ItemChecked INT ,
      @CommentCount INT ,
      @CustomContent NTEXT ,
      @IsCreateContentPage BIT ,
      @IsCreateListPage BIT ,
      @AutoCreateHtmlType INT ,
      @ContentPageHtmlRule NVARCHAR(255) ,
      @ListPageHtmlRule NVARCHAR(255) ,
      @ListPageSavePathType INT ,
      @ListPagePostfix NVARCHAR(50) ,
      @RelateNode NTEXT ,
      @RelateSpecial NTEXT ,
      @ItemAspxFileName NVARCHAR(50) ,
      @DefaultTemplateFile NVARCHAR(255) ,
      @ContainChildTemplateFile NVARCHAR(255) ,
      @ItemOpenType INT ,
      @ItemListOrderType INT ,
      @ItemPageSize INT ,
      @LinkUrl NVARCHAR(255) ,
      @Settings NTEXT ,
      @IPLock NTEXT ,
      @NeedCreateHtml BIT ,
      @CultureName NVARCHAR(10) ,
      @SubDomain NVARCHAR(255) ,
      @ConfigType INT ,
      @IncrementalUpdatePages INT ,
      @EnablePhone BIT ,
      @EnablePad BIT
    )
AS 
    UPDATE  PE_Nodes
    SET     NodeIdentifier = @NodeIdentifier ,
            ParentId = @ParentId ,
            ParentPath = @ParentPath ,
            Depth = @Depth ,
            RootId = @RootId ,
            Child = @Child ,
            ArrChildId = @ArrChildId ,
            PrevId = @PrevId ,
            NextId = @NextId ,
            OrderId = @OrderId ,
            NodeDir = @NodeDir ,
            ParentDir = @ParentDir ,
            EnableSubDomain = @EnableSubDomain ,
            NodeName = @NodeName ,
            Tips = @Tips ,
            Description = @Description ,
            NodePicUrl = @NodePicUrl ,
            Meta_Keywords = @MetaKeywords ,
            Meta_Description = @MetaDescription ,
            ShowOnMenu = @ShowOnMenu ,
            ShowOnPath = @ShowOnPath ,
            ShowOnMap = @ShowOnMap ,
            ShowOnList_Index = @ShowOnListIndex ,
            ShowOnList_Parent = @ShowOnListParent ,
            PurviewType = @PurviewType ,
            Creater = @Creater ,
            InheritPurviewFromParent = @InheritPurviewFromParent ,
            WorkFlowID = @WorkFlowId ,
            HitsOfHot = @HitsOfHot ,
            LeastOfEliteLevel = @LeastOfEliteLevel ,
            OpenType = @OpenType ,
            ItemCount = @ItemCount ,
            ItemChecked = @ItemChecked ,
            CommentCount = @CommentCount ,
            Custom_Content = @CustomContent ,
            IsCreateContentPage = @IsCreateContentPage ,
            IsCreateListPage = @IsCreateListPage ,
            AutoCreateHtmlType = @AutoCreateHtmlType ,
            ContentPageHtmlRule = @ContentPageHtmlRule ,
            ListPageHtmlRule = @ListPageHtmlRule ,
            ListPageSavePathType = @ListPageSavePathType ,
            ListPagePostfix = @ListPagePostfix ,
            RelateNode = @RelateNode ,
            RelateSpecial = @RelateSpecial ,
            ItemAspxFileName = @ItemAspxFileName ,
            DefaultTemplateFile = @DefaultTemplateFile ,
            ContainChildTemplateFile = @ContainChildTemplateFile ,
            ItemOpenType = @ItemOpenType ,
            ItemListOrderType = @ItemListOrderType ,
            ItemPageSize = @ItemPageSize ,
            LinkUrl = @LinkUrl ,
            Settings = @Settings ,
            IPLock = @IPLock ,
            NeedCreateHtml = @NeedCreateHtml ,
            CultureName = @CultureName ,
            SubDomain = @SubDomain ,
            ConfigType = @ConfigType ,
            IncrementalUpdatePages = @IncrementalUpdatePages ,
            EnablePhone = @EnablePhone ,
            EnablePad = @EnablePad
    WHERE   NodeID = @NodeID
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_Contents_Nodes_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Contents_Nodes_Add]
    (
      @NodeId INT ,
      @NodeIdentifier NVARCHAR(50) ,
      @NodeType INT ,
      @ParentId INT ,
      @ParentPath NTEXT ,
      @Depth INT ,
      @RootId INT ,
      @Child INT ,
      @ArrChildId NTEXT ,
      @PrevId INT ,
      @NextId INT ,
      @OrderId INT ,
      @NodeDir NVARCHAR(50) ,
      @ParentDir NTEXT ,
      @NodeName NVARCHAR(50) ,
      @Tips NVARCHAR(255) ,
      @Description NTEXT ,
      @NodePicUrl NVARCHAR(255) ,
      @MetaKeywords NVARCHAR(255) ,
      @MetaDescription NVARCHAR(255) ,
      @ShowOnMenu BIT ,
      @ShowOnPath BIT ,
      @ShowOnMap BIT ,
      @ShowOnListIndex BIT ,
      @ShowOnListParent BIT ,
      @PurviewType INT ,
      @Creater NVARCHAR(50) ,
      @InheritPurviewFromParent INT ,
      @WorkFlowId INT ,
      @HitsOfHot INT ,
      @LeastOfEliteLevel INT ,
      @OpenType INT ,
      @ItemCount INT ,
      @ItemChecked INT ,
      @CommentCount INT ,
      @CustomContent NTEXT ,
      @EnableSubDomain BIT ,
      @IsCreateContentPage BIT ,
      @IsCreateListPage BIT ,
      @AutoCreateHtmlType INT ,
      @ContentPageHtmlRule NVARCHAR(255) ,
      @ListPageHtmlRule NVARCHAR(255) ,
      @ListPageSavePathType INT ,
      @ListPagePostfix NVARCHAR(50) ,
      @RelateNode NTEXT ,
      @RelateSpecial NTEXT ,
      @ItemAspxFileName NVARCHAR(50) ,
      @DefaultTemplateFile NVARCHAR(255) ,
      @ContainChildTemplateFile NVARCHAR(255) ,
      @ItemOpenType INT ,
      @ItemListOrderType INT ,
      @ItemPageSize INT ,
      @LinkUrl NVARCHAR(255) ,
      @Settings NTEXT ,
      @IPLock NTEXT ,
      @NeedCreateHtml BIT ,
      @CultureName NVARCHAR(10) ,
      @SubDomain NVARCHAR(255) ,
      @ConfigType INT ,
      @IncrementalUpdatePages INT,
      @EnablePhone BIT ,
      @EnablePad BIT
    )
AS 
    INSERT  INTO PE_Nodes
            ( NodeID ,
              NodeIdentifier ,
              NodeType ,
              ParentID ,
              ParentPath ,
              Depth ,
              RootID ,
              Child ,
              arrChildID ,
              PrevID ,
              NextID ,
              OrderID ,
              NodeDir ,
              ParentDir ,
              NodeName ,
              Tips ,
              Description ,
              NodePicUrl ,
              Meta_Keywords ,
              Meta_Description ,
              ShowOnMenu ,
              ShowOnPath ,
              ShowOnMap ,
              ShowOnList_Index ,
              ShowOnList_Parent ,
              PurviewType ,
              Creater ,
              InheritPurviewFromParent ,
              WorkFlowID ,
              HitsOfHot ,
              LeastOfEliteLevel ,
              OpenType ,
              ItemCount ,
              ItemChecked ,
              CommentCount ,
              Custom_Content ,
              IsCreateContentPage ,
              IsCreateListPage ,
              AutoCreateHtmlType ,
              ContentPageHtmlRule ,
              ListPageHtmlRule ,
              ListPageSavePathType ,
              ListPagePostfix ,
              RelateNode ,
              RelateSpecial ,
              ItemAspxFileName ,
              DefaultTemplateFile ,
              ContainChildTemplateFile ,
              ItemOpenType ,
              ItemListOrderType ,
              ItemPageSize ,
              LinkUrl ,
              Settings ,
              IPLock ,
              NeedCreateHtml ,
              CultureName ,
              EnableSubDomain ,
              SubDomain ,
              ConfigType ,
              IncrementalUpdatePages ,
              EnablePhone ,
              EnablePad
		)
    VALUES  ( @NodeId ,
              @NodeIdentifier ,
              @NodeType ,
              @ParentId ,
              @ParentPath ,
              @Depth ,
              @RootId ,
              @Child ,
              @ArrChildId ,
              @PrevId ,
              @NextId ,
              @OrderId ,
              @NodeDir ,
              @ParentDir ,
              @NodeName ,
              @Tips ,
              @Description ,
              @NodePicUrl ,
              @MetaKeywords ,
              @MetaDescription ,
              @ShowOnMenu ,
              @ShowOnPath ,
              @ShowOnMap ,
              @ShowOnListIndex ,
              @ShowOnListParent ,
              @PurviewType ,
              @Creater ,
              @InheritPurviewFromParent ,
              @WorkFlowId ,
              @HitsOfHot ,
              @LeastOfEliteLevel ,
              @OpenType ,
              @ItemCount ,
              @ItemChecked ,
              @CommentCount ,
              @CustomContent ,
              @IsCreateContentPage ,
              @IsCreateListPage ,
              @AutoCreateHtmlType ,
              @ContentPageHtmlRule ,
              @ListPageHtmlRule ,
              @ListPageSavePathType ,
              @ListPagePostfix ,
              @RelateNode ,
              @RelateSpecial ,
              @ItemAspxFileName ,
              @DefaultTemplateFile ,
              @ContainChildTemplateFile ,
              @ItemOpenType ,
              @ItemListOrderType ,
              @ItemPageSize ,
              @LinkUrl ,
              @Settings ,
              @IPLock ,
              @NeedCreateHtml ,
              @CultureName ,
              @EnableSubDomain ,
              @SubDomain ,
              @ConfigType ,
              @IncrementalUpdatePages ,
              @EnablePhone ,
              @EnablePad
		)
    RETURN
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
