private void Add() { if (bool.Parse(Request.Form["checked"]) == false) { News_ContentInfo model = new News_ContentInfo(); model.ID = int.Parse(Request.Form["ID"]); model.NewsID = int.Parse(Request.Form["id"]); model.N_Content = Request.Form["N_Content"]; model.attributes = Request.Form["attributes"]; model.weight = int.Parse(Request.Form["weight"]); model.State = Convert.ToBoolean(Request.Form["State"]); model.Headings = Convert.ToBoolean(Request.Form["Headings"]); //大文本处理 int id = dao.Add(model); Log.WritePage(id > 0 ? "SUCCESS" : "Error"); } else { News_ContentInfo model = new News_ContentInfo(); model.ID = int.Parse(Request.Form["ID"]); model.NewsID = int.Parse(Request.Form["id"]); string url = ConfigurationManager.AppSettings["url"].ToString(); model.N_Content = url + AliyunOSS.UploadPictrue("blog"); model.attributes = Request.Form["attributes"]; model.weight = int.Parse(Request.Form["weight"]); model.State = Convert.ToBoolean(Request.Form["State"]); model.Headings = Convert.ToBoolean(Request.Form["Headings"]); int id = dao.Add(model); Log.WritePage(id > 0 ? "SUCCESS" : "Error"); } }
private void Detail() { string id = Request["id"]; News_ContentInfo model = dao.GetModel(int.Parse(id)); string json = Newtonsoft.Json.JsonConvert.SerializeObject(model); Log.WritePage(json); }
/// <summary> /// 得到一个对象实体 /// </summary> public News_ContentInfo DataRowToModel(DataRow row) { News_ContentInfo model = new News_ContentInfo(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["NewsID"] != null && row["NewsID"].ToString() != "") { model.NewsID = int.Parse(row["NewsID"].ToString()); } if (row["N_Content"] != null) { model.N_Content = row["N_Content"].ToString(); } if (row["attributes"] != null) { model.attributes = row["attributes"].ToString(); } if (row["weight"] != null && row["weight"].ToString() != "") { model.weight = int.Parse(row["weight"].ToString()); } if (row["State"] != null && row["State"].ToString() != "") { if ((row["State"].ToString() == "1") || (row["State"].ToString().ToLower() == "true")) { model.State = true; } else { model.State = false; } } if (row["Headings"] != null && row["Headings"].ToString() != "") { if ((row["Headings"].ToString() == "1") || (row["Headings"].ToString().ToLower() == "true")) { model.Headings = true; } else { model.Headings = false; } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(News_ContentInfo model) { string sql = "UPDATE [News_Content] SET [NewsID] = @0,[N_Content] = @1,[attributes] = @2,[weight] = @3,[State] = @4,[Headings] = @5 WHERE [ID]=@6"; int rows = DBHelp.ExecuteNonQuery(sql, DBHelp.Databasetype.SQL2005.ToString(), CommandType.Text, model.NewsID, model.N_Content, model.attributes, model.weight, model.State, model.Headings, model.ID); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(News_ContentInfo model) { string sql = "insert into News_Content([NewsID],[N_Content],[attributes],[weight],[State],[Headings])" + " values (@0,@1,@2,@3,@4,@5) select @@identity"; object obj = DBHelp.ExecuteScalar(sql, DBHelp.Databasetype.SQL2005.ToString(), CommandType.Text, model.NewsID, model.N_Content, model.attributes, model.weight, model.State, model.Headings); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public News_ContentInfo GetModel(int ID) { string sql = "select top 1 * from News_Content where [ID]=@0"; News_ContentInfo model = new News_ContentInfo(); DataSet ds = DBHelp.ExecteDataSet(sql, DBHelp.Databasetype.SQL2005.ToString(), CommandType.Text, ID); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void edit() { News_ContentInfo model = new News_ContentInfo(); model.ID = int.Parse(Request.Form["ID"]); model.NewsID = int.Parse(Request.Form["NewsID"]); model.N_Content = Request.Form["N_Content"]; model.attributes = Request.Form["attributes"]; model.weight = int.Parse(Request.Form["weight"]); model.State = Convert.ToBoolean(Request.Form["State"]); model.Headings = Convert.ToBoolean(Request.Form["Headings"]); //上传图片处理 //string imgUrl = ImageHelper.UploadImg("fuligoods"); //if (imgUrl != "") model.imgUrl = imgUrl; bool result = dao.Update(model); Log.WritePage(result ? "SUCCESS" : "Error"); }