点评删除和编辑

ALTER PROC [dbo].[PTS_DeleteOrUpdateWorkRemark]
@ID int,
@UserName nvarchar(50),
@CommondType int,
@RemarkScore float,
@Remark text
AS
BEGIN
    DECLARE @ReportOwn nvarchar(50),@Reviewer nvarchar(50),@TempCount int,@UpLeader1 nvarchar(50),@UpLeader2 nvarchar(50)
    SET @TempCount=0;
    SELECT @ReportOwn=UserName FROM PTS_WorkRemark INNER JOIN PTS_WorkReport ON PTS_WorkRemark.ReportID=PTS_WorkReport.ID
    WHERE PTS_WorkRemark.ID=@ID;
    SELECT @Reviewer=Reviewer FROM PTS_WorkRemark WHERE ID=@ID;
    BEGIN
        IF @Reviewer<>@UserName
            SELECT 11;    --不是自己的点评,不能操作
        ELSE IF @ReportOwn=@UserName
            SELECT 1;    --自评不能操作
        ELSE
            BEGIN
                SELECT @UpLeader1=Name from person where Name in(select superior FROM subgroup WHERE junior=@UserName
                and treelevel=1) and Coding in (1,2);
                SELECT @UpLeader2=Name from person where Name in(select superior FROM subgroup WHERE junior=@UpLeader1
                and treelevel=1) and Coding in (1,2);
                SELECT @TempCount=Count(1) FROM PTS_WorkRemark WHERE Reviewer IN(ISNULL(@UpLeader1,'NULL'),ISNULL(@UpLeader2,'NULL'))
                and ReportID=(SELECT ReportID FROM PTS_WorkRemark WHERE ID=@ID)
                IF @TempCount>0
                    BEGIN
                        SELECT 2;        ---上级领导已评,不能操作
                    END
                ELSE
                    BEGIN
                        IF @CommondType=0
                            BEGIN
                                DELETE FROM PTS_WorkRemark WHERE ID=@ID
                                IF @@ERROR<>0
                                    SELECT 3;  --删除失败
                                ELSE
                                    SELECT 4;  --删除成功
                            END
                        ELSE IF @CommondType=1
                            BEGIN
                                IF @RemarkScore=-1
                                    SELECT 5;    --可以编辑
                                ELSE
                                    BEGIN
                                        UPDATE PTS_WorkRemark SET RemarkScore=@RemarkScore,Remark=@Remark WHERE ID=@ID
                                        IF @@ERROR<>0
                                            SELECT 6   --编辑失败
                                        ELSE
                                            SELECT 7   --编辑成功
                                    END
                            END
                    END
            END
    END
END

 

posted @ 2014-03-06 12:29  kedarui  阅读(149)  评论(0编辑  收藏  举报