⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 savedepartmanage.aspx.cs

📁 办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using Office.BLL;
using Office.Model;

public partial class PersonManage_SaveDepartManager : System.Web.UI.Page
{
    private static Boolean IsUpdate = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Bind();
            //获得请求的数据(部门ID)
            string departId = Request["DepartId"];
            if (departId != "" && departId != null)
            {
                this.InitControl(Int32.Parse(departId));
                //将状态设为更新
                IsUpdate = true;
                ViewState["departId"] = departId;
            }
            else
            {
                //将状态设为添加
                IsUpdate = false;
            }
        }
        this.DIV1.Visible = false;
    }
    //查看所有员工事件
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        this.DIV1.Visible = true;
        this.TreeView1.Nodes.Clear();
        InitMenu();
        this.TreeView1.ExpandAll();
    }
    //初始化树型控件
    private void InitMenu()
    {
        IList<BranchInfo> brach = BranchInfoManager.GetAllBranchInfos();
        foreach (BranchInfo tmp in brach)
        {
            TreeNode root = new TreeNode(tmp.BranchName);
            root.ImageUrl = "~/Images/menuclose.gif";
            IList<DepartInfo> depart = DepartInfoManager.GetDepartInfoByBranchId(tmp.BranchId);
            foreach (DepartInfo de in depart)
            {
                TreeNode node = new TreeNode(de.DepartName);
                node.ImageUrl = "~/Images/OpenTree.gif";
                IList<UserInfo> user = UserInfoManager.GetUserInfosByDepartId(de.DepartId);
                foreach (UserInfo u in user)
                {
                    TreeNode node1 = new TreeNode(u.UserId);
                    node1.ImageUrl = "~/Images/person.gif";
                    node.ChildNodes.Add(node1);
                }
                root.ChildNodes.Add(node);
            }
            this.TreeView1.Nodes.Add(root);
        }
    }
    //数据绑定
    private void Bind()
    {
        this.DropDownList1.DataSource = BranchInfoManager.GetAllBranchInfos();
        this.DropDownList1.DataTextField = "BranchName";
        this.DropDownList1.DataValueField = "BranchId";
        this.DropDownList1.DataBind();
    }
    //初始化页面所有控件
    protected void InitControl(Int32 departId)
    {
        DepartInfo depart = DepartInfoManager.GetDepartInfoByDepartId(departId);
        txtDepartName.Text = depart.DepartName;
        DropDownList1.SelectedValue = depart.Branch.BranchId.ToString();
        txtPrincipal.Text = depart.PrincipalUser.UserId;
        txtTelNo.Text = depart.ConnectTelNo.ToString();
        txtMobile.Text = depart.ConnectMobileTelNo.ToString();
        txtFaxes.Text = depart.Faxes.ToString();
    }
    //根据用户填写的数据得到一个部门实体类
    private DepartInfo GetDepartInfo()
    {
        DepartInfo depart = new DepartInfo();
        depart.DepartName = txtDepartName.Text;
        depart.Branch = BranchInfoManager.GetBranchInfoByBranchId(Int32.Parse(DropDownList1.SelectedValue));
        depart.PrincipalUser = UserInfoManager.GetUserInfoByUserId(txtPrincipal.Text);
        if (txtTelNo.Text != "")
            depart.ConnectTelNo = long.Parse(txtTelNo.Text);
        else
            depart.ConnectTelNo = 0;
        if (txtMobile.Text != "")
            depart.ConnectMobileTelNo = long.Parse(txtMobile.Text);
        else
            depart.ConnectMobileTelNo = 0;
        if (txtFaxes.Text != "")
            depart.Faxes = long.Parse(txtFaxes.Text);
        else
            depart.Faxes = 0;

        return depart;
    }
    //保存
    protected void Button2_Click(object sender, EventArgs e)
    {
        DepartInfo depart = GetDepartInfo();
        if (IsUpdate)
        {
            depart.DepartId = Int32.Parse(ViewState["departId"].ToString());
            DepartInfoManager.ModifyDepartInfo(depart);
        }
        else
        {
            DepartInfoManager.AddDepartInfo(depart);
        }
        Response.Redirect("DepartManage.aspx");
    }
    //返回
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("DepartManage.aspx");
    }
    //树型控件的选择事件
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        String principal = TreeView1.SelectedNode.Text;
        if (UserInfoManager.CheckUser(principal))
        {
            this.txtPrincipal.Text = principal;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -