123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.InitialSet
- {
- public partial class FrmDepartmentSet : LYFZ.Software.UI.InitialSet.FrmDepartmentSet
- {
- public FrmDepartmentSet()
- {
- try
- {
- TreeNode node = new TreeNode();
- node.Text = "所有部门";
- this.trvdep.Nodes.Add(node);
- GetAllFunc(0, node);
- this.trvdep.ExpandAll();
- //trvdep.SelectedNode = trvdep.Nodes[0].Nodes[0];
- trvdep.SelectedNode = trvdep.Nodes[0];
- trvdep.Select();
-
- }
- catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
- this.FormClosed += FrmDepartmentSet_FormClosed;
- }
- void FrmDepartmentSet_FormClosed(object sender, FormClosedEventArgs e)
- {
- if (bl==true)
- {
- this.DialogResult = DialogResult.OK;
- }
- }
- bool bl = false;
- #region 获取数据
- /// <summary>
- /// 构造权限树
- /// </summary>
- /// <param name="parentmenuid"></param>
- public void GetAllFunc(int parentmenuid, TreeNode parent)
- {
- LYFZ.BLL.BLL_ErpDepartment bll = new BLL.BLL_ErpDepartment();
- DataTable dt = bll.GetList("Dt_ClassParentID=" + parentmenuid + "").Tables[0];
- if (dt != null)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- TreeNode nodel = new TreeNode();
- nodel.Text = dt.Rows[i]["Dt_Name"].ToString();
- nodel.Tag = dt.Rows[i]["ID"].ToString();
- GetparentFunc(nodel); //构造子节点功能
- parent.Nodes.Add(nodel);
- }
- }
- }
- /// <summary>
- /// 构造子节点功能
- /// </summary>
- /// <param name="parent"></param>
- public void GetparentFunc(TreeNode parent)
- {
- int memuid = Convert.ToInt32(parent.Tag.ToString());
- LYFZ.BLL.BLL_ErpDepartment bll = new BLL.BLL_ErpDepartment();
- DataTable dt = bll.GetList("Dt_ClassParentID=" + memuid + "").Tables[0]; ;
- if (dt != null)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- TreeNode nodel = new TreeNode();
- nodel.Text = dt.Rows[i]["Dt_Name"].ToString();
- nodel.Tag = dt.Rows[i]["ID"].ToString();
- parent.Nodes.Add(nodel);
- }
- }
- }
- #endregion
- #region 增加
- protected override void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- //MessageBoxCustom.Show(trvdep.SelectedNode.Tag.ToString());
- LYFZ.Model.Model_ErpDepartment model = new Model.Model_ErpDepartment();
- LYFZ.BLL.BLL_ErpDepartment bll = new BLL.BLL_ErpDepartment();
- DataTable dt = new DataTable();
- if (string.IsNullOrEmpty(txtDt_Name.Text))
- {
- MessageBoxCustom.Show("部门名称不能为空!");
- return;
- }
- if (this.trvdep.SelectedNode.Text != "所有部门")
- {
- MessageBoxCustom.Show("此节点不能添加!请添加一级部门");
- BindRefresh();
- return;
- }
- if (bll.Exists("Dt_Name", this.txtDt_Name.Text) == true)
- {
- MessageBoxCustom.Show("部门名称已经存在!");
- this.txtDt_Name.Text = "";
- this.txtDt_Name.Focus();
- return;
- }
- model.Dt_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
- model.Dt_Name = this.txtDt_Name.Text;
- if (this.trvdep.SelectedNode.Text == "所有部门")
- {
- model.Dt_ClassParentID = 0;
- }
- else { model.Dt_ClassParentID = Convert.ToInt32(this.trvdep.SelectedNode.Tag); }
- if (bll.Add(model) == true)
- {
- MessageBoxCustom.Show("增加成功!");
- BindRefresh();
- }
- else { MessageBoxCustom.Show("增加失败!"); }
- }
- catch { MessageBoxCustom.Show("请选择你要增加的节点"); }
- }
- #endregion
- #region 显示树节点
- protected override void trvdep_AfterSelect(object sender, TreeViewEventArgs e)
- {
- try
- {
- LYFZ.BLL.BLL_ErpDepartment bll = new BLL.BLL_ErpDepartment();
- if (trvdep.SelectedNode.Text == "所有部门")
- {
- this.txtDt_Name2.Text = "";
- }
- else
- {
- //修改
- DataTable dt = bll.GetList("ID=" + trvdep.SelectedNode.Tag + "").Tables[0];
- this.txtDt_Name2.Text = dt.Rows[0]["Dt_Name"].ToString();
- }
- }
- catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
- }
- #endregion
- #region 删除
- protected override void btnDelete_Click(object sender, EventArgs e)
- {
- try
- {
- if (string.IsNullOrEmpty(trvdep.SelectedNode.Text))
- {
- MessageBoxCustom.Show("请选择你要删除的子节点!");
- return;
- }
- if (trvdep.SelectedNode.Text == "所有部门")
- {
- MessageBoxCustom.Show("此节点不能删除,请选择子节点!");
- return;
- }
- LYFZ.Model.Model_ErpSystemCategory model = new Model.Model_ErpSystemCategory();
- LYFZ.BLL.BLL_ErpDepartment bll = new BLL.BLL_ErpDepartment();
- DataTable dt = bll.GetList("ID='" + trvdep.SelectedNode.Tag.ToString() + "'").Tables[0];
- int id = Convert.ToInt32(dt.Rows[0]["ID"]);
- if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- if (bll.Delete(id) == true)
- {
- MessageBoxCustom.Show("删除成功!");
- BindRefresh();
- }
- else { MessageBoxCustom.Show("删除失败!"); }
- }
- }
- catch { MessageBoxCustom.Show("请选择你要删除的节点"); }
- }
- #endregion
- #region 修改
- protected override void btnUpdate_Click(object sender, EventArgs e)
- {
- try
- {
- LYFZ.Model.Model_ErpDepartment model = new Model.Model_ErpDepartment();
- LYFZ.BLL.BLL_ErpDepartment bll = new BLL.BLL_ErpDepartment();
- if (string.IsNullOrEmpty(txtDt_Name2.Text))
- {
- MessageBoxCustom.Show("部门名称不能为空!");
- return;
- }
- if (bll.Exists("Dt_Name", this.txtDt_Name2.Text) == true)
- {
- MessageBoxCustom.Show("部门名称已经存在!");
- this.txtDt_Name.Text = "";
- this.txtDt_Name.Focus();
- return;
- }
- model.ID = Convert.ToInt32(trvdep.SelectedNode.Tag);
- model.Dt_Name = this.txtDt_Name2.Text;
- if (bll.Update(model, "ID", "=", overlookFieldList: "ID,Dt_ClassParentID") == true)
- {
- MessageBoxCustom.Show("更新成功!");
- BindRefresh();
- }
- else { MessageBoxCustom.Show("更新失败!"); }
- }
- catch { MessageBoxCustom.Show("请选择你要修改的节点"); }
- }
- #endregion
- #region 关闭
- protected override void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- if (bl == true)
- {
- this.DialogResult = DialogResult.OK;
- }
- }
- #endregion
- #region 刷新数据
- /// <summary>
- /// 刷新数据
- /// </summary>
- public void BindRefresh()
- {
- this.txtDt_Name2.Text = "";
- this.txtDt_Name2.Focus();
- this.trvdep.Nodes.Clear();
- TreeNode node = new TreeNode();
- node.Text = "所有部门";
- this.trvdep.Nodes.Add(node);
- GetAllFunc(0, node);
- this.trvdep.ExpandAll();
- trvdep.SelectedNode = trvdep.Nodes[0];
- trvdep.Select();
- bl = true;
- }
- #endregion
- }
- }
|