protected void btnSubmit_Click(object sender, EventArgs e) { string pwd = Session["Pwd"].ToString(); int id = int.Parse(Session["id"].ToString()); DALadmin_user dal = new DALadmin_user(); admin_userEntity admin = dal.Getadmin_user(id); if (pwd == txtjPwd.Text.Trim()) { if (txtxPwd.Text.Trim() == txtrPwd.Text.Trim() && txtxPwd.Text.Trim() != "" && txtrPwd.Text.Trim() != "") { admin.UserPassword = txtxPwd.Text.Trim(); if (dal.Modadmin_user(admin) > 0) { this.Page.RegisterStartupScript("", "<script>alert('密码修改成功!')</script>"); Response.Redirect("NewsManage.aspx"); } else { this.Page.RegisterStartupScript("", "<script>alert('密码修改失败!');</script>"); } } else { this.Page.RegisterStartupScript("", "<script>alert('两次密码输入不一致!');</script>"); } } else { this.Page.RegisterStartupScript("", "<script>alert('原密码不正确!');</script>"); } }
protected void grdadmin_RowCommand(object sender, GridViewCommandEventArgs e) { int rowindex = int.Parse(e.CommandArgument.ToString()); //获取操作行的行号 string Id = grdadmin.DataKeys[rowindex].Value.ToString(); //获取操作行数据的主键Id DALadmin_user dal = new DALadmin_user(); //定义针对admin_user表的操作对象 switch (e.CommandName) //获取操作对象的命令 { case "edit": //调转到编辑页面 //Response.Redirect("StudentAdd.aspx?id=" + Id); break; case "del": //删除用户 dal.Deladmin_user(int.Parse(Id)); LoadData(); //重新加载数据,验证是否成功删除 ///Response.Write("<script>alert('数据删除成功!')</script>"); break; case "reset": //修改密码 admin_userEntity admin = dal.Getadmin_user(int.Parse(Id)); admin.UserPassword = "******"; dal.Modadmin_user(admin); LoadData(); //重新加载数据,验证是否重置 //Response.Write("<script>alert('用户密码重置成功,新密码123456')</script>"); break; } }
protected void grdadmin_RowCommand(object sender, GridViewCommandEventArgs e) { int rowindex = int.Parse(e.CommandArgument.ToString()); //获取操作行的行号 string Id = grdadmin.DataKeys[rowindex].Value.ToString(); //获取操作行数据的主键Id DALadmin_user dal = new DALadmin_user(); //定义针对admin_user表的操作对象 switch (e.CommandName) //获取操作对象的命令 { case "edit": //调转到编辑页面 Response.Redirect("AdminEdit.aspx?id=" + Id); break; case "del": //删除用户 dal.Deladmin_user(int.Parse(Id)); LoadData(); //重新加载数据,验证是否成功删除 ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('数据删除成功!');location.href='AdminList.aspx';</script>"); break; case "reset": //修改密码 admin_userEntity admin = dal.Getadmin_user(int.Parse(Id)); admin.UserPassword = "******"; dal.Modadmin_user(admin); LoadData(); //重新加载数据,验证是否重置 ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('用户密码重置成功,新密码123456');location.href='AdminList.aspx';</script>"); break; } }
protected void Submit_Click(object sender, EventArgs e) { string name = login_username.Value; string pwd = login_password.Value; if (rbtnType.SelectedIndex == 0) { DALadmin_user dal = new DALadmin_user(); IList <admin_userEntity> admins = dal.Getadmin_usersbyCondition(" userName='******' and userPassword='******'"); if (admins.Count > 0) { string trueName = admins[0].TrueName.ToString(); int id = admins[0].Id; //修改登录次数 admin_userEntity admin = dal.Getadmin_user(id); admin.LoginTimes++; dal.Modadmin_user(admin); Session["adminID"] = name; Session["TrueName"] = trueName; Session["Pwd"] = pwd; Session["id"] = id; Response.Redirect("NewsManage.aspx"); } else { this.Page.RegisterStartupScript("", "<script>alert('登录失败!');</script>"); } } else if (rbtnType.SelectedIndex == 1) { DALstudent_info dal = new DALstudent_info(); IList <student_infoEntity> stus = dal.Getstudent_infosbyCondition(" studentId='" + name + "' and studentPassword='******'"); if (stus.Count > 0) { int id = stus[0].Id; string phone = stus[0].StudentPhoto; string trueName = stus[0].StudentName.ToString(); Session["studentID"] = name; Session["StudentName"] = trueName; Session["id"] = id; Session["Pwd"] = pwd; //Session["phone"] = phone; Response.Redirect("NewsList.aspx"); } else { this.Page.RegisterStartupScript("", "<script>alert('登录失败!');</script>"); } } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { DALadmin_user dal = new DALadmin_user(); //定义针对admin_user表的操作对象 string Id = GridView1.DataKeys[e.RowIndex].Value.ToString(); //获取操作行数据的主键Id admin_userEntity admin = dal.Getadmin_user(int.Parse(Id)); admin.UserName = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim(); admin.TrueName = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim(); admin.LinkTelephone = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim(); dal.Modadmin_user(admin); GridView1.EditIndex = -1; LoadData();//重新加载数据,验证是否重置 }
/// <summary> ///行内命令被触发的时候执行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int rowindex = int.Parse(e.CommandArgument.ToString()); //获取操作行的行号 string Id = GridView1.DataKeys[rowindex].Value.ToString(); //获取操作行数据的主键Id DALadmin_user dal = new DALadmin_user(); //定义针对admin_user表的操作对象 if (e.CommandName == "reset") { admin_userEntity admin = dal.Getadmin_user(int.Parse(Id)); admin.UserPassword = "******"; dal.Modadmin_user(admin); LoadData();//重新加载数据,验证是否重置 this.Page.RegisterStartupScript("a", "<script>alert('用户密码重置成功');</script>"); } }
//public void LoadData() //{ // string bian = Session["uName"].ToString(); // string conditon = string.Empty; // if (!string.IsNullOrEmpty(bian)) // { // conditon += "UserName='******'"; // } // DALadmin_user dal = new DALadmin_user(); // IList<admin_userEntity> ad = dal.Getadmin_usersbyCondition(conditon); // if (ad.Count != 0) // { //判断是否为空 // for (int i = 0; i < ad.Count(); i++) // { //for循环将数据逐一获取到 // admin_userEntity defCodeInfoResDto = ad[i]; // } // int j = ad[1].Id; // admin_userEntity admin = dal.Getadmin_user(j); // ViewState["admin"] = admin;//在当前页缓存数据。 // UserId.Value = admin.UserName;//加载显示数据 // //Password1.Value = admin.UserPassword; // } //} protected void btnedit_Click(object sender, EventArgs e) { DALadmin_user dal = new DALadmin_user(); admin_userEntity admin = (admin_userEntity)ViewState["user"];//获取缓存数据 if (admin.UserPassword == Password1.Value) { admin.UserPassword = L_repass.Value; dal.Modadmin_user(admin);//提交到数据库 ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('修改成功!');</script>"); } else { ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('修改失败,请检查密码正确性!');</script>"); } }