/// <summary> /// 更新一条数据 /// </summary> public bool Update(Shop.Model.Notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_notice set "); strSql.Append("notitle=@notitle,"); strSql.Append("nocontent=@nocontent,"); strSql.Append("notime=@notime"); strSql.Append(" where noid=@noid"); SqlParameter[] parameters = { new SqlParameter("@notitle", SqlDbType.VarChar, 60), new SqlParameter("@nocontent", SqlDbType.VarChar, 500), new SqlParameter("@notime", SqlDbType.DateTime), new SqlParameter("@noid", SqlDbType.Int, 4), new SqlParameter("@adminid", SqlDbType.Int, 4) }; parameters[0].Value = model.notitle; parameters[1].Value = model.nocontent; parameters[2].Value = model.notime; parameters[3].Value = model.noid; parameters[4].Value = model.adminid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Shop.Model.Notice DataRowToModel(DataRow row) { Shop.Model.Notice model = new Shop.Model.Notice(); if (row != null) { if (row["noid"] != null && row["noid"].ToString() != "") { model.noid = int.Parse(row["noid"].ToString()); } if (row["adminid"] != null && row["adminid"].ToString() != "") { model.adminid = int.Parse(row["adminid"].ToString()); } if (row["notitle"] != null) { model.notitle = row["notitle"].ToString(); } if (row["nocontent"] != null) { model.nocontent = row["nocontent"].ToString(); } if (row["notime"] != null && row["notime"].ToString() != "") { model.notime = DateTime.Parse(row["notime"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Shop.Model.Notice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_notice("); strSql.Append("adminid,notitle,nocontent,notime)"); strSql.Append(" values ("); strSql.Append("@adminid,@notitle,@nocontent,@notime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@adminid", SqlDbType.Int, 4), new SqlParameter("@notitle", SqlDbType.VarChar, 60), new SqlParameter("@nocontent", SqlDbType.VarChar, 500), new SqlParameter("@notime", SqlDbType.DateTime) }; parameters[0].Value = model.adminid; parameters[1].Value = model.notitle; parameters[2].Value = model.nocontent; parameters[3].Value = model.notime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Shop.Model.Notice GetModel(int noid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 noid,adminid,notitle,nocontent,notime from t_notice "); strSql.Append(" where noid=@noid"); SqlParameter[] parameters = { new SqlParameter("@noid", SqlDbType.Int, 4) }; parameters[0].Value = noid; Shop.Model.Notice model = new Shop.Model.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); } }