/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.T_Notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Notice("); strSql.Append("title,content,create_time,isDeleted,admin_id)"); strSql.Append(" values ("); strSql.Append("@title,@content,@create_time,@isDeleted,@admin_id)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.VarChar, 50), new SqlParameter("@content", SqlDbType.Text), new SqlParameter("@create_time", SqlDbType.DateTime), new SqlParameter("@isDeleted", SqlDbType.Int, 4), new SqlParameter("@admin_id", SqlDbType.Int, 4) }; parameters[0].Value = model.title; parameters[1].Value = model.content; parameters[2].Value = model.create_time; parameters[3].Value = model.isDeleted; parameters[4].Value = model.admin_id; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.T_Notice DataRowToModel(DataRow row) { Maticsoft.Model.T_Notice model = new Maticsoft.Model.T_Notice(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["content"] != null) { model.content = row["content"].ToString(); } if (row["create_time"] != null && row["create_time"].ToString() != "") { model.create_time = DateTime.Parse(row["create_time"].ToString()); } if (row["isDeleted"] != null && row["isDeleted"].ToString() != "") { model.isDeleted = int.Parse(row["isDeleted"].ToString()); } if (row["admin_id"] != null && row["admin_id"].ToString() != "") { model.admin_id = int.Parse(row["admin_id"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.T_Notice DataRowToModel(DataRow row) { Maticsoft.Model.T_Notice model = new Maticsoft.Model.T_Notice(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["content"] != null) { model.content = row["content"].ToString(); } if (row["create_time"] != null && row["create_time"].ToString() != "") { model.create_time = DateTime.Parse(row["create_time"].ToString()); } if (row["isDeleted"] != null && row["isDeleted"].ToString() != "") { model.isDeleted = int.Parse(row["isDeleted"].ToString()); } if (row["admin_id"] != null && row["admin_id"].ToString() != "") { model.admin_id = int.Parse(row["admin_id"].ToString()); } } return model; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.T_Notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Notice set "); strSql.Append("title=@title,"); strSql.Append("content=@content,"); strSql.Append("create_time=@create_time,"); strSql.Append("isDeleted=@isDeleted,"); strSql.Append("admin_id=@admin_id"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.VarChar, 50), new SqlParameter("@content", SqlDbType.Text), new SqlParameter("@create_time", SqlDbType.DateTime), new SqlParameter("@isDeleted", SqlDbType.Int, 4), new SqlParameter("@admin_id", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.title; parameters[1].Value = model.content; parameters[2].Value = model.create_time; parameters[3].Value = model.isDeleted; parameters[4].Value = model.admin_id; parameters[5].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.T_Notice GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from T_Notice "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.T_Notice model = new Maticsoft.Model.T_Notice(); 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.T_Notice GetModel(int id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 * from T_Notice "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Maticsoft.Model.T_Notice model=new Maticsoft.Model.T_Notice(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }