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

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 DepartmentManager : 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.     protected void Page_Load(object sender, EventArgs e)
  22.     {
  23.         LoginLogic.MatchLoad("", "DepartmentManager");
  24.         if (!IsPostBack)
  25.         {
  26.             
  27.             TreeLoadSet();
  28.             DropLoadSet();
  29.         }
  30.     }
  31.     public void DropLoadSet()
  32.     {
  33.         Department_DropDownList.DataTextField = "DeptName";
  34.         Department_DropDownList.DataValueField = "ID";
  35.         Department_DropDownList.DataSource = EnumGet.DepartmentGetEnum();
  36.         Department_DropDownList.DataBind();
  37.         ListItem linone = new ListItem();
  38.         linone.Text = "无";
  39.         linone.Value = "0";
  40.         Department_DropDownList.Items.Add(linone);
  41.         Department_DropDownList.SelectedIndex = Department_DropDownList.Items.Count - 1;
  42.         DepLoadSet(3);
  43.     }
  44.     /// <summary>
  45.     /// 加载
  46.     /// </summary>
  47.     protected void DepLoadSet(int dpid)
  48.     {
  49.         MD = BD.GetModel(dpid);
  50.         DepartMent_TextBox.Text = MD.DeptName;
  51.         Num_TextBox.Text = MD.DeptNo.ToString();
  52.         DeptFunc_TextBox.Text = MD.DeptFunc;
  53.         Leader1_TextBox.Text = MD.Leader1;
  54.         Leader2_TextBox.Text = MD.Leader2;
  55.         DepartmentMain_TextBox.Text = MD.Manager;
  56.         try { Department_DropDownList.SelectedValue = MD.ParentDept.ToString(); }
  57.         catch { Department_DropDownList.SelectedIndex = Department_DropDownList.Items.Count - 1; }
  58.         Fax_TextBox.Text = MD.FaxNo;
  59.         Tel_TextBox.Text = MD.TelNo;
  60.     }
  61.     protected void TreeLoadSet()
  62.     {
  63.         TreeView1.Nodes.Clear();
  64.         object objcount=OACommon.HLP.ExecuteScalar(CommandType.Text, "select  max(parentdept) from department", null);
  65.         if (objcount != null)
  66.         {
  67.             int AllCount =int.Parse(objcount.ToString());//最深的ID
  68.             List<Model.Department> DPMT = BD.GetList();
  69.             foreach (Model.Department MD in DPMT)
  70.             {
  71.                 if (MD.ParentDept == 0)
  72.                 {
  73.                     TreeNode tn = new TreeNode();
  74.                     tn.Text = MD.DeptName;
  75.                     tn.Value = MD.ID.ToString();
  76.                     tn.ImageUrl = "~/images/node_dept.gif";
  77.                     TreeView1.Nodes.Add(tn);
  78.                 }
  79.             }
  80.             foreach (TreeNode tn in TreeView1.Nodes)
  81.             {
  82.                 CallMeTree(tn);
  83.             }
  84.         }
  85.     }
  86.     /// <summary>
  87.     /// 递归调用
  88.     /// </summary>
  89.     /// <param name="MaxDep"></param>
  90.     /// <param name="DepId"></param>
  91.     public void CallMeTree(TreeNode TNId)
  92.     {       
  93.         List<Model.Department> DPMT = BD.GetList();     
  94.         foreach (Model.Department MD in DPMT)
  95.         {
  96.             if (MD.ParentDept.ToString() == TNId.Value)
  97.             {
  98.                 TreeNode tn = new TreeNode();
  99.                 tn.Text = MD.DeptName;
  100.                 tn.Value = MD.ID.ToString();
  101.                 tn.ImageUrl = "~/images/node_dept.gif";
  102.               //  Console.WriteLine(TreeView1.ExpandDepth.ToString());          
  103.                 TNId.ChildNodes.Add(tn);
  104.                 int Count = BD.GetCount("ParentDept=" + tn.Value);
  105.                 if (Count > 0)
  106.                 {
  107.                     CallMeTree(tn);
  108.                 }
  109.             }
  110.         }
  111.     }
  112.     protected void Button5_Click(object sender, EventArgs e)
  113.     {
  114.         try
  115.         {
  116.             int Num_TextBox_int = 0;
  117.             if (!int.TryParse(Num_TextBox.Text, out Num_TextBox_int))
  118.             {
  119.                 throw new Exception("序号必须为数字");
  120.             }
  121.             MD.ID = int.Parse(MyId.Text);
  122.             MD.DeptName = DepartMent_TextBox.Text;
  123.             MD.DeptNo = Num_TextBox_int;
  124.             MD.DeptFunc = DeptFunc_TextBox.Text;
  125.             MD.Leader1 = Leader1_TextBox.Text;
  126.             MD.Leader2 = Leader2_TextBox.Text;
  127.             MD.Manager = DepartmentMain_TextBox.Text;
  128.             MD.ParentDept = int.Parse(Department_DropDownList.SelectedValue);
  129.             MD.FaxNo = Fax_TextBox.Text;
  130.             MD.TelNo = Tel_TextBox.Text;
  131.             BD.Update(MD);
  132.             TreeLoadSet();
  133.             DropLoadSet();
  134.             MessageBox.Show("更新成功!");
  135.         }
  136.         catch (Exception exp)
  137.         {
  138.             MessageBox.Show(exp.Message);
  139.         }
  140.     }
  141.     protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
  142.     {
  143.         DepLoadSet(int.Parse(TreeView1.SelectedNode.Value));
  144.         MyId.Text = TreeView1.SelectedNode.Value;
  145.     }
  146.     protected void Button6_Click(object sender, EventArgs e)
  147.     {
  148.         try
  149.         {
  150.             BD.Delete(int.Parse(MyId.Text));
  151.             TreeLoadSet();
  152.             DropLoadSet();
  153.             MessageBox.Show("删除成功!");
  154.         }
  155.         catch (Exception exp)
  156.         {
  157.             MessageBox.Show(exp.Message);
  158.         }
  159.     }
  160. }