AddPost /**////<summary> /// Adds a new Post. This method checks the allowDuplicatePosts settings to determine whether /// or not to allow for duplicate posts. If allowDuplicatePosts is set to false and the user /// attempts to enter a duplicate post, a PostDuplicateException exception is thrown. ///</summary> ///<param name="PostToAdd">A Post object containing the information needed to add a new /// post. The essential fields of the Post class that must be set are: the Subject, the /// Body, the Username, and a ForumID or a ParentID (depending on whether the post to add is /// a new post or a reply to an existing post, respectively).</param> ///<returns>A Post object with information on the newly inserted post. This returned Post /// object includes the ID of the newly added Post (PostID) as well as if the Post is /// Approved or not.</returns> publicoverride ForumPost AddPost (ForumPost post, int userID, bool autoApprove) { int postID =-1; // Create Instance of Connection and Command Object // using( SqlConnection myConnection = GetSqlConnection() ) { SqlCommand myCommand =new SqlCommand(databaseOwner +".cs_Post_CreateUpdate", myConnection); myCommand.CommandType = CommandType.StoredProcedure; // Add parameters // myCommand.Parameters.Add(this.SettingsIDParameter()); myCommand.Parameters.Add("@SectionID", SqlDbType.Int).Value = post.SectionID; //3 //论坛板块 myCommand.Parameters.Add("@ParentID", SqlDbType.Int).Value = post.ParentID; //0 // myCommand.Parameters.Add("@AllowDuplicatePosts", SqlDbType.Bit).Value = sqlHelper.GetSiteSettings().EnableDuplicatePosts; //false myCommand.Parameters.Add("@DuplicateIntervalInMinutes", SqlDbType.Int).Value = sqlHelper.GetSiteSettings().DuplicatePostIntervalInMinutes; //15 myCommand.Parameters.Add("@Subject", SqlDbType.NVarChar, 256).Value = post.Subject; //论坛跟踪,发表新贴 myCommand.Parameters.Add("@IsLocked", SqlDbType.Bit).Value = post.IsLocked; //false myCommand.Parameters.Add("@IsTracked", SqlDbType.Bit).Value = post.IsTracked; //false myCommand.Parameters.Add("@PostType", SqlDbType.Int).Value = post.PostType; //HTML myCommand.Parameters.Add("@EmoticonID", SqlDbType.Int).Value = post.EmoticonID; //0 myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = userID; //2105 myCommand.Parameters.Add("@Body", SqlDbType.NText).Value = post.Body; //test myCommand.Parameters.Add("@FormattedBody", SqlDbType.NText).Value = post.FormattedBody; //test myCommand.Parameters.Add("@UserHostAddress", SqlDbType.NVarChar, 32).Value = post.UserHostAddress; //127.0.0.1 myCommand.Parameters.Add("@PostID", SqlDbType.Int).Direction = ParameterDirection.Output; ////output参数 if( userID ==0 ) { myCommand.Parameters.Add("@PostAuthor", SqlDbType.NVarChar, 128).Value = post.Username; } if (post is Thread) { myCommand.Parameters.Add("@IsSticky", SqlDbType.Bit).Value = ((Thread) post).IsSticky; //false myCommand.Parameters.Add("@StickyDate", SqlDbType.DateTime).Value = ((Thread) post).StickyDate; //10/18/1980 } SerializerData data = post.GetSerializerData(); myCommand.Parameters.Add("@PropertyNames", SqlDbType.NText).Value = data.Keys; //null myCommand.Parameters.Add("@PropertyValues", SqlDbType.NText).Value = data.Values; //null // If autoApprove is true, mark it as approved if(autoApprove) myCommand.Parameters.Add("@IsApproved", SqlDbType.Bit).Value =true; myCommand.Parameters.Add("@PostConfiguration", SqlDbType.Int).Value = post.PostConfiguration; //0 myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); // LN 5/27/04: try/catch added to get rid of exceptions try { postID = (int) myCommand.Parameters["@PostID"].Value; } catch{} if (postID ==-1) { thrownew CSException(CSExceptionType.PostDuplicate); } // Return the newly inserted Post // return GetPost(postID, userID, false); } }