protected void Page_Load(object sender, EventArgs e) { if (!Convert.ToBoolean(Session["user"])) { Response.Write(JSHelper.alert("请先登录!", "login.aspx")); } }
protected void btnSubmit_Click(object sender, EventArgs e) { string username = txtUsername.Text.Trim(); string password = txtPassword.Text.Trim(); string verify = txtValidate.Text.Trim(); if (username.Equals(string.Empty)) { Response.Write(JSHelper.alert("请输入用户名!")); } else if (password.Equals(string.Empty)) { Response.Write(JSHelper.alert("请输入密码!")); } else if (verify.Equals(string.Empty) || !verify.Equals(Session["verifyCode"].ToString())) { Response.Write(JSHelper.alert("请检查验证码!")); } else if (!username.Equals(WEBCONFIG.ADMIN_USERNAME) || !password.Equals(WEBCONFIG.ADMIN_PASSWORD)) { Response.Write(JSHelper.alert("用户名或密码错误!")); } else { //Response.Write(JSHelper.alert("登录成功!", "articleList.aspx")); Session["user"] = true; Response.Redirect("articleList.aspx"); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (txtTitle.Text.Trim().Equals(string.Empty)) { Response.Write(JSHelper.alert("请输入文章标题")); } else if (txtAuthor.Text.Trim().Equals(string.Empty)) { Response.Write(JSHelper.alert("请输入文章作者")); } else if (txtSummary.Text.Trim().Equals(string.Empty)) { Response.Write(JSHelper.alert("请输入文章摘要")); } else if (txtLink.Text.Trim().Equals(string.Empty)) { Response.Write(JSHelper.alert("请输入文章链接")); } else { //检测LINK正确性 string pattern = @"(http|https)://[^\s]*"; Regex r = new Regex(pattern); if (r.IsMatch(txtLink.Text.Trim()) == false) { Response.Write(JSHelper.alert("请输入合法链接,检查链接的完整性!(http(s)://xxx)")); } else { if (Request.QueryString["id"] != null) { //更新文章 int articleId = Convert.ToInt32(Request.QueryString["id"].ToString()); if (updateArticle(articleId)) { Response.Write(JSHelper.alert("文章更新成功!", "articleList.aspx")); } else { Response.Write(JSHelper.alert("文章更新失败!请重试!")); } } else { //保存文章 if (addNewArticle()) { Response.Write(JSHelper.alert("文章添加成功!", "articleList.aspx")); } else { Response.Write(JSHelper.alert("文章添加失败!请重试!")); } } } } }
protected void gdvSecondLevel_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("delSecondLevel")) { int id = Convert.ToInt32(e.CommandArgument); if (LabelHelper.removeItem(id, "secondLevel")) { Response.Write(JSHelper.alert("删除成功!", "manageLabel.aspx")); } else { Response.Write(JSHelper.alert("删除失败,请重试!")); } } }
protected void gdvArticle_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("delAritcle")) { int id = Convert.ToInt32(e.CommandArgument); if (ArticleHelper.delArticle(id)) { Response.Write(JSHelper.alert("删除成功!", "articleList.aspx")); } else { Response.Write(JSHelper.alert("删除失败,请重试!")); } } }
protected void btnSecondLevel_Click(object sender, EventArgs e) { string secondLevelVal = txtSecondLevel.Text.Trim(); if (secondLevelVal.Equals(string.Empty)) { Response.Write(JSHelper.alert("二级分类不能为空,请重新输入!")); } else { try { using (var db = new PaperDbEntities()) { Category c = db.Category.Single(a => a.Name == dplFirstLevel.SelectedValue); Option tmp = db.Option.SingleOrDefault(a => a.Name == secondLevelVal && a.CategoryId == c.id); if (tmp == null) { Option secondLevel = new Option(); secondLevel.Name = secondLevelVal; secondLevel.CategoryId = LabelHelper.getCategoryIdByName(dplFirstLevel.SelectedValue); db.Option.Add(secondLevel); db.SaveChanges(); Response.Write(JSHelper.alert("添加成功!", "manageLabel.aspx")); } else { Response.Write(JSHelper.alert("二级分类重复,请检查!")); } } } catch (Exception ex) { //ex.Message; Response.Write(JSHelper.alert("添加失败,请重新尝试!")); } } }
protected void btnFirstLevel_Click(object sender, EventArgs e) { string firstLevelVal = txtFirstLevel.Text.Trim(); if (firstLevelVal.Equals(string.Empty)) { Response.Write(JSHelper.alert("一级分类不能为空,请重新输入!")); } else { try { using (var db = new PaperDbEntities()) { Category tmp = db.Category.SingleOrDefault(a => a.Name == firstLevelVal); if (tmp == null) { Category firstLevel = new Category(); firstLevel.Name = firstLevelVal; db.Category.Add(firstLevel); db.SaveChanges(); Response.Write(JSHelper.alert("添加成功!", "manageLabel.aspx")); } else { Response.Write(JSHelper.alert("一级分类重复,请检查!")); } } } catch (Exception ex) { //ex.Message; Response.Write(JSHelper.alert("添加失败,请重新尝试!")); } } }
protected void btnKeyword_Click(object sender, EventArgs e) { string keywordvalu = txtKeyword.Text.Trim(); if (keywordvalu.Equals(string.Empty)) { Response.Write(JSHelper.alert("关键词不能为空,请重新输入!")); } else { try { using (var db = new PaperDbEntities()) { KeyWords tmp = db.KeyWords.SingleOrDefault(a => a.Name == keywordvalu); if (tmp == null) { KeyWords keyword = new KeyWords(); keyword.Name = keywordvalu; db.KeyWords.Add(keyword); db.SaveChanges(); Response.Write(JSHelper.alert("添加成功!", "manageLabel.aspx")); } else { Response.Write(JSHelper.alert("关键词重复,请检查!")); } } } catch (Exception ex) { //ex.Message; Response.Write(JSHelper.alert("添加失败,请重新尝试!")); } } }
protected void logout_Click(object sender, EventArgs e) { Session["user"] = false; Response.Write(JSHelper.alert("登出成功!", "/")); }