Exemple #1
0
 protected void lvUserMgr_ItemCommand(object sender, ListViewCommandEventArgs e)
 {
     //检查命令名称
     //更新数据
     if (e.CommandName == "UpdateById")
     {
         //当前角色id
         Int16 roleId = Convert.ToInt16(Session["role_id"]);
         //检测是否有权限
         if (roleId < 0 || roleId > 2)
         {
             throw new Exception("您没有更改记录的权限!");
         }
         //当前行
         var itm = e.Item;
         //全部文本框
         var ddlProc = (DropDownList)itm.FindControl("ddlProc");
         var txtUserId = (TextBox)itm.FindControl("txtUserId");
         var txtUserName = (TextBox)itm.FindControl("txtUserName");
         var txtUserPwd = (TextBox)itm.FindControl("txtUserPwd");
         var txtUserRemark = (TextBox)itm.FindControl("txtUserRemark");
         var txtPwdErrTimes = (TextBox)itm.FindControl("txtPwdErrTimes");
         //获取值
         var iProc = Convert.ToByte(ddlProc.SelectedValue);
         var iUserId = Convert.ToInt16(txtUserId.Text);
         var sUserName = txtUserName.Text;
         var sUserPwd = txtUserPwd.Text;
         var sUserPwdOld = txtUserPwd.Attributes["oldpwd"];
         if (!sUserPwd.Equals(sUserPwdOld))
         {
             //密码如果有修改就使用两次md5加密
             sUserPwd = ydPublicMethod.GetMd5(ydPublicMethod.GetMd5(sUserPwd));
         }
         var sUserRemark = txtUserRemark.Text;
         if (txtPwdErrTimes.Text.Trim().Length == 0)
         {
             txtPwdErrTimes.Text = "0";
         }
         var iPwdErrTimes = Convert.ToByte(txtPwdErrTimes.Text);
         var iId = Convert.ToInt32(e.CommandArgument);
         //数据适配器
         using (var da = new t_userTableAdapter())
         {
             try
             {
                 //执行更新
                 da.UpdateById(iProc, iUserId, sUserName, sUserPwd, sUserRemark, iPwdErrTimes, iId);
                 //设置当前编辑的行索引号
                 lvUserMgr.EditIndex = -1;
                 //重新绑定数据
                 lvUserMgr.DataBind();
             }
             catch { }
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// 更改部门名称后就刷新到该部门的数据
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void ddlProc_SelectedIndexChanged(object sender, EventArgs e)
 {
     //获取Session中保存的用户id
     Int16 userId = Int16.Parse(Session["user_id"].ToString());
     //当前用户选择的部门id
     byte procId = Byte.Parse(ddlProc.SelectedValue);
     //通过选择的部门id以及当前用户id获取用户权限
     using (var da = new v_user_proc_roleTableAdapter())
     {
         //获取数据
         var tab = da.GetDataByUserIdAndProcId(userId, procId);
         //检测有无数据
         if (tab != null && tab.Rows.Count > 0)
         {
             //只取首行
             var row = (DataSetUserProcRole.v_user_proc_roleRow)tab.Rows[0];
             //清除之前保存的全部session
             Session.Clear();
             //将用户名id写入Session
             Session["user_id"] = row.u_id;
             //将用户名写入Session
             Session["user_name"] = row.u_name;
             //将部门id写入Session
             Session["proc_id"] = row.proc_id;
             //将部门名称写入Session
             Session["proc_name"] = row.proc_name;
             //将角色id写入Session
             Session["role_id"] = row.ro_id;
             //更新最后一次部门名称
             using (var da2 = new t_userTableAdapter())
             {
                 da2.UpdateLastProcByUserId(row.proc_name, row.u_id);
             }
             //刷新页面
             StringBuilder sb = new StringBuilder();
             sb.AppendLine("<script type=\"text/javascript\">");
             sb.AppendLine("this.top.location.replace(this.top.location.href);");
             sb.AppendLine("this.top.document.title=\"" + ddlProc.SelectedItem.Text + "部门管理系统\";");
             sb.AppendLine("</script>");
             Response.Write(sb.ToString());
         }
     }
 }
Exemple #3
0
 protected void btnAccept_Click(object sender, EventArgs e)
 {
     //取得客户输入的验证码
     string strCode = txtCode.Text;
     //之前生成的验证码已经过期或不存在
     object strCode2 = Session["check_code"];
     if (strCode2 == null || strCode.ToString().ToLower() != strCode2.ToString().ToLower())
     {
         //显示验证码输入错误
         ydAlertMessage.AlertMessage("验证码输入错误或已经过期,请重新输入!");
         txtCode.Text = "";
         txtOldPwd.Focus();
         return;
     }
     else
     {
         //更换验证码为随机数
         Session["check_code"] = (new Random()).Next().ToString();
     }
     //实例化更新用户表的类
     var da = new t_userTableAdapter();
     //获取用户id
     Int16 id = Int16.Parse(ddlUser.SelectedValue);
     //获取用户输入的旧密码
     string oldPwd = ydPublicMethod.GetMd5(ydPublicMethod.GetMd5(txtOldPwd.Text));
     //用户输入的新密码
     string newPwd = ydPublicMethod.GetMd5(ydPublicMethod.GetMd5(txtNewPwd.Text));
     //待返回的值
     string strError = string.Empty;
     //执行更新
     if (da.UpdateUserPwdByUserIdAndPwd(newPwd, id, oldPwd) > 0)
     {
         ydAlertMessage.AlertMessage("修改成功");
         //将导向的网页路径
         Response.Redirect("~/Shared/Success.aspx?msg=修改密码成功!", true);
     }
     else
     {
         ydAlertMessage.AlertMessage("修改失败!可能旧密码不正确!");
     }
 }
Exemple #4
0
 protected void ddlProc_DataBound(object sender, EventArgs e)
 {
     //获取Session中保存的用户id
     Int16 userId = Int16.Parse(Session["user_id"].ToString());
     //当前用户选择的部门id
     object obj = Session["proc_id"];
     //通过选择的部门id以及当前用户id获取用户权限
     using (var da = new v_user_proc_roleTableAdapter())
     {
         //保存查询数据的表
         DataSetUserProcRole.v_user_proc_roleDataTable tab;
         //检测部门id号
         byte procId;
         if (obj != null && byte.TryParse(obj.ToString(), out procId) && procId != byte.MaxValue)
         {
             //获取数据
             tab = da.GetDataByUserIdAndProcId(userId, procId);
         }
         else
         {
             //获取数据
             tab = da.GetDataByUserId(userId);
         }
         //检测有无数据
         if (tab != null && tab.Rows.Count > 0)
         {
             //只取首行
             var row = (DataSetUserProcRole.v_user_proc_roleRow)tab.Rows[0];
             //设置用户名和部门名称
             ltlUser.Text = row.u_name;
             //清除之前保存的全部session
             Session.Clear();
             //将用户名id写入Session
             Session["user_id"] = row.u_id;
             //将用户名写入Session
             Session["user_name"] = row.u_name;
             //将部门id写入Session
             Session["proc_id"] = row.proc_id;
             //将部门名称写入Session
             Session["proc_name"] = row.proc_name;
             //将角色id写入Session
             Session["role_id"] = row.ro_id;
             //取得是否部门名称
             using (var da2 = new t_procTableAdapter())
             {
                 //获取全部部门清单
                 var tab2 = da2.GetDataByProductProcName(row.proc_name);
                 //检测结果
                 if (tab2.Rows.Count <= 0)
                 {
                     //改变为部门
                     litProc.Text = "部门";
                 }
             }
             //显示到ddl控件中
             for (int i = 0; i < ddlProc.Items.Count; i++)
             {
                 //当前项
                 var itm = ddlProc.Items[i];
                 if (itm.Text == row.proc_name)
                 {
                     //设置当前项为选中项
                     if (ddlProc.SelectedIndex != i)
                     {
                         ddlProc.SelectedIndex = i;
                     }
                     //更新最后一次部门名称
                     using (var da2 = new t_userTableAdapter())
                     {
                         da2.UpdateLastProcByUserId(row.proc_name, row.u_id);
                     }
                     //刷新页面
                     StringBuilder sb = new StringBuilder();
                     sb.AppendLine("<script type=\"text/javascript\">");
                     sb.AppendLine("this.top.document.title=\"" + ddlProc.SelectedItem.Text + litProc.Text + "管理系统\";");
                     sb.AppendLine("</script>");
                     Response.Write(sb.ToString());
                     //退出循环
                     break;
                 }
             }
         }
     }
 }
Exemple #5
0
 protected void lvUserMgr_ItemInserting(object sender, ListViewInsertEventArgs e)
 {
     //取消请求执行自定义的方法
     e.Cancel = true;
     //当前角色id
     Int16 roleId = Convert.ToInt16(Session["role_id"]);
     //检测是否有权限
     if (roleId < 0 || roleId > 2)
     {
         throw new Exception("您没有添加记录权限!");
     }
     //当前行
     var itm = e.Item;
     //全部DropDownList
     var ddlProc = (DropDownList)itm.FindControl("ddlProc");
     //设置值
     e.Values["proc_id"] = ddlProc.SelectedValue;
     //获取最大用户序号+1
     using (var da = new t_userTableAdapter())
     {
         var uid = Convert.ToInt16(da.GetMaxUserId());
         e.Values["u_id"] = uid + 1;
     }
     //当前用户输入的密码
     object obj = e.Values["u_pwd"];
     if (obj == null || obj.ToString().Trim().Length == 0)
     {
         throw new Exception("您没有输入密码!");
     }
     string userPwd = obj.ToString().Trim();
     //密码使用两次md5加密
     e.Values["u_pwd"] = ydPublicMethod.GetMd5(ydPublicMethod.GetMd5(userPwd));
     //允许插入数据
     e.Cancel = false;
 }