添加新闻及判断验证码的问题

#region 添加评论
           /// <summary>
      /// 添加评论
      /// </summary>
      /// <param name="c"></param>
      /// <returns></returns>
      public bool Insert(CommentModel c)
      {
          bool flag = false;
          string sql = "insert into comment(content,userip,newsid) values(@content,@userip,@newsid)";
          SqlParameter[] para = new SqlParameter[] {
          new SqlParameter("@content",c.Content),
          new SqlParameter("@userip",c.Userip),
          new SqlParameter("@newsid",c.Newsid)
          };
          int ins = sqlhelper.ExecuteNonQuery(sql,para,CommandType.Text);
          if (ins>0)
          {
              flag = true;
          }
          return flag;
      }
      #endregion

 

 

      <asp:TextBox ID="txtCode" runat="server" CssClass="txtcode" ValidationGroup="ccc" ></asp:TextBox>
            <asp:RequiredFieldValidator ValidationGroup="ccc" ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCode" ErrorMessage="请输入验证码" Text="*"></asp:RequiredFieldValidator>
             <asp:Button ID="Btnsub" runat="server" Text="确定" Width="59px"
                οnclick="Btnsub_Click" ValidationGroup="ccc"  />
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="ccc" />

 

 

 

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string newsid = Request.QueryString["newsid"];
            NewsBLL nb = new NewsBLL();
            newsModel nm = new NewsBLL().SelectNew(newsid);
            Lbltitle.Text = nm.Title;
            Lblcontent.Text = nm.Content;
            Lblcreatetime.Text = nm.Createtime;
            //绑定评论
           DataTable dt=new CommentBLL().SelectComment(newsid);
        if (dt.Rows.Count ==0)
        {
            //无新闻就显示
            empdata.Visible = true;
        }
        else {
            //有新闻就不显示
            empdata.Visible = false;
         repComment.DataSource = dt;
        repComment.DataBind();
        }
        }
    }

 

 

 

 

 

  //添加按钮;
    protected void Btnsub_Click(object sender, EventArgs e)
    {
        //判断验证码是否正确;
        string txtcode = txtCode.Text.Trim().ToString().ToUpper(); //转成大写;
        string right = Session["Code"].ToString();
        if (txtcode != right)
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('验证码输入错误!');</script>");
            return;
        }
        //添加进数据库
        string content = txtcomment.Text.Trim();
        string userip = Request.ServerVariables["REMOTE_ADDR"];  //获取客户端的ip;
        string newsid = Request.QueryString["newsid"];
        CommentModel cm = new CommentModel(content,userip,newsid);
        bool b = new CommentBLL().Insert(cm);
        if (b)
        {
            txtCode.Text = "";
            txtcomment.Text = "";
            //隐藏"该新闻暂时无评论!"
            empdata.Visible = false;
            //绑定评论
            repComment.DataSource = new CommentBLL().SelectComment(newsid);
            repComment.DataBind();
        }
        else {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('评论添加失败!');</script>");  

        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值