SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InsertSiteBasicProperty]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[InsertSiteBasicProperty]
GO




CREATE PROCEDURE [dbo].[InsertSiteBasicProperty]
(
	@pkId int,
	@grade int,
	@defaultPassed int,
	@review int,
	@showIp int,
	@reviewCheck int,
	@reviewFiltrate varchar(100),
	@reviewAlternation int,
	@showClick int,
	@navGate int,
	@shareNewsUrl  varchar(100),
	@shareNewsLayoutTemplateID int,
	@newsOpenMode int,
	@IsAllowContribute int,
	@IsAllowCopy int
)
AS
	SET NOCOUNT OFF;
INSERT INTO siteBasicProperty(pkId, grade, defaultPassed, review, showIp, reviewCheck, reviewFiltrate, reviewAlternation, showClick, navGate,shareNewsUrl,shareNewsLayoutTemplateID,newsOpenMode, IsAllowContribute,IsAllowCopy) VALUES (@pkId, @grade, @defaultPassed, @review, @showIp, @reviewCheck, @reviewFiltrate, @reviewAlternation, @showClick, @navGate,@shareNewsUrl,@shareNewsLayoutTemplateID,@newsOpenMode, @IsAllowContribute,@IsAllowCopy)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UpdateSiteBasicProperty]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[UpdateSiteBasicProperty]
GO



CREATE PROCEDURE [dbo].[UpdateSiteBasicProperty] 
(
	@pkId int,
	@grade int,
	@defaultPassed int,
	@review int,
	@showIp int,
	@reviewCheck int,
	@reviewFiltrate varchar(100),
	@reviewAlternation int,
	@showClick int,
	@navGate int,
	@navPage varchar(100),
	@pagesize int,
	@shareNewsUrl  varchar(100),
	@shareNewsLayoutTemplateID int,
	@outputCacheTime int,
	@newsOpenMode int,
	@IsAllowContribute int,
	@IsAllowCopy int
)
AS
	SET NOCOUNT OFF;
UPDATE siteBasicProperty SET IsAllowCopy = @IsAllowCopy, IsAllowContribute = @IsAllowContribute , newsOpenMode=@newsOpenMode,outputCacheTime=@outputCacheTime,shareNewsLayoutTemplateID=@shareNewsLayoutTemplateID,shareNewsUrl=@shareNewsUrl,pagesize=@pagesize,navPage=@navPage,grade = @grade, defaultPassed = @defaultPassed, review = @review, showIp = @showIp, reviewCheck = @reviewCheck, reviewFiltrate = @reviewFiltrate, reviewAlternation = @reviewAlternation, showClick = @showClick, navGate = @navGate



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetPrivilege]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetPrivilege]
GO



create PROCEDURE [dbo].[GetPrivilege]
AS
	SET NOCOUNT ON
	select *
	  from privilege
	 	 order by pkid asc
	RETURN



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InsertNews]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[InsertNews]
GO




CREATE PROCEDURE [dbo].[InsertNews]
(
	@specialId int,
	@gradeId int,
	@gate int,
	@departmentId int,
	@listTitle varchar(1000),
	@intactTitle varchar(500),
	@subheading varchar(500),
	@isRecommand int,
	@isTop int,
	@useListTitle int,
	@showReviewLink int,
	@Author varchar(100),
	@AuthorMail varchar(100),
	@CopyFrom varchar(100),
	@copyFromLink varchar(100),
	@about varchar(100),
	@pageType int,
	@autoPageCharNum int,
	@readPoint int,
	@itemType int,
	@content text,
	@descript varchar(1000),
	@usersId int,
	@editor varchar(100),
	@click int,
	@updateTime datetime,
	@passed int,
	@isReview int,
	@isImageNews int,
	@imageName varchar(100),
	@MenuId int,
	@bigClassId int,
	@width int,
	@height int,
	@pkId int output,
	@updateIp varchar(100),
	@useSubHeading int,
	@isDuplicated int=0,
	@duplicateFrom varchar(100),
	@duplicatedPkId int,
	@validDays int
)
AS
	SET NOCOUNT OFF;	 BEGIN TRANSACTION
IF (@validDays is null)
	set @validDays = -1	
IF (@isDuplicated is null)
	set @isDuplicated = 0
IF (@duplicatedPkId is null)
	set @duplicatedPkId = 0
INSERT INTO news(specialId, gradeId, gate, departmentId, listTitle, intactTitle, subheading, isRecommand, isTop, useListTitle, showReviewLink, Author, AuthorMail, CopyFrom, copyFromLink, about, pageType, autoPageCharNum, readPoint, itemType, content, descript, usersId, editor, click, updateTime, passed, isReview, isImageNews, imageName, MenuId, bigClassId, width, height,updateIp,useSubHeading, isDuplicated, duplicateFrom, duplicatedPkId, validDays) VALUES (@specialId, @gradeId, @gate, @departmentId, @listTitle, @intactTitle, @subheading, @isRecommand, @isTop, @useListTitle, @showReviewLink, @Author, @AuthorMail, @CopyFrom, @copyFromLink, @about, @pageType, @autoPageCharNum, @readPoint, @itemType, @content, @descript, @usersId, @editor, @click, @updateTime, @passed, @isReview, @isImageNews, @imageName, @MenuId, @bigClassId, @width, @height,@updateIp,@useSubHeading, @isDuplicated, @duplicateFrom, @duplicatedPkId, @validDays)
SET @pkId = @@IDENTITY
  COMMIT TRANSACTION


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UpdateNews]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[UpdateNews]
GO




CREATE PROCEDURE [dbo].[UpdateNews]
(
	@specialId int,
	@gradeId int,
	@gate int,
	@departmentId int,
	@listTitle varchar(1000),
	@intactTitle varchar(500),
	@subheading varchar(500),
	@isRecommand int,
	@isTop int,
	@useListTitle int,
	@showReviewLink int,
	@Author varchar(100),
	@AuthorMail varchar(100),
	@CopyFrom varchar(100),
	@copyFromLink varchar(100),
	@about varchar(100),
	@pageType int,
	@autoPageCharNum int,
	@readPoint int,
	@itemType int,
	@content text,
	@descript varchar(1000),
	@usersId int,
	@editor varchar(100),
	@click int,
	@updateTime datetime,
	@passed int,
	@isReview int,
	@isImageNews int,
	@imageName varchar(100),
	@MenuId int,
	@bigClassId int,
	@width int,
	@height int,
	@pkId int,
	@updateIp  varchar(100),
	@useSubHeading int,
	@isDuplicated int=0,
	@duplicateFrom varchar(100),
	@duplicatedPkId	int,
	@validDays int
)
AS
	SET NOCOUNT OFF;
IF (@validDays is null)
	set @validDays = -1	
UPDATE news SET useSubHeading=@useSubHeading,updateIp=@updateIp,specialId = @specialId, gradeId = @gradeId, gate = @gate, departmentId = @departmentId, listTitle = @listTitle, intactTitle = @intactTitle, subheading = @subheading, isRecommand = @isRecommand, isTop = @isTop, useListTitle = @useListTitle, showReviewLink = @showReviewLink, Author = @Author, AuthorMail = @AuthorMail, CopyFrom = @CopyFrom, copyFromLink = @copyFromLink, about = @about, pageType = @pageType, autoPageCharNum = @autoPageCharNum, readPoint = @readPoint, itemType = @itemType, content = @content, descript = @descript, usersId = @usersId, editor = @editor, click = @click, updateTime = @updateTime, passed = @passed, isReview = @isReview, isImageNews = @isImageNews, imageName = @imageName, MenuId = @MenuId, bigClassId = @bigClassId, width = @width, height = @height, isDuplicated = @isDuplicated, duplicateFrom = @duplicateFrom, duplicatedPkId = @duplicatedPkId, validDays = @validDays WHERE (pkId = @pkId)
UPDATE news SET passed = @passed WHERE duplicatedPkId=@pkId AND duplicateFrom='news'			-- 更新news时，同时更新news抄送的信息
UPDATE board SET passed = @passed WHERE duplicatedPkId=@pkId AND duplicateFrom = 'news'		-- 更新news时，同时更新board抄送的信息



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InsertBoard]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[InsertBoard]
GO




CREATE PROCEDURE [dbo].[InsertBoard]
(
	@pkId int output,
	@name varchar(500),
	@boardContent ntext,
	@IsTop int,
	@showDay int,
	@gate int,
	@gradeId int,
	@userId int,
	@updateIp varchar(100),
	@updateTime datetime,
	@passed int,
	@ordering int,
	@bigClassId int,
	@isDuplicated int=0,
	@duplicateFrom varchar(100),
	@duplicatedPkId int
)
AS
	SET NOCOUNT OFF;
	 BEGIN TRANSACTION
INSERT INTO board(name,ordering,bigClassId,boardContent, IsTop, showDay, gate, gradeId, userId, updateIp, updateTime, passed, isDuplicated, duplicateFrom, duplicatedPkId) VALUES (@name,@ordering,@bigClassId,@boardContent, @IsTop, @showDay, @gate, @gradeId, @userId, @updateIp, @updateTime, @passed, @isDuplicated, @duplicateFrom, @duplicatedPkId)
SET @pkId = @@IDENTITY
  COMMIT TRANSACTION




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UpdateBoard]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[UpdateBoard]
GO



CREATE PROCEDURE [dbo].[UpdateBoard]
(
	@boardContent ntext,
	@IsTop int,
	@showDay int,
	@gate int,
	@gradeId int,
	@userId int,
	@updateIp varchar(100),
	@updateTime datetime,
	@passed int,
	@pkId int,
	@name varchar(500),
	@bigClassId int,
	@ordering int,
	@isDuplicated int=0,
	@duplicateFrom varchar(100),
	@duplicatedPkId int
)
AS
	SET NOCOUNT OFF;
UPDATE board SET bigClassId=@bigClassId,name=@name,ordering=@ordering,boardContent = @boardContent, IsTop = @IsTop, showDay = @showDay, gate = @gate, gradeId = @gradeId, userId = @userId, updateIp = @updateIp, updateTime = @updateTime, passed = @passed, isDuplicated = @isDuplicated, duplicateFrom = @duplicateFrom, duplicatedPkId = @duplicatedPkId WHERE (pkId = @pkId)
UPDATE board SET passed = @passed WHERE duplicatedPkId = @pkId AND duplicateFrom = 'board'	-- 更新board时，同时更新抄送的信息



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetAdmin]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetAdmin]
GO




CREATE PROCEDURE [dbo].[GetAdmin]
AS
	SET NOCOUNT ON;
SELECT * FROM Admin




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetIsFlippy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetIsFlippy]
GO

CREATE PROCEDURE [dbo].[GetIsFlippy]
(@bigClassId int)
AS
	SET NOCOUNT ON;
SELECT * FROM bigClass
where pkId = @bigClassId and templateId = 25
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

