Example #1
0
 private void btnDel_Click(object sender, EventArgs e)
 {
     if (tvwDepart.SelectedNode == null)
     {
         UnitCommon.WarnMsg("请选择待删除的部门!");
         return;
     }
     if (tvwDepart.SelectedNode.Level == 0)
     {
         UnitCommon.WarnMsg("不能删除公司!"); // 根节点不能删除
         return;
     }
     if (UnitCommon.ConfirmMsg("确定要删除该部门吗?"))
     {
         int id = int.Parse(tvwDepart.SelectedNode.Tag.ToString());
         DepartmentManager deptMgr = new DepartmentManager();
         bool succ3 = deptMgr.DelDept(id);
         if (succ3)
         {
             FormState = "查看";
             BuildDeptTree();
         }
         else
         {
             UnitCommon.ErrorMsg("删除部门失败!");
         }
     }
 }
Example #2
0
        private void toolbtnDel_Click(object sender, EventArgs e)
        {
            if (UnitCommon.ConfirmMsg("您确定要删除此员工的信息吗?"))
            {
                tabControl1.SelectedIndex = 0; // 切换到tabControl1的第一个界面,员工信息
                //当双击dataGridView1某行时,获取所选行(可能有多行)的第一行、第一列的值,即员工编号
                int             id     = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                EmployeeManager empMgr = new EmployeeManager();
                empMgr.DelEmployee(id);
                int result = empMgr.DelEmployee(id);
                if (result == -1)
                {
                    UnitCommon.WarnMsg("该员工是仓库保管员,必须取消其仓管身份之后才请允许删除,删除失败!");
                    return;
                }

                if (result == -2)
                {
                    UnitCommon.WarnMsg("该员工领取的固定资产尚未归还,必须归还之后才允许删除,删除失败!");
                    return;
                }
                if (result > 0)
                {
                    BindDataGridView(); // 重新刷新DataGridView
                    BuildEmpTree();     // 重新刷新TreeView
                }
                else
                {
                    UnitCommon.ErrorMsg("删除员工信息失败!");
                }
            }
        }
Example #3
0
        private void toolbtnSearch_Click(object sender, EventArgs e)
        {
            if (toolcbxSearchtype.SelectedIndex == -1)
            {
                UnitCommon.WarnMsg("请选择查询类别!");
                toolcbxSearchtype.Focus();
                return;
            }

            if (toolStripTextBox1.Text.Trim() == "")
            {
                UnitCommon.WarnMsg("请输入查询条件!");
                toolStripTextBox1.Focus();
                return;
            }

            string searchField = "";

            if (toolcbxSearchtype.Text.Trim() == "工号")
            {
                searchField = "empid";
            }
            else if (toolcbxSearchtype.Text.Trim() == "姓名")
            {
                searchField = "name";
            }
            else if (toolcbxSearchtype.Text.Trim() == "性别")
            {
                searchField = "sex";
            }
            else
            {
                searchField = "departname";
            }

            string          cond   = string.Format("{0}='{1}'", searchField, toolStripTextBox1.Text.Trim());
            EmployeeManager empMgr = new EmployeeManager();
            DataTable       dt     = empMgr.GetEmployeeByCondition(cond);

            dataGridView1.DataSource = dt;
        }
Example #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string state    = FormState; // 获取当前的状态
            string deptName = "";

            if (state == "添加")
            {
                // 遍历Tree根节点下的所有子节点,找到添加的新节点
                foreach (TreeNode node in tvwDepart.Nodes[0].Nodes)
                {
                    if (node.Tag.ToString() == "new")
                    {
                        deptName = node.Text.Trim(); // 获取添加节点的名字
                        break;
                    }
                }

                if (deptName == "" || deptName == "请输入新部门名称")
                {
                    UnitCommon.InfoMsg("请输入新部门名称!");
                    return;
                }

                Department dept = new Department();
                dept.Name = deptName;
                DepartmentManager deptMgr = new DepartmentManager();
                bool succ = deptMgr.AddDept(dept);
                if (succ)             // 保存成功
                {
                    FormState = "查看"; // 注意不要写成formState
                    BuildDeptTree();
                }
                else
                {
                    UnitCommon.ErrorMsg("保存新部门失败!");
                }

                return;
            }
            else if (state == "修改")
            {
                if (deptofModified != null)
                {
                    int    id   = int.Parse(deptofModified.Tag.ToString());
                    string name = deptofModified.Text.Trim();
                    if (name == "")
                    {
                        UnitCommon.WarnMsg("部门名称不能为空!");
                        return;
                    }

                    Department dept = new Department();
                    dept.Id   = id;
                    dept.Name = name;
                    DepartmentManager deptMgr = new DepartmentManager();
                    bool succ2 = deptMgr.UpadateDept(dept);
                    if (succ2)
                    {
                        FormState = "查看";
                        BuildDeptTree();
                    }
                    else
                    {
                        UnitCommon.ErrorMsg("修改部门信息失败!");
                    }
                }
            }
        }
Example #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 1) // 代表控件tabControl1的第二个界面,新员工注册
            {
                Employee emp = new Employee();
                if (txtNewName.Text.Trim() == "")
                {
                    UnitCommon.WarnMsg("请输入新员工姓名!");
                    return;
                }
                else
                {
                    emp.Name     = txtNewName.Text.Trim();
                    emp.Sex      = rabFemale.Checked ? "女" : "男";
                    emp.Departid = int.Parse(cbxNewDepart.SelectedValue.ToString());

                    EmployeeManager empMgr = new EmployeeManager();
                    bool            succ   = empMgr.AddEmployee(emp);
                    if (succ)
                    {
                        BindEmpInfo();                     //重新 刷新dataGridView
                        txtNewName.Text            = "";   // 重新初始化为空
                        rabMale.Checked            = true; // 默认勾选 男
                        cbxNewDepart.SelectedIndex = 0;    // 下拉框ComoBox默认显示第一项
                        tabControl1.SelectedIndex  = 0;    // 默认显示控件tabControl1的第一个界面,员工信息
                        BuildEmpTree();                    // 重新 刷新TreeView
                    }
                    else
                    {
                        UnitCommon.ErrorMsg("新员工注册失败!");
                        return;
                    }
                }
            }
            if (tabControl1.SelectedIndex == 2) //代表修改
            {
                int             id     = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                EmployeeManager empMgr = new EmployeeManager();
                Employee        emp    = empMgr.GetEmployeeById(id);
                if (emp != null)
                {
                    emp.Name     = txtName.Text;
                    emp.Sex      = rabBoy.Checked ? "男" : "女";
                    emp.Departid = int.Parse(cbxDepart.SelectedValue.ToString());

                    bool succ = empMgr.UpdateEmployee(emp);
                    if (succ)
                    {
                        BindEmpInfo();                     //重新 刷新dataGridView
                        txtName.Text              = "";
                        rabBoy.Checked            = false; // 不勾选 男
                        rabGirl.Checked           = false; // 不勾选 女
                        cbxDepart.SelectedIndex   = -1;    // 下拉框不显示下拉项值
                        tabControl1.SelectedIndex = 0;     // 回到第一个界面,员工信息
                        BuildEmpTree();                    //重新 刷新TreeView
                    }
                    else
                    {
                        UnitCommon.ErrorMsg("修改员工信息失败!");
                        return;
                    }
                }
            }
        }