- 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 DepartmentManager : System.Web.UI.Page
- {
- /// <summary>
- /// 模板
- /// </summary>
- Model.Department MD = new Model.Department();
- /// <summary>
- /// 业务
- /// </summary>
- BLL.Department BD = new BLL.Department();
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginLogic.MatchLoad("", "DepartmentManager");
- if (!IsPostBack)
- {
- TreeLoadSet();
- DropLoadSet();
- }
- }
- public void DropLoadSet()
- {
- Department_DropDownList.DataTextField = "DeptName";
- Department_DropDownList.DataValueField = "ID";
- Department_DropDownList.DataSource = EnumGet.DepartmentGetEnum();
- Department_DropDownList.DataBind();
- ListItem linone = new ListItem();
- linone.Text = "无";
- linone.Value = "0";
- Department_DropDownList.Items.Add(linone);
- Department_DropDownList.SelectedIndex = Department_DropDownList.Items.Count - 1;
- DepLoadSet(3);
- }
- /// <summary>
- /// 加载
- /// </summary>
- protected void DepLoadSet(int dpid)
- {
- MD = BD.GetModel(dpid);
- DepartMent_TextBox.Text = MD.DeptName;
- Num_TextBox.Text = MD.DeptNo.ToString();
- DeptFunc_TextBox.Text = MD.DeptFunc;
- Leader1_TextBox.Text = MD.Leader1;
- Leader2_TextBox.Text = MD.Leader2;
- DepartmentMain_TextBox.Text = MD.Manager;
- try { Department_DropDownList.SelectedValue = MD.ParentDept.ToString(); }
- catch { Department_DropDownList.SelectedIndex = Department_DropDownList.Items.Count - 1; }
- Fax_TextBox.Text = MD.FaxNo;
- Tel_TextBox.Text = MD.TelNo;
- }
- 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);
- }
- }
- }
- }
- protected void Button5_Click(object sender, EventArgs e)
- {
- try
- {
- int Num_TextBox_int = 0;
- if (!int.TryParse(Num_TextBox.Text, out Num_TextBox_int))
- {
- throw new Exception("序号必须为数字");
- }
- MD.ID = int.Parse(MyId.Text);
- MD.DeptName = DepartMent_TextBox.Text;
- MD.DeptNo = Num_TextBox_int;
- MD.DeptFunc = DeptFunc_TextBox.Text;
- MD.Leader1 = Leader1_TextBox.Text;
- MD.Leader2 = Leader2_TextBox.Text;
- MD.Manager = DepartmentMain_TextBox.Text;
- MD.ParentDept = int.Parse(Department_DropDownList.SelectedValue);
- MD.FaxNo = Fax_TextBox.Text;
- MD.TelNo = Tel_TextBox.Text;
- BD.Update(MD);
- TreeLoadSet();
- DropLoadSet();
- MessageBox.Show("更新成功!");
- }
- catch (Exception exp)
- {
- MessageBox.Show(exp.Message);
- }
- }
- protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
- {
- DepLoadSet(int.Parse(TreeView1.SelectedNode.Value));
- MyId.Text = TreeView1.SelectedNode.Value;
- }
- protected void Button6_Click(object sender, EventArgs e)
- {
- try
- {
- BD.Delete(int.Parse(MyId.Text));
- TreeLoadSet();
- DropLoadSet();
- MessageBox.Show("删除成功!");
- }
- catch (Exception exp)
- {
- MessageBox.Show(exp.Message);
- }
- }
- }