コード例 #1
0
    /// <summary>
    /// Adds the New post to the Database
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void PostClick(object sender, EventArgs e)
    {
        bool GroupExist = false;
        int  GroupID    = 0;

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ToString()))
        {
            conn.Open();
            string     sql = "select ReplyGroupID FROM FORUM_POST where PostID=@PostID";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.Add(new SqlParameter("@PostID", Request.QueryString["PostID"]));
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (dr["ReplyGroupID"] != System.DBNull.Value)
                {
                    GroupExist = true;
                    GroupID    = (int)dr["ReplyGroupID"];
                }
                else
                {
                    GroupExist = false;
                }
            }
            dr.Close();


            if (GroupExist == false)
            {
                sql     = "insert into FORUM_GROUP (DateCreated) Output inserted.GroupID Values (GETDATE())";
                cmd     = new SqlCommand(sql, conn);
                GroupID = (int)cmd.ExecuteScalar();

                sql = "update FORUM_POST set ReplyGroupID=@ReplyGroup where PostID=@PostID";
                cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add(new SqlParameter("@ReplyGroup", GroupID));
                cmd.Parameters.Add(new SqlParameter("@PostID", Request.QueryString["PostID"]));
                cmd.ExecuteNonQuery();
            }
            TextBox txt = (TextBox)CommentContent.FindControl("CommentBox");


            sql = "insert into FORUM_GROUP_ITEM (GroupID, ReplyText, UserID, DatePosted) Values (@GroupID, @ReplyText, @UserID, GetDate())";
            cmd = new SqlCommand(sql, conn);
            cmd.Parameters.Add(new SqlParameter("@GroupID", GroupID));
            cmd.Parameters.Add(new SqlParameter("@ReplyText", txt.Text));
            cmd.Parameters.Add(new SqlParameter("@UserID", Session["UserID"]));
            cmd.ExecuteNonQuery();

            txt.Text = "";
            FillComments();
        }
    }
コード例 #2
0
 public void CheckAuth()
 {
     if (Session["Auth"] != null)
     {
         if ((bool)Session["Auth"] == true)
         {
             Button btn = (Button)CommentContent.FindControl("Postbtn");
             btn.Enabled = true;
             TextBox txt = (TextBox)CommentContent.FindControl("CommentBox");
             txt.Enabled = true;
         }
         else
         {
             Button btn = (Button)CommentContent.FindControl("Postbtn");
             btn.Enabled = false;
             TextBox txt = (TextBox)CommentContent.FindControl("CommentBox");
             txt.Enabled = false;
         }
     }
 }