ÏÂÃæÊÇÉÏÆªÎÄÕÂËù˵µÄ´æ´¢¹ý³Ì£¬Æä×÷ÓÃÒѾ˵¹ý£¬ÔÚÕâÀï¾Í²»ÔÙ׸ÊöÁË¡£Çë´ó¼Ò×Ô¼º¿´´úÂë°É¡£Õâ¸ö´æ´¢¹ý³ÌÖ»ÊÇ´æ´¢Êý¾ÝµÄ¹ý³Ì£¬ÒÔºóÈç¹ûÓÐʱ¼äÎÒ½«½²Ò»Ï¶ÁÈ¡Êý¾Ý¡£
/**********************************************************************/
/* */
/* Stored Procudure : up_PostTopic */
/* */
/* Description: Ìù×Ó´æ´¢¼°»Ø¸´Email */
/* */
/* Author: Bigeagle */
/* */
/* date: 2000/7/25 Á賿 */
/* */
/* History: version 1.0 by BigEagle , 2000/7/25 */
/* */
/**********************************************************************/
if exists (select * from sysobjects where id = object_id("up_PostTopic"))
drop proc up_PostTopic
go
create proc up_PostTopic @a_intID int OUTPUT ,
@a_intFatherID int , @a_intForumID int , @a_intUserID int ,
@a_strTitle varchar(255) , @a_strContent text , @a_intFaceID tinyint ,
@a_bIfEmail bit , @a_bIfSignature bit
as
declare @m_intTopicID int
declare @m_intLayer tinyint
declare @m_intRootID int
declare @m_fOrderNum float
select @m_fOrderNum = power(2 , 30) --³õʼ»¯ÅÅÐò»ùÊý
/*Ê×ÏÈÅжÏÊÇ·ñÓÐÕâ¸öÂÛ̳£¬Ã»ÓÐÔòÍ˳ö*/
if not exists (select * from BBSCategory where CategoryID = @a_intForumID)
begin
select @a_intID = 0
return(0)
end
/*ÅжÏÊÇз¢Ìù×Ó»¹ÊÇ»ØÓ¦Ö÷Ìâ*/
if @a_intFatherID = 0 --ûÓи¸Ìù×Ó£¬ËµÃ÷ÊÇз¢Ìù×Ó
select @m_intLayer = 1 , @m_intRootID = 0
else
begin
if not exists(select * from BBS where ID = @a_intFatherID) --Èç¹ûû·¢ÏÖ¸¸Ìù×Ó
begin
select 'TopicID' = 0
return (0)
end
else --Èç¹û·¢ÏÖ¸¸Ìù×Ó£¬ÔòÈ¡³ö²ãÊýºÍ¸ùID
select @m_intLayer = Layer + 1 ,@m_intRootID = RootID ,@m_fOrderNum = OrderNum
from BBS where ID = @a_intFatherID
end
/*¸üÐÂ±í£¬ÒòΪҪ¶Ô¶à¸ö±í²Ù×÷£¬ËùÒԷŵ½ÊÂÎñÀï*/
begin transaction
/*²åÈë±íBBS*/
insert into BBS (FatherID , Layer , ForumID , UserID , Title ,
Content , PostTime , FaceID , Hits , selected ,
closed , IfEmail , IfSignature , OrderNum)
values(@a_intFatherID , @m_intLayer , @a_intForumID , @a_intUserID , @a_strTitle ,
@a_strContent , getdate() , @a_intFaceID , 0 , 0 ,
0 , @a_bIfEmail , @a_bIfSignature , default)
if (@@error 0) goto On_Error --Èç¹û³ö´íתÏò´íÎó´¦Àí²¿·Ö
select @m_intTopicID = @@identity --È¡³ö¸Õ¸Õ²åÈë¼Í¼µÄID
/*Èç¹ûÊÇз¢Ìù×ÓÔòÈ¡IDΪRootID*/
if @m_intRootID = 0 --з¢Ìù×Ó
begin
select @m_intRootID = @m_intTopicID
end
else --²»ÊÇз¢Ìù×ÓÔò¸üиù¼Í¼µÄTotalCounts
begin
update BBS set TotalChilds = TotalChilds + 1 --¸üиùµÄ×ÓÌùÊý
where ID = @m_intRootID
if (@@error 0) goto On_Error --Èç¹û¸üÐÂʧ°ÜÔòתÏò´íÎó´¦Àí²¿·Ö
end
select @m_fOrderNum = @m_fOrderNum + power(2,30)/power(2,TotalChilds)
from BBS where ID = @m_intRootID
select @m_fOrderNum
/*¸üÐÂRootID , OrderNum*/
update BBS set OrderNum = @m_fOrderNum , RootID = @m_intRootID
where ID = @m_intTopicID
if (@@error 0) goto On_Error --Èç¹û¸üÐÂʧ°ÜÔòתÏò´íÎó´¦Àí²¿·Ö
/*¸üÐÂBBSCategory±í*/
update BBSCategory set TopicCounts = TopicCounts + 1 , LastReplyTime = getDate()
where CategoryID = @a_intForumID
if (@@error 0) goto On_Error --Èç¹û¸üÐÂʧ°ÜÔòתÏò´íÎó´¦Àí²¿·Ö
/*¸üÐÂBBSUser±í£¬½«Óû§·ÖÊý¼ÓÒ»*/
update BBSUser set Point = Point + 1
where ID = @a_intUserID
/*Èç¹ûÈ«²¿³É¹¦ÔòÍê³ÉÊÂÎñ*/
commit transaction
/*Èç¹ûÒªÇ󻨏´Ôò·¢Óʼþ*/
declare @m_strEmail varchar(100) , @m_bIfEmail bit
declare @m_strName varchar(20) , @m_strSubject varchar(50)
declare @m_strMessage varchar(255)
select @m_bIfEmail = a.IfEmail , @m_strEmail = IsNull(b.Email , ""),
@m_strName = b.UserName
from BBS as a
left join BBSUser as b on a.UserID = b.ID
where a.ID = @a_intFatherID
select @m_strSubject = "À´×ÔeMatter Board : ÄúÓлظ´"
select @m_strMessage = "Äú·¢±íÔÚeMatter BoardµÄÌù×ÓÏÖÔÚÓÐÈ˻ظ´£º"
+ " http://server1/bbs/showtopic.ASP?ID="
+ convert(varchar,@a_intFatherID)
if @m_StrEmail "" and @m_bIfEmail = 1
exec master..xp_sendmail @recipients = @m_strEmail , @subject = @m_strSubject,
@message = @m_strMessage
select @a_intID = @m_intTopicID --·µ»ØÌù×ÓID
return (0)
On_error: --´íÎó´¦Àí²¿·Ö
rollback transaction
select @a_intID = 0 --Ìù×ÓID·µ»Ø0£¬´ú±íʧ°Ü
return (-1)
go

