/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.comment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dt_comment set "); strSql.Append("channel_id=@channel_id,"); strSql.Append("content_id=@content_id,"); strSql.Append("title=@title,"); strSql.Append("user_id=@user_id,"); strSql.Append("user_name=@user_name,"); strSql.Append("user_ip=@user_ip,"); strSql.Append("content=@content,"); strSql.Append("is_lock=@is_lock,"); strSql.Append("add_time=@add_time,"); strSql.Append("is_reply=@is_reply,"); strSql.Append("reply_content=@reply_content,"); strSql.Append("reply_time=@reply_time"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@content_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 255), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.NVarChar, 50), new SqlParameter("@user_ip", SqlDbType.NVarChar, 255), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@is_reply", SqlDbType.TinyInt, 1), new SqlParameter("@reply_content", SqlDbType.NText), new SqlParameter("@reply_time", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.channel_id; parameters[2].Value = model.content_id; parameters[3].Value = model.title; parameters[4].Value = model.user_id; parameters[5].Value = model.user_name; parameters[6].Value = model.user_ip; parameters[7].Value = model.content; parameters[8].Value = model.is_lock; parameters[9].Value = model.add_time; parameters[10].Value = model.is_reply; parameters[11].Value = model.reply_content; parameters[12].Value = model.reply_time; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTcms.Model.comment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_comment("); strSql.Append("channel_id,content_id,title,user_id,user_name,user_ip,content,is_lock,add_time)"); strSql.Append(" values ("); strSql.Append("@channel_id,@content_id,@title,@user_id,@user_name,@user_ip,@content,@is_lock,@add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@content_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 255), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.NVarChar, 50), new SqlParameter("@user_ip", SqlDbType.NVarChar, 255), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.channel_id; parameters[1].Value = model.content_id; parameters[2].Value = model.title; parameters[3].Value = model.user_id; parameters[4].Value = model.user_name; parameters[5].Value = model.user_ip; parameters[6].Value = model.content; parameters[7].Value = model.is_lock; parameters[8].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DTcms.Model.comment GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,channel_id,content_id,title,user_id,user_name,user_ip,content,is_lock,add_time,is_reply,reply_content,reply_time from dt_comment "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; DTcms.Model.comment model = new DTcms.Model.comment(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["channel_id"].ToString() != "") { model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString()); } if (ds.Tables[0].Rows[0]["content_id"].ToString() != "") { model.content_id = int.Parse(ds.Tables[0].Rows[0]["content_id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].ToString(); if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString(); model.user_ip = ds.Tables[0].Rows[0]["user_ip"].ToString(); model.content = ds.Tables[0].Rows[0]["content"].ToString(); if (ds.Tables[0].Rows[0]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } if (ds.Tables[0].Rows[0]["is_reply"].ToString() != "") { model.is_reply = int.Parse(ds.Tables[0].Rows[0]["is_reply"].ToString()); } model.reply_content = ds.Tables[0].Rows[0]["reply_content"].ToString(); if (ds.Tables[0].Rows[0]["reply_time"].ToString() != "") { model.reply_time = DateTime.Parse(ds.Tables[0].Rows[0]["reply_time"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.comment model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTcms.Model.comment model) { return(dal.Add(model)); }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public DTcms.Model.comment GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,channel_id,content_id,title,user_id,user_name,user_ip,content,is_lock,add_time,is_reply,reply_content,reply_time from dt_comment "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; DTcms.Model.comment model = new DTcms.Model.comment(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["channel_id"].ToString() != "") { model.channel_id = int.Parse(ds.Tables[0].Rows[0]["channel_id"].ToString()); } if (ds.Tables[0].Rows[0]["content_id"].ToString() != "") { model.content_id = int.Parse(ds.Tables[0].Rows[0]["content_id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].ToString(); if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString(); model.user_ip = ds.Tables[0].Rows[0]["user_ip"].ToString(); model.content = ds.Tables[0].Rows[0]["content"].ToString(); if (ds.Tables[0].Rows[0]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } if (ds.Tables[0].Rows[0]["is_reply"].ToString() != "") { model.is_reply = int.Parse(ds.Tables[0].Rows[0]["is_reply"].ToString()); } model.reply_content = ds.Tables[0].Rows[0]["reply_content"].ToString(); if (ds.Tables[0].Rows[0]["reply_time"].ToString() != "") { model.reply_time = DateTime.Parse(ds.Tables[0].Rows[0]["reply_time"].ToString()); } return model; } else { return null; } }