public JsonResult GetNews(int id) { B_News b_new = new B_News(); var res = b_new.Get(id); return(Json(res)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["NewsID"] != null) { admin = (M_Admin)Session["name"]; string newsid = Request.QueryString["NewsID"].ToString(); List <M_News> news = new List <M_News>(); news = B_News.SelectNewsID(newsid); txtTitle.Text = news[0].News_Title.ToString(); ddlClass.DataSource = B_News.SelectClass(admin); ddlClass.DataTextField = "Class_Name"; ddlClass.DataValueField = "Class_ID"; ddlClass.DataBind(); ddlClass.SelectedValue = news[0].Class_ID.ToString(); lblDate.Text = news[0].News_Date.ToString(); txtKey.Text = news[0].News_Key.ToString(); txtFrom.Text = admin.Admin_Name; ckContet.Text = news[0].News_Content.ToString(); } else { admin = (M_Admin)Session["name"]; ddlClass.AppendDataBoundItems = true; ddlClass.Items.Add(new ListItem("-- 请选择一个选择项 --", "")); ddlClass.DataSource = B_News.SelectClass(admin); ddlClass.DataTextField = "Class_Name"; ddlClass.DataValueField = "Class_ID"; ddlClass.DataBind(); lblDate.Text = DateTime.Now.ToString(); txtFrom.Text = admin.Admin_Name; } } }
public ActionResult DeleteConfirmed(int id) { B_News b_News = db.B_News.Find(id); db.B_News.Remove(b_News); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "NewsId,Title,NewContent,ImagePath,MoviePath,NewIdNHK,NewsDate,NewsWebUrl,ActiveFlag,CreateTime,UpdateTime,DeleteTime,TitleWithRuby,NewContentWithRuby")] B_News b_News) { if (ModelState.IsValid) { db.Entry(b_News).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(b_News)); }
protected void Button1_Click(object sender, EventArgs e) { string classid = "0"; if (ddlClass.SelectedIndex != 0) { classid = ddlClass.SelectedValue.ToString(); } string key = txtKey.Text.Trim(); gvNews.DataSource = B_News.jiansuo(classid, key); gvNews.DataBind(); }
// GET: B_News_Admin/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } B_News b_News = db.B_News.Find(id); if (b_News == null) { return(HttpNotFound()); } return(View(b_News)); }
public JsonResult DelNews(string ids) { Common.Json json = new Common.Json(); B_News b_new = new B_News(); foreach (var id in ids.Split(new char[] { ',' })) { var m_new = b_new.Get(Convert.ToInt32(id)); b_new.Delete(Convert.ToInt32(id)); string pastImg = Path.Combine(Request.MapPath("/") + "../Images", m_new.img_url);//旧文件的物理路径 } json.msg = "成功删除" + ids.Split(new char[] { ',' }).Length + "条记录!"; return(Json(json)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { M_Admin admin = new M_Admin(); admin = (M_Admin)Session["name"]; ddlClass.AppendDataBoundItems = true; ddlClass.Items.Add(new ListItem("-- 请选择一个选择项 --", "")); ddlClass.DataSource = B_News.SelectClass(admin); ddlClass.DataTextField = "Class_Name"; ddlClass.DataValueField = "Class_ID"; ddlClass.DataBind(); gvNews.DataSource = B_News.SelectNews(admin); gvNews.DataBind(); } }
public JsonResult ExamNews(string ids, int?txt_status) { Common.Json json = new Common.Json(); B_News b_new = new B_News(); foreach (var id in ids.Split(new char[] { ',' })) { var m_new = b_new.Get(Convert.ToInt32(id)); if (m_new.status != txt_status) { m_new.status = txt_status; b_new.Update(m_new); } } json.msg = "成功审核" + ids.Split(new char[] { ',' }).Length + "条记录!"; return(Json(json)); }
public JsonResult GetNewsList(int limit = 10, int offset = 1) { B_News b_new = new B_News(); List <Order> order = new List <Order>() { Order.Asc("sort_id") }; List <SearchTemplate> st = new List <SearchTemplate>() { new SearchTemplate() { key = "", value = new int[] { offset, limit }, searchType = EnumBase.SearchType.Paging } }; var list_new = b_new.GetList(st, order); var list_new_count = b_new.GetCount(st); return(Json(new { total = list_new_count, rows = list_new }, JsonRequestBehavior.AllowGet)); }
protected void Button1_Click(object sender, EventArgs e) { if (Request.QueryString["NewsID"] != null) { admin = (M_Admin)Session["name"]; news.News_ID = Convert.ToInt32(Request.QueryString["NewsID"]); news.News_Title = txtTitle.Text.Trim(); news.Class_ID = Convert.ToInt32(ddlClass.SelectedValue); news.Admin_ID = admin.Admin_ID; news.News_Key = txtKey.Text.Trim(); news.News_Ource = txtFrom.Text; news.News_Content = ckContet.Text; news.News_Date = DateTime.Now; if (B_News.UpdateNews(news)) { Response.Write("<script>alert('修改成功!')</script>"); } else { Response.Write("<script>alert('修改失败!')</script>"); } } else { admin = (M_Admin)Session["name"]; news.News_Title = txtTitle.Text.Trim(); news.Class_ID = Convert.ToInt32(ddlClass.SelectedValue); news.Admin_ID = admin.Admin_ID; news.News_Key = txtKey.Text.Trim(); news.News_Ource = txtFrom.Text; news.News_Content = ckContet.Text; news.News_Date = DateTime.Now; if (B_News.InsertNews(news)) { Response.Write("<script>alert('添加成功!')</script>"); } else { Response.Write("<script>alert('添加失败!')</script>"); } } }
public ActionResult Create(string linkDown) { var newsDate = (from d in db.B_News select d.NewsDate).Max(); if (ModelState.IsValid) { using (var client = new WebClient()) { var responseString = client.DownloadString(linkDown); var news = Helper.News.FromJson(responseString); if (news.Count > 0) { foreach (KeyValuePair <string, List <Helper.News> > item in news[0]) { foreach (var el in item.Value) { //if (el.NewsPrearrangedTime.DateTime > newsDate) //{ var responseString1 = client.DownloadString("https://www3.nhk.or.jp/news/easy/" + el.NewsId + "/" + el.NewsId + ".html"); int startIndex = responseString1.IndexOf("<h1 class=\"article-main__title\""); int endIndex = responseString1.LastIndexOf("class=\"article-main__date\"") - 4; int length = endIndex - startIndex + 1; String title = responseString1.Substring(startIndex, length).Trim(); title = title.Replace(" ", ""); startIndex = responseString1.IndexOf("<div class=\"article-main__body article-body\""); endIndex = responseString1.LastIndexOf("<div class=\"article-main__colors\">") - 1; length = endIndex - startIndex + 1; String content = responseString1.Substring(startIndex, length).Trim(); content = content.Replace(" ", ""); try { if (!db.B_News.Any(s => s.Title == el.Title)) { B_News b_News = new B_News(); b_News.Title = el.Title; b_News.TitleWithRuby = el.TitleWithRuby; b_News.NewContent = content; b_News.NewContentWithRuby = content; b_News.NewIdNHK = el.NewsId; b_News.NewsDate = el.NewsPrearrangedTime.DateTime; b_News.ImagePath = el.NewsWebImageUri; b_News.MoviePath = el.NewsWebMovieUri; b_News.NewsWebUrl = el.NewsWebUrl.ToString(); b_News.ActiveFlag = 1; b_News.CreateTime = DateTime.Now; b_News.UpdateTime = DateTime.Now; db.B_News.Add(b_News); db.SaveChanges(); } } catch (DbEntityValidationException ex) { var sb = new StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), ex ); } } //} } } } return(RedirectToAction("Create")); } return(View()); }