SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL Serializable
GO
BEGIN TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_DownLoadAddress]'
GO
CREATE TABLE [dbo].[Qianbo_DownLoadAddress]
(
[AddressId] [int] NOT NULL IDENTITY(1, 1),
[DownLoadDataId] [int] NOT NULL,
[AddressNum] [int] NULL,
[DownLoadServerID] [int] NULL,
[AddressName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[AddressPath] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_DownLoadAddress_1] on [dbo].[Qianbo_DownLoadAddress]'
GO
ALTER TABLE [dbo].[Qianbo_DownLoadAddress] ADD CONSTRAINT [PK_Qianbo_DownLoadAddress_1] PRIMARY KEY CLUSTERED  ([AddressId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [DownLoadServerID] on [dbo].[Qianbo_DownLoadAddress]'
GO
CREATE NONCLUSTERED INDEX [DownLoadServerID] ON [dbo].[Qianbo_DownLoadAddress] ([DownLoadServerID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadAddress_GetInfoBySoftId]'
GO
CREATE PROC [dbo].[Proc_DownLoadAddress_GetInfoBySoftId] @SoftId INT
AS
    SELECT *
    FROM   Qianbo_DownLoadAddress
    WHERE  DownLoadDataId = @SoftId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_DownLoadData]'
GO
CREATE TABLE [dbo].[Qianbo_DownLoadData]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ChId] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_ChId] DEFAULT ((0)),
[ColId] [int] NOT NULL CONSTRAINT [DF_Qianbo_DownLoadData_ColId] DEFAULT ((0)),
[Title] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_Title] DEFAULT (''),
[TitleColor] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_TitleColor] DEFAULT (''),
[TitleFontType] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_TitleFontType] DEFAULT (''),
[TitleType] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_TitleType] DEFAULT ((0)),
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_TitleImgPath] DEFAULT (''),
[UId] [int] NOT NULL,
[UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UserType] [int] NOT NULL,
[AdminUId] [int] NULL,
[AdminUName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_AdminUName] DEFAULT (''),
[Status] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_Status] DEFAULT ((0)),
[HitCount] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_HitCount] DEFAULT ((0)),
[AddTime] [datetime] NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_TemplatePath] DEFAULT (''),
[PageType] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_PageType] DEFAULT ((1)),
[IsCreated] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsCreated] DEFAULT ((0)),
[UserCateId] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_UserCateId] DEFAULT ((0)),
[PointCount] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_PointCount] DEFAULT ((0)),
[ChargeType] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_ChargeType] DEFAULT ((1)),
[ChargeHourCount] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_ChargeHourCount] DEFAULT ((0)),
[ChargeViewCount] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_ChargeViewCount] DEFAULT ((0)),
[IsOpened] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsOpened] DEFAULT ((2)),
[GroupIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_GroupIdStr] DEFAULT (''),
[IsDeleted] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsDeleted] DEFAULT ((0)),
[IsRecommend] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsRecommend] DEFAULT ((0)),
[IsTop] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsTop] DEFAULT ((0)),
[IsFocus] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsFocus] DEFAULT ((0)),
[IsSideShow] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsSideShow] DEFAULT ((0)),
[IsAllowComment] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadData_IsAllowComment] DEFAULT ((0)),
[TagIdStr] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_TagIdStr] DEFAULT (''),
[TagNameStr] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_TagNameStr] DEFAULT (''),
[SpecialIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_DownLoadData_SpecialIdStr] DEFAULT (''),
[Content] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[Edition] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[PlayAddress] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[DownLoadDownNum] [int] NULL,
[DownLoadDownMonthNum] [int] NULL,
[DownLoadDownWeekNum] [int] NULL,
[DownLoadDownDayNum] [int] NULL,
[DownLoadOS] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[DownLoadServerDataId] [int] NULL,
[Language] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[WarrantType] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[DownLoadSize] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[RegAddress] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Plugin] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[DownLoadStarLevel] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[DownLoadDisplePwd] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[DownLoadType] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[MonthCountTime] [datetime] NULL CONSTRAINT [DF_Qianbo_DownLoadData_CountTime] DEFAULT (getdate()),
[WeekCountTime] [datetime] NULL CONSTRAINT [DF_Qianbo_DownLoadData_WeekCountTime] DEFAULT (getdate()),
[DayCountTime] [datetime] NULL CONSTRAINT [DF_Qianbo_DownLoadData_DayCountTime] DEFAULT (getdate())
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_DownLoadData] on [dbo].[Qianbo_DownLoadData]'
GO
ALTER TABLE [dbo].[Qianbo_DownLoadData] ADD CONSTRAINT [PK_Qianbo_DownLoadData] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_DownLoadData_AddTime] on [dbo].[Qianbo_DownLoadData]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_DownLoadData_AddTime] ON [dbo].[Qianbo_DownLoadData] ([AddTime])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_DownLoadData_ChId] on [dbo].[Qianbo_DownLoadData]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_DownLoadData_ChId] ON [dbo].[Qianbo_DownLoadData] ([ChId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_DownLoadData_ColId] on [dbo].[Qianbo_DownLoadData]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_DownLoadData_ColId] ON [dbo].[Qianbo_DownLoadData] ([ColId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_DownLoadData_SpecialIdStr] on [dbo].[Qianbo_DownLoadData]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_DownLoadData_SpecialIdStr] ON [dbo].[Qianbo_DownLoadData] ([SpecialIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_DownLoadData_TagIdStr] on [dbo].[Qianbo_DownLoadData]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_DownLoadData_TagIdStr] ON [dbo].[Qianbo_DownLoadData] ([TagIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoad_SetDownCount]'
GO
CREATE PROC [dbo].[Proc_DownLoad_SetDownCount] @id INT
AS
    UPDATE Qianbo_DownLoadData
    SET    downloaddownnum = downloaddownnum + 1,
           downloaddownmonthnum = downloaddownmonthnum + 1,
           downloaddownweeknum = downloaddownweeknum + 1,
           downloaddowndaynum = downloaddowndaynum + 1
    WHERE  [id] = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Link]'
GO
CREATE TABLE [dbo].[Qianbo_Link]
(
[LinkId] [int] NOT NULL IDENTITY(1, 1),
[LinkType] [int] NULL CONSTRAINT [DF_Qianbo_Link_LinkType] DEFAULT ((1)),
[LinkCategory] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Link_LinkCategory] DEFAULT (''),
[SiteName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Link_SiteName] DEFAULT (''),
[SiteUrl] [varchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[SiteLogo] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Link_SiteLogo] DEFAULT (''),
[OwnerName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Link_OwnerName] DEFAULT (''),
[Email] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Description] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Link_Description] DEFAULT (''),
[AddTime] [datetime] NULL,
[Status] [int] NOT NULL CONSTRAINT [DF_Qianbo_Link_Status] DEFAULT ((1)),
[IsDisable] [bit] NULL CONSTRAINT [DF_Qianbo_Link_IsDisable] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Link] on [dbo].[Qianbo_Link]'
GO
ALTER TABLE [dbo].[Qianbo_Link] ADD CONSTRAINT [PK_Qianbo_Link] PRIMARY KEY CLUSTERED  ([LinkId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Link_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Link_Add] @LinkType     INT,
                                       @LinkCategory NVARCHAR(40),
                                       @SiteName     NVARCHAR(100),
                                       @SiteUrl      VARCHAR(255),
                                       @SiteLogo     VARCHAR(255),
                                       @OwnerName    NVARCHAR(100),
                                       @Email        NVARCHAR(100),
                                       @Description  NVARCHAR(400),
                                       @AddTime      DATETIME,
                                       @Status       INT,
                                       @IsDisable    BIT
AS
    INSERT INTO Qianbo_Link
                ([LinkType],
                 [LinkCategory],
                 [SiteName],
                 [SiteUrl],
                 [SiteLogo],
                 [OwnerName],
                 [Email],
                 [Description],
                 [AddTime],
                 [Status],
                 [IsDisable])
    VALUES      ( @LinkType,
                  @LinkCategory,
                  @SiteName,
                  @SiteUrl,
                  @SiteLogo,
                  @OwnerName,
                  @Email,
                  @Description,
                  @AddTime,
                  @Status,
                  @IsDisable )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Admin]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Admin]
(
[UserId] [int] NOT NULL IDENTITY(1, 1),
[LoginName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[Password] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[LastLoginIP] [varchar] (11) COLLATE Chinese_PRC_CI_AS NULL,
[LastLoginTime] [datetime] NULL,
[LastLogoutTime] [datetime] NULL,
[LoginTime] [int] NULL CONSTRAINT [DF_Qianbo_Admin_LoginTime] DEFAULT ((0)),
[AllowMultiLogin] [bit] NULL CONSTRAINT [DF_Qianbo_Admin_AllowMultiLogin] DEFAULT ((1)),
[CheckCount] [int] NULL CONSTRAINT [DF_Qianbo_Admin_CheckCount] DEFAULT ((0)),
[AddCount] [int] NULL CONSTRAINT [DF_Qianbo_Admin_AddCount] DEFAULT ((0)),
[RejectCount] [int] NULL CONSTRAINT [DF_Qianbo_Admin_RejectCount] DEFAULT ((0)),
[GroupId] [int] NULL,
[GroupName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[RandNumber] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Admin_RandNumber] DEFAULT ((0)),
[SiteId] [int] NULL CONSTRAINT [DF_Qianbo_Admin_SiteId] DEFAULT ((0)),
[Contact] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL,
[Locked] [bit] NULL CONSTRAINT [DF_Qianbo_Admin_Locked] DEFAULT ((0)),
[IsSiteManage] [int] NULL CONSTRAINT [DF_Qianbo_Admin_IsSiteManage] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK__Qianbo_Admin__76CBA758] on [dbo].[Qianbo_Admin]'
GO
ALTER TABLE [dbo].[Qianbo_Admin] ADD CONSTRAINT [PK__Qianbo_Admin__76CBA758] PRIMARY KEY CLUSTERED  ([UserId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_GetInfoByNameAndPass]'
GO
CREATE PROCEDURE [dbo].[Proc_Admin_GetInfoByNameAndPass] @LoginName NVARCHAR(20),
                                                         @Password  VARCHAR(200)
AS
    SELECT *
    FROM   Qianbo_Admin
    WHERE  LoginName = @LoginName
           AND [Password] = @Password
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserMessage]'
GO
CREATE TABLE [dbo].[Qianbo_UserMessage]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[Title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [text] COLLATE Chinese_PRC_CI_AS NULL,
[UserId] [int] NULL,
[AnounName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[HomePage] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_UserMessage_UserHome] DEFAULT (N'http://'),
[IsPrivacy] [bit] NULL,
[IsResume] [bit] NULL,
[ResumeContent] [text] COLLATE Chinese_PRC_CI_AS NULL,
[PostTime] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[ResumeTime] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserMessage] on [dbo].[Qianbo_UserMessage]'
GO
ALTER TABLE [dbo].[Qianbo_UserMessage] ADD CONSTRAINT [PK_Qianbo_UserMessage] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserMessage_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_UserMessage_Set] @Id            INT,
                                              @Title         NVARCHAR(100),
                                              @Content       TEXT,
                                              @UserId        INT,
                                              @AnounName     NVARCHAR(50),
                                              @HomePage      NVARCHAR(100),
                                              @IsPrivacy     BIT,
                                              @IsResume      BIT,
                                              @ResumeContent TEXT,
                                              @PostTime      NVARCHAR(100)
AS
    IF( @Id = 0 )
      BEGIN
          INSERT INTO Qianbo_UserMessage
                      ([Title],
                       [Content],
                       [UserId],
                       [AnounName],
                       [HomePage],
                       [IsPrivacy],
                       [IsResume],
                       [ResumeContent],
                       [PostTime])
          VALUES      ( @Title,
                        @Content,
                        @UserId,
                        @AnounName,
                        @HomePage,
                        @IsPrivacy,
                        @IsResume,
                        @ResumeContent,
                        @PostTime )
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Ad]'
GO
CREATE TABLE [dbo].[Qianbo_Ad]
(
[AdId] [int] NOT NULL IDENTITY(1, 1),
[CategoryId] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[AdName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Ad_AdName] DEFAULT (''),
[AdType] [int] NULL CONSTRAINT [DF_Qianbo_Ad_AdType] DEFAULT ((1)),
[Content] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NULL,
[EndTime] [datetime] NULL CONSTRAINT [DF_Table2_DisplayType] DEFAULT (getdate()),
[Weight] [int] NULL CONSTRAINT [DF_Qianbo_Ad_Weight] DEFAULT ((10)),
[HitCount] [int] NULL CONSTRAINT [DF_Table2_Click] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Ad] on [dbo].[Qianbo_Ad]'
GO
ALTER TABLE [dbo].[Qianbo_Ad] ADD CONSTRAINT [PK_Qianbo_Ad] PRIMARY KEY CLUSTERED  ([AdId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Ad_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_Ad_Set] @Type       INT,
                                     @AdId       INT,
                                     @CategoryId VARCHAR(100),
                                     @AdName     NVARCHAR(100),
                                     @AdType     INT,
                                     @Content    NVARCHAR(2000),
                                     @EndTime    DATETIME,
                                     @Weight     INT,
                                     @HitCount   INT
AS
    IF( @Type = 1 )
      BEGIN
          INSERT INTO Qianbo_Ad
                      ([CategoryId],
                       [AdName],
                       [AdType],
                       [Content],
                       [EndTime],
                       [Weight],
                       [HitCount])
          VALUES      ( @CategoryId,
                        @AdName,
                        @AdType,
                        @Content,
                        @EndTime,
                        @Weight,
                        @HitCount )
      END
    IF( @Type = 2 )
      BEGIN
          UPDATE Qianbo_Ad
          SET    [CategoryId] = @CategoryId,
                 [AdName] = @AdName,
                 [AdType] = @AdType,
                 [Content] = @Content,
                 [EndTime] = @EndTime,
                 [Weight] = @Weight,
                 [HitCount] = @HitCount
          WHERE  [AdId] = @AdId
      END
    IF( @Type = 3 )
      BEGIN
          DELETE Qianbo_Ad
          WHERE  [AdId] = @AdId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Column]'
GO
CREATE TABLE [dbo].[Qianbo_Column]
(
[ColId] [int] NOT NULL IDENTITY(1, 1),
[ChId] [int] NOT NULL,
[ColName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[ColDirName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[ColParentId] [int] NOT NULL,
[IsOuterColumn] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsOuterColumnUrl] DEFAULT ((0)),
[OuterColumnUrl] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL,
[ColumnImgPath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL,
[Description] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL,
[Keyword] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL,
[IsAllowAddInfo] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsAllowAddInfo] DEFAULT ((1)),
[ColumnTemplatePath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[InfoTemplatePath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[CommentTemplatePath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Sort] [int] NULL CONSTRAINT [DF_Qianbo_Column_Sort] DEFAULT ((1)),
[IsAllowComment] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsAllowCount] DEFAULT ((1)),
[IsCheckComment] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsCheckComment] DEFAULT ((0)),
[InfoTableName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_Column_InfoTableName] DEFAULT (''),
[ScoreReward] [int] NULL CONSTRAINT [DF_Qianbo_Column_ScoreReward] DEFAULT ((0)),
[PointCount] [int] NULL CONSTRAINT [DF_Qianbo_Column_PointCount] DEFAULT ((0)),
[ChargeType] [int] NULL CONSTRAINT [DF_Qianbo_Column_ChargeType] DEFAULT ((1)),
[ChargeHourCount] [int] NULL CONSTRAINT [DF_Qianbo_Column_ChargeHourCount] DEFAULT ((0)),
[ChargeViewCount] [int] NULL CONSTRAINT [DF_Qianbo_Column_ChargeViewCount] DEFAULT ((0)),
[IsOpened] [bit] NULL,
[GroupIdStr] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Column_GroupIdStr] DEFAULT (''),
[ColumnPageType] [int] NULL CONSTRAINT [DF_Qianbo_Column_ColumnPageType] DEFAULT ((1)),
[InfoPageType] [int] NULL CONSTRAINT [DF_Qianbo_Column_InfoPageType] DEFAULT ((1)),
[IsDeleted] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsDeleted] DEFAULT ((0)),
[AddTime] [datetime] NULL,
[IsParentHtml] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsParentHtml_1] DEFAULT ((0)),
[IsUserHtml] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsUserHtml_1] DEFAULT ((0)),
[UserHtml] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[IsSystemHtml] [bit] NULL CONSTRAINT [DF_Qianbo_Column_IsSystemHtml_1] DEFAULT ((0)),
[SystemHtml] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[FieldOrder] [ntext] COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Column] on [dbo].[Qianbo_Column]'
GO
ALTER TABLE [dbo].[Qianbo_Column] ADD CONSTRAINT [PK_Qianbo_Column] PRIMARY KEY CLUSTERED  ([ColId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Column_chid] on [dbo].[Qianbo_Column]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Column_chid] ON [dbo].[Qianbo_Column] ([ChId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_GetAll]'
GO
CREATE PROCEDURE [dbo].[Proc_Column_GetAll]
AS
    SELECT *
    FROM   Qianbo_Column
    ORDER  BY sort ASC,
              colid ASC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Users]'
GO
CREATE TABLE [dbo].[Qianbo_Users]
(
[UserID] [int] NOT NULL IDENTITY(1, 1),
[LogName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[UserPwd] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[Email] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[TypeId] [int] NULL,
[GroupID] [int] NULL,
[Question] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Answer] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Integral] [int] NULL,
[YellowBoy] [decimal] (10, 2) NULL CONSTRAINT [DF_Qianbo_Users_YellowBoy] DEFAULT ((0)),
[IsLock] [bit] NULL CONSTRAINT [DF_Qianbo_Users_IsLock] DEFAULT ((0)),
[LoginNum] [int] NULL CONSTRAINT [DF_Qianbo_Users_LoginNum] DEFAULT ((1)),
[LastLoginIP] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[RegTime] [datetime] NULL CONSTRAINT [DF_Qianbo_Users_RegTime] DEFAULT (getdate()),
[LastLoginTime] [datetime] NULL CONSTRAINT [DF_Qianbo_Users_LastLoginTime] DEFAULT (getdate()),
[Secret] [tinyint] NULL,
[ErrorNum] [int] NULL CONSTRAINT [DF_Qianbo_Users_ErrorNum] DEFAULT ((0)),
[ErrorTime] [datetime] NULL CONSTRAINT [DF_Qianbo_Users_ErrorTime] DEFAULT (getdate()),
[ExpireTime] [datetime] NULL CONSTRAINT [DF_Qianbo_Users_ExpireTime] DEFAULT (getdate()),
[ConfirmRegCode] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Status] [int] NULL,
[SiteId] [int] NULL CONSTRAINT [DF_Qianbo_Users_SiteId] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Users] on [dbo].[Qianbo_Users]'
GO
ALTER TABLE [dbo].[Qianbo_Users] ADD CONSTRAINT [PK_Qianbo_Users] PRIMARY KEY CLUSTERED  ([UserID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_Login_OnErrorNum]'
GO
CREATE PROC [dbo].[Proc_Users_Login_OnErrorNum] @userid    INT,
                                                @errortime DATETIME
AS
    UPDATE [Qianbo_Users]
    SET    [errortime] = @errortime
    WHERE  [userid] = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Tag]'
GO
CREATE TABLE [dbo].[Qianbo_Tag]
(
[TagId] [bigint] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[TagCategoryId] [int] NOT NULL,
[ModelType] [int] NOT NULL,
[DaySearchCount] [int] NULL CONSTRAINT [DF_Qianbo_TagKeyword_DaySearchCount] DEFAULT ((0)),
[YesterdaySearchCount] [int] NULL CONSTRAINT [DF_Qianbo_TagKeyword_YesterdaySearchCount] DEFAULT ((0)),
[TotalSearchCount] [int] NULL CONSTRAINT [DF_Qianbo_TagKeyword_TotalSearchCount] DEFAULT ((0)),
[UserId] [int] NULL CONSTRAINT [DF_Qianbo_TagKeyword_UserId] DEFAULT ((0)),
[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[CountTime] [datetime] NULL CONSTRAINT [DF_Qianbo_Tag_CountTime] DEFAULT (getdate())
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_TagKeyword] on [dbo].[Qianbo_Tag]'
GO
ALTER TABLE [dbo].[Qianbo_Tag] ADD CONSTRAINT [PK_Qianbo_TagKeyword] PRIMARY KEY CLUSTERED  ([TagId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Tag] on [dbo].[Qianbo_Tag]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Tag] ON [dbo].[Qianbo_Tag] ([TotalSearchCount] DESC, [TagId] DESC)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Tag_AddTagStr]'
GO
CREATE PROCEDURE [dbo].[Proc_Tag_AddTagStr] @tagstr    NVARCHAR(300),
                                            @modeltype INT,
                                            @uid       INT,
                                            @uname     NVARCHAR(20)
AS
    IF( @tagstr = '' )
      SELECT '',
             ''
    ELSE
      SET @tagstr = @tagstr + '|'
    DECLARE @tb TABLE
      (
         [name] NVARCHAR(20)
      )
    DECLARE @index INT
    DECLARE @name NVARCHAR(20)
    WHILE( @tagstr <> '' )
      BEGIN
          SET @index = Charindex('|', @tagstr)
          SET @name = Substring(@tagstr, 1, @index - 1)
          SET @tagstr = Substring(@tagstr, @index + 1, Len(@tagstr) - @index)
          INSERT INTO @tb
          VALUES      (@name)
      END
    DECLARE @returnidstr NVARCHAR(300)
    DECLARE @char NVARCHAR(1)
    SET @returnidstr = ''
    SET @char = '';
    DECLARE @returnid NVARCHAR(15)
    DECLARE @returnnamestr NVARCHAR(300)
    SET @returnnamestr = ''
    DECLARE cur CURSOR fast_forward FOR
      (SELECT [name]
       FROM   @tb)
    OPEN cur
    FETCH next FROM cur INTO @name
    WHILE( @@fetch_status = 0 )
      BEGIN
          IF EXISTS(SELECT *
                    FROM   Qianbo_Tag
                    WHERE  [name] = @name)
            BEGIN
                SET @returnid = (SELECT tagid
                                 FROM   Qianbo_Tag
                                 WHERE  [name] = @name)
                SET @returnidstr= @returnidstr + @char + @returnid
                SET @returnnamestr = @returnnamestr + @char + @name
                SET @char = '|'
            END
          ELSE
            BEGIN
                IF( @name != '' )
                  BEGIN
                      INSERT INTO Qianbo_Tag
                                  ([name],
                                   tagcategoryid,
                                   modeltype,
                                   userid,
                                   username)
                      VALUES      (@name,
                                   0,
                                   @modeltype,
                                   @uid,
                                   @uname)
                      SET @returnid = Scope_identity()
                      SET @returnidstr= @returnidstr + @char + @returnid
                      SET @returnnamestr = @returnnamestr + @char + @name
                      SET @char = '|'
                  END
            END
          FETCH next FROM cur INTO @name
      END
    CLOSE cur
    DEALLOCATE cur
    SELECT @returnidstr,
           @returnnamestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadAddress_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadAddress_Set] @AddressId        INT output,
                                                  @DownLoadDataId   INT,
                                                  @AddressNum       INT,
                                                  @DownLoadServerID INT,
                                                  @AddressName      NVARCHAR(100),
                                                  @AddressPath      NVARCHAR(100)
AS
    IF( @AddressId = 0 )
      BEGIN
          INSERT INTO Qianbo_DownLoadAddress
                      ([DownLoadDataId],
                       [AddressNum],
                       [DownLoadServerID],
                       [AddressName],
                       [AddressPath])
          VALUES      ( @DownLoadDataId,
                        @AddressNum,
                        @DownLoadServerID,
                        @AddressName,
                        @AddressPath )
          SET @AddressId=Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_DownLoadAddress
          SET    [DownLoadDataId] = @DownLoadDataId,
                 [AddressNum] = @AddressNum,
                 [DownLoadServerID] = @DownLoadServerID,
                 [AddressName] = @AddressName,
                 [AddressPath] = @AddressPath
          WHERE  [AddressId] = @AddressId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Article]'
GO
CREATE TABLE [dbo].[Qianbo_Article]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ChId] [int] NULL CONSTRAINT [DF_Qianbo_Article_ChId] DEFAULT ((0)),
[ColId] [int] NOT NULL CONSTRAINT [DF_Qianbo_Article_ColId] DEFAULT ((0)),
[Title] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_Title] DEFAULT (''),
[TitleColor] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_TitleColor] DEFAULT (''),
[TitleFontType] [int] NULL CONSTRAINT [DF_Qianbo_Article_TitleFontType] DEFAULT (''),
[TitleType] [int] NULL CONSTRAINT [DF_Qianbo_Article_TitleType] DEFAULT ((0)),
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_TitleImgPath] DEFAULT (''),
[UId] [int] NOT NULL,
[UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UserType] [int] NOT NULL,
[AdminUId] [int] NULL,
[AdminUName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_AdminUName] DEFAULT (''),
[Status] [int] NULL CONSTRAINT [DF_Qianbo_Article_Status] DEFAULT ((0)),
[HitCount] [int] NULL CONSTRAINT [DF_Qianbo_Article_HitsCount] DEFAULT ((0)),
[AddTime] [datetime] NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_TemplatePath] DEFAULT (''),
[PageType] [int] NULL CONSTRAINT [DF_Qianbo_Article_PageType] DEFAULT ((1)),
[IsCreated] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsCreated] DEFAULT ((0)),
[UserCateId] [int] NULL CONSTRAINT [DF_Qianbo_Article_UserCateId] DEFAULT ((0)),
[PointCount] [int] NULL CONSTRAINT [DF_Qianbo_Article_PointCount] DEFAULT ((0)),
[ChargeType] [int] NULL CONSTRAINT [DF_Qianbo_Article_ChargeType] DEFAULT ((1)),
[ChargeHourCount] [int] NULL CONSTRAINT [DF_Qianbo_Article_ChargeHourCount] DEFAULT ((0)),
[ChargeViewCount] [int] NULL CONSTRAINT [DF_Qianbo_Article_ChargeViewCount] DEFAULT ((0)),
[IsOpened] [int] NULL CONSTRAINT [DF_Qianbo_Article_IsOpened] DEFAULT ((2)),
[GroupIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_GroupIdStr] DEFAULT (''),
[IsDeleted] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsDeleted] DEFAULT ((0)),
[IsRecommend] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsRecommend] DEFAULT ((0)),
[IsTop] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsTop] DEFAULT ((0)),
[IsFocus] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsFocus] DEFAULT ((0)),
[IsSideShow] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsSideShow] DEFAULT ((0)),
[IsAllowComment] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsAllowComment] DEFAULT ((0)),
[TagIdStr] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_TagIdStr] DEFAULT (''),
[TagNameStr] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_TagNameStr] DEFAULT (''),
[SpecialIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_SpecialIdStr] DEFAULT (''),
[LongTitle] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_LongTitle] DEFAULT (''),
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_Content] DEFAULT (''),
[ShortContent] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_ShortContent] DEFAULT (''),
[OuterUrl] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_OuterUrl] DEFAULT (''),
[Author] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_Author] DEFAULT (''),
[Source] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_Source] DEFAULT (''),
[IsHeader] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsHeader] DEFAULT ((0)),
[HeaderFont] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_HeaderFont] DEFAULT (''),
[HeaderImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_HeaderImgPath] DEFAULT (''),
[StarLevel] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_StarLevel] DEFAULT (''),
[IsShowCommentLink] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsShowCommentLink] DEFAULT ((0)),
[IsIrregular] [bit] NULL CONSTRAINT [DF_Qianbo_Article_IsIrregular] DEFAULT ((0)),
[IrregularId] [int] NULL CONSTRAINT [DF_Qianbo_Article_IrregularId] DEFAULT ((0)),
[ViewUName] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_ViewUName1] DEFAULT (''),
[ViewUName2] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_ViewUName2] DEFAULT (''),
[ViewEndTime] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Article_ViewEndTime] DEFAULT (''),
[ExpireTime] [datetime] NOT NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Article] on [dbo].[Qianbo_Article]'
GO
ALTER TABLE [dbo].[Qianbo_Article] ADD CONSTRAINT [PK_Qianbo_Article] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Article_AddTime] on [dbo].[Qianbo_Article]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Article_AddTime] ON [dbo].[Qianbo_Article] ([AddTime])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Article_ChId] on [dbo].[Qianbo_Article]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Article_ChId] ON [dbo].[Qianbo_Article] ([ChId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Article_ColId] on [dbo].[Qianbo_Article]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Article_ColId] ON [dbo].[Qianbo_Article] ([ColId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Article_ExpireTime] on [dbo].[Qianbo_Article]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Article_ExpireTime] ON [dbo].[Qianbo_Article] ([ExpireTime])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Article_SpecialIdStr] on [dbo].[Qianbo_Article]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Article_SpecialIdStr] ON [dbo].[Qianbo_Article] ([SpecialIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Article_TagIdStr] on [dbo].[Qianbo_Article]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Article_TagIdStr] ON [dbo].[Qianbo_Article] ([TagIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Article_GetExpireArticleCount]'
GO
CREATE PROC [dbo].[Proc_Article_GetExpireArticleCount] @chid  INT,
                                                       @colid INT
AS
    IF @colid = 0
      SELECT Count([id])
      FROM   [Qianbo_Article] i
             JOIN [Qianbo_Column] co
               ON i.colid = co.colid
      WHERE  co.chid = @chid
             AND expiretime < Getdate()
    ELSE
      SELECT Count([id])
      FROM   [Qianbo_Article] i
             JOIN [Qianbo_Column] co
               ON i.colid = co.colid
      WHERE  co.chid = @chid
             AND i.colid = @colid
             AND expiretime < Getdate()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Special]'
GO
CREATE TABLE [dbo].[Qianbo_Special]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[ParentID] [int] NULL,
[SiteID] [int] NULL,
[SpecialCName] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NULL,
[SpecialEName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[SpecialDomain] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[SpecialRemark] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[IsLock] [bit] NULL,
[IsCommand] [bit] NULL,
[SpecialAddTime] [datetime] NULL,
[MetaKeyWord] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[MetaRemark] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[SpecialTemplet] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[SpecialItemNum] [int] NULL,
[SpecialContent] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[SaveDirType] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[IsDeleted] [int] NULL,
[Extension] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[PicSavePath] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_GetSpecial]'
GO
CREATE PROCEDURE [dbo].[Proc_Special_GetSpecial] (@ID INT)
AS
    SELECT *
    FROM   Qianbo_Special
    WHERE  [ID] = @ID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_Move]'
GO
CREATE PROCEDURE [dbo].[Proc_Column_Move] @ColId      INT,
                                          @TargetId   INT,
                                          @IsChannel  BIT,
                                          @ChildIdStr NVARCHAR(1000)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF( @IsChannel = 1 )
      BEGIN
          UPDATE Qianbo_Column
          SET    ChId = @TargetId,
                 ColParentId = 0
          WHERE  ColId = @ColId;
          SET @SqlStr = N'update Qianbo_Column set ChId = '
                        + CONVERT(NVARCHAR(15), @TargetId)
                        + ' where ColId in(' + @ChildIdStr + ')'
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
    ELSE
      BEGIN
          DECLARE @ChId INT
          SET @ChId=(SELECT ChId
                     FROM   Qianbo_Column
                     WHERE  ColId = @TargetId);
          UPDATE Qianbo_Column
          SET    ChId = @ChId,
                 ColParentId = @TargetId
          WHERE  ColId = @ColId;
          SET @SqlStr = N'update Qianbo_Column set ChId = '
                        + CONVERT(NVARCHAR(15), @ChId)
                        + ' where ColId in(' + @ChildIdStr + ')'
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Property]'
GO
CREATE TABLE [dbo].[Qianbo_Property]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ParentId] [int] NULL,
[ModelId] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[FormId] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[UserId] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[PropertyCName] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[PropertyEName] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[PropertyKeyword] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[PropertyContent] [text] COLLATE Chinese_PRC_CI_AS NULL,
[PropertyExtName] [int] NULL,
[PropertyPic] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[PropertyTemplate] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[PropertyDir] [int] NULL,
[PropertyOrder] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Property] on [dbo].[Qianbo_Property]'
GO
ALTER TABLE [dbo].[Qianbo_Property] ADD CONSTRAINT [PK_Qianbo_Property] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_Update]'
GO
CREATE PROC [dbo].[Proc_Property_Update] @Id               INT,
                                         @ParentId         INT,
                                         @PropertyCName    NVARCHAR(400),
                                         @PropertyEName    NVARCHAR(400),
                                         @PropertyKeyword  NVARCHAR(1000),
                                         @PropertyContent  TEXT,
                                         @PropertyExtName  INT,
                                         @PropertyPic      NVARCHAR(400),
                                         @PropertyTemplate NVARCHAR(400),
                                         @PropertyDir      INT,
                                         @PropertyOrder    INT
AS
    UPDATE Qianbo_Property
    SET    [ParentId] = @ParentId,
           [PropertyCName] = @PropertyCName,
           [PropertyEName] = @PropertyEName,
           [PropertyKeyword] = @PropertyKeyword,
           [PropertyContent] = @PropertyContent,
           [PropertyExtName] = @PropertyExtName,
           [PropertyPic] = @PropertyPic,
           [PropertyTemplate] = @PropertyTemplate,
           [PropertyDir] = @PropertyDir,
           [PropertyOrder] = @PropertyOrder
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_ViewLog]'
GO
CREATE TABLE [dbo].[Qianbo_ViewLog]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[UserId] [int] NOT NULL,
[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[ModelType] [int] NOT NULL,
[InfoId] [int] NOT NULL,
[AddTime] [datetime] NOT NULL CONSTRAINT [DF_Qianbo_ViewLog_AddTime] DEFAULT (getdate())
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_ViewLog] on [dbo].[Qianbo_ViewLog]'
GO
ALTER TABLE [dbo].[Qianbo_ViewLog] ADD CONSTRAINT [PK_Qianbo_ViewLog] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ViewLog_GetViewCount]'
GO
CREATE PROCEDURE [dbo].[Proc_ViewLog_GetViewCount] @UserId INT,
                                                   @Date   VARCHAR(10)
AS
    SELECT Count(Id)
    FROM   Qianbo_ViewLog
    WHERE  CONVERT(VARCHAR(10), AddTime, 120) = @Date
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_FeedBack]'
GO
CREATE TABLE [dbo].[Qianbo_FeedBack]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[ParentId] [int] NULL,
[title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_FeedBack_title] DEFAULT (''),
[author] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_FeedBack_author] DEFAULT (''),
[reward] [int] NULL CONSTRAINT [DF_Qianbo_FeedBack_reward] DEFAULT ((0)),
[scoring] [int] NULL CONSTRAINT [DF_Qianbo_FeedBack_scoring] DEFAULT ((0)),
[categoryId] [int] NULL CONSTRAINT [DF_Qianbo_FeedBack_category] DEFAULT ((5)),
[content] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_FeedBack_content] DEFAULT (''),
[state] [int] NULL CONSTRAINT [DF_Qianbo_FeedBack_state] DEFAULT ((0)),
[replyDate] [datetime] NULL CONSTRAINT [DF_Qianbo_FeedBack_replyDate] DEFAULT (getdate()),
[EndDate] [datetime] NULL,
[IP] [nvarchar] (15) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_FeedBack_IP] DEFAULT ('')
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Communit] on [dbo].[Qianbo_FeedBack]'
GO
ALTER TABLE [dbo].[Qianbo_FeedBack] ADD CONSTRAINT [PK_Qianbo_Communit] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_FeedBack_Count]'
GO
CREATE PROCEDURE [dbo].[Proc_FeedBack_Count]
AS
    SELECT Count(id) AS total
    FROM   Qianbo_FeedBack
    WHERE  ParentId = 0
    SELECT Count(id) AS finished
    FROM   Qianbo_FeedBack
    WHERE  parentId = 0
           AND state = 1
            OR state = 2
    SELECT Count(id) AS answing
    FROM   Qianbo_FeedBack
    WHERE  parentId = 0
           AND state = 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Tag_Clear]'
GO
CREATE PROC [dbo].[Proc_Tag_Clear]
AS
    UPDATE [Qianbo_Tag]
    SET    daysearchcount = 0,
           yesterdaysearchcount = daysearchcount,
           counttime = Getdate()
    WHERE  Datediff(day, counttime, Getdate()) != 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_StyleCategory]'
GO
CREATE TABLE [dbo].[Qianbo_StyleCategory]
(
[StyleCategoryID] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[ParentID] [int] NULL CONSTRAINT [DF_Qianbo_StyleCategory_ParentID] DEFAULT ((0)),
[Desc] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_StyleCategory] on [dbo].[Qianbo_StyleCategory]'
GO
ALTER TABLE [dbo].[Qianbo_StyleCategory] ADD CONSTRAINT [PK_Qianbo_StyleCategory] PRIMARY KEY CLUSTERED  ([StyleCategoryID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_StyleCategory_Update]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_StyleCategory_Update] @StyleCategoryId INT,
                                                   @ParentId        INT,
                                                   @Name            NVARCHAR(50),
                                                   @Desc            NVARCHAR(100)
AS
    UPDATE Qianbo_StyleCategory
    SET    ParentId = @ParentId,
           [Name] = @Name,
           [Desc] = @Desc
    WHERE  StyleCategoryId = @StyleCategoryId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_GetSiteModel]'
GO
CREATE PROCEDURE [dbo].[Proc_Admin_GetSiteModel] @SiteId INT
AS
    SELECT *
    FROM   [Qianbo_Admin]
    WHERE  SiteId = @SiteId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserFriendGroup]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_UserFriendGroup]
(
[FriendGroupId] [int] NOT NULL IDENTITY(1, 1),
[FriendGroupName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[IsUserId] [int] NULL CONSTRAINT [DF_Qianbo_UserFriendGroup_IsSystem] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserFriendGroup] on [dbo].[Qianbo_UserFriendGroup]'
GO
ALTER TABLE [dbo].[Qianbo_UserFriendGroup] ADD CONSTRAINT [PK_Qianbo_UserFriendGroup] PRIMARY KEY CLUSTERED  ([FriendGroupId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserFriend]'
GO
CREATE TABLE [dbo].[Qianbo_UserFriend]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[UserId] [int] NOT NULL,
[FriendId] [int] NOT NULL,
[FriendGroupId] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserFriend] on [dbo].[Qianbo_UserFriend]'
GO
ALTER TABLE [dbo].[Qianbo_UserFriend] ADD CONSTRAINT [PK_Qianbo_UserFriend] PRIMARY KEY CLUSTERED  ([UserId], [FriendId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_SetFriendGroup]'
GO
CREATE PROCEDURE [dbo].[Proc_User_SetFriendGroup] @GroupName NVARCHAR(50),
                                                  @IsUserId  INT,
                                                  @GroupId   INT,
                                                  @Type      VARCHAR(20)
AS
    IF @Type = 'Add'
      BEGIN
          INSERT INTO Qianbo_UserFriendGroup
          VALUES      (@GroupName,
                       @IsUserId)
      END
    IF @Type = 'ListGroup'
      BEGIN
          SELECT *
          FROM   Qianbo_UserFriendGroup
          WHERE  IsUserId = @IsUserId
                  OR IsUserId = 0
      END
    IF @Type = 'Delete'
      BEGIN
          DELETE FROM Qianbo_UserFriendGroup
          WHERE  FriendGroupId = @GroupId
          DELETE FROM Qianbo_UserFriend
          WHERE  FriendGroupId = @GroupId
      END
    IF @Type = 'Update'
      BEGIN
          UPDATE Qianbo_UserFriendGroup
          SET    FriendGroupName = @GroupName
          WHERE  FriendGroupId = @GroupId
      END
    IF @Type = 'CountMember'
      BEGIN
          SELECT Count(FriendId)
          FROM   Qianbo_UserFriend
          WHERE  FriendGroupId = @GroupId
                 AND UserId = @IsUserId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Link_GetModel]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Link_GetModel] @LinkId INT
AS
    SELECT [LinkId],
           [LinkType],
           [LinkCategory],
           [SiteName],
           [SiteUrl],
           [SiteLogo],
           [OwnerName],
           [Email],
           [Description],
           [AddTime],
           [Status],
           [IsDisable]
    FROM   Qianbo_Link
    WHERE  [LinkId] = @LinkId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_Login_Success]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Users_Login_Success] @userid        INT,
                                             @lastloginip   NVARCHAR(20),
                                             @lastlogintime DATETIME
AS
    UPDATE [Qianbo_Users]
    SET    [loginnum] = [loginnum] + 1,
           [lastloginip] = @lastloginip,
           [lastlogintime] = @lastlogintime,
           [errornum] = 0
    WHERE  [userid] = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_SinglePage]'
GO
CREATE TABLE [dbo].[Qianbo_SinglePage]
(
[SingleId] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[FolderPath] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[FileName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[FileExtend] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[TemplatePath] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[AddTime] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_SinglePage] on [dbo].[Qianbo_SinglePage]'
GO
ALTER TABLE [dbo].[Qianbo_SinglePage] ADD CONSTRAINT [PK_Qianbo_SinglePage] PRIMARY KEY CLUSTERED  ([SingleId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SinglePage_Update]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SinglePage_Update] @SingleId     INT,
                                                @Name         NVARCHAR(200),
                                                @FolderPath   NVARCHAR(100),
                                                @FileName     NVARCHAR(200),
                                                @FileExtend   NVARCHAR(100),
                                                @TemplatePath NVARCHAR(300),
                                                @Content      NVARCHAR(400),
                                                @AddTime      DATETIME
AS
    UPDATE Qianbo_SinglePage
    SET    [Name] = @Name,
           [FolderPath] = @FolderPath,
           [FileName] = @FileName,
           [FileExtend] = @FileExtend,
           [TemplatePath] = @TemplatePath,
           [Content] = @Content,
           [AddTime] = @AddTime
    WHERE  [SingleId] = @SingleId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Tag_Delete]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Tag_Delete] @SearchCount INT
AS
    DELETE FROM Qianbo_Tag
    WHERE  TotalSearchCount < @SearchCount
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_HireInfo]'
GO
CREATE TABLE [dbo].[Qianbo_HireInfo]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[UId] [int] NULL,
[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[UnitId] [int] NULL,
[UnitName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[UserType] [int] NULL,
[Status] [int] NULL,
[AddTime] [datetime] NULL,
[JobId] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_HireInfo_Set]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_HireInfo_Set] @Type     INT=1,
                                           @Id       INT=0,
                                           @UserId   INT,
                                           @UserName NVARCHAR(20),
                                           @UnitId   INT,
                                           @UnitName NVARCHAR(100),
                                           @UserType INT,
                                           @Status   INT,
                                           @AddTime  DATETIME,
                                           @JobId    INT
AS
    IF @Type = 1
      BEGIN
          IF EXISTS(SELECT *
                    FROM   Qianbo_HireInfo
                    WHERE  UId = @UserId
                           AND JobId = @JobId
                           AND UserType = @UserType)
            RETURN
          ELSE
            INSERT INTO Qianbo_HireInfo
            VALUES      (@UserId,
                         @UserName,
                         @UnitId,
                         @UnitName,
                         @UserType,
                         @Status,
                         @AddTime,
                         @JobId)
      END
    ELSE IF @Type = 2
      BEGIN
          UPDATE Qianbo_HireInfo
          SET    Status = @Status
          WHERE  [Id] = @Id
      END
    ELSE IF @Type = 3
      BEGIN
          DELETE FROM Qianbo_HireInfo
          WHERE  [Id] = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Link_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_Link_Set] @LinkId INT,
                                       @Type   INT
AS
    IF( @Type = 1 )
      BEGIN
          DELETE Qianbo_Link
          WHERE  [LinkId] = @LinkId
      END
    IF( @Type = 2 )
      BEGIN
          UPDATE Qianbo_Link
          SET    Status = 2
          WHERE  LinkId = @LinkId
      END
    IF( @Type = 3 )
      BEGIN
          UPDATE Qianbo_Link
          SET    IsDisable = 1
          WHERE  LinkId = @LinkId
      END
    IF( @Type = 4 )
      BEGIN
          UPDATE Qianbo_Link
          SET    IsDisable = 0
          WHERE  LinkId = @LinkId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Model]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Model]
(
[ModelId] [int] NOT NULL IDENTITY(1, 1),
[ModelName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[ModelDesc] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Model_ModelDesc] DEFAULT (''),
[TableName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UploadPath] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UploadSize] [int] NULL CONSTRAINT [DF_Qianbo_Model_UploadSize] DEFAULT ((0)),
[IsSystem] [bit] NOT NULL CONSTRAINT [DF_Qianbo_Model_IsSystem] DEFAULT ((0)),
[AddTime] [datetime] NOT NULL CONSTRAINT [DF_Qianbo_Model_AddTime] DEFAULT (getdate()),
[ModelHtml] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[IsHtml] [bit] NULL CONSTRAINT [DF_Qianbo_Model_IsHtml] DEFAULT ((0)),
[ModelSort] [int] NULL CONSTRAINT [DF_Qianbo_Model_ModelSort] DEFAULT ((1))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Model] on [dbo].[Qianbo_Model]'
GO
ALTER TABLE [dbo].[Qianbo_Model] ADD CONSTRAINT [PK_Qianbo_Model] PRIMARY KEY CLUSTERED  ([ModelId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Channel]'
GO
CREATE TABLE [dbo].[Qianbo_Channel]
(
[ChId] [int] NOT NULL IDENTITY(1, 1),
[ChName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Description] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Channel_Description] DEFAULT (''),
[TemplatePath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[IsChildSite] [bit] NULL CONSTRAINT [DF_Qianbo_Channel_IsChildSite] DEFAULT ((0)),
[ChildSiteUrl] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Channel_ChildSiteUrl] DEFAULT (''),
[IsOpenLink] [bit] NULL CONSTRAINT [DF_Qianbo_Channel_IsOpenLink] DEFAULT ((0)),
[ModelType] [int] NOT NULL,
[DirName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[TypeName] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL,
[TypeUnit] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL,
[IsDisabled] [bit] NULL CONSTRAINT [DF_Qianbo_Channel_IsDisabled] DEFAULT ((0)),
[IsOpened] [bit] NULL CONSTRAINT [DF_Qianbo_Channel_IsOpened] DEFAULT ((1)),
[GroupIdStr] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Channel_GroupIdStr] DEFAULT (''),
[VerifyType] [int] NULL CONSTRAINT [DF_Qianbo_Channel_VerifyType] DEFAULT ((0)),
[Notice1] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Channel_Notice1] DEFAULT (''),
[Notice2] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Channel_Notice2] DEFAULT (''),
[Keyword] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Channel_Keyword] DEFAULT (''),
[Content] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Channel_Content] DEFAULT (''),
[MiniHitCount] [int] NOT NULL CONSTRAINT [DF_Qianbo_Channel_MiniHitCount] DEFAULT ((500)),
[IsStaticType] [bit] NOT NULL CONSTRAINT [DF_Qianbo_Channel_IsStaticType] DEFAULT ((1)),
[ColumnSortType] [int] NOT NULL CONSTRAINT [DF_Qianbo_Channel_ColumnSortType] DEFAULT ((1)),
[InfoSortType] [int] NOT NULL CONSTRAINT [DF_Qianbo_Channel_InfoSortType] DEFAULT ((1)),
[FileNameType] [int] NOT NULL,
[ChannelPageType] [int] NULL CONSTRAINT [DF_Qianbo_Channel_ChannelExtNameType] DEFAULT ((1)),
[ColumnPageType] [int] NULL CONSTRAINT [DF_Qianbo_Channel_ColumnExtName] DEFAULT ((1)),
[InfoPageType] [int] NULL CONSTRAINT [DF_Qianbo_Channel_InfoPageType] DEFAULT ((1)),
[AddTime] [datetime] NOT NULL,
[Sort] [int] NULL CONSTRAINT [DF_Qianbo_Channel_Sort] DEFAULT ((1)),
[ColumnTemplatePath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_Channel_ColumnTemplatePath] DEFAULT (''),
[InfoTemplatePath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_Channel_InfoTemplatePath] DEFAULT (''),
[CommentTemplatePath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_Channel_CommentTemplatePath] DEFAULT (''),
[IsDeleted] [bit] NOT NULL CONSTRAINT [DF_Qianbo_Channel_IsDeleted] DEFAULT ((0)),
[ChType] [int] NULL CONSTRAINT [DF_Qianbo_Channel_ChType] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Channel] on [dbo].[Qianbo_Channel]'
GO
ALTER TABLE [dbo].[Qianbo_Channel] ADD CONSTRAINT [PK_Qianbo_Channel] PRIMARY KEY CLUSTERED  ([ChId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Channel_ModelType] on [dbo].[Qianbo_Channel]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Channel_ModelType] ON [dbo].[Qianbo_Channel] ([ModelType])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Channel_CompleteDelete]'
GO
CREATE PROC [dbo].[Proc_Channel_CompleteDelete] @chid INT
AS
    DECLARE @tablename NVARCHAR(50)
    SET @tablename = (SELECT tablename
                      FROM   Qianbo_Channel ch
                             JOIN Qianbo_Model m
                               ON ch.modeltype = m.modelid
                      WHERE  ch.chid = @chid)
    DECLARE @sqlstr NVARCHAR(2000)
    DECLARE @param NVARCHAR(200)
    SET @param = '@tchid int'
    SET @sqlstr = 'delete i from [' + @tablename
                  + '] i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid where ch.chid = @tchid'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
    SET @sqlstr = 'delete co from Qianbo_Column co join Qianbo_Channel ch on co.chid = ch.chid where ch.chid = @tchid '
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
    SET @sqlstr = 'delete from Qianbo_Channel where chid = @tchid'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_Column_Update] @ColId               INT,
                                            @ChId                INT,
                                            @ColName             NVARCHAR(50),
                                            @ColDirName          NVARCHAR(50),
                                            @ColParentId         INT,
                                            @IsOuterColumn       BIT,
                                            @OuterColumnUrl      VARCHAR(255),
                                            @ColumnImgPath       NVARCHAR(255),
                                            @Description         NVARCHAR(510),
                                            @Keyword             NVARCHAR(100),
                                            @Content             NVARCHAR(300),
                                            @IsAllowAddInfo      BIT,
                                            @ColumnTemplatePath  NVARCHAR(255),
                                            @InfoTemplatePath    NVARCHAR(255),
                                            @CommentTemplatePath NVARCHAR(255),
                                            @Sort                INT,
                                            @IsAllowComment      BIT,
                                            @IsCheckComment      BIT,
                                            @InfoTableName       NVARCHAR(50),
                                            @ScoreReward         INT,
                                            @PointCount          INT,
                                            @ChargeType          INT,
                                            @ChargeHourCount     INT,
                                            @ChargeViewCount     INT,
                                            @IsOpened            BIT,
                                            @GroupIdStr          VARCHAR(500),
                                            @ColumnPageType      INT,
                                            @InfoPageType        INT,
                                            @IsParentHtml        BIT
AS
    UPDATE Qianbo_Column
    SET    [ChId] = @ChId,
           [ColName] = @ColName,
           [ColDirName] = @ColDirName,
           [ColParentId] = @ColParentId,
           [IsOuterColumn] = @IsOuterColumn,
           [OuterColumnUrl] = @OuterColumnUrl,
           [ColumnImgPath] = @ColumnImgPath,
           [Description] = @Description,
           [Keyword] = @Keyword,
           [Content] = @Content,
           [IsAllowAddInfo] = @IsAllowAddInfo,
           [ColumnTemplatePath] = @ColumnTemplatePath,
           [InfoTemplatePath] = @InfoTemplatePath,
           [CommentTemplatePath] = @CommentTemplatePath,
           [Sort] = @Sort,
           [IsAllowComment] = @IsAllowComment,
           [IsCheckComment] = @IsCheckComment,
           [InfoTableName] = @InfoTableName,
           [ScoreReward] = @ScoreReward,
           [PointCount] = @PointCount,
           [ChargeType] = @ChargeType,
           [ChargeHourCount] = @ChargeHourCount,
           [ChargeViewCount] = @ChargeViewCount,
           [IsOpened] = @IsOpened,
           [GroupIdStr] = @GroupIdStr,
           [ColumnPageType] = @ColumnPageType,
           [InfoPageType] = @InfoPageType,
           [IsParentHtml] = @IsParentHtml
    WHERE  [ColId] = @ColId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Vote]'
GO
CREATE TABLE [dbo].[Qianbo_Vote]
(
[VoteId] [int] NOT NULL IDENTITY(1, 1),
[SubjectId] [int] NULL,
[VoteTitle] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[DisplayType] [int] NULL CONSTRAINT [DF_Qianbo_Vote_DisplayType] DEFAULT ((1)),
[IsMore] [bit] NULL,
[ModelType] [int] NOT NULL CONSTRAINT [DF_Qianbo_Vote_ModelType] DEFAULT ((1)),
[ItemTitle1] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[ItemNum1] [int] NULL,
[ItemTitle2] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[ItemNum2] [int] NULL,
[ItemTitle3] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[ItemNum3] [int] NULL,
[ItemTitle4] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[ItemNum4] [int] NULL,
[ItemTitle5] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[ItemNum5] [int] NULL,
[ItemTitle6] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[ItemNum6] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Vote_1] on [dbo].[Qianbo_Vote]'
GO
ALTER TABLE [dbo].[Qianbo_Vote] ADD CONSTRAINT [PK_Qianbo_Vote_1] PRIMARY KEY CLUSTERED  ([VoteId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Vote_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_Vote_Update] @VoteId     INT,
                                          @VoteTitle  NVARCHAR(100),
                                          @IsMore     BIT,
                                          @ItemTitle1 NVARCHAR(100),
                                          @ItemNum1   INT,
                                          @ItemTitle2 NVARCHAR(100),
                                          @ItemNum2   INT,
                                          @ItemTitle3 NVARCHAR(100),
                                          @ItemNum3   INT,
                                          @ItemTitle4 NVARCHAR(100),
                                          @ItemNum4   INT,
                                          @ItemTitle5 NVARCHAR(100),
                                          @ItemNum5   INT,
                                          @ItemTitle6 NVARCHAR(100),
                                          @ItemNum6   INT
AS
    UPDATE Qianbo_Vote
    SET    [VoteTitle] = @VoteTitle,
           [IsMore] = @IsMore,
           [ItemTitle1] = @ItemTitle1,
           [ItemNum1] = @ItemNum1,
           [ItemTitle2] = @ItemTitle2,
           [ItemNum2] = @ItemNum2,
           [ItemTitle3] = @ItemTitle3,
           [ItemNum3] = @ItemNum3,
           [ItemTitle4] = @ItemTitle4,
           [ItemNum4] = @ItemNum4,
           [ItemTitle5] = @ItemTitle5,
           [ItemNum5] = @ItemNum5,
           [ItemTitle6] = @ItemTitle6,
           [ItemNum6] = @ItemNum6
    WHERE  [VoteId] = @VoteId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Tag_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_Tag_GetList] @currpage    INT,
                                          @pagesize    INT,
                                          @recordcount INT output
AS
    DECLARE @sqlstr NVARCHAR(4000)
    DECLARE @selectfield NVARCHAR(1000)
    DECLARE @selecttable NVARCHAR(1000)
    DECLARE @order NVARCHAR(500)
    SET @selectfield = ' a.tagid,tagname = a.name,tagcategoryname=isnull(b.name,''无类别''),a.modeltype,a.yesterdaysearchcount,a.daysearchcount,a.totalsearchcount,a.username,a.userid,c.modelname '
    SET @selecttable =' Qianbo_Tag a left join Qianbo_TagCategory b on a.tagcategoryid = b.tagcategoryid join Qianbo_Model c on a.modeltype = c.modelid '
    SET @order = ' order by totalsearchcount desc, tagid desc '
    IF( @currpage = 1 )
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + @selectfield + 'from' + @selecttable + @order
    ELSE
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + @selectfield + 'from' + @selecttable
                    + 'where a.tagid not in(select top '
                    + CONVERT(NVARCHAR(15), (@currpage - 1) * @pagesize)
                    + ' a.tagid from ' + @selecttable + @order + ')'
                    + @order
    EXECUTE sp_executesql
      @sqlstr
    SET @recordcount = (SELECT Count(tagid)
                        FROM   Qianbo_Tag)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Style]'
GO
CREATE TABLE [dbo].[Qianbo_Style]
(
[StyleID] [int] NOT NULL IDENTITY(1, 1),
[StyleCategoryId] [int] NULL,
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Content] [text] COLLATE Chinese_PRC_CI_AS NULL,
[Type] [int] NOT NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Style] on [dbo].[Qianbo_Style]'
GO
ALTER TABLE [dbo].[Qianbo_Style] ADD CONSTRAINT [PK_Qianbo_Style] PRIMARY KEY CLUSTERED  ([StyleID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_GetId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_GetId] @StyleId INT
AS
    SELECT [StyleCategoryId],
           [Name],
           [Content],
           [Type]
    FROM   Qianbo_Style
    WHERE  StyleId = @StyleId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Enterprise]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Enterprise]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[UserId] [int] NULL,
[TypeId] [int] NULL CONSTRAINT [DF_Qianbo_Enterprise_TypeId] DEFAULT ((0)),
[Title] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[Conetent] [text] COLLATE Chinese_PRC_CI_AS NULL,
[AddTime] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Enterprise] on [dbo].[Qianbo_Enterprise]'
GO
ALTER TABLE [dbo].[Qianbo_Enterprise] ADD CONSTRAINT [PK_Qianbo_Enterprise] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_EnterPrise_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_EnterPrise_Set] @Id       INT output,
                                             @UserId   INT,
                                             @Title    NVARCHAR(200),
                                             @Conetent TEXT,
                                             @AddTime  NVARCHAR(50),
                                             @TypeId   INT
AS
    IF( @Id = 0 )
      BEGIN
          INSERT INTO Qianbo_Enterprise
                      ([UserId],
                       [Title],
                       [Conetent],
                       [AddTime],
                       [TypeId])
          VALUES      ( @UserId,
                        @Title,
                        @Conetent,
                        @AddTime,
                        @TypeId )
          SET @Id = Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_Enterprise
          SET    [Title] = @Title,
                 [Conetent] = @Conetent,
                 [TypeId] = @TypeId
          WHERE  Id = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Link_Update]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Link_Update] @LinkId       INT,
                                          @LinkType     INT,
                                          @LinkCategory NVARCHAR(40),
                                          @SiteName     NVARCHAR(100),
                                          @SiteUrl      VARCHAR(255),
                                          @SiteLogo     VARCHAR(255),
                                          @OwnerName    NVARCHAR(100),
                                          @Email        NVARCHAR(100),
                                          @Description  NVARCHAR(400),
                                          @AddTime      DATETIME,
                                          @Status       INT,
                                          @IsDisable    BIT
AS
    UPDATE Qianbo_Link
    SET    [LinkType] = @LinkType,
           [LinkCategory] = @LinkCategory,
           [SiteName] = @SiteName,
           [SiteUrl] = @SiteUrl,
           [SiteLogo] = @SiteLogo,
           [OwnerName] = @OwnerName,
           [Email] = @Email,
           [Description] = @Description,
           [AddTime] = @AddTime,
           [Status] = @Status,
           [IsDisable] = @IsDisable
    WHERE  [LinkId] = @LinkId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Channel_Delete]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Channel_Delete] @chid INT
AS
    SET Xact_Abort ON
    BEGIN TRAN
    DECLARE @modeltype INT
    SET @modeltype=(SELECT ModelType
                    FROM   Qianbo_Channel
                    WHERE  ChId = @ChId);
    DECLARE @tablename NVARCHAR(50)
    SET @tablename = (SELECT TableName
                      FROM   Qianbo_Model
                      WHERE  ModelId = @ModelType)
    DECLARE @sqlstr NVARCHAR(2000)
    DECLARE @param NVARCHAR(500)
    SET @param = '@tchid int'
    SET @sqlstr = 'update i set i.[isdeleted] = 1 from ['
                  + @tablename
                  + '] i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid where ch.chid = @tchid';
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
    SET @sqlstr = 'update co set co.[isdeleted] = 1 from Qianbo_Column co join Qianbo_Channel ch on co.chid = ch.chid where ch.chid = @tchid'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
    SET @sqlstr = 'update ch set ch.[isdeleted] = 1 from Qianbo_Channel ch where ch.chid = @tchid';
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_UpdateHtml]'
GO
CREATE PROCEDURE [dbo].[Proc_Column_UpdateHtml] @ColId        INT,
                                                @IsUserHtml   BIT,
                                                @UserHtml     NTEXT,
                                                @IsSystemHtml BIT,
                                                @SystemHtml   NTEXT,
                                                @FieldOrder   NTEXT,
                                                @TypeId       NVARCHAR(20)
AS
    IF( @TypeId = '0' )
      UPDATE [Qianbo_Column]
      SET    [FieldOrder] = @FieldOrder
      WHERE  [ColId] = @ColId
    ELSE IF( @TypeId = '1' )
      UPDATE [Qianbo_Column]
      SET    [UserHtml] = @UserHtml,
             [IsUserHtml] = @IsUserHtml
      WHERE  [ColId] = @ColId
    ELSE IF( @TypeId = '2' )
      UPDATE [Qianbo_Column]
      SET    [SystemHtml] = @SystemHtml,
             [IsSystemHtml] = @IsSystemHtml
      WHERE  [ColId] = @ColId
    ELSE IF( @TypeId = '01' )
      UPDATE [Qianbo_Column]
      SET    [FieldOrder] = @FieldOrder,
             [UserHtml] = @UserHtml
      WHERE  [ColId] = @ColId
    ELSE IF( @TypeId = '02' )
      UPDATE [Qianbo_Column]
      SET    [FieldOrder] = @FieldOrder,
             [SystemHtml] = @SystemHtml
      WHERE  [ColId] = @ColId
    ELSE IF( @TypeId = '12' )
      UPDATE [Qianbo_Column]
      SET    [UserHtml] = @UserHtml,
             [SystemHtml] = @SystemHtml
      WHERE  [ColId] = @ColId
    ELSE IF( @TypeId = '012' )
      UPDATE [Qianbo_Column]
      SET    [FieldOrder] = @FieldOrder,
             [UserHtml] = @UserHtml,
             [SystemHtml] = @SystemHtml
      WHERE  [ColId] = @ColId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Tag_SetSearchCount]'
GO
CREATE PROC [dbo].[Proc_Tag_SetSearchCount] @tagName   NVARCHAR(20),
                                            @modeltype INT
AS
    UPDATE Qianbo_Tag
    SET    daysearchcount = daysearchcount + 1,
           totalsearchcount = totalsearchcount + 1
    WHERE  [name] = @tagname
           AND modeltype = @modeltype
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Log]'
GO
CREATE TABLE [dbo].[Qianbo_Log]
(
[LogId] [int] NOT NULL IDENTITY(1, 1),
[Description] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[UserId] [int] NULL,
[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[LogTime] [datetime] NULL,
[IpAddress] [varchar] (15) COLLATE Chinese_PRC_CI_AS NULL,
[LogType] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK__Qianbo_Log__7C8480AE] on [dbo].[Qianbo_Log]'
GO
ALTER TABLE [dbo].[Qianbo_Log] ADD CONSTRAINT [PK__Qianbo_Log__7C8480AE] PRIMARY KEY CLUSTERED  ([LogId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [idx_1] on [dbo].[Qianbo_Log]'
GO
CREATE NONCLUSTERED INDEX [idx_1] ON [dbo].[Qianbo_Log] ([LogTime], [UserId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Log_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Log_Add] @LogType     INT,
                                      @UserName    NVARCHAR(20),
                                      @UserId      INT,
                                      @Description NVARCHAR(100),
                                      @IpAddress   VARCHAR(15),
                                      @LogTime     DATETIME
AS
    INSERT INTO Qianbo_Log
                (LogType,
                 UserName,
                 UserId,
                 Description,
                 IpAddress,
                 LogTime)
    VALUES      (@LogType,
                 @UserName,
                 @UserId,
                 @Description,
                 @IpAddress,
                 @LogTime)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_Update_Template]'
GO
CREATE PROCEDURE [dbo].[Proc_Column_Update_Template] @ColId               INT output,
                                                     @ColumnTemplatePath  NVARCHAR(510),
                                                     @InfoTemplatePath    NVARCHAR(510),
                                                     @CommentTemplatePath NVARCHAR(510)
AS
    UPDATE Qianbo_Column
    SET    [ColumnTemplatePath] = ( CASE @ColumnTemplatePath
                                      WHEN '' THEN [ColumnTemplatePath]
                                      ELSE @ColumnTemplatePath
                                    END ),
           [InfoTemplatePath] = ( CASE @InfoTemplatePath
                                    WHEN '' THEN [InfoTemplatePath]
                                    ELSE @InfoTemplatePath
                                  END ),
           [CommentTemplatePath] = ( CASE @CommentTemplatePath
                                       WHEN '' THEN [CommentTemplatePath]
                                       ELSE @CommentTemplatePath
                                     END )
    WHERE  [ColId] = @ColId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_TempTable]'
GO
CREATE TABLE [dbo].[Qianbo_TempTable]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ChId] [int] NOT NULL,
[ColId] [int] NOT NULL,
[Title] [nvarchar] (400) COLLATE Chinese_PRC_CI_AS NULL,
[TitleColor] [nvarchar] (12) COLLATE Chinese_PRC_CI_AS NULL,
[TitleFontType] [int] NULL,
[TitleType] [int] NULL,
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL,
[UId] [int] NOT NULL,
[UName] [nvarchar] (40) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UserType] [int] NOT NULL,
[AdminUId] [int] NULL,
[AdminUName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Status] [int] NULL,
[HitCount] [int] NULL,
[AddTime] [datetime] NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[PageType] [int] NULL,
[IsCreated] [bit] NULL,
[UserCateId] [int] NULL,
[PointCount] [int] NULL,
[ChargeType] [int] NULL,
[ChargeHourCount] [int] NULL,
[ChargeViewCount] [int] NULL,
[IsOpened] [int] NULL,
[OuterUrl] [nvarchar] (600) COLLATE Chinese_PRC_CI_AS NULL,
[GroupIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[IsDeleted] [bit] NULL,
[IsRecommend] [bit] NULL,
[IsTop] [bit] NULL,
[IsFocus] [bit] NULL,
[IsSideShow] [bit] NULL,
[TagIdStr] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL,
[TagNameStr] [nvarchar] (600) COLLATE Chinese_PRC_CI_AS NULL,
[IsAllowComment] [bit] NULL,
[SpecialIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[ViewUName] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[ViewUName2] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[ExtendContentTable] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[InputDateOuthor] [int] NULL,
[SubSiteId] [int] NULL,
[IsSend] [bit] NULL,
[SendTime] [datetime] NULL,
[InfoId] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTablePage_GetList]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROC [dbo].[Proc_TempTablePage_GetList] @pageIndex   INT,
                                               @pageSize    INT,
                                               @recordCount INT output
AS
    DECLARE @sqlStr NVARCHAR(2000)
    IF( @pageIndex = 1 )
      SET @sqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @pageSize)
                  + ' * from Qianbo_TempTable where issend = 0 order by id desc'
    ELSE
      SET @sqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @pageSize)
                  + ' * from Qianbo_TempTable where id < (select min(id) from (select top '
                  + CONVERT(NVARCHAR(15), (@pageIndex-1) * @pageSize)
                  + ' id from Qianbo_TempTable order by id desc)o) and  issend = 0 order by id desc'
    EXECUTE Sp_ExecuteSql
      @sqlStr
    SET @recordCount=(SELECT Count(id)
                      FROM   Qianbo_TempTable
                      WHERE  issend = 0)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_WebMessage]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_WebMessage]
(
[WMId] [int] NOT NULL IDENTITY(1, 1),
[ReceiverId] [int] NULL,
[ReceiverName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[SendId] [int] NULL,
[SendName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Title] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[IsSend] [int] NULL CONSTRAINT [DF_Qianbo_WebMessage_IsSend] DEFAULT ((0)),
[IsRead] [int] NULL CONSTRAINT [DF_Qianbo_WebMessage_IsRead] DEFAULT ((0)),
[ReceiverDel] [int] NULL CONSTRAINT [DF_Qianbo_WebMessage_IsDel] DEFAULT ((0)),
[SendDel] [int] NULL,
[AllUser] [int] NULL CONSTRAINT [DF_Qianbo_WebMessage_AllUser] DEFAULT ((0)),
[UserGroupId] [int] NULL CONSTRAINT [DF_Qianbo_WebMessage_UserGroupId] DEFAULT ((0)),
[OverdueDate] [datetime] NULL,
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_WebMessage] on [dbo].[Qianbo_WebMessage]'
GO
ALTER TABLE [dbo].[Qianbo_WebMessage] ADD CONSTRAINT [PK_Qianbo_WebMessage] PRIMARY KEY CLUSTERED  ([WMId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_WebMessage]'
GO
CREATE PROCEDURE [dbo].[Proc_WebMessage] @WMId               INT=0,
                                         @ReceiverId         INT=0,
                                         @ReceiverName       NVARCHAR(50)=" ",
                                         @SendId             INT=0,
                                         @SendName           NVARCHAR(50)=" ",
                                         @Title              NVARCHAR(150)=" ",
                                         @Content            NTEXT=" ",
                                         @IsSend             INT=0,
                                         @IsRead             INT=0,
                                         @ReceiverDel        INT=0,
                                         @SendDel            INT=0,
                                         @ReceiverRecycleDel INT=0,
                                         @SendRecycleDel     INT=0,
                                         @AllUser            INT=0,
                                         @UserGroupId        INT=0,
                                         @AddDate            DATETIME=" ",
                                         @OverdueDate        DATETIME=" ",
                                         @WhereStr           NVARCHAR(100)=" "
AS
    INSERT INTO [Qianbo_WebMessage]
                (ReceiverId,
                 ReceiverName,
                 SendId,
                 SendName,
                 Title,
                 Content,
                 IsSend,
                 IsRead,
                 ReceiverDel,
                 SendDel,
                 AllUser,
                 UserGroupId,
                 OverdueDate,
                 AddDate)
    VALUES      (@ReceiverId,
                 @ReceiverName,
                 @SendId,
                 @SendName,
                 @Title,
                 @Content,
                 @IsSend,
                 @IsRead,
                 @ReceiverDel,
                 @SendDel,
                 @AllUser,
                 @UserGroupId,
                 @OverdueDate,
                 @AddDate)
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Log_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_Log_Delete] @LogTime DATETIME
AS
    DELETE FROM Qianbo_Log
    WHERE  LogTime < @LogTime
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_GetList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_GetList] @StyleCategoryId INT
AS
    SELECT StyleID,
           [Name],
           Content,
           Type
    FROM   Qianbo_Style
    WHERE  StyleCategoryId = @StyleCategoryId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Channel_GetAll]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Channel_GetAll]
AS
    SELECT *
    FROM   Qianbo_Channel a,
           Qianbo_Model b
    WHERE  a.ModelType = b.ModelId
    ORDER  BY ModelType,
              Sort ASC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_ListStyleContent]'
GO
CREATE TABLE [dbo].[Qianbo_ListStyleContent]
(
[ModelId] [int] NOT NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ListStyleContent_Content] DEFAULT ('')
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_ListStyleContent] on [dbo].[Qianbo_ListStyleContent]'
GO
ALTER TABLE [dbo].[Qianbo_ListStyleContent] ADD CONSTRAINT [PK_Qianbo_ListStyleContent] PRIMARY KEY CLUSTERED  ([ModelId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_GetSearchStyle]'
GO
CREATE PROC [dbo].[Proc_Style_GetSearchStyle] @modelid INT
AS
    SELECT *
    FROM   Qianbo_ListStyleContent
    WHERE  modelid = @modelid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Admin_Add] @LogName         NVARCHAR(20),
                                        @UserName        NVARCHAR(20),
                                        @Password        VARCHAR(200),
                                        @GroupId         INT,
                                        @GroupName       NVARCHAR(50),
                                        @AllowMultiLogin BIT,
                                        @SiteId          INT,
                                        @Contact         NVARCHAR(150),
                                        @Locked          BIT,
                                        @IsSiteManage    INT,
                                        @output          BIT output
AS
    IF EXISTS(SELECT *
              FROM   Qianbo_Admin
              WHERE  LoginName = @LogName
                      OR UserName = @UserName)
      SET @output=0
    ELSE
      BEGIN
          INSERT INTO Qianbo_Admin
                      (LoginName,
                       UserName,
                       Password,
                       GroupId,
                       GroupName,
                       AllowMultiLogin,
                       SiteId,
                       Contact,
                       Locked,
                       IsSiteManage)
          VALUES      (@LogName,
                       @UserName,
                       @Password,
                       @GroupId,
                       @GroupName,
                       @AllowMultiLogin,
                       @SiteId,
                       @Contact,
                       @Locked,
                       @IsSiteManage)
          SET @output=1
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Controller]'
GO
CREATE TABLE [dbo].[Qianbo_Controller]
(
[ControllerId] [int] NOT NULL IDENTITY(1, 1),
[ControllerName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[LinkURI] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL,
[OrderNum] [int] NULL,
[UserId] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Controller] on [dbo].[Qianbo_Controller]'
GO
ALTER TABLE [dbo].[Qianbo_Controller] ADD CONSTRAINT [PK_Qianbo_Controller] PRIMARY KEY CLUSTERED  ([ControllerId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Controller_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_Controller_Delete] @ControllerId INT,
                                                @UserId       INT
AS
    DELETE FROM Qianbo_Controller
    WHERE  ControllerId = @ControllerId
           AND UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_UpdateRegCode]'
GO
CREATE PROCEDURE [dbo].[Proc_User_UpdateRegCode] @UserId  INT,
                                                 @NewCode VARCHAR(50)
AS
    UPDATE Qianbo_Users
    SET    ConfirmRegCode = @NewCode
    WHERE  UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTableSimple_Delete]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_TempTableSimple_Delete] @Id INT
AS
    DELETE Qianbo_TempTable
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Controller_GetList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Controller_GetList] @UserId INT
AS
    IF NOT EXISTS(SELECT *
                  FROM   Qianbo_Controller
                  WHERE  UserId = @UserId)
      BEGIN
          INSERT INTO Qianbo_Controller
                      (ControllerName,
                       LinkURI,
                       OrderNum,
                       UserId)
          SELECT ControllerName,
                 LinkURI,
                 OrderNum,
                 @UserId
          FROM   Qianbo_Controller
          WHERE  UserId = 0
      END
    SELECT *
    FROM   Qianbo_Controller
    WHERE  UserId = @UserId
    ORDER  BY OrderNum ASC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_WorkFlow]'
GO
CREATE TABLE [dbo].[Qianbo_WorkFlow]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL,
[Auditing] [int] NULL,
[PowerIdStr] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[AddDate] [datetime] NULL,
[UpdateDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_AuditingFlow] on [dbo].[Qianbo_WorkFlow]'
GO
ALTER TABLE [dbo].[Qianbo_WorkFlow] ADD CONSTRAINT [PK_Qianbo_AuditingFlow] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_WorkFlow_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_WorkFlow_Add] @Name       NVARCHAR(150),
                                           @Auditing   INT,
                                           @AddDate    DATETIME,
                                           @UpdateDate DATETIME,
                                           @PowerIdStr NTEXT
AS
    INSERT INTO [Qianbo_WorkFlow]
                ([Name],
                 [Auditing],
                 [AddDate],
                 [UpdateDate],
                 [PowerIdStr])
    VALUES      (@Name,
                 @Auditing,
                 @AddDate,
                 @UpdateDate,
                 @PowerIdStr)
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTable_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_TempTable_Add] @ChId               INT,
                                            @ColId              INT,
                                            @Title              NVARCHAR(200),
                                            @TitleColor         NVARCHAR(6),
                                            @TitleFontType      INT,
                                            @TitleType          INT,
                                            @TitleImgPath       VARCHAR(255),
                                            @UId                INT,
                                            @UName              NVARCHAR(20),
                                            @UserType           INT,
                                            @AdminUId           INT,
                                            @AdminUName         NVARCHAR(50),
                                            @Status             INT,
                                            @HitCount           INT,
                                            @AddTime            DATETIME,
                                            @UpdateTime         DATETIME,
                                            @TemplatePath       VARCHAR(255),
                                            @PageType           INT,
                                            @IsCreated          BIT,
                                            @UserCateId         INT,
                                            @PointCount         INT,
                                            @ChargeType         INT,
                                            @ChargeHourCount    INT,
                                            @ChargeViewCount    INT,
                                            @IsOpened           INT,
                                            @OuterUrl           NVARCHAR(300),
                                            @GroupIdStr         VARCHAR(200),
                                            @IsDeleted          BIT,
                                            @IsRecommend        BIT,
                                            @IsTop              BIT,
                                            @IsFocus            BIT,
                                            @IsSideShow         BIT,
                                            @TagIdStr           VARCHAR(300),
                                            @TagNameStr         NVARCHAR(300),
                                            @IsAllowComment     BIT,
                                            @SpecialIdStr       VARCHAR(200),
                                            @ViewUName          NTEXT,
                                            @ViewUName2         NTEXT,
                                            @ExtendContentTable NVARCHAR(50),
                                            @InputDateOuthor    INT,
                                            @SubSiteId          INT,
                                            @IsSend             BIT,
                                            @SendTime           DATETIME,
                                            @InfoId             INT
AS
    INSERT INTO Qianbo_TempTable
                ([ChId],
                 [ColId],
                 [Title],
                 [TitleColor],
                 [TitleFontType],
                 [TitleType],
                 [TitleImgPath],
                 [UId],
                 [UName],
                 [UserType],
                 [AdminUId],
                 [AdminUName],
                 [Status],
                 [HitCount],
                 [AddTime],
                 [UpdateTime],
                 [TemplatePath],
                 [PageType],
                 [IsCreated],
                 [UserCateId],
                 [PointCount],
                 [ChargeType],
                 [ChargeHourCount],
                 [ChargeViewCount],
                 [IsOpened],
                 [OuterUrl],
                 [GroupIdStr],
                 [IsDeleted],
                 [IsRecommend],
                 [IsTop],
                 [IsFocus],
                 [IsSideShow],
                 [TagIdStr],
                 [TagNameStr],
                 [IsAllowComment],
                 [SpecialIdStr],
                 [ViewUName],
                 [ViewUName2],
                 [ExtendContentTable],
                 [InputDateOuthor],
                 [SubSiteId],
                 [IsSend],
                 [SendTime],
                 [InfoId])
    VALUES      ( @ChId,
                  @ColId,
                  @Title,
                  @TitleColor,
                  @TitleFontType,
                  @TitleType,
                  @TitleImgPath,
                  @UId,
                  @UName,
                  @UserType,
                  @AdminUId,
                  @AdminUName,
                  @Status,
                  @HitCount,
                  @AddTime,
                  @UpdateTime,
                  @TemplatePath,
                  @PageType,
                  @IsCreated,
                  @UserCateId,
                  @PointCount,
                  @ChargeType,
                  @ChargeHourCount,
                  @ChargeViewCount,
                  @IsOpened,
                  @OuterUrl,
                  @GroupIdStr,
                  @IsDeleted,
                  @IsRecommend,
                  @IsTop,
                  @IsFocus,
                  @IsSideShow,
                  @TagIdStr,
                  @TagNameStr,
                  @IsAllowComment,
                  @SpecialIdStr,
                  @ViewUName,
                  @ViewUName2,
                  @ExtendContentTable,
                  @InputDateOuthor,
                  @SubSiteId,
                  @IsSend,
                  @SendTime,
                  @InfoId )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_StyleIDGetStylegoryId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_StyleIDGetStylegoryId] @StyleID INT
AS
    SELECT [StyleID],
           [StyleCategoryId]
    FROM   Qianbo_Style
    WHERE  [StyleID] = @StyleID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_ModelField]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_ModelField]
(
[FieldId] [int] NOT NULL IDENTITY(1, 1),
[ModelId] [int] NULL,
[ColId] [int] NULL CONSTRAINT [DF_Qianbo_ModelField_ColId_1] DEFAULT ((0)),
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Alias] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL,
[Description] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[IsNotNull] [bit] NULL,
[IsSearchForm] [bit] NULL,
[Type] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[OrderId] [int] NULL CONSTRAINT [DF_Qianbo_ModelField_OrderId] DEFAULT ((0)),
[IsChild] [bit] NULL CONSTRAINT [DF_Qianbo_ModelField_IsChild_1] DEFAULT ((0)),
[IsList] [bit] NULL CONSTRAINT [DF_Qianbo_ModelField_IsList_1] DEFAULT ((0)),
[IsUserInsert] [bit] NULL CONSTRAINT [DF_Qianbo_ModelField_IsUserInsert_1] DEFAULT ((0)),
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_ModelField] on [dbo].[Qianbo_ModelField]'
GO
ALTER TABLE [dbo].[Qianbo_ModelField] ADD CONSTRAINT [PK_Qianbo_ModelField] PRIMARY KEY CLUSTERED  ([FieldId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_Add] @ModelId      INT,
                                             @Name         NVARCHAR(100),
                                             @Alias        NVARCHAR(300),
                                             @Description  NVARCHAR(400),
                                             @IsNotNull    BIT,
                                             @IsSearchForm BIT,
                                             @Type         NVARCHAR(100),
                                             @Content      NTEXT,
                                             @AddDate      DATETIME,
                                             @ColId        INT,
                                             @IsChild      BIT,
                                             @IsList       BIT,
                                             @IsUserInsert BIT
AS
    DECLARE @OrderId INT;
    SET @OrderId=(SELECT Max(OrderId)
                  FROM   [Qianbo_ModelField]
                  WHERE  ModelId = @ModelId)
    IF @OrderId IS NULL
      SET @OrderId=0
    ELSE
      SET @OrderId = @OrderId + 1
    INSERT INTO [Qianbo_ModelField]
                ([ModelId],
                 [Name],
                 [Alias],
                 [Description],
                 [IsNotNull],
                 [IsSearchForm],
                 [Type],
                 [Content],
                 [AddDate],
                 [OrderId],
                 [ColId],
                 [IsList],
                 [IsUserInsert],
                 [IsChild])
    VALUES      (@ModelId,
                 @Name,
                 @Alias,
                 @Description,
                 @IsNotNull,
                 @IsSearchForm,
                 @Type,
                 @Content,
                 @AddDate,
                 @OrderId,
                 @ColId,
                 @IsList,
                 @IsUserInsert,
                 @IsChild)
    SELECT Scope_identity()
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Channel_SetDisaled]'
GO
CREATE PROCEDURE [dbo].[Proc_Channel_SetDisaled] @ChId       INT,
                                                 @IsDisabled BIT
AS
    UPDATE Qianbo_Channel
    SET    IsDisabled = @IsDisabled
    WHERE  ChId = @ChId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Controller_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_Controller_Set] @ControllerId   INT,
                                             @ControllerName NVARCHAR(50),
                                             @LinkURI        VARCHAR(255),
                                             @OrderNum       INT,
                                             @UserId         INT
AS
    IF( @ControllerId = 0 )
      BEGIN
          INSERT INTO Qianbo_Controller
                      (ControllerName,
                       LinkURI,
                       OrderNum,
                       UserId)
          VALUES      (@ControllerName,
                       @LinkURI,
                       @OrderNum,
                       @UserId)
      END
    ELSE
      BEGIN
          UPDATE Qianbo_Controller
          SET    ControllerName = @ControllerName,
                 LinkURI = @LinkURI,
                 OrderNum = @OrderNum
          WHERE  ControllerId = @ControllerId
                 AND UserId = @UserId
                 AND UserId != 0
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_WorkFlow_Delete]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_WorkFlow_Delete] @Id INT
AS
    DELETE Qianbo_WorkFlow
    WHERE  Id = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Controller_Set_Default]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Controller_Set_Default] @UserId INT
AS
    DELETE FROM Qianbo_Controller
    WHERE  UserId = @UserId
           AND UserId != 0
    INSERT INTO Qianbo_Controller
                (ControllerName,
                 LinkURI,
                 OrderNum,
                 UserId)
    SELECT ControllerName,
           LinkURI,
           OrderNum,
           @UserId
    FROM   Qianbo_Controller
    WHERE  UserId = 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_Update]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_Update] @StyleID         INT,
                                           @StyleCategoryId INT,
                                           @Name            NVARCHAR(100),
                                           @Content         TEXT,
                                           @Type            INT
AS
    UPDATE Qianbo_Style
    SET    [StyleCategoryId] = @StyleCategoryId,
           [Name] = @Name,
           [Content] = @Content,
           [Type] = @Type
    WHERE  [StyleID] = @StyleID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTable_Exists]'
GO
CREATE PROCEDURE [dbo].[Proc_TempTable_Exists] @outUrl NVARCHAR(500)
AS
    SELECT [id]
    FROM   Qianbo_TempTable
    WHERE  [OuterUrl] = @outUrl
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Channel_Update]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Channel_Update] @ChId                INT,
                                             @ChName              NVARCHAR(50),
                                             @Description         NVARCHAR(255),
                                             @TemplatePath        NVARCHAR(255),
                                             @IsChildSite         BIT,
                                             @ChildSiteUrl        NVARCHAR(255),
                                             @IsOpenLink          BIT,
                                             @ModelType           INT,
                                             @DirName             NVARCHAR(50),
                                             @TypeName            NVARCHAR(10),
                                             @TypeUnit            NVARCHAR(10),
                                             @IsDisabled          BIT,
                                             @IsOpened            BIT,
                                             @GroupIdStr          VARCHAR(500),
                                             @VerifyType          INT,
                                             @Notice1             NVARCHAR(500),
                                             @Notice2             NVARCHAR(500),
                                             @Keyword             NVARCHAR(100),
                                             @Content             NVARCHAR(300),
                                             @MiniHitCount        INT,
                                             @IsStaticType        BIT,
                                             @ColumnSortType      INT,
                                             @InfoSortType        INT,
                                             @FileNameType        INT,
                                             @ChannelPageType     INT,
                                             @ColumnPageType      INT,
                                             @InfoPageType        INT,
                                             @Sort                INT,
                                             @ColumnTemplatePath  NVARCHAR(255),
                                             @InfoTemplatePath    NVARCHAR(255),
                                             @CommentTemplatePath NVARCHAR(255),
                                             @ChType              INT
AS
    UPDATE Qianbo_Channel
    SET    [ChName] = @ChName,
           [Description] = @Description,
           [TemplatePath] = @TemplatePath,
           [IsChildSite] = @IsChildSite,
           [ChildSiteUrl] = @ChildSiteUrl,
           [IsOpenLink] = @IsOpenLink,
           [ModelType] = @ModelType,
           [DirName] = @DirName,
           [TypeName] = @TypeName,
           [TypeUnit] = @TypeUnit,
           [IsDisabled] = @IsDisabled,
           [IsOpened] = @IsOpened,
           [GroupIdStr] = @GroupIdStr,
           [VerifyType] = @VerifyType,
           [Notice1] = @Notice1,
           [Notice2] = @Notice2,
           [Keyword] = @Keyword,
           [Content] = @Content,
           [MiniHitCount] = @MiniHitCount,
           [IsStaticType] = @IsStaticType,
           [ColumnSortType] = @ColumnSortType,
           [InfoSortType] = @InfoSortType,
           [FileNameType] = @FileNameType,
           [ChannelPageType] = @ChannelPageType,
           [ColumnPageType] = @ColumnPageType,
           [InfoPageType] = @InfoPageType,
           [Sort] = @Sort,
           [ColumnTemplatePath] = @ColumnTemplatePath,
           [InfoTemplatePath] = @InfoTemplatePath,
           [CommentTemplatePath] = @CommentTemplatePath,
           [ChType] = @ChType
    WHERE  [ChId] = @ChId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_Del]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_Del] @FieldId INT
AS
    DELETE FROM [Qianbo_ModelField]
    WHERE  FieldId = @FieldId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_UpdateModelId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_UpdateModelId] @oldmodelid INT,
                                                  @newmodelid INT
AS
    UPDATE Qianbo_Style
    SET    Type = @newmodelid
    WHERE  Type = @oldmodelid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTable_IsSend]'
GO
CREATE PROCEDURE [dbo].[Proc_TempTable_IsSend] (@subsiteid INT,
                                                @colid     INT,
                                                @infoid    INT)
AS
    SELECT id
    FROM   Qianbo_TempTable
    WHERE  infoid = @infoid
           AND colid = @colid
           AND subsiteid = @subsiteid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_CountDay]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_CountDay]
(
[0] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_0] DEFAULT ((0)),
[1] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_1] DEFAULT ((0)),
[2] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_2] DEFAULT ((0)),
[3] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_3] DEFAULT ((0)),
[4] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_4] DEFAULT ((0)),
[5] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_5] DEFAULT ((0)),
[6] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_6] DEFAULT ((0)),
[7] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_7] DEFAULT ((0)),
[8] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_8] DEFAULT ((0)),
[9] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_9] DEFAULT ((0)),
[10] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_10] DEFAULT ((0)),
[11] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_11] DEFAULT ((0)),
[12] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_12] DEFAULT ((0)),
[13] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_13] DEFAULT ((0)),
[14] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_14] DEFAULT ((0)),
[15] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_15] DEFAULT ((0)),
[16] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_16] DEFAULT ((0)),
[17] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_17] DEFAULT ((0)),
[18] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_18] DEFAULT ((0)),
[19] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_19] DEFAULT ((0)),
[20] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_20] DEFAULT ((0)),
[21] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_21] DEFAULT ((0)),
[22] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_22] DEFAULT ((0)),
[23] [int] NULL CONSTRAINT [DF_Qianbo_CountDay_23] DEFAULT ((0)),
[Flag] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsCount_AddDayCount]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsCount_AddDayCount] @CurrHour VARCHAR(2),
                                                   @CurrDay  VARCHAR(10)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF EXISTS(SELECT *
              FROM   Qianbo_CountDay
              WHERE  Flag = @CurrDay)
      SET @SqlStr = N'update Qianbo_CountDay set [' + @CurrHour
                    + '] = [' + @CurrHour + '] + 1  where Flag = '''
                    + @CurrDay + '''';
    ELSE
      SET @SqlStr = N'insert into Qianbo_CountDay (['
                    + @CurrHour + '],Flag)values(1,''' + @CurrDay
                    + ''')';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'update Qianbo_CountDay set [' + @CurrHour
                  + '] = [' + @CurrHour
                  + '] + 1 where Flag = ''Total''';
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetList] @ModelId INT
AS
    SELECT *
    FROM   [Qianbo_ModelField]
    WHERE  ModelId = @ModelId
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_WorkFlow_GetModel]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_WorkFlow_GetModel] @Id INT
AS
    SELECT *
    FROM   Qianbo_WorkFlow
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetList_Col]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetList_Col] @ModelId  INT,
                                                     @ColIdStr NVARCHAR(3500)
AS
    SELECT *
    FROM   [Qianbo_ModelField]
    WHERE  ( ModelId = @ModelId
             AND [ColId] = 0 )
            OR ( Charindex(',' + CONVERT(VARCHAR, ColId) + ',', ',' + @ColIdStr + ',') > 0
                 AND IsChild = 1 )
    ORDER  BY OrderId,
              FieldId;
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_UpdateSearchStyle]'
GO
CREATE PROCEDURE [dbo].[Proc_Style_UpdateSearchStyle] @modelId INT,
                                                      @content NTEXT
AS
    UPDATE Qianbo_ListStyleContent
    SET    Content = @content
    WHERE  ModelId = @modelId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_GetSpecials]'
GO
CREATE PROCEDURE [dbo].[Proc_Special_GetSpecials] (@SelectType INT,
                                                   @ParentId   INT)
AS
    IF @SelectType = 0
      BEGIN
          SELECT Qianbo_Special.*,
                 Qianbo_Channel.ChName
          FROM   Qianbo_Special
                 LEFT JOIN Qianbo_Channel
                        ON Qianbo_Special.SiteID = Qianbo_Channel.ChId
          WHERE  Qianbo_Special.parentId = 0
                 AND Qianbo_Special.IsDeleted = 0
          ORDER  BY Qianbo_Special.SiteID
      END
    IF @SelectType = 1
      BEGIN
          SELECT Qianbo_Special.*,
                 Qianbo_Channel.ChName
          FROM   Qianbo_Special
                 LEFT JOIN Qianbo_Channel
                        ON Qianbo_Special.SiteID = Qianbo_Channel.ChId
          WHERE  parentId = @ParentId
                 AND Qianbo_Special.IsDeleted = 0
          ORDER  BY Qianbo_Special.SiteID
      END
    IF @SelectType = 2
      BEGIN
          SELECT Qianbo_Special.*
          FROM   Qianbo_Special
                 LEFT JOIN Qianbo_Channel
                        ON Qianbo_Special.SiteID = Qianbo_Channel.ChId
          WHERE  Qianbo_Special.IsLock = 0
                 AND Qianbo_Special.IsDeleted = 0
          ORDER  BY ID
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UpdateMoney]'
GO
CREATE PROCEDURE [dbo].[Proc_UpdateMoney] @Value  DECIMAL,
                                          @UserID INT,
                                          @TypeId INT
AS
    IF @TypeId = 1
      BEGIN
          UPDATE [Qianbo_Users]
          SET    YellowBoy = YellowBoy + @Value
          WHERE  UserID = @UserID
      END
    IF @TypeId = 2
      BEGIN
          UPDATE [Qianbo_Users]
          SET    Integral = Integral + @Value
          WHERE  UserID = @UserID
      END
    IF @TypeId = 3
      BEGIN
          UPDATE [Qianbo_Users]
          SET    ExpireTime = Dateadd([day], @Value, ExpireTime)
          WHERE  UserID = @UserID
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_CountMonth]'
GO
CREATE TABLE [dbo].[Qianbo_CountMonth]
(
[1] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_1] DEFAULT ((0)),
[2] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_2] DEFAULT ((0)),
[3] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_3] DEFAULT ((0)),
[4] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_4] DEFAULT ((0)),
[5] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_5] DEFAULT ((0)),
[6] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_6] DEFAULT ((0)),
[7] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_7] DEFAULT ((0)),
[8] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_8] DEFAULT ((0)),
[9] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_9] DEFAULT ((0)),
[10] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_10] DEFAULT ((0)),
[11] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_11] DEFAULT ((0)),
[12] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_12] DEFAULT ((0)),
[13] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_13] DEFAULT ((0)),
[14] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_14] DEFAULT ((0)),
[15] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_15] DEFAULT ((0)),
[16] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_16] DEFAULT ((0)),
[17] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_17] DEFAULT ((0)),
[18] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_18] DEFAULT ((0)),
[19] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_19] DEFAULT ((0)),
[20] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_20] DEFAULT ((0)),
[21] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_21] DEFAULT ((0)),
[22] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_22] DEFAULT ((0)),
[23] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_23] DEFAULT ((0)),
[24] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_24] DEFAULT ((0)),
[25] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_25] DEFAULT ((0)),
[26] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_26] DEFAULT ((0)),
[27] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_27] DEFAULT ((0)),
[28] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_28] DEFAULT ((0)),
[29] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_29] DEFAULT ((0)),
[30] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_30] DEFAULT ((0)),
[31] [int] NULL CONSTRAINT [DF_Qianbo_CountMonth_31] DEFAULT ((0)),
[Flag] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsCount_AddMonthCount]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsCount_AddMonthCount] @CurrDay   VARCHAR(2),
                                                     @CurrMonth VARCHAR(7)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF EXISTS(SELECT *
              FROM   Qianbo_CountMonth
              WHERE  Flag = @CurrMonth)
      SET @SqlStr = N'update Qianbo_CountMonth set ['
                    + @CurrDay + '] = [' + @CurrDay
                    + '] + 1  where Flag = ''' + @CurrMonth + '''';
    ELSE
      SET @SqlStr = N'insert into Qianbo_CountMonth (['
                    + @CurrDay + '],Flag)values(1,''' + @CurrMonth
                    + ''')';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'update Qianbo_CountMonth set ['
                  + @CurrDay + '] = [' + @CurrDay
                  + '] + 1 where Flag = ''Total''';
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_FeedBack_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_FeedBack_Delete] @FeedBackId INT
AS
    SET Xact_Abort ON
    BEGIN TRAN
    DELETE FROM Qianbo_FeedBack
    WHERE  [ID] = @FeedBackId
    IF EXISTS(SELECT Id
              FROM   Qianbo_FeedBack
              WHERE  parentId = @FeedBackId)
      DELETE FROM Qianbo_FeedBack
      WHERE  parentId = @FeedBackId
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetList_FieldOrder]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetList_FieldOrder] @FieldOrder NVARCHAR(2000)
AS
    SELECT *
    FROM   [Qianbo_ModelField]
    WHERE  Charindex(',' + CONVERT(VARCHAR, FieldId) + ',', ',' + @FieldOrder + ',') > 0
    ORDER  BY OrderId,
              FieldId;
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_WorkFlow_Update]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_WorkFlow_Update] @Id         INT,
                                              @Name       NVARCHAR(150),
                                              @Auditing   INT,
                                              @UpdateDate DATETIME,
                                              @PowerIdStr NTEXT
AS
    UPDATE [Qianbo_WorkFlow]
    SET    [Name] = @Name,
           [Auditing] = @Auditing,
           [UpdateDate] = @UpdateDate,
           [PowerIdStr] = @PowerIdStr
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_Update]'
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Admin_Update] @UserId          INT,
                                      @Password        VARCHAR(200),
                                      @AllowMultiLogin BIT,
                                      @GroupId         INT,
                                      @GroupName       NVARCHAR(50),
                                      @UserName        NVARCHAR(50),
                                      @SiteId          INT,
                                      @Contact         NVARCHAR(150),
                                      @Locked          BIT,
                                      @IsSiteManage    INT
AS
    UPDATE Qianbo_Admin
    SET    [Password] = ( CASE @Password
                            WHEN '' THEN [Password]
                            ELSE @Password
                          END ),
           AllowMultiLogin = @AllowMultiLogin,
           GroupId = @GroupId,
           GroupName = @GroupName,
           UserName = @UserName,
           SiteId = @SiteId,
           Contact = @Contact,
           Locked = @Locked,
           IsSiteManage = @IsSiteManage
    WHERE  UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserPhoto]'
GO
CREATE TABLE [dbo].[Qianbo_UserPhoto]
(
[PhotoId] [int] NOT NULL IDENTITY(1, 1),
[AlbumId] [int] NOT NULL,
[FileName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[FilePath] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Description] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[PostTime] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[VisitNum] [int] NULL CONSTRAINT [DF_Qianbo_UserPhoto_VisitNum] DEFAULT ((0)),
[UserId] [int] NULL,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[FileSize] [int] NULL CONSTRAINT [DF_Qianbo_UserPhoto_FileSize] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_User_Photo] on [dbo].[Qianbo_UserPhoto]'
GO
ALTER TABLE [dbo].[Qianbo_UserPhoto] ADD CONSTRAINT [PK_Qianbo_User_Photo] PRIMARY KEY CLUSTERED  ([PhotoId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserAlbum]'
GO
CREATE TABLE [dbo].[Qianbo_UserAlbum]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[AlbumName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[AlbumCate] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[AlbumDescription] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[ImgCount] [int] NULL,
[Logo] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[IsOpened] [int] NULL,
[AlbumPassword] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[AddTime] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[UserId] [int] NULL,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserAlbum] on [dbo].[Qianbo_UserAlbum]'
GO
ALTER TABLE [dbo].[Qianbo_UserAlbum] ADD CONSTRAINT [PK_Qianbo_UserAlbum] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserAlbum_Delete]'
GO
CREATE PROC [dbo].[Proc_UserAlbum_Delete] @Id     INT,
                                          @UserId INT
AS
    DELETE Qianbo_UserAlbum
    WHERE  Id = @Id
           AND userId = @UserId
    DELETE Qianbo_UserPhoto
    WHERE  AlbumId = @Id
           AND userId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_ModifyOtherBasicInfo]'
GO
CREATE PROC [dbo].[Proc_Users_ModifyOtherBasicInfo] @userid  INT,
                                                    @email   VARCHAR(100),
                                                    @groupid INT,
                                                    @secret  INT
AS
    UPDATE [Qianbo_Users]
    SET    [email] = @email,
           [groupid] = @groupid,
           [secret] = @secret
    WHERE  [userid] = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetList_Model]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetList_Model] @ModelId INT
AS
    SELECT *
    FROM   [Qianbo_ModelField]
    WHERE  ModelId = @ModelId
           AND [ColId] = 0
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_Update]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Special_Update] @ID             INT,
                                             @ParentID       INT,
                                             @SiteID         INT,
                                             @SpecialCName   NVARCHAR(30),
                                             @SpecialDomain  NVARCHAR(100),
                                             @SpecialRemark  NVARCHAR(200),
                                             @IsLock         BIT,
                                             @IsCommand      BIT,
                                             @SpecialAddTime DATETIME,
                                             @MetaKeyWord    NVARCHAR(200),
                                             @MetaRemark     NVARCHAR(200),
                                             @SpecialTemplet NVARCHAR(200),
                                             @SpecialItemNum INT,
                                             @SpecialContent NTEXT,
                                             @SaveDirType    NVARCHAR(200),
                                             @Extension      VARCHAR(50),
                                             @PicSavePath    NVARCHAR(200)
AS
    UPDATE Qianbo_Special
    SET    [ParentID] = @ParentID,
           [SiteID] = @SiteID,
           [SpecialCName] = @SpecialCName,
           [SpecialDomain] = @SpecialDomain,
           [SpecialRemark] = @SpecialRemark,
           [IsLock] = @IsLock,
           [IsCommand] = @IsCommand,
           [SpecialAddTime] = @SpecialAddTime,
           [MetaKeyWord] = @MetaKeyWord,
           [MetaRemark] = @MetaRemark,
           [SpecialTemplet] = @SpecialTemplet,
           [SpecialItemNum] = @SpecialItemNum,
           [SpecialContent] = @SpecialContent,
           [SaveDirType] = @SaveDirType,
           Extension = @Extension,
           PicSavePath = @PicSavePath
    WHERE  [ID] = @ID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserAlbum_GetById]'
GO
CREATE PROCEDURE [dbo].[Proc_UserAlbum_GetById] @Id     INT,
                                                @UserId INT
AS
    SELECT [Id],
           [AlbumName],
           [AlbumCate],
           [AlbumDescription],
           [ImgCount],
           [Logo],
           [IsOpened],
           [AlbumPassword],
           [AddTime],
           [UserId],
           [UserName]
    FROM   Qianbo_UserAlbum
    WHERE  [Id] = @Id
           AND UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadData_ClearDownCount]'
GO
CREATE PROC [dbo].[Proc_DownLoadData_ClearDownCount]
AS
    UPDATE [Qianbo_DownLoadData]
    SET    downloaddownmonthnum = 0,
           monthcounttime = Getdate()
    WHERE  Datediff(month, monthcounttime, Getdate()) != 0
    UPDATE [Qianbo_DownLoadData]
    SET    downloaddownweeknum = 0,
           weekcounttime = Getdate()
    WHERE  Datediff(week, weekcounttime, Getdate()) != 0
    UPDATE [Qianbo_DownLoadData]
    SET    downloaddowndaynum = 0,
           daycounttime = Getdate()
    WHERE  Datediff(day, daycounttime, Getdate()) != 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_FeedBack_GetFeedBack]'
GO
CREATE PROCEDURE [dbo].[Proc_FeedBack_GetFeedBack] @FeedBackID INT,
                                                   @Type       INT,
                                                   @author     NVARCHAR(20)
AS
    IF @Type = 1
      BEGIN
          SELECT *
          FROM   Qianbo_FeedBack
          WHERE  Id = @FeedBackID
          SELECT *
          FROM   Qianbo_FeedBack
          WHERE  parentId = @FeedBackID
      END
    IF @Type = 2
      BEGIN
          SELECT author,
                 Id
          FROM   Qianbo_FeedBack
          WHERE  parentId = @FeedBackID
                 AND author != @author
      END
    IF @Type = 3
      BEGIN
          SELECT TOP 10 author,
                        scoring,
                        Sum(scoring) AS [Sum]
          FROM   Qianbo_FeedBack
          WHERE  scoring > 0
          GROUP  BY author,
                    scoring
          ORDER  BY scoring DESC
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetModel] @FieldId INT
AS
    SELECT *
    FROM   [Qianbo_ModelField]
    WHERE  FieldId = @FieldId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_UpdatePropertyArea]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Property_UpdatePropertyArea] @id    INT,
                                                          @type  INT,
                                                          @value NVARCHAR(1000)
AS
    IF( @type = 0 )
      UPDATE Qianbo_Property
      SET    [ModelId] = @value
      WHERE  [id] = @id
    ELSE IF( @type = 1 )
      UPDATE Qianbo_Property
      SET    [FormId] = @value
      WHERE  [id] = @id
    ELSE IF( @type = 2 )
      UPDATE Qianbo_Property
      SET    [UserId] = @value
      WHERE  [id] = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_UpdateState]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Admin_UpdateState] @LastLoginIP   VARCHAR(11),
                                                @LastLoginTime DATETIME,
                                                @RandNumber    VARCHAR(30),
                                                @LoginName     VARCHAR(50)
AS
    UPDATE Qianbo_Admin
    SET    LastLoginIP = @LastLoginIp,
           LastLoginTime = @LastLoginTime,
           LoginTime = LoginTime + 1,
           RandNumber = @RandNumber
    WHERE  LoginName = @LoginName
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetSearchField]'
GO
CREATE PROC [dbo].[Proc_ModelField_GetSearchField] @modelid INT
AS
    SELECT *
    FROM   Qianbo_ModelField
    WHERE  modelid = @modelid
           AND issearchform = 1
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_ModifyPwd]'
GO
CREATE PROCEDURE [dbo].[Proc_Users_ModifyPwd] @userid INT,
                                              @pwd    NVARCHAR(200)
AS
    UPDATE [Qianbo_Users]
    SET    [userpwd] = @pwd
    WHERE  userid = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserAlbum_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_UserAlbum_Set] @Id               INT output,
                                            @AlbumName        NVARCHAR(50),
                                            @AlbumCate        NVARCHAR(50),
                                            @AlbumDescription NVARCHAR(500),
                                            @ImgCount         INT,
                                            @Logo             NVARCHAR(50),
                                            @IsOpened         INT,
                                            @AlbumPassword    NVARCHAR(50),
                                            @AddTime          NVARCHAR(50),
                                            @UserId           INT,
                                            @UserName         NVARCHAR(50)
AS
    IF( @Id = 0 )
      BEGIN
          INSERT INTO Qianbo_UserAlbum
                      ([AlbumName],
                       [AlbumCate],
                       [AlbumDescription],
                       [ImgCount],
                       [Logo],
                       [IsOpened],
                       [AlbumPassword],
                       [AddTime],
                       [UserId],
                       [UserName])
          VALUES      ( @AlbumName,
                        @AlbumCate,
                        @AlbumDescription,
                        0,
                        @Logo,
                        @IsOpened,
                        @AlbumPassword,
                        @AddTime,
                        @UserId,
                        @UserName )
          SET @Id=Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_UserAlbum
          SET    [AlbumName] = @AlbumName,
                 [AlbumCate] = @AlbumCate,
                 [AlbumDescription] = @AlbumDescription,
                 [Logo] = @Logo,
                 [IsOpened] = @IsOpened,
                 [AlbumPassword] = @AlbumPassword,
                 [UserId] = @UserId,
                 [UserName] = @UserName
          WHERE  [Id] = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserCate]'
GO
CREATE TABLE [dbo].[Qianbo_UserCate]
(
[UserCateId] [int] NOT NULL IDENTITY(1, 1),
[UserId] [int] NOT NULL,
[CateName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[ModelType] [int] NOT NULL,
[Discription] [text] COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserCate] on [dbo].[Qianbo_UserCate]'
GO
ALTER TABLE [dbo].[Qianbo_UserCate] ADD CONSTRAINT [PK_Qianbo_UserCate] PRIMARY KEY CLUSTERED  ([UserCateId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserCate_Delete]'
GO
CREATE PROC [dbo].[Proc_UserCate_Delete] @UserCateId INT
AS
    DELETE FROM Qianbo_UserCate
    WHERE  UserCateId = @UserCateId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserCate_GetById]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserCate_GetById] @UserCateId INT
AS
    SELECT *
    FROM   Qianbo_UserCate
    WHERE  UserCateId = @UserCateId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserCate_GetCountByUserId]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_UserCate_GetCountByUserId] @UserId INT
AS
    SELECT Count(userCateId)
    FROM   Qianbo_UserCate
    WHERE  UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserPhoto_GetByPhotoId]'
GO
CREATE PROCEDURE [dbo].[Proc_UserPhoto_GetByPhotoId] @PhotoId INT
AS
    SELECT *
    FROM   Qianbo_UserPhoto
    WHERE  PhotoId = @PhotoId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_StyleCategoryId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_StyleCategoryId]
AS
    SELECT StyleCategoryID,
           [Name],
           ParentID
    FROM   Qianbo_StyleCategory
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserCate_GetList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_UserCate_GetList] @userid    INT,
                                          @modeltype INT
AS
    IF( @modeltype = 0 )
      SELECT a.*,
             c.modelname
      FROM   Qianbo_UserCate a
             INNER JOIN Qianbo_Users b
                     ON a.userid = b.userid
             INNER JOIN Qianbo_Model c
                     ON a.modeltype = c.modelid
      WHERE  a.userid = @userid
    ELSE
      SELECT a.*,
             c.modelname
      FROM   Qianbo_UserCate a
             INNER JOIN Qianbo_Users b
                     ON a.userid = b.userid
             INNER JOIN Qianbo_Model c
                     ON a.modeltype = c.modelid
      WHERE  a.userid = @userid
             AND a.modeltype = @modeltype
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadData_GetDataById]'
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadData_GetDataById] @Id INT
AS
    SELECT *
    FROM   Qianbo_DownLoadData
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_MoveField]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_MoveField] @ModelId  INT,
                                                   @FieldId  INT,
                                                   @MoveType NVARCHAR(20)
AS
    DECLARE @OrderId INT;
    DECLARE @NewFieldId INT;
    DECLARE @NewOrderId INT;
    IF @MoveType = 'UpMove'
      BEGIN
          DECLARE @MinOrderId INT;
          SET @MinOrderId=(SELECT Min(OrderId)
                           FROM   [Qianbo_ModelField]
                           WHERE  ModelId = @ModelId)
          SET @OrderId=(SELECT OrderId
                        FROM   [Qianbo_ModelField]
                        WHERE  ModelId = @ModelId
                               AND FieldId = @FieldId)
          IF @OrderId != @MinOrderId
            BEGIN
                SET @NewFieldId=(SELECT TOP 1 FieldId
                                 FROM   [Qianbo_ModelField]
                                 WHERE  ModelId = @ModelId
                                        AND OrderId < @OrderId
                                 ORDER  BY OrderId DESC)
                SET @NewOrderId=(SELECT OrderId
                                 FROM   [Qianbo_ModelField]
                                 WHERE  ModelId = @ModelId
                                        AND FieldId = @NewFieldId)
                UPDATE [Qianbo_ModelField]
                SET    OrderId = @OrderId
                WHERE  FieldId = @NewFieldId
                       AND ModelId = @ModelId
                UPDATE [Qianbo_ModelField]
                SET    OrderId = @NewOrderId
                WHERE  FieldId = @FieldId
                       AND ModelId = @ModelId
            END
      END
    IF @MoveType = 'DownMove'
      BEGIN
          DECLARE @MaxOrderId INT;
          SET @MaxOrderId=(SELECT Max(OrderId)
                           FROM   [Qianbo_ModelField]
                           WHERE  ModelId = @ModelId)
          SET @OrderId=(SELECT OrderId
                        FROM   [Qianbo_ModelField]
                        WHERE  ModelId = @ModelId
                               AND FieldId = @FieldId)
          IF @OrderId != @MaxOrderId
            BEGIN
                SET @NewFieldId=(SELECT TOP 1 FieldId
                                 FROM   [Qianbo_ModelField]
                                 WHERE  ModelId = @ModelId
                                        AND OrderId > @OrderId
                                 ORDER  BY OrderId)
                SET @NewOrderId=(SELECT OrderId
                                 FROM   [Qianbo_ModelField]
                                 WHERE  ModelId = @ModelId
                                        AND FieldId = @NewFieldId)
                UPDATE [Qianbo_ModelField]
                SET    OrderId = @OrderId
                WHERE  FieldId = @NewFieldId
                       AND ModelId = @ModelId
                UPDATE [Qianbo_ModelField]
                SET    OrderId = @NewOrderId
                WHERE  FieldId = @FieldId
                       AND ModelId = @ModelId
            END
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_SubSite]'
GO
CREATE TABLE [dbo].[Qianbo_SubSite]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_SubSite_Name] DEFAULT (''),
[FirstChar] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[EnName] [varchar] (200) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Domain] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[LOGO] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_SubSite_LOGO] DEFAULT (''),
[Sort] [int] NULL CONSTRAINT [DF_Qianbo_SubSite_Sort] DEFAULT ((1)),
[Status] [int] NULL CONSTRAINT [DF_Qianbo_SubSite_Status] DEFAULT ((0)),
[AddTime] [datetime] NULL CONSTRAINT [DF_Qianbo_SubSite_AddTime] DEFAULT (getdate()),
[Remark] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_SubSite_Remark] DEFAULT (''),
[OpenTime] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_SubSite_OpenTime] DEFAULT ('-'),
[DbServer] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[DbName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[DbUid] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[DbPwd] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Permision] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[CallName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[CallPass] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[IsCreateModel] [bit] NULL CONSTRAINT [DF__Qianbo_SubSite__IsCre__28CDE297] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_SubSite] on [dbo].[Qianbo_SubSite]'
GO
ALTER TABLE [dbo].[Qianbo_SubSite] ADD CONSTRAINT [PK_Qianbo_SubSite] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SubSite_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SubSite_Add] @Name          NVARCHAR(100),
                                          @FirstChar     NVARCHAR(20),
                                          @EnName        VARCHAR(200),
                                          @LOGO          NVARCHAR(400),
                                          @Sort          INT,
                                          @Status        INT,
                                          @AddTime       DATETIME,
                                          @Remark        NVARCHAR(1000),
                                          @OpenTime      VARCHAR(50),
                                          @DbServer      VARCHAR(50),
                                          @DbName        VARCHAR(50),
                                          @DbUid         VARCHAR(50),
                                          @DbPwd         VARCHAR(50),
                                          @Permision     VARCHAR(500),
                                          @CallName      NVARCHAR(50),
                                          @CallPass      NVARCHAR(50),
                                          @IsCreateModel BIT,
                                          @Domain        NVARCHAR(100)
AS
    INSERT INTO Qianbo_SubSite
                ([Name],
                 [FirstChar],
                 [EnName],
                 [LOGO],
                 [Sort],
                 [Status],
                 [AddTime],
                 [Remark],
                 [OpenTime],
                 [DbServer],
                 [DbName],
                 [DbUid],
                 [DbPwd],
                 [Permision],
                 [CallName],
                 [CallPass],
                 [IsCreateModel],
                 [Domain])
    VALUES      ( @Name,
                  @FirstChar,
                  @EnName,
                  @LOGO,
                  @Sort,
                  @Status,
                  @AddTime,
                  @Remark,
                  @OpenTime,
                  @DbServer,
                  @DbName,
                  @DbUid,
                  @DbPwd,
                  @Permision,
                  @CallName,
                  @CallPass,
                  @IsCreateModel,
                  @Domain )
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserCate_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_UserCate_Set] @UserCateId  INT output,
                                           @UserId      INT,
                                           @CateName    VARCHAR(50),
                                           @CateType    INT,
                                           @Discription TEXT
AS
    IF( @UserCateId = 0 )
      BEGIN
          INSERT INTO Qianbo_UserCate
                      ([UserId],
                       [CateName],
                       [ModelType],
                       [Discription])
          VALUES      ( @UserId,
                        @CateName,
                        @CateType,
                        @Discription )
          SET @UserCateId=Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_UserCate
          SET    [UserId] = @UserId,
                 [CateName] = @CateName,
                 [ModelType] = @CateType,
                 [Discription] = @Discription
          WHERE  [UserCateId] = @UserCateId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_CountWeek]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_CountWeek]
(
[1] [int] NULL CONSTRAINT [DF_Qianbo_CountWeek_1] DEFAULT ((0)),
[2] [int] NULL CONSTRAINT [DF_Qianbo_CountWeek_2] DEFAULT ((0)),
[3] [int] NULL CONSTRAINT [DF_Qianbo_CountWeek_3] DEFAULT ((0)),
[4] [int] NULL CONSTRAINT [DF_Qianbo_CountWeek_4] DEFAULT ((0)),
[5] [int] NULL CONSTRAINT [DF_Qianbo_CountWeek_5] DEFAULT ((0)),
[6] [int] NULL CONSTRAINT [DF_Qianbo_CountWeek_6] DEFAULT ((0)),
[7] [int] NULL CONSTRAINT [DF_Qianbo_CountWeek_7] DEFAULT ((0)),
[Flag] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsCount_AddWeekCount]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsCount_AddWeekCount] @CurrDate    VARCHAR(10),
                                                    @CurrWeekDay VARCHAR(1)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @param NVARCHAR(400)
    IF NOT EXISTS(SELECT *
                  FROM   Qianbo_CountWeek
                  WHERE  flag <> 'total')
      BEGIN
          SET @sqlstr = 'insert into Qianbo_CountWeek([1],[2],[3],[4],[5],[6],[7],flag)values(0,0,0,0,0,0,0,@tCurrDate)'
          SET @param = '@tcurrdate nvarchar(10)'
          EXECUTE Sp_ExecuteSql
            @SqlStr,
            @param,
            @tcurrdate = @currdate
      END
    IF( @CurrDate != ''
        AND NOT EXISTS(SELECT *
                       FROM   Qianbo_CountWeek
                       WHERE  Flag = @CurrDate) )
      BEGIN
          SET @SqlStr = N'update Qianbo_CountWeek set [1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,Flag = '''
                        + @CurrDate + ''' where Flag <> ''Total'''
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
    SET @SqlStr = N'update Qianbo_CountWeek set ['
                  + @CurrWeekDay + '] = [' + @CurrWeekDay + '] + 1'
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Anomaly]'
GO
CREATE TABLE [dbo].[Qianbo_Anomaly]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[InfoId] [int] NULL,
[ChId] [int] NULL,
[ColName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Title] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Anomaly] on [dbo].[Qianbo_Anomaly]'
GO
ALTER TABLE [dbo].[Qianbo_Anomaly] ADD CONSTRAINT [PK_Qianbo_Anomaly] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Anomaly_Add]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Anomaly_Add] @InfoId  INT,
                                          @ChId    INT,
                                          @ColName NVARCHAR(100),
                                          @Title   VARCHAR(200)
AS
    INSERT INTO Qianbo_Anomaly
                ([InfoId],
                 [ChId],
                 [ColName],
                 [Title])
    VALUES      ( @InfoId,
                  @ChId,
                  @ColName,
                  @Title )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_SelectPropertyTrue]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_SelectPropertyTrue] @ModelId NVARCHAR(50)
AS
    SELECT *
    FROM   [Qianbo_ModelField]
    WHERE  ModelId = @ModelId
           AND Content LIKE '%Property=2%'
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserPhoto_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_UserPhoto_Set] @PhotoId     INT output,
                                            @AlbumId     INT,
                                            @FileName    NVARCHAR(50),
                                            @FilePath    NVARCHAR(100),
                                            @Description NVARCHAR(500),
                                            @PostTime    NVARCHAR(50),
                                            @UserId      INT,
                                            @UserName    NVARCHAR(50),
                                            @VisitNum    INT,
                                            @FileSize    INT
AS
    IF( @PhotoId = 0 )
      BEGIN
          INSERT INTO Qianbo_UserPhoto
                      ([AlbumId],
                       [FileName],
                       [FilePath],
                       [Description],
                       [PostTime],
                       [UserId],
                       [UserName],
                       [VisitNum],
                       [FileSize])
          VALUES      ( @AlbumId,
                        @FileName,
                        @FilePath,
                        @Description,
                        @PostTime,
                        @UserId,
                        @UserName,
                        @VisitNum,
                        @FileSize )
          SET @PhotoId =Scope_identity()
          UPDATE Qianbo_UserAlbum
          SET    imgcount = imgcount + 1
          FROM   Qianbo_UserAlbum a
                 JOIN Qianbo_UserPhoto b
                   ON a.id = b.albumid
          WHERE  photoid = @PhotoId
      END
    ELSE
      BEGIN
          UPDATE Qianbo_UserPhoto
          SET    [FileName] = @FileName,
                 [FilePath] = @FilePath,
                 [Description] = @Description,
                 [PostTime] = @PostTime,
                 [UserName] = @UserName,
                 [FileSize] = @FileSize,
                 [VisitNum] = @VisitNum
          WHERE  [PhotoId] = @PhotoId
                 AND [UserId] = @UserId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SubSite_DelAdmin]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SubSite_DelAdmin] @SiteId INT
AS
    DELETE FROM [Qianbo_Admin]
    WHERE  [SiteId] = @SiteId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_ModifyQuestion]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Users_ModifyQuestion] @userid   INT,
                                              @question NVARCHAR(50),
                                              @answer   NVARCHAR(50)
AS
    UPDATE [Qianbo_Users]
    SET    [question] = @question,
           [answer] = @answer
    WHERE  userid = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserFavorite]'
GO
CREATE TABLE [dbo].[Qianbo_UserFavorite]
(
[id] [int] NOT NULL IDENTITY(1, 1),
[UserId] [int] NULL,
[Title] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Url] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserFavorite] on [dbo].[Qianbo_UserFavorite]'
GO
ALTER TABLE [dbo].[Qianbo_UserFavorite] ADD CONSTRAINT [PK_Qianbo_UserFavorite] PRIMARY KEY CLUSTERED  ([id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserFavorite]'
GO
CREATE PROCEDURE [dbo].[Proc_UserFavorite] @id      INT=0,
                                           @UserId  INT=0,
                                           @Title   NVARCHAR(100)=" ",
                                           @Url     NVARCHAR(1000)=" ",
                                           @AddDate DATETIME=" ",
                                           @TypeId  INT=0
AS
    IF @TypeId = 1
      BEGIN
          INSERT INTO Qianbo_UserFavorite
                      ([UserId],
                       [Title],
                       [Url],
                       [AddDate])
          VALUES      (@UserId,
                       @Title,
                       @Url,
                       @AddDate)
      END
    IF @TypeId = 2
      BEGIN
          DELETE Qianbo_UserFavorite
          WHERE  [id] = @id
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_CountYear]'
GO
CREATE TABLE [dbo].[Qianbo_CountYear]
(
[1] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_1] DEFAULT ((0)),
[2] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_2] DEFAULT ((0)),
[3] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_3] DEFAULT ((0)),
[4] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_4] DEFAULT ((0)),
[5] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_5] DEFAULT ((0)),
[6] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_6] DEFAULT ((0)),
[7] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_7] DEFAULT ((0)),
[8] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_8] DEFAULT ((0)),
[9] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_9] DEFAULT ((0)),
[10] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_10] DEFAULT ((0)),
[11] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_11] DEFAULT ((0)),
[12] [int] NULL CONSTRAINT [DF_Qianbo_CountYear_12] DEFAULT ((0)),
[Flag] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsCount_AddYearCount]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsCount_AddYearCount] @CurrMonth VARCHAR(2),
                                                    @CurrYear  VARCHAR(4)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF EXISTS(SELECT *
              FROM   Qianbo_CountYear
              WHERE  Flag = @CurrYear)
      SET @SqlStr = N'update Qianbo_CountYear set ['
                    + @CurrMonth + '] = [' + @CurrMonth
                    + '] + 1  where Flag = ''' + @CurrYear + '''';
    ELSE
      SET @SqlStr = N'insert into Qianbo_CountYear (['
                    + @CurrMonth + '],Flag)values(1,''' + @CurrYear
                    + ''')';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'update Qianbo_CountYear set ['
                  + @CurrMonth + '] = [' + @CurrMonth
                  + '] + 1 where Flag = ''Total''';
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_StyleCategory_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_StyleCategory_Add] @Name     NVARCHAR(100),
                                                @ParentID INT,
                                                @Desc     NVARCHAR(200)
AS
    INSERT INTO Qianbo_StyleCategory
                ([Name],
                 [ParentID],
                 [Desc])
    VALUES      ( @Name,
                  @ParentID,
                  @Desc )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_Update]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_Update] @FieldId      INT,
                                                @ModelId      INT,
                                                @Alias        NVARCHAR(300),
                                                @Description  NVARCHAR(400),
                                                @IsNotNull    BIT,
                                                @IsSearchForm BIT,
                                                @Content      NTEXT,
                                                @AddDate      DATETIME,
                                                @ColId        INT,
                                                @IsChild      INT,
                                                @IsList       INT,
                                                @IsUserInsert INT
AS
    UPDATE Qianbo_ModelField
    SET    [Alias] = @Alias,
           [Description] = @Description,
           [IsNotNull] = @IsNotNull,
           [IsSearchForm] = @IsSearchForm,
           [Content] = @Content,
           [AddDate] = @AddDate,
           [ColId] = @ColId,
           [IsChild] = @IsChild,
           [IsList] = @IsList,
           [IsUserInsert] = @IsUserInsert
    WHERE  [FieldId] = @FieldId
           AND ModelId = @ModelId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SubSite_Delete]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SubSite_Delete] @Id INT
AS
    DELETE FROM Qianbo_SubSite
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_FeedBack_UpdateState]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_FeedBack_UpdateState] @Id    INT,
                                                   @Type  INT,
                                                   @Value NVARCHAR(20)
AS
    IF @Type = 0
      BEGIN
          UPDATE Qianbo_FeedBack
          SET    State = @Value
          WHERE  [Id] = @Id
      END
    IF @Type = 1
      BEGIN
          UPDATE Qianbo_FeedBack
          SET    categoryId = @Value
          WHERE  [Id] = @Id
      END
    IF @Type = 2
      BEGIN
          UPDATE Qianbo_FeedBack
          SET    scoring = @Value
          WHERE  [Id] = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SubSite_GetModel]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SubSite_GetModel] @Id INT
AS
    SELECT *
    FROM   Qianbo_SubSite
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_ExpireArticle]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_ExpireArticle]
(
[Id] [int] NOT NULL,
[ColId] [int] NOT NULL,
[Title] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_Title] DEFAULT (''),
[TitleColor] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_TitleColor] DEFAULT (''),
[TitleFontType] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_TitleFontType] DEFAULT (''),
[TitleType] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_TitleType] DEFAULT ((0)),
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_TitleImgPath] DEFAULT (''),
[UId] [int] NOT NULL,
[UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UserType] [int] NOT NULL,
[AdminUId] [int] NULL,
[AdminUName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_AdminUName] DEFAULT (''),
[Status] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_Status] DEFAULT ((0)),
[HitCount] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_HitCount] DEFAULT ((0)),
[AddTime] [datetime] NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_TemplatePath] DEFAULT (''),
[PageType] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_PageType] DEFAULT ((1)),
[IsCreated] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsCreated] DEFAULT ((0)),
[UserCateId] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_UserCateId] DEFAULT ((0)),
[PointCount] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_PointCount] DEFAULT ((0)),
[ChargeType] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_ChargeType] DEFAULT ((1)),
[ChargeHourCount] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_ChargeHourCount] DEFAULT ((0)),
[ChargeViewCount] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_ChargeViewCount] DEFAULT ((0)),
[IsOpened] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsOpened] DEFAULT ((2)),
[GroupIdStr] [varchar] (1000) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_GroupIdStr] DEFAULT (''),
[IsDeleted] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsDeleted] DEFAULT ((0)),
[IsRecommend] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsRecommend] DEFAULT ((0)),
[IsTop] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsTop] DEFAULT ((0)),
[IsFocus] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsFocus] DEFAULT ((0)),
[IsSideShow] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsSideShow] DEFAULT ((0)),
[IsAllowComment] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsAllowComment] DEFAULT ((0)),
[TagIdStr] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_TagIdStr] DEFAULT (''),
[TagNameStr] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_TagNameStr] DEFAULT (''),
[SpecialIdStr] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_SpecialIdStr] DEFAULT (''),
[LongTitle] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_LongTitle] DEFAULT (''),
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_Content] DEFAULT (''),
[ShortContent] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_ShortContent] DEFAULT (''),
[OuterUrl] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_OuterUrl] DEFAULT (''),
[Author] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_Author] DEFAULT (''),
[Source] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_Source] DEFAULT (''),
[IsHeader] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsHeader] DEFAULT ((0)),
[HeaderFont] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_HeaderFont] DEFAULT (''),
[HeaderImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_HeaderImgPath] DEFAULT (''),
[StarLevel] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_StarLevel] DEFAULT (''),
[IsShowCommentLink] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsShowCommentLink] DEFAULT ((0)),
[IsIrregular] [bit] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IsIrregular] DEFAULT ((0)),
[IrregularId] [int] NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_IrregularId] DEFAULT ((0)),
[ViewUName] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_ViewUName] DEFAULT (''),
[ViewUName2] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_ViewUName2] DEFAULT (''),
[ViewEndTime] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_ExpirtArticle_ViewEndTime] DEFAULT (''),
[ExpireTime] [datetime] NOT NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_ExpirtArticle_ExpirtTime] on [dbo].[Qianbo_ExpireArticle]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_ExpirtArticle_ExpirtTime] ON [dbo].[Qianbo_ExpireArticle] ([ExpireTime])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Article_MoveExpireArticle]'
GO
CREATE PROC [dbo].[Proc_Article_MoveExpireArticle] @chid  INT,
                                                   @colid INT
AS
    IF( @colid = 0 )
      BEGIN
          INSERT INTO Qianbo_ExpireArticle
                      ([Id],
                       ColId,
                       Title,
                       TitleColor,
                       TitleFontType,
                       TitleType,
                       TitleImgPath,
                       UId,
                       UName,
                       UserType,
                       AdminUId,
                       AdminUName,
                       Status,
                       HitCount,
                       AddTime,
                       UpdateTime,
                       TemplatePath,
                       PageType,
                       IsCreated,
                       UserCateId,
                       PointCount,
                       ChargeType,
                       ChargeHourCount,
                       ChargeViewCount,
                       IsOpened,
                       GroupIdStr,
                       IsDeleted,
                       IsRecommend,
                       IsTop,
                       IsFocus,
                       IsSideShow,
                       TagIdStr,
                       TagNameStr,
                       SpecialIdStr,
                       LongTitle,
                       Content,
                       ShortContent,
                       OuterUrl,
                       Author,
                       Source,
                       IsHeader,
                       HeaderFont,
                       HeaderImgPath,
                       StarLevel,
                       IsShowCommentLink,
                       IsIrregular,
                       IrregularId,
                       ViewUName,
                       ViewUName2,
                       ViewEndTime,
                       IsAllowComment,
                       ExpireTime)
          SELECT i.[Id],
                 i.ColId,
                 i.Title,
                 i.TitleColor,
                 i.TitleFontType,
                 i.TitleType,
                 i.TitleImgPath,
                 i.UId,
                 i.UName,
                 i.UserType,
                 i.AdminUId,
                 i.AdminUName,
                 i.Status,
                 i.HitCount,
                 i.AddTime,
                 i.UpdateTime,
                 i.TemplatePath,
                 i.PageType,
                 i.IsCreated,
                 i.UserCateId,
                 i.PointCount,
                 i.ChargeType,
                 i.ChargeHourCount,
                 i.ChargeViewCount,
                 i.IsOpened,
                 i.GroupIdStr,
                 i.IsDeleted,
                 i.IsRecommend,
                 i.IsTop,
                 i.IsFocus,
                 i.IsSideShow,
                 i.TagIdStr,
                 i.TagNameStr,
                 i.SpecialIdStr,
                 i.LongTitle,
                 i.Content,
                 i.ShortContent,
                 i.OuterUrl,
                 i.Author,
                 i.Source,
                 i.IsHeader,
                 i.HeaderFont,
                 i.HeaderImgPath,
                 i.StarLevel,
                 i.IsShowCommentLink,
                 i.IsIrregular,
                 i.IrregularId,
                 i.ViewUName,
                 i.ViewUName2,
                 i.ViewEndTime,
                 i.IsAllowComment,
                 i.ExpireTime
          FROM   Qianbo_Article i
                 JOIN Qianbo_Column co
                   ON i.colid = co.colid
          WHERE  co.chid = @chid
                 AND i.expiretime < Getdate()
          DELETE i
          FROM   Qianbo_Article i
                 JOIN Qianbo_Column co
                   ON i.colid = co.colid
          WHERE  co.chid = @chid
                 AND i.expiretime < Getdate();
          DELETE i
          FROM   Qianbo_Article i
                 JOIN Qianbo_Column co
                   ON i.colid = co.colid
          WHERE  co.chid = @chid
                 AND i.expiretime < Getdate();
      END
    ELSE
      BEGIN
          INSERT INTO Qianbo_ExpireArticle
                      ([Id],
                       ColId,
                       Title,
                       TitleColor,
                       TitleFontType,
                       TitleType,
                       TitleImgPath,
                       UId,
                       UName,
                       UserType,
                       AdminUId,
                       AdminUName,
                       Status,
                       HitCount,
                       AddTime,
                       UpdateTime,
                       TemplatePath,
                       PageType,
                       IsCreated,
                       UserCateId,
                       PointCount,
                       ChargeType,
                       ChargeHourCount,
                       ChargeViewCount,
                       IsOpened,
                       GroupIdStr,
                       IsDeleted,
                       IsRecommend,
                       IsTop,
                       IsFocus,
                       IsSideShow,
                       TagIdStr,
                       TagNameStr,
                       SpecialIdStr,
                       LongTitle,
                       Content,
                       ShortContent,
                       OuterUrl,
                       Author,
                       Source,
                       IsHeader,
                       HeaderFont,
                       HeaderImgPath,
                       StarLevel,
                       IsShowCommentLink,
                       IsIrregular,
                       IrregularId,
                       ViewUName,
                       ViewUName2,
                       ViewEndTime,
                       IsAllowComment,
                       ExpireTime)
          SELECT i.[Id],
                 i.ColId,
                 i.Title,
                 i.TitleColor,
                 i.TitleFontType,
                 i.TitleType,
                 i.TitleImgPath,
                 i.UId,
                 i.UName,
                 i.UserType,
                 i.AdminUId,
                 i.AdminUName,
                 i.Status,
                 i.HitCount,
                 i.AddTime,
                 i.UpdateTime,
                 i.TemplatePath,
                 i.PageType,
                 i.IsCreated,
                 i.UserCateId,
                 i.PointCount,
                 i.ChargeType,
                 i.ChargeHourCount,
                 i.ChargeViewCount,
                 i.IsOpened,
                 i.GroupIdStr,
                 i.IsDeleted,
                 i.IsRecommend,
                 i.IsTop,
                 i.IsFocus,
                 i.IsSideShow,
                 i.TagIdStr,
                 i.TagNameStr,
                 i.SpecialIdStr,
                 i.LongTitle,
                 i.Content,
                 i.ShortContent,
                 i.OuterUrl,
                 i.Author,
                 i.Source,
                 i.IsHeader,
                 i.HeaderFont,
                 i.HeaderImgPath,
                 i.StarLevel,
                 i.IsShowCommentLink,
                 i.IsIrregular,
                 i.IrregularId,
                 i.ViewUName,
                 i.ViewUName2,
                 i.ViewEndTime,
                 i.IsAllowComment,
                 i.ExpireTime
          FROM   Qianbo_Article i
                 JOIN Qianbo_Column co
                   ON i.colid = co.colid
          WHERE  co.chid = @chid
                 AND i.colid = @colid
                 AND i.expiretime < Getdate()
          DELETE i
          FROM   Qianbo_Article i
                 JOIN Qianbo_Column co
                   ON i.colid = co.colid
          WHERE  co.chid = @chid
                 AND i.colid = @colid
                 AND i.expiretime < Getdate();
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Anomaly_CheckHas]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Anomaly_CheckHas] @chid   INT,
                                               @infoid INT
AS
    SELECT [Id]
    FROM   Qianbo_Anomaly
    WHERE  Chid = @chid
           AND InfoId = @infoid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SubSite_GetModel_EnName]'
GO
CREATE PROCEDURE [dbo].[Proc_SubSite_GetModel_EnName] @EnName VARCHAR(200)
AS
    SELECT *
    FROM   Qianbo_SubSite
    WHERE  [EnName] = @EnName
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_SetLockStatus]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Users_SetLockStatus] @userid     INT,
                                             @lockstatus BIT
AS
    UPDATE [Qianbo_Users]
    SET    [islock] = @lockstatus
    WHERE  [userid] = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Report]'
GO
CREATE TABLE [dbo].[Qianbo_Report]
(
[ReportId] [int] NOT NULL IDENTITY(1, 1),
[Content] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Url] [varchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UserId] [int] NOT NULL,
[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[IsComplete] [int] NOT NULL CONSTRAINT [DF_Qianbo_Report_IsComplete] DEFAULT ((0)),
[AddTime] [datetime] NULL CONSTRAINT [DF_Qianbo_Report_AddTime] DEFAULT (getdate())
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Report] on [dbo].[Qianbo_Report]'
GO
ALTER TABLE [dbo].[Qianbo_Report] ADD CONSTRAINT [PK_Qianbo_Report] PRIMARY KEY CLUSTERED  ([ReportId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Report_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Report_Add] @Content    NVARCHAR(500),
                                         @Url        VARCHAR(255),
                                         @UserId     INT,
                                         @UserName   NVARCHAR(20),
                                         @IsComplete INT,
                                         @AddTime    DATETIME
AS
    INSERT INTO Qianbo_Report
                ([Content],
                 [Url],
                 [UserId],
                 [UserName],
                 [IsComplete],
                 [AddTime])
    VALUES      (@Content,
                 @Url,
                 @UserId,
                 @UserName,
                 @IsComplete,
                 @AddTime)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SubSite_Update]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SubSite_Update] @Id            INT,
                                             @Name          NVARCHAR(100),
                                             @FirstChar     CHAR(1),
                                             @EnName        VARCHAR(200),
                                             @LOGO          NVARCHAR(400),
                                             @Sort          INT,
                                             @Status        INT,
                                             @AddTime       DATETIME,
                                             @Remark        NVARCHAR(1000),
                                             @OpenTime      VARCHAR(50),
                                             @DbServer      VARCHAR(50),
                                             @DbName        VARCHAR(50),
                                             @DbUid         VARCHAR(50),
                                             @DbPwd         VARCHAR(50),
                                             @Permision     VARCHAR(500),
                                             @CallName      NVARCHAR(50),
                                             @CallPass      NVARCHAR(50),
                                             @IsCreateModel BIT,
                                             @Domain        NVARCHAR(100)
AS
    UPDATE Qianbo_SubSite
    SET    [Name] = @Name,
           [FirstChar] = @FirstChar,
           [EnName] = @EnName,
           [LOGO] = @LOGO,
           [Sort] = @Sort,
           [Status] = @Status,
           [AddTime] = @AddTime,
           [Remark] = @Remark,
           [OpenTime] = @OpenTime,
           [DbServer] = @DbServer,
           [DbName] = @DbName,
           [DbUid] = @DbUid,
           [DbPwd] = @DbPwd,
           [Permision] = @Permision,
           CallName = @CallName,
           CallPass = @CallPass,
           IsCreateModel = @IsCreateModel,
           Domain = @Domain
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_StyleCategory_Delete]'
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[Proc_StyleCategory_Delete] @StyleCategoryID INT
AS
    DELETE FROM Qianbo_StyleCategory
    WHERE  StyleCategoryID = @StyleCategoryID
            OR ParentID = @StyleCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Dig]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Dig]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[InfoId] [int] NULL,
[ModelId] [int] NULL,
[DigCount] [int] NULL CONSTRAINT [DF_Qianbo_Dig_DigCount] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Dig] on [dbo].[Qianbo_Dig]'
GO
ALTER TABLE [dbo].[Qianbo_Dig] ADD CONSTRAINT [PK_Qianbo_Dig] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetDigCount]'
GO
CREATE PROC [dbo].[Proc_Create_GetDigCount] @modelid INT,
                                            @infoid  INT
AS
    SELECT digcount
    FROM   Qianbo_Dig
    WHERE  modelid = @modelid
           AND infoid = @infoid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadData_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadData_Set] @Id                   INT output,
                                               @ChId                 INT,
                                               @ColId                INT,
                                               @Title                NVARCHAR(200),
                                               @TitleColor           NVARCHAR(6)='',
                                               @TitleFontType        INT,
                                               @TitleType            INT,
                                               @TitleImgPath         VARCHAR(255) ='',
                                               @UId                  INT,
                                               @UName                NVARCHAR(20) ='',
                                               @UserType             INT,
                                               @AdminUId             INT,
                                               @AdminUName           NVARCHAR(20) ='',
                                               @Status               INT,
                                               @HitCount             INT,
                                               @AddTime              DATETIME,
                                               @UpdateTime           DATETIME,
                                               @TemplatePath         VARCHAR(255)='',
                                               @PageType             INT,
                                               @IsCreated            BIT,
                                               @UserCateId           INT,
                                               @PointCount           INT,
                                               @ChargeType           INT,
                                               @ChargeHourCount      INT,
                                               @ChargeViewCount      INT,
                                               @IsOpened             INT,
                                               @GroupIdStr           VARCHAR(200) ='',
                                               @IsDeleted            BIT,
                                               @IsRecommend          BIT,
                                               @IsTop                BIT,
                                               @IsFocus              BIT,
                                               @IsSideShow           BIT,
                                               @TagIdStr             VARCHAR(300) ='',
                                               @TagNameStr           NVARCHAR(300) ='',
                                               @SpecialIdStr         VARCHAR(200) ='',
                                               @Content              NVARCHAR(500),
                                               @Edition              NVARCHAR(50),
                                               @PlayAddress          NVARCHAR(100) ='',
                                               @DownLoadDownNum      INT,
                                               @DownLoadDownMonthNum INT,
                                               @DownLoadDownWeekNum  INT,
                                               @DownLoadDownDayNum   INT,
                                               @DownLoadOS           NVARCHAR(100) ='',
                                               @DownLoadServerDataId INT,
                                               @Language             NVARCHAR(50) ='',
                                               @WarrantType          NVARCHAR(50) ='',
                                               @DownLoadSize         NVARCHAR(50) ='',
                                               @RegAddress           NVARCHAR(100) ='',
                                               @Plugin               NVARCHAR(20) ='',
                                               @DownLoadStarLevel    NVARCHAR(50) ='',
                                               @DownLoadDisplePwd    NVARCHAR(50) ='',
                                               @DownLoadType         NVARCHAR(50) ='',
                                               @IsAllowComment       BIT
AS
    IF( @Id = 0 )
      BEGIN
          INSERT INTO Qianbo_DownLoadData
                      ([ChId],
                       [ColId],
                       [Title],
                       [TitleColor],
                       [TitleFontType],
                       [TitleType],
                       [TitleImgPath],
                       [UId],
                       [UName],
                       [UserType],
                       [AdminUId],
                       [AdminUName],
                       [Status],
                       [HitCount],
                       [AddTime],
                       [UpdateTime],
                       [TemplatePath],
                       [PageType],
                       [IsCreated],
                       [UserCateId],
                       [PointCount],
                       [ChargeType],
                       [ChargeHourCount],
                       [ChargeViewCount],
                       [IsOpened],
                       [GroupIdStr],
                       [IsDeleted],
                       [IsRecommend],
                       [IsTop],
                       [IsFocus],
                       [IsSideShow],
                       [TagIdStr],
                       [TagNameStr],
                       [SpecialIdStr],
                       [Content],
                       [Edition],
                       [PlayAddress],
                       [DownLoadDownNum],
                       [DownLoadDownMonthNum],
                       [DownLoadDownWeekNum],
                       [DownLoadDownDayNum],
                       [DownLoadOS],
                       [DownLoadServerDataId],
                       [Language],
                       [WarrantType],
                       [DownLoadSize],
                       [RegAddress],
                       [Plugin],
                       [DownLoadStarLevel],
                       [DownLoadDisplePwd],
                       [DownLoadType],
                       [IsAllowComment])
          VALUES      (@ChId,
                       @ColId,
                       @Title,
                       @TitleColor,
                       @TitleFontType,
                       @TitleType,
                       @TitleImgPath,
                       @UId,
                       @UName,
                       @UserType,
                       @AdminUId,
                       @AdminUName,
                       @Status,
                       @HitCount,
                       @AddTime,
                       @UpdateTime,
                       @TemplatePath,
                       @PageType,
                       @IsCreated,
                       @UserCateId,
                       @PointCount,
                       @ChargeType,
                       @ChargeHourCount,
                       @ChargeViewCount,
                       @IsOpened,
                       @GroupIdStr,
                       @IsDeleted,
                       @IsRecommend,
                       @IsTop,
                       @IsFocus,
                       @IsSideShow,
                       @TagIdStr,
                       @TagNameStr,
                       @SpecialIdStr,
                       @Content,
                       @Edition,
                       @PlayAddress,
                       @DownLoadDownNum,
                       @DownLoadDownMonthNum,
                       @DownLoadDownWeekNum,
                       @DownLoadDownDayNum,
                       @DownLoadOS,
                       @DownLoadServerDataId,
                       @Language,
                       @WarrantType,
                       @DownLoadSize,
                       @RegAddress,
                       @Plugin,
                       @DownLoadStarLevel,
                       @DownLoadDisplePwd,
                       @DownLoadType,
                       @IsAllowComment )
          SET @ID = Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_DownLoadData
          SET    [ChId] = @ChId,
                 [ColId] = @ColId,
                 [Title] = @Title,
                 [TitleColor] = @TitleColor,
                 [TitleFontType] = @TitleFontType,
                 [TitleType] = @TitleType,
                 [TitleImgPath] = @TitleImgPath,
                 [HitCount] = @HitCount,
                 [UpdateTime] = @UpdateTime,
                 [TemplatePath] = @TemplatePath,
                 [PageType] = @PageType,
                 [PointCount] = @PointCount,
                 [ChargeType] = @ChargeType,
                 [ChargeHourCount] = @ChargeHourCount,
                 [ChargeViewCount] = @ChargeViewCount,
                 [IsOpened] = @IsOpened,
                 [GroupIdStr] = @GroupIdStr,
                 [IsRecommend] = @IsRecommend,
                 [IsTop] = @IsTop,
                 [IsFocus] = @IsFocus,
                 [IsSideShow] = @IsSideShow,
                 [TagIdStr] = @TagIdStr,
                 [TagNameStr] = @TagNameStr,
                 [SpecialIdStr] = @SpecialIdStr,
                 [Content] = @Content,
                 [Edition] = @Edition,
                 [PlayAddress] = @PlayAddress,
                 [DownLoadDownNum] = @DownLoadDownNum,
                 [DownLoadDownMonthNum] = @DownLoadDownMonthNum,
                 [DownLoadDownWeekNum] = @DownLoadDownWeekNum,
                 [DownLoadDownDayNum] = @DownLoadDownDayNum,
                 [DownLoadOS] = @DownLoadOS,
                 [DownLoadServerDataId] = @DownLoadServerDataId,
                 [Language] = @Language,
                 [WarrantType] = @WarrantType,
                 [DownLoadSize] = @DownLoadSize,
                 [RegAddress] = @RegAddress,
                 [Plugin] = @Plugin,
                 [DownLoadStarLevel] = @DownLoadStarLevel,
                 [DownLoadDisplePwd] = @DownLoadDisplePwd,
                 [DownLoadType] = @DownLoadType,
                 [IsAllowComment] = @IsAllowComment
          WHERE  [Id] = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_VoteCategory]'
GO
CREATE TABLE [dbo].[Qianbo_VoteCategory]
(
[CategoryId] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NOT NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_VoteCategory] on [dbo].[Qianbo_VoteCategory]'
GO
ALTER TABLE [dbo].[Qianbo_VoteCategory] ADD CONSTRAINT [PK_Qianbo_VoteCategory] PRIMARY KEY CLUSTERED  ([CategoryId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_VoteCategory_Get]'
GO
CREATE PROCEDURE [dbo].[Proc_VoteCategory_Get] @Id   INT=0,
                                               @Type INT
AS
    IF @Type = 1
      BEGIN
          SELECT *
          FROM   Qianbo_VoteCategory
          WHERE  CategoryId = @Id
      END
    IF @Type = 2
      BEGIN
          SELECT *
          FROM   Qianbo_VoteCategory
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserGroup]'
GO
CREATE TABLE [dbo].[Qianbo_UserGroup]
(
[UserGroupId] [int] NOT NULL IDENTITY(1, 1),
[UserGroupName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[UserGroupContent] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[TypeId] [int] NULL,
[GroupPower] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[AllChannel] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[AllColumn] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[ChannelPower] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[ColumnPower] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[IsSystem] [int] NULL,
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserGroup] on [dbo].[Qianbo_UserGroup]'
GO
ALTER TABLE [dbo].[Qianbo_UserGroup] ADD CONSTRAINT [PK_Qianbo_UserGroup] PRIMARY KEY CLUSTERED  ([UserGroupId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroup]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroup] @UserGroupId      INT=0,
                                        @UserGroupName    NVARCHAR(100)=" ",
                                        @UserGroupContent NVARCHAR(1000)=" ",
                                        @TypeId           INT=0,
                                        @GroupPower       NTEXT=" ",
                                        @ColumnPower      NTEXT=" ",
                                        @IsSystem         INT=0,
                                        @AddDate          DATETIME=" ",
                                        @Up_Id            INT=0,
                                        @ChannelPower     NTEXT=" ",
                                        @AllChannel       NTEXT=" ",
                                        @AllColumn        NTEXT=" "
AS
    IF( @Up_Id = 1 )
      BEGIN
          INSERT INTO Qianbo_UserGroup
                      ([UserGroupName],
                       [UserGroupContent],
                       [TypeId],
                       [GroupPower],
                       [ColumnPower],
                       [IsSystem],
                       [AddDate],
                       [ChannelPower],
                       [AllChannel],
                       [AllColumn])
          VALUES      (@UserGroupName,
                       @UserGroupContent,
                       @TypeId,
                       @GroupPower,
                       @ColumnPower,
                       @IsSystem,
                       @AddDate,
                       @ChannelPower,
                       @AllChannel,
                       @AllColumn)
      END
    IF( @Up_Id = 2 )
      BEGIN
          UPDATE Qianbo_UserGroup
          SET    [UserGroupName] = @UserGroupName,
                 [UserGroupContent] = @UserGroupContent,
                 [GroupPower] = @GroupPower,
                 [ColumnPower] = @ColumnPower,
                 [AddDate] = @AddDate,
                 [ChannelPower] = @ChannelPower,
                 [AllChannel] = @AllChannel,
                 [AllColumn] = @AllColumn
          WHERE  [UserGroupId] = @UserGroupId
      END
    IF( @Up_Id = 3 )
      BEGIN
          DELETE Qianbo_UserGroup
          WHERE  [UserGroupId] = @UserGroupId
      END
    IF( @Up_Id = 4 )
      BEGIN
          SELECT *
          FROM   Qianbo_UserGroup
          WHERE  [UserGroupId] = @UserGroupId
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserSpace]'
GO
CREATE TABLE [dbo].[Qianbo_UserSpace]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[SpaceName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[SpaceDescription] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[PrevPower] [int] NULL,
[Password] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[AddTime] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[UserId] [int] NOT NULL,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[TemplateId] [int] NULL,
[UserType] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserSpace] on [dbo].[Qianbo_UserSpace]'
GO
ALTER TABLE [dbo].[Qianbo_UserSpace] ADD CONSTRAINT [PK_Qianbo_UserSpace] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserSpace_GetById]'
GO
CREATE PROCEDURE [dbo].[Proc_UserSpace_GetById] @Id INT
AS
    SELECT *
    FROM   Qianbo_UserSpace
    WHERE  [UserId] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_StyleContent_GetLbCategoryNameList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROC [dbo].[Proc_StyleContent_GetLbCategoryNameList] @labelName   NVARCHAR(200),
                                                            @CursorPage  INT,
                                                            @PageSize    INT,
                                                            @RecordCount INT output
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CursorPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_Style where [Name] like @tlabelName order by StyleID desc'
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_Style where [Name] like @tlabelName and StyleID < (select min(StyleID) from(select top '
                  + CONVERT(NVARCHAR(15), (@CursorPage - 1) * @PageSize)
                  + ' StyleID from Qianbo_Style where [Name] like @tlabelName order by StyleID desc)O)order by StyleID desc'
    DECLARE @paramlb NVARCHAR(500)
    SET @paramlb=N'@tlabelName Nvarchar(200)'
    EXECUTE Sp_executeSql
      @SqlStr,
      @paramlb,
      @tlabelName = @labelName
    SET @RecordCount=(SELECT Count(StyleID)
                      FROM   Qianbo_Style
                      WHERE  [Name] LIKE @labelName)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Report_Delete]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Report_Delete] @ReportId INT
AS
    DELETE FROM Qianbo_Report
    WHERE  ReportId = @ReportId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_PowerGroup]'
GO
CREATE TABLE [dbo].[Qianbo_PowerGroup]
(
[PowerId] [int] NOT NULL IDENTITY(1, 1),
[SiteId] [int] NULL CONSTRAINT [DF_Qianbo_PowerGroup_SiteId] DEFAULT ((0)),
[PowerName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[PowerFunction] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[AllChannel] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[AllColumn] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[PowerColumn] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[PowerChannel] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[PowerAuditing] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[PowerModel] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[PowerContent] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[IsSystem] [int] NULL CONSTRAINT [DF_Qianbo_PowerGroup_IsSystem] DEFAULT ((0)),
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_PowerGroup] on [dbo].[Qianbo_PowerGroup]'
GO
ALTER TABLE [dbo].[Qianbo_PowerGroup] ADD CONSTRAINT [PK_Qianbo_PowerGroup] PRIMARY KEY CLUSTERED  ([PowerId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Group_Delete]'
GO
CREATE PROC [dbo].[Proc_Group_Delete] @GroupId INT
AS
    DECLARE @IsSystem INT
    SET @IsSystem = (SELECT IsSystem
                     FROM   Qianbo_PowerGroup
                     WHERE  PowerId = @GroupId)
    IF( @IsSystem = 1 )
      BEGIN
          SELECT 0;
          RETURN;
      END
    DELETE Qianbo_PowerGroup
    WHERE  PowerId = @GroupId
    SELECT 1;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_SuperLabel]'
GO
CREATE TABLE [dbo].[Qianbo_SuperLabel]
(
[SuperId] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[LbCategoryName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[LbCategoryId] [int] NULL,
[DataBaseType] [int] NULL,
[SuperDes] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[IsUnlockPage] [bit] NULL,
[PageSize] [int] NULL CONSTRAINT [DF_Qianbo_SuperLabel_PageSize] DEFAULT ((10)),
[HostTable] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[GuestTable] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[SqlStr] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[AddTime] [datetime] NULL,
[NumColumns] [int] NULL CONSTRAINT [DF_Qianbo_SuperLabel_NumColumns] DEFAULT ((1)),
[IsHtml] [bit] NULL CONSTRAINT [DF__Qianbo_SuperLa__IsHtm__59D10CA5] DEFAULT ((1)),
[DataBaseConn] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_SuperLabel] on [dbo].[Qianbo_SuperLabel]'
GO
ALTER TABLE [dbo].[Qianbo_SuperLabel] ADD CONSTRAINT [PK_Qianbo_SuperLabel] PRIMARY KEY CLUSTERED  ([SuperId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_Add] @Name           NVARCHAR(100),
                                             @LbCategoryName NVARCHAR(100),
                                             @LbCategoryId   INT,
                                             @DataBaseType   INT,
                                             @SuperDes       NVARCHAR(1000),
                                             @IsUnlockPage   BIT,
                                             @HostTable      NVARCHAR(100),
                                             @GuestTable     NVARCHAR(100),
                                             @SqlStr         NVARCHAR(1000),
                                             @Content        NTEXT,
                                             @AddTime        DATETIME,
                                             @PageSize       INT,
                                             @NumColumns     INT,
                                             @IsHtml         BIT,
                                             @DataBaseConn   NVARCHAR(300)=" "
AS
    INSERT INTO [Qianbo_SuperLabel]
                ([Name],
                 [LbCategoryName],
                 [LbCategoryId],
                 [DataBaseType],
                 [SuperDes],
                 [IsUnlockPage],
                 [HostTable],
                 [GuestTable],
                 [SqlStr],
                 [Content],
                 [AddTime],
                 [PageSize],
                 [NumColumns],
                 [IsHtml],
                 [DataBaseConn])
    VALUES      (@Name,
                 @LbCategoryName,
                 @LbCategoryId,
                 @DataBaseType,
                 @SuperDes,
                 @IsUnlockPage,
                 @HostTable,
                 @GuestTable,
                 @SqlStr,
                 @Content,
                 @AddTime,
                 @PageSize,
                 @NumColumns,
                 @IsHtml,
                 @DataBaseConn)
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Anomaly_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_Anomaly_Delete] @Id INT
AS
    DELETE Qianbo_Anomaly
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_CheckName]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_CheckName] @Name NVARCHAR(100)
AS
    IF EXISTS(SELECT *
              FROM   [Qianbo_SuperLabel]
              WHERE  NAME = @Name)
      SELECT 1
    ELSE
      SELECT 0
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_SetStatus]'
GO
CREATE PROC [dbo].[Proc_Users_SetStatus] @userid INT,
                                         @status INT
AS
    UPDATE [Qianbo_Users]
    SET    [status] = @status
    WHERE  [userid] = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserGroupModelField]'
GO
CREATE TABLE [dbo].[Qianbo_UserGroupModelField]
(
[FieldId] [int] NOT NULL IDENTITY(1, 1),
[ModelId] [int] NULL,
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Alias] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL,
[Description] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[IsNotNull] [bit] NULL,
[IsSearchForm] [bit] NULL,
[Type] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[OrderId] [int] NULL CONSTRAINT [DF_Qianbo_UserGroupModelField_OrderId] DEFAULT ((0)),
[IsList] [bit] NULL,
[IsUserInsert] [bit] NULL,
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserGroupModelField] on [dbo].[Qianbo_UserGroupModelField]'
GO
ALTER TABLE [dbo].[Qianbo_UserGroupModelField] ADD CONSTRAINT [PK_Qianbo_UserGroupModelField] PRIMARY KEY CLUSTERED  ([FieldId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_Add] @ModelId      INT,
                                                      @Name         NVARCHAR(100),
                                                      @Alias        NVARCHAR(300),
                                                      @Description  NVARCHAR(400),
                                                      @IsNotNull    BIT,
                                                      @IsSearchForm BIT,
                                                      @Type         NVARCHAR(100),
                                                      @Content      NTEXT,
                                                      @IsList       BIT,
                                                      @IsUserInsert BIT,
                                                      @AddDate      DATETIME
AS
    DECLARE @OrderId INT;
    SET @OrderId=(SELECT Max(OrderId)
                  FROM   [Qianbo_UserGroupModelField]
                  WHERE  ModelId = @ModelId)
    IF @OrderId IS NULL
      SET @OrderId=0
    ELSE
      SET @OrderId = @OrderId + 1
    INSERT INTO [Qianbo_UserGroupModelField]
                ([ModelId],
                 [Name],
                 [Alias],
                 [Description],
                 [IsNotNull],
                 [IsSearchForm],
                 [Type],
                 [Content],
                 [AddDate],
                 [OrderId],
                 [IsList],
                 [IsUserInsert])
    VALUES      (@ModelId,
                 @Name,
                 @Alias,
                 @Description,
                 @IsNotNull,
                 @IsSearchForm,
                 @Type,
                 @Content,
                 @AddDate,
                 @OrderId,
                 @IsList,
                 @IsUserInsert)
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_StyleCategory_GetIdData]'
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[Proc_StyleCategory_GetIdData] @StyleCategoryId INT
AS
    SELECT ParentId,
           [NAME],
           [DESC]
    FROM   Qianbo_StyleCategory
    WHERE  StyleCategoryId = @StyleCategoryId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_Del]'
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_Del] @FieldId INT
AS
    DELETE FROM [Qianbo_UserGroupModelField]
    WHERE  FieldId = @FieldId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Group_GetAdminGroupUserCount]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Group_GetAdminGroupUserCount] @GroupId INT
AS
    SELECT Count(UserId)
    FROM   Qianbo_Admin a
           JOIN Qianbo_PowerGroup b
             ON a.GroupId = b.PowerId
    WHERE  a.GroupId = @GroupId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_GetIsUserList]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_GetIsUserList] @ModelId INT
AS
    SELECT *
    FROM   [Qianbo_UserGroupModelField]
    WHERE  ModelId = @ModelId
           AND IsUserInsert = 1
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_DownLoadServerData]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_DownLoadServerData]
(
[DownLoadServerDataId] [int] NOT NULL IDENTITY(1, 1),
[TypeId] [int] NULL,
[DownLoadServerName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[DownLoadServerDir] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[IsOpened] [bit] NULL CONSTRAINT [DF_Qianbo_DownLoadServerData_IsOpened] DEFAULT ((0)),
[IsOuter] [int] NULL CONSTRAINT [DF_Qianbo_DownLoadServerData_IsOuter] DEFAULT ((0)),
[UnionId] [text] COLLATE Chinese_PRC_CI_AS NULL,
[DayDownNum] [int] NULL,
[AllDownNum] [int] NULL,
[AddTime] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_DownLoadServerData] on [dbo].[Qianbo_DownLoadServerData]'
GO
ALTER TABLE [dbo].[Qianbo_DownLoadServerData] ADD CONSTRAINT [PK_Qianbo_DownLoadServerData] PRIMARY KEY CLUSTERED  ([DownLoadServerDataId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [TypeId] on [dbo].[Qianbo_DownLoadServerData]'
GO
CREATE NONCLUSTERED INDEX [TypeId] ON [dbo].[Qianbo_DownLoadServerData] ([DownLoadServerDataId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerData_Delete]'
GO
CREATE PROC [dbo].[Proc_DownLoadServerData_Delete] @DownLoadServerDataId INT
AS
    DELETE Qianbo_DownLoadServerData
    WHERE  [DownLoadServerDataId] = @DownLoadServerDataId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_LabelContent]'
GO
CREATE TABLE [dbo].[Qianbo_LabelContent]
(
[LabelCategoryID] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [text] COLLATE Chinese_PRC_CI_AS NULL,
[AnomalyStyle] [text] COLLATE Chinese_PRC_CI_AS NULL,
[LbCategoryId] [int] NULL,
[ModeType] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_LabelContent] on [dbo].[Qianbo_LabelContent]'
GO
ALTER TABLE [dbo].[Qianbo_LabelContent] ADD CONSTRAINT [PK_Qianbo_LabelContent] PRIMARY KEY CLUSTERED  ([LabelCategoryID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_ConByName]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_ConByName] @Name NVARCHAR(50)
AS
    SELECT Content
    FROM   Qianbo_LabelContent
    WHERE  NAME = @Name
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Anomaly_GetList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Anomaly_GetList] @chid        INT,
                                         @pageindex   INT,
                                         @pagesize    INT,
                                         @recordcount INT output
AS
    DECLARE @sqlstr NVARCHAR(2000)
    IF( @pageindex = 1 )
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' * from Qianbo_Anomaly where [chid] = '
                  + CONVERT(NVARCHAR(15), @chid)
                  + ' order by id desc'
    ELSE
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' * from Qianbo_Anomaly where [chid] = '
                  + CONVERT(NVARCHAR(15), @chid)
                  + ' and id < (select min(id) from (select top '
                  + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                  + ' id from Qianbo_Anomaly where [chid] = '
                  + CONVERT(NVARCHAR(15), @chid)
                  + ' order by id desc)o) order by id desc'
    EXECUTE Sp_executeSql
      @sqlstr
    SET @recordcount =(SELECT Count(chid)
                       FROM   Qianbo_Anomaly
                       WHERE  chid = @chid)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_CheckExistsChannel]'
GO
CREATE PROCEDURE [dbo].[Proc_Model_CheckExistsChannel] @modelid INT
AS
    IF EXISTS(SELECT *
              FROM   Qianbo_Channel
              WHERE  modeltype = @modelid)
      SELECT 1
    ELSE
      SELECT 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserSpace_GetPrevPower]'
GO
CREATE PROC [dbo].[Proc_UserSpace_GetPrevPower] @userId INT
AS
    SELECT PrevPower
    FROM   Qianbo_UserSpace
    WHERE  UserId = @userId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_Delete] @SuperId INT
AS
    DELETE [Qianbo_SuperLabel]
    WHERE  [SuperId] = @SuperId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_GetList]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_GetList] @ModelId INT
AS
    SELECT *
    FROM   [Qianbo_UserGroupModelField]
    WHERE  ModelId = @ModelId
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerData_GetInfo]'
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_DownLoadServerData_GetInfo] @DownLoadServerDataId INT
AS
    SELECT [DownLoadServerDataId],
           [TypeId],
           [DownLoadServerName],
           [DownLoadServerDir],
           [IsOpened],
           [IsOuter],
           [UnionId],
           [DayDownNum],
           [AllDownNum],
           [AddTime]
    FROM   Qianbo_DownLoadServerData
    WHERE  [DownLoadServerDataId] = @DownLoadServerDataId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_GetContent]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_GetContent] @LabelCategoryID INT
AS
    SELECT Content
    FROM   Qianbo_LabelContent
    WHERE  LabelCategoryID = @LabelCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_GetModel]'
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_GetModel] @FieldId INT=0,
                                                           @ModelId INT=0,
                                                           @Name    NVARCHAR(50)=" ",
                                                           @TypeId  INT
AS
    IF @TypeId = 1
      SELECT *
      FROM   [Qianbo_UserGroupModelField]
      WHERE  FieldId = @FieldId
    ELSE
      SELECT *
      FROM   [Qianbo_UserGroupModelField]
      WHERE  ModelId = @ModelId
             AND [Name] = @Name
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserSpace_Set]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_UserSpace_Set] @Id               INT output,
                                            @SpaceName        NVARCHAR(50),
                                            @SpaceDescription NVARCHAR(500),
                                            @PrevPower        INT,
                                            @Password         NVARCHAR(50),
                                            @AddTime          NVARCHAR(50),
                                            @UserId           INT,
                                            @UserName         NVARCHAR(50),
                                            @TemplateId       INT,
                                            @UserType         INT
AS
    IF( @Id = 0 )
      BEGIN
          INSERT INTO Qianbo_UserSpace
                      ([SpaceName],
                       [SpaceDescription],
                       [PrevPower],
                       [Password],
                       [AddTime],
                       [UserId],
                       [UserName],
                       [TemplateId],
                       [UserType])
          VALUES      ( @SpaceName,
                        @SpaceDescription,
                        @PrevPower,
                        @Password,
                        @AddTime,
                        @UserId,
                        @UserName,
                        @TemplateId,
                        @UserType )
          SET @Id=Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_UserSpace
          SET    [SpaceName] = @SpaceName,
                 [SpaceDescription] = @SpaceDescription,
                 [PrevPower] = @PrevPower,
                 [Password] = @Password,
                 [UserId] = @UserId,
                 [UserName] = @UserName,
                 [TemplateId] = @TemplateId,
                 [UserType] = @UserType
          WHERE  [Id] = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_GetModel] @SuperId INT
AS
    SELECT [SuperId],
           [Name],
           [LbCategoryName],
           [LbCategoryId],
           [DataBaseType],
           [SuperDes],
           [IsUnlockPage],
           [HostTable],
           [GuestTable],
           [SqlStr],
           [Content],
           [AddTime],
           [PageSize],
           [NumColumns],
           [IsHtml],
           [DataBaseConn]
    FROM   [Qianbo_SuperLabel]
    WHERE  [SuperId] = @SuperId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_CheckUploadPathValidate]'
GO
CREATE PROCEDURE [dbo].[Proc_Model_CheckUploadPathValidate] @UploadPath NVARCHAR(50)
AS
    IF EXISTS (SELECT *
               FROM   Qianbo_Model
               WHERE  UploadPath = @UploadPath)
      SELECT 0
    ELSE
      SELECT 1
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Report_SetStatus]'
GO
CREATE PROCEDURE [dbo].[Proc_Report_SetStatus] @ReportId INT,
                                               @Status   INT
AS
    UPDATE Qianbo_Report
    SET    IsComplete = @Status
    WHERE  ReportId = @ReportId
           AND IsComplete = 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_GetInfo]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_GetInfo] @LabelCategoryID INT
AS
    SELECT [LabelCategoryID],
           [Name],
           [Content],
           [LbCategoryId],
           [ModeType],
           [AnomalyStyle]
    FROM   Qianbo_LabelContent
    WHERE  [LabelCategoryID] = @LabelCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ViewLog_Add]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_ViewLog_Add] @UserId    INT,
                                          @UserName  NVARCHAR(20),
                                          @ModelType INT,
                                          @InfoId    INT,
                                          @AddTime   DATETIME
AS
    INSERT INTO Qianbo_ViewLog
                ([UserId],
                 [UserName],
                 [ModelType],
                 [InfoId],
                 [AddTime])
    VALUES      (@UserId,
                 @UserName,
                 @ModelType,
                 @InfoId,
                 @AddTime)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_GetTitleList]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_GetTitleList] @ModelId INT
AS
    SELECT *
    FROM   [Qianbo_UserGroupModelField]
    WHERE  IsList = 1
           AND ModelId = @ModelId
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_StyleCategory_GetList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[Proc_StyleCategory_GetList] @ParentID INT
AS
    SELECT [StyleCategoryID],
           [Name],
           [ParentID],
           [Desc]
    FROM   Qianbo_StyleCategory
    WHERE  ParentID = @ParentID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_Delete]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Model_Delete] @modelid INT
AS
    DECLARE @tablename NVARCHAR(50)
    SET @tablename=''
    SET @tablename=(SELECT tablename
                    FROM   Qianbo_Model
                    WHERE  modelid = @modelid)
    DECLARE @sqlstr NVARCHAR(1000)
    DECLARE @param NVARCHAR(100);
    SET @param='@tmodelid int'
    IF( @tablename != '' )
      BEGIN
          SET @sqlstr = N'delete from Qianbo_Model where modelid = @tmodelid'
          EXEC sp_executesql
            @sqlstr,
            @param,
            @tmodelid = @modelid
          SET @sqlstr = N'drop table [' + @tablename + ']'
          EXEC sp_executesql
            @sqlstr
          SET @sqlstr = N'delete from Qianbo_ModelField where modelId = @tmodelid'
          EXEC sp_executesql
            @sqlstr,
            @param,
            @tmodelid = @modelid
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_MoveField]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_MoveField] @ModelId  INT,
                                                            @FieldId  INT,
                                                            @MoveType NVARCHAR(20)
AS
    DECLARE @OrderId INT;
    DECLARE @NewFieldId INT;
    DECLARE @NewOrderId INT;
    IF @MoveType = 'UpMove'
      BEGIN
          DECLARE @MinOrderId INT;
          SET @MinOrderId=(SELECT Min(OrderId)
                           FROM   [Qianbo_UserGroupModelField]
                           WHERE  ModelId = @ModelId)
          SET @OrderId=(SELECT OrderId
                        FROM   [Qianbo_UserGroupModelField]
                        WHERE  ModelId = @ModelId
                               AND FieldId = @FieldId)
          IF @OrderId != @MinOrderId
            BEGIN
                SET @NewFieldId=(SELECT TOP 1 FieldId
                                 FROM   [Qianbo_UserGroupModelField]
                                 WHERE  ModelId = @ModelId
                                        AND OrderId < @OrderId
                                 ORDER  BY OrderId DESC)
                SET @NewOrderId=(SELECT OrderId
                                 FROM   [Qianbo_UserGroupModelField]
                                 WHERE  ModelId = @ModelId
                                        AND FieldId = @NewFieldId)
                UPDATE [Qianbo_UserGroupModelField]
                SET    OrderId = @OrderId
                WHERE  FieldId = @NewFieldId
                       AND ModelId = @ModelId
                UPDATE [Qianbo_UserGroupModelField]
                SET    OrderId = @NewOrderId
                WHERE  FieldId = @FieldId
                       AND ModelId = @ModelId
            END
      END
    IF @MoveType = 'DownMove'
      BEGIN
          DECLARE @MaxOrderId INT;
          SET @MaxOrderId=(SELECT Max(OrderId)
                           FROM   [Qianbo_UserGroupModelField]
                           WHERE  ModelId = @ModelId)
          SET @OrderId=(SELECT OrderId
                        FROM   [Qianbo_UserGroupModelField]
                        WHERE  ModelId = @ModelId
                               AND FieldId = @FieldId)
          IF @OrderId != @MaxOrderId
            BEGIN
                SET @NewFieldId=(SELECT TOP 1 FieldId
                                 FROM   [Qianbo_UserGroupModelField]
                                 WHERE  ModelId = @ModelId
                                        AND OrderId > @OrderId
                                 ORDER  BY OrderId)
                SET @NewOrderId=(SELECT OrderId
                                 FROM   [Qianbo_UserGroupModelField]
                                 WHERE  ModelId = @ModelId
                                        AND FieldId = @NewFieldId)
                UPDATE [Qianbo_UserGroupModelField]
                SET    OrderId = @OrderId
                WHERE  FieldId = @NewFieldId
                       AND ModelId = @ModelId
                UPDATE [Qianbo_UserGroupModelField]
                SET    OrderId = @NewOrderId
                WHERE  FieldId = @FieldId
                       AND ModelId = @ModelId
            END
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_CollectionAddress]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_CollectionAddress]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ColectionId] [int] NULL,
[CollectionUrl] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[State] [bit] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_CollectionAddress] on [dbo].[Qianbo_CollectionAddress]'
GO
ALTER TABLE [dbo].[Qianbo_CollectionAddress] ADD CONSTRAINT [PK_CollectionAddress] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CollectionAddress_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_CollectionAddress_Add] @ColectionId   INT,
                                                    @CollectionUrl NVARCHAR(1000),
                                                    @State         BIT
AS
    INSERT INTO Qianbo_CollectionAddress
                ([ColectionId],
                 [CollectionUrl],
                 [State])
    VALUES      ( @ColectionId,
                  @CollectionUrl,
                  @State )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_SelectPropertyTrue]'
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_SelectPropertyTrue] @ModelId NVARCHAR(50)
AS
    SELECT *
    FROM   [Qianbo_UserGroupModelField]
    WHERE  ModelId = @ModelId
           AND Type = 'RadioType'
           AND Content LIKE '%Property=True%'
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_DownLoadServerType]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_DownLoadServerType]
(
[TypeId] [int] NOT NULL IDENTITY(1, 1),
[TypeName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF_Qianbo_DownLoadServerType_TypeName] DEFAULT ('')
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_DownLoadServerType] on [dbo].[Qianbo_DownLoadServerType]'
GO
ALTER TABLE [dbo].[Qianbo_DownLoadServerType] ADD CONSTRAINT [PK_Qianbo_DownLoadServerType] PRIMARY KEY CLUSTERED  ([TypeId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerData_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadServerData_GetList] @TypeId INT
AS
    SELECT [DownLoadServerDataId],
           D.[TypeId],
           [DownLoadServerName],
           [DownLoadServerDir],
           [IsOpened],
           [IsOuter],
           [UnionId],
           [DayDownNum],
           [AllDownNum],
           [AddTime],
           T.[TypeName],
           T.[TypeId]
    FROM   Qianbo_DownLoadServerData D
           JOIN Qianbo_DownLoadServerType T
             ON D.TypeId = T.[TypeId]
    WHERE  D.TypeId = @TypeId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_GetSuperId]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_GetSuperId] @Name NVARCHAR(150)
AS
    DECLARE @SuperId INT;
    SET @SuperId=(SELECT TOP 1 SuperId
                  FROM   [Qianbo_SuperLabel]
                  WHERE  [Name] = @Name
                  ORDER  BY SuperId DESC)
    IF @SuperId IS NULL
      SELECT 0
    ELSE
      SELECT @SuperId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_GetInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_Model_GetInfo] @modelid INT
AS
    SELECT *
    FROM   Qianbo_Model
    WHERE  modelid = @modelid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_GetLabelByModelId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_GetLabelByModelId] @modelId INT
AS
    SELECT *
    FROM   Qianbo_LabelContent
    WHERE  ModeType = @modelId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_SetDigCount]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Create_SetDigCount] @modelid INT,
                                            @infoid  INT
AS
    IF EXISTS(SELECT *
              FROM   Qianbo_Dig
              WHERE  modelid = @modelid
                     AND infoid = @infoid)
      UPDATE Qianbo_Dig
      SET    digcount = digcount + 1
      WHERE  modelid = @modelid
             AND infoid = @infoid
    ELSE
      INSERT INTO Qianbo_Dig
                  (modelid,
                   infoid,
                   digcount)
      SELECT @modelid,
             @infoid,
             1
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CollectionAddress_CheckAddress]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_CollectionAddress_CheckAddress] @collectionaddress NVARCHAR(500)
AS
    SELECT CollectionUrl
    FROM   Qianbo_CollectionAddress
    WHERE  CollectionUrl = @collectionaddress
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModelField_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModelField_Update] @FieldId      INT,
                                                         @ModelId      INT,
                                                         @Alias        NVARCHAR(300),
                                                         @Description  NVARCHAR(400),
                                                         @IsNotNull    BIT,
                                                         @IsSearchForm BIT,
                                                         @Content      NTEXT,
                                                         @IsList       BIT,
                                                         @IsUserInsert BIT,
                                                         @AddDate      DATETIME
AS
    UPDATE [Qianbo_UserGroupModelField]
    SET    [Alias] = @Alias,
           [Description] = @Description,
           [IsNotNull] = @IsNotNull,
           [IsSearchForm] = @IsSearchForm,
           [Content] = @Content,
           [IsList] = @IsList,
           [IsUserInsert] = @IsUserInsert,
           [AddDate] = @AddDate
    WHERE  [FieldId] = @FieldId
           AND ModelId = @ModelId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_IsModelTable]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_IsModelTable] @TableName NVARCHAR(100)
AS
    IF EXISTS(SELECT *
              FROM   [Qianbo_Model]
              WHERE  TableName = @TableName)
      SELECT 1
    ELSE
      SELECT 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_GetList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Model_GetList]
AS
    SELECT *
    FROM   Qianbo_Model
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CollectionAddress_DeleteCollId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_CollectionAddress_DeleteCollId] @collid INT,
                                                             @state  BIT
AS
    DELETE FROM Qianbo_CollectionAddress
    WHERE  ColectionId = @collid
           AND State = @state
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserGroupModel]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_UserGroupModel]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[TableName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[IsHtml] [bit] NULL,
[ModelHtml] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[IsValidate] [bit] NULL,
[UserGroupId] [int] NULL,
[AddTime] [datetime] NULL,
[SpaceTypeId] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_UserGroupModel] on [dbo].[Qianbo_UserGroupModel]'
GO
ALTER TABLE [dbo].[Qianbo_UserGroupModel] ADD CONSTRAINT [PK_Qianbo_UserGroupModel] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_Add] @Name        NVARCHAR(100),
                                                 @TableName   NVARCHAR(200),
                                                 @Content     NVARCHAR(1000),
                                                 @ModelHtml   NTEXT,
                                                 @AddTime     DATETIME,
                                                 @IsValidate  BIT,
                                                 @UserGroupId INT,
                                                 @IsHtml      BIT,
                                                 @SpaceTypeId INT
AS
    INSERT INTO Qianbo_UserGroupModel
                ([Name],
                 [TableName],
                 [Content],
                 [ModelHtml],
                 [AddTime],
                 [IsValidate],
                 [UserGroupId],
                 [IsHtml],
                 [SpaceTypeId])
    VALUES      (@Name,
                 @TableName,
                 @Content,
                 @ModelHtml,
                 @AddTime,
                 @IsValidate,
                 @UserGroupId,
                 @IsHtml,
                 @SpaceTypeId)
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_GetLbCategoryNameList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROC [dbo].[Proc_LabelContent_GetLbCategoryNameList] @labelName   NVARCHAR(200),
                                                            @CursorPage  INT,
                                                            @PageSize    INT,
                                                            @RecordCount INT output
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CursorPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_LabelContent where [Name] like @tlabelName order by LabelCategoryID desc'
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_LabelContent where [Name] like @tlabelName and LabelCategoryID < (select min(LabelCategoryID) from(select top '
                  + CONVERT(NVARCHAR(15), (@CursorPage - 1) * @PageSize)
                  + ' LabelCategoryID from Qianbo_LabelContent where [Name] like @tlabelName order by LabelCategoryID desc)O)order by LabelCategoryID desc'
    DECLARE @paramlb NVARCHAR(500)
    SET @paramlb=N'@tlabelName Nvarchar(200)'
    EXECUTE Sp_executeSql
      @SqlStr,
      @paramlb,
      @tlabelName = @labelName
    SET @RecordCount=(SELECT Count(LabelCategoryID)
                      FROM   Qianbo_LabelContent
                      WHERE  [Name] LIKE @labelName)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CollectionAddress_GetCollIdList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_CollectionAddress_GetCollIdList] @collid      INT,
                                                         @state       BIT,
                                                         @pageindex   INT,
                                                         @pagesize    INT,
                                                         @recordcount INT output
AS
    DECLARE @sqlstr NVARCHAR(2000);
    IF( @pageindex = 1 )
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' * from Qianbo_CollectionAddress where ColectionId = '
                  + CONVERT(NVARCHAR (15), @collid)
                  + ' and state = '
                  + CONVERT(NVARCHAR(15), @state)
                  + '  order by id desc'
    ELSE
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' * from Qianbo_CollectionAddress where id < (select min(id) from (select top '
                  + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                  + ' id from Qianbo_CollectionAddress where ColectionId =  '
                  + CONVERT(NVARCHAR(15), @collid)
                  + ' and state = '
                  + CONVERT(NVARCHAR(15), @state)
                  + ' order by id desc)o) and ColectionId = '
                  + CONVERT(NVARCHAR(15), @collid)
                  + ' and state = '
                  + CONVERT(NVARCHAR(15), @state)
                  + ' order by id desc'
    EXECUTE Sp_executeSql
      @sqlstr
    SET @recordcount=(SELECT Count(id)
                      FROM   Qianbo_CollectionAddress
                      WHERE  ColectionId = @collid
                             AND State = @state)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_Update] @SuperId        INT,
                                                @Name           NVARCHAR(100),
                                                @LbCategoryName NVARCHAR(100),
                                                @LbCategoryId   INT,
                                                @DataBaseType   INT,
                                                @SuperDes       NVARCHAR(1000),
                                                @IsUnlockPage   BIT,
                                                @HostTable      NVARCHAR(100),
                                                @GuestTable     NVARCHAR(100),
                                                @SqlStr         NVARCHAR(1000),
                                                @Content        NTEXT,
                                                @AddTime        DATETIME,
                                                @PageSize       INT,
                                                @NumColumns     INT,
                                                @IsHtml         BIT,
                                                @DataBaseConn   NVARCHAR(300)=" "
AS
    UPDATE [Qianbo_SuperLabel]
    SET    [Name] = @Name,
           [LbCategoryName] = @LbCategoryName,
           [LbCategoryId] = @LbCategoryId,
           [DataBaseType] = @DataBaseType,
           [SuperDes] = @SuperDes,
           [IsUnlockPage] = @IsUnlockPage,
           [HostTable] = @HostTable,
           [GuestTable] = @GuestTable,
           [SqlStr] = @SqlStr,
           [Content] = @Content,
           [AddTime] = @AddTime,
           PageSize = @PageSize,
           NumColumns = @NumColumns,
           IsHtml = @IsHtml,
           DataBaseConn = @DataBaseConn
    WHERE  [SuperId] = @SuperId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_GetList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_GetList]
AS
    SELECT *
    FROM   [Qianbo_LabelContent]
    ORDER  BY LabelCategoryID DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_CustomFormField]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_CustomFormField]
(
[FieldId] [int] NOT NULL IDENTITY(1, 1),
[CustomFormId] [int] NULL,
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Alias] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL,
[Description] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[IsNotNull] [bit] NULL,
[IsSearchForm] [bit] NULL,
[Type] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[OrderId] [int] NULL CONSTRAINT [DF_Qianbo_CustomFormField_OrderId] DEFAULT ((0)),
[IsList] [bit] NULL,
[IsUserInsert] [bit] NULL,
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_CustomFormField] on [dbo].[Qianbo_CustomFormField]'
GO
ALTER TABLE [dbo].[Qianbo_CustomFormField] ADD CONSTRAINT [PK_Qianbo_CustomFormField] PRIMARY KEY CLUSTERED  ([FieldId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_Add] @CustomFormId INT,
                                                  @Name         NVARCHAR(100),
                                                  @Alias        NVARCHAR(300),
                                                  @Description  NVARCHAR(400),
                                                  @IsNotNull    BIT,
                                                  @IsSearchForm BIT,
                                                  @Type         NVARCHAR(100),
                                                  @Content      NTEXT,
                                                  @IsList       BIT,
                                                  @IsUserInsert BIT,
                                                  @AddDate      DATETIME
AS
    DECLARE @OrderId INT;
    SET @OrderId=(SELECT Max(OrderId)
                  FROM   [Qianbo_CustomFormField]
                  WHERE  CustomFormId = @CustomFormId)
    IF @OrderId IS NULL
      SET @OrderId=0
    ELSE
      SET @OrderId = @OrderId + 1
    INSERT INTO [Qianbo_CustomFormField]
                ([CustomFormId],
                 [Name],
                 [Alias],
                 [Description],
                 [IsNotNull],
                 [IsSearchForm],
                 [Type],
                 [Content],
                 [AddDate],
                 [OrderId],
                 [IsList],
                 [IsUserInsert])
    VALUES      (@CustomFormId,
                 @Name,
                 @Alias,
                 @Description,
                 @IsNotNull,
                 @IsSearchForm,
                 @Type,
                 @Content,
                 @AddDate,
                 @OrderId,
                 @IsList,
                 @IsUserInsert)
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CollectionAddress_GetCollidByAddress]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_CollectionAddress_GetCollidByAddress] @collectionid INT
AS
    SELECT CollectionUrl
    FROM   Qianbo_CollectionAddress
    WHERE  ColectionId = @collectionid
           AND state = 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_ModelHtml]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Model_ModelHtml] @ModelHtml NTEXT,
                                              @ModelId   INT
AS
    UPDATE [Qianbo_Model]
    SET    ModelHtml = @ModelHtml
    WHERE  ModelId = @ModelId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_Del]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_Del] @FieldId INT
AS
    DELETE FROM [Qianbo_CustomFormField]
    WHERE  FieldId = @FieldId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_Delete]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_Delete] @Id INT
AS
    DECLARE @tablename NVARCHAR(50)
    SET @tablename=''
    SET @tablename=(SELECT TableName
                    FROM   [Qianbo_UserGroupModel]
                    WHERE  [Id] = @Id)
    DECLARE @sqlstr NVARCHAR(500)
    IF( @tablename != '' )
      BEGIN
          SET @sqlstr = N'delete from [Qianbo_UserGroupModel] where [Id] = '
                        + CONVERT(NVARCHAR(15), @Id)
          EXEC sp_executesql
            @sqlstr
          SET @sqlstr = N'drop table [' + @tablename + ']'
          EXEC sp_executesql
            @sqlstr
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Superior]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Superior]
(
[id] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[StartCode] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[EndCode] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Superior] on [dbo].[Qianbo_Superior]'
GO
ALTER TABLE [dbo].[Qianbo_Superior] ADD CONSTRAINT [PK_Qianbo_Superior] PRIMARY KEY CLUSTERED  ([id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Superior_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Superior_Add] @Name      NVARCHAR(400),
                                           @StartCode NVARCHAR(1000),
                                           @EndCode   NVARCHAR(1000)
AS
    INSERT INTO Qianbo_Superior
                ([Name],
                 [StartCode],
                 [EndCode])
    VALUES      ( @Name,
                  @StartCode,
                  @EndCode )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_GetIsUserList]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_GetIsUserList] @CustomFormId INT
AS
    SELECT *
    FROM   [Qianbo_CustomFormField]
    WHERE  CustomFormId = @CustomFormId
           AND IsUserInsert = 1
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_Set]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_Set] @LabelCategoryID INT,
                                               @Name            NVARCHAR(100),
                                               @Content         TEXT,
                                               @LbCategoryId    INT,
                                               @ModeType        INT,
                                               @AnomalyStyle    TEXT
AS
    IF( @LabelCategoryID <= 0 )
      BEGIN
          INSERT INTO Qianbo_LabelContent
                      ([Name],
                       [Content],
                       [LbCategoryId],
                       [ModeType],
                       [AnomalyStyle])
          VALUES      (@Name,
                       @Content,
                       @LbCategoryId,
                       @ModeType,
                       @AnomalyStyle)
      END
    ELSE
      BEGIN
          UPDATE Qianbo_LabelContent
          SET    [Name] = @Name,
                 [Content] = @Content,
                 [LbCategoryId] = @LbCategoryId,
                 [ModeType] = @ModeType,
                 [AnomalyStyle] = @AnomalyStyle
          WHERE  [LabelCategoryID] = @LabelCategoryID
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_GetAll]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_GetAll]
AS
    SELECT [Id],
           [Name],
           [TableName],
           [Content],
           [ModelHtml],
           [AddTime],
           [IsValidate],
           [UserGroupId],
           [IsHtml],
           [SpaceTypeId]
    FROM   [Qianbo_UserGroupModel]
    ORDER  BY Id DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_AddFriend]'
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_User_AddFriend] @UserId        INT,
                                        @FriendName    NVARCHAR(20),
                                        @FriendGroupId INT,
                                        @Flag          INT=0 output
AS
    DECLARE @FriendId INT
    IF EXISTS(SELECT [UserID]
              FROM   Qianbo_Users
              WHERE  LogName = @FriendName)
      BEGIN
          SELECT @FriendId = UserId
          FROM   Qianbo_Users
          WHERE  LogName = @FriendName
          IF EXISTS(SELECT *
                    FROM   Qianbo_UserFriend
                    WHERE  UserId = @UserId
                           AND FriendId = @FriendId)
            BEGIN
                SET @Flag=1
            END
          ELSE
            BEGIN
                INSERT INTO Qianbo_UserFriend
                VALUES      (@UserId,
                             @FriendId,
                             @FriendGroupId)
                SET @Flag=3
            END
      END
    ELSE
      SET @Flag=2
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CollectionAddress_UpdateState]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_CollectionAddress_UpdateState] @collectionaddress NVARCHAR(500)
AS
    UPDATE Qianbo_CollectionAddress
    SET    State = 1
    WHERE  CollectionUrl = @collectionaddress
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_Set]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Model_Set] @ModelId    INT,
                                        @ModelName  NVARCHAR(20),
                                        @ModelDesc  NVARCHAR(200),
                                        @TableName  NVARCHAR(50),
                                        @UploadPath VARCHAR(50),
                                        @UploadSize INT,
                                        @ModelHtml  NTEXT,
                                        @IsHtml     BIT,
                                        @ModelSort  INT
AS
    IF( @ModelId = 0 )
      BEGIN
          INSERT INTO Qianbo_Model
                      (modelname,
                       modeldesc,
                       tablename,
                       uploadpath,
                       uploadsize,
                       ModelHtml,
                       IsHtml,
                       ModelSort)
          VALUES      (@modelname,
                       @modeldesc,
                       @tablename,
                       @uploadpath,
                       @uploadsize,
                       @ModelHtml,
                       @IsHtml,
                       @ModelSort)
          SELECT Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_Model
          SET    modelname = @modelname,
                 modeldesc = @modeldesc,
                 uploadpath = @uploadpath,
                 uploadsize = @uploadsize,
                 IsHtml = @IsHtml,
                 ModelSort = @ModelSort
          WHERE  modelid = @modelid
          SELECT @modelid
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Superior_Delete]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Superior_Delete] @id INT
AS
    DELETE Qianbo_Superior
    WHERE  [id] = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_GetList]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_GetList] @CustomFormId INT
AS
    SELECT *
    FROM   [Qianbo_CustomFormField]
    WHERE  CustomFormId = @CustomFormId
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_UpdateModelId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_UpdateModelId] @oldmodelid INT,
                                                         @newmodelid INT
AS
    UPDATE Qianbo_LabelContent
    SET    ModeType = @newmodelid
    WHERE  ModeType = @oldmodelid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_GetModel]'
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_GetModel] @Id INT
AS
    SELECT [Id],
           [Name],
           [TableName],
           [Content],
           [ModelHtml],
           [AddTime],
           [IsValidate],
           [UserGroupId],
           [IsHtml],
           [SpaceTypeId]
    FROM   Qianbo_UserGroupModel
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Review]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Review]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ModelType] [int] NOT NULL,
[InfoId] [int] NOT NULL,
[ReviewTitle] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[IsArgue] [bit] NULL,
[IsSquare] [tinyint] NULL,
[BrarNum] [int] NULL,
[FightNum] [int] NULL,
[IsElite] [bit] NULL,
[ReviewContent] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[ReviewTime] [datetime] NULL,
[UserNum] [nvarchar] (18) COLLATE Chinese_PRC_CI_AS NULL,
[ReviewIP] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[IsCheck] [bit] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Review] on [dbo].[Qianbo_Review]'
GO
ALTER TABLE [dbo].[Qianbo_Review] ADD CONSTRAINT [PK_Qianbo_Review] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Review] on [dbo].[Qianbo_Review]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Review] ON [dbo].[Qianbo_Review] ([ModelType])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Review_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Review_Add] @ModelType     INT,
                                         @InfoId        INT,
                                         @ReviewTitle   NVARCHAR(200),
                                         @IsArgue       BIT,
                                         @IsSquare      TINYINT,
                                         @BrarNum       INT,
                                         @FightNum      INT,
                                         @IsElite       BIT,
                                         @ReviewContent NTEXT,
                                         @ReviewTime    DATETIME,
                                         @UserNum       NVARCHAR(36),
                                         @ReviewIP      NVARCHAR(40),
                                         @IsCheck       BIT
AS
    INSERT INTO Qianbo_Review
                ([ModelType],
                 [InfoId],
                 [ReviewTitle],
                 [IsArgue],
                 [IsSquare],
                 [BrarNum],
                 [FightNum],
                 [IsElite],
                 [ReviewContent],
                 [ReviewTime],
                 [UserNum],
                 [ReviewIP],
                 [IsCheck])
    VALUES      (@ModelType,
                 @InfoId,
                 @ReviewTitle,
                 @IsArgue,
                 @IsSquare,
                 @BrarNum,
                 @FightNum,
                 @IsElite,
                 @ReviewContent,
                 @ReviewTime,
                 @UserNum,
                 @ReviewIP,
                 @IsCheck )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerData_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadServerData_Set] @DownLoadServerDataId INT=0,
                                                     @TypeId               INT,
                                                     @DownLoadServerName   NVARCHAR(100),
                                                     @DownLoadServerDir    NVARCHAR(100),
                                                     @IsOpened             BIT,
                                                     @IsOuter              INT,
                                                     @UnionId              TEXT='',
                                                     @DayDownNum           INT=0,
                                                     @AllDownNum           INT=0,
                                                     @AddTime              DATETIME
AS
    IF( @DownLoadServerDataId = 0 )
      BEGIN
          INSERT INTO Qianbo_DownLoadServerData
                      ([TypeId],
                       [DownLoadServerName],
                       [DownLoadServerDir],
                       [IsOpened],
                       [IsOuter],
                       [UnionId],
                       [DayDownNum],
                       [AllDownNum],
                       [AddTime])
          VALUES      ( @TypeId,
                        @DownLoadServerName,
                        @DownLoadServerDir,
                        @IsOpened,
                        @IsOuter,
                        @UnionId,
                        @DayDownNum,
                        @AllDownNum,
                        @AddTime )
          SET @DownLoadServerDataId=Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_DownLoadServerData
          SET    [TypeId] = @TypeId,
                 [DownLoadServerName] = @DownLoadServerName,
                 [DownLoadServerDir] = @DownLoadServerDir,
                 [IsOpened] = @IsOpened,
                 [IsOuter] = @IsOuter,
                 [UnionId] = @UnionId,
                 [DayDownNum] = @DayDownNum,
                 [AllDownNum] = @AllDownNum,
                 [AddTime] = @AddTime
          WHERE  [DownLoadServerDataId] = @DownLoadServerDataId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_Changepwd]'
GO
CREATE PROCEDURE [dbo].[Proc_User_Changepwd] (@LogName NVARCHAR(20),
                                              @newPwd  NVARCHAR(200))
AS
    UPDATE Qianbo_Users
    SET    UserPwd = @newPwd
    WHERE  LogName = @LogName
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Collection]'
GO
CREATE TABLE [dbo].[Qianbo_Collection]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ObjectName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[WebSite] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[ColId] [int] NULL,
[SpecialId] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[CharSet] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[ListPageUrl] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[ObjectDemo] [text] COLLATE Chinese_PRC_CI_AS NULL,
[ListStartCode] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[ListEndCode] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[LinkStartCode] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[LinkEndCode] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[PageSet] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NULL,
[ContentPageSet] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NULL,
[FieldListSet] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[SimpleFilterRule] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[ComplexityFilterRule] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[ProterySet] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[StarLevel] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[HiteCount] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Collection] on [dbo].[Qianbo_Collection]'
GO
ALTER TABLE [dbo].[Qianbo_Collection] ADD CONSTRAINT [PK_Qianbo_Collection] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Collection_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Collection_Add] @ObjectName           NVARCHAR(100),
                                             @WebSite              NVARCHAR(1000),
                                             @ColId                INT,
                                             @SpecialId            NVARCHAR(1000),
                                             @CharSet              NVARCHAR(100),
                                             @ListPageUrl          NVARCHAR(1000),
                                             @ObjectDemo           TEXT,
                                             @ListStartCode        NTEXT,
                                             @ListEndCode          NTEXT,
                                             @LinkStartCode        NTEXT,
                                             @LinkEndCode          NTEXT,
                                             @PageSet              NVARCHAR(2000),
                                             @ContentPageSet       NVARCHAR(2000),
                                             @FieldListSet         NTEXT,
                                             @SimpleFilterRule     NVARCHAR(100),
                                             @ComplexityFilterRule NVARCHAR(100),
                                             @ProterySet           NVARCHAR(100),
                                             @StarLevel            NVARCHAR(100),
                                             @HiteCount            INT
AS
    INSERT INTO Qianbo_Collection
                ([ObjectName],
                 [WebSite],
                 [ColId],
                 [SpecialId],
                 [CharSet],
                 [ListPageUrl],
                 [ObjectDemo],
                 [ListStartCode],
                 [ListEndCode],
                 [LinkStartCode],
                 [LinkEndCode],
                 [PageSet],
                 [ContentPageSet],
                 [FieldListSet],
                 [SimpleFilterRule],
                 [ComplexityFilterRule],
                 [ProterySet],
                 [StarLevel],
                 [HiteCount])
    VALUES      ( @ObjectName,
                  @WebSite,
                  @ColId,
                  @SpecialId,
                  @CharSet,
                  @ListPageUrl,
                  @ObjectDemo,
                  @ListStartCode,
                  @ListEndCode,
                  @LinkStartCode,
                  @LinkEndCode,
                  @PageSet,
                  @ContentPageSet,
                  @FieldListSet,
                  @SimpleFilterRule,
                  @ComplexityFilterRule,
                  @ProterySet,
                  @StarLevel,
                  @HiteCount )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Notice]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Notice]
(
[NoticeId] [int] NOT NULL IDENTITY(1, 1),
[Title] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[UserId] [int] NULL,
[UserName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[OverdueDate] [datetime] NULL,
[IsPriority] [int] NULL,
[IsState] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL,
[AddDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Notice] on [dbo].[Qianbo_Notice]'
GO
ALTER TABLE [dbo].[Qianbo_Notice] ADD CONSTRAINT [PK_Qianbo_Notice] PRIMARY KEY CLUSTERED  ([NoticeId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Notice]'
GO
CREATE PROCEDURE [dbo].[Proc_Notice] @NoticeId    INT=0,
                                     @Title       NVARCHAR(300)=" ",
                                     @Content     NTEXT=" ",
                                     @UserId      INT=0,
                                     @UserName    NVARCHAR(100)=" ",
                                     @OverdueDate DATETIME=" ",
                                     @IsPriority  INT=0,
                                     @IsState     NVARCHAR(20)=" ",
                                     @AddDate     DATETIME=" ",
                                     @TypeId      INT=0
AS
    IF @TypeId = 1
      BEGIN
          INSERT INTO Qianbo_Notice
                      ([Title],
                       [Content],
                       [UserId],
                       [UserName],
                       [OverdueDate],
                       [IsPriority],
                       [IsState],
                       [AddDate])
          VALUES      (@Title,
                       @Content,
                       @UserId,
                       @UserName,
                       @OverdueDate,
                       @IsPriority,
                       @IsState,
                       @AddDate)
      END
    IF @TypeId = 2
      BEGIN
          UPDATE Qianbo_Notice
          SET    [Title] = @Title,
                 [Content] = @Content,
                 [UserId] = @UserId,
                 [UserName] = @UserName,
                 [OverdueDate] = @OverdueDate,
                 [IsPriority] = @IsPriority,
                 [IsState] = @IsState,
                 [AddDate] = @AddDate
          WHERE  [NoticeId] = @NoticeId
      END
    IF @TypeId = 3
      BEGIN
          DELETE Qianbo_Notice
          WHERE  [NoticeId] = @NoticeId
      END
    IF @TypeId = 4
      BEGIN
          SELECT [NoticeId],
                 [Title],
                 [Content],
                 [UserId],
                 [UserName],
                 [OverdueDate],
                 [IsPriority],
                 [IsState],
                 [AddDate]
          FROM   Qianbo_Notice
          WHERE  NoticeId = @NoticeId
      END
    IF @TypeId = 5
      BEGIN
          UPDATE Qianbo_Notice
          SET    [IsState] = @IsState
          WHERE  [NoticeId] = @NoticeId
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerData_SetIsOpened]'
GO
CREATE PROC [dbo].[Proc_DownLoadServerData_SetIsOpened] @DownServerId INT,
                                                        @IsOpened     BIT
AS
    UPDATE Qianbo_DownLoadServerData
    SET    IsOpened = @IsOpened
    WHERE  DownLoadServerDataId = @DownServerId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Superior_GetIdBySuperiorl]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Superior_GetIdBySuperiorl] @id INT
AS
    SELECT [id],
           [Name],
           [StartCode],
           [EndCode]
    FROM   Qianbo_Superior
    WHERE  [id] = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Image]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Image]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ChId] [int] NULL CONSTRAINT [DF_Qianbo_Image_ChId] DEFAULT ((0)),
[ColId] [int] NOT NULL CONSTRAINT [DF_Qianbo_Image_ColId] DEFAULT ((0)),
[Title] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_Title] DEFAULT (''),
[TitleColor] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_TitleColor] DEFAULT ((0)),
[TitleFontType] [int] NULL CONSTRAINT [DF_Qianbo_Image_TitleFontType] DEFAULT ((0)),
[TitleType] [int] NULL CONSTRAINT [DF_Qianbo_Image_TitleType] DEFAULT ((0)),
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_TitleImgPath] DEFAULT (''),
[UId] [int] NOT NULL,
[UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UserType] [int] NOT NULL,
[AdminUId] [int] NULL,
[AdminUName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_AdminUName] DEFAULT (''),
[Status] [int] NULL CONSTRAINT [DF_Qianbo_Image_Status] DEFAULT ((0)),
[HitCount] [int] NULL CONSTRAINT [DF_Qianbo_Image_HitsCount] DEFAULT ((0)),
[AddTime] [datetime] NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_TemplatePath] DEFAULT (''),
[PageType] [int] NULL CONSTRAINT [DF_Qianbo_Image_PageType] DEFAULT ((1)),
[IsCreated] [bit] NULL CONSTRAINT [DF_Qianbo_Image_IsCreated] DEFAULT ((0)),
[UserCateId] [int] NULL CONSTRAINT [DF_Qianbo_Image_UserCateId] DEFAULT ((0)),
[PointCount] [int] NULL CONSTRAINT [DF_Qianbo_Image_PointCount] DEFAULT ((0)),
[ChargeType] [int] NULL CONSTRAINT [DF_Qianbo_Image_ChargeType] DEFAULT ((1)),
[ChargeHourCount] [int] NULL CONSTRAINT [DF_Qianbo_Image_ChargeHourCount] DEFAULT ((0)),
[ChargeViewCount] [int] NULL CONSTRAINT [DF_Qianbo_Image_ChargeViewCount] DEFAULT ((0)),
[IsOpened] [int] NULL CONSTRAINT [DF_Qianbo_Image_IsOpened] DEFAULT ((2)),
[GroupIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_GroupIdStr] DEFAULT (''),
[IsDeleted] [bit] NOT NULL CONSTRAINT [DF_Qianbo_Image_IsDeleted] DEFAULT ((0)),
[IsRecommend] [bit] NULL CONSTRAINT [DF_Qianbo_Image_IsRecommend] DEFAULT ((0)),
[IsTop] [bit] NULL CONSTRAINT [DF_Qianbo_Image_IsTop] DEFAULT ((0)),
[IsFocus] [bit] NULL CONSTRAINT [DF_Qianbo_Image_IsFocus] DEFAULT ((0)),
[IsSideShow] [bit] NULL CONSTRAINT [DF_Qianbo_Image_IsSideShow] DEFAULT ((0)),
[TagIdStr] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_TagIdStr] DEFAULT (''),
[IsAllowComment] [bit] NULL CONSTRAINT [DF_Qianbo_Image_IsAllowComment] DEFAULT ((0)),
[TagNameStr] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_TagNameStr] DEFAULT (''),
[SpecialIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_SpecialIdStr] DEFAULT (''),
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_Content] DEFAULT (''),
[ImgPath] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_Image_ImgPath] DEFAULT ('')
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Image] on [dbo].[Qianbo_Image]'
GO
ALTER TABLE [dbo].[Qianbo_Image] ADD CONSTRAINT [PK_Qianbo_Image] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Image_AddTime] on [dbo].[Qianbo_Image]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Image_AddTime] ON [dbo].[Qianbo_Image] ([AddTime])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Image_ChId] on [dbo].[Qianbo_Image]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Image_ChId] ON [dbo].[Qianbo_Image] ([ChId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Image_ColId] on [dbo].[Qianbo_Image]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Image_ColId] ON [dbo].[Qianbo_Image] ([ColId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Image_SpecialIdStr] on [dbo].[Qianbo_Image]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Image_SpecialIdStr] ON [dbo].[Qianbo_Image] ([SpecialIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Image_TagIdStr] on [dbo].[Qianbo_Image]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Image_TagIdStr] ON [dbo].[Qianbo_Image] ([TagIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Image_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Image_Add] @ChId            INT,
                                        @ColId           INT,
                                        @Title           NVARCHAR(200),
                                        @TitleColor      NVARCHAR(12),
                                        @TitleFontType   INT,
                                        @TitleType       INT,
                                        @TitleImgPath    VARCHAR(255),
                                        @UId             INT,
                                        @UName           NVARCHAR(40),
                                        @UserType        INT,
                                        @AdminUId        INT,
                                        @AdminUName      CHAR(10),
                                        @Status          INT,
                                        @HitCount        INT,
                                        @AddTime         DATETIME,
                                        @UpdateTime      DATETIME,
                                        @TemplatePath    VARCHAR(255),
                                        @PageType        INT,
                                        @IsCreated       BIT,
                                        @UserCateId      INT,
                                        @PointCount      INT,
                                        @ChargeType      INT,
                                        @ChargeHourCount INT,
                                        @ChargeViewCount INT,
                                        @IsOpened        INT,
                                        @GroupIdStr      VARCHAR(200),
                                        @IsDeleted       BIT,
                                        @IsRecommend     BIT,
                                        @IsTop           BIT,
                                        @IsFocus         BIT,
                                        @IsSideShow      BIT,
                                        @TagIdStr        VARCHAR(300),
                                        @IsAllowComment  BIT,
                                        @TagNameStr      NVARCHAR(600),
                                        @SpecialIdStr    VARCHAR(200),
                                        @Content         NTEXT,
                                        @ImgPath         NTEXT,
                                        @Identity        INT=0 output
AS
    INSERT INTO Qianbo_Image
                ([ChId],
                 [ColId],
                 [Title],
                 [TitleColor],
                 [TitleFontType],
                 [TitleType],
                 [TitleImgPath],
                 [UId],
                 [UName],
                 [UserType],
                 [AdminUId],
                 [AdminUName],
                 [Status],
                 [HitCount],
                 [AddTime],
                 [UpdateTime],
                 [TemplatePath],
                 [PageType],
                 [IsCreated],
                 [UserCateId],
                 [PointCount],
                 [ChargeType],
                 [ChargeHourCount],
                 [ChargeViewCount],
                 [IsOpened],
                 [GroupIdStr],
                 [IsDeleted],
                 [IsRecommend],
                 [IsTop],
                 [IsFocus],
                 [IsSideShow],
                 [TagIdStr],
                 [IsAllowComment],
                 [TagNameStr],
                 [SpecialIdStr],
                 [Content],
                 [ImgPath])
    VALUES      (@ChId,
                 @ColId,
                 @Title,
                 @TitleColor,
                 @TitleFontType,
                 @TitleType,
                 @TitleImgPath,
                 @UId,
                 @UName,
                 @UserType,
                 @AdminUId,
                 @AdminUName,
                 @Status,
                 @HitCount,
                 @AddTime,
                 @UpdateTime,
                 @TemplatePath,
                 @PageType,
                 @IsCreated,
                 @UserCateId,
                 @PointCount,
                 @ChargeType,
                 @ChargeHourCount,
                 @ChargeViewCount,
                 @IsOpened,
                 @GroupIdStr,
                 @IsDeleted,
                 @IsRecommend,
                 @IsTop,
                 @IsFocus,
                 @IsSideShow,
                 @TagIdStr,
                 @IsAllowComment,
                 @TagNameStr,
                 @SpecialIdStr,
                 @Content,
                 @ImgPath )
    SELECT @Identity = Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_GetModel] @FieldId      INT=0,
                                                       @CustomFormId INT=0,
                                                       @Name         NVARCHAR(50)=" ",
                                                       @TypeId       INT
AS
    IF @TypeId = 1
      SELECT *
      FROM   [Qianbo_CustomFormField]
      WHERE  FieldId = @FieldId
    ELSE
      SELECT *
      FROM   [Qianbo_CustomFormField]
      WHERE  CustomFormId = @CustomFormId
             AND [Name] = @Name
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerType_Delete]'
GO
CREATE PROC [dbo].[Proc_DownLoadServerType_Delete] @TypeId INT
AS
    DELETE FROM Qianbo_DownLoadServerType
    WHERE  TypeId = @TypeId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Article_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_Article_Set] @Id                INT output,
                                          @ColId             INT,
                                          @ChId              INT,
                                          @Title             NVARCHAR(200),
                                          @TitleColor        NVARCHAR(6) ='',
                                          @TitleFontType     INT,
                                          @TitleType         INT,
                                          @TitleImgPath      VARCHAR(255)='',
                                          @UId               INT,
                                          @UName             NVARCHAR(20) ='',
                                          @UserType          INT,
                                          @AdminUId          INT,
                                          @AdminUName        NVARCHAR(20)='',
                                          @Status            INT,
                                          @HitCount          INT,
                                          @AddTime           DATETIME,
                                          @UpdateTime        DATETIME,
                                          @TemplatePath      VARCHAR(255)='',
                                          @PageType          INT,
                                          @IsCreated         BIT,
                                          @UserCateId        INT,
                                          @PointCount        INT,
                                          @ChargeType        INT,
                                          @ChargeHourCount   INT,
                                          @ChargeViewCount   INT,
                                          @IsOpened          INT,
                                          @GroupIdStr        VARCHAR(200)='',
                                          @IsDeleted         BIT,
                                          @IsRecommend       BIT,
                                          @IsTop             BIT,
                                          @IsFocus           BIT,
                                          @IsSideShow        BIT,
                                          @TagIdStr          VARCHAR(300) ='',
                                          @TagNameStr        NVARCHAR(300) ='',
                                          @SpecialIdStr      VARCHAR(200)='',
                                          @LongTitle         NVARCHAR(500) ='',
                                          @Content           NTEXT='',
                                          @ShortContent      NVARCHAR(200) ='',
                                          @OuterUrl          VARCHAR(255)='',
                                          @Author            NVARCHAR(50) ='',
                                          @Source            NVARCHAR(50) ='',
                                          @IsHeader          BIT,
                                          @HeaderFont        NVARCHAR(100) ='',
                                          @HeaderImgPath     VARCHAR(255) ='',
                                          @StarLevel         NVARCHAR(20) ='',
                                          @IsShowCommentLink BIT,
                                          @IsIrregular       BIT,
                                          @IrregularId       INT,
                                          @ViewUName         NTEXT ='',
                                          @ViewUName2        NTEXT='',
                                          @ViewEndTime       NVARCHAR(20) ='',
                                          @IsAllowComment    BIT,
                                          @ExpireTime        DATETIME
AS
    IF( @Id = 0 )
      BEGIN
          INSERT INTO Qianbo_Article
                      ([ChId],
                       [ColId],
                       [Title],
                       [TitleColor],
                       [TitleFontType],
                       [TitleType],
                       [TitleImgPath],
                       [UId],
                       [UName],
                       [UserType],
                       [AdminUId],
                       [AdminUName],
                       [Status],
                       [HitCount],
                       [AddTime],
                       [UpdateTime],
                       [TemplatePath],
                       [PageType],
                       [IsCreated],
                       [UserCateId],
                       [PointCount],
                       [ChargeType],
                       [ChargeHourCount],
                       [ChargeViewCount],
                       [IsOpened],
                       [GroupIdStr],
                       [IsDeleted],
                       [IsRecommend],
                       [IsTop],
                       [IsFocus],
                       [IsSideShow],
                       [TagIdStr],
                       [TagNameStr],
                       [SpecialIdStr],
                       [LongTitle],
                       [Content],
                       [ShortContent],
                       [OuterUrl],
                       [Author],
                       [Source],
                       [IsHeader],
                       [HeaderFont],
                       [HeaderImgPath],
                       [StarLevel],
                       [IsShowCommentLink],
                       [IsIrregular],
                       [IrregularId],
                       [ViewUName],
                       [ViewUName2],
                       [ViewEndTime],
                       [IsAllowComment],
                       [ExpireTime])
          VALUES      (@ChId,
                       @ColId,
                       @Title,
                       @TitleColor,
                       @TitleFontType,
                       @TitleType,
                       @TitleImgPath,
                       @UId,
                       @UName,
                       @UserType,
                       @AdminUId,
                       @AdminUName,
                       @Status,
                       @HitCount,
                       @AddTime,
                       @UpdateTime,
                       @TemplatePath,
                       @PageType,
                       @IsCreated,
                       @UserCateId,
                       @PointCount,
                       @ChargeType,
                       @ChargeHourCount,
                       @ChargeViewCount,
                       @IsOpened,
                       @GroupIdStr,
                       @IsDeleted,
                       @IsRecommend,
                       @IsTop,
                       @IsFocus,
                       @IsSideShow,
                       @TagIdStr,
                       @TagNameStr,
                       @SpecialIdStr,
                       @LongTitle,
                       @Content,
                       @ShortContent,
                       @OuterUrl,
                       @Author,
                       @Source,
                       @IsHeader,
                       @HeaderFont,
                       @HeaderImgPath,
                       @StarLevel,
                       @IsShowCommentLink,
                       @IsIrregular,
                       @IrregularId,
                       @ViewUName,
                       @ViewUName2,
                       @ViewEndTime,
                       @IsAllowComment,
                       @ExpireTime )
          SET @Id=Scope_identity()
      END
    ELSE
      BEGIN
          UPDATE Qianbo_Article
          SET    [AddTime] = @AddTime,
                 [ChId] = @ChId,
                 [ColId] = @ColId,
                 [Title] = @Title,
                 [TitleColor] = @TitleColor,
                 [TitleFontType] = @TitleFontType,
                 [TitleType] = @TitleType,
                 [TitleImgPath] = @TitleImgPath,
                 [UpdateTime] = @UpdateTime,
                 [TemplatePath] = @TemplatePath,
                 [PageType] = @PageType,
                 [IsCreated] = @IsCreated,
                 [PointCount] = @PointCount,
                 [ChargeType] = @ChargeType,
                 [ChargeHourCount] = @ChargeHourCount,
                 [ChargeViewCount] = @ChargeViewCount,
                 [IsOpened] = @IsOpened,
                 [GroupIdStr] = @GroupIdStr,
                 [IsRecommend] = @IsRecommend,
                 [IsTop] = @IsTop,
                 [IsFocus] = @IsFocus,
                 [IsSideShow] = @IsSideShow,
                 [TagIdStr] = @TagIdStr,
                 [TagNameStr] = @TagNameStr,
                 [SpecialIdStr] = @SpecialIdStr,
                 [LongTitle] = @LongTitle,
                 [Content] = @Content,
                 [ShortContent] = @ShortContent,
                 [OuterUrl] = @OuterUrl,
                 [Author] = @Author,
                 [Source] = @Source,
                 [IsHeader] = @IsHeader,
                 [HeaderFont] = @HeaderFont,
                 [HeaderImgPath] = @HeaderImgPath,
                 [StarLevel] = @StarLevel,
                 [IsShowCommentLink] = @IsShowCommentLink,
                 [IsIrregular] = @IsIrregular,
                 [IrregularId] = @IrregularId,
                 [ViewUName] = @ViewUName,
                 [ViewEndTime] = @ViewEndTime,
                 [IsAllowComment] = @IsAllowComment,
                 [ExpireTime] = @ExpireTime,
                 [HitCount] = @HitCount
          WHERE  [Id] = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_GetTextType]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_GetTextType] @ModelId INT
AS
    SELECT ModelId,
           [Name],
           Type
    FROM   [Qianbo_UserGroupModelField]
    WHERE  [ModelId] = @ModelId
           AND [Type] = 'MultipleHtmlType'
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_DeleteFriend]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_User_DeleteFriend] @Id INT
AS
    DELETE FROM Qianbo_UserFriend
    WHERE  [ID] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_VoteCategory_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_VoteCategory_Set] @CategoryId INT=0,
                                               @Name       NVARCHAR(200)='NULL',
                                               @Type       INT
AS
    IF @Type = 1
      BEGIN
          INSERT INTO Qianbo_VoteCategory
          VALUES      (@Name)
      END
    IF @Type = 2
      BEGIN
          UPDATE Qianbo_VoteCategory
          SET    [Name] = @Name
          WHERE  CategoryId = @CategoryId
      END
    IF @Type = 3
      BEGIN
          DELETE Qianbo_VoteCategory
          WHERE  CategoryId = @CategoryId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_GetTitleList]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_GetTitleList] @CustomFormId INT
AS
    SELECT *
    FROM   [Qianbo_CustomFormField]
    WHERE  IsList = 1
           AND CustomFormId = @CustomFormId
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Review_GetTop5List]'
GO
CREATE PROCEDURE [dbo].[Proc_Review_GetTop5List] @ModelType INT,
                                                 @InfoId    INT,
                                                 @IsCheck   BIT
AS
    SELECT TOP 5 [Id],
                 UserNum,
                 InfoId,
                 ReviewContent,
                 ReviewTime
    FROM   Qianbo_Review a
    WHERE  ModelType = @ModelType
           AND InfoId = @InfoId
           AND IsCheck = @IsCheck
    ORDER  BY [Id] DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_Add]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_Add] @StyleCategoryId INT,
                                        @Name            NVARCHAR(100),
                                        @Content         TEXT,
                                        @Type            INT,
                                        @Id              INT output
AS
    INSERT INTO Qianbo_Style
                ([StyleCategoryId],
                 [Name],
                 [Content],
                 [Type])
    VALUES      ( @StyleCategoryId,
                  @Name,
                  @Content,
                  @Type )
    SET @Id = @@identity
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_ModelHtml]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_ModelHtml] @ModelHtml NTEXT,
                                                       @Id        INT
AS
    UPDATE [Qianbo_UserGroupModel]
    SET    ModelHtml = @ModelHtml
    WHERE  [Id] = @Id
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerType_GetInfo]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_DownLoadServerType_GetInfo] @TypeId INT
AS
    SELECT *
    FROM   Qianbo_DownLoadServerType
    WHERE  typeid = @TypeId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_LbCategory]'
GO
CREATE TABLE [dbo].[Qianbo_LbCategory]
(
[LbCategoryID] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[ParentID] [int] NOT NULL CONSTRAINT [DF_Qianbo_LbCategory_ParentID] DEFAULT ((0)),
[Desc] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_LbCategory] on [dbo].[Qianbo_LbCategory]'
GO
ALTER TABLE [dbo].[Qianbo_LbCategory] ADD CONSTRAINT [PK_Qianbo_LbCategory] PRIMARY KEY CLUSTERED  ([LbCategoryID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LbCategory_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LbCategory_Add] @LbCategoryID INT output,
                                             @Name         NVARCHAR(100),
                                             @ParentID     INT,
                                             @Desc         NVARCHAR(200)
AS
    INSERT INTO Qianbo_LbCategory
                ([Name],
                 [ParentID],
                 [Desc])
    VALUES      ( @Name,
                  @ParentID,
                  @Desc )
    SET @LbCategoryID = @@identity
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Image_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_Image_Update] @ChId            INT,
                                           @Id              INT,
                                           @ColId           INT,
                                           @Title           NVARCHAR(200),
                                           @TitleColor      NVARCHAR(12),
                                           @TitleFontType   INT,
                                           @TitleType       INT,
                                           @TitleImgPath    VARCHAR(255),
                                           @UId             INT,
                                           @UName           NVARCHAR(40),
                                           @UserType        INT,
                                           @AdminUId        INT,
                                           @AdminUName      CHAR(10),
                                           @Status          INT,
                                           @HitCount        INT,
                                           @AddTime         DATETIME,
                                           @UpdateTime      DATETIME,
                                           @TemplatePath    VARCHAR(255),
                                           @PageType        INT,
                                           @IsCreated       BIT,
                                           @UserCateId      INT,
                                           @PointCount      INT,
                                           @ChargeType      INT,
                                           @ChargeHourCount INT,
                                           @ChargeViewCount INT,
                                           @IsOpened        INT,
                                           @GroupIdStr      VARCHAR(200),
                                           @IsDeleted       BIT,
                                           @IsRecommend     BIT,
                                           @IsTop           BIT,
                                           @IsFocus         BIT,
                                           @IsSideShow      BIT,
                                           @TagIdStr        VARCHAR(300),
                                           @IsAllowComment  BIT,
                                           @TagNameStr      NVARCHAR(600),
                                           @SpecialIdStr    VARCHAR(200),
                                           @Content         NTEXT,
                                           @ImgPath         NTEXT
AS
    UPDATE Qianbo_Image
    SET    [ChId] = @ChId,
           [ColId] = @ColId,
           [Title] = @Title,
           [TitleColor] = @TitleColor,
           [TitleFontType] = @TitleFontType,
           [TitleType] = @TitleType,
           [TitleImgPath] = @TitleImgPath,
           [UId] = @UId,
           [UName] = @UName,
           [UserType] = @UserType,
           [AdminUId] = @AdminUId,
           [AdminUName] = @AdminUName,
           [Status] = @Status,
           [HitCount] = @HitCount,
           [AddTime] = @AddTime,
           [UpdateTime] = @UpdateTime,
           [TemplatePath] = @TemplatePath,
           [PageType] = @PageType,
           [IsCreated] = @IsCreated,
           [UserCateId] = @UserCateId,
           [PointCount] = @PointCount,
           [ChargeType] = @ChargeType,
           [ChargeHourCount] = @ChargeHourCount,
           [ChargeViewCount] = @ChargeViewCount,
           [IsOpened] = @IsOpened,
           [GroupIdStr] = @GroupIdStr,
           [IsDeleted] = @IsDeleted,
           [IsRecommend] = @IsRecommend,
           [IsTop] = @IsTop,
           [IsFocus] = @IsFocus,
           [IsSideShow] = @IsSideShow,
           [TagIdStr] = @TagIdStr,
           [IsAllowComment] = @IsAllowComment,
           [TagNameStr] = @TagNameStr,
           [SpecialIdStr] = @SpecialIdStr,
           [Content] = @Content,
           [ImgPath] = @ImgPath
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_MoveField]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_MoveField] @CustomFormId INT,
                                                        @FieldId      INT,
                                                        @MoveType     NVARCHAR(20)
AS
    DECLARE @OrderId INT;
    DECLARE @NewFieldId INT;
    DECLARE @NewOrderId INT;
    IF @MoveType = 'UpMove'
      BEGIN
          DECLARE @MinOrderId INT;
          SET @MinOrderId=(SELECT Min(OrderId)
                           FROM   [Qianbo_CustomFormField]
                           WHERE  CustomFormId = @CustomFormId)
          SET @OrderId=(SELECT OrderId
                        FROM   [Qianbo_CustomFormField]
                        WHERE  CustomFormId = @CustomFormId
                               AND FieldId = @FieldId)
          IF @OrderId != @MinOrderId
            BEGIN
                SET @NewFieldId=(SELECT TOP 1 FieldId
                                 FROM   [Qianbo_CustomFormField]
                                 WHERE  CustomFormId = @CustomFormId
                                        AND OrderId < @OrderId
                                 ORDER  BY OrderId DESC)
                SET @NewOrderId=(SELECT OrderId
                                 FROM   [Qianbo_CustomFormField]
                                 WHERE  CustomFormId = @CustomFormId
                                        AND FieldId = @NewFieldId)
                UPDATE [Qianbo_CustomFormField]
                SET    OrderId = @OrderId
                WHERE  FieldId = @NewFieldId
                       AND CustomFormId = @CustomFormId
                UPDATE [Qianbo_CustomFormField]
                SET    OrderId = @NewOrderId
                WHERE  FieldId = @FieldId
                       AND CustomFormId = @CustomFormId
            END
      END
    IF @MoveType = 'DownMove'
      BEGIN
          DECLARE @MaxOrderId INT;
          SET @MaxOrderId=(SELECT Max(OrderId)
                           FROM   [Qianbo_CustomFormField]
                           WHERE  CustomFormId = @CustomFormId)
          SET @OrderId=(SELECT OrderId
                        FROM   [Qianbo_CustomFormField]
                        WHERE  CustomFormId = @CustomFormId
                               AND FieldId = @FieldId)
          IF @OrderId != @MaxOrderId
            BEGIN
                SET @NewFieldId=(SELECT TOP 1 FieldId
                                 FROM   [Qianbo_CustomFormField]
                                 WHERE  CustomFormId = @CustomFormId
                                        AND OrderId > @OrderId
                                 ORDER  BY OrderId)
                SET @NewOrderId=(SELECT OrderId
                                 FROM   [Qianbo_CustomFormField]
                                 WHERE  CustomFormId = @CustomFormId
                                        AND FieldId = @NewFieldId)
                UPDATE [Qianbo_CustomFormField]
                SET    OrderId = @OrderId
                WHERE  FieldId = @NewFieldId
                       AND CustomFormId = @CustomFormId
                UPDATE [Qianbo_CustomFormField]
                SET    OrderId = @NewOrderId
                WHERE  FieldId = @FieldId
                       AND CustomFormId = @CustomFormId
            END
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Collection_Delete]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Collection_Delete] @Id INT
AS
    DELETE Qianbo_Collection
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Article_SetViewer]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Article_SetViewer] @id         INT,
                                                @viewername NVARCHAR(50)
AS
    UPDATE Qianbo_Article
    SET    viewuname2 = @viewername
    WHERE  id = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_Update]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_Update] @Id          INT,
                                                    @Name        NVARCHAR(100),
                                                    @TableName   NVARCHAR(200),
                                                    @Content     NVARCHAR(1000),
                                                    @AddTime     DATETIME,
                                                    @IsValidate  BIT,
                                                    @IsHtml      BIT,
                                                    @SpaceTypeId INT
AS
    UPDATE [Qianbo_UserGroupModel]
    SET    [Name] = @Name,
           [TableName] = @TableName,
           [Content] = @Content,
           [AddTime] = @AddTime,
           [IsValidate] = @IsValidate,
           [IsHtml] = @IsHtml,
           [SpaceTypeId] = @SpaceTypeId
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Superior_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_Superior_GetList]
AS
    SELECT [id],
           [Name],
           [StartCode],
           [EndCode]
    FROM   Qianbo_Superior
    ORDER  BY [ID] DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_SelectPropertyTrue]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_SelectPropertyTrue] @CustomFormId NVARCHAR(50)
AS
    SELECT *
    FROM   [Qianbo_CustomFormField]
    WHERE  CustomFormId = @CustomFormId
           AND Type = 'RadioType'
           AND Content LIKE '%Property=True%'
    ORDER  BY OrderId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_GetAllInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_User_GetAllInfo] @userId INT
AS
    DECLARE @tableName NVARCHAR(30)
    DECLARE @spaceTypeId INT
    SELECT @tableName = [tablename],
           @spacetypeid = [spacetypeid]
    FROM   [Qianbo_Users] u
           JOIN [Qianbo_UserGroupModel] m
             ON u.[typeid] = m.[id]
    WHERE  [userid] = @userid
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select u.*,e.*,g.[usergroupname],'
                  + CONVERT(NVARCHAR(15), @spacetypeid)
                  + ' as spacetypeid from [Qianbo_Users] u join ['
                  + @tablename
                  + '] e on u.[userid] = e.[uid] join [Qianbo_UserGroup] g on u.[groupid] = g.[usergroupid] where u.[userid] = @t_userid'
    DECLARE @param NVARCHAR(200)
    SET @param='@t_userid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @t_userid = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LbCategory_Delete]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LbCategory_Delete] @LbCategoryID INT
AS
    DELETE Qianbo_LbCategory
    WHERE  [LbCategoryID] = @LbCategoryID
            OR ParentID = @LbCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_UpdateUserGroupId]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_UpdateUserGroupId] @Id          INT,
                                                               @UserGroupId INT
AS
    UPDATE [Qianbo_UserGroupModel]
    SET    UserGroupId = @UserGroupId
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Review_Oper]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Review_Oper] @id        INT=0,
                                     @infoid    INT=0,
                                     @modeltype INT=1,
                                     @typeid    INT,
                                     @ischeck   BIT=1
AS
    IF( @typeid = 1 )
      BEGIN
          DELETE FROM Qianbo_Review
          WHERE  [id] = @id
      END
    ELSE IF( @typeid = 2 )
      BEGIN
          DELETE FROM Qianbo_Review
          WHERE  infoid = @infoid
                 AND modeltype = @modeltype
      END
    ELSE IF( @typeid = 3 )
      BEGIN
          UPDATE Qianbo_Review
          SET    ischeck = @ischeck
          WHERE  [id] = @id
      END
    ELSE IF( @typeid = 4 )
      BEGIN
          SELECT *
          FROM   Qianbo_Review
          WHERE  [id] = @id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Collection_GetIdByCollection]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Collection_GetIdByCollection] @Id INT
AS
    SELECT [Id],
           [ObjectName],
           [WebSite],
           [ColId],
           [SpecialId],
           [CharSet],
           [ListPageUrl],
           [ObjectDemo],
           [ListStartCode],
           [ListEndCode],
           [LinkStartCode],
           [LinkEndCode],
           [PageSet],
           [ContentPageSet],
           [FieldListSet],
           [SimpleFilterRule],
           [ComplexityFilterRule],
           [ProterySet],
           [StarLevel],
           [HiteCount]
    FROM   Qianbo_Collection
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_VoteSubject]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_VoteSubject]
(
[VoteSubjectId] [int] NOT NULL IDENTITY(1, 1),
[Subject] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NOT NULL,
[StartDate] [datetime] NULL,
[EndDate] [datetime] NULL,
[RequireLogin] [bit] NULL,
[CategoryId] [int] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_VoteSubject] on [dbo].[Qianbo_VoteSubject]'
GO
ALTER TABLE [dbo].[Qianbo_VoteSubject] ADD CONSTRAINT [PK_Qianbo_VoteSubject] PRIMARY KEY CLUSTERED  ([VoteSubjectId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_VoteSubject_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_VoteSubject_Add] @Subject      NVARCHAR(200),
                                              @StartDate    DATETIME,
                                              @EndDate      DATETIME,
                                              @RequireLogin BIT,
                                              @CategoryId   INT,
                                              @Identity     INT output
AS
    INSERT INTO Qianbo_VoteSubject
    VALUES      (@Subject,
                 @StartDate,
                 @EndDate,
                 @RequireLogin,
                 @CategoryId)
    SELECT @Identity = Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomFormField_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomFormField_Update] @FieldId      INT,
                                                     @CustomFormId INT,
                                                     @Alias        NVARCHAR(300),
                                                     @Description  NVARCHAR(400),
                                                     @IsNotNull    BIT,
                                                     @IsSearchForm BIT,
                                                     @Content      NTEXT,
                                                     @IsList       BIT,
                                                     @IsUserInsert BIT,
                                                     @AddDate      DATETIME
AS
    UPDATE Qianbo_CustomFormField
    SET    [Alias] = @Alias,
           [Description] = @Description,
           [IsNotNull] = @IsNotNull,
           [IsSearchForm] = @IsSearchForm,
           [Content] = @Content,
           [IsList] = @IsList,
           [IsUserInsert] = @IsUserInsert,
           [AddDate] = @AddDate
    WHERE  [FieldId] = @FieldId
           AND CustomFormId = @CustomFormId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerType_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadServerType_GetList]
AS
    SELECT *
    FROM   Qianbo_DownLoadServerType
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Superior_Update]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Superior_Update] @id        INT,
                                              @Name      NVARCHAR(400),
                                              @StartCode NVARCHAR(1000),
                                              @EndCode   NVARCHAR(1000)
AS
    UPDATE Qianbo_Superior
    SET    [Name] = @Name,
           [StartCode] = @StartCode,
           [EndCode] = @EndCode
    WHERE  [id] = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadServerType_Set]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadServerType_Set] @TypeId   INT output,
                                                     @TypeName NVARCHAR(100)
AS
    IF( @TypeId = 0 )
      BEGIN
          INSERT INTO Qianbo_DownLoadServerType
                      ([TypeName])
          VALUES      ( @TypeName )
      END
    ELSE
      BEGIN
          UPDATE Qianbo_DownLoadServerType
          SET    [TypeName] = @TypeName
          WHERE  [TypeId] = @TypeId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LbCategory_GetIdData]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LbCategory_GetIdData] @LbCategoryID INT
AS
    SELECT [Name],
           [ParentID],
           [Desc]
    FROM   Qianbo_LbCategory
    WHERE  [LbCategoryID] = @LbCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Site_Count]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Site_Count] @Type   VARCHAR(10),
                                         @Filter VARCHAR(15)
AS
    IF @Type = 'Year'
      BEGIN
          SELECT *
          FROM   Qianbo_CountYear
          WHERE  Flag = @Filter
      END
    IF @Type = 'Month'
      BEGIN
          SELECT *
          FROM   Qianbo_CountMonth
          WHERE  Flag = @Filter
      END
    IF @Type = 'Week'
      BEGIN
          SELECT *
          FROM   Qianbo_CountWeek
          WHERE  Flag = @Filter
      END
    IF @Type = 'Day'
      BEGIN
          SELECT *
          FROM   Qianbo_CountDay
          WHERE  Flag = @Filter
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SelectAll]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SelectAll]
AS
    SELECT *
    FROM   Qianbo_Users
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Collection_GetList]'
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_Collection_GetList]
AS
    SELECT [Id],
           [ObjectName],
           [WebSite],
           [ColId],
           [SpecialId],
           [CharSet],
           [ListPageUrl],
           [ObjectDemo],
           [ListStartCode],
           [ListEndCode],
           [LinkStartCode],
           [LinkEndCode],
           [PageSet],
           [ContentPageSet],
           [FieldListSet],
           [SimpleFilterRule],
           [ComplexityFilterRule],
           [ProterySet],
           [StarLevel],
           [HiteCount]
    FROM   Qianbo_Collection
    ORDER  BY [id] DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_Delete]'
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Admin_Delete] @UserId INT
AS
    DELETE dbo.Qianbo_Admin
    WHERE  UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoad_GetAddressPath]'
GO
CREATE PROC [dbo].[Proc_DownLoad_GetAddressPath] @serverid  INT,
                                                 @addressid INT
AS
    SELECT c.downloadserverdir,
           a.addressPath,
           a.downloaddataid,
           c.isopened
    FROM   Qianbo_DownLoadAddress a
           LEFT JOIN Qianbo_DownLoadServerType b
                  ON a.downloadserverid = b.typeid
           LEFT JOIN Qianbo_DownLoadServerData c
                  ON b.typeid = c.typeid
    WHERE  isnull(downloadserverdataid, -1) = @serverid
           AND addressid = @addressid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_AddSearchStyle]'
GO
CREATE PROCEDURE [dbo].[Proc_Style_AddSearchStyle] @modelId INT,
                                                   @content NTEXT
AS
    INSERT INTO Qianbo_ListStyleContent
                (ModelId,
                 Content)
    VALUES      (@modelid,
                 @content)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Users_Add] @logname     NVARCHAR(100),
                                        @userpwd     NVARCHAR(200),
                                        @typeid      INT,
                                        @email       VARCHAR(100),
                                        @islock      BIT,
                                        @groupid     INT,
                                        @question    NVARCHAR(50),
                                        @answer      NVARCHAR(50),
                                        @integral    INT,
                                        @secret      TINYINT,
                                        @confirmCode NVARCHAR(50),
                                        @status      INT,
                                        @SiteId      INT
AS
    INSERT INTO Qianbo_Users
                ([logname],
                 [userpwd],
                 [typeid],
                 [email],
                 [islock],
                 [groupid],
                 [question],
                 [answer],
                 [integral],
                 [secret],
                 [confirmregcode],
                 [status],
                 [SiteId])
    VALUES      (@logname,
                 @userpwd,
                 @typeid,
                 @email,
                 @islock,
                 @groupid,
                 @question,
                 @answer,
                 @integral,
                 @secret,
                 @confirmcode,
                 @status,
                 @SiteId)
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_CustomForm]'
GO
CREATE TABLE [dbo].[Qianbo_CustomForm]
(
[CustomFormId] [int] NOT NULL IDENTITY(1, 1),
[ShowForm] [int] NULL,
[FormName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[TableName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[UploadPath] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[UploadSize] [int] NULL CONSTRAINT [DF_Qianbo_CustomForm_UploadSize] DEFAULT ((0)),
[FormDesc] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[IsUnlockTime] [bit] NULL,
[StartTime] [datetime] NULL,
[EndTime] [datetime] NULL,
[UserGroup] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[IsSubmitNum] [bit] NULL,
[Money] [int] NULL,
[IsValidate] [bit] NULL,
[AddTime] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_CustomForm] on [dbo].[Qianbo_CustomForm]'
GO
ALTER TABLE [dbo].[Qianbo_CustomForm] ADD CONSTRAINT [PK_Qianbo_CustomForm] PRIMARY KEY CLUSTERED  ([CustomFormId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomForm_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomForm_Add] @ShowForm     INT,
                                             @FormName     NVARCHAR(100),
                                             @TableName    NVARCHAR(100),
                                             @UploadPath   NVARCHAR(100),
                                             @FormDesc     NVARCHAR(400),
                                             @IsUnlockTime BIT,
                                             @StartTime    DATETIME,
                                             @EndTime      DATETIME,
                                             @UserGroup    NVARCHAR(200),
                                             @IsSubmitNum  BIT,
                                             @Money        INT,
                                             @IsValidate   BIT,
                                             @AddTime      DATETIME
AS
    INSERT INTO [Qianbo_CustomForm]
                ([ShowForm],
                 [FormName],
                 [TableName],
                 [UploadPath],
                 [FormDesc],
                 [IsUnlockTime],
                 [StartTime],
                 [EndTime],
                 [UserGroup],
                 [IsSubmitNum],
                 [Money],
                 [IsValidate],
                 [AddTime])
    VALUES      (@ShowForm,
                 @FormName,
                 @TableName,
                 @UploadPath,
                 @FormDesc,
                 @IsUnlockTime,
                 @StartTime,
                 @EndTime,
                 @UserGroup,
                 @IsSubmitNum,
                 @Money,
                 @IsValidate,
                 @AddTime)
    SELECT Scope_identity()
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_Login]'
GO
CREATE PROCEDURE [dbo].[Proc_User_Login] (@LogName NVARCHAR(20),
                                          @Pwd     NVARCHAR(200))
AS
    SELECT UserID
    FROM   Qianbo_Users
    WHERE  LogName = @LogName
           AND UserPwd = @Pwd
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroup_GetNameAndId]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroup_GetNameAndId] @TypeId INT
AS
    SELECT UserGroupId,
           UserGroupName
    FROM   Qianbo_UserGroup
    WHERE  TypeId = @TypeId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_TagCategory]'
GO
CREATE TABLE [dbo].[Qianbo_TagCategory]
(
[TagCategoryId] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[Desc] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Tag] on [dbo].[Qianbo_TagCategory]'
GO
ALTER TABLE [dbo].[Qianbo_TagCategory] ADD CONSTRAINT [PK_Qianbo_Tag] PRIMARY KEY CLUSTERED  ([TagCategoryId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TagCategory_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_TagCategory_GetList]
AS
    SELECT *
    FROM   Qianbo_TagCategory
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Special_Add] @ParentID       INT,
                                          @SiteID         INT,
                                          @SpecialCName   NVARCHAR(30),
                                          @SpecialEName   NVARCHAR(20),
                                          @SpecialDomain  NVARCHAR(100),
                                          @SpecialRemark  NVARCHAR(200),
                                          @IsLock         BIT,
                                          @IsCommand      BIT,
                                          @SpecialAddTime DATETIME,
                                          @MetaKeyWord    NVARCHAR(200),
                                          @MetaRemark     NVARCHAR(200),
                                          @SpecialTemplet NVARCHAR(200),
                                          @SpecialItemNum INT,
                                          @SpecialContent NTEXT,
                                          @SaveDirType    NVARCHAR(200),
                                          @Extension      VARCHAR(50),
                                          @PicSavePath    NVARCHAR(200),
                                          @IsDeleted      BIT
AS
    INSERT INTO Qianbo_Special
                ([ParentID],
                 [SiteID],
                 [SpecialCName],
                 [SpecialEName],
                 [SpecialDomain],
                 [SpecialRemark],
                 [IsLock],
                 [IsCommand],
                 [SpecialAddTime],
                 [MetaKeyWord],
                 [MetaRemark],
                 [SpecialTemplet],
                 [SpecialItemNum],
                 [SpecialContent],
                 [SaveDirType],
                 IsDeleted,
                 Extension,
                 PicSavePath)
    VALUES      ( @ParentID,
                  @SiteID,
                  @SpecialCName,
                  @SpecialEName,
                  @SpecialDomain,
                  @SpecialRemark,
                  @IsLock,
                  @IsCommand,
                  @SpecialAddTime,
                  @MetaKeyWord,
                  @MetaRemark,
                  @SpecialTemplet,
                  @SpecialItemNum,
                  @SpecialContent,
                  @SaveDirType,
                  @IsDeleted,
                  @Extension,
                  @PicSavePath )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LbCategory_GetParentIDList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LbCategory_GetParentIDList] @ParentID INT
AS
    SELECT [LbCategoryID],
           [Name],
           [ParentID],
           [Desc]
    FROM   Qianbo_LbCategory
    WHERE  [ParentID] = @ParentID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Enterprise_GetById]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Enterprise_GetById] @Id     INT,
                                                 @UserId INT
AS
    SELECT *
    FROM   Qianbo_Enterprise
    WHERE  [Id] = @Id
           AND UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SinglePage_Add]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SinglePage_Add] @Name         NVARCHAR(200),
                                             @FolderPath   NVARCHAR(100),
                                             @FileName     NVARCHAR(200),
                                             @FileExtend   NVARCHAR(100),
                                             @TemplatePath NVARCHAR(300),
                                             @Content      NVARCHAR(400),
                                             @AddTime      DATETIME
AS
    INSERT INTO [Qianbo_SinglePage]
                ([Name],
                 [FolderPath],
                 [FileName],
                 [FileExtend],
                 [TemplatePath],
                 [Content],
                 [AddTime])
    VALUES      (@Name,
                 @FolderPath,
                 @FileName,
                 @FileExtend,
                 @TemplatePath,
                 @Content,
                 @AddTime)
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Collection_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_Collection_Update] @Id                   INT,
                                                @ObjectName           NVARCHAR(100),
                                                @WebSite              NVARCHAR(1000),
                                                @ColId                INT,
                                                @SpecialId            NVARCHAR(1000),
                                                @CharSet              NVARCHAR(100),
                                                @ListPageUrl          NVARCHAR(1000),
                                                @ObjectDemo           TEXT,
                                                @ListStartCode        NTEXT,
                                                @ListEndCode          NTEXT,
                                                @LinkStartCode        NTEXT,
                                                @LinkEndCode          NTEXT,
                                                @PageSet              NVARCHAR(2000),
                                                @ContentPageSet       NVARCHAR(2000),
                                                @FieldListSet         NTEXT,
                                                @SimpleFilterRule     NVARCHAR(100),
                                                @ComplexityFilterRule NVARCHAR(100),
                                                @ProterySet           NVARCHAR(100),
                                                @StarLevel            NVARCHAR(100),
                                                @HiteCount            INT
AS
    UPDATE Qianbo_Collection
    SET    [ObjectName] = @ObjectName,
           [WebSite] = @WebSite,
           [ColId] = @ColId,
           [SpecialId] = @SpecialId,
           [CharSet] = @CharSet,
           [ListPageUrl] = @ListPageUrl,
           [ObjectDemo] = @ObjectDemo,
           [ListStartCode] = @ListStartCode,
           [ListEndCode] = @ListEndCode,
           [LinkStartCode] = @LinkStartCode,
           [LinkEndCode] = @LinkEndCode,
           [PageSet] = @PageSet,
           [ContentPageSet] = @ContentPageSet,
           [FieldListSet] = @FieldListSet,
           [SimpleFilterRule] = @SimpleFilterRule,
           [ComplexityFilterRule] = @ComplexityFilterRule,
           [ProterySet] = @ProterySet,
           [StarLevel] = @StarLevel,
           [HiteCount] = @HiteCount
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_GetAdminCount]'
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_Admin_GetAdminCount] @GroupId INT
AS
    SELECT Count(*)
    FROM   Qianbo_Admin
    WHERE  GroupId = @GroupId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_PowerColumn]'
GO
CREATE TABLE [dbo].[Qianbo_PowerColumn]
(
[PCId] [int] NOT NULL IDENTITY(1, 1),
[PowerColumnName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[ColumnErrorCodes] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_PowerColumu] on [dbo].[Qianbo_PowerColumn]'
GO
ALTER TABLE [dbo].[Qianbo_PowerColumn] ADD CONSTRAINT [PK_Qianbo_PowerColumu] PRIMARY KEY CLUSTERED  ([PCId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PowerColumn_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_PowerColumn_Update] @id INT
AS
    SELECT *
    FROM   [Qianbo_PowerColumn]
    WHERE  PCId = @id
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoad_GetDownCount]'
GO
CREATE PROC [dbo].[Proc_DownLoad_GetDownCount] @id   INT,
                                               @type INT
AS
    IF( @type = 1 )
      SELECT downloaddownnum
      FROM   Qianbo_DownLoadData
      WHERE  [id] = @id
    ELSE IF( @type = 2 )
      SELECT downloaddownmonthnum
      FROM   Qianbo_DownLoadData
      WHERE  [id] = @id
    ELSE IF( @type = 3 )
      SELECT downloaddownweeknum
      FROM   Qianbo_DownLoadData
      WHERE  [id] = @id
    ELSE
      SELECT downloaddowndaynum
      FROM   Qianbo_DownLoadData
      WHERE  [id] = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TagCategory_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_TagCategory_Set] @TagCategoryId INT,
                                              @Name          NVARCHAR(20),
                                              @Desc          NVARCHAR(100)
AS
    IF ( @TagCategoryId <= 0 )
      BEGIN
          INSERT INTO Qianbo_TagCategory
                      ([Name],
                       [Desc])
          VALUES      (@Name,
                       @Desc);
      END
    ELSE
      BEGIN
          UPDATE Qianbo_TagCategory
          SET    [Name] = @Name,
                 [Desc] = @Desc
          WHERE  TagCategoryId = @TagCategoryId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomForm_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomForm_Delete] @CustomFormId INT
AS
    DECLARE @tablename NVARCHAR(50)
    SET @tablename=''
    SET @tablename=(SELECT TableName
                    FROM   [Qianbo_CustomForm]
                    WHERE  [CustomFormId] = @CustomFormId)
    DECLARE @sqlstr NVARCHAR(500)
    IF( @tablename != '' )
      BEGIN
          SET @sqlstr = N'delete from [Qianbo_CustomForm] where [CustomFormId] = '
                        + CONVERT(NVARCHAR(15), @CustomFormId)
          EXEC sp_executesql
            @sqlstr
          SET @sqlstr = N'drop table [' + @tablename + ']'
          EXEC sp_executesql
            @sqlstr
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LbCategory_ID]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LbCategory_ID]
AS
    SELECT *
    FROM   Qianbo_LbCategory
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_Add]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Column_Add] @ChId                INT,
                                         @ColName             NVARCHAR(50),
                                         @ColDirName          NVARCHAR(50),
                                         @ColParentId         INT,
                                         @IsOuterColumn       BIT,
                                         @OuterColumnUrl      VARCHAR(255),
                                         @ColumnImgPath       NVARCHAR(510),
                                         @Description         NVARCHAR(510),
                                         @Keyword             NVARCHAR(100),
                                         @Content             NVARCHAR(300),
                                         @IsAllowAddInfo      BIT,
                                         @ColumnTemplatePath  NVARCHAR(255),
                                         @InfoTemplatePath    NVARCHAR(255),
                                         @CommentTemplatePath NVARCHAR(255),
                                         @Sort                INT,
                                         @IsAllowComment      BIT,
                                         @IsCheckComment      BIT,
                                         @InfoTableName       NVARCHAR(50),
                                         @ScoreReward         INT,
                                         @PointCount          INT,
                                         @ChargeType          INT,
                                         @ChargeHourCount     INT,
                                         @ChargeViewCount     INT,
                                         @IsOpened            BIT,
                                         @GroupIdStr          VARCHAR(500),
                                         @ColumnPageType      INT,
                                         @InfoPageType        INT,
                                         @IsDeleted           BIT,
                                         @AddTime             DATETIME,
                                         @IsParentHtml        BIT
AS
    INSERT INTO Qianbo_Column
                ([ChId],
                 [ColName],
                 [ColDirName],
                 [ColParentId],
                 [IsOuterColumn],
                 [OuterColumnUrl],
                 [ColumnImgPath],
                 [Description],
                 [Keyword],
                 [Content],
                 [IsAllowAddInfo],
                 [ColumnTemplatePath],
                 [InfoTemplatePath],
                 [CommentTemplatePath],
                 [Sort],
                 [IsAllowComment],
                 [IsCheckComment],
                 [InfoTableName],
                 [ScoreReward],
                 [PointCount],
                 [ChargeType],
                 [ChargeHourCount],
                 [ChargeViewCount],
                 [IsOpened],
                 [GroupIdStr],
                 [ColumnPageType],
                 [InfoPageType],
                 [IsDeleted],
                 [AddTime],
                 [IsParentHtml])
    VALUES      ( @ChId,
                  @ColName,
                  @ColDirName,
                  @ColParentId,
                  @IsOuterColumn,
                  @OuterColumnUrl,
                  @ColumnImgPath,
                  @Description,
                  @Keyword,
                  @Content,
                  @IsAllowAddInfo,
                  @ColumnTemplatePath,
                  @InfoTemplatePath,
                  @CommentTemplatePath,
                  @Sort,
                  @IsAllowComment,
                  @IsCheckComment,
                  @InfoTableName,
                  @ScoreReward,
                  @PointCount,
                  @ChargeType,
                  @ChargeHourCount,
                  @ChargeViewCount,
                  @IsOpened,
                  @GroupIdStr,
                  @ColumnPageType,
                  @InfoPageType,
                  @IsDeleted,
                  @AddTime,
                  @IsParentHtml )
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_InfoModel_GetTextType]'
GO
CREATE PROCEDURE [dbo].[Proc_InfoModel_GetTextType] @ModelId INT
AS
    SELECT ModelId,
           [Name],
           Type
    FROM   [Qianbo_ModelField]
    WHERE  [ModelId] = @ModelId
           AND [Type] = 'MultipleHtmlType'
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_UserLog]'
GO
CREATE TABLE [dbo].[Qianbo_UserLog]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[UserId] [int] NOT NULL,
[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Description] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NULL,
[InfoId] [int] NOT NULL,
[ModelType] [int] NOT NULL,
[Point] [int] NULL CONSTRAINT [DF_Qianbo_UserLog_Point] DEFAULT ((0)),
[AddTime] [datetime] NOT NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserLog_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_UserLog_Add] @UserId      INT,
                                          @UserName    NVARCHAR(20),
                                          @Description NVARCHAR(1000),
                                          @InfoId      INT,
                                          @ModelType   INT,
                                          @Point       INT,
                                          @AddTime     DATETIME
AS
    INSERT INTO Qianbo_UserLog
                ([UserId],
                 [UserName],
                 [Description],
                 [InfoId],
                 [ModelType],
                 [Point],
                 [AddTime])
    VALUES      (@UserId,
                 @UserName,
                 @Description,
                 @InfoId,
                 @ModelType,
                 @Point,
                 @AddTime)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Card]'
GO
CREATE TABLE [dbo].[Qianbo_Card]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[Type] [int] NULL,
[CardAccount] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL,
[Password] [varchar] (200) COLLATE Chinese_PRC_CI_AS NOT NULL,
[IsUsed] [bit] NULL,
[CardPoint] [int] NULL,
[CardDay] [int] NULL,
[AdminID] [int] NULL,
[AdminName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[UserID] [int] NULL,
[UserName] [nvarchar] (18) COLLATE Chinese_PRC_CI_AS NULL,
[OverdueDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Card] on [dbo].[Qianbo_Card]'
GO
ALTER TABLE [dbo].[Qianbo_Card] ADD CONSTRAINT [PK_Qianbo_Card] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Card_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Card_Add] @Type        INT,
                                       @CardAccount VARCHAR(20),
                                       @Password    VARCHAR(200),
                                       @IsUsed      BIT,
                                       @CardPoint   INT,
                                       @CardDay     INT,
                                       @AdminID     INT,
                                       @AdminName   VARCHAR(50),
                                       @OverdueDate DATETIME
AS
  BEGIN
      INSERT INTO Qianbo_Card
                  ([Type],
                   [Password],
                   [IsUsed],
                   [CardPoint],
                   [CardDay],
                   [AdminID],
                   [AdminName],
                   [OverdueDate])
      VALUES      ( @Type,
                    @Password,
                    @IsUsed,
                    @CardPoint,
                    @CardDay,
                    @AdminID,
                    @AdminName,
                    @OverdueDate )
      IF @@rowcount > 0
        BEGIN
            DECLARE @ID INT
            SET @ID = Scope_identity()
            SET @CardAccount = @CardAccount + CONVERT(VARCHAR(10), @ID)
            UPDATE Qianbo_Card
            SET    CardAccount = @CardAccount
            WHERE  [id] = @ID
        END
      SELECT @CardAccount AS Account
  END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_Users_Delete] @UserID INT
AS
    SET Xact_Abort ON
    BEGIN TRAN
    DELETE FROM Qianbo_Users
    WHERE  UserID = @UserId
    DELETE FROM Qianbo_UserFavorite
    WHERE  UserId = @UserId
    DELETE FROM Qianbo_UserCate
    WHERE  UserId = @UserId
    DELETE FROM Qianbo_UserFriend
    WHERE  FriendId = @UserId
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PowerGroup]'
GO
CREATE PROCEDURE [dbo].[Proc_PowerGroup] @PowerId       INT=0,
                                         @PowerName     NVARCHAR(50)=" ",
                                         @PowerColumn   NTEXT=" ",
                                         @PowerChannel  NTEXT=" ",
                                         @PowerAuditing NTEXT=" ",
                                         @PowerModel    NVARCHAR(50)=" ",
                                         @PowerContent  NVARCHAR(500)=" ",
                                         @AddDate       DATETIME="2008-8-8",
                                         @TypeId        INT=0,
                                         @AllChannel    NTEXT=" ",
                                         @AllColumn     NTEXT=" ",
                                         @PowerFunction NTEXT=" ",
                                         @SiteId        INT=0
AS
    IF @TypeId = 1
      BEGIN
          SELECT *
          FROM   [Qianbo_PowerGroup]
          WHERE  PowerModel = '否'
          ORDER  BY PowerId DESC
      END
    IF @TypeId = 2
      BEGIN
          SELECT *
          FROM   [Qianbo_PowerGroup]
          WHERE  PowerId = @PowerId
      END
    IF @TypeId = 3
      BEGIN
          UPDATE [Qianbo_PowerGroup]
          SET    PowerName = @PowerName,
                 PowerColumn = @PowerColumn,
                 PowerChannel = @PowerChannel,
                 PowerAuditing = @PowerAuditing,
                 PowerModel = @PowerModel,
                 PowerContent = @PowerContent,
                 AllChannel = @AllChannel,
                 AllColumn = @AllColumn,
                 PowerFunction = @PowerFunction,
                 SiteId = @SiteId
          WHERE  PowerId = @PowerId
      END
    IF @TypeId = 4
      BEGIN
          DELETE [Qianbo_PowerGroup]
          WHERE  PowerId = @PowerId
      END
    IF @TypeId = 5
      BEGIN
          INSERT INTO [Qianbo_PowerGroup]
                      (PowerName,
                       PowerColumn,
                       PowerChannel,
                       PowerAuditing,
                       PowerModel,
                       PowerContent,
                       AddDate,
                       AllChannel,
                       AllColumn,
                       PowerFunction,
                       SiteId)
          VALUES      (@PowerName,
                       @PowerColumn,
                       @PowerChannel,
                       @PowerAuditing,
                       @PowerModel,
                       @PowerContent,
                       @AddDate,
                       @AllChannel,
                       @AllColumn,
                       @PowerFunction,
                       @SiteId)
      END
    IF @TypeId = 6
      BEGIN
          SELECT *
          FROM   [Qianbo_PowerColumn]
          ORDER  BY PCId ASC
      END
    IF @TypeId = 7
      BEGIN
          SELECT PowerId,
                 PowerName
          FROM   [Qianbo_PowerGroup]
          WHERE  PowerModel = '是'
          ORDER  BY PowerId
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_CompleteDelete]'
GO
CREATE PROC [dbo].[Proc_Special_CompleteDelete] @specialid INT
AS
    DELETE FROM Qianbo_Special
    WHERE  id = @specialid
    DELETE FROM Qianbo_Special
    WHERE  parentid = @specialid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomForm_GetAll]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomForm_GetAll]
AS
    SELECT *
    FROM   [Qianbo_CustomForm]
    ORDER  BY CustomFormId DESC
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_GetAdminList]'
GO
CREATE PROC [dbo].[Proc_Admin_GetAdminList]
AS
    SELECT *
    FROM   Qianbo_Admin
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserLog_CheckIsPay]'
GO
CREATE PROCEDURE [dbo].[Proc_UserLog_CheckIsPay] @CheckPayType INT,
                                                 @ModelType    INT,
                                                 @InfoId       INT,
                                                 @UserId       INT,
                                                 @HourCount    INT,
                                                 @ViewCount    INT
AS
    IF( @CheckPayType = 6 )
      BEGIN
          SELECT 0;
          RETURN;
      END
    DECLARE @PrePayTime DATETIME;
    DECLARE @PreViewCount INT
    IF NOT EXISTS(SELECT Id
                  FROM   Qianbo_UserLog
                  WHERE  UserId = @UserId
                         AND ModelType = @ModelType
                         AND InfoId = @InfoId)
      BEGIN
          SELECT 0;
          RETURN;
      END
    IF( @CheckPayType = 1 )
      BEGIN
          SELECT 1;
          RETURN;
      END
    IF( @CheckPayType = 2 )
      BEGIN
          IF( @HourCount <= 0 )
            BEGIN
                SELECT 1;
                RETURN;
            END
          ELSE
            BEGIN
                SET @PrePayTime = (SELECT TOP 1 AddTime
                                   FROM   Qianbo_UserLog
                                   WHERE  UserId = @UserId
                                          AND ModelType = @ModelType
                                          AND InfoId = @InfoId
                                   ORDER  BY Id DESC)
                IF( Datediff(hour, @PrePayTime, Getdate()) < @HourCount )
                  BEGIN
                      SELECT 1;
                      RETURN;
                  END
                ELSE
                  BEGIN
                      SELECT 0;
                      RETURN;
                  END
            END
      END
    IF( @CheckPayType = 3 )
      BEGIN
          IF( @ViewCount <= 0 )
            BEGIN
                SELECT 1;
                RETURN;
            END
          ELSE
            BEGIN
                SET @PrePayTime = (SELECT TOP 1 AddTime
                                   FROM   Qianbo_UserLog
                                   WHERE  UserId = @UserId
                                          AND ModelType = @ModelType
                                          AND InfoId = @InfoId
                                   ORDER  BY Id DESC)
                SET @PreViewCount = (SELECT Count(Id)
                                     FROM   Qianbo_ViewLog
                                     WHERE  UserId = @UserId
                                            AND ModelType = @ModelType
                                            AND InfoId = @InfoId
                                            AND AddTime >= @PrePayTime)
                IF( @PreViewCount < @ViewCount )
                  BEGIN
                      SELECT 1;
                      RETURN;
                  END
                ELSE
                  BEGIN
                      SELECT 0;
                      RETURN;
                  END
            END
      END
    IF( @CheckPayType = 4 )
      BEGIN
          IF( @ViewCount <= 0
               OR @HourCount <= 0 )
            BEGIN
                SELECT 1;
                RETURN;
            END
          ELSE
            BEGIN
                SET @PrePayTime = (SELECT TOP 1 AddTime
                                   FROM   Qianbo_UserLog
                                   WHERE  UserId = @UserId
                                          AND ModelType = @ModelType
                                          AND InfoId = @InfoId
                                   ORDER  BY Id DESC)
                SET @PreViewCount = (SELECT Count(Id)
                                     FROM   Qianbo_ViewLog
                                     WHERE  UserId = @UserId
                                            AND ModelType = @ModelType
                                            AND InfoId = @InfoId
                                            AND AddTime >= @PrePayTime)
                IF( Datediff(hour, @PrePayTime, Getdate()) < @HourCount
                     OR @PreViewCount < @ViewCount )
                  BEGIN
                      SELECT 1;
                      RETURN;
                  END
                ELSE
                  BEGIN
                      SELECT 0;
                      RETURN;
                  END
            END
      END
    IF( @CheckPayType = 5 )
      BEGIN
          IF( @ViewCount <= 0
              AND @HourCount <= 0 )
            BEGIN
                SELECT 1;
                RETURN;
            END
          ELSE
            BEGIN
                SET @PrePayTime = (SELECT TOP 1 AddTime
                                   FROM   Qianbo_UserLog
                                   WHERE  UserId = @UserId
                                          AND ModelType = @ModelType
                                          AND InfoId = @InfoId
                                   ORDER  BY Id DESC)
                SET @PreViewCount = (SELECT Count(Id)
                                     FROM   Qianbo_ViewLog
                                     WHERE  UserId = @UserId
                                            AND ModelType = @ModelType
                                            AND InfoId = @InfoId
                                            AND AddTime >= @PrePayTime)
                IF( ( Datediff(hour, @PrePayTime, Getdate()) < @HourCount
                       OR @HourCount <= 0 )
                    AND ( @PreViewCount < @ViewCount
                           OR @ViewCount <= 0 ) )
                  BEGIN
                      SELECT 1;
                      RETURN;
                  END
                ELSE
                  BEGIN
                      SELECT 0;
                      RETURN;
                  END
            END
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_AdCategory]'
GO
CREATE TABLE [dbo].[Qianbo_AdCategory]
(
[AdCategoryId] [int] NOT NULL IDENTITY(1, 1),
[CategoryName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[IsDisabled] [int] NULL CONSTRAINT [DF_Qianbo_AdCategory_IsDisabled] DEFAULT ((1)),
[WidthHeigth] [varchar] (12) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_AdCategory_Width] DEFAULT ((468)|(60)),
[DisplayType] [int] NULL CONSTRAINT [DF_Qianbo_AdCategory_DisplayType] DEFAULT ((1)),
[Description] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Qianbo_AdCategory_Description] DEFAULT ('')
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_AdCategory] on [dbo].[Qianbo_AdCategory]'
GO
ALTER TABLE [dbo].[Qianbo_AdCategory] ADD CONSTRAINT [PK_Qianbo_AdCategory] PRIMARY KEY CLUSTERED  ([AdCategoryId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_AdCategory_Get]'
GO
CREATE PROCEDURE [dbo].[Proc_AdCategory_Get] @Type         INT,
                                             @AdCategoryId INT,
                                             @PageSize     INT=20,
                                             @PageIndex    INT=1,
                                             @WhereString  NVARCHAR(500)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @Filter NVARCHAR(2000)
    IF( @WhereString = '' )
      BEGIN
          SET @WhereString=' where '
          SET @Filter=''
      END
    ELSE
      BEGIN
          SET @Filter=' where ' + @WhereString
          SET @WhereString=' where ' + @WhereString + ' and '
      END
    IF( @Type = 1 )
      BEGIN
          SELECT *
          FROM   Qianbo_AdCategory
          WHERE  AdCategoryId = @AdCategoryId
      END
    IF( @Type = 2 )
      BEGIN
          IF( @PageIndex = 1 )
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' * from Qianbo_AdCategory ' + @Filter
                              + ' order by AdCategoryId desc'
            END
          ELSE
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' * from Qianbo_AdCategory ' + @WhereString
                              + ' AdCategoryId < (select min(AdCategoryId) from(select top '
                              + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                              + ' * from Qianbo_AdCategory  ' + @Filter
                              + ' order by AdCategoryId desc)O) order by AdCategoryId desc'
            END
          PRINT @SqlStr
          EXECUTE Sp_ExecuteSql
            @SqlStr
          SET @SqlStr = 'select Count(*) from Qianbo_AdCategory '
                        + @Filter
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_GetUser]'
GO
CREATE PROCEDURE [dbo].[Proc_Users_GetUser] @Identity NVARCHAR(20),
                                            @Type     INT
AS
    IF( @Type = 1 )
      SELECT *
      FROM   Qianbo_Users
      WHERE  UserId = @Identity
    IF( @Type = 0 )
      SELECT *
      FROM   Qianbo_Users
      WHERE  LogName = @Identity
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PowerGroup_BySiteId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_PowerGroup_BySiteId] @PowerId       INT=0,
                                                  @PowerName     NVARCHAR(50)=" ",
                                                  @PowerColumn   NTEXT=" ",
                                                  @PowerChannel  NTEXT=" ",
                                                  @PowerAuditing NTEXT=" ",
                                                  @PowerModel    NVARCHAR(50)=" ",
                                                  @PowerContent  NVARCHAR(500)=" ",
                                                  @AddDate       DATETIME="2008-8-8",
                                                  @TypeId        INT=0,
                                                  @AllChannel    NTEXT=" ",
                                                  @AllColumn     NTEXT=" ",
                                                  @PowerFunction NTEXT=" ",
                                                  @SiteId        INT=0
AS
    IF @TypeId = 1
      BEGIN
          SELECT *
          FROM   [Qianbo_PowerGroup]
          WHERE  PowerModel = '否'
                 AND SiteId = @SiteId
          ORDER  BY PowerId DESC
      END
    IF @TypeId = 2
      BEGIN
          SELECT *
          FROM   [Qianbo_PowerGroup]
          WHERE  PowerId = @PowerId
      END
    IF @TypeId = 3
      BEGIN
          UPDATE [Qianbo_PowerGroup]
          SET    PowerName = @PowerName,
                 PowerColumn = @PowerColumn,
                 PowerChannel = @PowerChannel,
                 PowerAuditing = @PowerAuditing,
                 PowerModel = @PowerModel,
                 PowerContent = @PowerContent,
                 AllChannel = @AllChannel,
                 AllColumn = @AllColumn,
                 PowerFunction = @PowerFunction,
                 SiteId = @SiteId
          WHERE  PowerId = @PowerId
      END
    IF @TypeId = 4
      BEGIN
          DELETE [Qianbo_PowerGroup]
          WHERE  PowerId = @PowerId
      END
    IF @TypeId = 5
      BEGIN
          INSERT INTO [Qianbo_PowerGroup]
                      (PowerName,
                       PowerColumn,
                       PowerChannel,
                       PowerAuditing,
                       PowerModel,
                       PowerContent,
                       AddDate,
                       AllChannel,
                       AllColumn,
                       PowerFunction,
                       SiteId)
          VALUES      (@PowerName,
                       @PowerColumn,
                       @PowerChannel,
                       @PowerAuditing,
                       @PowerModel,
                       @PowerContent,
                       @AddDate,
                       @AllChannel,
                       @AllColumn,
                       @PowerFunction,
                       @SiteId)
      END
    IF @TypeId = 6
      BEGIN
          SELECT *
          FROM   [Qianbo_PowerColumn]
          ORDER  BY PCId ASC
      END
    IF @TypeId = 7
      BEGIN
          SELECT PowerId,
                 PowerName
          FROM   [Qianbo_PowerGroup]
          WHERE  PowerModel = '是'
          ORDER  BY PowerId
      END
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_Delete]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Special_Delete] @ID INT
AS
    SET Xact_Abort ON
  BEGIN
      UPDATE Qianbo_Special
      SET    [IsDeleted] = 1
      WHERE  [ID] = @ID
      IF EXISTS(SELECT [ID]
                FROM   Qianbo_Special
                WHERE  ParentId = @ID)
        UPDATE Qianbo_Special
        SET    [IsDeleted] = 1
        WHERE  ParentId = @ID
  END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomForm_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomForm_GetModel] @CustomFormId INT
AS
    SELECT *
    FROM   [Qianbo_CustomForm]
    WHERE  CustomFormId = @CustomFormId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_VoteSubject_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_VoteSubject_Delete] @SubjectId INT
AS
    SET XACT_ABORT ON
    BEGIN TRAN
    DELETE FROM Qianbo_VoteSubject
    WHERE  VoteSubjectId = @SubjectId
    DELETE FROM Qianbo_Vote
    WHERE  subjectId = @SubjectId
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_GetAdminListByGroupId]'
GO
CREATE PROC [dbo].[Proc_Admin_GetAdminListByGroupId] @GroupId INT
AS
    SELECT UserId,
           UserName,
           GroupName,
           AllowMultiLogin,
           LastLoginIP,
           LastLoginTime,
           LoginTime
    FROM   Qianbo_Admin
    WHERE  GroupId = @GroupId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_Add]'
GO
CREATE PROC [dbo].[Proc_Property_Add] @ParentId         INT,
                                      @PropertyCName    NVARCHAR(400),
                                      @PropertyEName    NVARCHAR(400),
                                      @PropertyKeyword  NVARCHAR(1000),
                                      @PropertyContent  TEXT,
                                      @PropertyExtName  INT,
                                      @PropertyPic      NVARCHAR(400),
                                      @PropertyTemplate NVARCHAR(400),
                                      @PropertyDir      INT,
                                      @PropertyOrder    INT
AS
    INSERT INTO Qianbo_Property
                ([ParentId],
                 [PropertyCName],
                 [PropertyEName],
                 [PropertyKeyword],
                 [PropertyContent],
                 [PropertyExtName],
                 [PropertyPic],
                 [PropertyTemplate],
                 [PropertyDir],
                 [PropertyOrder])
    VALUES      ( @ParentId,
                  @PropertyCName,
                  @PropertyEName,
                  @PropertyKeyword,
                  @PropertyContent,
                  @PropertyExtName,
                  @PropertyPic,
                  @PropertyTemplate,
                  @PropertyDir,
                  @PropertyOrder )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TagCateogry_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_TagCateogry_Delete] @TagCategoryId INT
AS
    SET Xact_Abort ON
    BEGIN TRAN
    UPDATE Qianbo_Tag
    SET    TagCategoryId = 0
    WHERE  TagCategoryId = @TagCategoryId
    DELETE FROM Qianbo_TagCategory
    WHERE  TagCategoryId = @TagCategoryId
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_ConById]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_ConById] @StyleID INT
AS
    SELECT Content
    FROM   Qianbo_Style
    WHERE  StyleID = @StyleID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_GetAll]'
GO
CREATE PROCEDURE [dbo].[Proc_Special_GetAll]
AS
    SELECT *
    FROM   Qianbo_Special
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomForm_Update]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_CustomForm_Update] @CustomFormId INT,
                                                @ShowForm     INT,
                                                @FormName     NVARCHAR(100),
                                                @TableName    NVARCHAR(100),
                                                @UploadPath   NVARCHAR(100),
                                                @FormDesc     NVARCHAR(400),
                                                @IsUnlockTime BIT,
                                                @StartTime    DATETIME,
                                                @EndTime      DATETIME,
                                                @UserGroup    NVARCHAR(200),
                                                @IsSubmitNum  BIT,
                                                @Money        INT,
                                                @IsValidate   BIT,
                                                @AddTime      DATETIME
AS
    UPDATE [Qianbo_CustomForm]
    SET    [ShowForm] = @ShowForm,
           [FormName] = @FormName,
           [TableName] = @TableName,
           [UploadPath] = @UploadPath,
           [FormDesc] = @FormDesc,
           [IsUnlockTime] = @IsUnlockTime,
           [StartTime] = @StartTime,
           [EndTime] = @EndTime,
           [UserGroup] = @UserGroup,
           [IsSubmitNum] = @IsSubmitNum,
           [Money] = @Money,
           [IsValidate] = @IsValidate,
           [AddTime] = @AddTime
    WHERE  [CustomFormId] = @CustomFormId
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LbCategory_Update]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LbCategory_Update] @LbCategoryID INT,
                                                @Name         NVARCHAR(100),
                                                @ParentID     INT,
                                                @Desc         NVARCHAR(200)
AS
    UPDATE Qianbo_LbCategory
    SET    [Name] = @Name,
           [ParentID] = @ParentID,
           [Desc] = @Desc
    WHERE  [LbCategoryID] = @LbCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Card_Delete]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Card_Delete] @CardAccount VARCHAR(15)
AS
    DELETE Qianbo_Card
    WHERE  [CardAccount] = @CardAccount
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Admin_GetInfoById]'
GO
CREATE PROCEDURE [dbo].[Proc_Admin_GetInfoById] @UserId INT
AS
    SELECT *
    FROM   [Qianbo_Admin]
    WHERE  UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserLog_ReducePoint]'
GO
CREATE PROCEDURE [dbo].[Proc_UserLog_ReducePoint] @UserId INT,
                                                  @Point  INT
AS
    DECLARE @CurrPoint INT
    SET @CurrPoint=(SELECT YellowBoy
                    FROM   Qianbo_Users
                    WHERE  UserId = @UserId)
    IF( @CurrPoint < @Point )
      SELECT 0;
    ELSE
      BEGIN
          UPDATE Qianbo_Users
          SET    YellowBoy = YellowBoy - @Point
          WHERE  UserId = @UserId
          SELECT 1
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_RechargeRecord]'
GO
CREATE TABLE [dbo].[Qianbo_RechargeRecord]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[UserId] [int] NOT NULL,
[CardAccount] [varchar] (15) COLLATE Chinese_PRC_CI_AS NOT NULL,
[CardPoint] [int] NULL,
[CardDay] [int] NULL,
[RechargeDate] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_RechargeRecord] on [dbo].[Qianbo_RechargeRecord]'
GO
ALTER TABLE [dbo].[Qianbo_RechargeRecord] ADD CONSTRAINT [PK_Qianbo_RechargeRecord] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_Recharge]'
GO
CREATE PROCEDURE [dbo].[Proc_User_Recharge] (@UserId      INT,
                                             @CardAccount VARCHAR(15),
                                             @CardPwd     VARCHAR(200),
                                             @Flag        INT output)
AS
    SET Xact_Abort ON
    BEGIN TRAN
    IF EXISTS(SELECT [ID]
              FROM   Qianbo_Card
              WHERE  CardAccount = @CardAccount
                     AND Password = @CardPwd)
      BEGIN
          DECLARE @Type INT
          DECLARE @Point INT
          DECLARE @date DATETIME
          DECLARE @day INT
          DECLARE @IsUsed BIT
          DECLARE @expireTime DATETIME
          SELECT @Type = Type
          FROM   Qianbo_Card
          WHERE  CardAccount = @CardAccount
          SELECT @Point = CardPoint
          FROM   Qianbo_Card
          WHERE  CardAccount = @CardAccount
          SELECT @date = OverdueDate
          FROM   Qianbo_Card
          WHERE  CardAccount = @CardAccount
          SELECT @day = CardDay
          FROM   Qianbo_Card
          WHERE  CardAccount = @CardAccount
          SELECT @IsUsed = IsUsed
          FROM   Qianbo_Card
          WHERE  CardAccount = @CardAccount
          SELECT @expireTime = ExpireTime
          FROM   Qianbo_Users
          WHERE  UserId = @UserId
          IF( @IsUsed = 0 )
            BEGIN
                IF( @date > Getdate() )
                  BEGIN
                      IF( @Type = 1 )
                        BEGIN
                            UPDATE Qianbo_Card
                            SET    OverdueDate = Dateadd(dd, @day, OverdueDate),
                                   IsUsed = 1,
                                   UserId = @UserId
                            WHERE  CardAccount = @CardAccount
                            IF( @expireTime >= Getdate() )
                              UPDATE Qianbo_Users
                              SET    ExpireTime = Dateadd(dd, @day, @expireTime)
                              WHERE  UserId = @UserId
                            ELSE
                              UPDATE Qianbo_Users
                              SET    ExpireTime = Dateadd(dd, @day, Getdate())
                              WHERE  UserId = @UserId
                            INSERT INTO Qianbo_RechargeRecord
                            VALUES      (@UserId,
                                         @CardAccount,
                                         @Point,
                                         @day,
                                         Getdate())
                            SET @Flag=1
                        END
                      IF( @Type = 0 )
                        BEGIN
                            UPDATE Qianbo_Users
                            SET    YellowBoy = YellowBoy + @Point
                            WHERE  UserId = @UserId
                            UPDATE Qianbo_Card
                            SET    IsUsed = 1,
                                   UserId = @UserId
                            WHERE  CardAccount = @CardAccount
                            INSERT INTO Qianbo_RechargeRecord
                            VALUES      (@UserId,
                                         @CardAccount,
                                         @Point,
                                         @day,
                                         Getdate())
                            SET @Flag=1
                        END
                  END
                ELSE
                  SET @Flag=3
            END
          ELSE
            SET @Flag=2
      END
    ELSE
      SET @Flag=4
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_CompleteDelete]'
GO
CREATE PROC [dbo].[Proc_Column_CompleteDelete] @colid INT
AS
    DECLARE @tablename NVARCHAR(50)
    SET @tablename = (SELECT tablename
                      FROM   Qianbo_Column co
                             JOIN Qianbo_Channel ch
                               ON co.chid = ch.chid
                             JOIN Qianbo_Model m
                               ON ch.modeltype = m.modelid
                      WHERE  co.colid = @colid)
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'declare @tb table(id int)  ' + 'insert into @tb select @tcolid  while exists(select * from Qianbo_Column where (colparentid in(select [id] from @tb)) and (colid not in(select [id] from @tb)))
begin
        insert into @tb select colid from Qianbo_Column where (colparentid in(select [id] from @tb)) and (colid not in(select [id] from @tb))
end  '
                  + 'delete i from [' + @tablename
                  + '] i join @tb t on i.colid = t.[id] '
                  + 'delete co from Qianbo_Column co join @tb t on co.colid = t.[id]'
    DECLARE @param NVARCHAR(200)
    SET @param='@tcolid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tcolid = @colid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_VoteSubject_Get]'
GO
CREATE PROCEDURE [dbo].[Proc_VoteSubject_Get] @SubjectId INT=0,
                                              @Type      INT,
                                              @PageSize  INT=20,
                                              @PageIndex INT=1,
                                              @WhereStr  VARCHAR(100)='',
                                              @Total     INT=0 output
AS
  BEGIN
      DECLARE @SqlStr NVARCHAR(2000)
      DECLARE @fff NVARCHAR(200)
      IF @WhereStr != ''
        BEGIN
            SET @fff=' where ' + @WhereStr + ' and'
            SET @WhereStr=' where ' + @WhereStr
        END
      IF @WhereStr = ''
        SET @fff=' where '
      IF @Type = 1
        IF @PageIndex = 1
          BEGIN
              SET @SqlStr = N'select top '
                            + CONVERT(NVARCHAR(10), @PageSize)
                            + ' Qianbo_VoteSubject.* ,Qianbo_VoteCategory.Name as CategoryName from Qianbo_VoteSubject left join Qianbo_VoteCategory on Qianbo_VoteSubject.CategoryId = Qianbo_VoteCategory.CategoryId  '
                            + @WhereStr + ' order by VoteSubjectID desc'
          END
        ELSE
          SET @SqlStr = N'select top '
                        + CONVERT(NVARCHAR(10), @PageSize)
                        + ' Qianbo_VoteSubject.*,Qianbo_VoteCategory.Name as CategoryName from Qianbo_VoteSubject left join Qianbo_VoteCategory on Qianbo_VoteSubject.CategoryId = Qianbo_VoteCategory.CategoryId '
                        + @fff
                        + ' VoteSubjectID < (select min(VoteSubjectID) from(select top '
                        + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                        + ' Qianbo_VoteSubject.* from Qianbo_VoteSubject order by VoteSubjectID desc)O) order by VoteSubjectID desc'
      IF @Type = 2
        SELECT Qianbo_Vote.*,
               Qianbo_VoteSubject.*
        FROM   Qianbo_Vote
               JOIN Qianbo_VoteSubject
                 ON Qianbo_Vote.SubjectId = Qianbo_VoteSubject.VoteSubjectId
        WHERE  VoteSubjectId = @SubjectId
  END
EXECUTE Sp_ExecuteSql
  @SqlStr
SET @SqlStr ='select @TRecord = Count(VoteSubjectID) from Qianbo_VoteSubject '
             + @WhereStr
DECLARE @Parm NVARCHAR(50)
SET @Parm = '@TRecord int output';
EXEC Sp_ExecuteSql
  @SqlStr,
  @Parm,
  @TRecord = @Total output;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_Login_Error]'
GO
CREATE PROC [dbo].[Proc_Users_Login_Error] @userid INT
AS
    UPDATE [Qianbo_Users]
    SET    [errornum] = [errornum] + 1
    WHERE  [userid] = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_GetAllList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Property_GetAllList]
AS
    SELECT *
    FROM   Qianbo_Property
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SinglePage_Del]'
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_SinglePage_Del] @SingleId INT
AS
    DELETE Qianbo_SinglePage
    WHERE  [SingleId] = @SingleId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LbContent_DeleteLbCategoryId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[Proc_LbContent_DeleteLbCategoryId] @lbCategoryID INT
AS
    DELETE FROM Qianbo_LabelContent
    WHERE  LbCategoryId = @lbCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_Style_Delete] @StyleId INT
AS
    DELETE FROM Qianbo_Style
    WHERE  StyleId = @StyleId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Special_GetChSpecialList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Special_GetChSpecialList] @chid INT
AS
    SELECT *
    FROM   Qianbo_Special
    WHERE  ( siteid = @chid
              OR siteid = 0 )
           AND isdeleted = 0
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_AdCategory_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_AdCategory_Set] @Type         INT,
                                             @AdCategoryId INT,
                                             @CategoryName NVARCHAR(100),
                                             @IsDisabled   INT,
                                             @WidthHeigth  VARCHAR(12),
                                             @DisplayType  INT,
                                             @Description  NVARCHAR(100)
AS
    IF( @Type = 1 )
      BEGIN
          INSERT INTO Qianbo_AdCategory
                      ([CategoryName],
                       [IsDisabled],
                       [WidthHeigth],
                       [DisplayType],
                       [Description])
          VALUES      ( @CategoryName,
                        @IsDisabled,
                        @WidthHeigth,
                        @DisplayType,
                        @Description )
      END
    IF( @Type = 2 )
      BEGIN
          UPDATE Qianbo_AdCategory
          SET    [CategoryName] = @CategoryName,
                 [IsDisabled] = @IsDisabled,
                 [WidthHeigth] = @WidthHeigth,
                 [DisplayType] = @DisplayType,
                 [Description] = @Description
          WHERE  [AdCategoryId] = @AdCategoryId
      END
    IF( @Type = 3 )
      BEGIN
          DELETE Qianbo_AdCategory
          WHERE  [AdCategoryId] = @AdCategoryId
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_Column_Delete] @chid     INT,
                                            @colidstr NVARCHAR(2000)
AS
    SET Xact_Abort ON
    BEGIN TRAN
    DECLARE @modeltype INT
    SET @modeltype=(SELECT ModelType
                    FROM   Qianbo_Channel
                    WHERE  chid = @chid);
    DECLARE @tablename NVARCHAR(50)
    SET @tablename = (SELECT tablename
                      FROM   Qianbo_Model
                      WHERE  ModelId = @modeltype)
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update i set i.[isdeleted] = 1 from ['
                  + @tablename + '] i where i.colid in('
                  + @colidstr + ')'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr = 'update co set co.[isdeleted] = 1 from Qianbo_Column co where co.colid in('
                  + @colidstr + ')'
    EXECUTE sp_executesql
      @sqlstr
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Card_GetCard]'
GO
CREATE PROCEDURE [dbo].[Proc_Card_GetCard] @Account VARCHAR(15)
AS
    SELECT [Type],
           [Password],
           [IsUsed],
           [CardPoint],
           [CardDay],
           [AdminID],
           [AdminName],
           [UserID],
           [UserName],
           [OverdueDate]
    FROM   Qianbo_Card
    WHERE  [CardAccount] = @Account
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoad_IsAllowDeleteType]'
GO
CREATE PROC [dbo].[Proc_DownLoad_IsAllowDeleteType] @TypeId INT
AS
    SELECT a.[TypeId]
    FROM   Qianbo_DownLoadServerType a
           INNER JOIN Qianbo_DownLoadServerData b
                   ON a.[TypeId] = b.TypeId
    WHERE  a.[TypeId] = @TypeId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Tag_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Tag_Add] @Name          NVARCHAR(20),
                                      @TagCategoryId INT,
                                      @ModelType     INT,
                                      @UserId        INT,
                                      @UserName      NVARCHAR(20)
AS
    IF EXISTS(SELECT *
              FROM   Qianbo_Tag
              WHERE  NAME = @Name)
      RETURN
    INSERT INTO Qianbo_Tag
                ([Name],
                 TagCategoryId,
                 ModelType,
                 UserId,
                 UserName)
    VALUES      (@Name,
                 @TagCategoryId,
                 @ModelType,
                 @UserId,
                 @UserName)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_VoteSubject_GetAll]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_VoteSubject_GetAll]
AS
    SELECT VoteSubjectId,
           Subject,
           EndDate,
           RequireLogin
    FROM   Qianbo_VoteSubject
    ORDER  BY VoteSubjectId DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_DeleteAndStyleCategoryId]'
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Proc_Style_DeleteAndStyleCategoryId] @StyleCategoryID INT
AS
    DELETE FROM Qianbo_Style
    WHERE  StyleCategoryID = @StyleCategoryID
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Dictionary]'
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Qianbo_Dictionary]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[ParentId] [int] NOT NULL,
[DicName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Sort] [int] NULL CONSTRAINT [DF_Qianbo_Dictionary2_Sort] DEFAULT ((5))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_Dictionary] on [dbo].[Qianbo_Dictionary]'
GO
ALTER TABLE [dbo].[Qianbo_Dictionary] ADD CONSTRAINT [PK_Qianbo_Dictionary] PRIMARY KEY CLUSTERED  ([ID])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Dictionary_Get]'
GO
CREATE PROCEDURE [dbo].[Proc_Dictionary_Get] @Type      INT,
                                             @PageSize  INT=20,
                                             @PageIndex INT=1,
                                             @WhereStr  NVARCHAR(2000),
                                             @Id        INT
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @Filter NVARCHAR(2000)
    IF( @WhereStr = '' )
      BEGIN
          SET @WhereStr=' where '
          SET @Filter=''
      END
    ELSE
      BEGIN
          SET @Filter=' where ' + @WhereStr
          SET @WhereStr=' where ' + @WhereStr + ' and '
      END
    IF( @Type = 1 )
      BEGIN
          SELECT *
          FROM   Qianbo_Dictionary
          WHERE  [ID] = @Id
      END
    IF( @Type = 2 )
      BEGIN
          IF( @PageIndex = 1 )
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' * from Qianbo_Dictionary ' + @Filter
                              + ' order by Sort,[ID] desc'
            END
          ELSE
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' * from Qianbo_Dictionary ' + @WhereStr
                              + ' [ID] < (select min([ID]) from(select top '
                              + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                              + ' * from Qianbo_Dictionary  ' + @Filter
                              + ' order by Sort,[ID] desc)O) order by Sort,[ID] desc'
            END
          EXECUTE Sp_ExecuteSql
            @SqlStr
          SET @SqlStr = 'select Count(*) from Qianbo_Dictionary '
                        + @Filter
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_VoteSubject_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_VoteSubject_Update] @VoteSubjectId INT,
                                                 @Subject       NVARCHAR(200),
                                                 @StartDate     DATETIME,
                                                 @EndDate       DATETIME,
                                                 @RequireLogin  BIT,
                                                 @CategoryId    INT
AS
    UPDATE Qianbo_VoteSubject
    SET    [Subject] = @Subject,
           [StartDate] = @StartDate,
           [EndDate] = @EndDate,
           [RequireLogin] = @RequireLogin,
           [CategoryId] = @CategoryId
    WHERE  [VoteSubjectId] = @VoteSubjectId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_GetAll]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_GetAll]
AS
    SELECT *
    FROM   Qianbo_Style
    ORDER  BY StyleID DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Card_Update]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Card_Update] @Type        INT,
                                          @CardAccount VARCHAR(20),
                                          @Password    VARCHAR(200),
                                          @IsUsed      BIT,
                                          @CardPoint   INT,
                                          @CardDay     INT,
                                          @AdminID     INT,
                                          @AdminName   VARCHAR(50),
                                          @UserID      INT,
                                          @UserName    NVARCHAR(36),
                                          @OverdueDate DATETIME
AS
    UPDATE Qianbo_Card
    SET    [Type] = @Type,
           [Password] = @Password,
           [IsUsed] = @IsUsed,
           [CardPoint] = @CardPoint,
           [CardDay] = @CardDay,
           [AdminID] = @AdminID,
           [AdminName] = @AdminName,
           [UserID] = @UserID,
           [UserName] = @UserName,
           [OverdueDate] = @OverdueDate
    WHERE  [CardAccount] = @CardAccount
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Vote_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Vote_Add] @SubjectId   INT,
                                       @VoteTitle   NVARCHAR(100),
                                       @DisplayType INT,
                                       @IsMore      BIT,
                                       @ModelType   INT,
                                       @ItemTitle1  NVARCHAR(100),
                                       @ItemNum1    INT,
                                       @ItemTitle2  NVARCHAR(100),
                                       @ItemNum2    INT,
                                       @ItemTitle3  NVARCHAR(100),
                                       @ItemNum3    INT,
                                       @ItemTitle4  NVARCHAR(100),
                                       @ItemNum4    INT,
                                       @ItemTitle5  NVARCHAR(100),
                                       @ItemNum5    INT,
                                       @ItemTitle6  NVARCHAR(100),
                                       @ItemNum6    INT
AS
    INSERT INTO Qianbo_Vote
                ([SubjectId],
                 [VoteTitle],
                 [DisplayType],
                 [IsMore],
                 [ModelType],
                 [ItemTitle1],
                 [ItemNum1],
                 [ItemTitle2],
                 [ItemNum2],
                 [ItemTitle3],
                 [ItemNum3],
                 [ItemTitle4],
                 [ItemNum4],
                 [ItemTitle5],
                 [ItemNum5],
                 [ItemTitle6],
                 [ItemNum6])
    VALUES      ( @SubjectId,
                  @VoteTitle,
                  @DisplayType,
                  @IsMore,
                  @ModelType,
                  @ItemTitle1,
                  @ItemNum1,
                  @ItemTitle2,
                  @ItemNum2,
                  @ItemTitle3,
                  @ItemNum3,
                  @ItemTitle4,
                  @ItemNum4,
                  @ItemTitle5,
                  @ItemNum5,
                  @ItemTitle6,
                  @ItemNum6 )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserMessage_GetById]'
GO
CREATE PROC [dbo].[Proc_UserMessage_GetById] @Id     INT,
                                             @UserId INT
AS
    SELECT *
    FROM   Qianbo_UserMessage
    WHERE  [id] = @Id
           AND UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_GetByModelId]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_GetByModelId] @type INT
AS
    SELECT StyleID,
           [Name]
    FROM   Qianbo_Style
    WHERE  [Type] = @type
    ORDER  BY StyleID DESC
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Dictionary_Set]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Dictionary_Set] @Type     INT,
                                             @Id       INT,
                                             @ParentId INT,
                                             @DicName  NVARCHAR(50),
                                             @Sort     INT,
                                             @Identity INT=0 output
AS
    IF @Type = 1
      BEGIN
          INSERT INTO Qianbo_Dictionary
          VALUES      (@ParentId,
                       @DicName,
                       @Sort)
          SELECT @Identity = Scope_identity()
      END
    IF @Type = 2
      BEGIN
          UPDATE Qianbo_Dictionary
          SET    ParentId = @ParentId,
                 DicName = @DicName,
                 Sort = @Sort
          WHERE  ID = @Id
      END
    IF @Type = 3
      BEGIN
          DELETE FROM Qianbo_Dictionary
          WHERE  ID = @Id
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Channel_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_Channel_Add] @ChName              NVARCHAR(50),
                                          @Description         NVARCHAR(255),
                                          @TemplatePath        NVARCHAR(255),
                                          @IsChildSite         BIT,
                                          @ChildSiteUrl        NVARCHAR(255),
                                          @IsOpenLink          BIT,
                                          @ModelType           INT,
                                          @DirName             NVARCHAR(50),
                                          @TypeName            NVARCHAR(10),
                                          @TypeUnit            NVARCHAR(10),
                                          @IsDisabled          BIT,
                                          @IsOpened            BIT,
                                          @GroupIdStr          VARCHAR(500),
                                          @VerifyType          INT,
                                          @Notice1             NVARCHAR(500),
                                          @Notice2             NVARCHAR(500),
                                          @Keyword             NVARCHAR(100),
                                          @Content             NVARCHAR(300),
                                          @MiniHitCount        INT,
                                          @IsStaticType        BIT,
                                          @ColumnSortType      INT,
                                          @InfoSortType        INT,
                                          @FileNameType        INT,
                                          @ChannelPageType     INT,
                                          @ColumnPageType      INT,
                                          @InfoPageType        INT,
                                          @AddTime             DATETIME,
                                          @Sort                INT,
                                          @ColumnTemplatePath  NVARCHAR(255),
                                          @InfoTemplatePath    NVARCHAR(255),
                                          @CommentTemplatePath NVARCHAR(255),
                                          @IsDeleted           BIT,
                                          @ChType              INT
AS
    INSERT INTO Qianbo_Channel
                ([ChName],
                 [Description],
                 [TemplatePath],
                 [IsChildSite],
                 [ChildSiteUrl],
                 [IsOpenLink],
                 [ModelType],
                 [DirName],
                 [TypeName],
                 [TypeUnit],
                 [IsDisabled],
                 [IsOpened],
                 [GroupIdStr],
                 [VerifyType],
                 [Notice1],
                 [Notice2],
                 [Keyword],
                 [Content],
                 [MiniHitCount],
                 [IsStaticType],
                 [ColumnSortType],
                 [InfoSortType],
                 [FileNameType],
                 [ChannelPageType],
                 [ColumnPageType],
                 [InfoPageType],
                 [AddTime],
                 [Sort],
                 [ColumnTemplatePath],
                 [InfoTemplatePath],
                 [CommentTemplatePath],
                 [IsDeleted],
                 [ChType])
    VALUES      ( @ChName,
                  @Description,
                  @TemplatePath,
                  @IsChildSite,
                  @ChildSiteUrl,
                  @IsOpenLink,
                  @ModelType,
                  @DirName,
                  @TypeName,
                  @TypeUnit,
                  @IsDisabled,
                  @IsOpened,
                  @GroupIdStr,
                  @VerifyType,
                  @Notice1,
                  @Notice2,
                  @Keyword,
                  @Content,
                  @MiniHitCount,
                  @IsStaticType,
                  @ColumnSortType,
                  @InfoSortType,
                  @FileNameType,
                  @ChannelPageType,
                  @ColumnPageType,
                  @InfoPageType,
                  @AddTime,
                  @Sort,
                  @ColumnTemplatePath,
                  @InfoTemplatePath,
                  @CommentTemplatePath,
                  @IsDeleted,
                  @ChType )
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadAddress_GetGroupAddresList]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_DownLoadAddress_GetGroupAddresList] @addresnum        INT,
                                                                 @downloadserverid INT
AS
    SELECT *
    FROM   Qianbo_DownLoadAddress a
           LEFT JOIN Qianbo_DownLoadServerType b
                  ON downloadserverid = b.typeid
           LEFT JOIN Qianbo_DownLoadServerData c
                  ON b.typeid = c.typeid
    WHERE  a.downloaddataid = @addresnum
           AND a.downloadserverid = @downloadserverid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Ad_Get]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Ad_Get] @Type        INT,
                                     @AdId        INT,
                                     @PageSize    INT=20,
                                     @PageIndex   INT=1,
                                     @WhereString NVARCHAR(500)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @Filter NVARCHAR(2000)
    IF( @WhereString = '' )
      BEGIN
          SET @WhereString=' where '
          SET @Filter=''
      END
    ELSE
      BEGIN
          SET @Filter=' where ' + @WhereString
          SET @WhereString=' where ' + @WhereString + ' and '
      END
    IF( @Type = 1 )
      BEGIN
          SELECT *
          FROM   Qianbo_Ad
          WHERE  AdId = @AdId
      END
    IF( @Type = 2 )
      BEGIN
          IF( @PageIndex = 1 )
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' Qianbo_Ad.*,Qianbo_AdCategory.CategoryName from Qianbo_Ad left join Qianbo_AdCategory on Qianbo_Ad.CategoryId = Qianbo_AdCategory.AdCategoryId '
                              + @Filter + ' order by AdId desc'
            END
          ELSE
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' Qianbo_Ad.*,Qianbo_AdCategory.CategoryName from Qianbo_Ad left join Qianbo_AdCategory on Qianbo_Ad.CategoryId = Qianbo_AdCategory.AdCategoryId '
                              + @WhereString
                              + ' AdId < (select min(AdId) from(select top '
                              + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                              + ' * from Qianbo_Ad  ' + @Filter
                              + ' order by AdId desc)O) order by AdId desc'
            END
          EXECUTE Sp_ExecuteSql
            @SqlStr
          SET @SqlStr = 'select Count(*) from Qianbo_Ad ' + @Filter
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Vote_GetVoteIdByInfo]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Vote_GetVoteIdByInfo] @voteId INT
AS
    SELECT *
    FROM   Qianbo_Vote
    WHERE  voteId = @voteId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserMessage_Resume]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_UserMessage_Resume] @Id            INT,
                                                 @UserId        INT,
                                                 @ResumeContent TEXT,
                                                 @ResumeTime    NVARCHAR(100)
AS
    UPDATE Qianbo_UserMessage
    SET    IsResume = 1,
           [ResumeContent] = @ResumeContent,
           [ResumeTime] = @ResumeTime
    WHERE  [Id] = @Id
           AND UserId = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_SetFriend]'
GO
CREATE PROCEDURE [dbo].[Proc_User_SetFriend] (@Id        INT,
                                              @IsDisable INT)
AS
    UPDATE Qianbo_UserFriend
    SET    FriendGroupId = @IsDisable
    WHERE  [ID] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Style_GetHasRows]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Style_GetHasRows] @Name NVARCHAR(200)
AS
    SELECT [Name]
    FROM   Qianbo_Style
    WHERE  [Name] = @Name
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_GetList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Property_GetList] @ParentId INT
AS
    SELECT *
    FROM   Qianbo_Property
    WHERE  [ParentId] = @ParentId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SinglePage_GetModel]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SinglePage_GetModel] @SingleId INT
AS
    SELECT [SingleId],
           [Name],
           [FolderPath],
           [FileName],
           [FileExtend],
           [TemplatePath],
           [Content],
           [AddTime]
    FROM   [Qianbo_SinglePage]
    WHERE  [SingleId] = @SingleId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_Property_GetModel] @Id INT
AS
    SELECT *
    FROM   Qianbo_Property
    WHERE  [Id] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_FeedBack_Add]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_FeedBack_Add] @ParentId   INT,
                                           @title      NVARCHAR(100),
                                           @author     NVARCHAR(20),
                                           @reward     INT,
                                           @scoring    INT,
                                           @categoryId INT,
                                           @content    NTEXT,
                                           @state      INT,
                                           @replyDate  DATETIME,
                                           @EndDate    DATETIME,
                                           @IP         NVARCHAR(15)
AS
    SET Xact_Abort ON
    BEGIN TRAN
    IF @ParentId = 0
      BEGIN
          INSERT INTO Qianbo_FeedBack
                      ([ParentId],
                       [title],
                       [author],
                       [reward],
                       [scoring],
                       [categoryId],
                       [content],
                       [state],
                       [replyDate],
                       [EndDate],
                       [IP])
          VALUES      ( @ParentId,
                        @title,
                        @author,
                        @reward,
                        @scoring,
                        @categoryId,
                        @content,
                        @state,
                        @replyDate,
                        @EndDate,
                        @IP )
      END
    ELSE
      BEGIN
          INSERT INTO Qianbo_FeedBack
                      ([ParentId],
                       [author],
                       [scoring],
                       [content],
                       [replyDate],
                       [IP])
          VALUES      ( @ParentId,
                        @author,
                        @scoring,
                        @content,
                        @replyDate,
                        @IP )
      END
    COMMIT TRAN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_ExtendContent]'
GO
CREATE TABLE [dbo].[Qianbo_ExtendContent]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ChId] [int] NULL,
[ColId] [int] NULL,
[ModelId] [int] NULL,
[InfoId] [int] NULL,
[FieldId] [int] NULL,
[FieldName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Nvarchar] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[DateTime] [datetime] NULL,
[Ntext] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[Bit] [bit] NULL,
[Decimal] [decimal] (18, 2) NULL,
[Int] [int] NULL,
[AddTime] [datetime] NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_Qianbo_ExtendContent] on [dbo].[Qianbo_ExtendContent]'
GO
ALTER TABLE [dbo].[Qianbo_ExtendContent] ADD CONSTRAINT [PK_Qianbo_ExtendContent] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Form_WoYaoGuJia]'
GO
CREATE TABLE [dbo].[Qianbo_Form_WoYaoGuJia]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[UId] [int] NULL,
[UName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Ip] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[AddTime] [datetime] NULL,
[ChengHu] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_Fo__Cheng__4C214075] DEFAULT (''),
[PinPai_Id] [int] NULL,
[PinPai] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_Fo__PinPa__4D1564AE] DEFAULT (''),
[DianHua] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_Fo__DianH__4E0988E7] DEFAULT (''),
[FuYan] [ntext] COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK__Qianbo_F__3214EC074A38F803] on [dbo].[Qianbo_Form_WoYaoGuJia]'
GO
ALTER TABLE [dbo].[Qianbo_Form_WoYaoGuJia] ADD CONSTRAINT [PK__Qianbo_F__3214EC074A38F803] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Form_WoYaoGuJia_UId] on [dbo].[Qianbo_Form_WoYaoGuJia]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Form_WoYaoGuJia_UId] ON [dbo].[Qianbo_Form_WoYaoGuJia] ([UId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_Form_WoYaoMaiChe]'
GO
CREATE TABLE [dbo].[Qianbo_Form_WoYaoMaiChe]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[UId] [int] NULL,
[UName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[Ip] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[AddTime] [datetime] NULL,
[ChengHu] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_Fo__Cheng__44801EAD] DEFAULT (''),
[PinPai_Id] [int] NULL,
[PinPai] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_Fo__PinPa__475C8B58] DEFAULT (''),
[DianHua] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_Fo__DianH__4668671F] DEFAULT (''),
[FuYan] [ntext] COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK__Qianbo_F__3214EC074297D63B] on [dbo].[Qianbo_Form_WoYaoMaiChe]'
GO
ALTER TABLE [dbo].[Qianbo_Form_WoYaoMaiChe] ADD CONSTRAINT [PK__Qianbo_F__3214EC074297D63B] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_Form_WoYaoMaiChe_UId] on [dbo].[Qianbo_Form_WoYaoMaiChe]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_Form_WoYaoMaiChe_UId] ON [dbo].[Qianbo_Form_WoYaoMaiChe] ([UId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_SalesProject]'
GO
CREATE TABLE [dbo].[Qianbo_SalesProject]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[Name] [nvarchar] (250) COLLATE Chinese_PRC_CI_AS NULL,
[ValidityStartTime] [datetime] NULL,
[ValidityEndTime] [datetime] NULL,
[PriceStart] [decimal] (18, 0) NULL,
[PreceEnd] [decimal] (18, 0) NULL,
[Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK_SalesProject] on [dbo].[Qianbo_SalesProject]'
GO
ALTER TABLE [dbo].[Qianbo_SalesProject] ADD CONSTRAINT [PK_SalesProject] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_U_CheYuan]'
GO
CREATE TABLE [dbo].[Qianbo_U_CheYuan]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[ChId] [int] NOT NULL,
[ColId] [int] NOT NULL,
[Title] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Title__222B06A9] DEFAULT (''),
[TitleColor] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Title__231F2AE2] DEFAULT (''),
[TitleFontType] [int] NULL CONSTRAINT [DF__Qianbo_U___Title__24134F1B] DEFAULT ((0)),
[TitleType] [int] NULL CONSTRAINT [DF__Qianbo_U___Title__25077354] DEFAULT ((0)),
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Title__25FB978D] DEFAULT (''),
[UId] [int] NOT NULL,
[UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL,
[UserType] [int] NOT NULL,
[AdminUId] [int] NULL,
[AdminUName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Admin__26EFBBC6] DEFAULT (''),
[Status] [int] NULL CONSTRAINT [DF__Qianbo_U___Statu__27E3DFFF] DEFAULT ((0)),
[HitCount] [int] NULL CONSTRAINT [DF__Qianbo_U___HitCo__28D80438] DEFAULT ((0)),
[AddTime] [datetime] NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL CONSTRAINT [DF__Qianbo_U___Templ__29CC2871] DEFAULT (''),
[PageType] [int] NULL CONSTRAINT [DF__Qianbo_U___PageT__2AC04CAA] DEFAULT ((1)),
[IsCreated] [bit] NULL CONSTRAINT [DF__Qianbo_U___IsCre__2BB470E3] DEFAULT ((0)),
[UserCateId] [int] NULL CONSTRAINT [DF__Qianbo_U___UserC__2CA8951C] DEFAULT ((0)),
[PointCount] [int] NULL CONSTRAINT [DF__Qianbo_U___Point__2D9CB955] DEFAULT ((0)),
[ChargeType] [int] NULL CONSTRAINT [DF__Qianbo_U___Charg__2E90DD8E] DEFAULT ((1)),
[ChargeHourCount] [int] NULL CONSTRAINT [DF__Qianbo_U___Charg__2F8501C7] DEFAULT ((0)),
[ChargeViewCount] [int] NULL CONSTRAINT [DF__Qianbo_U___Charg__30792600] DEFAULT ((0)),
[IsOpened] [int] NULL CONSTRAINT [DF__Qianbo_U___IsOpe__316D4A39] DEFAULT ((2)),
[OuterUrl] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Outer__32616E72] DEFAULT (''),
[GroupIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Group__335592AB] DEFAULT (''),
[IsDeleted] [bit] NULL CONSTRAINT [DF__Qianbo_U___IsDel__3449B6E4] DEFAULT ((0)),
[IsRecommend] [bit] NULL CONSTRAINT [DF__Qianbo_U___IsRec__353DDB1D] DEFAULT ((0)),
[IsTop] [bit] NULL CONSTRAINT [DF__Qianbo_U___IsTop__3631FF56] DEFAULT ((0)),
[IsFocus] [bit] NULL CONSTRAINT [DF__Qianbo_U___IsFoc__3726238F] DEFAULT ((0)),
[IsSideShow] [bit] NULL CONSTRAINT [DF__Qianbo_U___IsSid__381A47C8] DEFAULT ((0)),
[TagIdStr] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___TagId__390E6C01] DEFAULT (''),
[TagNameStr] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___TagNa__3A02903A] DEFAULT (''),
[IsAllowComment] [bit] NULL CONSTRAINT [DF__Qianbo_U___IsAll__3AF6B473] DEFAULT ((0)),
[SpecialIdStr] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Speci__3BEAD8AC] DEFAULT (''),
[ViewUName] [ntext] COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___ViewU__3CDEFCE5] DEFAULT ('),
[ViewUName2] [ntext]  NULL default ('),
[ExtendContentTable] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___Exten__3DD3211E] DEFAULT (''),
[JianYao] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[CheZhuBaoJia] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___CheZh__3EC74557] DEFAULT (''),
[ChuChangBaoJia] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_U___ChuCh__3FBB6990] DEFAULT (''),
[ShuoMing] [ntext] COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK__Qianbo_U__3214EC072042BE37] on [dbo].[Qianbo_U_CheYuan]'
GO
ALTER TABLE [dbo].[Qianbo_U_CheYuan] ADD CONSTRAINT [PK__Qianbo_U__3214EC072042BE37] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_U_CheYuan_AddTime] on [dbo].[Qianbo_U_CheYuan]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_U_CheYuan_AddTime] ON [dbo].[Qianbo_U_CheYuan] ([AddTime])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_U_CheYuan_ChId] on [dbo].[Qianbo_U_CheYuan]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_U_CheYuan_ChId] ON [dbo].[Qianbo_U_CheYuan] ([ChId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_U_CheYuan_ColId] on [dbo].[Qianbo_U_CheYuan]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_U_CheYuan_ColId] ON [dbo].[Qianbo_U_CheYuan] ([ColId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_U_CheYuan_SpecialIdStr] on [dbo].[Qianbo_U_CheYuan]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_U_CheYuan_SpecialIdStr] ON [dbo].[Qianbo_U_CheYuan] ([SpecialIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_U_CheYuan_TagIdStr] on [dbo].[Qianbo_U_CheYuan]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_U_CheYuan_TagIdStr] ON [dbo].[Qianbo_U_CheYuan] ([TagIdStr])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_User_Business]'
GO
CREATE TABLE [dbo].[Qianbo_User_Business]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[UId] [int] NULL,
[AddTime] [datetime] NULL,
[UpdateTime] [datetime] NULL,
[EmployNumber] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Emplo__2A02C949] DEFAULT ('5'),
[License] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Licen__2BA02DA1] DEFAULT (''),
[TaxCertificates] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__TaxCe__2C9451DA] DEFAULT (''),
[OtherCertificates] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Other__2D887613] DEFAULT (''),
[ContactPersonal] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Conta__2E7C9A4C] DEFAULT (''),
[Telephone] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Telep__2F70BE85] DEFAULT (''),
[CompanyEmail] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Compa__3064E2BE] DEFAULT (''),
[Fax] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_Bus__Fax__315906F7] DEFAULT (''),
[Address] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Addre__324D2B30] DEFAULT (''),
[Zip] [int] NULL,
[HomePage] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__HomeP__33414F69] DEFAULT (''),
[LOGO] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_Bu__LOGO__343573A2] DEFAULT (''),
[Introduce] [ntext] COLLATE Chinese_PRC_CI_AS NULL,
[name] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_Bu__name__36DCD623] DEFAULT (''),
[lx] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_Busi__lx__2AF6ED82] DEFAULT ('培训机构'),
[tID] [int] NULL CONSTRAINT [DF_Qianbo_User_Business_tID] DEFAULT ((0)),
[tName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__tName__381BDE76] DEFAULT (''),
[area_Id] [int] NULL,
[area] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_Bu__area__54B81D24] DEFAULT (''),
[Geographical_Id] [int] NULL,
[Geographical] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_B__Geogr__55AC415D] DEFAULT (''),
[lx_Id] [int] NULL CONSTRAINT [DF__Qianbo_User_B__lx_Id__0393079E] DEFAULT ((0)),
[EmployNumber_Id] [int] NULL CONSTRAINT [DF__Qianbo_User_B__Emplo__04872BD7] DEFAULT ((0))
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK__Qianbo_U__3214EC0700200768] on [dbo].[Qianbo_User_Business]'
GO
ALTER TABLE [dbo].[Qianbo_User_Business] ADD CONSTRAINT [PK__Qianbo_U__3214EC0700200768] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_User_Business_UId] on [dbo].[Qianbo_User_Business]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_User_Business_UId] ON [dbo].[Qianbo_User_Business] ([UId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Qianbo_User_Personal]'
GO
CREATE TABLE [dbo].[Qianbo_User_Personal]
(
[Id] [int] NOT NULL IDENTITY(1, 1),
[UId] [int] NULL,
[AddTime] [datetime] NULL,
[UpdateTime] [datetime] NULL,
[TrueName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_P__TrueN__4D61141F] DEFAULT (''),
[area_Id] [int] NULL,
[area] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_Pe__area__4E553858] DEFAULT (''),
[Geographical_Id] [int] NULL,
[Geographical] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_P__Geogr__4F495C91] DEFAULT (''),
[Address] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_P__Addre__503D80CA] DEFAULT (''),
[Phone] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_P__Phone__5131A503] DEFAULT (''),
[qq] [int] NULL,
[Email] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_P__Email__5225C93C] DEFAULT (''),
[Picture] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF__Qianbo_User_P__Pictu__269C4CB9] DEFAULT ('')
)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating primary key [PK__Qianbo_U__3214EC0702FC7413] on [dbo].[Qianbo_User_Personal]'
GO
ALTER TABLE [dbo].[Qianbo_User_Personal] ADD CONSTRAINT [PK__Qianbo_U__3214EC0702FC7413] PRIMARY KEY CLUSTERED  ([Id])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating index [IX_Qianbo_User_Personal_UId] on [dbo].[Qianbo_User_Personal]'
GO
CREATE NONCLUSTERED INDEX [IX_Qianbo_User_Personal_UId] ON [dbo].[Qianbo_User_Personal] ([UId])
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Card_GetCards]'
GO
CREATE PROCEDURE [dbo].[Proc_Card_GetCards] (@PageSize  INT=20,
                                             @PageIndex INT=1,
                                             @WhereStr  VARCHAR(100),
                                             @Total     INT=0 output)
AS
  BEGIN
      DECLARE @SqlStr NVARCHAR(2000)
      DECLARE @fff NVARCHAR(100)
      IF( @WhereStr = '' )
        BEGIN
            SET @WhereStr=' where '
            SET @fff=''
        END
      ELSE
        BEGIN
            SET @fff=' where ' + @WhereStr
            SET @WhereStr=' where ' + @WhereStr + ' and '
        END
      IF( @PageIndex = 1 )
        SET @SqlStr = N'select top '
                      + CONVERT(NVARCHAR(10), @PageSize)
                      + ' * from Qianbo_Card ' + @fff
                      + ' order by ID desc'
      ELSE
        SET @SqlStr = N'select top '
                      + CONVERT(NVARCHAR(10), @PageSize)
                      + ' * from Qianbo_Card ' + @WhereStr
                      + ' ID < (select min(ID) from(select top '
                      + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                      + ' * from Qianbo_Card  ' + @fff
                      + ' order by ID desc)O) order by ID desc'
  END
PRINT @SqlStr
EXECUTE Sp_ExecuteSql
  @SqlStr
SET @SqlStr ='select @TRecord =count(ID) from Qianbo_Card '
             + @fff
DECLARE @Parm NVARCHAR(50)
SET @Parm = '@TRecord int output';
EXEC Sp_ExecuteSql
  @SqlStr,
  @Parm,
  @TRecord = @Total output;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Channel_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_Channel_GetList] @pageSize  INT,
                                              @pageIndex INT,
                                              @strWhere  NVARCHAR(2000)
AS
    DECLARE @sql NVARCHAR(2000)
    DECLARE @Filter NVARCHAR(2000)
    IF( @strWhere = '' )
      BEGIN
          SET @strWhere=' where '
          SET @Filter=''
      END
    ELSE
      BEGIN
          SET @Filter=' where ' + @strWhere
          SET @strWhere=' where ' + @strWhere + ' and '
      END
    IF( @PageIndex = 1 )
      BEGIN
          SET @sql = N'select top '
                     + CONVERT(NVARCHAR(10), @pageSize)
                     + ' * from Qianbo_Channel a,Qianbo_Model b '
                     + @Filter + ' order by ModelType,Sort asc'
      END
    ELSE
      BEGIN
          SET @sql = N'select top '
                     + CONVERT(NVARCHAR(10), @pageSize)
                     + ' * from Qianbo_Channel a,Qianbo_Model b '
                     + @strWhere
                     + ' [ChId] > (select max([ChId]) from(select top '
                     + CONVERT(NVARCHAR(10), (@pageIndex-1) * @pageSize)
                     + ' [ChId] from Qianbo_Channel a,Qianbo_Model b  '
                     + @Filter
                     + ' order by ModelType,Sort asc)U) order by ModelType,Sort asc'
      END
    EXECUTE Sp_ExecuteSql
      @sql
    PRINT @sql
    SET @sql = 'select Count(*) from Qianbo_Channel a,Qianbo_Model b '
               + @Filter
    EXECUTE Sp_ExecuteSql
      @sql
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsShopBrand_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsShopBrand_Delete] @IdStr NVARCHAR(1000)
AS
    DELETE Qianbo_ShopBrand
    WHERE  BrandId IN ( @IdStr )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsShopBrand_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsShopBrand_GetList] @PageIndex    INT,
                                                   @PageSize     INT,
                                                   @RecordCount  INT=0 output,
                                                   @ProducerType INT,
                                                   @Filter       NVARCHAR(4000)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @PageIndex = 1 )
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_ShopProcuder where @FileTer order by procuderid desc'
    ELSE
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_ShopProcuder where @Fileter and id < (select min(o,id) from (select top '
                  + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                  + ' id from Qianbo_ShopProcuder where @Filter order by procuderid desc)o) order by procuderid desc'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsShopBrand_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsShopBrand_GetModel] @Id INT
AS
    SELECT *
    FROM   Qianbo_ShopBrand
    WHERE  [BrandId] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsShopProcuder_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsShopProcuder_GetList] @PageIndex    INT,
                                                      @PageSize     INT,
                                                      @RecordCount  INT=0 output,
                                                      @ProducerType INT,
                                                      @Filter       NVARCHAR(4000)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @PageIndex = 1 )
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_ShopProcuder where @FileTer order by procuderid desc'
    ELSE
      SET @sqlstr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_ShopProcuder where @Fileter and id < (select min(o,id) from (select top '
                  + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                  + ' id from Qianbo_ShopProcuder where @Filter order by procuderid desc)o) order by procuderid desc'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsShopProducer_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsShopProducer_Delete] @IdStr NVARCHAR(1000)
AS
    DELETE Qianbo_ShopProcuder
    WHERE  ProcuderId IN ( @IdStr )
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsShopProducer_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsShopProducer_GetModel] @Id INT
AS
    SELECT *
    FROM   Qianbo_ShopProducer
    WHERE  [ProducerId] = @Id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CmsShopProducer_Set]'
GO
CREATE PROCEDURE [dbo].[Proc_CmsShopProducer_Set] @ProducerId        INT output,
                                                  @ProducerType      INT,
                                                  @ProducerName      NVARCHAR(200),
                                                  @ProducerShortName NVARCHAR(50),
                                                  @ProducerPhoto     NVARCHAR(255),
                                                  @AddTime           DATETIME,
                                                  @Address           NVARCHAR(255),
                                                  @Postcode          NVARCHAR(10),
                                                  @Phone             NVARCHAR(50),
                                                  @Fax               NVARCHAR(50),
                                                  @Email             NVARCHAR(50),
                                                  @Homepage          NVARCHAR(50),
                                                  @ProducerIntro     NTEXT,
                                                  @LastUpdateTime    DATETIME,
                                                  @IsPassed          BIT,
                                                  @IsTop             BIT,
                                                  @IsRecommend       BIT,
                                                  @HitCount          INT
AS
    IF( @ProducerId = 0 )
      BEGIN
          INSERT INTO Qianbo_ShopProducer
                      ([ProducerType],
                       [ProducerName],
                       [ProducerShortName],
                       [ProducerPhoto],
                       [AddTime],
                       [Address],
                       [Postcode],
                       [Phone],
                       [Fax],
                       [Email],
                       [Homepage],
                       [ProducerIntro],
                       [IsPassed],
                       [IsTop],
                       [IsRecommend],
                       [HitCount])
          VALUES      ( @ProducerType,
                        @ProducerName,
                        @ProducerShortName,
                        @ProducerPhoto,
                        @AddTime,
                        @Address,
                        @Postcode,
                        @Phone,
                        @Fax,
                        @Email,
                        @Homepage,
                        @ProducerIntro,
                        @IsPassed,
                        @IsTop,
                        @IsRecommend,
                        @HitCount )
          SET @ProducerId = Scope_identity()
      END
    ELSE
      UPDATE Qianbo_ShopProducer
      SET    [ProducerType] = @ProducerType,
             [ProducerName] = @ProducerName,
             [ProducerShortName] = @ProducerShortName,
             [ProducerPhoto] = @ProducerPhoto,
             [Address] = @Address,
             [Postcode] = @Postcode,
             [Phone] = @Phone,
             [Fax] = @Fax,
             [Email] = @Email,
             [Homepage] = @Homepage,
             [ProducerIntro] = @ProducerIntro,
             [LastUpdateTime] = @LastUpdateTime,
             [IsPassed] = @IsPassed,
             [IsTop] = @IsTop,
             [IsRecommend] = @IsRecommend,
             [HitCount] = @HitCount
      WHERE  [ProducerId] = @ProducerId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Cms_CheckHasOnUpdate]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Cms_CheckHasOnUpdate] @Input      NVARCHAR(500),
                                                   @FileldName NVARCHAR(100),
                                                   @TableName  NVARCHAR(100),
                                                   @KeyValue   NVARCHAR(1000),
                                                   @KeyName    NVARCHAR(100)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    SET @SqlStr = N'If Exists(select 1 from ' + @TableName
                  + ' where ' + @FileldName + '='''
                  + Replace(@Input, '''', '''''') + ''' and ['
                  + @KeyName + '] !=' + @KeyValue
                  + ') Select 1 Else Select 0'
    EXECUTE SP_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Cms_CheckHas]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Cms_CheckHas] @Input      NVARCHAR(500),
                                           @FileldName NVARCHAR(100),
                                           @TableName  NVARCHAR(100)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    SET @SqlStr = N'If Exists(select 1 from ' + @TableName
                  + ' where ' + @FileldName + '='''
                  + Replace(@Input, '''', '''''')
                  + ''') Select 1 Else Select 0'
    EXECUTE SP_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Column_SetInfoTemplate]'
GO
CREATE PROCEDURE [dbo].[Proc_Column_SetInfoTemplate] @colid            INT,
                                                     @tablename        NVARCHAR(50),
                                                     @InfoTemplatePath VARCHAR(255)
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update [' + @tablename
                  + '] set templatepath = @ttemplatepath where colid = @tcolid'
    DECLARE @param NVARCHAR(400)
    SET @param = '@ttemplatepath varchar(255),@tcolid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @ttemplatepath = @InfoTemplatePath,
      @tcolid = @colid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_Article_HeaderList]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_Article_HeaderList] @infocount INT,
                                                        @colid     INT,
                                                        @isimg     BIT
AS
    DECLARE @wherestr NVARCHAR(500)
    IF( @isimg = 0 )
      SET @wherestr = ' isheader=1 and headerfont<>'''' '
    ELSE
      SET @wherestr = ' isheader=1 and headerimgpath<>'''' '
    SET @wherestr =
    + ' i.status = 3 and i.isdeleted = 0 and i.colid = @tcolid and '
    + @wherestr
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [Qianbo_Article] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr='select top '
                + CONVERT(NVARCHAR(15), @infocount)
                + @fieldstr + 'from' + @tablestr + 'where' + @wherestr
                + 'order by i.[id] desc'
    DECLARE @param NVARCHAR(400)
    SET @param = '@tcolid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tcolid = @colid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_Ch_GetSpecialInfoCount]'
GO
CREATE PROC [dbo].[Proc_Create_Ch_GetSpecialInfoCount] @tablename    NVARCHAR(50),
                                                       @infocount    INT,
                                                       @specialidstr NVARCHAR(3000),
                                                       @datestr      DATETIME
AS
    DECLARE @fieldstr NVARCHAR(500)
    SET @fieldstr = ' i.[id] '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(4000)
    SET @wherestr = ''
    IF( @datestr != '' )
      SET @wherestr = @wherestr + ' i.addtime >= @tdatestr and '
    SET @wherestr = @wherestr + @specialidstr
                    + ' i.status = 3 and i.isdeleted = 0 '
    DECLARE @topnum NVARCHAR(50)
    SET @topnum = '';
    IF( @infocount != 0 )
      SET @topnum = ' top ' + CONVERT(NVARCHAR(15), @infocount)
                    + ' '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select ' + @topnum + @fieldstr + 'from' + @tablestr
                  + 'where' + @wherestr
    DECLARE @param NVARCHAR(500)
    SET @param='@tdatestr datetime'
    DECLARE @countstr NVARCHAR(4000)
    SET @countstr = 'select Count(*) from (' + @sqlstr + ')o'
    EXECUTE sp_executesql
      @countstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_Ch_GetSpecialInfoList]'
GO
CREATE PROC [dbo].[Proc_Create_Ch_GetSpecialInfoList] @tablename    NVARCHAR(50),
                                                      @infocount    INT,
                                                      @specialidstr NVARCHAR(3000),
                                                      @datestr      DATETIME,
                                                      @orderstr     NVARCHAR(100)
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(4000)
    SET @wherestr = ''
    IF( @datestr != '' )
      SET @wherestr = @wherestr + ' i.addtime >= @tdatestr and '
    SET @wherestr = @wherestr + @specialidstr
                    + ' i.status = 3 and i.isdeleted = 0 '
    DECLARE @topnum NVARCHAR(50)
    SET @topnum = '';
    IF( @infocount != 0 )
      SET @topnum = ' top ' + CONVERT(NVARCHAR(15), @infocount)
                    + ' '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select ' + @topnum + @fieldstr + 'from' + @tablestr
                  + 'where' + @wherestr + ' order by ' + @orderstr
    DECLARE @param NVARCHAR(500)
    SET @param='@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetAll_Info]'
GO
CREATE PROC [dbo].[Proc_Create_GetAll_Info] @CursorPage INT,
                                            @PageSize   INT,
                                            @tableName  NVARCHAR(50)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    DECLARE @fieldstr NVARCHAR(500);
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(200)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    IF( @CursorPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize) + @fieldstr
                  + ' from' + @tablestr
                  + ' where i.status = 3 and i.isdeleted = 0 order by i.[id] desc'
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize) + @fieldstr
                  + ' from' + @tablestr
                  + ' where i.status = 3 and i.isdeleted = 0 and i.Id < (select min(id) from(select top '
                  + CONVERT(NVARCHAR(15), (@CursorPage - 1) * @PageSize)
                  + ' i.[id] from ' + @tablestr
                  + ' where i.status = 3 and i.isdeleted = 0 order by i.Id desc)O) order by i.[id] desc '
    EXECUTE SP_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetChannel_Column_InfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetChannel_Column_InfoList] @chid     INT,
                                                                @colcount INT,
                                                                @colidstr NVARCHAR(1000)
AS
    DECLARE @topnum NVARCHAR(50)
    SET @topnum = '';
    DECLARE @wherestr NVARCHAR(1000)
    SET @wherestr = ' co.chid = @tchid and co.colparentid=0 ';
    IF( @colcount != 0
        AND @colidstr = '' )
      SET @topnum = ' top ' + CONVERT(NVARCHAR(15), @colcount)
                    + ' '
    ELSE IF( @colidstr != '' )
      SET @wherestr = @wherestr + ' and colid in(' + @colidstr + ') '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select ' + @topnum
                  + ' co.colid,co.colname,co.colid,co.columnimgpath from Qianbo_Column co where '
                  + @wherestr
                  + ' and co.isdeleted = 0 order by co.sort asc'
    DECLARE @param NVARCHAR(500)
    SET @param = '@tchid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetChannel_FinallyInfoCount]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetChannel_FinallyInfoCount] @tablename NVARCHAR(50),
                                                                 @chidstr   NVARCHAR(1000),
                                                                 @datestr   NVARCHAR(50)
AS
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Channel ch on i.chid=ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(500)
    SET @wherestr=''
    IF( @datestr != '' )
      SET @wherestr = @wherestr
                      + ' i.[addtime] >= @tdatestr and '
    SET @wherestr = @wherestr + ' i.chid in(' + @chidstr
                    + ') and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select Count(i.[id]) from' + @tablestr
                  + 'where' + @wherestr
    DECLARE @param NVARCHAR(50)
    SET @param='@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetChannel_FinallyInfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetChannel_FinallyInfoList] @tablename NVARCHAR(50),
                                                                @chidstr   NVARCHAR(1000),
                                                                @datestr   NVARCHAR(50),
                                                                @orderstr  NVARCHAR(50),
                                                                @ispadding BIT,
                                                                @pageindex INT,
                                                                @pagesize  INT
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.typeunit,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] i join Qianbo_Channel ch on i.chid=ch.chid join Qianbo_Model m on ch.modeltype = m.modelid left outer join Qianbo_Column co on i.colid = co.colid '
    DECLARE @wherestr NVARCHAR(500)
    SET @wherestr = '';
    IF( @datestr != '' )
      SET @wherestr=' i.[addtime] >= @tdatestr and '
    SET @wherestr = @wherestr + ' i.chid in(' + @chidstr
                    + ') and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @ispadding = 0 )
      SET @sqlstr = 'select' + @fieldstr + 'from' + @tablestr + 'where'
                    + @wherestr + ' order by ' + @orderstr
    ELSE
      BEGIN
          IF( @pageindex = 1 )
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                          + 'from' + @tablestr + 'where' + @wherestr
                          + ' order by ' + @orderstr
          ELSE
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                          + 'from' + @tablestr
                          + 'where i.[id] not in(select top '
                          + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                          + ' i.[id] from' + @tablestr + 'where' + @wherestr
                          + ' order by ' + @orderstr + ') and ' + @wherestr
                          + ' order by ' + @orderstr
      END
    DECLARE @param NVARCHAR(50)
    SET @param='@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetChannel_InfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetChannel_InfoList] @tablename NVARCHAR(50),
                                                         @infocount INT,
                                                         @chid      INT,
                                                         @typestr   NVARCHAR(1000),
                                                         @datestr   DATETIME,
                                                         @orderstr  NVARCHAR(50)
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @topnum NVARCHAR(50)
    SET @topnum = '';
    IF( @infocount != '' )
      SET @topnum = ' top ' + CONVERT(NVARCHAR(15), @infocount)
                    + ' ';
    DECLARE @wherestr NVARCHAR(2000)
    SET @wherestr = '';
    IF( @typestr != '' )
      SET @wherestr = @wherestr + @typestr + ' and '
    IF( @datestr != '' )
      SET @wherestr = @wherestr + ' i.addtime >= @tdatestr and '
    SET @wherestr = @wherestr
                    + ' co.chid = @tchid and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(1000)
    SET @sqlstr = 'select ' + @topnum + @fieldstr + 'from' + @tablestr
                  + 'where' + @wherestr + ' order by ' + @orderstr
    DECLARE @param NVARCHAR(500)
    SET @param = '@tchid int,@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetCloseInfo]'
GO
CREATE PROC [dbo].[Proc_Create_GetCloseInfo] @tablename NVARCHAR(50),
                                             @id        INT,
                                             @colid     INT,
                                             @direct    NVARCHAR(10)
AS
    DECLARE @sqlstr NVARCHAR(2000)
    DECLARE @param NVARCHAR(500)
    IF( @direct = 'pre' )
      SET @sqlstr = 'if exists(select [id] from [' + @tablename
                    + '] where [id] < @tid and colid = @tcolid and status = 3 and isdeleted = 0) '
                    + 'select top 1 [id],title from ['
                    + @tablename
                    + '] where [id] < @tid and colid = @tcolid and status = 3 and  isdeleted = 0 order by id desc '
                    + 'else ' + 'select [id] = 0'
    ELSE
      SET @sqlstr = 'if exists(select [id] from [' + @tablename
                    + '] where [id] > @tid and colid = @tcolid and status = 3 and isdeleted = 0) '
                    + 'select top 1 [id],title from ['
                    + @tablename
                    + '] where [id] > @tid and colid = @tcolid and status = 3 and isdeleted = 0 order by id asc '
                    + 'else ' + 'select [id] = 0'
    SET @param = '@tid int,@tcolid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id,
      @tcolid = @colid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetColumn_ChildCol_InfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetColumn_ChildCol_InfoList] @colid    INT,
                                                                 @colcount INT
AS
    DECLARE @topnum NVARCHAR(50)
    SET @topnum = '';
    IF( @colcount != 0 )
      SET @topnum = ' top ' + CONVERT(NVARCHAR(15), @colcount)
                    + ' '
    DECLARE @wherestr NVARCHAR(500)
    SET @wherestr = ' co.colparentid = @tcolid and co.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'select ' + @topnum
                  + ' co.colid,co.colname,co.colid from Qianbo_Column co where'
                  + @wherestr + ' order by co.sort asc'
    DECLARE @param NVARCHAR(50)
    SET @param = '@tcolid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tcolid = @colid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetColumn_FinallyInfoCount]'
GO
CREATE PROC [dbo].[Proc_Create_GetColumn_FinallyInfoCount] @tablename NVARCHAR(50),
                                                           @colidstr  NVARCHAR(1000),
                                                           @datestr   NVARCHAR(50)
AS
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(500)
    SET @wherestr=''
    IF( @datestr != '' )
      SET @wherestr = @wherestr
                      + ' i.[addtime] >= @tdatestr and '
    SET @wherestr = @wherestr + ' i.colid in(' + @colidstr
                    + ') and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select Count(i.[id]) from' + @tablestr
                  + 'where' + @wherestr
    DECLARE @param NVARCHAR(50)
    SET @param='@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetColumn_FinallyInfoList]'
GO
CREATE PROC [dbo].[Proc_Create_GetColumn_FinallyInfoList] @tablename NVARCHAR(50),
                                                          @colidstr  NVARCHAR(1000),
                                                          @datestr   NVARCHAR(50),
                                                          @orderstr  NVARCHAR(50),
                                                          @ispadding BIT,
                                                          @pageindex INT,
                                                          @pagesize  INT
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.typeunit,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(500)
    SET @wherestr = '';
    IF( @datestr != '' )
      SET @wherestr=' i.[addtime] >= @tdatestr and '
    SET @wherestr = @wherestr + ' i.colid in(' + @colidstr
                    + ') and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @ispadding = 0 )
      SET @sqlstr = 'select' + @fieldstr + 'from' + @tablestr + 'where'
                    + @wherestr + ' order by ' + @orderstr
    ELSE
      BEGIN
          IF( @pageindex = 1 )
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                          + 'from' + @tablestr + 'where' + @wherestr
                          + ' order by ' + @orderstr
          ELSE
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                          + 'from' + @tablestr
                          + 'where i.[id] not in(select top '
                          + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                          + ' i.[id] from' + @tablestr + 'where' + @wherestr
                          + ' order by ' + @orderstr + ') and ' + @wherestr
                          + ' order by ' + @orderstr
      END
    DECLARE @param NVARCHAR(50)
    SET @param='@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetColumn_FlashInfoList]'
GO
CREATE PROC [dbo].[Proc_Create_GetColumn_FlashInfoList] @tablename NVARCHAR(50),
                                                        @chid      INT,
                                                        @colidstr  VARCHAR(1000),
                                                        @infocount INT
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @sqlstr NVARCHAR(4000)
    DECLARE @wherestr NVARCHAR(1000)
    SET @wherestr = '';
    IF( @chid != 0 )
      SET @wherestr = @wherestr + ' ch.chid = @tchid and '
    IF( @colidstr != '' )
      SET @wherestr = @wherestr + ' i.colid in(' + @colidstr + ') and '
    SET @wherestr = @wherestr
                    + ' i.status = 3 and i.isdeleted = 0 and issideshow=1 '
    SET @sqlstr = 'select top '
                  + CONVERT(NVARCHAR(15), @infocount)
                  + @fieldstr + 'from' + @tablestr + 'where '
                  + @wherestr + ' order by i.[id] desc'
    DECLARE @param NVARCHAR(400)
    SET @param = '@tchid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetColumn_InfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetColumn_InfoList] @tablename NVARCHAR(50),
                                                        @infocount INT,
                                                        @colidstr  NVARCHAR(1000),
                                                        @typestr   NVARCHAR(1000),
                                                        @datestr   DATETIME,
                                                        @orderstr  NVARCHAR(50)
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @topnum NVARCHAR(50)
    SET @topnum = '';
    IF( @infocount != '' )
      SET @topnum = ' top ' + CONVERT(NVARCHAR(15), @infocount)
                    + ' ';
    DECLARE @wherestr NVARCHAR(2000)
    SET @wherestr = '';
    IF( @typestr != '' )
      SET @wherestr = @wherestr + @typestr + ' and '
    IF( @datestr != '' )
      SET @wherestr = @wherestr + ' i.addtime >= @tdatestr and '
    SET @wherestr = @wherestr + ' i.colid in(' + @colidstr
                    + ') and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(1000)
    SET @sqlstr = 'select ' + @topnum + @fieldstr + 'from' + @tablestr
                  + 'where' + @wherestr + ' order by ' + @orderstr
    DECLARE @param NVARCHAR(500)
    SET @param = '@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetColumn_Info]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetColumn_Info] @tablename NVARCHAR(50),
                                                    @colidstr  NVARCHAR(2000),
                                                    @pageindex INT,
                                                    @pagesize  INT
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(2000)
    SET @wherestr = ' i.colid in(' + @colidstr
                    + ') and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(2000)
    IF( @pageindex = 1 )
      SET @sqlstr ='select top '
                   + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                   + 'from' + @tablestr + 'where' + @wherestr
                   + 'order by i.[id] desc'
    ELSE
      SET @sqlstr ='select top '
                   + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                   + 'from' + @tablestr
                   + 'where i.[id] < (select min(o.[id]) from(select top '
                   + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                   + ' i.[id] from' + @tablestr + 'where' + @wherestr
                   + 'order by i.[id] desc)o) and ' + @wherestr
                   + 'order by i.[id] desc'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetDateRange_Info]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetDateRange_Info] @tablename NVARCHAR(50),
                                                       @startdate NVARCHAR(15),
                                                       @enddate   NVARCHAR(15),
                                                       @pageindex INT,
                                                       @pagesize  INT
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(400)
    SET @wherestr = ' (i.addtime >= @tstartdate and i.addtime <= @tenddate) and i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(2000)
    IF( @pageindex = 1 )
      SET @sqlstr ='select top '
                   + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                   + 'from' + @tablestr + 'where' + @wherestr
                   + 'order by i.[id] desc'
    ELSE
      SET @sqlstr ='select top '
                   + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                   + 'from' + @tablestr
                   + 'where i.[id] < (select min(o.[id]) from(select top '
                   + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                   + ' i.[id] from' + @tablestr + 'where' + @wherestr
                   + 'order by i.[id] desc)o) and ' + @wherestr
                   + 'order by i.[id] desc'
    DECLARE @param NVARCHAR(400)
    SET @param = '@tstartdate datetime,@tenddate datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tstartdate = @startdate,
      @tenddate = @enddate
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetIdRange_Info]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetIdRange_Info] @tablename NVARCHAR(50),
                                                     @startid   INT,
                                                     @endid     INT,
                                                     @pageindex INT,
                                                     @pagesize  INT
AS
    DECLARE @sqlstr NVARCHAR(4000);
    DECLARE @wherestr NVARCHAR(2000)
    SET @wherestr = ' i.status = 3 and i.isdeleted = 0 and i.[id] in(select [id] from ['
                    + @tablename
                    + '] where [id] >= @tstartid and [id] <= @tendid) '
    DECLARE @fieldstr NVARCHAR(500);
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    IF( @pageindex = 1 )
      SET @sqlstr='select top '
                  + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                  + 'from' + @tablestr + 'where' + @wherestr
                  + 'order by i.[id] desc'
    ELSE
      SET @sqlstr='select top '
                  + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                  + 'from' + @tablestr + 'where' + @wherestr
                  + 'and i.[id] < (select min(id) from(select top '
                  + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                  + ' i.[id] from' + @tablestr + 'where' + @wherestr
                  + ' order by i.[id] desc )o) order by i.[id] desc'
    DECLARE @param NVARCHAR(400)
    SET @param = '@tstartid int,@tendid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tstartid = @startid,
      @tendid = @endid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetId_Info]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetId_Info] @tablename NVARCHAR(50),
                                                @id        INT
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.isdisabled,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr='select ' + @fieldstr + ' from ' + @tablestr
                + ' where i.[id] = @tid and i.isdeleted = 0'
    DECLARE @param NVARCHAR(200)
    SET @param = '@tid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetNewRange_Info]'
GO
CREATE PROCEDURE [dbo].[Proc_Create_GetNewRange_Info] @tablename NVARCHAR(50),
                                                      @topnum    INT,
                                                      @pageIndex INT,
                                                      @pagesize  INT
AS
    DECLARE @sqlstr NVARCHAR(2000);
    DECLARE @fieldstr NVARCHAR(500);
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(400)
    SET @wherestr = ' where i.status = 3 and i.isdeleted = 0 '
    DECLARE @subsqlstr NVARCHAR(1000)
    SET @subsqlstr = 'select top '
                     + CONVERT(NVARCHAR(15), @topnum) + @fieldstr
                     + 'from' + @tablestr + @wherestr
                     + ' order by i.[id] desc '
    IF( @pageindex = 1 )
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + ' * from(' + @subsqlstr
                    + ')o order by o.[id] desc'
    ELSE
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + ' * from(' + @subsqlstr
                    + ')o where o.[id] < (select min([id]) from(select top '
                    + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                    + ' k.[id] from (' + @subsqlstr
                    + ')k)p) order by o.[id] desc'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetPropertyCount]'
GO
CREATE PROC [dbo].[Proc_Create_GetPropertyCount] @tablename NVARCHAR(50),
                                                 @prowhe    NVARCHAR(1000),
                                                 @datestr   NVARCHAR(50)
AS
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(500)
    SET @wherestr=''
    IF( @prowhe != '' )
      SET @wherestr=' ' + @prowhe + ' and '
    IF( @datestr != '' )
      SET @wherestr = @wherestr
                      + ' i.[addtime] >= @tdatestr and '
    SET @wherestr = @wherestr
                    + ' i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select Count(i.[id]) as recordCount from'
                  + @tablestr + 'where' + @wherestr
    DECLARE @param NVARCHAR(50)
    SET @param='@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_GetPropertyList]'
GO
CREATE PROC [dbo].[Proc_Create_GetPropertyList] @tablename NVARCHAR(50),
                                                @infocount INT,
                                                @prowhe    NVARCHAR(500),
                                                @datestr   NVARCHAR(50),
                                                @orderstr  NVARCHAR(50),
                                                @ispadding BIT,
                                                @pageindex INT,
                                                @pagesize  INT
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.typeunit,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(500)
    SET @wherestr = '';
    IF( @prowhe != '' )
      SET @wherestr=' ' + @prowhe + ' and '
    IF( @datestr != '' )
      SET @wherestr=' i.[addtime] >= @tdatestr and '
    SET @wherestr = @wherestr
                    + ' i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @ispadding = 0 )
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @infocount)
                    + @fieldstr + 'from' + @tablestr + 'where' + @wherestr
                    + ' order by ' + @orderstr
    ELSE
      BEGIN
          IF( @pageindex = 1 )
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                          + 'from' + @tablestr + 'where' + @wherestr
                          + ' order by ' + @orderstr
          ELSE
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize) + @fieldstr
                          + 'from' + @tablestr
                          + 'where i.[id] not in(select top '
                          + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                          + ' i.[id] from' + @tablestr + 'where' + @wherestr
                          + ' order by ' + @orderstr + ') and ' + @wherestr
                          + ' order by ' + @orderstr
      END
    DECLARE @param NVARCHAR(50)
    SET @param='@tdatestr datetime'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tdatestr = @datestr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_InfoRecordCount]'
GO
CREATE PROC [dbo].[Proc_Create_InfoRecordCount] @InputStr    NVARCHAR(2000),
                                                @tableName   NVARCHAR(200),
                                                @RecordCount INT output
AS
    DECLARE @WhereStr NVARCHAR(2000);
    DECLARE @SqlStr NVARCHAR(2000);
    DECLARE @Param NVARCHAR(50)
    SET @Param=N'@TRecordCount int output'
    SET @WhereStr=CONVERT(NVARCHAR(200), @tableName)
                  + ' as i,Qianbo_Channel as ch,Qianbo_Column as co where co.Chid = ch.ChId and i.colid = co.colid and i.status = 3 and i.isdeleted = 0 ';
    SET @SqlStr=N'select @TRecordCount = Count(i.Id) from '
                + @WhereStr
                + CONVERT(NVARCHAR(2000), @InputStr);
    EXECUTE SP_ExecuteSql
      @SqlStr,
      @Param,
      @TRecordCount = @RecordCount output
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_Info_RelationInfoList]'
GO
CREATE PROC [dbo].[Proc_Create_Info_RelationInfoList] @tablename NVARCHAR(50),
                                                      @infocount INT,
                                                      @wherestr  NVARCHAR(2000)
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'select top '
                  + CONVERT(NVARCHAR(15), @infocount)
                  + @fieldstr + 'from' + @tablestr
                  + 'where i.status = 3 and i.isdeleted = 0 '
                  + @wherestr + ' order by i.[id] desc'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_Irregular_GetInfoList]'
GO
CREATE PROC [dbo].[Proc_Create_Irregular_GetInfoList] @chid      INT,
                                                      @tablename NVARCHAR(50),
                                                      @pageindex INT,
                                                      @pagesize  INT
AS
    DECLARE @wherestr NVARCHAR(400)
    SET @wherestr = '';
    IF( @tablename = 'Qianbo_Article' )
      SET @wherestr = ' ch.chid = @tchid and i.isirregular = 1 and i.status = 3 and i.isdeleted = 0 '
    ELSE
      SET @wherestr = ' ch.chid = @tchid and i.status = 3 and i.isdeleted = 0  '
    DECLARE @sqlstr NVARCHAR(3000)
    DECLARE @param NVARCHAR(400)
    DECLARE @tablestr NVARCHAR(500)
    SET @tablestr = ' [' + @tablename
                    + '] i join Qianbo_Column co on i.[colid] = co.[colid] join Qianbo_Channel ch on co.[chid] = ch.[chid] '
    SET @param = '@tchid int'
    IF( @pageindex = 1 )
      SET @sqlstr='select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' co.colname,i.id,i.colid,i.title,i.addtime from '
                  + @tablestr + '  where ' + @wherestr
                  + ' order by i.addtime desc'
    ELSE
      SET @sqlstr='select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' co.colname,i.id,i.colid,i.title,i.addtime from '
                  + @tablestr + ' where ' + @wherestr
                  + ' and i.[id] < (select min(o.id) from(select top '
                  + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                  + ' i.[id] from ' + @tablestr + ' where '
                  + @wherestr
                  + ' order by i.addtime desc)o) order by i.addtime desc'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
    SET @sqlstr = 'select Count(*) from ' + @tablestr
                  + ' where ' + @wherestr
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Create_ListInfoCount]'
GO
CREATE PROC [dbo].[Proc_Create_ListInfoCount] @tablename NVARCHAR(50),
                                              @topnum    INT
AS
    DECLARE @recordcount INT
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'select Count(i.[id]) from(select top '
                  + CONVERT(NVARCHAR(15), @topnum)
                  + ' [id] from [' + @tablename
                  + '] where status = 3 and isdeleted = 0 order by id desc)i'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomField_SubmitNum]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomField_SubmitNum] @TableName NVARCHAR(50),
                                                    @UId       INT
AS
    DECLARE @sqlstr NVARCHAR(500)
    SET @sqlstr='select * from [' + @TableName
                + '] where UId = '
                + CONVERT(NVARCHAR(100), @UId)
                + ' order by Id desc'
    EXECUTE sp_executesql
      @sqlstr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomForm_AddTable]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomForm_AddTable] @TableName NVARCHAR(50)
AS
    DECLARE @sqlstr NVARCHAR(500)
    SET @sqlstr=N'
CREATE TABLE [dbo].[' + @TableName
                + ']
(
[Id] [int] IDENTITY (1, 1) PRIMARY Key NOT NULL,
[UId] [int] NULL ,
[UName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Ip] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[AddTime] [datetime] NULL)
CREATE  INDEX [IX_' + @TableName
                + '_UId] ON [' + @TableName
                + ']([UId]) ON [PRIMARY]'
    EXEC sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_CustomTable_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_CustomTable_GetList] @TableName NVARCHAR(50),
                                                  @CurrPage  INT,
                                                  @PageSize  INT,
                                                  @strWhere  NVARCHAR(2000)
AS
    DECLARE @SqlStr NVARCHAR(3000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [' + @TableName + '] ' + @strWhere
                  + ' order by Id desc';
    ELSE IF( @strWhere = '' )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [' + @TableName
                  + '] where Id < (select min(Id) from (select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' Id from [' + @TableName + '] ' + @strWhere
                  + ' order by Id desc)o) order by Id desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [' + @TableName + '] ' + @strWhere
                  + ' and Id < (select min(Id) from (select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' Id from [' + @TableName + '] ' + @strWhere
                  + ' order by Id desc)o) order by Id desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(Id) from [' + @TableName + ']'
                  + @strWhere;
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoadData_Delete]'
GO
CREATE PROC [dbo].[Proc_DownLoadData_Delete] @IDstr  NVARCHAR(2000),
                                             @Option VARCHAR(50)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF( @Option = 'Delete' )
      BEGIN
          SET @SqlStr = 'delete from Qianbo_DownLoadData where Id in('
                        + @IDstr + ')'
      END
    IF( @Option = 'Recycle' )
      BEGIN
          SET @SqlStr = 'update Qianbo_DownLoadData set SoftIsDel = 0 where Id in('
                        + @IDstr + ')'
      END
    IF( @Option = 'DeletedToRecycle' )
      BEGIN
          SET @SqlStr = 'update Qianbo_DownLoadData set SoftIsDel = 1 where Id in('
                        + @IDstr + ')'
      END
    EXEC sp_executesql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_DownLoad_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_DownLoad_GetList] @SortName    NVARCHAR(20)='',
                                               @Keyword     NVARCHAR(50)='',
                                               @ChannelId   INT=-1,
                                               @ColumnId    NVARCHAR(500)='-1',
                                               @SoftStatus  VARCHAR(50)='-10',
                                               @IsRecommend INT=-1,
                                               @IsTop       INT=-1,
                                               @UserCateId  INT=-1,
                                               @CurrPage    INT=1,
                                               @PageSize    INT=20,
                                               @UserType    INT=-1,
                                               @RecordCount INT=0 output
AS
    DECLARE @WhereStr NVARCHAR(2000);
    SET @WhereStr = '';
    IF( @SortName != '' )
      BEGIN
          SET @WhereStr = @WhereStr + @SortName + ' like ''%' + @Keyword
                          + '%''' + ' and';
      END
    IF( @ChannelId !=- 1 )
      BEGIN
          SET @WhereStr = @WhereStr + ' a.ChId = '
                          + CONVERT(NVARCHAR(15), @ChannelId) + ' and';
      END
    IF( @ColumnId != '-1' )
      BEGIN
          SET @WhereStr = @WhereStr + ' a.ColId in(' + @ColumnId + ') and';
      END
    IF( @SoftStatus != '-10' )
      BEGIN
          SET @WhereStr = @WhereStr + ' SoftStatus in(' + @SoftStatus
                          + ') and';
      END
    IF( @IsRecommend !=- 1 )
      BEGIN
          SET @WhereStr = @WhereStr + ' SoftIsCommand = '
                          + CONVERT(NVARCHAR(15), @IsRecommend) + ' and';
      END
    IF( @IsTop != -1 )
      BEGIN
          SET @WhereStr = @WhereStr + ' SoftIsTop = '
                          + CONVERT(NVARCHAR(15), @IsTop) + ' and';
      END
    IF( @UserCateId !=- 1 )
      BEGIN
          SET @WhereStr = @WhereStr + ' a.UserCateId = '
                          + CONVERT(NVARCHAR(15), @UserCateId) + ' and ';
      END
    IF( @UserType = 0 )
      BEGIN
          SET @WhereStr = @WhereStr + ' UserType = 0 and '
      END
    ELSE IF( @UserType = -1 )
      BEGIN
          SET @whereStr = @WhereStr + ' SoftStatus != -1 and '
      END
    SET @WhereStr = @WhereStr + ' a.SoftIsDel = 0';
    DECLARE @SqlStr NVARCHAR(2000)
    IF( @CurrPage = 1 )
      SET @SqlStr = 'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + ' a.*,b.colname from Qianbo_DownLoadData a inner join Qianbo_Column b on a.colid = b.colid where '
                    + @WhereStr + ' order by a.ID desc'
    ELSE
      SET @SqlStr = 'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + ' a.*,b.colname from Qianbo_DownLoadData a inner join Qianbo_Column b on a.colid = b.colid where '
                    + @WhereStr
                    + ' and a.ID <(select min(ID) from(select top '
                    + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                    + ' ID from Qianbo_DownLoadData a where '
                    + @WhereStr
                    + ' order by ID desc)O) order by a.ID desc'
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr ='select @TRecord = Count(a.ID) from Qianbo_DownLoadData a inner join Qianbo_Column b on a.colid = b.colid where '
                 + @WhereStr
    DECLARE @Parm NVARCHAR(50)
    SET @Parm = '@TRecord int output';
    EXEC Sp_ExecuteSql
      @SqlStr,
      @Parm,
      @TRecord = @RecordCount output;
    PRINT @RecordCount
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Enterprise_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_Enterprise_Delete] @IdStr  NVARCHAR(1000),
                                                @UserId INT
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'delete Qianbo_Enterprise where [id] in('
                  + @idstr + ') and userid = @temp_userid'
    DECLARE @param NVARCHAR(400)
    SET @param='@temp_userid int '
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @temp_userid = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Enterprise_GetByUserId]'
GO
CREATE PROC [dbo].[Proc_Enterprise_GetByUserId] @UserId      INT,
                                                @PageIndex   INT=1,
                                                @PageSize    INT=10,
                                                @RecordCount INT=0 output
AS
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @PageIndex = 1 )
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' * from Qianbo_Enterprise where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' order by Id desc'
    ELSE
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' * from Qianbo_Enterprise where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' and id < (select min(o.id) from(select top '
                   + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                   + ' id from Qianbo_Enterprise where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' order by Id desc)o) order by Id desc'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr='select Count(Id) from Qianbo_Enterprise where UserId = '
                + CONVERT(NVARCHAR(15), @UserId)
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ExtendContent_Del]'
GO
CREATE PROCEDURE [dbo].[Proc_ExtendContent_Del] @TableName NVARCHAR(100),
                                                @FieldId   INT,
                                                @InfoId    INT,
                                                @ChId      INT,
                                                @ColId     INT
AS
    DECLARE @SqlStr NVARCHAR(500)
    IF( @FieldId = 0 )
      SET @SqlStr=N'delete from [' + @TableName
                  + '] where FieldId = ' + @FieldId + '';
    ELSE
      SET @SqlStr=N'delete from [' + @TableName
                  + '] where ChId = '
                  + CONVERT(NVARCHAR(15), @ChId)
                  + ' and ColId = '
                  + CONVERT(NVARCHAR(15), @ColId)
                  + ' and InfoId = '
                  + CONVERT(NVARCHAR(15), @InfoId) + '';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ExtendContent_List]'
GO
CREATE PROCEDURE [dbo].[Proc_ExtendContent_List] @TableName NVARCHAR(50),
                                                 @ChId      INT,
                                                 @ColId     INT,
                                                 @InfoId    INT
AS
    DECLARE @SqlStr NVARCHAR(2000);
    SET @SqlStr=N'select * from [' + @TableName
                + '] where [ChId] = '
                + CONVERT(NVARCHAR(15), @ChId)
                + ' and [ColId] = '
                + CONVERT(NVARCHAR(15), @ColId)
                + ' and [InfoId] = '
                + CONVERT(NVARCHAR(15), @InfoId) + '';
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_FeedBack_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_FeedBack_GetList] @PageSize  INT=20,
                                               @PageIndex INT=1,
                                               @WhereStr  NVARCHAR(200)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @fff NVARCHAR(200)
    IF( @WhereStr = '' )
      BEGIN
          SET @WhereStr=' where '
          SET @fff=''
      END
    ELSE
      BEGIN
          SET @fff=' where ' + @WhereStr
          SET @WhereStr=' where ' + @WhereStr + ' and '
      END
    IF( @PageIndex = 1 )
      SET @SqlStr='select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' * from Qianbo_FeedBack ' + @fff
                  + ' order by [ID] desc'
    ELSE
      SET @SqlStr='select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' * from Qianbo_FeedBack  ' + @WhereStr
                  + ' [ID] < (select min(ID) from (select top '
                  + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                  + ' * from Qianbo_FeedBack' + @fff
                  + ' order by [ID] desc)F) order by [ID] desc'
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr ='select Count([ID]) from Qianbo_FeedBack '
                 + @fff
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_HireInfo_Get]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_HireInfo_Get] @Type      INT,
                                           @PageSize  INT=20,
                                           @PageIndex INT=1,
                                           @WhereStr  NVARCHAR(2000)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @Filter NVARCHAR(2000)
    IF( @WhereStr = '' )
      BEGIN
          SET @WhereStr=' where '
          SET @Filter=''
      END
    ELSE
      BEGIN
          SET @Filter=' where ' + @WhereStr
          SET @WhereStr=' where ' + @WhereStr + ' and '
      END
    IF( @Type = 1 )
      BEGIN
          SET @SqlStr = N'select Qianbo_User_Personal.[Sex],[Address],[Phone],[TrueName],[Geographical],[qq],[Email],[Picture],Qianbo_U_Job.[Drection],[Type],Qianbo_U_Job.[Industry],[work],[Posts],[city],Qianbo_U_Job.[Area],[Times],[more],[Money],[Types],Birthday,Height,Degree,experience from Qianbo_User_Personal join Qianbo_U_Job on Qianbo_User_Personal.UId = Qianbo_U_Job.Uid '
                        + @Filter
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
    IF( @Type = 2 )
      BEGIN
          IF( @PageIndex = 1 )
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' * from Qianbo_HireInfo ' + @Filter
                              + ' order by [Id] desc'
            END
          ELSE
            BEGIN
                SET @SqlStr = N'select top '
                              + CONVERT(NVARCHAR(10), @PageSize)
                              + ' * from Qianbo_HireInfo ' + @WhereStr
                              + ' [Id] < (select min(Id) from(select top '
                              + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                              + ' * from Qianbo_HireInfo  ' + @Filter
                              + ' order by [Id] desc)O) order by [Id] desc'
            END
          EXECUTE Sp_ExecuteSql
            @SqlStr
          SET @SqlStr = 'select Count(*) from Qianbo_HireInfo '
                        + @Filter
          EXECUTE Sp_ExecuteSql
            @SqlStr
      END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_AddHitCount]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Info_AddHitCount] @tablename NVARCHAR(50),
                                               @id        INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update [' + @tablename
                  + '] set hitcount = hitcount + 1 where id = '
                  + CONVERT(NVARCHAR(15), @id)
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_Auditing]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_Auditing] @tablename NVARCHAR(50),
                                            @id        INT,
                                            @status    INT,
                                            @adminid   INT,
                                            @adminname NVARCHAR(20)
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update [' + @tablename
                  + '] set [status] = @tstatus,[adminuname] = @tadminname,[adminuid] = @tadminid where id = @tid and status in(0,1,2)'
    DECLARE @param NVARCHAR(1000)
    SET @param ='@tid int,@tstatus int,@tadminid int,@tadminname nvarchar(20)'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id,
      @tstatus = @status,
      @tadminid = @adminid,
      @tadminname = @adminname
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_Cancel]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_Cancel] @tablename NVARCHAR(50),
                                          @id        INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update [' + @tablename
                  + '] set [status] = -2 where id = @tid';
    DECLARE @param NVARCHAR(50)
    SET @param = '@tid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_CompleteDeleteInfo]'
GO
CREATE PROC [dbo].[Proc_Info_CompleteDeleteInfo] @tablename NVARCHAR(50),
                                                 @id        INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    DECLARE @param NVARCHAR(200)
    SET @param='@tid int'
    SET @sqlstr = 'delete from [' + @tablename
                  + '] where [id] = @tid'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_DeleteToRecycle]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_DeleteToRecycle] @idstr     NVARCHAR(2000),
                                                   @tablename NVARCHAR(50)
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = N'update [' + @tablename
                  + '] set isdeleted = 1 where [id] in ('
                  + @idstr + ')';
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_GetHitCount]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_GetHitCount] @tablename NVARCHAR(50),
                                               @id        INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'select hitcount from [' + @tablename
                  + '] where id = ' + CONVERT(NVARCHAR(15), @id)
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_GetInfoCount]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_GetInfoCount] @tablename NVARCHAR(50),
                                                @wherestr  NVARCHAR(2000)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @wherestr = '' )
      BEGIN
          SET @sqlstr = 'select Count([id]) from [' + @tablename + ']'
      END
    ELSE
      BEGIN
          SET @sqlstr = 'select Count([id]) from [' + @tablename
                        + '] where ' + @wherestr
      END
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_GetInfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_GetInfoList] @tableName     NVARCHAR(50)='',
                                               @fieldName     NVARCHAR(20)='',
                                               @keyword       NVARCHAR(50)='',
                                               @chid          INT,
                                               @colidstr      NVARCHAR(3000)='',
                                               @status        VARCHAR(50)='-99',
                                               @property      VARCHAR(50)='',
                                               @propertytype  VARCHAR(10)='=',
                                               @propertyvalue VARCHAR(50)='',
                                               @usertype      INT=-1,
                                               @pageindex     INT=1,
                                               @pagesize      INT=20,
                                               @recordcount   INT=0 output
AS
    DECLARE @wherestr NVARCHAR(4000)
    SET @wherestr = '';
    IF( @tablename = '' )
      RETURN;
    IF( @fieldname != '' )
      SET @wherestr = @wherestr + ' i.' + @fieldname + ' like ''%'
                      + @keyword + '%'' and ';
    IF( @chid != 0 )
      SET @wherestr = @wherestr + ' co.chid = '
                      + CONVERT(NVARCHAR(15), @chid) + ' and ';
    IF( @colidstr != '0' )
      SET @wherestr = @wherestr + ' i.colId in(' + @colidstr + ') and ';
    IF( @status != '-99' )
      SET @wherestr = @wherestr + ' i.status in(' + @status + ') and ';
    IF( @property != ''
        AND @propertytype != ''
        AND @propertyvalue != '' )
      SET @wherestr = @wherestr + ' i.' + @property + @propertytype
                      + @propertyvalue + ' and ';
    IF( @usertype !=- 1 )
      SET @wherestr = @wherestr + ' i.usertype='
                      + CONVERT(NVARCHAR(15), @usertype) + ' and '
    SET @wherestr = @wherestr
                    + ' i.status != -1 and i.isdeleted = 0'
    DECLARE @selectfield NVARCHAR(500)
    SET @selectfield = ' co.colname,i.[id],i.title,i.titletype,i.colid,i.uname,i.usertype,i.hitcount,i.issideshow,i.istop,i.isrecommend,i.isfocus,i.status,i.iscreated '
    DECLARE @selecttable NVARCHAR(500)
    SET @selecttable = @tablename
                       + ' i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on ch.chid = co.chid '
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @pageindex = 1 )
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + @selectfield + ' from ' + @selecttable
                    + ' where ' + @wherestr
                    + ' order by i.[id] desc';
    ELSE
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + @selectfield + ' from ' + @selecttable
                    + ' where ' + @wherestr
                    + ' and i.[id] < (select min(O.[id]) from(select top '
                    + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                    + ' i.[id] from ' + @selecttable + ' where '
                    + @wherestr
                    + ' order by i.[id] desc)O) order by i.[id] desc'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr ='select Count(i.[id]) from ' + @selecttable
                 + ' where ' + @wherestr
    EXECUTE sp_executesql
      @sqlstr;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_GetInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_GetInfo] @tablename NVARCHAR(50),
                                           @id        INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr='select t.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname from ['
                + @tablename
                + '] t inner join Qianbo_Column co on t.ColId = co.ColId inner join Qianbo_Channel ch on t.ChId = ch.ChId inner join Qianbo_Model m on ch.ModelType = m.ModelId where t.Id = @tid';
    DECLARE @param NVARCHAR(200)
    SET @param='@tid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_GetInfo_CustomForm]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Info_GetInfo_CustomForm] @tablename NVARCHAR(50),
                                                      @id        INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr='select * from [' + @tablename
                + '] where [id] = @tid';
    DECLARE @param NVARCHAR(200)
    SET @param='@tid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_GetRecycleInfoList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Info_GetRecycleInfoList] @tablename NVARCHAR(50),
                                                      @type      INT,
                                                      @pageindex INT=1,
                                                      @pagesize  INT=20
AS
    DECLARE @sqlstr NVARCHAR(2000)
    DECLARE @countstr NVARCHAR(2000)
    IF( @type = 1 )
      BEGIN
          SET @sqlstr = 'select chid as id,chname,description,addtime from Qianbo_Channel where isdeleted = 1'
          SET @countstr = 'select Count(*) from Qianbo_Channel where isdeleted = 1'
      END
    ELSE IF( @type = 2 )
      BEGIN
          SET @sqlstr = 'select colid as id,colname,co.description,co.chid,colparentid,chname from Qianbo_Column co join Qianbo_Channel ch on co.chid = ch.chid where co.isdeleted = 1'
          SET @countstr = 'select Count(*) from Qianbo_Column co join Qianbo_Channel ch on co.chid = ch.chid where co.isdeleted = 1'
      END
    ELSE IF( @type = 3 )
      BEGIN
          IF( @pageindex = 1 )
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize)
                          + ' id,specialcname,specialdomain,specialremark,specialaddtime,parentid from Qianbo_Special where isdeleted = 1 order by id desc'
          ELSE
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize)
                          + ' id,specialcname,specialdomain,specialremark,specialaddtime,parentid from Qianbo_Special where isdeleted = 1 and id < (select min(id) from(select top '
                          + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                          + ' id from Qianbo_Special where isdeleted = 1 order by id desc)o) order by id desc'
          SET @countstr = 'select Count(*) from Qianbo_Special where isdeleted = 1'
      END
    ELSE IF( @type = 4 )
      BEGIN
          IF( @tablename = '' )
            RETURN;
          IF( @pageindex = 1 )
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize)
                          + ' co.colname,i.[id],i.colid,i.title,i.addtime from ['
                          + @tablename
                          + '] i join Qianbo_Column co on i.colid = co.colid where i.[isdeleted] = 1 order by id desc'
          ELSE
            SET @sqlstr = 'select top '
                          + CONVERT(NVARCHAR(15), @pagesize)
                          + ' co.colname,i.[id],i.colid,i.title,i.addtime from ['
                          + @tablename
                          + '] i join Qianbo_Column co on i.colid = co.colid where i.[isdeleted] = 1 and i.[id] < (select min(id) from(select top '
                          + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                          + ' id from [' + @tablename
                          + '] i join Qianbo_Column co on i.colid = co.colid  where i.isdeleted = 1 order by id desc)o) order by id desc'
          SET @countstr = 'select Count(*) from [' + @tablename
                          + '] i join Qianbo_Column co on i.colid = co.colid where i.isdeleted = 1'
      END
    EXECUTE sp_executesql
      @sqlstr
    EXECUTE sp_executesql
      @countstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_GetUserInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_GetUserInfo] @tablename NVARCHAR(50),
                                               @UserId    INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr='select * from [' + @tablename
                + '] where [UId] = @tid';
    DECLARE @param NVARCHAR(200)
    SET @param='@tid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @UserId
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_MassMoveInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_MassMoveInfo] @tablename   NVARCHAR(20),
                                                @idstr       VARCHAR(2000),
                                                @colid       INT,
                                                @targetcolid INT
AS
    IF( @tablename = '' )
      RETURN;
    DECLARE @sqlstr NVARCHAR(4000)
    DECLARE @wherestr NVARCHAR(400)
    IF( @idstr = '' )
      SET @wherestr = ' where colid = @tcolid'
    ELSE
      SET @wherestr = ' where [id] in(' + @idstr + ')'
    SET @sqlstr = 'update [' + @tablename
                  + '] set colid = @ttargetcolid ' + @wherestr
    DECLARE @param NVARCHAR(400)
    SET @param = '@ttargetcolid int,@tcolid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @ttargetcolid = @targetcolid,
      @tcolid = @colid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_MassSetInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_MassSetInfo] @tablename           NVARCHAR(50),
                                               @idstr               VARCHAR(2000),
                                               @colid               INT,
                                               @tagflag             BIT,
                                               @tagidstr            NVARCHAR(300),
                                               @tagnamestr          NVARCHAR(300),
                                               @topflag             BIT,
                                               @istop               BIT,
                                               @recommendflag       BIT,
                                               @isrecommend         BIT,
                                               @focusflag           BIT,
                                               @isfocus             BIT,
                                               @templatepathflag    BIT,
                                               @templatepath        VARCHAR(255),
                                               @hitcountflag        BIT,
                                               @hitcount            INT,
                                               @isopenedflag        BIT,
                                               @isopened            INT,
                                               @groupidstrflag      BIT,
                                               @groupidstr          VARCHAR(1000),
                                               @pointcountflag      BIT,
                                               @pointcount          INT,
                                               @chargetypeflag      BIT,
                                               @chargetype          INT,
                                               @chargehourcountflag BIT,
                                               @chargehourcount     INT,
                                               @chargeviewcountflag BIT,
                                               @chargeviewcount     INT,
                                               @pagetypeflag        BIT,
                                               @pagetype            INT
AS
    IF( @tablename = '' )
      RETURN;
    DECLARE @sqlstr NVARCHAR(4000)
    DECLARE @param NVARCHAR(4000)
    DECLARE @wherestr NVARCHAR(2000)
    SET @wherestr=''
    DECLARE @setstr NVARCHAR(4000)
    SET @setstr = ''
    DECLARE @char VARCHAR(1)
    SET @char=''
    IF( @idstr = '' )
      SET @wherestr = ' where i.colid = @tcolid ';
    ELSE
      SET @wherestr = ' where i.[id] in(' + @idstr + ')'
    IF( @tagflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.tagidstr = @ttagidstr,i.tagnamestr = @ttagnamestr'
          SET @char = ','
      END
    IF( @topflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char + 'i.istop = @tistop'
          SET @char=','
      END
    IF( @recommendflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.isrecommend = @tisrecommend'
          SET @char=','
      END
    IF( @focusflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char + 'i.isfocus = @tisfocus'
          SET @char=','
      END
    IF( @templatepathflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.templatepath = @ttemplatepath'
          SET @char=','
      END
    IF( @hitcountflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char + 'i.hitcount = @thitcount'
          SET @char=','
      END
    IF( @isopenedflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char + 'i.isopened = @tisopened'
          SET @char=','
      END
    IF( @groupidstrflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.groupidstr = @tgroupidstr'
          SET @char=','
      END
    IF( @pointcountflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.pointcount = @tpointcount'
          SET @char=','
      END
    IF( @chargetypeflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.chargetype = @tchargetype'
          SET @char=','
      END
    IF( @chargehourcountflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.chargehourcount = @tchargehourcount'
          SET @char=','
      END
    IF( @chargeviewcountflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char
                        + 'i.chargeviewcount = @tchargeviewcount'
          SET @char=','
      END
    IF( @pagetypeflag = 1 )
      BEGIN
          SET @setstr = @setstr + @char + 'i.pagetype = @tpagetype'
      END
    IF( @setstr = '' )
      RETURN;
    SET @sqlstr='update i set ' + @setstr + ' from ['
                + @tablename + ' ] i ' + @wherestr
    SET @param = '@ttagidstr nvarchar(300),@ttagnamestr nvarchar(300),@tistop bit,@tisrecommend bit,@tisfocus bit,@ttemplatepath varchar(255),@thitcount int,@tisopened int,@tgroupidstr varchar(1000),@tpointcount int,@tchargetype int,@tchargehourcount int,@tchargeviewcount int,@tpagetype int,@tcolid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @ttagidstr = @tagidstr,
      @ttagnamestr = @tagnamestr,
      @tistop = @istop,
      @tisrecommend = @isrecommend,
      @tisfocus = @isfocus,
      @ttemplatepath = @templatepath,
      @thitcount = @hitcount,
      @tisopened = @isopened,
      @tgroupidstr = @groupidstr,
      @tpointcount = @pointcount,
      @tchargetype = @chargetype,
      @tchargehourcount = @chargehourcount,
      @tchargeviewcount = @chargeviewcount,
      @tpagetype = @pagetype,
      @tcolid = @colid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_SetInfoSpecial]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_SetInfoSpecial] @tablename    NVARCHAR(50),
                                                  @id           INT,
                                                  @specialidstr VARCHAR(500)
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update [' + @tablename
                  + '] set [specialidstr] = @tspecialidstr where [id] = @tid'
    DECLARE @param NVARCHAR(2000)
    SET @param = '@tspecialidstr varchar(5000),@tid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tspecialidstr = @specialidstr,
      @tid = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_SetProperty]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_SetProperty] @tablename     NVARCHAR(50),
                                               @property      NVARCHAR(50),
                                               @propertyvalue NVARCHAR(50),
                                               @id            INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update ' + @tablename + ' set [' + @property
                  + '] = ' + @propertyvalue + ' where [id] = '
                  + CONVERT(NVARCHAR(15), @id);
    EXEC sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_UpdateIsCreated]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_UpdateIsCreated] @tablename NVARCHAR(50),
                                                   @id        INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update [' + @tablename
                  + '] set iscreated=1 where [id] = '
                  + CONVERT(NVARCHAR(15), @id)
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_User_DeleteInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_User_DeleteInfo] @idstr     NVARCHAR(2000),
                                                   @tablename NVARCHAR(50),
                                                   @uid       INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'delete from [' + @tablename
                  + '] where [id] in (' + @idstr
                  + ') and [uId] = @tuid and usertype = 0 and status = -1';
    DECLARE @param NVARCHAR(200)
    SET @param = '@tuid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tuid = @uid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_User_GetInfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_User_GetInfoList] @tableName     NVARCHAR(50)='',
                                                    @uid           INT,
                                                    @fieldName     NVARCHAR(20)='',
                                                    @keyword       NVARCHAR(50)='',
                                                    @chid          INT,
                                                    @colidstr      NVARCHAR(500)='',
                                                    @status        VARCHAR(50)='-99',
                                                    @property      VARCHAR(50)='',
                                                    @propertytype  VARCHAR(10)='=',
                                                    @propertyvalue VARCHAR(50)='',
                                                    @usercateid    INT=-1,
                                                    @pageindex     INT=1,
                                                    @pagesize      INT=20,
                                                    @recordcount   INT=0 output
AS
    IF( @tablename = '' )
      RETURN;
    DECLARE @wherestr NVARCHAR(2000)
    SET @wherestr = ' i.uid = ' + CONVERT(NVARCHAR(15), @uid)
                    + ' and usertype = 0 and ';
    IF( @fieldname != '' )
      SET @wherestr = @wherestr + ' i.' + @fieldname + ' like ''%'
                      + @keyword + '%'' and ';
    IF( @chid != 0 )
      SET @wherestr = @wherestr + ' co.chid = '
                      + CONVERT(NVARCHAR(15), @chid) + ' and ';
    IF( @colidstr != '0' )
      SET @wherestr = @wherestr + ' i.colId in(' + @colidstr + ') and ';
    IF( @status != '-99' )
      SET @wherestr = @wherestr + ' i.status in(' + @status + ') and ';
    IF( @property != ''
        AND @propertyType != ''
        AND @propertyvalue != '' )
      SET @wherestr = @wherestr + ' i.' + @property + @propertyType
                      + @propertyvalue + ' and ';
    IF( @usercateid !=- 1 )
      SET @wherestr = @wherestr + ' i.usercateid='
                      + CONVERT(NVARCHAR(15), @usercateid) + ' and '
    SET @wherestr = @wherestr + ' i.isdeleted = 0 '
    DECLARE @selectfield NVARCHAR(500)
    SET @selectfield = ' ch.chid,ch.modeltype,ch.minihitcount,co.colname,i.[id],i.title,i.titletype,i.colid,i.uname,i.usertype,i.hitcount,i.issideshow,i.istop,i.isrecommend,i.isfocus,i.status,i.addtime '
    DECLARE @selecttable NVARCHAR(500)
    SET @selecttable = @tablename
                       + ' i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on ch.chid = co.chid '
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @pageindex = 1 )
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + @selectfield + ' from ' + @selecttable
                    + ' where ' + @wherestr
                    + ' order by i.[id] desc';
    ELSE
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + @selectfield + ' from ' + @selecttable
                    + ' where ' + @wherestr
                    + ' and i.[id] < (select min(O.[id]) from(select top '
                    + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                    + ' i.[id] from ' + @selecttable + ' where '
                    + @wherestr
                    + ' order by i.[id] desc)O) order by i.[id] desc'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr ='select Count(i.[id]) from ' + @selecttable
                 + ' where ' + @wherestr
    EXECUTE sp_executesql
      @sqlstr;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_User_IsExistsInfo]'
GO
CREATE PROCEDURE [dbo].[Proc_Info_User_IsExistsInfo] @tableName NVARCHAR(50),
                                                     @UId       INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr='if exists(select 1 from ' + @tableName
                + ' where status = 3 and isdeleted = 0 and UId = '
                + CONVERT(NVARCHAR(15), @UId)
                + ') select 1 else select 0'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Info_User_Publish]'
GO
CREATE PROC [dbo].[Proc_Info_User_Publish] @tablename NVARCHAR(50),
                                           @id        INT,
                                           @uId       INT
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr = 'update [' + @tablename
                  + '] set status = 0 where [id] = @tid and [uid] = @tuid and usertype = 0 and status = -1'
    DECLARE @param NVARCHAR(200)
    SET @param = '@tid int,@tuid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tid = @id,
      @tuid = @uid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_Delete]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_LabelContent_Delete] @LabelCategoryID NVARCHAR(500)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    SET @SqlStr = N'delete Qianbo_LabelContent where [LabelCategoryID] in ('
                  + @LabelCategoryID + ')'
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_LabelContent_GetLbCategoryIdList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_LabelContent_GetLbCategoryIdList] @LbCategoryId INT,
                                                          @CursorPage   INT,
                                                          @PageSize     INT,
                                                          @RecordCount  INT output
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CursorPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_LabelContent where LbCategoryId = '
                  + CONVERT(NVARCHAR(50), @LbCategoryId)
                  + ' order by LabelCategoryID desc'
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from Qianbo_LabelContent where LbCategoryId = '
                  + CONVERT(NVARCHAR(50), @LbCategoryId)
                  + 'and LabelCategoryID < (select min(LabelCategoryID) from(select top '
                  + CONVERT(NVARCHAR(15), (@CursorPage - 1) * @PageSize)
                  + ' LabelCategoryID from Qianbo_LabelContent where LbCategoryId = '
                  + CONVERT(NVARCHAR(50), @LbCategoryId)
                  + ' order by LabelCategoryID desc)O)order by LabelCategoryID desc'
    EXECUTE SP_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select @TRecordCount = Count(LabelCategoryID) from Qianbo_LabelContent where LbCategoryId = '
                  + CONVERT(NVARCHAR(50), @LbCategoryId);
    DECLARE @Param NVARCHAR(50)
    SET @Param = N'@TRecordCount int output'
    EXECUTE SP_ExecuteSql
      @SqlStr,
      @Param,
      @TRecordCount = @RecordCount output
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Link_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_Link_GetList] (@PageSize    INT=20,
                                            @PageIndex   INT=1,
                                            @WhereString NVARCHAR(200))
AS
  BEGIN
      DECLARE @SqlStr NVARCHAR(2000)
      DECLARE @Filter NVARCHAR(200)
      IF( @WhereString = '' )
        BEGIN
            SET @WhereString=' where '
            SET @Filter=''
        END
      ELSE
        BEGIN
            SET @Filter=' where ' + @WhereString
            SET @WhereString=' where ' + @WhereString + ' and '
        END
      IF( @PageIndex = 1 )
        SET @SqlStr = N'select top '
                      + CONVERT(NVARCHAR(10), @PageSize)
                      + ' * from Qianbo_Link ' + @Filter
                      + ' order by LinkId desc'
      ELSE
        SET @SqlStr = N'select top '
                      + CONVERT(NVARCHAR(10), @PageSize)
                      + ' * from Qianbo_Link ' + @WhereString
                      + ' LinkId < (select min(LinkId) from(select top '
                      + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                      + ' * from Qianbo_Link  ' + @Filter
                      + ' order by LinkId desc)L) order by LinkId desc'
  END
PRINT @SqlStr
EXECUTE Sp_ExecuteSql
  @SqlStr
SET @SqlStr ='select Count(LinkId) as Total from Qianbo_Link '
             + @Filter
EXEC Sp_ExecuteSql
  @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Log_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_Log_GetList] @LogType     INT,
                                          @UserName    NVARCHAR(20),
                                          @StartTime   VARCHAR(10),
                                          @EndTime     VARCHAR(10),
                                          @CurrPage    INT,
                                          @PageSize    INT,
                                          @RecordCount INT Output
AS
    DECLARE @SqlStr NVARCHAR(2000);
    DECLARE @WhereStr NVARCHAR(500);
    SET @WhereStr = '';
    IF( @LogType != 0 )
      SET @WhereStr = @WhereStr + N' LogType = '
                      + CONVERT(NVARCHAR(5), @LogType) + ' and ';
    IF( @UserName != '' )
      SET @WhereStr = @WhereStr + N' UserName = ''' + @UserName
                      + ''' and ';
    IF( @StartTime != ' '
        AND @EndTime != '' )
      SET @WhereStr = @WhereStr + N' LogTime >= ''' + @StartTime
                      + ''' and LogTime <  ''' + @EndTime + ''' and '
    IF( @StartTime != ''
        AND @EndTime = '' )
      SET @WhereStr = @WhereStr + N' LogTime >= ''' + @StartTime
                      + ''' and '
    IF( @StartTime = ''
        AND @EndTime != '' )
      SET @WhereStr = @WhereStr + N' LogTime < ''' + @EndTime
                      + ''' and '
    SET @WhereStr = @WhereStr + N' 1=1 '
    IF( @CurrPage = 1 )
      SET @SqlStr = N'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + ' * from Qianbo_Log where ' + @WhereStr
                    + ' order by LogId desc ';
    ELSE
      SET @SqlStr = N'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + ' * from Qianbo_Log where LogId < (select min(LogId) from(select top '
                    + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                    + ' LogId from Qianbo_Log where ' + @WhereStr
                    + ' order by LogId desc)O) and ' + @WhereStr
                    + ' order by LogId desc'
    EXECUTE SP_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select @TRecordCount = Count(LogId) from Qianbo_Log where '
                  + @WhereStr;
    DECLARE @Param NVARCHAR(50)
    SET @Param = N'@TRecordCount int output'
    EXECUTE SP_ExecuteSql
      @SqlStr,
      @Param,
      @TRecordCount = @RecordCount output
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_AddField]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_AddField] @TableName    NVARCHAR(50),
                                                  @FieldName    NVARCHAR(50),
                                                  @FieldType    NVARCHAR(50),
                                                  @DefaultValue NVARCHAR(150)
AS
    DECLARE @sqlstr NVARCHAR(1000)
    IF( @FieldType = 'nvarchar' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] nvarchar(100) default ('''
                    + @DefaultValue + ''')'
    ELSE IF( @FieldType = 'varchar' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] varchar(100)'
    ELSE IF( @FieldType = 'ntext' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] ntext'
    ELSE IF( @FieldType = 'int' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] int'
    ELSE IF( @FieldType = 'bit' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] bit'
    ELSE IF( @FieldType = 'char' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] char(10)'
    ELSE IF( @FieldType = 'datetime' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] datetime'
    ELSE IF( @FieldType = 'decimal' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] decimal(8)'
    ELSE IF( @FieldType = 'money' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] money'
    ELSE IF( @FieldType = 'nchar' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] nchar(10)'
    ELSE IF( @FieldType = 'text' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] text'
    ELSE IF( @FieldType = 'float' )
      SET @sqlstr = 'alter table [' + @TableName + '] add ['
                    + @FieldName + '] float(8)'
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_DelField]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_DelField] @TableName NVARCHAR(50),
                                                  @FieldName NVARCHAR(50)
AS
    DECLARE @Name NVARCHAR(50)
    DECLARE @sqlstr NVARCHAR(500)
    SELECT @Name = b.NAME
    FROM   syscolumns a,
           sysobjects b
    WHERE  a.id = Object_id(@TableName)
           AND b.id = a.cdefault
           AND a.NAME = @FieldName
           AND b.NAME LIKE 'DF%'
    SET @sqlstr = 'alter table [' + @TableName
                  + '] drop constraint [' + @Name + ']'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr = 'alter table [' + @TableName
                  + '] drop column [' + @FieldName + ']'
    EXECUTE sp_executesql
      @sqlstr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetAllTable]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetAllTable]
AS
    SELECT NAME
    FROM   [sysobjects]
    WHERE  xtype = 'U'
    ORDER  BY NAME
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetTableAllFieldAndType]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetTableAllFieldAndType] @TableName NVARCHAR(50)
AS
    SELECT COLUMN_NAME,
           DATA_TYPE
    FROM   INFORMATION_SCHEMA.COLUMNS
    WHERE  TABLE_NAME = @TableName
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_GetTableAllField]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_GetTableAllField] @TableName NVARCHAR(50)
AS
    SELECT a.NAME
    FROM   syscolumns a,
           sysobjects b
    WHERE  a.id = b.id
           AND b.NAME = @TableName
    ORDER  BY a.colid
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_InField]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_InField] @FieldStr NVARCHAR(3000)
AS
    DECLARE @SqlStr NVARCHAR(4000)
    SET @SqlStr=N'select * from [Qianbo_ModelField] where FieldId in('
                + @FieldStr + ')'
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_InModelId]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_InModelId] @InModelId NVARCHAR(2000)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    SET @SqlStr=N'select * from [Qianbo_ModelField] where ModelId in('
                + @InModelId + ')';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_IsNotField]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_IsNotField] @TableName NVARCHAR(50),
                                                    @FieldName NVARCHAR(50)
AS
    SELECT *
    FROM   syscolumns a,
           sysobjects b
    WHERE  a.id = b.id
           AND a.NAME = @FieldName
           AND b.NAME = @TableName
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_ModelField_UpdateFieldDefault]'
GO
CREATE PROCEDURE [dbo].[Proc_ModelField_UpdateFieldDefault] @TableName    NVARCHAR(50),
                                                            @FieldName    NVARCHAR(50),
                                                            @DefaultValue NVARCHAR(50)
AS
    DECLARE @Name NVARCHAR(50)
    DECLARE @sqlstr NVARCHAR(1000)
    SELECT @Name = b.NAME
    FROM   syscolumns a,
           sysobjects b
    WHERE  a.id = Object_id(@TableName)
           AND b.id = a.cdefault
           AND a.NAME = @FieldName
           AND b.NAME LIKE 'DF%'
    SET @sqlstr = 'alter table [' + @TableName
                  + '] drop constraint [' + @Name + ']'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr='alter table [' + @TableName
                + '] add default (''' + @DefaultValue
                + ''') for [' + @FieldName + ']'
    EXECUTE sp_executesql
      @sqlstr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_AddTableGIPS]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Model_AddTableGIPS] @TableName NVARCHAR(50)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr=N'
CREATE TABLE [dbo].[' + @TableName
                + ']
(
[Id] [int] IDENTITY (1, 1) PRIMARY Key NOT NULL,
[ChId] [int] NOT NULL ,
[ColId] [int] NOT NULL ,
[Title] [nvarchar] (200)  COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''''),
[TitleColor] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''''),
[TitleFontType] [int]   NULL default (0),
[TitleType] [int]   NULL default (0),
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL default (''''),
[IndexNum] [nvarchar] (200)  COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''''),
[UId] [int] NOT NULL ,
[UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[UserType] [int] NOT NULL ,
[AdminUId] [int] NULL ,
[AdminUName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL default (''''),
[Status] [int]  NULL default (0),
[HitCount] [int]  NULL default (0),
[AddTime] [datetime] NOT NULL ,
[UpdateTime] [datetime] NOT NULL ,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL default ('''') ,
[PageType] [int] NULL default (1) ,
[IsCreated] [bit]  NULL default (0),
[UserCateId] [int]  NULL default (0),
[PointCount] [int]  NULL default (0),
[ChargeType] [int]  NULL default (1),
[ChargeHourCount] [int]  NULL default (0),
[ChargeViewCount] [int] NULL default (0) ,
[IsOpened] [int]  NULL default (2),
[GroupIdStr] [varchar] (200)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[IsDeleted] [bit] NULL default (0) ,
[IsRecommend] [bit]  NULL default (0),
[IsTop] [bit]  NULL default (0),
[IsFocus] [bit]  NULL default (0),
[IsSideShow] [bit] NULL default (0) ,
[TagIdStr] [varchar] (300)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[TagNameStr] [nvarchar] (300)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[IsAllowComment] [bit]  NULL default (0),
[SpecialIdStr] [varchar] (200)  COLLATE Chinese_PRC_CI_AS NULL default ('''') )
CREATE  INDEX [IX_' + @TableName
                + '_ColId] ON [' + @TableName
                + ']([ColId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_AddTime] ON [' + @TableName
                + ']([AddTime]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_SpecialIdStr] ON [' + @TableName
                + ']([SpecialIdStr]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_TagIdStr] ON [' + @TableName
                + ']([TagIdStr]) ON [PRIMARY]'
    EXEC sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_AddTableShop]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Model_AddTableShop] @TableName NVARCHAR(50)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr=N'
CREATE TABLE [dbo].[' + @TableName
                + ']
(
        [Id] [int] IDENTITY (1, 1) NOT NULL ,
        [ChId] [int] NULL ,
        [ColId] [int] NULL ,
        [ProductNum] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
        [BarCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
        [Title] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
        [TitleColor] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
        [TitleFontType] [int] NULL ,
        [TitleType] [int] NULL ,
        [TitleImgPath] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
        [UId] [int] NULL ,
        [UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
        [UserType] [int] NULL ,
        [AdminUId] [int] NULL ,
        [AdminUName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
        [Status] [int] NULL ,
        [TagIdStr] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
        [TagNameStr] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
        [IsRecommend] [bit] NULL,
        [IsFocus] [bit] NULL,
        [IsTop] [bit] NULL,
        [IsSideShow] [bit] NULL ,
        [IsAllowComment] [bit] NULL ,
        [IsCreated] [bit] NULL ,
        [IsSale] [bit] NULL ,
        [IsDeleted] [bit] NULL ,
        [IsOpened] [int] NULL ,
        [SpecialIdStr] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
        [ProducerId] [int] NULL ,
        [ProducerName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
        [BrandId] [int] NULL ,
        [BrandName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
        [OutOfStockIsBuy] [bit] NULL ,
        [LimitNum] [int] NULL ,
        [StorageNum] [int] NULL ,
        [StorageCallNum] [int] NULL ,
        [StorageCountMode] [int] NULL ,
        [TaxRateSet] [int] NULL ,
        [TaxRate] [decimal](18, 6) NULL ,
        [StarLevel] [nvarchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
        [MarketPrice] [decimal](18, 2) NULL ,
        [NowRetailPrice] [decimal](18, 2) NULL ,
        [RetailPriceSet] [int] NULL ,
        [RetailPrice] [decimal](18, 2) NULL ,
        [IsWholesale] [bit] NULL ,
        [Wholesale] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
        [SalesPromotionSet] [int] NULL ,
        [SalesPromotion] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
        [PresentId] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
        [PresentName] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
        [PresentPoint] [int] NULL ,
        [PresentExp] [int] NULL ,
        [PresentMoney] [int] NULL ,
        [Priority] [int] NULL ,
        [HitCount] [int] NULL ,
        [AddTime] [datetime] NULL ,
        [UpdateTime] [datetime] NULL ,
        [TemplatePath] [nvarchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
        [PageType] [int] Null,
        [PointCount] [int] Null)
CREATE  INDEX [IX_' + @TableName
                + '_ChId] ON [' + @TableName
                + ']([ChId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_ColId] ON [' + @TableName
                + ']([ColId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_AddTime] ON [' + @TableName
                + ']([AddTime]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_SpecialIdStr] ON [' + @TableName
                + ']([SpecialIdStr]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_TagIdStr] ON [' + @TableName
                + ']([TagIdStr]) ON [PRIMARY]'
    EXEC sp_executesql
      @sqlstr
    SET @sqlstr=N'
ALTER TABLE [dbo].[' + @TableName
                + '] WITH NOCHECK ADD
        CONSTRAINT [PK_' + @TableName
                + '] PRIMARY KEY  CLUSTERED
        (
                [Id]
        )  ON [PRIMARY]'
    EXEC sp_executesql
      @sqlstr
    SET @sqlstr=N'
ALTER TABLE [dbo].[' + @TableName
                + '] ADD
        CONSTRAINT [DF_' + @TableName
                + '_TitleColor] default ('''') FOR [TitleColor],
        CONSTRAINT [DF_' + @TableName
                + '_TitleFontType] default (0) FOR [TitleFontType],
        CONSTRAINT [DF_' + @TableName
                + '_TitleType] default (0) FOR [TitleType],
        CONSTRAINT [DF_' + @TableName
                + '_TitleImgPath] default ('''') FOR [TitleImgPath],
        CONSTRAINT [DF_' + @TableName
                + '_AdminUName] default ('''') FOR [AdminUName],
        CONSTRAINT [DF_' + @TableName
                + '_Status] default (0) FOR [Status],
        CONSTRAINT [DF_' + @TableName
                + '_TagIdStr] default ('''') FOR [TagIdStr],
        CONSTRAINT [DF_' + @TableName
                + '_TagNameStr] default ('''') FOR [TagNameStr],
        CONSTRAINT [DF_' + @TableName
                + '_IsRecommend] default (0) FOR [IsRecommend],
        CONSTRAINT [DF_' + @TableName
                + '_IsFocus] default (0) FOR [IsFocus],
        CONSTRAINT [DF_' + @TableName
                + '_IsTop] default (0) FOR [IsTop],
        CONSTRAINT [DF_' + @TableName
                + '_IsSideShow] default (0) FOR [IsSideShow],
        CONSTRAINT [DF_' + @TableName
                + '_IsAllowComment] default (0) FOR [IsAllowComment],
        CONSTRAINT [DF_' + @TableName
                + '_IsCreate] default (0) FOR [IsCreated],
        CONSTRAINT [DF_' + @TableName
                + '_IsSale] default (0) FOR [IsSale],
        CONSTRAINT [DF_' + @TableName
                + '_IsDeleted] default (0) FOR [IsDeleted],
        CONSTRAINT [DF_' + @TableName
                + '_SpecialIdStr] default ('''') FOR [SpecialIdStr],
        CONSTRAINT [DF_' + @TableName
                + '_ProducerId] default (0) FOR [ProducerId],
        CONSTRAINT [DF_' + @TableName
                + '_ProducerName] default ('''') FOR [ProducerName],
        CONSTRAINT [DF_' + @TableName
                + '_BrandId] default (0) FOR [BrandId],
        CONSTRAINT [DF_' + @TableName
                + '_OutOfStockIsBuy] default (0) FOR [OutOfStockIsBuy],
        CONSTRAINT [DF_' + @TableName
                + '_LimitNum] default (0) FOR [LimitNum],
        CONSTRAINT [DF_' + @TableName
                + '_StorageNum] default (0) FOR [StorageNum],
        CONSTRAINT [DF_' + @TableName
                + '_StorageCallNum] default (0) FOR [StorageCallNum],
        CONSTRAINT [DF_' + @TableName
                + '_StorageCountMode] default (1) FOR [StorageCountMode],
        CONSTRAINT [DF_' + @TableName
                + '_TaxRate] default (1) FOR [TaxRateSet],
        CONSTRAINT [DF_' + @TableName
                + '_MarketPrice] default (0) FOR [MarketPrice],
        CONSTRAINT [DF_' + @TableName
                + '_RetailPrice] default (0) FOR [NowRetailPrice],
        CONSTRAINT [DF_' + @TableName
                + '_SalesPromotionSet] default (1) FOR [SalesPromotionSet],
        CONSTRAINT [DF_' + @TableName
                + '_PresentId] default (0) FOR [PresentId],
        CONSTRAINT [DF_' + @TableName
                + '_PresentPoint] default (0) FOR [PresentPoint],
        CONSTRAINT [DF_' + @TableName
                + '_PresentExp] default (0) FOR [PresentExp],
        CONSTRAINT [DF_' + @TableName
                + '_Priority] default (0) FOR [Priority],
        CONSTRAINT [DF_' + @TableName
                + '_HitCount] default (0) FOR [HitCount],
        CONSTRAINT [DF_' + @TableName
                + '_PageType] default (1) FOR [PageType]'
    EXEC sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_AddTable]'
GO
CREATE PROCEDURE [dbo].[Proc_Model_AddTable] @TableName NVARCHAR(50)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr=N'
CREATE TABLE [dbo].[' + @TableName
                + ']
(
[Id] [int] IDENTITY (1, 1) PRIMARY Key NOT NULL,
[ChId] [int] NOT NULL ,
[ColId] [int] NOT NULL ,
[Title] [nvarchar] (200)  COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''''),
[TitleColor] [nvarchar] (6) COLLATE Chinese_PRC_CI_AS NULL DEFAULT(''''),
[TitleFontType] [int]   NULL default (0),
[TitleType] [int]   NULL default (0),
[TitleImgPath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL default (''''),
[UId] [int] NOT NULL ,
[UName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[UserType] [int] NOT NULL ,
[AdminUId] [int] NULL ,
[AdminUName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL default (''''),
[Status] [int]  NULL default (0),
[HitCount] [int]  NULL default (0),
[AddTime] [datetime] NOT NULL ,
[UpdateTime] [datetime] NOT NULL ,
[TemplatePath] [varchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL default ('''') ,
[PageType] [int] NULL default (1) ,
[IsCreated] [bit]  NULL default (0),
[UserCateId] [int]  NULL default (0),
[PointCount] [int]  NULL default (0),
[ChargeType] [int]  NULL default (1),
[ChargeHourCount] [int]  NULL default (0),
[ChargeViewCount] [int] NULL default (0) ,
[IsOpened] [int]  NULL default (2),
[OuterUrl] [nvarchar] (300)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[GroupIdStr] [varchar] (200)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[IsDeleted] [bit] NULL default (0) ,
[IsRecommend] [bit]  NULL default (0),
[IsTop] [bit]  NULL default (0),
[IsFocus] [bit]  NULL default (0),
[IsSideShow] [bit] NULL default (0) ,
[TagIdStr] [varchar] (300)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[TagNameStr] [nvarchar] (300)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[IsAllowComment] [bit]  NULL default (0),
[SpecialIdStr] [varchar] (200)  COLLATE Chinese_PRC_CI_AS NULL default (''''),
[ViewUName] [ntext]  NULL default (''),
[ViewUName2] [ntext]  NULL default (''),
[ExtendContentTable] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL default ('''') )
CREATE  INDEX [IX_' + @TableName
                + '_ChId] ON [' + @TableName
                + ']([ChId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_ColId] ON [' + @TableName
                + ']([ColId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_AddTime] ON [' + @TableName
                + ']([AddTime]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_SpecialIdStr] ON [' + @TableName
                + ']([SpecialIdStr]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_TagIdStr] ON [' + @TableName
                + ']([TagIdStr]) ON [PRIMARY]'
    EXEC sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_CheckTableValidate]'
GO
CREATE PROCEDURE [dbo].[Proc_Model_CheckTableValidate] @TableName NVARCHAR(50)
AS
    IF EXISTS (SELECT *
               FROM   sysobjects
               WHERE  xtype = 'U'
                      AND NAME = @TableName)
      SELECT 0
    ELSE
      SELECT 1
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_ExtendTable]'
GO
CREATE PROCEDURE [dbo].[Proc_Model_ExtendTable] @TableName NVARCHAR(50)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr=N'
CREATE TABLE [dbo].[' + @TableName
                + ']
(
[Id] [int] IDENTITY (1, 1) PRIMARY Key NOT NULL,
[ChId] [int]  NULL,
[ColId] [int]  NULL,
[ModelId] [int]  NULL,
[InfoId] [int]  NULL,
[FieldId] [int]  NULL,
[FieldName] [nvarchar] (100) NULL,
[Nvarchar] [nvarchar]  (200) NULL,
[DateTime] [datetime]  NULL default (getdate()),
[Ntext] [ntext]  NULL,
[Bit] [bit]  NULL default (0),
[Decimal] [decimal]  (18,2) NULL default (0),
[Int] [int]  NULL default (0),
[AddTime] [datetime]  NULL default (getdate())
)
CREATE  INDEX [IX_' + @TableName
                + '_ChId] ON [dbo].[' + @TableName
                + ']([ChId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_ColId] ON [dbo].[' + @TableName
                + ']([ColId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_ModelId] ON [dbo].[' + @TableName
                + ']([ModelId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_InfoId] ON [dbo].[' + @TableName
                + ']([InfoId]) ON [PRIMARY]
CREATE  INDEX [IX_' + @TableName
                + '_FieldId] ON [dbo].[' + @TableName
                + ']([FieldId]) ON [PRIMARY]'
    EXEC sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_InfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Model_InfoList] @TableName NVARCHAR(100),
                                             @CurrPage  INT,
                                             @PageSize  INT,
                                             @strWhere  NVARCHAR(3000)
AS
    DECLARE @SqlStr NVARCHAR(4000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select m.*,ch.ChName,ch.DirName,co.ColName,co.ColDirName from ['
                  + @TableName
                  + '] m inner join Qianbo_Channel ch on m.ChId = ch.ChId inner join Qianbo_Column co on m.ColId = co.ColId '
                  + @strWhere + ' order by m.AddTime desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' m.*,ch.ChName,ch.DirName,co.ColName,co.ColDirName from ['
                  + @TableName
                  + '] m inner join Qianbo_Channel ch on m.ChId = ch.ChId inner join Qianbo_Column co on m.ColId = co.ColId '
                  + @strWhere + ' and m.AddTime < (select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' m.AddTime from [' + @TableName + '] '
                  + @strWhere
                  + ' order by m.AddTime desc) order by m.AddTime desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(Id) from [' + @TableName
                  + '] m ' + @strWhere;
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Model_Out]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Model_Out] @InModelId NVARCHAR(2000)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    SET @SqlStr=N'select * from [Qianbo_Model] where ModelId in('
                + @InModelId + ')';
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Notice_GetTop]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Notice_GetTop] @Top INT
AS
    DECLARE @SqlStr NVARCHAR(2000);
    SET @SqlStr=N'select top ' + CONVERT(NVARCHAR(15), @Top)
                + ' * from [Qianbo_Notice]  where datediff(day,OverdueDate,getdate()) <= 0 and IsState = ''审核通过'' order by IsPriority desc,NoticeId desc'
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PlanAssignMent_Add]'
GO
CREATE PROCEDURE [dbo].[Proc_PlanAssignMent_Add] @Name       NVARCHAR(300),
                                                 @AssType    INT,
                                                 @PlanAss    NVARCHAR(50),
                                                 @Content    NTEXT,
                                                 @AddDate    DATETIME,
                                                 @UpdateDate DATETIME
AS
    INSERT INTO Qianbo_PlanAssignMent
                ([Name],
                 [AssType],
                 [PlanAss],
                 [Content],
                 [AddDate],
                 [UpdateDate])
    VALUES      (@Name,
                 @AssType,
                 @PlanAss,
                 @Content,
                 @AddDate,
                 @UpdateDate)
    SELECT Scope_identity()
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PlanAssignMent_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_PlanAssignMent_Delete] @id INT
AS
    DELETE [Qianbo_PlanAssignMent]
    WHERE  id = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PlanAssignMent_GetModel]'
GO
CREATE PROCEDURE [dbo].[Proc_PlanAssignMent_GetModel] @id INT
AS
    SELECT *
    FROM   Qianbo_PlanAssignMent
    WHERE  id = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PlanAssignMent_List]'
GO
CREATE PROCEDURE [dbo].[Proc_PlanAssignMent_List] @PageSize  INT,
                                                  @PageIndex INT
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @PageIndex = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_PlanAssignMent] order by Id desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_PlanAssignMent] where Id not in(select top '
                  + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                  + ' Id from [Qianbo_PlanAssignMent] order by Id desc) order by Id desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(Id) from [Qianbo_PlanAssignMent]';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_PlanAssignMent_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_PlanAssignMent_Update] @id         INT,
                                                    @Name       NVARCHAR(300),
                                                    @AssType    INT,
                                                    @PlanAss    NVARCHAR(50),
                                                    @Content    NTEXT,
                                                    @AddDate    DATETIME,
                                                    @UpdateDate DATETIME
AS
    UPDATE Qianbo_PlanAssignMent
    SET    [Name] = @Name,
           [AssType] = @AssType,
           [PlanAss] = @PlanAss,
           [Content] = @Content,
           [AddDate] = @AddDate,
           [UpdateDate] = @UpdateDate
    WHERE  id = @id
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_Delete]'
GO
CREATE PROC [dbo].[Proc_Property_Delete] @idStr NVARCHAR(1000)
AS
    DECLARE @sqlStr NVARCHAR(2000)
    SET @sqlStr=N'delete from Qianbo_Property where id in('
                + @idStr + ')'
    EXECUTE Sp_ExecuteSql
      @sqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_GetAllSubProperty]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_Property_GetAllSubProperty] @subidstr NVARCHAR(1000)
AS
    DECLARE @sqlstr VARCHAR(2000)
    SET @sqlstr=N'select * from Qianbo_Property where id in('
                + @subidstr + ')'
    EXEC (@sqlstr)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Property_GetIdStrList]'
GO
CREATE PROCEDURE [dbo].[Proc_Property_GetIdStrList] @idstr NVARCHAR(1000)
AS
    DECLARE @sqlstr NVARCHAR(2000)
    SET @sqlstr=N'select [Id],[ParentId],[ModelId],[PropertyCName],[PropertyEName],[PropertyKeyword],[PropertyContent],[PropertyExtName],[PropertyPic],[PropertyTemplate],[PropertyDir],[PropertyOrder] from Qianbo_Property where [Id] in('
                + @idstr + ')'
    EXECUTE SP_EXECUTESQL
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Recycle_Restore]'
GO
CREATE PROCEDURE [dbo].[Proc_Recycle_Restore] @TableName VARCHAR(50),
                                              @Type      INT,
                                              @Id        INT
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @Filed NVARCHAR(200)
    IF( @Type = 1 )
      BEGIN
          SET @SqlStr='update Qianbo_Channel set [IsDeleted] = 0 where ChId = '
                      + CONVERT(NVARCHAR(10), @Id)
      END
    IF ( @Type = 2 )
      BEGIN
          SET @SqlStr='update Qianbo_Column set [IsDeleted] = 0 where ColId = '
                      + CONVERT(NVARCHAR(10), @Id)
      END
    IF( @Type = 3 )
      BEGIN
          SET @SqlStr='update Qianbo_Special set [IsDeleted] = 0 where [Id] = '
                      + CONVERT(NVARCHAR(10), @Id)
      END
    IF( @Type = 4 )
      BEGIN
          IF( @TableName = '' )
            RETURN;
          SET @SqlStr='update ' + @TableName
                      + ' set [IsDeleted] = 0 where [Id] = '
                      + CONVERT(NVARCHAR(10), @Id)
      END
    EXECUTE sp_executesql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Report_GetList]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_Report_GetList] @PageIndex INT,
                                             @PageSize  INT,
                                             @WhereStr  NVARCHAR(1000)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF( @PageIndex = 1 )
      SET @SqlStr = N'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + ' * from Qianbo_Report where ' + @WhereStr
                    + ' order by ReportId desc';
    ELSE
      SET @SqlStr = N'select top '
                    + CONVERT(NVARCHAR(15), @PageSize)
                    + ' * from Qianbo_Report where ReportId not in(select top '
                    + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                    + ' ReportId from Qianbo_Report where '
                    + @WhereStr + ') and ' + @WhereStr
                    + ' order by ReportId desc'
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(ReportId) from Qianbo_Report where '
                  + @WhereStr
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Review_GetManageList]'
GO
CREATE PROCEDURE [dbo].[Proc_Review_GetManageList] @tablename NVARCHAR(100),
                                                   @modeltype INT,
                                                   @ischeck   BIT,
                                                   @pageindex INT,
                                                   @pagesize  INT
AS
    IF( @tablename = '' )
      RETURN;
    DECLARE @sqlstr NVARCHAR(2000)
    DECLARE @param NVARCHAR(200)
    DECLARE @selecttable NVARCHAR(500)
    SET @selecttable = ' [' + @tablename
                       + '] i join Qianbo_Review re on re.modeltype = @tmodeltype and i.[id] = re.infoid '
    SET @param = '@tischeck bit,@tmodeltype int'
    IF( @pageindex = 1 )
      SET @sqlstr = 'select distinct top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + ' i.[id],i.title from ' + @selecttable
                    + ' where re.ischeck = @tischeck order by i.[id] desc'
    ELSE
      SET @sqlstr = 'select distinct top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + ' i.[id],i.title from ' + @selecttable
                    + ' where i.[id] < (select min(o.[id]) from(select distinct top '
                    + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                    + ' i.[id] from ' + @selecttable
                    + ' where re.ischeck = @tischeck order by i.[id] desc )o) and re.ischeck = @tischeck order by i.[id] desc'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tischeck = @ischeck,
      @tmodeltype = @modeltype
    SET @sqlstr = 'select Count(*) as tatal from (select distinct i.[id] from '
                  + @selecttable
                  + ' where re.ischeck = @tischeck)c'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tischeck = @ischeck,
      @tmodeltype = @modeltype
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Review_GetMoreList]'
GO
CREATE PROCEDURE [dbo].[Proc_Review_GetMoreList] @pageindex INT,
                                                 @pagesize  INT,
                                                 @wherestr  NVARCHAR(500)
AS
    DECLARE @sqlstr NVARCHAR(2000);
    IF( @pageindex = 1 )
      SET @sqlStr='select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' a.* from Qianbo_Review a  ' + @wherestr
                  + ' order by [id] desc';
    ELSE
      SET @sqlstr='select top '
                  + CONVERT(NVARCHAR(15), @pagesize)
                  + ' a.* from Qianbo_Review a  ' + @whereStr
                  + ' and id not in(select top '
                  + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                  + ' id from Qianbo_Review a ' + @wherestr
                  + ' order by [id] desc) order by [id] desc';
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr = 'select Count(id) from Qianbo_Review '
                  + @wherestr;
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Rss_GetInfoList]'
GO
CREATE PROCEDURE [dbo].[Proc_Rss_GetInfoList] @tablename NVARCHAR(50),
                                              @chid      INT,
                                              @colid     NVARCHAR(3000)
AS
    DECLARE @fieldstr NVARCHAR(1000)
    SET @fieldstr = ' i.*,m.modelid,m.tablename,m.uploadpath,ch.chid,ch.typename,ch.chname,ch.dirName,ch.infosorttype,ch.filenametype,ch.isstatictype,colisopened = co.isopened,co.colName,co.coldirname '
    DECLARE @tablestr NVARCHAR(400)
    SET @tablestr = ' [' + @tableName
                    + '] as i join Qianbo_Column co on i.colid = co.colid join Qianbo_Channel ch on co.chid = ch.chid join Qianbo_Model m on ch.modeltype = m.modelid '
    DECLARE @wherestr NVARCHAR(3000)
    SET @wherestr = ''
    IF( @chid != 0 )
      SET @wherestr = @wherestr + ' co.chid = @tchid and '
    IF( @colid != '0' )
      SET @wherestr = @wherestr + ' i.colid in(' + @colid + ') and '
    SET @wherestr = @wherestr
                    + '  i.status = 3 and i.isdeleted = 0 '
    DECLARE @sqlstr NVARCHAR(1000)
    SET @sqlstr = 'select top 100 ' + @fieldstr + 'from'
                  + @tablestr + 'where' + @wherestr
                  + ' order by i.[id] desc'
    DECLARE @param NVARCHAR(500)
    SET @param = '@tchid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @tchid = @chid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SinglePage_GetList]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_SinglePage_GetList] @CurrPage INT,
                                                 @PageSize INT
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_SinglePage] order by SingleId desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_SinglePage] where SingleId not in(select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' SingleId from [Qianbo_SinglePage] order by SingleId desc) order by SingleId desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(SingleId) from [Qianbo_SinglePage]';
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SubSite_GetList]'
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[Proc_SubSite_GetList] @PageSize  INT=20,
                                              @PageIndex INT=1,
                                              @strWhere  VARCHAR(200)
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @Filter NVARCHAR(2000)
    IF( @strWhere = '' )
      BEGIN
          SET @strWhere=' where '
          SET @Filter=''
      END
    ELSE
      BEGIN
          SET @Filter=' where ' + @strWhere
          SET @strWhere=' where ' + @strWhere + ' and '
      END
  BEGIN
      IF( @PageIndex = 1 )
        BEGIN
            SET @SqlStr = N'select top '
                          + CONVERT(NVARCHAR(10), @PageSize)
                          + ' * from Qianbo_SubSite ' + @Filter
                          + ' order by [Id] desc'
        END
      ELSE
        BEGIN
            SET @SqlStr = N'select top '
                          + CONVERT(NVARCHAR(10), @PageSize)
                          + ' * from Qianbo_SubSite ' + @strWhere
                          + ' Id not in(select top '
                          + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                          + ' Id from Qianbo_SubSite ' + @Filter
                          + ' order by [Id] desc) order by [Id] desc'
        END
      EXECUTE Sp_ExecuteSql
        @SqlStr
      SET @SqlStr = 'select Count(*) from Qianbo_SubSite '
                    + @Filter
      EXECUTE Sp_ExecuteSql
        @SqlStr
  END
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_GetList] @CurrPage INT,
                                                 @PageSize INT
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_SuperLabel] order by SuperId desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_SuperLabel] where SuperId not in(select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' SuperId from [Qianbo_SuperLabel] order by SuperId desc) order by SuperId desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(SuperId) from [Qianbo_SuperLabel]';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_SuperLabel_Out]'
GO
CREATE PROCEDURE [dbo].[Proc_SuperLabel_Out] @InSuperId NVARCHAR(2000)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    SET @SqlStr=N'select * from [Qianbo_SuperLabel] where SuperId in('
                + @InSuperId + ')';
    EXECUTE Sp_ExecuteSql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TagNotice_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_TagNotice_GetList] @CurrPage INT,
                                                @PageSize INT,
                                                @WhereStr NVARCHAR(1000)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_Notice] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by IsPriority desc,NoticeId desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_Notice] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' and NoticeId not in(select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' NoticeId from [Qianbo_Notice] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by IsPriority desc,NoticeId desc) order by IsPriority desc,NoticeId desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(NoticeId) from [Qianbo_Notice] '
                  + @WhereStr;
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTable_Delete]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_TempTable_Delete] @idstr NVARCHAR(2000)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr='delete Qianbo_TempTable where id in('
                + @idstr + ')'
    EXECUTE (@sqlstr)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTable_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_TempTable_GetList] @idstr NVARCHAR(2000)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr='select Id,ChId,ColId,Title,TitleColor,TitleFontType,TitleType,TitleImgPath,UId,UName,UserType,AdminUId,AdminUName,Status,HitCount,AddTime,UpdateTime,TemplatePath,PageType,IsCreated,UserCateId,PointCount,ChargeType,ChargeHourCount,ChargeViewCount,IsOpened,OuterUrl,GroupIdStr,IsDeleted,IsRecommend,IsTop,IsFocus,IsSideShow,TagIdStr,TagNameStr,IsAllowComment,SpecialIdStr,ViewUName,ViewUName2,ExtendContentTable from Qianbo_TempTable where [id] in ('
                + CONVERT(NVARCHAR(2000), @idstr) + ')'
    EXECUTE (@sqlstr)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTable_UpdateSate]'
GO
CREATE PROCEDURE [dbo].[Proc_TempTable_UpdateSate] @idstr NVARCHAR(2000)
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr='update Qianbo_TempTable set IsSend = 1 where id in('
                + @idstr + ')'
    EXECUTE (@sqlstr)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_TempTable_Update]'
GO
CREATE PROCEDURE [dbo].[Proc_TempTable_Update] @ChId  INT,
                                               @ColId INT,
                                               @idstr VARCHAR(2000)
AS
    DECLARE @sqlstr VARCHAR(4000)
    SET @sqlstr='update Qianbo_TempTable set [ChId] ='
                + CONVERT(VARCHAR(15), @ChId) + ',[ColId] = '
                + CONVERT(VARCHAR(15), @ColId)
                + ' where [id] in (' + @idstr + ')'
    EXECUTE (@sqlstr)
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserAlbum_GetByUserId]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROC [dbo].[Proc_UserAlbum_GetByUserId] @UserId      INT,
                                               @PageIndex   INT=1,
                                               @PageSize    INT=10,
                                               @RecordCount INT=0 output
AS
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @PageIndex = 1 )
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' * from Qianbo_UserAlbum where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' order by Id desc'
    ELSE
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' * from Qianbo_UserAlbum where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' and id < (select min(o.id) from(select top '
                   + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                   + ' id from Qianbo_UserAlbum where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' order by Id desc)o) order by Id desc'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr='select Count(Id) from Qianbo_UserAlbum where UserId = '
                + CONVERT(NVARCHAR(15), @UserId)
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserCate_GetByUser]'
GO
CREATE PROC [dbo].[Proc_UserCate_GetByUser] @UserId   INT,
                                            @CateType INT=-1,
                                            @KeyWord  NVARCHAR(500)=''
AS
    DECLARE @WhereStr NVARCHAR(2000)
    SET @Wherestr='';
    IF( @CateType !=- 1 )
      BEGIN
          SET @WhereStr = @WhereStr + 'a.CateType='
                          + CONVERT(NVARCHAR(15), @CateType) + ' and ';
      END
    IF( @KeyWord != '' )
      BEGIN
          SET @WhereStr = @WhereStr + 'a.CateName like ''%' + @KeyWord
                          + '%''' + ' and ';
      END
    SET @WhereStr = @WhereStr + 'a.UserId = '
                    + CONVERT(NVARCHAR(15), @UserId)
    DECLARE @SqlStr NVARCHAR(2000)
    SET @SqlStr='select a.*,b.LogName from Qianbo_UserCate a inner join Qianbo_Users b on a.UserId = b.UserID where '
                + @WhereStr
    EXECUTE sp_executesql
      @SqlStr
    PRINT @sqlstr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserFavorite_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_UserFavorite_GetList] @CurrPage INT,
                                                   @PageSize INT,
                                                   @WhereStr NVARCHAR(100)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_UserFavorite] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by Id desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_UserFavorite] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' and Id not in(select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' Id from [Qianbo_UserFavorite] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by Id desc) order by Id desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(Id) from [Qianbo_UserFavorite] '
                  + @WhereStr;
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroupModel_AddTable]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroupModel_AddTable] @TableName NVARCHAR(50)
AS
    DECLARE @sqlstr NVARCHAR(500)
    SET @sqlstr=N'
CREATE TABLE [dbo].[' + @TableName
                + ']
(
[Id] [int] IDENTITY (1, 1) PRIMARY Key NOT NULL,
[UId] [int] NULL ,
[AddTime] [datetime] NULL,
[UpdateTime] [datetime] NULL)
CREATE  INDEX [IX_' + @TableName
                + '_UId] ON [' + @TableName
                + ']([UId]) ON [PRIMARY]'
    EXEC sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroup_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroup_GetList] @CurrPage INT,
                                                @PageSize INT,
                                                @WhereStr NVARCHAR(100)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_UserGroup] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by UserGroupId desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_UserGroup] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' and UserGroupId not in(select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' UserGroupId from [Qianbo_UserGroup] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by UserGroupId desc) order by UserGroupId desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(UserGroupId) from [Qianbo_UserGroup] '
                  + @WhereStr;
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserGroup_ManageList]'
GO
CREATE PROCEDURE [dbo].[Proc_UserGroup_ManageList] @StrWhere NVARCHAR(1000)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    SET @SqlStr = N'select * from [Qianbo_UserGroup] '
                  + @StrWhere;
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserLog_ListLog]'
GO
CREATE PROCEDURE [dbo].[Proc_UserLog_ListLog] @WhereStr  NVARCHAR(200),
                                              @PageSize  INT=20,
                                              @PageIndex INT=1,
                                              @Total     INT=0 output
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF @PageIndex = 1
      SET @SqlStr='select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' * from Qianbo_UserLog where ' + @WhereStr
    ELSE
      SET @SqlStr='select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' * from Qianbo_UserLog where ' + @WhereStr
                  + ' and [ID] < (select min([ID]) from (select top '
                  + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                  + ' * from Qianbo_UserLog where ' + @WhereStr
                  + ' order by [ID] desc)L) order by [ID] desc'
    PRINT @SqlStr
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr ='select @TRecord = Count([ID]) from Qianbo_UserLog where '
                 + @WhereStr
    DECLARE @Parm NVARCHAR(50)
    SET @Parm = '@TRecord int output';
    EXEC Sp_ExecuteSql
      @SqlStr,
      @Parm,
      @TRecord = @Total output;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserMessage_Delete]'
GO
CREATE PROCEDURE [dbo].[Proc_UserMessage_Delete] @IdStr  NVARCHAR(1000),
                                                 @UserId INT
AS
    DECLARE @sqlstr NVARCHAR(4000)
    SET @sqlstr = 'delete Qianbo_UserMessage where [id] in('
                  + @idstr + ') and userid = @temp_userid'
    DECLARE @param NVARCHAR(400)
    SET @param='@temp_userid int '
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @temp_userid = @userid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserMessage_GetByUserId]'
GO
CREATE PROC [dbo].[Proc_UserMessage_GetByUserId] @UserId      INT,
                                                 @PageIndex   INT=1,
                                                 @PageSize    INT=10,
                                                 @RecordCount INT=0 output
AS
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @PageIndex = 1 )
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' * from Qianbo_UserMessage where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' order by Id desc'
    ELSE
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' * from Qianbo_UserMessage where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' and id < (select min(o.id) from(select top '
                   + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                   + ' id from Qianbo_UserMessage where UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' order by Id desc)o) order by Id desc'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr='select Count(Id) from Qianbo_UserMessage where UserId = '
                + CONVERT(NVARCHAR(15), @UserId)
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserPhoto_Delete]'
GO
CREATE PROC [dbo].[Proc_UserPhoto_Delete] @PhotoIdStr NVARCHAR(1000),
                                          @UserId     INT,
                                          @Count      INT
AS
    DECLARE @SqlStr NVARCHAR(4000)
    SET @SqlStr=N'update Qianbo_UserAlbum set Qianbo_UserAlbum.imgcount = imgcount-'
                + CONVERT(NVARCHAR(15), @Count)
                + ' from Qianbo_UserPhoto inner join Qianbo_UserAlbum on Qianbo_UserAlbum.Id = Qianbo_UserPhoto.AlbumId where Qianbo_UserAlbum.UserId = '
                + CONVERT(NVARCHAR(15), @UserId)
                + ' and photoid in(' + @PhotoIdStr + ')'
    EXECUTE sp_executesql
      @SqlStr
    SET @SqlStr=N'delete Qianbo_UserPhoto where PhotoId in ('
                + @PhotoIdStr + ') and UserId = '
                + CONVERT(NVARCHAR(15), @UserId) + ''
    EXECUTE sp_executesql
      @SqlStr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_UserPhoto_GetById]'
GO
CREATE PROC [dbo].[Proc_UserPhoto_GetById] @AlbumId     INT,
                                           @UserId      INT,
                                           @PageIndex   INT=1,
                                           @PageSize    INT=10,
                                           @RecordCount INT=0 output
AS
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @PageIndex = 1 )
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' p.*,a.AlbumName from Qianbo_UserPhoto as p join Qianbo_UserAlbum as a on p.AlbumId = a.Id where p.UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' and P.Albumid = '
                   + CONVERT(NVARCHAR(15), @AlbumId)
                   + ' order by PhotoId desc'
    ELSE
      SET @sqlstr =N'select top '
                   + CONVERT(NVARCHAR(15), @PageSize)
                   + ' p.*,a.AlbumName from Qianbo_UserPhoto as p join Qianbo_UserAlbum as a on p.AlbumId = a.Id where p.UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' and P.Albumid = '
                   + CONVERT(NVARCHAR(15), @AlbumId)
                   + ' and PhotoId < (select min(o.PhotoId) from(select top '
                   + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                   + ' PhotoId from Qianbo_UserPhoto as p where p.UserId = '
                   + CONVERT(NVARCHAR(15), @UserId)
                   + ' and P.Albumid = '
                   + CONVERT(NVARCHAR(15), @AlbumId)
                   + ' order by PhotoId desc)o) order by PhotoId desc'
    EXECUTE sp_executesql
      @sqlstr
    SET @sqlstr='select Count(Photoid) from Qianbo_UserPhoto where UserId = '
                + CONVERT(NVARCHAR(15), @UserId)
                + ' and AlbumId = '
                + CONVERT(NVARCHAR(15), @AlbumId)
    EXECUTE sp_executesql
      @sqlstr
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_CheckMultiIdentity]'
GO
CREATE PROCEDURE [dbo].[Proc_User_CheckMultiIdentity] @input     NVARCHAR(500),
                                                      @tableName NVARCHAR(100),
                                                      @filedName NVARCHAR(100),
                                                      @output    INT=0 output
AS
    DECLARE @SqlStr NVARCHAR(2000)
    SET @SqlStr ='select @TRecord = Count(*) from '
                 + @tableName + ' where ' + @filedName + '=''' + @input
                 + ''''
    DECLARE @Parm NVARCHAR(50)
    SET @Parm = '@TRecord int output';
    EXEC Sp_ExecuteSql
      @SqlStr,
      @Parm,
      @TRecord = @output output;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_GetUserCount]'
GO
CREATE PROC [dbo].[Proc_User_GetUserCount] @typeid  INT,
                                           @groupid INT
AS
    DECLARE @wherestr NVARCHAR(2000)
    DECLARE @wherestr2 NVARCHAR(10)
    SET @wherestr2 = ' where '
    DECLARE @char NVARCHAR(10)
    SET @char = ''
    SET @wherestr = '';
    DECLARE @sqlstr NVARCHAR(4000)
    IF( @typeid != 0 )
      BEGIN
          SET @wherestr = @wherestr + @wherestr2 + @char
                          + ' [typeid] = @t_typeid '
          SET @char = ' and '
          SET @wherestr2 = '';
      END
    IF( @groupid != 0 )
      BEGIN
          SET @wherestr = @wherestr + @wherestr2 + @char
                          + ' [groupid] = @t_groupid '
      END
    SET @sqlstr = 'select Count([userid]) from [Qianbo_Users] '
                  + @wherestr
    DECLARE @param NVARCHAR(400)
    SET @param = '@t_typeid int,@t_groupid int'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @t_typeid = @typeid,
      @t_groupid = @groupid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_ListGroupMember]'
GO
CREATE PROCEDURE [dbo].[Proc_User_ListGroupMember] @WhereStr  NVARCHAR(2000),
                                                   @PageSize  INT=20,
                                                   @PageIndex INT=0,
                                                   @Total     INT=0 output
AS
    DECLARE @SqlStr NVARCHAR(2000)
    DECLARE @fff NVARCHAR(100)
    IF( @WhereStr = '' )
      BEGIN
          SET @WhereStr=' where '
          SET @fff=''
      END
    ELSE
      BEGIN
          SET @fff=' where ' + @WhereStr
          SET @WhereStr=' where ' + @WhereStr + ' and '
      END
    IF @PageIndex = 1
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' FriendId,[ID],LogName from Qianbo_UserFriend inner join Qianbo_Users on Qianbo_UserFriend.FriendId = Qianbo_Users.UserId'
                  + @fff + ' order by [ID] desc'
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' FriendId,[ID],LogName from Qianbo_UserFriend inner join Qianbo_Users on Qianbo_UserFriend.FriendId = Qianbo_Users.UserId'
                  + @WhereStr
                  + ' ID < (select min(ID) from (select top '
                  + CONVERT(NVARCHAR(10), (@PageIndex - 1) * @PageSize)
                  + ' * from Qianbo_UserFriend ' + @fff
                  + ' order by [ID] desc)F) order by [ID] desc'
    PRINT @SqlStr
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr ='select @Count = Count([ID]) from Qianbo_UserFriend'
                 + @fff
    DECLARE @Parm NVARCHAR(50)
    SET @Parm = '@Count int output';
    EXEC Sp_ExecuteSql
      @SqlStr,
      @Parm,
      @Count = @Total output
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_User_RechargeRecord]'
GO
CREATE PROCEDURE [dbo].[Proc_User_RechargeRecord] @UserId    INT,
                                                  @PageSize  INT=20,
                                                  @PageIndex INT=1,
                                                  @PageCount INT=0 output
AS
    DECLARE @SqlStr NVARCHAR(2000)
    IF( @PageIndex = 1 )
      SET @SqlStr='select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' * from Qianbo_RechargeRecord where [UserId] = '
                  + CONVERT(NVARCHAR(20), @UserId)
                  + ' order by [ID] desc'
    ELSE
      SET @SqlStr='select top '
                  + CONVERT(NVARCHAR(10), @PageSize)
                  + ' * from Qianbo_RechargeRecord where [ID] < (select min([ID]) from (select top '
                  + CONVERT(NVARCHAR(10), (@PageSize * (@PageIndex-1)))
                  + ' * from Qianbo_RechargeRecord where [UserId] = '
                  + CONVERT(NVARCHAR(20), @UserId)
                  + ' order by [ID] desc)R) order by [ID] desc'
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr ='select @Total = Count([ID]) from Qianbo_RechargeRecord where UserId = '
                 + CONVERT(NVARCHAR(20), @UserId)
    DECLARE @Parm NVARCHAR(50)
    SET @Parm = '@Total int output';
    EXEC Sp_ExecuteSql
      @SqlStr,
      @Parm,
      @Total = @PageCount output
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_Users_GetUserList]'
GO
CREATE PROCEDURE [dbo].[Proc_Users_GetUserList] @groupid     INT,
                                                @nologintype INT,
                                                @logname     NVARCHAR(20),
                                                @typeid      INT,
                                                @islock      INT,
                                                @order       NVARCHAR(50),
                                                @pageindex   INT,
                                                @pagesize    INT,
                                                @siteid      INT
AS
    DECLARE @wherestr NVARCHAR(4000)
    SET @wherestr = '';
    IF( @groupid > 0 )
      BEGIN
          SET @wherestr = @wherestr
                          + ' a.[groupid] = @t_groupid and ';
      END
    IF( @nologintype > 0 )
      BEGIN
          DECLARE @nologintime DATETIME
          IF( @nologintype = 1 )
            BEGIN
                SET @nologintime = Dateadd(month, -3, Getdate());
            END
          ELSE IF( @nologintype = 2 )
            BEGIN
                SET @nologintime = Dateadd(month, -6, Getdate())
            END
          ELSE
            BEGIN
                SET @nologintime = Dateadd(month, -12, Getdate())
            END
          SET @wherestr = @wherestr
                          + ' a.[lastlogintime]<@t_nologintime and '
      END
    IF( @logname != '' )
      BEGIN
          SET @wherestr = @wherestr
                          + ' a.[logname] like @t_logname and '
      END
    IF( @islock !=- 1 )
      BEGIN
          SET @wherestr = @wherestr + ' a.[islock] = @t_islock and '
      END
    IF( @siteid != '' )
      BEGIN
          SET @wherestr = @wherestr + ' a.[siteid] = @t_siteid and '
      END
    IF( @typeid > 0 )
      BEGIN
          SET @wherestr = @wherestr + ' a.typeid = @t_typeid '
      END
    ELSE
      BEGIN
          SET @wherestr = @wherestr + ' 1=1 '
      END
    DECLARE @sqlstr NVARCHAR(4000)
    DECLARE @param NVARCHAR(2000)
    SET @param='@t_groupid int,@t_nologintime datetime,@t_logname nvarchar(50),@t_islock bit,@t_typeid int,@t_siteid int'
    IF( @pageindex = 1 )
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + ' * from [Qianbo_Users] a join [Qianbo_UserGroup] b on a.groupid = b.usergroupid where '
                    + @wherestr + ' order by a.[' + @order + '] desc'
    ELSE
      SET @sqlstr = 'select top '
                    + CONVERT(NVARCHAR(15), @pagesize)
                    + ' * from [Qianbo_Users] a join [Qianbo_UserGroup] b on a.groupid = b.usergroupid where '
                    + @wherestr
                    + ' and a.[userid] not in(select top '
                    + CONVERT(NVARCHAR(15), (@pageindex - 1) * @pagesize)
                    + ' a.[userid] from [Qianbo_Users] a join [Qianbo_UserGroup] b on a.groupid = b.usergroupid where '
                    + @wherestr + ' order by a.[' + @order
                    + '] desc) order by a.[' + @order + '] desc'
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @t_groupid = @groupid,
      @t_nologintime = @nologintime,
      @t_logname = @logname,
      @t_islock = @islock,
      @t_typeid = @typeid,
      @t_siteid = @siteid
    SET @sqlstr = 'select Count(a.[userid]) from Qianbo_Users a join [Qianbo_UserGroup] b on a.groupid = b.usergroupid where '
                  + @wherestr
    EXECUTE sp_executesql
      @sqlstr,
      @param,
      @t_groupid = @groupid,
      @t_nologintime = @nologintime,
      @t_logname = @logname,
      @t_islock = @islock,
      @t_typeid = @typeid,
      @t_siteid = @siteid
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_WebMessage_GetList]'
GO
CREATE PROCEDURE [dbo].[Proc_WebMessage_GetList] @CurrPage INT,
                                                 @PageSize INT,
                                                 @WhereStr NVARCHAR(100)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @CurrPage = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_WebMessage] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by WMId desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_WebMessage] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' and WMId not in(select top '
                  + CONVERT(NVARCHAR(15), (@CurrPage - 1) * @PageSize)
                  + ' WMId from [Qianbo_WebMessage] '
                  + CONVERT(NVARCHAR(100), @WhereStr)
                  + ' order by WMId desc) order by WMId desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(WMId) from [Qianbo_WebMessage] '
                  + @WhereStr;
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[Proc_WorkFlow_GetList]'
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[Proc_WorkFlow_GetList] @PageIndex INT,
                                               @PageSize  INT,
                                               @strWhere  NVARCHAR(1000)
AS
    DECLARE @SqlStr NVARCHAR(2000);
    IF( @PageIndex = 1 )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_WorkFlow] '
                  + CONVERT(NVARCHAR(100), @strWhere)
                  + ' order by Id desc';
    ELSE IF( @strWhere = '' )
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_WorkFlow] where Id not in(select top '
                  + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                  + ' Id from [Qianbo_WorkFlow] '
                  + CONVERT(NVARCHAR(1000), @strWhere)
                  + ' order by Id desc) order by Id desc';
    ELSE
      SET @SqlStr=N'select top '
                  + CONVERT(NVARCHAR(15), @PageSize)
                  + ' * from [Qianbo_WorkFlow] '
                  + CONVERT(NVARCHAR(100), @strWhere)
                  + ' and Id not in(select top '
                  + CONVERT(NVARCHAR(15), (@PageIndex - 1) * @PageSize)
                  + ' Id from [Qianbo_WorkFlow] '
                  + CONVERT(NVARCHAR(1000), @strWhere)
                  + ' order by Id desc) order by Id desc';
    EXECUTE Sp_ExecuteSql
      @SqlStr
    SET @SqlStr = N'select Count(Id) from [Qianbo_WorkFlow] '
                  + @strWhere;
    EXECUTE Sp_ExecuteSql
      @SqlStr
    RETURN
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
SET ANSI_NULLS ON
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
COMMIT TRANSACTION
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @Success AS BIT
SET @Success = 1
SET NOEXEC OFF
IF (@Success = 1) PRINT 'The database update succeeded'
ELSE BEGIN
	IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
	PRINT 'The database update failed'
END
GO
