コード例 #1
0
ファイル: Add.aspx.cs プロジェクト: fangxman/BBS
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsNumber(txtRTID.Text))
            {
                strErr += "RTID格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtRSID.Text))
            {
                strErr += "RSID格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtRUID.Text))
            {
                strErr += "RUID格式错误!\\n";
            }
            if (this.txtRTopic.Text.Trim().Length == 0)
            {
                strErr += "RTopic不能为空!\\n";
            }
            if (this.txtRContents.Text.Trim().Length == 0)
            {
                strErr += "RContents不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtRTime.Text))
            {
                strErr += "RTime格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtRClickCount.Text))
            {
                strErr += "RClickCount格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      RTID        = int.Parse(this.txtRTID.Text);
            int      RSID        = int.Parse(this.txtRSID.Text);
            int      RUID        = int.Parse(this.txtRUID.Text);
            string   RTopic      = this.txtRTopic.Text;
            string   RContents   = this.txtRContents.Text;
            DateTime RTime       = DateTime.Parse(this.txtRTime.Text);
            int      RClickCount = int.Parse(this.txtRClickCount.Text);

            BBS.Model.BBSReply model = new BBS.Model.BBSReply();
            model.RTID        = RTID;
            model.RSID        = RSID;
            model.RUID        = RUID;
            model.RTopic      = RTopic;
            model.RContents   = RContents;
            model.RTime       = RTime;
            model.RClickCount = RClickCount;

            BBS.BLL.BBSReply bll = new BBS.BLL.BBSReply();
            bll.Add(model);
            Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
コード例 #2
0
ファイル: BBSReply.cs プロジェクト: jesonab/BBS
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BBS.Model.BBSReply model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.RTID != null)
            {
                strSql1.Append("RTID,");
                strSql2.Append("" + model.RTID + ",");
            }
            if (model.RSID != null)
            {
                strSql1.Append("RSID,");
                strSql2.Append("" + model.RSID + ",");
            }
            if (model.RUID != null)
            {
                strSql1.Append("RUID,");
                strSql2.Append("" + model.RUID + ",");
            }
            if (model.RTopic != null)
            {
                strSql1.Append("RTopic,");
                strSql2.Append("'" + model.RTopic + "',");
            }
            if (model.RContents != null)
            {
                strSql1.Append("RContents,");
                strSql2.Append("'" + model.RContents + "',");
            }
            if (model.RTime != null)
            {
                strSql1.Append("RTime,");
                strSql2.Append("'" + model.RTime + "',");
            }
            if (model.RClickCount != null)
            {
                strSql1.Append("RClickCount,");
                strSql2.Append("" + model.RClickCount + ",");
            }
            strSql.Append("insert into BBSReply(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #3
0
ファイル: Modify.aspx.cs プロジェクト: chenglingr/BBS
 private void ShowInfo(int RID)
 {
     BBS.BLL.BBSReply   bll   = new BBS.BLL.BBSReply();
     BBS.Model.BBSReply model = bll.GetModel(RID);
     this.lblRID.Text         = model.RID.ToString();
     this.txtRTID.Text        = model.RTID.ToString();
     this.txtRSID.Text        = model.RSID.ToString();
     this.txtRUID.Text        = model.RUID.ToString();
     this.txtRTopic.Text      = model.RTopic;
     this.txtRContents.Text   = model.RContents;
     this.txtRTime.Text       = model.RTime.ToString();
     this.txtRClickCount.Text = model.RClickCount.ToString();
 }
コード例 #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BBS.Model.BBSReply GetModel(int RID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  ");
            strSql.Append(" RID,RTID,RSID,RUID,RTopic,RContents,RTime,RClickCount ");
            strSql.Append(" from BBSReply ");
            strSql.Append(" where RID=" + RID + "");
            BBS.Model.BBSReply model = new BBS.Model.BBSReply();
            DataSet            ds    = DbHelperSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BBS.Model.BBSReply DataRowToModel(DataRow row)
 {
     BBS.Model.BBSReply model = new BBS.Model.BBSReply();
     if (row != null)
     {
         if (row["RID"] != null && row["RID"].ToString() != "")
         {
             model.RID = int.Parse(row["RID"].ToString());
         }
         if (row["RTID"] != null && row["RTID"].ToString() != "")
         {
             model.RTID = int.Parse(row["RTID"].ToString());
         }
         if (row["RSID"] != null && row["RSID"].ToString() != "")
         {
             model.RSID = int.Parse(row["RSID"].ToString());
         }
         if (row["RUID"] != null && row["RUID"].ToString() != "")
         {
             model.RUID = int.Parse(row["RUID"].ToString());
         }
         if (row["RTopic"] != null)
         {
             model.RTopic = row["RTopic"].ToString();
         }
         if (row["RContents"] != null)
         {
             model.RContents = row["RContents"].ToString();
         }
         if (row["RTime"] != null && row["RTime"].ToString() != "")
         {
             model.RTime = DateTime.Parse(row["RTime"].ToString());
         }
         if (row["RClickCount"] != null && row["RClickCount"].ToString() != "")
         {
             model.RClickCount = int.Parse(row["RClickCount"].ToString());
         }
     }
     return(model);
 }
コード例 #6
0
ファイル: AddComment.ashx.cs プロジェクト: chenglingr/BBS
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";


            string json = "{}";

            if (context.Session["ID"] != null)
            {
                int      RTID        = int.Parse(context.Request.Form["TID"]);
                int      RSID        = 1;
                int      RUID        = int.Parse(context.Session["ID"].ToString());
                string   RTopic      = context.Request.Form["title"];;
                string   RContents   = context.Request.Form["content"];;
                DateTime RTime       = DateTime.Now;
                int      RClickCount = 0;

                BBS.Model.BBSReply model = new BBS.Model.BBSReply();
                model.RTID        = RTID;
                model.RSID        = RSID;
                model.RUID        = RUID;
                model.RTopic      = RTopic;
                model.RContents   = RContents;
                model.RTime       = RTime;
                model.RClickCount = RClickCount;

                BBS.BLL.BBSReply bll = new BBS.BLL.BBSReply();
                int n = bll.Add(model);
                if (n > 0)
                {
                    json = "{\"info\":\"增加数据失败\"}";
                }
            }

            context.Response.Write(json);
        }
コード例 #7
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BBS.Model.BBSReply model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.RTID != null)
            {
                strSql1.Append("RTID,");
                strSql2.Append("" + model.RTID + ",");
            }
            if (model.RSID != null)
            {
                strSql1.Append("RSID,");
                strSql2.Append("" + model.RSID + ",");
            }
            if (model.RUID != null)
            {
                strSql1.Append("RUID,");
                strSql2.Append("" + model.RUID + ",");
            }
            if (model.RTopic != null)
            {
                strSql1.Append("RTopic,");
                strSql2.Append("'" + model.RTopic + "',");
            }
            if (model.RContents != null)
            {
                strSql1.Append("RContents,");
                strSql2.Append("'" + model.RContents + "',");
            }
            if (model.RTime != null)
            {
                strSql1.Append("RTime,");
                strSql2.Append("'" + model.RTime + "',");
            }
            if (model.RClickCount != null)
            {
                strSql1.Append("RClickCount,");
                strSql2.Append("" + model.RClickCount + ",");
            }
            strSql.Append("insert into BBSReply(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                //更新帖子表里回复数
                string sqlupdateReplyCount = string.Format("update BBSTopic set treplycount=treplycount+1 where tid={0}", model.RTID);
                DbHelperSQL.ExecuteSql(sqlupdateReplyCount);//更新
                return(Convert.ToInt32(obj));
            }
        }
コード例 #8
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BBS.Model.BBSReply model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BBSReply set ");
            if (model.RTID != null)
            {
                strSql.Append("RTID=" + model.RTID + ",");
            }
            else
            {
                strSql.Append("RTID= null ,");
            }
            if (model.RSID != null)
            {
                strSql.Append("RSID=" + model.RSID + ",");
            }
            else
            {
                strSql.Append("RSID= null ,");
            }
            if (model.RUID != null)
            {
                strSql.Append("RUID=" + model.RUID + ",");
            }
            else
            {
                strSql.Append("RUID= null ,");
            }
            if (model.RTopic != null)
            {
                strSql.Append("RTopic='" + model.RTopic + "',");
            }
            else
            {
                strSql.Append("RTopic= null ,");
            }
            if (model.RContents != null)
            {
                strSql.Append("RContents='" + model.RContents + "',");
            }
            else
            {
                strSql.Append("RContents= null ,");
            }
            if (model.RTime != null)
            {
                strSql.Append("RTime='" + model.RTime + "',");
            }
            else
            {
                strSql.Append("RTime= null ,");
            }
            if (model.RClickCount != null)
            {
                strSql.Append("RClickCount=" + model.RClickCount + ",");
            }
            else
            {
                strSql.Append("RClickCount= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where RID=" + model.RID + "");
            int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }