UserManagerByDept.aspx.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:7k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections.Generic;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. public partial class UserManagerByDept : System.Web.UI.Page
  12. {
  13.     /// <summary>
  14.     /// 模板 
  15.     /// </summary>
  16.     Model.Department MD = new Model.Department();
  17.     /// <summary>
  18.     /// 业务
  19.     /// </summary>
  20.     BLL.Department BD = new BLL.Department();
  21.     Model.Users nc_Users = new Model.Users();
  22.     BLL.Users bll_Users = new BLL.Users();
  23.     protected void Page_Load(object sender, EventArgs e)
  24.     {
  25.         LoginLogic.MatchLoad("", "UserManagerByDept");
  26.         if (!IsPostBack)
  27.         {
  28.             TreeLoadSet();
  29.         }
  30.     }
  31.     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  32.     {
  33.     }
  34.     public void LoadSet()
  35.     {
  36.         try
  37.         {
  38.             //UserId
  39.             if (KeyValue_UserId.Text == "")
  40.             {
  41.                 throw new Exception("用户名不能为空!");
  42.             }
  43.             BLL.Users bu = new BLL.Users();
  44.             if (bu.GetCount("UserId='" + KeyValue_UserId.Text + "'") > 0)
  45.             {
  46.                 throw new Exception("用户名有重复!");
  47.             }
  48.             //UserNo
  49.             int UserNo = 0;
  50.             if (!int.TryParse(this.KeyValue_UserNo.Text, out UserNo))
  51.             {
  52.                 throw new Exception("用户排序号必须为数字!");
  53.             }
  54.             //Password
  55.             //if (KeyValue_Password.Text == "")
  56.             //{
  57.             //    throw new Exception("密码不能为空!");
  58.             //}
  59.             //if (KeyValue_Password.Text != KeyValue_Password1.Text)
  60.             //{
  61.             //    throw new Exception("确认密码不符!");
  62.             //}
  63.             //PrivId
  64.             int PrivId = 0;
  65.             if (!int.TryParse(this.KeyValue_PrivId.Text, out PrivId))
  66.             {
  67.                 throw new Exception("角色不能为空!");
  68.             }
  69.             nc_Users.UserId = this.KeyValue_UserId.Text;
  70.             nc_Users.UserId2 = this.KeyValue_UserId2.Text;
  71.             nc_Users.UserNo = UserNo;
  72.             nc_Users.UserName = this.KeyValue_UserName.Text;
  73.            // nc_Users.Password = this.KeyValue_Password.Text;
  74.             nc_Users.PrivId = PrivId;
  75.             nc_Users.PrivId2 = "";
  76.             nc_Users.PostPriv = this.KeyValue_PostPriv.Text;
  77.             nc_Users.PostDept = "";
  78.             nc_Users.DeptId = int.Parse(this.KeyValue_DeptId.SelectedValue);
  79.             nc_Users.DeptId2 = "";
  80.             nc_Users.CanBroadcast = true;
  81.             if (this.KeyValue_Sex.SelectedValue == "0")
  82.             {
  83.                 nc_Users.Sex = true;
  84.             }
  85.             else
  86.             {
  87.                 nc_Users.Sex = false;
  88.             }
  89.             nc_Users.Birthday = DateTime.Parse(this.DropDownList6.Text + "-" + this.DropDownList7.Text + "-" + this.DropDownList8.Text);
  90.             nc_Users.IsHideBirthday = CheckBox5.Checked;
  91.             nc_Users.TelNoDept = "";
  92.             nc_Users.FaxNoDept = "";
  93.             nc_Users.AddressHome = "";
  94.             nc_Users.ZipHome = "";
  95.             nc_Users.TelHome = "";
  96.             nc_Users.Mobile = "";
  97.             nc_Users.IsHideMobile = false;
  98.             nc_Users.Bp = "";
  99.             nc_Users.Email = "";
  100.             nc_Users.Oicq = "";
  101.             nc_Users.Icq = "";
  102.             nc_Users.Msn = "";
  103.             nc_Users.Skype = "";
  104.             nc_Users.Photo = "";
  105.             nc_Users.NickName = this.KeyValue_UserId.Text;
  106.             nc_Users.Avatar = 0;
  107.             nc_Users.MenuType = false;
  108.             nc_Users.MenuHide = false;
  109.             nc_Users.SmsOn = false;
  110.             nc_Users.CallSound = 1;
  111.             nc_Users.Theme = 1;
  112.             nc_Users.Note = "";
  113.             nc_Users.MytableLeft = "";
  114.             nc_Users.MytableRight = "";
  115.             nc_Users.EmailCapacity = 0;
  116.             nc_Users.FolderCapacity = 0;
  117.             nc_Users.OnlineTime = 10;
  118.             nc_Users.DutyType = 1;
  119.             nc_Users.AttendCard = "00000";
  120.             nc_Users.State = 1;
  121.             nc_Users.LastPassTime = DateTime.Now;
  122.             nc_Users.LastVisitTime = DateTime.Now;
  123.             nc_Users.LastIp = "127.0.0.1";
  124.             nc_Users.Disabled = this.KeyValue_Disabled.Checked;
  125.             nc_Users.BindIp = "";
  126.             nc_Users.UsingKey = this.KeyValue_UsingKey.Checked;
  127.             nc_Users.UGuid = "";
  128.             nc_Users.UKey = "";
  129.             nc_Users.UExt = "";
  130.             if (this.KeyValue_NotUser.Checked)
  131.             {
  132.                 nc_Users.NotUser = 1;
  133.             }
  134.             else
  135.             {
  136.                 nc_Users.NotUser = 0;
  137.             }
  138.             if (this.KeyValue_NotTable.Checked)
  139.             {
  140.                 nc_Users.NotTable = 1;
  141.             }
  142.             else
  143.             {
  144.                 nc_Users.NotTable = 0;
  145.             }
  146.             nc_Users.DefaultMenu = "";
  147.             nc_Users.TablePhoto = "";
  148.             nc_Users.WebmailNum = 0;
  149.             nc_Users.WebmailCapacity = 0;
  150.             nc_Users.AdUserId = "";
  151.             nc_Users.UsingAd = true;
  152.             bll_Users.Update(nc_Users);
  153.             MessageBox.Show("修改成功!");
  154.         }
  155.         catch (Exception exp)
  156.         {
  157.             MessageBox.Show(exp.Message);
  158.         }
  159.     }
  160.     protected void TreeLoadSet()
  161.     {
  162.         TreeView1.Nodes.Clear();
  163.         object objcount = OACommon.HLP.ExecuteScalar(CommandType.Text, "select  max(parentdept) from department", null);
  164.         if (objcount != null)
  165.         {
  166.             int AllCount = int.Parse(objcount.ToString());//最深的ID
  167.             List<Model.Department> DPMT = BD.GetList();
  168.             foreach (Model.Department MD in DPMT)
  169.             {
  170.                 if (MD.ParentDept == 0)
  171.                 {
  172.                     TreeNode tn = new TreeNode();
  173.                     tn.Text = MD.DeptName;
  174.                     tn.Value = MD.ID.ToString();
  175.                     tn.ImageUrl = "~/images/node_dept.gif";
  176.                     TreeView1.Nodes.Add(tn);
  177.                 }
  178.             }
  179.             foreach (TreeNode tn in TreeView1.Nodes)
  180.             {
  181.                 CallMeTree(tn);
  182.             }
  183.         }
  184.     }
  185.     /// <summary>
  186.     /// 递归调用
  187.     /// </summary>
  188.     /// <param name="MaxDep"></param>
  189.     /// <param name="DepId"></param>
  190.     public void CallMeTree(TreeNode TNId)
  191.     {
  192.         List<Model.Department> DPMT = BD.GetList();
  193.         foreach (Model.Department MD in DPMT)
  194.         {
  195.             if (MD.ParentDept.ToString() == TNId.Value)
  196.             {
  197.                 TreeNode tn = new TreeNode();
  198.                 tn.Text = MD.DeptName;
  199.                 tn.Value = MD.ID.ToString();
  200.                 tn.ImageUrl = "~/images/node_dept.gif";
  201.                 //  Console.WriteLine(TreeView1.ExpandDepth.ToString());          
  202.                 TNId.ChildNodes.Add(tn);
  203.                 int Count = BD.GetCount("ParentDept=" + tn.Value);
  204.                 if (Count > 0)
  205.                 {
  206.                     CallMeTree(tn);
  207.                 }
  208.             }
  209.         }
  210.     }
  211. }