public List <T_New> GetPageEntityList(int start, int end) { string sql = "select * from (select row_number() over(order by id) as num, * from T_News) as t where t.num>=@start and t.num<=@end"; SqlParameter[] pars = { new SqlParameter("@start", start), new SqlParameter("@end", end) }; DataTable da = SqlHelper.GetTable(sql, CommandType.Text, pars); List <T_New> newInfoList = null; if (da.Rows.Count > 0) { newInfoList = new List <T_New>(); T_New newInfo = null; foreach (DataRow row in da.Rows) { newInfo = new T_New(); LoadEntity(row, newInfo); newInfoList.Add(newInfo); } } return(newInfoList); }
public ActionResult GetNewInfoModel() { int id = int.Parse(Request["id"]); T_New newInfo = NewInfoService.GetModel(id); return(Json(newInfo, JsonRequestBehavior.AllowGet)); }
public ActionResult ShowEdit() { int id = int.Parse(Request["id"]); T_New newInfo = NewInfoService.GetModel(id); ViewData.Model = newInfo; return(View()); }
public void LoadEntity(DataRow row, T_New newInfo) { newInfo.Id = Convert.ToInt32(row["Id"]); newInfo.Title = row["Title"] != DBNull.Value ? row["Title"].ToString() : string.Empty; newInfo.Msg = row["Msg"] != DBNull.Value ? row["Msg"].ToString() : string.Empty; newInfo.ImagePath = row["ImagePath"] != DBNull.Value ? row["ImagePath"].ToString() : string.Empty; newInfo.SubDateTime = Convert.ToDateTime(row["SubDateTime"]); newInfo.Author = row["Author"] != DBNull.Value ? row["Author"].ToString() : string.Empty; }
public ActionResult EditNewInfo(T_New newInfo) { if (NewInfoService.UpdateEntityModel(newInfo)) { return(Content("ok")); } else { return(Content("no")); } }
public T_New GetEntityModel(int id) { string sql = "select * from T_News where Id=@Id"; DataTable da = SqlHelper.GetTable(sql, CommandType.Text, new SqlParameter("@Id", id)); T_New newInfo = null; if (da.Rows.Count > 0) { newInfo = new T_New(); LoadEntity(da.Rows[0], newInfo); } return(newInfo); }
public ActionResult AddNewInfo(T_New newInfo) { //注意Upload:目录是编辑器的目录要加上,还要添加LitJson,然后生成一下 newInfo.SubDateTime = DateTime.Now; newInfo.Msg = Request["Msg"]; if (NewInfoService.InsertEntityModel(newInfo)) { return(Json(newInfo, JsonRequestBehavior.AllowGet)); } else { return(Content("no:添加失败")); } }
public int InsertEntityModel(T_New newInfo) { string sql = "insert into T_News(Title,Msg,Author,SubDateTime,ImagePath) values(@Title,@Msg,@Author,@SubDateTime,@ImagePath)"; SqlParameter[] pars = { new SqlParameter("@Title", SqlDbType.NVarChar, 32), new SqlParameter("@Msg", SqlDbType.NVarChar), new SqlParameter("@Author", SqlDbType.NVarChar, 32), new SqlParameter("@SubDateTime", SqlDbType.DateTime), new SqlParameter("@ImagePath", SqlDbType.NVarChar, 100) }; pars[0].Value = newInfo.Title; pars[1].Value = newInfo.Msg; pars[2].Value = newInfo.Author; pars[3].Value = newInfo.SubDateTime; pars[4].Value = newInfo.ImagePath; return(SqlHelper.ExecuteNonQuery(sql, CommandType.Text, pars)); }
public List <T_New> GetEntityList() { string sql = "select * from T_News"; DataTable da = SqlHelper.GetTable(sql, CommandType.Text); List <T_New> list = null; if (da.Rows.Count > 0) { list = new List <T_New>(); T_New newInfo = null; foreach (DataRow row in da.Rows) { newInfo = new T_New(); LoadEntity(row, newInfo); list.Add(newInfo); } } return(list); }
public int UpdateEntityModel(T_New newInfo) { string sql = "update T_News set Title=@Title,Msg=@Msg,Author=@Author,SubDateTime=@SubDateTime,ImagePath=@ImagePath where Id=@Id"; SqlParameter[] pars = { new SqlParameter("@Title", SqlDbType.NVarChar, 32), new SqlParameter("@Author", SqlDbType.NVarChar, 32), new SqlParameter("@Msg", SqlDbType.NVarChar), new SqlParameter("@SubDateTime", SqlDbType.DateTime), new SqlParameter("@ImagePath", SqlDbType.NVarChar, 100), new SqlParameter("@Id", SqlDbType.Int, 4) }; pars[0].Value = newInfo.Title; pars[1].Value = newInfo.Author; pars[2].Value = newInfo.Msg; pars[3].Value = newInfo.SubDateTime; pars[4].Value = newInfo.ImagePath; pars[5].Value = newInfo.Id; return(SqlHelper.ExecuteNonQuery(sql, CommandType.Text, pars)); }
public bool UpdateEntityModel(T_New newInfo) { return(NewInfoDal.UpdateEntityModel(newInfo) > 0); }
public bool InsertEntityModel(T_New newInfo) { return(NewInfoDal.InsertEntityModel(newInfo) > 0); }