using System; using System.Data; using BP.DA; using BP.En; using BP.Web; using BP.Port; namespace BP.Cloud { /// /// 部门属性 /// public class DeptAttr : EntityTreeAttr { /// /// 单位全名 /// public const string NameOfPath = "NameOfPath"; /// /// 管理员 /// public const string Adminer = "Adminer"; /// /// 组织编号 /// public const string OrgNo = "OrgNo"; /// /// 部门ID /// public const string RefID = "RefID"; /// /// 关联的父节点ID /// public const string RefParentID = "RefParentID"; /// /// 部门主管 /// public const string Leader = "Leader"; } /// /// 部门 /// public class Dept : EntityTree { #region 属性 /// /// 组织编号 /// public string OrgNo { get { return this.GetValStrByKey(DeptAttr.OrgNo); } set { this.SetValByKey(DeptAttr.OrgNo, value); } } /// /// 领导 /// public string Leader { get { return this.GetValStrByKey(DeptAttr.Leader); } set { this.SetValByKey(DeptAttr.Leader, value); } } /// /// 部门ID /// public string RefID { get { return this.GetValStrByKey(DeptAttr.RefID); } set { this.SetValByKey(DeptAttr.RefID, value); } } public string RefParentID { get { return this.GetValStrByKey(DeptAttr.RefParentID); } set { this.SetValByKey(DeptAttr.RefParentID, value); } } /// /// adminer /// public string Adminer { get { return this.GetValStrByKey(DeptAttr.Adminer); } set { this.SetValByKey(DeptAttr.Adminer, value); } } /// /// 全名 /// public string NameOfPath { get { return this.GetValStrByKey(DeptAttr.NameOfPath); } set { this.SetValByKey(DeptAttr.NameOfPath, value); } } /// /// 父节点的ID /// public new string ParentNo { get { return this.GetValStrByKey(DeptAttr.ParentNo); } set { this.SetValByKey(DeptAttr.ParentNo, value); } } #endregion #region 构造函数 /// /// 部门 /// public Dept() { } /// /// 部门 /// /// 编号 public Dept(string no) : base(no) { } #endregion #region 重写方法 public override UAC HisUAC { get { UAC uac = new UAC(); uac.OpenForSysAdmin(); uac.IsInsert = false; return uac; } } /// /// Map /// public override Map EnMap { get { if (this._enMap != null) return this._enMap; Map map = new Map("Port_Dept", "部门"); map.AddTBStringPK(DeptAttr.No, null, "编号", true, true, 1, 50, 20); map.AddTBString(DeptAttr.Name, null, "部门名称", true, false, 0, 100, 30, false); map.AddTBString(DeptAttr.NameOfPath, null, "部门全称", true, true, 0, 100, 30, true); map.AddTBString(DeptAttr.ParentNo, null, "父节点编号", true, true, 0, 100, 30); map.AddTBString(DeptAttr.OrgNo, null, "组织编码", true, true, 0, 100, 30); map.AddTBString(DeptAttr.Leader, null, "部门负责人", true, false, 0, 100, 30); map.AddTBString(DeptAttr.Adminer, null, "管理员帐号", false, false, 0, 100, 30); map.AddTBInt(DeptAttr.Idx, 0, "Idx", false, false); //顺序号. //微信,丁丁的第三方的ID. map.AddTBString(DeptAttr.RefID, null, "RefID", false, true, 0, 100, 30); map.AddTBString(DeptAttr.RefParentID, null, "RefParentID", false, true, 0, 100, 30); ////节点绑定人员. 使用树杆与叶子的模式绑定. //map.AttrsOfOneVSM.AddBranchesAndLeaf(new DeptEmps(), new BP.Port.Emps(), // DeptEmpAttr.FK_Dept, // DeptEmpAttr.FK_Emp, "对应人员", EmpAttr.FK_Dept, EmpAttr.Name, // EmpAttr.No, "@WebUser.FK_Dept"); RefMethod rm = new RefMethod(); rm.Title = "重置部门全称"; rm.ClassMethodName = this.ToString() + ".DoResetPathName"; rm.RefMethodType = RefMethodType.Func; string msg = "当该部门名称变化后,该部门与该部门的子部门名称路径(Port_Dept.NameOfPath)将发生变化."; msg += "\t\n 该部门与该部门的子部门的人员路径也要发生变化Port_Emp列DeptDesc.StaDesc."; msg += "\t\n 您确定要执行吗?"; rm.Warning = msg; map.AddRefMethod(rm); //rm = new RefMethod(); //rm.Title = "增加同级部门"; //rm.ClassMethodName = this.ToString() + ".DoSameLevelDept"; //rm.HisAttrs.AddTBString("No", null, "同级部门编号", true, false, 0, 100, 100); //rm.HisAttrs.AddTBString("Name", null, "部门名称", true, false, 0, 100, 100); //map.AddRefMethod(rm); //rm = new RefMethod(); //rm.Title = "增加下级部门"; //rm.ClassMethodName = this.ToString() + ".DoSubDept"; //rm.HisAttrs.AddTBString("No", null, "同级部门编号", true, false, 0, 100, 100); //rm.HisAttrs.AddTBString("Name", null, "部门名称", true, false, 0, 100, 100); //map.AddRefMethod(rm); this._enMap = map; return this._enMap; } } #endregion protected override bool beforeDelete() { DeptEmps ens = new DeptEmps(); ens.Retrieve(DeptEmpAttr.FK_Dept, this.No); if (ens.Count > 0) throw new Exception("err@删除部门错误,该部门下有人员。"); DeptEmpStations ensD = new DeptEmpStations(); ensD.Retrieve(DeptEmpAttr.FK_Dept, this.No); if (ensD.Count > 0) throw new Exception("err@删除部门错误,该部门角色下有人员。"); return base.beforeDelete(); } protected override bool beforeInsert() { if (BP.DA.DataType.IsNullOrEmpty(this.No) == true) this.No = BP.DA.DBAccess.GenerGUID(5, "Port_Dept", "No"); if (BP.DA.DataType.IsNullOrEmpty(this.OrgNo) == true) this.OrgNo = BP.Web.WebUser.OrgNo; this.Adminer = WebUser.No; return base.beforeInsert(); } /// /// 创建下级节点. /// /// public string DoMyCreateSubNode() { Entity en = this.DoCreateSubNode(); return en.ToJson(); } /// /// 创建同级节点. /// /// public string DoMyCreateSameLevelNode() { Entity en = this.DoCreateSameLevelNode(); return en.ToJson(); } public string DoSameLevelDept(string no, string name) { Dept en = new Dept(); en.No = no; if (en.RetrieveFromDBSources() == 1) return "err@编号已经存在"; en.Name = name; en.ParentNo = this.ParentNo; en.Insert(); return "增加成功.."; } public string DoSubDept(string no, string name) { Dept en = new Dept(); en.No = no; if (en.RetrieveFromDBSources() == 1) return "err@编号已经存在"; en.Name = name; en.ParentNo = this.No; en.Insert(); return "增加成功.."; } /// /// 重置部门 /// /// public string DoResetPathName() { this.GenerNameOfPath(); return "重置成功."; } /// /// 生成部门全名称. /// public void GenerNameOfPath() { string name = this.Name; //根目录不再处理. if (this.IsRoot == true || this.No.Equals("100") == true) { this.NameOfPath = name; this.DirectUpdate(); this.GenerChildNameOfPath(this.No); return; } Dept dept = new Dept(); dept.No = this.ParentNo; if (dept.RetrieveFromDBSources() == 0) return; while (true) { if (dept.IsRoot || dept.No == "100") break; name = dept.Name + "\\" + name; dept = new Dept(dept.ParentNo); } //根目录 name = dept.Name + "\\" + name; this.NameOfPath = name; this.DirectUpdate(); this.GenerChildNameOfPath(this.No); } /// /// 处理子部门全名称 /// /// public void GenerChildNameOfPath(string deptNo) { Depts depts = new Depts(deptNo); // BP.Port.Depts depts = new BP.Port.Depts(deptNo); if (depts != null && depts.Count > 0) { foreach (Dept dept in depts) { dept.GenerNameOfPath(); GenerChildNameOfPath(dept.No); ////更新人员路径信息. //BP.Port.Emps emps = new Emps(); //emps.Retrieve(EmpAttr.FK_Dept, this.No); //foreach (BP.Port.Emp emp in emps) // emp.Update(); } } } } /// ///部门集合 /// public class Depts : EntitiesTree { /// /// 得到一个新实体 /// public override Entity GetNewEntity { get { return new Dept(); } } /// /// 部门集合 /// /// 父部门No public Depts(string parentNo) { this.Retrieve(DeptAttr.ParentNo, parentNo); } /// /// 部门集合 /// public Depts() { } public override int RetrieveAll() { return this.Retrieve(EmpAttr.OrgNo, BP.Web.WebUser.OrgNo); } #region 为了适应自动翻译成java的需要,把实体转换成IList, c#代码调用会出错误。 /// /// 转化成 java list,C#不能调用. /// /// List public System.Collections.Generic.IList ToJavaList() { return (System.Collections.Generic.IList)this; } /// /// 转化成list /// /// List public System.Collections.Generic.List Tolist() { System.Collections.Generic.List list = new System.Collections.Generic.List(); for (int i = 0; i < this.Count; i++) { list.Add((Dept)this[i]); } return list; } #endregion 为了适应自动翻译成java的需要,把实体转换成IList, c#代码调用会出错误。 } }