/// <summary> /// 增加一条数据 /// </summary> public int Add(Tea.Model.order_comment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "order_comment("); strSql.Append("order_id,article_id,parent_id,user_id,user_name,user_ip,content,is_lock,add_time,is_reply,reply_content,order_code,order_name,title,type,reply_time)"); strSql.Append(" values ("); strSql.Append("@order_id,@article_id,@parent_id,@user_id,@user_name,@user_ip,@content,@is_lock,@add_time,@is_reply,@reply_content,@order_code,@order_name,@title,@type,@reply_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@order_id", SqlDbType.Int, 4), new SqlParameter("@article_id", SqlDbType.Int, 4), new SqlParameter("@parent_id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.NVarChar, 128), new SqlParameter("@user_ip", SqlDbType.NVarChar, 128), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@is_lock", SqlDbType.Int, 4), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@is_reply", SqlDbType.Int, 4), new SqlParameter("@reply_content", SqlDbType.NText), new SqlParameter("@order_code", SqlDbType.NVarChar, 128), new SqlParameter("@order_name", SqlDbType.NVarChar, 512), new SqlParameter("@title", SqlDbType.NVarChar, 128), new SqlParameter("@type", SqlDbType.Int, 4), new SqlParameter("@reply_time", SqlDbType.DateTime) }; parameters[0].Value = model.order_id; parameters[1].Value = model.article_id; parameters[2].Value = model.parent_id; 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; parameters[9].Value = model.is_reply; parameters[10].Value = model.reply_content; parameters[11].Value = model.order_code; parameters[12].Value = model.order_name; parameters[13].Value = model.title; parameters[14].Value = model.type; parameters[15].Value = model.reply_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Tea.Model.order_comment GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,order_id,article_id,parent_id,user_id,user_name,user_ip,content,is_lock,add_time,is_reply,reply_content,order_code,order_name,title,type,reply_time from " + databaseprefix + "order_comment "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Tea.Model.order_comment model = new Tea.Model.order_comment(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Tea.Model.order_comment DataRowToModel(DataRow row) { Tea.Model.order_comment model = new Tea.Model.order_comment(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["order_id"] != null && row["order_id"].ToString() != "") { model.order_id = int.Parse(row["order_id"].ToString()); } if (row["article_id"] != null && row["article_id"].ToString() != "") { model.article_id = int.Parse(row["article_id"].ToString()); } if (row["parent_id"] != null && row["parent_id"].ToString() != "") { model.parent_id = int.Parse(row["parent_id"].ToString()); } if (row["user_id"] != null && row["user_id"].ToString() != "") { model.user_id = int.Parse(row["user_id"].ToString()); } if (row["user_name"] != null) { model.user_name = row["user_name"].ToString(); } if (row["user_ip"] != null) { model.user_ip = row["user_ip"].ToString(); } if (row["content"] != null) { model.content = row["content"].ToString(); } if (row["is_lock"] != null && row["is_lock"].ToString() != "") { model.is_lock = int.Parse(row["is_lock"].ToString()); } if (row["add_time"] != null && row["add_time"].ToString() != "") { model.add_time = DateTime.Parse(row["add_time"].ToString()); } if (row["is_reply"] != null && row["is_reply"].ToString() != "") { model.is_reply = int.Parse(row["is_reply"].ToString()); } if (row["reply_content"] != null) { model.reply_content = row["reply_content"].ToString(); } if (row["order_code"] != null) { model.order_code = row["order_code"].ToString(); } if (row["order_name"] != null) { model.order_name = row["order_name"].ToString(); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["type"] != null && row["type"].ToString() != "") { model.type = int.Parse(row["type"].ToString()); } if (row["reply_time"] != null && row["reply_time"].ToString() != "") { model.reply_time = DateTime.Parse(row["reply_time"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Tea.Model.order_comment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "order_comment set "); strSql.Append("article_id=@article_id,"); strSql.Append("parent_id=@parent_id,"); 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("order_code=@order_code,"); strSql.Append("order_name=@order_name,"); strSql.Append("title=@title,"); strSql.Append("type=@type,"); strSql.Append("reply_time=@reply_time"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@article_id", SqlDbType.Int, 4), new SqlParameter("@parent_id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.NVarChar, 128), new SqlParameter("@user_ip", SqlDbType.NVarChar, 128), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@is_lock", SqlDbType.Int, 4), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@is_reply", SqlDbType.Int, 4), new SqlParameter("@reply_content", SqlDbType.NText), new SqlParameter("@order_code", SqlDbType.NVarChar, 128), new SqlParameter("@order_name", SqlDbType.NVarChar, 512), new SqlParameter("@title", SqlDbType.NVarChar, 128), new SqlParameter("@type", SqlDbType.Int, 4), new SqlParameter("@reply_time", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@order_id", SqlDbType.Int, 4) }; parameters[0].Value = model.article_id; parameters[1].Value = model.parent_id; parameters[2].Value = model.user_id; parameters[3].Value = model.user_name; parameters[4].Value = model.user_ip; parameters[5].Value = model.content; parameters[6].Value = model.is_lock; parameters[7].Value = model.add_time; parameters[8].Value = model.is_reply; parameters[9].Value = model.reply_content; parameters[10].Value = model.order_code; parameters[11].Value = model.order_name; parameters[12].Value = model.title; parameters[13].Value = model.type; parameters[14].Value = model.reply_time; parameters[15].Value = model.id; parameters[16].Value = model.order_id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }