/// <summary> /// 恢复删除 /// </summary> /// <returns></returns> public bool recoverDel() { try { //把原来表里面的数据删除标志位 置 0 if (!recordDelFlag(false)) { return(false); } //删除记录表中的数据 using (var db = new huxiuEntities()) { DeleteLog del = (from it in db.DeleteLog where it.Category == CategoryId && it.LogId == DelId select it).FirstOrDefault(); db.DeleteLog.Remove(del); db.SaveChanges(); } return(true); } catch { return(false); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (name.Text.Trim().Length > 0 && Request.Form["lb"].Trim().Length > 0 && summary.Text.Trim().Length > 0) { using (var db = new huxiuEntities()) { Author person = new Author { AuthorName = name.Text, AuthorSex = sex.SelectedValue == "1" ? true : false, AuthorImage = "~/File/" + Request.Form["lb"], AuthorSummary = summary.Text }; db.Author.Add(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('添加作者成功');location='AuthorList.aspx'</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (title.Text.Trim().Length > 0 && editor.InnerHtml.Trim().Length > 0 && link.Text.Trim().Length > 0) { using (var db = new huxiuEntities()) { News person = new News { NewsTitle = title.Text.Trim(), NewsBody = UeditorHelper.change(editor.InnerHtml), NewsDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), //发表时间 NewsLink = link.Text.Trim(), IsDel = false }; db.News.Add(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('添加成功');location='NewsList.aspx'</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
/// <summary> /// 记录原始数据项的删除标记 /// </summary> /// <param name="yes_or_no"></param> /// <returns>返回bool类型</returns> private bool recordDelFlag(bool yes_or_no) { try { using (var db = new huxiuEntities()) { switch (CategoryId) { case 1: //查找资讯 Passage delPassage = db.Passage.SingleOrDefault(a => a.PassageId == DelId); delPassage.IsDel = yes_or_no; break; case 2: //查找活动 Activity delActivty = db.Activity.SingleOrDefault(a => a.ActivityId == DelId); delActivty.IsDel = yes_or_no; break; case 3: //查找短趣 News delnews = db.News.SingleOrDefault(a => a.NewsId == DelId); delnews.IsDel = yes_or_no; break; } db.SaveChanges(); } return(true); } catch { return(false); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (name.Text.Trim().Length > 0) { using (var db = new huxiuEntities()) { PassageCategory person = new PassageCategory { CategoryName = name.Text.Trim() }; db.PassageCategory.Add(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('添加成功');location='PassageList.aspx'</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空!')</script>"); } }
protected void btnEditor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); if (title.Text.Trim().Length > 0 && editor.InnerHtml.Trim().Length > 0 && link.Text.Trim().Length > 0) { using (var db = new huxiuEntities())//修改短趣 { News person = (from it in db.News where it.NewsId == id select it).FirstOrDefault(); person.NewsTitle = title.Text.Trim(); //标题 person.NewsBody = UeditorHelper.change(editor.InnerHtml); //内容 // person.NewsDate = Convert.ToDateTime(dates.Text);//发布时间不做修改 person.NewsLink = link.Text.Trim(); //超链接 // person.IsDel = false;//是否删除 if (db.SaveChanges() == 1) { Response.Write("<script>alert('编辑成功');location='NewsEditor.aspx?id=" + id + "'</script>"); } else { Response.Write("<script>alert('编辑失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
/// <summary> /// 删除头条 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool delItem(int id) { try { using (var db = new huxiuEntities()) { Headline delHead = db.Headline.SingleOrDefault(a => a.Id == id); if (!delHead.HisDisplay) //如果删除队列中的项目,队列数量减一 { queueSize--; } else if (displayCount <= 4) //最少头条保留4条 { return(false); } db.Headline.Remove(delHead); db.SaveChanges(); } displayCount--; return(true); } catch { return(false); } }
protected void btnAdd_Click(object sender, EventArgs e) { //标题 内容 封面 作者 分类 不能为空 if (title.Text.Trim().Length > 0 && editor.InnerHtml.Trim().Length > 0 && Request.Form["lb"].Trim().Length > 0 && author.SelectedValue.Length > 0 && category.SelectedValue.Length > 0) { using (var db = new huxiuEntities()) { Passage passage = new Passage { PassageTitle = title.Text, PassageBody = UeditorHelper.change(editor.InnerHtml), PassageImage = "/File/" + Request.Form["lb"], PassageCategory = Convert.ToInt32(category.SelectedValue), PublishDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AuthorId = Convert.ToInt32(author.SelectedValue), PageViews = 0, IsDel = false }; db.Passage.Add(passage); if (db.SaveChanges() == 1) { Response.Write("<script>alert('添加成功');location='PassageList.aspx'</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空!')</script>"); } }
/// <summary> /// 本函数实现标记资讯, 短趣,活动 删除列,并且把记录写在 DeleteLog 中 /// </summary> /// <param name="CategoryId"></param> 参数解释:待删除 ID 的所在分类 1 资讯 ; 2 活动; 3 短趣 /// <param name="DelId"></param> 参数解释:待删除 ID /// <param name="OperatorId"></param> 参数解释:本次操作的管理员 ID /// <returns></returns> public bool delItem() { try { //记录准备删除的那条记录 if (!recordDelFlag(true)) { return(false); } using (var db = new huxiuEntities()) { //new 一个 delelog 对象,进行添加操作 DeleteLog addDelLog = new DeleteLog(); addDelLog.DelAdminId = OperatorId; addDelLog.DelTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); addDelLog.Category = CategoryId; addDelLog.LogId = DelId; //添加记录表中 db.DeleteLog.Add(addDelLog); //保存更改 db.SaveChanges(); return(true); } } catch { return(false); } }
/// <summary> /// 本函数删除相应分类下面的某一条 /// </summary> /// <param name="completeCate"> 相应分类</param> /// <param name="completeId"> 分类下面的id </param> /// <returns>返回 bool</returns> private bool delSourceData(int completeCate, int completeId) { try { using (var db = new huxiuEntities()) { switch (completeCate) { case 1: //查找资讯 Passage delPassage = db.Passage.SingleOrDefault(a => a.PassageId == completeId); db.Passage.Remove(delPassage); break; case 2: //查找活动 Activity delActivty = db.Activity.SingleOrDefault(a => a.ActivityId == completeId); db.Activity.Remove(delActivty); break; case 3: //查找短趣 News delnews = db.News.SingleOrDefault(a => a.NewsId == completeId); db.News.Remove(delnews); break; } db.SaveChanges(); } return(true); } catch { return(false); } }
protected void btnEditor_Click(object sender, EventArgs e) { if (name.Text.Trim().Length > 0) { using (var db = new huxiuEntities()) { int id = Convert.ToInt32(Request.QueryString["id"]); PassageCategory person = (from it in db.PassageCategory where it.PCategoryId == id select it).FirstOrDefault(); person.CategoryName = name.Text.Trim(); if (db.SaveChanges() == 1) { Response.Write("<script>alert('修改成功');location='/PCategoryList.aspx'</script>"); } else { Response.Write("<script>alert('修改失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void btnEditor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); //标题 内容 不能为空 if (title.Text.Trim().Length > 0 && editor.InnerHtml.Trim().Length > 0) { using (var db = new huxiuEntities()) { Passage person = (from it in db.Passage where it.PassageId == id select it).FirstOrDefault(); person.PassageTitle = title.Text; //标题 person.PassageBody = UeditorHelper.change(editor.InnerHtml); //内容 if (Request.Form["lb"] != "") { person.PassageImage = "~/File/" + Request.Form["lb"]; } person.PassageCategory = Convert.ToInt32(category.SelectedValue); //资讯分类 person.PublishDate = Convert.ToDateTime(dates.Text).ToString("yyyy-MM-dd HH:mm:ss"); //时间 person.AuthorId = Convert.ToInt32(author.SelectedValue); //作者 if (db.SaveChanges() == 1) { Response.Write("<script>alert('编辑成功');location='PassageEditor.aspx?id=" + id + "'</script>"); } else { Response.Write("<script>alert('编辑失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void Rpt_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "delete") { int pcId = Convert.ToInt32(e.CommandArgument); using (var db = new huxiuEntities()) { PassageCategory pc = db.PassageCategory.SingleOrDefault(a => a.PCategoryId == pcId); db.PassageCategory.Remove(pc); db.SaveChanges(); Response.Write("<script>alert('分类删除成功!');location='PCategoryList.aspx';</script>"); } } }
protected void Rpt_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "delete") { int authorId = Convert.ToInt32(e.CommandArgument); using (var db = new huxiuEntities()) { Author au = db.Author.SingleOrDefault(a => a.AuthorId == authorId); db.Author.Remove(au); db.SaveChanges(); Response.Write("<script>alert('作者删除成功!');location='AuthorList.aspx';</script>"); } } }
protected void btnEditor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); if (title.Text.Trim().Length > 0 && content.Text.Trim().Length > 0 && link.Text.Trim().Length > 0) { //string Pattern = @"^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.[a-zA-Z]{2,4})(\:[0-9]+)?(/[^/][a-zA-Z0-9\.\,\?\'\\/\+&%\$#\=~_\-@]*)*$"; string Pattern = @"(http|https)://[^\s]*"; Regex r = new Regex(Pattern); if (r.IsMatch(link.Text.Trim())) { using (var db = new huxiuEntities())//修改短趣 { News person = (from it in db.News where it.NewsId == id select it).FirstOrDefault(); if (person.NewsTitle == title.Text.Trim() && person.NewsBody == content.Text && person.NewsLink == link.Text.Trim()) { Response.Write("<script>alert('未修改');location='NewsEditor.aspx?id=" + id + "'</script>"); } else { person.NewsTitle = title.Text.Trim(); //标题 person.NewsBody = content.Text; //内容 // person.NewsDate = Convert.ToDateTime(dates.Text);//发布时间不做修改 person.NewsLink = link.Text.Trim(); //超链接 // person.IsDel = false;//是否删除 if (db.SaveChanges() == 1) { Response.Write("<script>alert('编辑成功');location='NewsEditor.aspx?id=" + id + "'</script>"); } else { Response.Write("<script>alert('编辑失败请重试')</script>"); } } } } else { Response.Write("<script>alert('格式错误')</script>"); } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (title.Text.Trim().Length > 0 && content.Text.Trim().Length > 0 && link.Text.Trim().Length > 0) { //(http|https)://[^\s]* //string Pattern = @"^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.[a-zA-Z]{2,4})(\:[0-9]+)?(/[^/][a-zA-Z0-9\.\,\?\'\\/\+&%\$#\=~_\-@]*)*$"; string Pattern = @"(http|https)://[^\s]*"; Regex r = new Regex(Pattern); if (r.IsMatch(link.Text.Trim())) { using (var db = new huxiuEntities()) { News person = new News { NewsTitle = title.Text.Trim(), NewsBody = content.Text.Trim(), NewsDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), //发表时间 NewsLink = link.Text.Trim(), IsDel = false }; db.News.Add(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('添加成功');location='NewsList.aspx'</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } else { Response.Write("<script>alert('请输入正确的网址')</script>"); } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void btnEditor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); if (title.Text.Trim().Length > 0 && content.Text.Trim().Length > 0 && where.Text.Length > 0 && tips.Text.Length > 0) { using (var db = new huxiuEntities()) { Activity person = (from it in db.Activity where it.ActivityId == id select it).FirstOrDefault(); person.ActivityTitle = title.Text; person.ActivityWhat = content.Text.Trim();//富文本编辑器里的内容 if (Request.Form["lb"] != "") { person.ActivityImage = "/File/" + Request.Form["lb"]; } if (requestedDeliveryDateTextBox.Text.Trim().Length > 0) { person.ActivityWhen = Convert.ToDateTime(requestedDeliveryDateTextBox.Text).ToString("yyyy-MM-dd"); } person.ActivityWhere = where.Text; person.ActivityTips = tips.Text; if (db.SaveChanges() == 1) { Response.Write("<script>alert('编辑成功');location='ActivityEditor.aspx?id=" + id + "'</script>"); } else { Response.Write("<script>alert('编辑失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
/// <summary> /// 添加一条头条 /// </summary> /// <param name="hId"></param> /// <param name="showTime"></param> /// <returns></returns> public bool addItem(int hId, string showTime) { if (!isExpire(showTime)) { try { using (var db = new huxiuEntities()) { //是否重复 Headline isRpt = db.Headline.SingleOrDefault(a => a.HId == hId); if (isRpt != null) { return(false); } //添加新头条 Passage pasInfo = db.Passage.SingleOrDefault(a => a.PassageId == hId && a.IsDel == false); if (pasInfo == null) { return(false); } Headline headSave = new Headline(); headSave.HId = hId; headSave.Htitle = pasInfo.PassageTitle; headSave.Himg = pasInfo.PassageImage; headSave.Hdeadline = showTime; headSave.HisDisplay = false; db.Headline.Add(headSave); db.SaveChanges(); } queueSize++; return(true); } catch { return(false); } } else { return(false); } }
/// <summary> /// 本函数用来删除超过阈值的记录,删除原始记录和记录删除行为的记录 /// </summary> /// <returns>返回 bool </returns> public bool dellongtimelog() { //获取当前时间 DateTime now = DateTime.Now; try { using (var db = new huxiuEntities()) { //查询所有超过删除阈值的条目 var delList = from it in db.DeleteLog // where (Convert.ToDateTime(it.DelTime) - now).Days > LogDeadline select it; //遍历结果集,进行删除 DeleteLog 和 相应分类下面的条目 foreach (var item in delList) { //转化字符串到时间 DateTime tt = Convert.ToDateTime(item.DelTime); //用 TimeSpan 计算相差天数 int tsday = Convert.ToInt32((now - tt).TotalDays); //和阈值比较 if (tsday > LogDeadline) { delSourceData(item.Category, item.LogId); DeleteLog delLogId = db.DeleteLog.SingleOrDefault(a => a.DelId == item.DelId); db.DeleteLog.Remove(delLogId); } } db.SaveChanges(); } return(true); } catch { return(false); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (title.Text.Trim().Length > 0 && Request.Form["lb"].Length > 0 && requestedDeliveryDateTextBox.Text.Trim().Length > 0 && editor.InnerHtml.Trim().Length > 0 && where.Text.Trim().Length > 0 && tips.Text.Trim().Length > 0) { using (var db = new huxiuEntities()) { Activity person = new Activity { ActivityTitle = title.Text, ActivityWhat = UeditorHelper.change(editor.InnerHtml), ActivityImage = "~/File/" + Request.Form["lb"],//活动封面 ActivityWhen = requestedDeliveryDateTextBox.Text, ActivityWhere = where.Text, ActivityTips = tips.Text }; db.Activity.Add(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('添加成功');location='ActivityList.aspx'</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void btnSubmit_Click(object sender, EventArgs e) { // SEESION 获取 ID int ID = 8; if (txtProAnswer.Text.Trim() == "" || txtProProtect.Text.Trim() == "" || txtPwd.Text.Trim() == "" || txtRptPwd.Text.Trim() == "") { Response.Write("<script>alert('请输入合法数据!')</script>"); } else { if (txtPwd.Text == txtRptPwd.Text) { //保存修改 try { using (var db = new huxiuEntities()) { Admin ad = db.Admin.SingleOrDefault(a => a.AdminId == ID); ad.AdminPassword = Security.SHA1_Hash(Security.MD5_hash(txtPwd.Text.Trim())); ad.AdminImage = "~/File" + Request.Form["lb"]; ad.AdminProblem = txtProProtect.Text.Trim(); ad.AdminAnswer = txtProAnswer.Text.Trim(); db.SaveChanges(); } Response.Write("<script>alert('修改成功!');</script>"); } catch (Exception ex) { Response.Write(ex); } } else { Response.Write("<script>alert('两次密码不一样,请检查!')</script>"); } } }
protected void rptActHead_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "editHead") //显示修改控件 { Label tmplal = (Label)e.Item.FindControl("labID"); TextBox tmptxt = (TextBox)e.Item.FindControl("txtID"); Button tmpbtn = (Button)e.Item.FindControl("btnSub"); tmpbtn.Visible = tmptxt.Visible = tmplal.Visible = true; } else if (e.CommandName == "SubChange") { TextBox tmptxt = (TextBox)e.Item.FindControl("txtID"); //获取修改的 ID 值 int oldID = Convert.ToInt32(e.CommandArgument); int newID = Convert.ToInt32(tmptxt.Text); try { using (var db = new huxiuEntities()) { Activity act = db.Activity.SingleOrDefault(a => a.ActivityId == newID && a.IsHeadline == false && a.IsDel == false); Activity actOld = db.Activity.SingleOrDefault(a => a.ActivityId == oldID); if (act == null) //是否已经作为头条 { Response.Write("<script>alert('请检查 ID 正确性!(不能重复添加和添加已经删除的条目) ');location.href='SetActiveHeadline.aspx';</script>"); return; } act.IsHeadline = true; actOld.IsHeadline = false; db.SaveChanges(); } Response.Write("<script>alert('修改成功!');location.href='SetActiveHeadline.aspx';</script>"); } catch { Response.Write("<script>alert('修改失败,请重试!');location.href='SetActiveHeadline.aspx';</script>"); } } }
/// <summary> /// 队列到头条 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool goHead(int id) { if (displayCount >= threshold) //头条已经达到预期展示数量,不能增加 { return(false); } try { using (var db = new huxiuEntities()) { Headline goHead = db.Headline.Single(a => a.Id == id); goHead.HisDisplay = true; db.SaveChanges(); } displayCount++; queueSize--; return(true); } catch { return(false); } }
protected void btnEditor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); if (name.Text.Trim().Length > 0 && Request.Form["lb"].Trim().Length > 0 && summary.Text.Trim().Length > 0) { using (var db = new huxiuEntities()) { Author person = (from it in db.Author where it.AuthorId == id select it).FirstOrDefault(); person.AuthorName = name.Text; person.AuthorSex = sex.SelectedValue == "1" ? true : false; person.AuthorSummary = summary.Text; if (Request.Form["lb"] != "") { person.AuthorImage = "~/File/" + Request.Form["lb"]; } if (db.SaveChanges() == 1) { Response.Write("<script>alert('编辑成功');location='AuthorEditor.aspx?id=" + id + "'</script>"); } else { Response.Write("<script>alert('编辑失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (name.Text.Trim().Length > 0) { string cname = name.Text.Trim(); using (var db = new huxiuEntities()) { PassageCategory people = (from it in db.PassageCategory where it.CategoryName == cname select it).FirstOrDefault(); if (people == null) { PassageCategory person = new PassageCategory { CategoryName = name.Text.Trim() }; db.PassageCategory.Add(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('添加成功');location='PassageList.aspx'</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } else { Response.Write("<script>alert('已存在该分类!')</script>"); } } } else { Response.Write("<script>alert('不能为空!')</script>"); } }
/// <summary> /// 编辑属于队列中的等待头条 /// </summary> /// <param name="id"></param> /// <param name="showTime"></param> /// <returns></returns> public bool edit(int id, string showTime) { if (!isExpire(showTime)) { try { using (var db = new huxiuEntities()) { Headline goHead = db.Headline.Single(a => a.Id == id); goHead.Hdeadline = showTime; db.SaveChanges(); } return(true); } catch { return(false); } } else { return(false); } }
protected void Page_Load(object sender, EventArgs e) { Regex r = new Regex("^[1-9]d*|0$"); if (Request.QueryString["id"] != null && r.IsMatch(Request.QueryString["id"])) { int id = Convert.ToInt32(Request.QueryString["id"]); using (var db = new huxiuEntities()) { Passage_Author person = (from it in db.Passage_Author where it.PassageId == id select it).FirstOrDefault(); Passage newperson = (from it in db.Passage where it.PassageId == id select it).FirstOrDefault(); if (newperson != null) { newperson.PageViews = newperson.PageViews + 1; db.SaveChanges(); person.PageViews = person.PageViews + 1; title.Text = person.PassageTitle; //标题 content.Text = person.PassageBody; //内容 image.ImageUrl = person.PassageImage; //封面 time.Text = person.PublishDate.ToString(); //时间 authorimage.ImageUrl = person.AuthorImage; //作者头像 authorname.Text = person.AuthorName; //作者名 authorsummary.Text = person.AuthorSummary; //作者简介 views.Text = "阅读量" + person.PageViews; //阅读量 List <Passage_Author> people = (from it in db.Passage_Author where it.PassageId != id select it).ToList(); //相关活动 title1.Text = people[0].PassageTitle; image1.ImageUrl = people[0].PassageImage; image1.PostBackUrl = "/PassageContent.aspx?id=" + people[0].PassageId; title2.Text = people[1].PassageTitle; image2.ImageUrl = people[1].PassageImage; image2.PostBackUrl = "/PassageContent.aspx?id=" + people[1].PassageId; title3.Text = people[2].PassageTitle; image3.ImageUrl = people[2].PassageImage; image3.PostBackUrl = "/PassageContent.aspx?id=" + people[2].PassageId; } else { Response.Write("<script>alert('地址栏有误');location='PassageList.aspx'</script>"); } } } else { Response.Write("<script>alert('地址栏有误');location='PassageList.aspx'</script>"); } }
/// <summary> /// 自动更新头条:有过期的就从队列里面顶上去;如果队列为空就把过期的都延长1天;如果过期的数量超过队列数量,就补充能补充的,其他的过期条目删除。 /// </summary> /// <returns></returns> public bool autoUpdate() { List <int> expireID = new List <int>(); //保存过期的 ID List <int> queueID = new List <int>(); //保存等待显示的头条 ID expireID.Clear(); queueID.Clear(); try { using (var db = new huxiuEntities()) { var item = from it in db.Headline select it; foreach (var it in item) { if (!it.HisDisplay) //记录下来所有队列中的ID { queueID.Add(it.Id); } else if (isExpire(it.Hdeadline)) //记录过期的 ID { expireID.Add(it.Id); } } } if (expireID.Count == 0) //显示的头条没有过期的 { return(true); } else //有过期的 { using (var db = new huxiuEntities()) { if (min(queueID.Count, expireID.Count) <= 0) //如果队列为空,没有可以补充的给现有的所有头条赋予现在时间另外延长1天 { for (int i = 0; i < expireID.Count; i++) { int t = expireID[i]; Headline addTime = db.Headline.SingleOrDefault(a => a.Id == t); addTime.Hdeadline = addOneDay(); db.SaveChanges(); } } else { //删除较小的,用队列值补充 int t = min(queueID.Count, expireID.Count); for (int i = 0; i < t; i++) { int tt = expireID[0]; Headline delH = db.Headline.SingleOrDefault(a => a.Id == tt); db.Headline.Remove(delH); tt = queueID[0]; Headline doHead = db.Headline.SingleOrDefault(a => a.Id == tt); doHead.HisDisplay = true; //删除记录 expireID.RemoveAt(0); queueID.RemoveAt(0); } int cnt = expireID.Count; if (expireID.Count > 0) //如果队列没了,但是头条还有过期的,就把过期的直接删除 { for (int i = 0; i < cnt; i++) { int tt = expireID[0]; Headline delH = db.Headline.SingleOrDefault(a => a.Id == tt); db.Headline.Remove(delH); displayCount--; expireID.RemoveAt(0); } } } db.SaveChanges(); } return(true); } } catch { return(false); } }
protected void btnSubmit_Click(object sender, EventArgs e) { /* * // Request.Form["lb"].Trim().Length > 0 * // SEESION 获取 ID * int ID =Convert.ToInt32( Session["AdminID"].ToString()); * if(!((txtPwd.Text!="" && txtRptPwd.Text!="") || (txtProProtect.Text!="" && txtProAnswer.Text!="") || Request.Form["lb"].Trim().Length > 0)) * * Response.Write("<script>alert('请输入合法数据!')</script>"); * // if (txtProAnswer.Text.Trim()=="" || txtProProtect.Text.Trim()=="" || txtPwd.Text.Trim() =="" || txtRptPwd.Text.Trim()=="") * // Response.Write("<script>alert('请输入合法数据!')</script>"); * else * { * if (txtPwd.Text == txtRptPwd.Text) * { * //保存修改 * try * { * using(var db=new huxiuEntities()) * { * Admin ad = db.Admin.SingleOrDefault(a => a.AdminId == ID); * ad.AdminPassword = Security.SHA1_Hash(Security.MD5_hash(txtPwd.Text.Trim())); * ad.AdminImage = "~/File" + Request.Form["lb"]; * ad.AdminProblem = txtProProtect.Text.Trim(); * ad.AdminAnswer = txtProAnswer.Text.Trim(); * db.SaveChanges(); * } * Response.Write("<script>alert('修改成功!');</script>"); * * } * catch (Exception ex) * { * Response.Write(ex); * } * } * else * { * Response.Write("<script>alert('两次密码不一样,请检查!')</script>"); * * } * } */ //----------------------------------------- int ID = Convert.ToInt32(Session["AdminID"].ToString()); string headImg = Request.Form["lb"].ToString(); string pwd = txtPwd.Text.Trim(); string pwdRpt = txtRptPwd.Text.Trim(); string proPro = txtProProtect.Text.Trim(); string proAns = txtProAnswer.Text.Trim(); bool isEditPwd = false; if (!((txtPwd.Text != "" && txtRptPwd.Text != "") || (txtProProtect.Text != "" && txtProAnswer.Text != "") || Request.Form["lb"].Trim().Length > 0)) { Response.Write("<script>alert('请输入合法数据!')</script>"); } else { try { using (var db = new huxiuEntities()) { Admin ad = db.Admin.SingleOrDefault(a => a.AdminId == ID); if (headImg != "") { ad.AdminImage = "/File/" + headImg; } if (pwd != "" && pwd == pwdRpt && pwd != "●●●●●●●●●●") { ad.AdminPassword = Security.SHA1_Hash(Security.MD5_hash(pwd)); isEditPwd = true; } else if (pwd != pwdRpt) { Response.Write("<script>alert('两次密码不一样,请检查!')</script>"); return; } if (proAns != "" && proPro != "") { ad.AdminProblem = proPro; ad.AdminAnswer = proAns; } db.SaveChanges(); } if (isEditPwd) { Response.Write("<script>alert('修改成功!下次登录使用新密码!');window.parent.location.reload();</script>"); } else { string url = "AdminInfo.aspx?id=" + ID; Response.Write("<script>alert('修改成功!');location.href='" + url + "'</script>"); } } catch (Exception ex) { Response.Write(ex); } } }