protected void Page_Load(object sender, EventArgs e) { if (Session["username"] != null) { if (!IsPostBack) { try { int id = Convert.ToInt32(Request.QueryString["id"]); using (var db = new ITShowEntities()) { Message message = db.Message.SingleOrDefault(a => a.MessageId == id); txtReply.Text = message.MessageComment; } } catch { Response.Write("<script>alert('地址栏错误!');location='index.aspx'</script>"); } } } else { Response.Write("<script>alert('尚未登陆!');location='Login.aspx'</script>"); } }
protected void btnGetNumber_Click(object sender, EventArgs e) { Random rd = new Random(); int number = rd.Next(1000, 10000); Session["number"] = number; Session["time"] = DateTime.Now.ToString(); using (var db = new ITShowEntities()) { string username = Session["name2"].ToString(); Admin admin = db.Admin.SingleOrDefault(a => a.AdminName == username); try { Library.DAL.Send.Sendemails("*****@*****.**", admin.AdminEmail, "修改密码", "本次操作验证码为'" + number + "'请在20分钟内完成验证!"); } catch (Exception ex) { Response.Write("<script>alert('未联网');location='Login.aspx'</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Write("<script>alert('尚未登录!');location='Login.aspx'</script>"); } else { using (var db = new ITShowEntities()) { string username = Session["username"].ToString(); Admin admin = db.Admin.SingleOrDefault(a => a.AdminName == username); //超级管理员才能使用此功能 if (admin.AdminId != 3) { Response.Write("<script>alert('你没有权限使用此功能!');location='Admin-role.aspx'</script>"); } } if (!IsPostBack) { RptDataBind(1, data()); } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Write("<script>alert('尚未登录!');location='Login.aspx'</script>"); } else { if (!IsPostBack) { 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 ITShowEntities()) { Works person = (from it in db.Works where it.WorksId == id select it).FirstOrDefault(); if (person != null) { txtTitle.Text = person.WorksName; txtLink.Text = person.WorksUrl; txtTime.Value = person.WorksTime.ToString(); btnImage.ImageUrl = person.WorksImage.Trim(); if (Request.Cookies["arr"] != null) { txtTitle.Text = Server.UrlDecode(Request.Cookies["arr"]["title"]); txtLink.Text = Server.UrlDecode(Request.Cookies["arr"]["link"]); txtTime.Value = Server.UrlDecode(Request.Cookies["arr"]["time"]); HttpCookie cookies = Request.Cookies["arr"];//删除cookies cookies.Expires = System.DateTime.Now.AddDays(-1); Response.Cookies.Add(cookies); } if (Request.Cookies["url"] != null) { btnImage.ImageUrl = Request.Cookies["url"].Value; HttpCookie cookies1 = Request.Cookies["url"];//删除cookies cookies1.Expires = System.DateTime.Now.AddDays(-1); Response.Cookies.Add(cookies1); } } else { Response.Write("<script>alert('地址栏有误');location='WorksList.aspx'</script>"); } } } else { Response.Write("<script>alert('地址栏有误');location='WorksList.aspx'</script>"); } } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Write("<script>alert('尚未登录!');location='Login.aspx'</script>"); } else { if (!IsPostBack) { using (var db = new ITShowEntities()) { List <Application> person; person = (from it in db.Application orderby it.Time descending select it).ToList(); Session["ds"] = person; lbcount.Text = person.Count.ToString();//报名总数量 DataBindToRepeater(1, (List <Application>)Session["ds"]); } } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (txtGradeMajor.Value.Length > 0 && txtQQ.Value.Length > 0 && txtName.Value.Length > 0 && txtTel.Value.Length > 0 && Request.Form["txtIntroduction"].Length > 0 && txtDepart.Value.Length > 0) { string name = txtName.Value; string tel = txtTel.Value; string gradeMajor = txtGradeMajor.Value; string introduction = Request.Form["txtIntroduction"]; int depart = Convert.ToInt32(txtDepart.Value); IPManager manager = new IPManager();//查看IP是否用得频繁 string IPAddress = manager.GetClientIPv4Address(); XmlManager xmanager = new XmlManager(); int ans = xmanager.Editor(IPAddress); if (ans > 0) //能否写入IP { if (ans == 1) //该IP十秒内无操作 { xmanager.Add(IPAddress); //如果没有这个IP,就加入记录 using (var db = new ITShowEntities()) { Application person = new Application(); person.Name = name; person.GradeMajor = gradeMajor; person.Telephone = tel; person.Introdution = introduction; person.Time = Convert.ToDateTime(DateTime.Now.ToString()); person.QQ = txtQQ.Value; switch (depart) { case 1: person.Department = "前端开发"; break; case 2: person.Department = "程序开发"; break; case 3: person.Department = "UI设计"; break; case 4: person.Department = "APP开发"; break; } db.Application.Add(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('报名成功,欢迎加入爱特交流群,群号:245775349');location='ApplicationFormMobile.aspx'</script>"); } else { Response.Write("<script>alert('报名失败请重试');location='ApplicationFormMobile.aspx'</script>"); } } } else { Response.Write("<script>alert('操作过于频繁请10秒后再操作');location='ApplicationFormMobile.aspx'</script>"); } } else { Response.Write("<script>alert('操作失败请重试');location='ApplicationFormMobile.aspx'</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Write("<script>alert('尚未登录!');location='Login.aspx'</script>"); } else { using (var db = new ITShowEntities()) { string username = Session["username"].ToString(); Admin admin = (from it in db.Admin where it.AdminName == username select it).FirstOrDefault(); img.ImageUrl = admin.AdminImage.Trim(); if (admin.Flag == false) { lbemail.Visible = true; } else { lbemail.Visible = false; } } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Write("<script>alert('尚未登录!');location='Login.aspx'</script>"); } else { if (!IsPostBack) { using (var db = new ITShowEntities()) { var person = (from it in db.Member select it); lbcount.Text = person.ToList().Count.ToString();//找出所有的成员的人数 var person1 = from it in db.Member where it.MemberYear == "2016" select it; Session["ds"] = person1.ToList(); } DataBindToRepeater(1);//显示16届成员 } } }
protected void lbemail_Click(object sender, EventArgs e) { Random ran = new Random(); int number = ran.Next(1000, 9999); Session["number"] = number; using (var db = new ITShowEntities()) { string username = Session["username"].ToString(); Admin admin = (from it in db.Admin where it.AdminName == username select it).FirstOrDefault(); try { Library.DAL.Send.Sendemails("*****@*****.**", admin.AdminEmail, "验证邮箱", "邮箱验证码为'" + number + "'"); divemail.Visible = true; Response.Write("<script>alert('验证码发送成功!')</script>"); } catch (Exception ex) { Response.Write("<script>alert('未联网');location='Login.aspx'</script>"); } } }
protected void btnemail_Click(object sender, EventArgs e) { if (Convert.ToInt32(Session["number"].ToString()) == Convert.ToInt32(txtemail.Text)) { using (var db = new ITShowEntities()) { string username = Session["username"].ToString(); Admin admin = (from it in db.Admin where it.AdminName == username select it).FirstOrDefault(); admin.Flag = true; db.SaveChanges(); divemail.Visible = false; Response.Write("<script>alert('验证成功!');location='Welcome.aspx'</script>"); } } else { Response.Write("<script>alert('验证码错误!')</script>"); } }
protected void RptDataBind(int currentPage) { using (var db = new ITShowEntities()) { var datascore = from it in db.Admin orderby it.AdminId select it; PagedDataSource pds = new PagedDataSource(); pds.AllowPaging = true; pds.PageSize = 5; pds.DataSource = datascore.ToList(); AdminCount = datascore.Count(); // lbTotal.Text = pds.PageCount.ToString(); pds.CurrentPageIndex = currentPage - 1;//当前页数从零开始,故把接受的数减一 rptAdmin.DataSource = pds; rptAdmin.DataBind(); } }
protected void btnpassword_Click(object sender, EventArgs e) { string username = Request.QueryString["username"]; if (RequiredFieldValidator2.IsValid == true && CompareValidator1.IsValid == true) { if (txtPwd.Text.Length >= 8) { string pwd = Class1.md5(txtPwd.Text, 32); using (var db = new ITShowEntities()) { Admin admin = db.Admin.SingleOrDefault(a => a.AdminName == username); admin.AdminPassword = pwd; if (db.SaveChanges() == 1) { Response.Write("<script>alert('修改成功')</script>"); } else { Response.Write("<script>alert('修改失败请重试')</script>"); } } } else { Response.Write("<script>alert('密码长度不够!')</script>"); } } }
protected void btnemail_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); string email = txtemail.Text; using (var db = new ITShowEntities()) { Admin admin = db.Admin.SingleOrDefault(a => a.AdminId == id); if (email == admin.AdminEmail) { Response.Write("<script>alert('邮箱相同')</script>"); } else { admin.AdminEmail = email; if (db.SaveChanges() == 1) { Response.Write("<script>alert('修改成功')</script>"); } else { Response.Write("<script>alert('修改失败请重试')</script>"); } } } }
protected void BtnFound_Click2(object sender, EventArgs e) { Random ran = new Random(); int id = ran.Next(0, 3); string name = username.Text; Session["name2"] = name; using (var db = new ITShowEntities()) { Admin admin = db.Admin.SingleOrDefault(a => a.AdminName == name); if (admin != null) { var question = from it in db.Question where it.AdminId == admin.AdminId select it; List <Question> dt = question.ToList(); question1.Text = dt[id].Question1; Session["answer"] = dt[id].Answer; divfoundback2.Visible = false; divfoundback3.Visible = true; } else { Response.Write("<script>alert('用户名不正确!')</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { Session["url"] = null; Session["arr"] = null;//清空储存编辑信息session if (Session["username"] == null) { Response.Write("<script>alert('尚未登录!');location='Login.aspx'</script>"); } else { if (!IsPostBack) { using (var db = new ITShowEntities()) { var person = (from it in db.Works select it); Session["ds"] = person.ToList(); lbcount.Text = person.ToList().Count.ToString(); DataBindToRepeater(1, (List <Works>)Session["ds"]); } } } }
protected void BtnReply_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); if (txtReply.Text.Trim().Length > 0) { using (var db = new ITShowEntities()) { if (txtReply.Text.Trim().Length > 90) { Response.Write("<script>alert('字数超过限制')</script>"); } else { Message message = db.Message.SingleOrDefault(a => a.MessageId == id); message.MessageComment = txtReply.Text.Trim(); message.MessageAdminName = Session["username"].ToString(); db.SaveChanges(); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script >alert('回复成功');layer_close();</script>"); } } } }
protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "delete") { int id = Convert.ToInt32(e.CommandArgument); using (var db = new ITShowEntities()) { Works person = (from it in db.Works where it.WorksId == id select it).FirstOrDefault(); db.Works.Remove(person); if (db.SaveChanges() == 1) { Response.Write("<script>alert('删除成功');location='WorksList.aspx'</script>"); } else { Response.Write("<script>alert('删除失败请重试');location='WorksList.aspx'</script>"); } } } //if (e.CommandName == "URL") //{ // //string url = Server.UrlEncode (e.CommandArgument.ToString().Trim()); // string url = e.CommandArgument.ToString().Trim(); // Response.Write("<script>window.open('http://www.baidu.com','_blank')</script>"); //} }
protected void rptAdmin_ItemCommand(object source, RepeaterCommandEventArgs e) { int id = Convert.ToInt32(e.CommandArgument); //删除对应管理员,超级管理员不能删除自己 if (id == 3) { Response.Write("<script>alert('你没有权限删除此管理员!');location='Admin-list.aspx'</script>"); } else { if (e.CommandName == "Delete") { using (var db = new ITShowEntities()) { Admin admin = db.Admin.SingleOrDefault(a => a.AdminId == id); db.Admin.Remove(admin); db.SaveChanges(); } Response.Write("<script>window.location='Admin-list.aspx'</script>"); } } }
protected void BtnLogin_Click(object sender, EventArgs e) { if (Session["CheckCode"] != null) { string checkcode = Session["CheckCode"].ToString(); if (this.TextBox1.Text == checkcode) { using (var db = new ITShowEntities()) { string password = Class1.md5(passWord.Text, 32); Admin admin = db.Admin.SingleOrDefault(a => a.AdminName == userName.Text.Trim() && a.AdminPassword == password); if (admin == null) { passWord.Text = "密码"; Response.Write("<script>alert('用户名或密码错误!')</script>"); } else { if (Session["username"] != null) { Session["username"] = userName.Text.Trim(); Response.Write("<script>alert('登录成功!');location='index.aspx'</script>"); } else { if (checkRemember.Checked) { HttpCookie userInfo = new HttpCookie("admin1"); //明文??? userInfo.Values["name"] = userName.Text; userInfo.Values["password"] = passWord.Text; userInfo.Expires = DateTime.Now.AddDays(15); // 15天记住我 Response.Cookies.Add(userInfo); } else { HttpCookie cookie = Response.Cookies["admin1"]; cookie.Expires = DateTime.Now.AddDays(-1); } Session["username"] = userName.Text.Trim(); Response.Write("<script>alert('登录成功!');location='index.aspx'</script>"); } } } } else { passWord.Text = "密码"; ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!')", true); } } }
protected void ReturnList() { using (var db = new ITShowEntities()) { var datascore = from it in db.Message orderby it.MessageTime descending select it; Session["list"] = datascore.ToList(); } }
protected void btnAdd_Click(object sender, EventArgs e) { string year = dropYear.SelectedValue;//届数 string name = txtName.Text.Trim(); string department = dropDepartment.SelectedValue; string grade = dropGrade.SelectedValue; string instruction = txtIntruduction.Text; string hobby = txtHobby.Text; //string image =; if (name.Length > 0 && img.ImageUrl.Length > 0) { using (var db = new ITShowEntities()) { Member person = new Member() { MemberDepartment = department, MemberGrade = grade, MemberName = name, MemberImage = img.ImageUrl, MemberYear = year, MemberInstruction = instruction, MemberInterest = hobby, }; db.Member.Add(person); if (db.SaveChanges() == 1) { ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script >alert('添加成功');layer_close();</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
// protected List <Admin> data() { using (var db = new ITShowEntities()) { var datascore = from it in db.Admin orderby it.AdminId select it; return(datascore.ToList()); } }
protected void btnEditor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); string title = txtTitle.Text.Trim(); string link = txtLink.Text.Trim(); string url = btnImage.ImageUrl.Trim();//图片 string Pattern = @"(http|https)://[^\s]*"; Regex r = new Regex(Pattern); if (title.Length > 0 && url.Length > 0 && link.Length > 0) { if (r.IsMatch(link)) { using (var db = new ITShowEntities())//修改 { Works person = (from it in db.Works where it.WorksId == id select it).FirstOrDefault(); if (person.WorksName == title && person.WorksImage == btnImage.ImageUrl && person.WorksUrl == link) { Response.Write("<script>alert('未修改');location='WorksList.aspx'</script>"); } else { person.WorksName = title; person.WorksUrl = link; person.WorksImage = url; if (db.SaveChanges() == 1) { Response.Write("<script>alert('编辑成功');location='WorksList.aspx'</script>"); } else { Response.Write("<script>alert('编辑失败请重试')</script>"); } } } } else { Response.Write("<script>alert('请输入有效URL,http/https格式')</script>"); } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void rptComment_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "Delete") { int idComment = Convert.ToInt32(e.CommandArgument); using (var db = new ITShowEntities()) { Message message = db.Message.SingleOrDefault(a => a.MessageId == idComment); db.Message.Remove(message); db.SaveChanges(); } Response.Write("<script>window.location='Comment-list.aspx'</script>"); } }
protected void BtnReply_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); using (var db = new ITShowEntities()) { Message message = db.Message.SingleOrDefault(a => a.MessageId == id); message.MessageComment = Server.HtmlDecode(myEditor.InnerText); message.MessageAdminName = Session["username"].ToString(); db.SaveChanges(); } }
protected void btnAdd_Click(object sender, EventArgs e) { string title = txtTitle.Text.Trim(); string link = txtLink.Text.Trim(); string Pattern = @"(http|https)://[^\s]*"; string time = txtTime.Value; Regex r = new Regex(Pattern); if (link.Length > 0 && time.Length > 0 && title.Length > 0 && img.ImageUrl.Length > 0)//都不能为空 { if (r.IsMatch(link)) { using (var db = new ITShowEntities()) { Works person = new Works() { WorksName = title, WorksUrl = link, WorksTime = Convert.ToDateTime(time), WorksImage = img.ImageUrl }; db.Works.Add(person); if (db.SaveChanges() == 1) { ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script >alert('添加成功');layer_close();</script>"); } else { Response.Write("<script>alert('添加失败请重试')</script>"); } } } Response.Write("<script>alert('请输入有效URL,http/https格式')</script>"); } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void btnEditor_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); string name = txtName.Text.Trim(); string instruction = txtIntruduction.Text; if (name.Length > 0 && instruction.Length > 0 && btnImage.ImageUrl.Length > 0) { using (var db = new ITShowEntities())//修改 { Member person = (from it in db.Member where it.MemberId == id select it).FirstOrDefault(); if (person.MemberImage == btnImage.ImageUrl && person.MemberInstruction == instruction && person.MemberName == name && person.MemberDepartment == dropDepartment.SelectedValue) { Response.Write("<script>alert('未修改');location='MemberList.aspx'</script>"); } else { if (instruction.Length > 40) { Response.Write("<script>alert('字数超过限制')</script>"); } else { person.MemberName = name; person.MemberDepartment = dropDepartment.SelectedValue; person.MemberImage = btnImage.ImageUrl;//修改图片 person.MemberYear = dropYear.SelectedValue; person.MemberInstruction = instruction; if (db.SaveChanges() == 1) { Response.Write("<script>alert('编辑成功');location='MemberList.aspx'</script>"); } else { Response.Write("<script>alert('编辑失败请重试')</script>"); } } } } } else { Response.Write("<script>alert('不能为空')</script>"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Write("<script>alert('尚未登录!');location='Login.aspx'</script>"); } else { if (!IsPostBack) { if (Session["Mds"] != null) { year.SelectedValue = Server.UrlDecode(Request.Cookies["year"]["year"]); if (Session["page"] != null) { DataBindToRepeater(Convert.ToInt32(Session["page"])); } else { DataBindToRepeater(1); } } else { using (var db = new ITShowEntities()) { var person = (from it in db.Member select it); lbcount.Text = person.ToList().Count.ToString();//找出所有的成员的人数 var person1 = from it in db.Member where it.MemberYear == "2016" select it; Session["Mds"] = person1.ToList(); HttpCookie cookie = new HttpCookie("year"); cookie.Values["year"] = "2016"; cookie.Expires = System.DateTime.Now.AddMinutes(6); Response.Cookies.Add(cookie); lbcount1.Text = person1.ToList().Count.ToString();//每届的人员的人数 } DataBindToRepeater(1);//显示16届成员 } } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Write("<script>window.location='Login.aspx'</script>"); } else { using (var db = new ITShowEntities()) { var message = from it in db.Message where (it.MessageComment == null) select it; if (message.Count() != 0) { lbMessage.Text = message.Count().ToString(); } } } }
private void ExportDataGrid(string Job, string FileType, string FileName) //从DataGrid导出 { System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid(); //DataSet dg = new DataSet(); using (var db = new ITShowEntities()) { List <Application> dt; if (Job == "全部") { dt = (from it in db.Application select it).ToList(); } else { dt = (from it in db.Application where it.Department == Job select it).ToList(); } dg.DataSource = dt; //DataTable ds = LINQToDataTable(dt); //dg.Tables.Add(ds); //CreateExcel(ds, FileType, FileName); } dg.DataBind(); //定义文档类型、字符编码 Response.Clear(); Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.Charset = "UTF-8"; Response.ContentEncoding = Encoding.Default; Response.ContentType = FileType; dg.EnableViewState = false; //定义一个输入流 StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); //目标数据绑定到输入流输出 dg.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); }