private void ShowInfo(int _id) { BLL.forum_posts bll = new BLL.forum_posts(); Model.forum_posts model = bll.GetModel(id); DTcms.BLL.users ubll = new DTcms.BLL.users(); DTcms.Model.users umodel = ubll.GetModel(model.user_id); ddlCategoryId.SelectedValue = model.board_id.ToString(); txtUserName.Text = umodel.user_name; txtUserName.ReadOnly = true; if (model.is_lock == 1) { cblItem.Items[0].Selected = true; } if (model.is_top == 1) { cblItem.Items[1].Selected = true; } if (model.is_red == 1) { cblItem.Items[2].Selected = true; } if (model.is_hot == 1) { cblItem.Items[3].Selected = true; } txtPostName.Text = model.title; txtPostContent.Value = model.content; }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.forum_posts GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,board_id,user_id,user_ip,parent_post_id,quote_id,title,zhaiyao,content,is_top,is_red,is_hot,is_lock,click,reply_count,reply_user_id,add_time,reply_time,post_type"); strSql.Append(" from " + databaseprefix + "forum_posts"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.forum_posts model = new Model.forum_posts(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private bool DoAdd() { bool result = false; BLL.forum_posts bll = new BLL.forum_posts(); Model.forum_posts model = new Model.forum_posts(); DTcms.BLL.users ubll = new DTcms.BLL.users(); DTcms.Model.users umodel = new DTcms.Model.users(); //判断用户名是否存在 if (!ubll.Exists(txtUserName.Text.Trim())) { JscriptMsg("用户名不存在,请重新填写!", ""); return(result); } umodel = ubll.GetModel(txtUserName.Text.Trim()); string _userip = System.Web.HttpContext.Current.Request.UserHostAddress; model.class_layer = 1; model.title = txtPostName.Text.Trim(); model.content = txtPostContent.Value; model.user_id = umodel.id; model.user_ip = _userip; model.board_id = Utils.StrToInt(ddlCategoryId.SelectedValue, 0); model.parent_post_id = 0; model.post_type = 1;//主题帖 model.reply_time = DateTime.Now; model.click = 0; model.is_lock = 0; model.is_top = 0; model.is_red = 0; model.is_hot = 0; if (cblItem.Items[0].Selected == true) { model.is_lock = 1; } if (cblItem.Items[1].Selected == true) { model.is_top = 1; } if (cblItem.Items[2].Selected == true) { model.is_red = 1; } if (cblItem.Items[3].Selected == true) { model.is_hot = 1; } model.add_time = DateTime.Now; if (bll.Add(model) > 0) { AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "发布了帖子:" + model.title); //记录日志 result = true; } return(result); }
//设置操作 protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e) { ChkAdminLevel("plugin_forum_post", DTEnums.ActionEnum.Edit.ToString()); //检查权限 int id = Convert.ToInt32(((HiddenField)e.Item.FindControl("hidId")).Value); BLL.forum_posts bll = new BLL.forum_posts(); Model.forum_posts model = bll.GetModel(id); switch (e.CommandName) { case "lbtnIsTop": if (model.is_top == 1) { bll.UpdateField(id, "is_top=0"); } else { bll.UpdateField(id, "is_top=1"); } break; case "lbtnIsRed": if (model.is_red == 1) { bll.UpdateField(id, "is_red=0"); } else { bll.UpdateField(id, "is_red=1"); } break; case "lbtnIsHot": if (model.is_hot == 1) { bll.UpdateField(id, "is_hot=0"); } else { bll.UpdateField(id, "is_hot=1"); } break; case "lbtnIsLock": if (model.is_lock == 1) { bll.UpdateField(id, "is_lock=0"); } else { bll.UpdateField(id, "is_lock=1"); } break; } this.RptBind(this.board_id, "post_type=1" + CombSqlTxt(this.keywords, this.property), "add_time desc,id desc"); }
private bool DoEdit(int _id) { bool result = false; BLL.forum_posts bll = new BLL.forum_posts(); Model.forum_posts model = bll.GetModel(_id); model.board_id = Utils.StrToInt(ddlCategoryId.SelectedValue, 0); model.is_lock = 0; model.is_top = 0; model.is_red = 0; model.is_hot = 0; if (cblItem.Items[0].Selected == true) { model.is_lock = 1; } if (cblItem.Items[1].Selected == true) { model.is_top = 1; } if (cblItem.Items[2].Selected == true) { model.is_red = 1; } if (cblItem.Items[3].Selected == true) { model.is_hot = 1; } model.title = txtPostName.Text; model.content = txtPostContent.Value; if (bll.Update(model)) { AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改帖子信息:" + model.title); //记录日志 result = true; } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.forum_posts model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.forum_posts model) { return(dal.Add(model)); }
/// <summary> /// 将对象转换为实体 /// </summary> private Model.forum_posts DataRowToModel(DataRow row) { Model.forum_posts model = new Model.forum_posts(); if (row != null) { #region 主表信息====================== if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["board_id"] != null && row["board_id"].ToString() != "") { model.board_id = int.Parse(row["board_id"].ToString()); } if (row["user_id"] != null && row["user_id"].ToString() != "") { model.user_id = int.Parse(row["user_id"].ToString()); } if (row["user_ip"] != null) { model.user_ip = row["user_ip"].ToString(); } if (row["parent_post_id"] != null && row["parent_post_id"].ToString() != "") { model.parent_post_id = int.Parse(row["parent_post_id"].ToString()); } if (row["quote_id"] != null && row["quote_id"].ToString() != "") { model.quote_id = int.Parse(row["quote_id"].ToString()); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["zhaiyao"] != null) { model.zhaiyao = row["zhaiyao"].ToString(); } if (row["content"] != null) { model.content = row["content"].ToString(); } if (row["is_top"] != null && row["is_top"].ToString() != "") { model.is_top = int.Parse(row["is_top"].ToString()); } if (row["is_red"] != null && row["is_red"].ToString() != "") { model.is_red = int.Parse(row["is_red"].ToString()); } if (row["is_hot"] != null && row["is_hot"].ToString() != "") { model.is_hot = int.Parse(row["is_hot"].ToString()); } if (row["is_lock"] != null && row["is_lock"].ToString() != "") { model.is_lock = int.Parse(row["is_lock"].ToString()); } if (row["click"] != null && row["click"].ToString() != "") { model.click = int.Parse(row["click"].ToString()); } if (row["reply_count"] != null && row["reply_count"].ToString() != "") { model.reply_count = int.Parse(row["reply_count"].ToString()); } if (row["reply_user_id"] != null && row["reply_user_id"].ToString() != "") { model.reply_user_id = int.Parse(row["reply_user_id"].ToString()); } if (row["add_time"] != null && row["add_time"].ToString() != "") { model.add_time = DateTime.Parse(row["add_time"].ToString()); } if (row["reply_time"] != null && row["reply_time"].ToString() != "") { model.reply_time = DateTime.Parse(row["reply_time"].ToString()); } if (row["post_type"] != null && row["post_type"].ToString() != "") { model.post_type = int.Parse(row["post_type"].ToString()); } #endregion } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.forum_posts model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { #region 添加主表数据==================== StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "forum_posts("); strSql.Append("board_id,user_id,user_ip,parent_post_id,quote_id,title,zhaiyao,content,is_top,is_red,is_hot,is_lock,click,reply_count,reply_user_id,add_time,reply_time,post_type)"); strSql.Append(" values ("); strSql.Append("@board_id,@user_id,@user_ip,@parent_post_id,@quote_id,@title,@zhaiyao,@content,@is_top,@is_red,@is_hot,@is_lock,@click,@reply_count,@reply_user_id,@add_time,@reply_time,@post_type)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@board_id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_ip", SqlDbType.NVarChar, 50), new SqlParameter("@parent_post_id", SqlDbType.Int, 4), new SqlParameter("@quote_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@zhaiyao", SqlDbType.NVarChar, 255), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@is_top", SqlDbType.TinyInt, 1), new SqlParameter("@is_red", SqlDbType.TinyInt, 1), new SqlParameter("@is_hot", SqlDbType.TinyInt, 1), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@click", SqlDbType.Int, 4), new SqlParameter("@reply_count", SqlDbType.Int, 4), new SqlParameter("@reply_user_id", SqlDbType.Int, 4), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@reply_time", SqlDbType.DateTime), new SqlParameter("@post_type", SqlDbType.Int, 4) }; parameters[0].Value = model.board_id; parameters[1].Value = model.user_id; parameters[2].Value = model.user_ip; parameters[3].Value = model.parent_post_id; parameters[4].Value = model.quote_id; parameters[5].Value = model.title; parameters[6].Value = model.zhaiyao; parameters[7].Value = model.content; parameters[8].Value = model.is_top; parameters[9].Value = model.is_red; parameters[10].Value = model.is_hot; parameters[11].Value = model.is_lock; parameters[12].Value = model.click; parameters[13].Value = model.reply_count; parameters[14].Value = model.reply_user_id; parameters[15].Value = model.add_time; parameters[16].Value = model.reply_time; parameters[17].Value = model.post_type; //添加主表数据 object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务 model.id = Convert.ToInt32(obj); #endregion #region 更新板块帖子数量============================== StringBuilder strSql2 = new StringBuilder(); strSql2.Append("update " + databaseprefix + "forum_board set "); if (model.post_type == 1) { strSql2.Append(" subject_count=subject_count+1,post_count=post_count+1 "); } else { strSql2.Append(" post_count=post_count+1 "); } strSql2.Append(" where id = @id"); SqlParameter[] parameters2 = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters2[0].Value = model.board_id; DbHelperSQL.GetSingle(conn, trans, strSql2.ToString(), parameters2); //带事务 #endregion #region 更新主题回复数和最后回复人==================== if (model.post_type == 2) { StringBuilder strSql3 = new StringBuilder(); strSql3.Append(" update " + databaseprefix + "forum_posts set "); strSql3.Append(" reply_count=reply_count+1,reply_user_id=@reply_user_id "); strSql3.Append(" where id = @id "); SqlParameter[] parameters3 = { new SqlParameter("@reply_user_id", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters3[0].Value = model.user_id; parameters3[1].Value = model.parent_post_id; DbHelperSQL.GetSingle(conn, trans, strSql3.ToString(), parameters3); //带事务 } #endregion trans.Commit(); } catch { trans.Rollback(); return(0); } } } return(model.id); }
/// <summary> /// 删除一条数据 /// </summary> public bool Delete(int id) { int subject_count = 0; int post_count = 0; Model.forum_posts model = GetModel(id); int board_id = model.board_id; List <CommandInfo> sqllist = new List <CommandInfo>(); CommandInfo cmd = new CommandInfo(); post_count -= 1; if (model.post_type == 1) //主题帖 { subject_count -= 1; post_count -= GetCount("parent_post_id=" + id); //先删除主题帖的回帖 StringBuilder strSql1 = new StringBuilder(); strSql1.Append("delete from " + databaseprefix + "forum_posts "); strSql1.Append(" where parent_post_id=@id "); SqlParameter[] parameters1 = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters1[0].Value = id; cmd = new CommandInfo(strSql1.ToString(), parameters1); sqllist.Add(cmd); } //删除帖子 StringBuilder strSql2 = new StringBuilder(); strSql2.Append("delete from " + databaseprefix + "forum_posts "); strSql2.Append(" where id=@id "); SqlParameter[] parameters2 = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters2[0].Value = id; cmd = new CommandInfo(strSql2.ToString(), parameters2); sqllist.Add(cmd); //更改板块贴子数量 StringBuilder strSql3 = new StringBuilder(); strSql3.Append("update " + databaseprefix + "forum_board set "); strSql3.Append(" subject_count=subject_count+@subject_count, post_count=post_count+@post_count "); strSql3.Append(" where id = @board_id"); SqlParameter[] parameters3 = { new SqlParameter("@subject_count", SqlDbType.Int, 4), new SqlParameter("@post_count", SqlDbType.Int, 4), new SqlParameter("@board_id", SqlDbType.Int, 4) }; parameters3[0].Value = subject_count; parameters3[1].Value = post_count; parameters3[2].Value = board_id; cmd = new CommandInfo(strSql3.ToString(), parameters3); sqllist.Add(cmd); int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist); if (rowsAffected > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.forum_posts model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { #region 修改主表数据========================== StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "forum_posts set "); strSql.Append("board_id=@board_id,"); strSql.Append("user_id=@user_id,"); strSql.Append("user_ip=@user_ip,"); strSql.Append("parent_post_id=@parent_post_id,"); strSql.Append("quote_id=@quote_id,"); strSql.Append("title=@title,"); strSql.Append("zhaiyao=@zhaiyao,"); strSql.Append("content=@content,"); strSql.Append("is_top=@is_top,"); strSql.Append("is_red=@is_red,"); strSql.Append("is_hot=@is_hot,"); strSql.Append("is_lock=@is_lock,"); strSql.Append("click=@click,"); strSql.Append("reply_count=@reply_count,"); strSql.Append("reply_user_id=@reply_user_id,"); strSql.Append("add_time=@add_time,"); strSql.Append("reply_time=@reply_time,"); strSql.Append("post_type=@post_type"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@board_id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_ip", SqlDbType.NVarChar, 50), new SqlParameter("@parent_post_id", SqlDbType.Int, 4), new SqlParameter("@quote_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@zhaiyao", SqlDbType.NVarChar, 255), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@is_top", SqlDbType.TinyInt, 1), new SqlParameter("@is_red", SqlDbType.TinyInt, 1), new SqlParameter("@is_hot", SqlDbType.TinyInt, 1), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@click", SqlDbType.Int, 4), new SqlParameter("@reply_count", SqlDbType.Int, 4), new SqlParameter("@reply_user_id", SqlDbType.Int, 4), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@reply_time", SqlDbType.DateTime), new SqlParameter("@post_type", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.board_id; parameters[1].Value = model.user_id; parameters[2].Value = model.user_ip; parameters[3].Value = model.parent_post_id; parameters[4].Value = model.quote_id; parameters[5].Value = model.title; parameters[6].Value = model.zhaiyao; parameters[7].Value = model.content; parameters[8].Value = model.is_top; parameters[9].Value = model.is_red; parameters[10].Value = model.is_hot; parameters[11].Value = model.is_lock; parameters[12].Value = model.click; parameters[13].Value = model.reply_count; parameters[14].Value = model.reply_user_id; parameters[15].Value = model.add_time; parameters[16].Value = model.reply_time; parameters[17].Value = model.post_type; parameters[18].Value = model.id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); #endregion trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }