示例#1
0
 public static void Add(OrgType type, Org org)
 {
     lock (_lock)
     {
         _roots.Add(type, org);
     }
 }
示例#2
0
 private void RemoveChild(Org child)
 {
     if (child == null || this._children == null) return;
     this._children.Remove(child);
 }
示例#3
0
 private void AddChild(Org child)
 {
     if (child == null) return;
     if (this._children == null) this._children = new List<Org>(1);
     this._children.Add(child);
 }
示例#4
0
 private static void SortOrg(Org parent, Org item)
 {
     if (parent == null || item == null || parent.Children == null || parent.Children.Count <= 1 || parent.Children.IndexOf(item) < 0) return;
     int itemIndex = parent.Children.IndexOf(item);
     int exchangeIndex = 0;
     for (int i = 0; i < parent.Children.Count; i++)
     {
         exchangeIndex = i;
         if (i == itemIndex) continue;
         if (item.OrgSeq <= parent.Children[i].OrgSeq) break;
     }
     if (itemIndex != exchangeIndex)
     {
         Org temp = parent.Children[exchangeIndex];
         parent.Children[exchangeIndex] = item;
         parent.Children[itemIndex] = temp;
     }
 }
示例#5
0
 private static void LoadTree(ISession session, Org org)
 {
     if (org == null) return;
     org._children = org.NextLevelChildren(session);
     if (org._children != null && org._children.Count > 0)
         for (int i = 0; i < org._children.Count; i++)
             LoadTree(session, org._children[i]);
 }
示例#6
0
 private static Org FindInTree(Org org, int id)
 {
     if (org == null || org.OrgId == id) return org;
     if (org.Children != null && org.Children.Count > 0)
         foreach (Org o in org.Children)
         {
             Org temp = Org.FindInTree(o, id);
             if (temp != null) return temp;
         }
     return null;
 }
示例#7
0
        public static SimpleJson SaveOrg(ISession session, Org org, OrgType type, string action, User oper)
        {
            Org original = null;
            switch (action)
            {
                case "create":
                    Org parent = Org.Get(session, type, org.ParentId);
                    if (parent == null) return new SimpleJson().HandleError(string.Format("父节点{0}不存在", org.ParentId));

                    org.CreateBy = oper.UserId;
                    org.CreateDate = DateTime.Now;
                    org.IsVirtual = false;
                    org.IsRoot = false;
                    org.OrgType = type;
                    org.Deleted = false;
                    org.OrgSeq = org.OrgSeq <= 0 ? (short)(Org.MaxSeq(session, org.ParentId) + 1) : org.OrgSeq;
                    org.Create(session);

                    if (OrgTypeRegistry.HasExtAttr(type) && org.ExtAttr != null)
                    {
                        IOrgExtend oext = org.ExtAttr as IOrgExtend;
                        oext.OrgId = org.OrgId;
                        oext.Create(session);
                    }

                    parent.AddChild(org);
                    Org.SortOrg(parent, org);
                    return Org.GetOrgJSON(session, org);
                case "update":
                    original = Org.Get(session, type, org.OrgId);
                    if (original == null) return new SimpleJson().HandleError(string.Format("{0}不存在", org.OrgId));
                    original.OrgCode = org.OrgCode;
                    original.OrgName = org.OrgName;
                    original.Description = org.Description;
                    original.ModifyBy = oper.UserId;
                    original.ModifyDate = DateTime.Now;
                    original.OrgSeq = org.OrgSeq;
                    original.Manager = org.Manager;
                    original.Update(session, "OrgCode", "OrgName", "Description", "ModifyBy", "ModifyDate", "OrgSeq", "Manager");

                    if (OrgTypeRegistry.HasExtAttr(type) && org.ExtAttr != null)
                    {
                        IOrgExtend oext = org.ExtAttr as IOrgExtend;
                        oext.OrgId = org.OrgId;
                        oext.Update(session);
                        original.ExtAttr = oext;
                    }

                    Org.SortOrg(Org.Get(session, type, original.ParentId), original);
                    return Org.GetOrgJSON(session, original);
                default:
                    return new SimpleJson().HandleError(string.Format("无效的操作{0}", action));
            }
        }
示例#8
0
        public static SimpleJson GetOrgJSON(ISession session, Org org)
        {
            SimpleJson json = new SimpleJson();
            if (org == null)
            {
                json.HandleError("Org is null");
                return json;
            }

            json.Add("id", org.OrgId)
                .Add("parent", org.ParentId)
                .Add("root", org.IsRoot)
                .Add("virtual", org.IsVirtual)
                .Add("seq", org.OrgSeq)
                .Add("code", org.OrgCode)
                .Add("name", org.OrgName)
                .Add("remark", org.Description)
                .Add("desc", org);

            if (org.CreateBy > 0)
            {
                User createBy = User.Retrieve(session, org.CreateBy);
                if (createBy != null)
                    json.Add("createBy", string.IsNullOrEmpty(createBy.FullName) ? createBy.UserName : createBy.FullName);
                else
                    Log.Warn<Org>("User {0} (CreateBy) not found when loading org {1}:{2}", org.CreateBy, org.OrgId, org.OrgCode);
            }
            else
                json.Add("createBy", "");
            json.Add("createTime", org.CreateDate);

            if (org.ModifyBy > 0)
            {
                User modefyBy = User.Retrieve(session, org.ModifyBy);
                if (modefyBy != null)
                    json.Add("modifyBy", string.IsNullOrEmpty(modefyBy.FullName) ? modefyBy.UserName : modefyBy.FullName);
                else
                    Log.Warn<Org>("User {0} (ModifyBy) not found when loading org {1}:{2}", org.ModifyBy, org.OrgId, org.OrgCode);
            }
            else
                json.Add("modifyBy", "");
            json.Add("modifyTime", org.ModifyDate);

            User manager = null;
            if (org.Manager > 0)
            {
                manager = User.Retrieve(session, org.Manager);
                if (manager == null)
                    Log.Warn<Org>("User {0} (Manager) not found when loading org {1}:{2}", org.Manager, org.OrgId, org.OrgCode);
            }
            if (manager != null)
                json.Add("managerId", manager.UserId)
                    .Add("manager", string.IsNullOrEmpty(manager.FullName) ? manager.UserName : manager.FullName);
            else
                json.Add("managerId", -1)
                    .Add("manager", "");

            if (OrgTypeRegistry.HasExtAttr(org.OrgType) && org.ExtAttr != null)
            {
                Type type = OrgTypeRegistry.ExtAttrType(org.OrgType);
                org.ExtAttr.Json(session, json);
            }

            return json;
        }