- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class UserManagerByDept : System.Web.UI.Page
- {
- /// <summary>
- /// 模板
- /// </summary>
- Model.Department MD = new Model.Department();
- /// <summary>
- /// 业务
- /// </summary>
- BLL.Department BD = new BLL.Department();
- Model.Users nc_Users = new Model.Users();
- BLL.Users bll_Users = new BLL.Users();
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginLogic.MatchLoad("", "UserManagerByDept");
- if (!IsPostBack)
- {
- TreeLoadSet();
- }
- }
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- public void LoadSet()
- {
- try
- {
- //UserId
- if (KeyValue_UserId.Text == "")
- {
- throw new Exception("用户名不能为空!");
- }
- BLL.Users bu = new BLL.Users();
- if (bu.GetCount("UserId='" + KeyValue_UserId.Text + "'") > 0)
- {
- throw new Exception("用户名有重复!");
- }
- //UserNo
- int UserNo = 0;
- if (!int.TryParse(this.KeyValue_UserNo.Text, out UserNo))
- {
- throw new Exception("用户排序号必须为数字!");
- }
- //Password
- //if (KeyValue_Password.Text == "")
- //{
- // throw new Exception("密码不能为空!");
- //}
- //if (KeyValue_Password.Text != KeyValue_Password1.Text)
- //{
- // throw new Exception("确认密码不符!");
- //}
- //PrivId
- int PrivId = 0;
- if (!int.TryParse(this.KeyValue_PrivId.Text, out PrivId))
- {
- throw new Exception("角色不能为空!");
- }
- nc_Users.UserId = this.KeyValue_UserId.Text;
- nc_Users.UserId2 = this.KeyValue_UserId2.Text;
- nc_Users.UserNo = UserNo;
- nc_Users.UserName = this.KeyValue_UserName.Text;
- // nc_Users.Password = this.KeyValue_Password.Text;
- nc_Users.PrivId = PrivId;
- nc_Users.PrivId2 = "";
- nc_Users.PostPriv = this.KeyValue_PostPriv.Text;
- nc_Users.PostDept = "";
- nc_Users.DeptId = int.Parse(this.KeyValue_DeptId.SelectedValue);
- nc_Users.DeptId2 = "";
- nc_Users.CanBroadcast = true;
- if (this.KeyValue_Sex.SelectedValue == "0")
- {
- nc_Users.Sex = true;
- }
- else
- {
- nc_Users.Sex = false;
- }
- nc_Users.Birthday = DateTime.Parse(this.DropDownList6.Text + "-" + this.DropDownList7.Text + "-" + this.DropDownList8.Text);
- nc_Users.IsHideBirthday = CheckBox5.Checked;
- nc_Users.TelNoDept = "";
- nc_Users.FaxNoDept = "";
- nc_Users.AddressHome = "";
- nc_Users.ZipHome = "";
- nc_Users.TelHome = "";
- nc_Users.Mobile = "";
- nc_Users.IsHideMobile = false;
- nc_Users.Bp = "";
- nc_Users.Email = "";
- nc_Users.Oicq = "";
- nc_Users.Icq = "";
- nc_Users.Msn = "";
- nc_Users.Skype = "";
- nc_Users.Photo = "";
- nc_Users.NickName = this.KeyValue_UserId.Text;
- nc_Users.Avatar = 0;
- nc_Users.MenuType = false;
- nc_Users.MenuHide = false;
- nc_Users.SmsOn = false;
- nc_Users.CallSound = 1;
- nc_Users.Theme = 1;
- nc_Users.Note = "";
- nc_Users.MytableLeft = "";
- nc_Users.MytableRight = "";
- nc_Users.EmailCapacity = 0;
- nc_Users.FolderCapacity = 0;
- nc_Users.OnlineTime = 10;
- nc_Users.DutyType = 1;
- nc_Users.AttendCard = "00000";
- nc_Users.State = 1;
- nc_Users.LastPassTime = DateTime.Now;
- nc_Users.LastVisitTime = DateTime.Now;
- nc_Users.LastIp = "127.0.0.1";
- nc_Users.Disabled = this.KeyValue_Disabled.Checked;
- nc_Users.BindIp = "";
- nc_Users.UsingKey = this.KeyValue_UsingKey.Checked;
- nc_Users.UGuid = "";
- nc_Users.UKey = "";
- nc_Users.UExt = "";
- if (this.KeyValue_NotUser.Checked)
- {
- nc_Users.NotUser = 1;
- }
- else
- {
- nc_Users.NotUser = 0;
- }
- if (this.KeyValue_NotTable.Checked)
- {
- nc_Users.NotTable = 1;
- }
- else
- {
- nc_Users.NotTable = 0;
- }
- nc_Users.DefaultMenu = "";
- nc_Users.TablePhoto = "";
- nc_Users.WebmailNum = 0;
- nc_Users.WebmailCapacity = 0;
- nc_Users.AdUserId = "";
- nc_Users.UsingAd = true;
- bll_Users.Update(nc_Users);
- MessageBox.Show("修改成功!");
- }
- catch (Exception exp)
- {
- MessageBox.Show(exp.Message);
- }
- }
- protected void TreeLoadSet()
- {
- TreeView1.Nodes.Clear();
- object objcount = OACommon.HLP.ExecuteScalar(CommandType.Text, "select max(parentdept) from department", null);
- if (objcount != null)
- {
- int AllCount = int.Parse(objcount.ToString());//最深的ID
- List<Model.Department> DPMT = BD.GetList();
- foreach (Model.Department MD in DPMT)
- {
- if (MD.ParentDept == 0)
- {
- TreeNode tn = new TreeNode();
- tn.Text = MD.DeptName;
- tn.Value = MD.ID.ToString();
- tn.ImageUrl = "~/images/node_dept.gif";
- TreeView1.Nodes.Add(tn);
- }
- }
- foreach (TreeNode tn in TreeView1.Nodes)
- {
- CallMeTree(tn);
- }
- }
- }
- /// <summary>
- /// 递归调用
- /// </summary>
- /// <param name="MaxDep"></param>
- /// <param name="DepId"></param>
- public void CallMeTree(TreeNode TNId)
- {
- List<Model.Department> DPMT = BD.GetList();
- foreach (Model.Department MD in DPMT)
- {
- if (MD.ParentDept.ToString() == TNId.Value)
- {
- TreeNode tn = new TreeNode();
- tn.Text = MD.DeptName;
- tn.Value = MD.ID.ToString();
- tn.ImageUrl = "~/images/node_dept.gif";
- // Console.WriteLine(TreeView1.ExpandDepth.ToString());
- TNId.ChildNodes.Add(tn);
- int Count = BD.GetCount("ParentDept=" + tn.Value);
- if (Count > 0)
- {
- CallMeTree(tn);
- }
- }
- }
- }
- }