UserUpdata.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:6k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Configuration;
  5. using System.Text;
  6. using System.Collections;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Web.UI.HtmlControls;
  13. using System.Net;
  14. using com.etong.BusinessRule.Zwf;
  15. public partial class SysManage_UserUpdata : System.Web.UI.Page
  16. {
  17.     protected  string userid = "";
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.         EtongZwf etongzwf = new EtongZwf();
  21.         userid = Request.QueryString["userid"].Trim();
  22.         if (!IsPostBack)
  23.         {
  24.             BT_Cancel.Attributes.Add("onclick", "javascript:if(confirm('确定要退出吗?')) {window.close();return;} else {return;}");
  25.             if (userid == "")
  26.                 return;
  27.            
  28.             DataView dv = etongzwf.UserSearch(userid, "4",false);
  29.             this.TB_Account.Text = dv[0]["UserAccount"].ToString().Trim();
  30.             this.TB_Decs.Text = dv[0]["UserDecs"].ToString().Trim();
  31.             //this.LB_EmpName.Text = dv[0]["OrgPath"].ToString().Trim() + "/" + dv[0]["EmpName"].ToString().Trim();
  32.             this.TB_address.Text = dv[0]["IPAddress"].ToString();
  33.             TB_employe.Text = dv[0]["EmpName"].ToString();
  34.             ((HtmlInputHidden)this.FindControl("txt_employeid")).Value = dv[0]["EmpID"].ToString();
  35.             ((HtmlInputHidden)this.FindControl("txt_password")).Value = dv[0]["UserPwd"].ToString();
  36.             DataView dvRoleList=etongzwf.RoleGetByID(Convert.ToInt16(userid));
  37.         
  38.             string RoleList = "";
  39.             string RoleIDList = "";
  40.             for( int j=0;j<dvRoleList.Count;j++)
  41.             {
  42.                 RoleList = RoleList + dvRoleList[j]["RoleName"].ToString().Trim() + ",";
  43.                 RoleIDList = RoleIDList + dvRoleList[j]["RoleID"].ToString().Trim() + ",";
  44.             }
  45.             this.TB_UserRole.Value = RoleList;
  46.             ((HtmlInputHidden)this.FindControl("txt_RoleID")).Value = RoleIDList;
  47.             
  48.             DataView Roles = etongzwf.RoleGetByID(Convert.ToInt16(userid)); //绑定已选角色列表
  49.             this.Select2.DataSource = Roles;
  50.             this.Select2.DataTextField = "RoleName";
  51.             this.Select2.DataValueField = "RoleID";
  52.             this.Select2.DataBind();
  53.           
  54.             this.CB_isIPbound.Checked = false;//初始化checkbox为未选中状态
  55.             this.CB_isLock.Checked = false;
  56.             int  islock=Convert.ToInt16(dv[0]["IsLock"].ToString().Trim());
  57.             if (islock == 1)
  58.                 this.CB_isLock.Checked = true;
  59.             else
  60.                 this.CB_isLock.Checked = false;
  61.             int ipbound = Convert.ToInt16(dv[0]["IsIPBound"].ToString().Trim());
  62.             if (ipbound == 1)
  63.                 this.CB_isIPbound.Checked = true;
  64.             else
  65.                 this.CB_isIPbound.Checked = false;
  66.         }
  67.        DataView dvRoles=etongzwf.RoleGetAll(); //绑定所有角色列表
  68.        this.Select1.DataSource = dvRoles;
  69.        this.Select1.DataTextField = "RoleName";
  70.        this.Select1.DataValueField = "RoleID";
  71.        this.Select1.DataBind();
  72.     }
  73.     protected void BT_Confirm_Click(object sender, EventArgs e)
  74.     {
  75.             string  strHostIP="";
  76.             IPHostEntry iphost = Dns.Resolve(Environment.MachineName);
  77.             if (iphost.AddressList.Length > 0)
  78.                 strHostIP = iphost.AddressList[0].ToString();
  79.             string account = this.TB_Account.Text.Trim();
  80.             string decs =this.TB_Decs.Text.Trim();
  81.             HtmlInputHidden txt_employeid = ((HtmlInputHidden)this.FindControl("txt_employeid"));
  82.             string employeid = txt_employeid.Value;
  83.             HtmlInputHidden txt_password = ((HtmlInputHidden)this.FindControl("txt_password"));
  84.             string password = txt_password.Value;
  85.         
  86.             int islock = 0;
  87.             if (this.CB_isLock.Checked == true)
  88.                 islock = 1;
  89.             int ipbound = 0;
  90.             if (this.CB_isIPbound.Checked == true)
  91.                 ipbound = 1;
  92.            
  93.             EtongZwf etongzwf = new EtongZwf();
  94.             bool returnvalue = false;
  95.             //更新用户基本信息
  96.             returnvalue = etongzwf.UserUpdata(Convert.ToInt32(userid), Convert.ToInt16(employeid), account, account, decs, 2, password, islock, strHostIP, ipbound, DateTime.Now, DateTime.Now, DateTime.Now);
  97.             //更新用户角色权限信息
  98.             etongzwf.UserRoleDelete(Convert.ToInt32(userid));  //清除该用户的角色权限
  99.             HtmlInputHidden txt_RoleID = ((HtmlInputHidden)this.form1.FindControl("txt_RoleID"));
  100.             string RoleID = txt_RoleID.Value;
  101.             string[] cklist = RoleID.Split(new Char[] {','}); 
  102.             bool returnvalue2 = false;
  103.             for (int j = 0; j < cklist.Length; j++)//添加该用户的角色权限
  104.             {
  105.                 if (cklist[j].ToString().Trim() != "")
  106.                 {
  107.                     int roleid = Convert.ToInt16(cklist[j].ToString().Trim());
  108.                     returnvalue2 = etongzwf.UserRoleAdd(Convert.ToInt32(userid), roleid, DateTime.Now);
  109.                     if (returnvalue2 == false)
  110.                         return;
  111.                 }
  112.             }
  113.           
  114.              if (returnvalue && returnvalue2)
  115.                  Page.ClientScript.RegisterStartupScript(this.GetType(),"","<script>alert('系统提示:修改记录成功!');window.close();</script>");
  116.              else
  117.                  Page.ClientScript.RegisterStartupScript(this.GetType(),"","<script>alert('系统提示:请选择关联角色!');</script>");
  118.             this.TB_Account.Text = "";
  119.             this.TB_Decs.Text = "";
  120.         }
  121.    
  122. }