预约系统(五) 管理页面框架 密码修改和用户信息功能

密码修改功能:

1.点击弹出一个dialog(easyui),弹出之前发送ajax请求获取旧的密码;

2.密码更新,发送ajax请求给后台,后台更新到数据库,返回值,前台根据返回值做判断。

前台密码修改js代码:(参考easyui API文档)

 1 //密码修改
 2     $("#pass_edit").click(function () {
 3         //
 4         $.messager.confirm('确认', '您确认要修改密码?', function (r) {
 5             if (r) {
 6                 //
 7                 $('#dd_pass').dialog({
 8                     title: '密码修改',
 9                     onBeforeOpen: function () {
10                         //
11                         $.ajax({
12                             url: "/Home/getOldPass",
13                             success: function (data) {
14                                 if (data.length > 0) {
15                                     $("#oldpassword").textbox("setText", data);
16                                 }
17                             }
18                         })
19                     },
20                     buttons: [{
21                         text: '更新',
22                         handler: function () {
23                             //
24 
25                             $.messager.confirm("确认", "确定要更新?", function (r) {
26                                 if (r) {
27                                     var new_pass = $("#pass_new").textbox("getText");
28                                     var new_re = $("#new_re").textbox("getText");
29 
30                                     if (new_pass == "" || new_re == "") {
31                                         $.messager.alert('警告', '新密码不能为空');
32                                         return;
33                                     }
34                                     //alert(new_pass + "," + new_re);
35                                     if (new_pass != new_re) {
36                                         $.messager.alert('警告', '两次输入的密码要一致!');
37                                         return;
38                                     }
39                                     //更新
40                                     $.ajax({
41                                         url: "/Home/Update_Password",
42                                         type: "post",
43                                         data: {
44                                             "password": $("#new_re").textbox("getText")
45                                         },
46                                         success: function (data) {
47                                             if (data == "ok") {
48                                                 $.messager.alert("提示", "修改成功!", "info", function () {
49                                                     $('#dd_pass').dialog('close');
50                                                     //***
51                                                 });
52                                             }
53                                             else {
54                                                 $.messager.alert("提示", "更新失败,系统异常!", "info");
55                                             }
56                                         }
57 
58                                     })
59                                 }
60                             });
61                         }
62                     }, {
63                         text: '关闭',
64                         handler: function () {
65                             //
66                             $('#dd_pass').dialog('close');
67                         }
68                     }],
69                     modal: true
70                 });
71 
72             }
73         });
74     })

密码修改功能中发送了两个ajax请求,一个是获取旧的密码,一个是更新密码。

获取旧的密码在Home控制器中的getOldPass()方法,从session中获取密码:

1 public ActionResult getOldPass()
2         {
3             //
4             string password = ((T_UserInfo)Session["UserInfo"]).UserPassword;
5             return Content(password);
6         }

更新密码也是在Home控制器中的Update_Password()方法,从session中获取用户信息的id值,从前台获取修改的密码,然后调用 BLL中的UserInfoService的Update_Pass方法,Dal中的UserInfoDal的Update_Pass方法。

Home控制中的Update_Password():

 1 public ActionResult Update_Password()
 2         {
 3             if (Session["userInfo"] != null)
 4             {
 5                 int id = ((T_UserInfo)Session["UserInfo"]).Id;
 6                 string password = Request["password"];
 7 
 8                 if (new UserInfoService().Update_Pass(id, password) > 0)
 9                 {
10                     return Content("ok");
11                 }
12                 else
13                 {
14                     return Content("no");
15                 }
16             }
17             else
18             {
19                 return Content("no");
20             }
21         }

UserInfoService的Update_Pass:

1 public int Update_Pass(int id, string userPassword)
2         {
3             return userInfoDal.Update_Pass(id, userPassword);
4         }

UserInfoDal的Update_Pass:

 1 public int Update_Pass(int id, string userPassword)
 2         {
 3             string sql = " update T_userInfo set userPassword=@userPassword where id=@id ";
 4             SqlParameter[] pars ={
 5                                       new SqlParameter("@userPassword",SqlDbType.NVarChar,50),
 6                                       new SqlParameter("@id",SqlDbType.Int)
 7                                   };
 8             pars[0].Value = userPassword;
 9             pars[1].Value = id;
10             return SqlHelper.ExcuteSQLReturnInt(sql, CommandType.Text, pars);
11         }

显示用户信息功能:

easyui dialog弹出,显示用户的相关信息

前台js:

 1 //用户信息
 2     $("#user_info").click(function () {
 3         //
 4         $('#dd_userinfo').dialog({
 5             title: '用户信息',
 6             onBeforeOpen: function () {
 7                 //
 8                 $.ajax({
 9                     url: "/Home/getUserInfo",
10                     success: function (data) {
11                         if (data.length > 0) {
12                             //$("#oldpassword").textbox("setText", data);
13                             var array = data.split('&');
14                             $("#user_name").textbox("setText", array[0]);
15                             $("#user_email").textbox("setText", array[1]);
16                             $("#user_fullname").textbox("setText", array[2]);
17                             $("#user_bm").textbox("setText", array[3]);
18                         }
19                     }
20                 })
21             },
22             buttons: [
23                 {
24                     text: '关闭',
25                     handler: function () {
26                         //
27                         $('#dd_userinfo').dialog('close');
28                     }
29                 }],
30             modal: true
31         });
32     })

发送了一个ajax请求,在Home控制器中的getUserInfo()方法,都是从session中取值的:

 1 public ActionResult getUserInfo()
 2         {
 3             string username = ((T_UserInfo)Session["UserInfo"]).UserName;
 4             string userEmail = ((T_UserInfo)Session["UserInfo"]).UserEmail;
 5             string bm = ((T_UserInfo)Session["UserInfo"]).User_BM;
 6             string fullname = ((T_UserInfo)Session["UserInfo"]).User_FullName;
 7 
 8             string result = username + "&" + userEmail + "&" + fullname + "&" + bm;
 9             return Content(result);
10         }
原文地址:https://www.cnblogs.com/youguess/p/7169981.html