Exemplo n.º 1
0
    public void Add_Comment(Object s, EventArgs e)
    {
        if (Authentication.IsUserAuthenticated)
        {
            if (Page.IsValid && (txtsecfield.Text.ToString() == Session["randomStr"].ToString()))
            {
                ArticleCommentsRepository comment = new ArticleCommentsRepository();

                comment.ID = (int)Util.Val(Request.QueryString["aid"]);
                comment.UID = UserIdentity.UserID;

                comment.Author = Util.FormatTextForInput(Request.Form[AUTHOR.UniqueID]);
                comment.Email = Util.FormatTextForInput(Request.Form[EMAIL.UniqueID]);
                comment.Comments = Util.FormatTextForInput(Request.Form[COMMENTS.UniqueID]);

                if (comment.Comments.Length == 0)
                {
                    lbvalenght.Text = "<br>Lỗi: Thảo luận không có sản phẩm nào, xin vui lòng nhập bình luận của bạn.";
                    lbvalenght.Visible = true;
                    txtsecfield.Text = "";
                    return;
                }
                if (comment.Comments.Length > 350)
                {
                    lbvalenght.Text = "<br>Lỗi: Bình luận là quá dài. Tối đa là 350 ký tự.";
                    lbvalenght.Visible = true;
                    txtsecfield.Text = "";
                    return;
                }

                if (comment.Add(comment) != 0)
                {
                    lbvalenght.Text = "Một lỗi cơ sở dữ liệu đã xảy ra khi xử lý luận của bạn.";
                    return;
                }

                EmailCommentNotificationToAdministrator(comment.ID, strArtTitle);

                comment = null;

                Response.Redirect("commentpostconfirmation.aspx?ReturnURL=" + this.Request.Url.PathAndQuery);
            }
            else
            {
                lbvalenght.Text = "<br>Không hợp lệ mã bảo mật. Hãy chắc chắn rằng bạn nhập chính xác.";
                lbvalenght.Visible = true;
                txtsecfield.Text = "";

                lblinvalidsecode.Text = "Không hợp lệ mã bảo mật. Hãy chắc chắn rằng bạn nhập chính xác.";
                lblinvalidsecode.Visible = true;
            }
        }
    }
    //Handle the delete button click event
    public void ArticleComments_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if ((e.CommandName == "DeleteComment"))
        {
            //Passing multiple command argument separated by comma so we can split it.
            string[] commandArgsDelete = e.CommandArgument.ToString().Split(new char[] { ',' });
            int COMID = int.Parse(commandArgsDelete[0].ToString()); // Get the Comment ID
            int RecID = int.Parse(commandArgsDelete[1].ToString()); // Get the Lyric ID

            ArticleCommentsRepository comment = new ArticleCommentsRepository();

            comment.ID = COMID;
            comment.RECID = RecID;

            comment.Delete(comment);

            comment = null;

            Response.Redirect("articlecommentconfirmation.aspx?mode=del&id=" + COMID);
        }

        if ((e.CommandName == "EditComment"))
        {
            //Passing multiple command argument separated by comma so we can split it.
            string[] commandArgsEdit = e.CommandArgument.ToString().Split(new char[] { ',' });
            int CID = int.Parse(commandArgsEdit[0].ToString()); // Get the Comment ID
            string strComment = commandArgsEdit[1].ToString(); // Get the Comment

            Panel1.Visible = true;

            KeyIDs.Value = CID.ToString();
            Comments.Text = strComment;
            lblheaderform.Text = "Updating Comment #:&nbsp;" + CID;

        }
        else
        {
            Panel1.Visible = false;
        }
    }
    //Handles update comment
    public void Update_Comments(Object s, EventArgs e)
    {
        ArticleCommentsRepository comment = new ArticleCommentsRepository();

        comment.ID = int.Parse(Request.Form["KeyIDs"]);
        comment.Comments = Request.Form["Comments"];

        if (comment.Update(comment) != 0)
        {
            JSLiteral.Text = "Error occured while processing your submit.";
            return;
        }

        comment = null;

        Response.Redirect("articlecommentconfirmation.aspx?mode=update&id=" + Request.Form["KeyIDs"]);
    }
    public void DeleteAllSelectedItems_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;

        for (int i = 0; i < ArticleComments.Rows.Count; i++)
        {
            CheckBox chkID = ArticleComments.Rows[i].FindControl("chkDelete") as CheckBox;

            if (chkID.Checked)
            {
                int ComID = int.Parse(ArticleComments.Rows[i].Cells[3].Text.ToString());
                int RecID = int.Parse(ArticleComments.Rows[i].Cells[4].Text.ToString());

                ArticleCommentsRepository comment = new ArticleCommentsRepository();

                comment.ID = ComID;
                comment.RECID = RecID;

                comment.Delete(comment);
            }
        }

        Response.Redirect("articlecommentconfirmation.aspx?mode=DeleteAll");
    }