/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.base_post model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into base_post("); strSql.Append("post_name,p_sid,remark,value1,value2,value3,value4,value5,value6,status,create_person,create_date,update_person,update_date)"); strSql.Append(" values ("); strSql.Append("@post_name,@p_sid,@remark,@value1,@value2,@value3,@value4,@value5,@value6,@status,@create_person,@create_date,@update_person,@update_date)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@post_name", SqlDbType.NVarChar, 10), new SqlParameter("@p_sid", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.Text), new SqlParameter("@value1", SqlDbType.NVarChar, 255), new SqlParameter("@value2", SqlDbType.NVarChar, 255), new SqlParameter("@value3", SqlDbType.NVarChar, 255), new SqlParameter("@value4", SqlDbType.NVarChar, 255), new SqlParameter("@value5", SqlDbType.NVarChar, 255), new SqlParameter("@value6", SqlDbType.NVarChar, 255), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@create_person", SqlDbType.NVarChar, 50), new SqlParameter("@create_date", SqlDbType.DateTime), new SqlParameter("@update_person", SqlDbType.NVarChar, 50), new SqlParameter("@update_date", SqlDbType.DateTime) }; parameters[0].Value = model.post_name; parameters[1].Value = model.p_sid; parameters[2].Value = model.remark; parameters[3].Value = model.value1; parameters[4].Value = model.value2; parameters[5].Value = model.value3; parameters[6].Value = model.value4; parameters[7].Value = model.value5; parameters[8].Value = model.value6; parameters[9].Value = model.status; parameters[10].Value = model.create_person; parameters[11].Value = model.create_date; parameters[12].Value = model.update_person; parameters[13].Value = model.update_date; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.base_post GetModel(int sid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 sid,post_name,p_sid,remark,value1,value2,value3,value4,value5,value6,status,create_person,create_date,update_person,update_date from base_post "); strSql.Append(" where sid=@sid"); SqlParameter[] parameters = { new SqlParameter("@sid", SqlDbType.Int, 4) }; parameters[0].Value = sid; Maticsoft.Model.base_post model = new Maticsoft.Model.base_post(); 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 Maticsoft.Model.base_post DataRowToModel(DataRow row) { Maticsoft.Model.base_post model = new Maticsoft.Model.base_post(); if (row != null) { if (row["sid"] != null && row["sid"].ToString() != "") { model.sid = int.Parse(row["sid"].ToString()); } if (row["post_name"] != null) { model.post_name = row["post_name"].ToString(); } if (row["p_sid"] != null && row["p_sid"].ToString() != "") { model.p_sid = int.Parse(row["p_sid"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["value1"] != null) { model.value1 = row["value1"].ToString(); } if (row["value2"] != null) { model.value2 = row["value2"].ToString(); } if (row["value3"] != null) { model.value3 = row["value3"].ToString(); } if (row["value4"] != null) { model.value4 = row["value4"].ToString(); } if (row["value5"] != null) { model.value5 = row["value5"].ToString(); } if (row["value6"] != null) { model.value6 = row["value6"].ToString(); } if (row["status"] != null && row["status"].ToString() != "") { model.status = int.Parse(row["status"].ToString()); } if (row["create_person"] != null) { model.create_person = row["create_person"].ToString(); } if (row["create_date"] != null && row["create_date"].ToString() != "") { model.create_date = DateTime.Parse(row["create_date"].ToString()); } if (row["update_person"] != null) { model.update_person = row["update_person"].ToString(); } if (row["update_date"] != null && row["update_date"].ToString() != "") { model.update_date = DateTime.Parse(row["update_date"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.base_post model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update base_post set "); strSql.Append("post_name=@post_name,"); strSql.Append("p_sid=@p_sid,"); strSql.Append("remark=@remark,"); strSql.Append("value1=@value1,"); strSql.Append("value2=@value2,"); strSql.Append("value3=@value3,"); strSql.Append("value4=@value4,"); strSql.Append("value5=@value5,"); strSql.Append("value6=@value6,"); strSql.Append("status=@status,"); strSql.Append("create_person=@create_person,"); strSql.Append("create_date=@create_date,"); strSql.Append("update_person=@update_person,"); strSql.Append("update_date=@update_date"); strSql.Append(" where sid=@sid"); SqlParameter[] parameters = { new SqlParameter("@post_name", SqlDbType.NVarChar, 10), new SqlParameter("@p_sid", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.Text), new SqlParameter("@value1", SqlDbType.NVarChar, 255), new SqlParameter("@value2", SqlDbType.NVarChar, 255), new SqlParameter("@value3", SqlDbType.NVarChar, 255), new SqlParameter("@value4", SqlDbType.NVarChar, 255), new SqlParameter("@value5", SqlDbType.NVarChar, 255), new SqlParameter("@value6", SqlDbType.NVarChar, 255), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@create_person", SqlDbType.NVarChar, 50), new SqlParameter("@create_date", SqlDbType.DateTime), new SqlParameter("@update_person", SqlDbType.NVarChar, 50), new SqlParameter("@update_date", SqlDbType.DateTime), new SqlParameter("@sid", SqlDbType.Int, 4) }; parameters[0].Value = model.post_name; parameters[1].Value = model.p_sid; parameters[2].Value = model.remark; parameters[3].Value = model.value1; parameters[4].Value = model.value2; parameters[5].Value = model.value3; parameters[6].Value = model.value4; parameters[7].Value = model.value5; parameters[8].Value = model.value6; parameters[9].Value = model.status; parameters[10].Value = model.create_person; parameters[11].Value = model.create_date; parameters[12].Value = model.update_person; parameters[13].Value = model.update_date; parameters[14].Value = model.sid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }