protected void Page_Load(object sender, EventArgs e) { int id = 1; try { id = Convert.ToInt32(Request.QueryString["id"].ToString()); } catch { } ArticleHelper.AddHitCount(id); Article ar = ArticleHelper.GetArticleByID(id); ltTitle.Text = ar.Title; ltSource.Text = ar.Source; ltAuthor.Text = ar.Author; ltHit.Text = ar.Hit.ToString(); DateTime time = ar.UpdateTime; ltTime.Text = time.Year.ToString() + "年" + time.Month.ToString() + "月" + time.Day.ToString() + "日"; if (ArticleHelper.getType(id) != "学术报告:学术报告") { ltContent.Text = ar.Content; } else { plAcademic.Visible = true; string[] all = ar.Content.Split(new char[] { '!', '#' }); //ltContent.Text = all[3]; ltContent.Text = ar.Content.Substring(ar.Content.IndexOf('#') + 1); DateTime date = Convert.ToDateTime(all[0]); ltHoldTime.Text = "举办时间:" + date.Month + "." + date.Day + " " + all[1]; ltHoldPlace.Text = "举办地点:" + all[2]; } //Response.Cookies["myCookies"].Expires = DateTime.Now.AddDays(30); //Cookie.Expires = DateTime.Now.AddDays(1); if (Request.Cookies["myCookies"] == null || Request.Cookies["myCookies"].Value == "|") { //Response.Cookies["myCookies"].Value = "|"; //Response.Cookies["myCookies"].Expires = DateTime.Now.AddDays(30); HttpCookie MyCookie1 = new HttpCookie("myCookies", "|"); //MyCookie.Value = Server.HtmlEncode("|");//设置Cookie的值 //MyCookie.Expires = DateTime.Now.AddDays(1); DateTime date = DateTime.Now.AddDays(30); MyCookie1.Expires = DateTime.Now.Add(new TimeSpan(0, 2, 0)); MyCookie1.Expires = date; //设置Cookie过期时间 Response.Cookies.Add(MyCookie1); //新增Cookie } if (CHelper.IsExit(id)) { if (!(Server.HtmlEncode(Request.Cookies["myCookies"].Value).Contains("|" + id.ToString() + "|"))) { LinkAdd.Visible = true; addID.Value = id.ToString(); } } }
protected void Page_Load(object sender, EventArgs e) { List <IndexCard>[] ls = ArticleHelper.IndexCards(""); //绑定学院新闻 rptCollege.DataSource = ls[0]; rptCollege.DataBind(); //绑定学生新闻 rptStudent.DataSource = ls[1]; rptStudent.DataBind(); //绑定通知公告 rptNotice1.DataSource = ArticleHelper.getList(0, ls[2]); rptNotice1.DataBind(); rptNotice2.DataSource = ArticleHelper.getList(1, ls[2]); rptNotice2.DataBind(); //绑定招聘资讯 rptJob1.DataSource = ArticleHelper.getList(0, ls[3]); rptJob1.DataBind(); rptJob2.DataSource = ArticleHelper.getList(1, ls[3]); rptJob2.DataBind(); //绑定学术报告部分 //string content = ArticleHelper.getReporter().Content; int id = ArticleHelper.getReporterID(); if (id == 0) { pnAcademic.Visible = false; } else { Article ar = ArticleHelper.GetArticleByID(id); string[] all = ar.Content.Split(new char[] { '!', '#' }); ltTitle.Text = ar.Title; string lt = MyHtmlHelper.RemoveTags(ar.Content.Substring(ar.Content.IndexOf('#'))); ltContent.Text = lt.Length > 40 ? lt.Substring(1, 39) : lt.Substring(1, lt.Length - 1); if (ar.Link == null) { lbtReporter.PostBackUrl = "Content.aspx?id=" + ar.ArticleID; } else { lbtReporter.PostBackUrl = ar.Link; } //时间--- string month = all[0].Substring(5, 2); if (month[0] == '0') { month = month.Substring(1, 1); } string day = all[0].Substring(8, 2); if (day[0] == '0') { day = day.Substring(1, 1); } ltTime.Text = month + "." + day + " " + all[1]; ltPlace.Text = all[2]; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["User"] == null) { Response.Write("<script>alert('账户过期请重新登录!');window.parent.location.href='Login.aspx';</script>"); } try { courseID = int.Parse(Request.QueryString["id"]); } catch { courseID = 0; }; //if(courseID==0) // h1_type = Request.QueryString["type"].ToString().Trim(); if (!IsPostBack) { /* * CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser(); * _FileBrowser.BasePath = ResolveUrl("~/ckfinder/"); * _FileBrowser.SetupCKEditor(CKEditor1); */ #region 控件绑定 if (courseID != 0)//判断是添加还是修改 { Article ar = ArticleHelper.GetArticleByID(courseID); if (ar.Type == "学术报告:学术报告") { panelAcademic.Visible = true; initAcademinTime(); //复赋值数据库内容 string tmpConent = ar.Content; //赋值地点 txtPlace.Text = tmpConent.Split('!')[2].Split('#')[0]; //赋值时间 dplHour.Text = tmpConent.Split('!')[1].Split(':')[0]; dplMinute.Text = tmpConent.Split('!')[1].Split(':')[1]; //赋值日期 2017-04-27 dplYear.Text = tmpConent.Split('!')[0].Split('-')[0]; dplMonth.SelectedIndex = Convert.ToInt32(tmpConent.Split('!')[0].Split('-')[1]) - 1; dplDay.SelectedIndex = Convert.ToInt32(tmpConent.Split('!')[0].Split('-')[2]) - 1; } // 为控件赋值 tbTitle.Text = ar.Title; tbSubTitle.Text = ar.SubTitle; subTypes.Visible = false; dplNewsSource.Visible = false; Label11.Visible = true; Label11.Text = ar.Type; h1_type = ar.Type.Split(':')[0]; if (ar.Type.Contains("学院新闻") && (ar.isOfficial == true || ar.isOfficial == null)) { Label11.Text += "\t学院官方"; } else if (ar.Type.Contains("学院新闻")) { Label11.Text += "\t学生组织"; } DropDownList3.SelectedValue = ar.Author; DropDownList4.SelectedValue = ar.Source; if (!string.IsNullOrEmpty(ar.Link)) { CheckBox1.Checked = true; tbLink.Text = ar.Link; content.Visible = false; } else { if (ar.Type == "学术报告:学术报告") { //myEditor11.InnerHtml = ar.Content.Split('#')[1]; myEditor11.InnerHtml = ar.Content.Substring(ar.Content.IndexOf('#') + 1); } else { myEditor11.InnerHtml = ar.Content; } } CheckBox2.Checked = string.IsNullOrEmpty(ar.ImgUrl) ? false : true; cbAttach.Checked = ar.Attachment; cbHot.Checked = ar.Hot; cbTop.Checked = ar.OnTop; tyear.Text = ar.UpdateTime.Year.ToString(); tmonth.Text = ar.UpdateTime.Month.ToString(); tday.Text = ar.UpdateTime.Day.ToString(); } else// Label11.Text = Request.QueryString["type"];//文章类型 { h1_type = Request.QueryString["type"].ToString().Trim(); if (h1_type.Equals("学术报告")) { panelAcademic.Visible = true; initAcademinTime(); } tyear.Text = DateTime.Now.Year.ToString(); tmonth.Text = DateTime.Now.Month.ToString(); tday.Text = DateTime.Now.Day.ToString(); Label11.Visible = false; List <string> ls = ArticleHelper.GetSubTypes(Request.QueryString["type"], ((User)Session["User"]).UserID); if (ls.Contains("学院新闻")) { dplNewsSource.Visible = true; } subTypes.DataSource = ArticleHelper.GetSubTypes(Request.QueryString["type"], ((User)Session["User"]).UserID); subTypes.DataBind(); if (h1_type == "学术报告") { List <string> timeList = new List <string>(); for (int i = 0; i < 24; i++) { timeList.Add(i.ToString("D2")); } dplHour.DataSource = timeList; dplHour.DataBind(); timeList.Clear(); for (int i = 0; i < 60; i++) { timeList.Add(i.ToString("D2")); } dplMinute.DataSource = timeList; dplMinute.DataBind(); } } #endregion } }
protected void Button1_Click(object sender, EventArgs e) { //以用户输入构建Article对象 Article ar; if (CheckBox1.Checked) { ar = new Article { Title = tbTitle.Text, SubTitle = tbSubTitle.Text, AuthorID = ((User)Session["User"]).UserID, Author = DropDownList3.SelectedValue == "我自己" ? UserHelper.RtnName(((User)Session["User"]).UserID) : DropDownList3.SelectedValue, Source = DropDownList4.SelectedValue == "我自己" ? UserHelper.RtnName(((User)Session["User"]).UserID) : DropDownList4.SelectedValue, Link = tbLink.Text, Type = Label11.Visible ? Label11.Text : Request.QueryString["type"] + ":" + subTypes.SelectedValue,//例如:党建工作:党员发展 OnTop = cbTop.Checked, Hot = cbHot.Checked, Attachment = cbAttach.Checked, UpdateTime = GetTime(tyear.Text, tmonth.Text, tday.Text) ?? DateTime.Now, Deleted = false, Content = " ", ImgUrl = null // HiddenField1.Value == "" ? null : HiddenField1.Value,CheckBox2.Checked?GetImgUrl(CKEditor1.Text): } } ; else { string saveContent = Server.HtmlDecode(myEditor11.InnerHtml); if (Label11.Text.Equals("学术报告:学术报告") || subTypes.SelectedValue.Equals("学术报告")) { saveContent = dplYear.SelectedValue + "-" + Convert.ToInt32(dplMonth.SelectedValue).ToString("D2") + "-" + Convert.ToInt32(dplDay.SelectedValue).ToString("D2") + "!" + dplHour.SelectedValue + ":" + dplMinute.SelectedValue + "!" + txtPlace.Text.Trim() + "#" + Server.HtmlDecode(myEditor11.InnerHtml); } ar = new Article { Title = tbTitle.Text, SubTitle = tbSubTitle.Text, AuthorID = ((User)Session["User"]).UserID, Author = DropDownList3.SelectedValue == "我自己" ? UserHelper.RtnName(((User)Session["User"]).UserID) : DropDownList3.SelectedValue, Source = DropDownList4.SelectedValue == "我自己" ? UserHelper.RtnName(((User)Session["User"]).UserID) : DropDownList4.SelectedValue, Link = null, Type = Label11.Visible ? Label11.Text : Request.QueryString["type"] + ":" + subTypes.SelectedValue,//例如:党建工作:党员发展 OnTop = cbTop.Checked, Hot = cbHot.Checked, Attachment = cbAttach.Checked, UpdateTime = GetTime(tyear.Text, tmonth.Text, tday.Text) ?? DateTime.Now, Deleted = false, //Content = dplYear.SelectedValue + "-" + Convert.ToInt32(dplMonth.SelectedValue).ToString("D2") + "-" + Convert.ToInt32(dplDay.SelectedValue).ToString("D2") + "!" + dplHour.SelectedValue + ":" + dplMinute.SelectedValue + "!" + txtPlace.Text.Trim() + "#" + Server.HtmlDecode(myEditor11.InnerHtml), Content = saveContent, ImgUrl = CheckBox2.Checked ? GetImgUrl(Server.HtmlDecode(myEditor11.InnerHtml)) : null }; } //增加是否官方的新闻 if (dplNewsSource.Visible == true) { if (dplNewsSource.Text.Contains("学院官方")) { ar.isOfficial = true; } else { ar.isOfficial = false; } } // 判断是添加还是修改,修改数据库 string Pattern = @"(http|https)://[^\s]*"; Regex r = new Regex(Pattern); if (courseID == 0) { if (panelAcademic.Visible == true && string.Equals(string.Empty, txtPlace.Text.Trim())) { Response.Write(JSHelper.ShowAlert("请检查举办地点!")); } else if (tbTitle.Text.Trim() == "") { Response.Write(JSHelper.ShowAlert("标题不能为空!")); } else if (CheckBox1.Checked == true && tbLink.Text.Trim() == "") { Response.Write(JSHelper.ShowAlert("转向链接不能为空!")); } else if (CheckBox1.Checked == true && r.IsMatch(tbLink.Text.Trim()) == false) { Response.Write(JSHelper.ShowAlert("转向链接格式有误!")); } else if (CheckBox1.Checked == false && Server.HtmlDecode(myEditor11.InnerHtml).Length == 0) { Response.Write(JSHelper.ShowAlert("正文不能为空!")); } else if (ArticleHelper.AddArticle(ar)) { if (ar.Type.Equals("就业工作:招聘信息")) { CHelper.Cread(ar.ArticleID, ar.Title, ar.Type); } else { Response.Write(JSHelper.ShowAlert("添加成功")); } JSHelper.Redirect("MyArticles.aspx", true); } else { Response.Write(JSHelper.ShowAlert("添加失败")); } } else { Article tem = ArticleHelper.GetArticleByID(courseID); ar.Hit = tem.Hit; ar.ArticleID = courseID; //处理修改的时候type叠加 ar.Type = ArticleHelper.GetArticleByID(courseID).Type; if (panelAcademic.Visible = true && string.Equals(string.Empty, txtPlace.Text.Trim())) { Response.Write(JSHelper.ShowAlert("请检举办地点!")); } else if (tbTitle.Text.Trim() == "") { Response.Write(JSHelper.ShowAlert("标题不能为空!")); } else if (CheckBox1.Checked == true && tbLink.Text.Trim() == "") { Response.Write(JSHelper.ShowAlert("转向链接不能为空!")); } else if (CheckBox1.Checked == true && r.IsMatch(tbLink.Text.Trim()) == false) { Response.Write(JSHelper.ShowAlert("转向链接格式有误!")); } else if (CheckBox1.Checked == false && Server.HtmlDecode(myEditor11.InnerHtml).Length == 0) { Response.Write(JSHelper.ShowAlert("正文不能为空!")); } else if (ArticleHelper.UpdateArticle(ar)) { Response.Write(JSHelper.ShowAlert("修改成功")); JSHelper.Redirect("MyArticles.aspx", true); } else { Response.Write(JSHelper.ShowAlert("修改失败")); } } }