using System; using System.Data; using BP.DA; using BP.En; using BP.Web; using BP.Port; using BP.Sys; using BP.WF.Template; namespace BP.WF.Port.Admin2Group { /// /// 部门属性 /// public class DeptAttr : BP.Port.DeptAttr { } /// /// 部门 /// public class Dept : EntityTree { #region 属性 /// /// 父节点编号 /// public string ParentNo { get { return this.GetValStrByKey(DeptAttr.ParentNo); } set { this.SetValByKey(DeptAttr.ParentNo, value); } } /// /// 组织编号 /// public string OrgNo { get { return this.GetValStrByKey(DeptAttr.OrgNo); } set { this.SetValByKey(DeptAttr.OrgNo, value); } } #endregion #region 构造函数 /// /// 部门 /// public Dept() { } /// /// 部门 /// /// 编号 public Dept(string no) : base(no) { } #endregion #region 重写方法 /// /// UI界面上的访问控制 /// 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, false, 1, 30, 40); map.AddTBString(DeptAttr.Name, null, "名称", true, false, 0, 60, 200); map.AddTBString(DeptAttr.ParentNo, null, "父节点编号", true, true, 0, 30, 40); map.AddTBString(DeptAttr.OrgNo, null, "隶属组织", true, true, 0, 50, 40); map.AddTBInt(DeptAttr.Idx, 0, "顺序号", true, false); if (BP.Web.WebUser.No.Equals("admin") == true) { RefMethod rm = new RefMethod(); rm.Title = "设置为独立组织"; rm.Warning = "如果当前部门已经是独立组织,系统就会提示错误。"; rm.ClassMethodName = this.ToString() + ".SetDept2Org"; rm.HisAttrs.AddTBString("adminer", null, "组织管理员编号", true, false, 0, 100, 100); map.AddRefMethod(rm); } this._enMap = map; return this._enMap; } } #endregion protected override bool beforeDelete() { //检查是否可以删除. BP.Port.Dept dept = new BP.Port.Dept(this.No); dept.CheckIsCanDelete(); return base.beforeDelete(); } /// /// 设置组织 /// /// 管理员编号 /// public string SetDept2Org(string adminer) { if (WebUser.No.Equals("admin") == false) return "err@非admin管理员,您无法执行该操作."; //检查是否有该用户. BP.Port.Emp emp = new BP.Port.Emp(); emp.UserID = adminer; if (emp.RetrieveFromDBSources() == 0) return "err@用户编号错误:" + adminer; //如果指定的人员. if (emp.FK_Dept.Equals(this.No) == false) { Depts depts = new Depts(); depts.Retrieve(DeptAttr.ParentNo, this.No); bool isHave = false; foreach (Dept dept in depts) { if (emp.FK_Dept.Equals(dept.No)) { isHave = true; break; } } if (isHave == false) return "err@管理员不在本部门及本部门下级部门下,您不能设置他为管理员."; } //检查该部门是否是独立组织. BP.WF.Port.Admin2Group.Org org = new BP.WF.Port.Admin2Group.Org(); org.No = this.No; if (org.RetrieveFromDBSources() == 1) return "err@当前已经是独立组织."; org.Name = this.Name; //把部门名字改为组织名字. //设置父级信息. BP.Port.Dept parentDept = new BP.Port.Dept(); if (this.ParentNo.Equals("0") == true) this.ParentNo = this.No; parentDept.No = this.ParentNo; parentDept.Retrieve(); //设置管理员信息. org.Adminer = emp.UserID; org.AdminerName = emp.Name; org.Insert(); //增加到管理员. OrgAdminer oa = new OrgAdminer(); oa.FK_Emp = emp.UserID; oa.OrgNo = this.No; oa.Insert(); //设置部门编号. this.OrgNo = this.No; this.DirectUpdate(); //如果不是视图. if (DBAccess.IsView("Port_StationType") == false) { StationTypes sts = new StationTypes(); sts.Retrieve("OrgNo", this.No); if (sts.Count == 0) { #region 高层角色. StationType st = new StationType(); st.No = DBAccess.GenerGUID(); st.Name = "高层岗"; st.OrgNo = this.No; st.DirectInsert(); Station sta = new Station(); sta.No = DBAccess.GenerGUID(); sta.Name = "总经理"; sta.OrgNo = this.No; sta.FK_StationType = st.No; sta.DirectInsert(); #endregion 高层角色. #region 中层岗. st = new StationType(); st.No = DBAccess.GenerGUID(); st.Name = "中层岗"; st.OrgNo = this.No; st.DirectInsert(); sta = new Station(); sta.No = DBAccess.GenerGUID(); sta.Name = "财务部经理"; sta.OrgNo = this.No; sta.FK_StationType = st.No; sta.DirectInsert(); sta = new Station(); sta.No = DBAccess.GenerGUID(); sta.Name = "研发部经理"; sta.OrgNo = this.No; sta.FK_StationType = st.No; sta.DirectInsert(); sta = new Station(); sta.No = DBAccess.GenerGUID(); sta.Name = "市场部经理"; sta.OrgNo = this.No; sta.FK_StationType = st.No; sta.DirectInsert(); #endregion 中层岗. #region 基层岗. st = new StationType(); st.No = DBAccess.GenerGUID(); st.Name = "基层岗"; st.OrgNo = this.No; st.DirectInsert(); sta = new Station(); sta.No = DBAccess.GenerGUID(); sta.Name = "会计岗"; sta.OrgNo = this.No; sta.FK_StationType = st.No; sta.DirectInsert(); sta = new Station(); sta.No = DBAccess.GenerGUID(); sta.Name = "销售岗"; sta.OrgNo = this.No; sta.FK_StationType = st.No; sta.DirectInsert(); sta = new Station(); sta.No = DBAccess.GenerGUID(); sta.Name = "程序员岗"; sta.OrgNo = this.No; sta.FK_StationType = st.No; sta.DirectInsert(); #endregion 基层岗. } } // 返回他的检查信息,这个方法里,已经包含了自动创建独立组织的,表单树,流程树。 // 自动他创建,角色类型,角色信息. string info = org.DoCheck(); if (info.IndexOf("err@") == 0) return info; return "设置成功."; //初始化表单树,流程树. //InitFlowSortTree(); //return "设置成功,[" + ad.No + "," + ad.Name + "]重新登录就可以看到."; } } /// ///部门集合 /// public class Depts : EntitiesTree { /// /// 查询全部。 /// /// public override int RetrieveAll() { if (BP.Web.WebUser.No.Equals("admin") == true) return base.RetrieveAll(); QueryObject qo = new QueryObject(this); qo.AddWhere(DeptAttr.No, " = ", BP.Web.WebUser.FK_Dept); qo.addOr(); qo.AddWhere(DeptAttr.ParentNo, " = ", BP.Web.WebUser.FK_Dept); return qo.DoQuery(); } /// /// 得到一个新实体 /// public override Entity GetNewEntity { get { return new Dept(); } } /// /// create ens /// public Depts() { } #region 为了适应自动翻译成java的需要,把实体转换成List. /// /// 转化成 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的需要,把实体转换成List. } }