Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteClicked(object sender, EventArgs e)
        {
            UserTreeNode Node = MainTreeView.SelectedNode == null ? null : MainTreeView.SelectedNode.Tag as UserTreeNode;

            if (Node == null)
            {
                return;
            }

            // Remove usergroup.
            if (Node.IsGroup)
            {
                Program.NetClient.DeleteUserGroup(Node.Group.Name);
            }

            // Remove permission.
            else if (Node.IsPermission)
            {
                Program.NetClient.RemoveUserGroupPermission(Node.Group.Name, Node.PermissionType, Node.PermissionPath);
            }

            // Remove user.
            else if (Node.IsUser)
            {
                Program.NetClient.RemoveUserFromUserGroup(Node.Group.Name, Node.Name);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 从指定的用户Id【从下往上】构建用户【树形结构】
        /// </summary>
        /// <returns>参数【bottomUserId】对应的节点</returns>
        public UserTreeNode BuildUserTree_BottomToTop(int bottomUserId, Action <UserTreeNode> action = null)
        {
            if (GetUserFunc == null)
            {
                throw new FException("您未指定查询用户信息的方法");
            }
            if (bottomUserId <= 0)
            {
                throw new FException("您必须要传入【用户Id】");
            }

            //获取自己的节点信息
            var bottomCacheModel = this.GetUserTreeNode(bottomUserId);

            var bottomTreeNode = new UserTreeNode
            {
                UserId     = bottomCacheModel.UserId,
                UserName   = bottomCacheModel.UserName,
                ParentId   = bottomCacheModel.ParentId,
                ParentName = bottomCacheModel.ParentName,
            };

            //执行附加任务
            if (action != null)
            {
                action.Invoke(bottomTreeNode);
            }

            //开始遍历上级节点
            this.Recursion_BuildUserTree_BottomToTop(ref bottomTreeNode, action);

            return(bottomTreeNode);
        }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Name"></param>
 /// <returns></returns>
 private UserTreeNode GetPermissionNode(UserPermission Permission, UserTreeNode ParentNode)
 {
     foreach (UserTreeNode Node in ParentNode.Nodes)
     {
         if (Node.IsPermission && Node.PermissionType == Permission.Type && Node.PermissionPath == Permission.VirtualPath)
         {
             return(Node);
         }
     }
     return(null);
 }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Name"></param>
 /// <returns></returns>
 private UserTreeNode GetUserNode(string Name, UserTreeNode ParentNode)
 {
     foreach (UserTreeNode Node in ParentNode.Nodes)
     {
         if (Node.IsUser && Node.Name == Name)
         {
             return(Node);
         }
     }
     return(null);
 }
Esempio n. 5
0
        /// <summary>
        /// 从指定的用户Id【从上往下】构建【用户树形结构】
        /// </summary>
        /// <returns>参数【topUserId】对应的节点</returns>
        public UserTreeNode BuildUserTree_TopToBottom(int topUserId)
        {
            if (GetUserFunc == null)
            {
                throw new FException("您未指定查询用户信息的方法");
            }
            if (topUserId <= 0)
            {
                throw new FException("您必须要传入【用户Id】");
            }

            //获取自己的节点信息
            var topCacheModel = this.GetUserTreeNode(topUserId);

            var topTreeNode = new UserTreeNode
            {
                UserId     = topCacheModel.UserId,
                UserName   = topCacheModel.UserName,
                ParentId   = topCacheModel.ParentId,
                ParentName = topCacheModel.ParentName,
            };

            //如果存在父级节点,那么添加父级节点
            if (topCacheModel.ParentId > 0)
            {
                var parentCacheModel = this.GetUserTreeNode(topCacheModel.ParentId);

                var parentNode = new UserTreeNode
                {
                    UserId     = parentCacheModel.UserId,
                    UserName   = parentCacheModel.UserName,
                    ParentId   = parentCacheModel.ParentId,
                    ParentName = parentCacheModel.ParentName,
                };

                parentNode.ChildrenNode.Add(topTreeNode);

                topTreeNode.ParentNode = parentNode;
            }

            //开始遍历下级节点
            this.Recursion_BuildUserTree_TopToBottom(ref topTreeNode);

            return(topTreeNode);
        }
Esempio n. 6
0
        /// <summary>
        /// 递归【从下往上】构建
        /// </summary>
        private void Recursion_BuildUserTree_BottomToTop(ref UserTreeNode currTreeNode, Action <UserTreeNode> action = null)
        {
            if (GetUserFunc == null)
            {
                throw new FException("您未指定查询用户信息的方法");
            }
            if (currTreeNode.UserId <= 0)
            {
                throw new FException("您必须要传入【用户Id】");
            }
            if (currTreeNode.ParentId < 0)
            {
                throw new FException("您传入的上级【用户Id】未能找到指定的用户");
            }

            //如果没有父级节点,直接返回
            if (currTreeNode.ParentId <= 0)
            {
                return;
            }

            var parentCacheModel = this.GetUserTreeNode(currTreeNode.ParentId);

            var parentNode = new UserTreeNode
            {
                UserId     = parentCacheModel.UserId,
                UserName   = parentCacheModel.UserName,
                ParentId   = parentCacheModel.ParentId,
                ParentName = parentCacheModel.ParentName,
            };

            currTreeNode.ParentNode = parentNode;

            parentNode.ChildrenNode.Add(currTreeNode);

            //执行附加任务
            if (action != null)
            {
                action.Invoke(parentNode);
            }

            this.Recursion_BuildUserTree_BottomToTop(ref parentNode, action);
        }
Esempio n. 7
0
        /// <summary>
        /// 递归【从上往下】构建
        /// </summary>
        private void Recursion_BuildUserTree_TopToBottom(ref UserTreeNode topTreeNode)
        {
            if (GetUserFunc == null)
            {
                throw new FException("您未指定查询用户信息的方法");
            }
            if (topTreeNode.UserId <= 0)
            {
                throw new FException("您必须要传入【用户Id】");
            }

            //查询直接孩子的缓存Key
            var childUserIdList = this.FindDirectChildUserId(topTreeNode.UserId);

            //如果没有孩子,直接返回
            if (childUserIdList.Count <= 0)
            {
                return;
            }

            //遍历孩子
            foreach (int childUserId in childUserIdList)
            {
                var cacheNode = this.GetUserTreeNode(childUserId);

                var childTreeNode = new UserTreeNode
                {
                    UserId     = cacheNode.UserId,
                    UserName   = cacheNode.UserName,
                    ParentId   = cacheNode.ParentId,
                    ParentName = cacheNode.ParentName,
                };

                childTreeNode.ParentNode = topTreeNode;

                topTreeNode.ChildrenNode.Add(childTreeNode);

                this.Recursion_BuildUserTree_TopToBottom(ref childTreeNode);
            }
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddClicked(object sender, EventArgs e)
        {
            UserTreeNode Node = MainTreeView.SelectedNode == null ? null : MainTreeView.SelectedNode.Tag as UserTreeNode;

            // Add usergroup.
            if (Node == null || Node.IsGroup)
            {
                using (AddUserGroupForm form = new AddUserGroupForm())
                {
                    if (form.ShowDialog(this) == DialogResult.OK)
                    {
                        Program.NetClient.CreateUserGroup(form.GroupName);
                    }
                }
            }

            // Add permission.
            else if (Node.IsPermission || Node.IsPermissionFolder)
            {
                using (AddPermissionForm form = new AddPermissionForm())
                {
                    if (form.ShowDialog(this) == DialogResult.OK)
                    {
                        Program.NetClient.AddUserGroupPermission(Node.Group.Name, form.Permission.Type, form.Permission.VirtualPath);
                    }
                }
            }

            // Add user.
            else if (Node.IsUser || Node.IsUserFolder)
            {
                using (AddUserForm form = new AddUserForm(AllUsers))
                {
                    if (form.ShowDialog(this) == DialogResult.OK)
                    {
                        Program.NetClient.AddUserToUserGroup(Node.Group.Name, form.Username);
                    }
                }
            }
        }
        public static int setCopiedNode(UserTreeNode utn) // 0 - bez błędu, 1 - węzeł już był kopiowany, 2 - nieznany błąd
        {
            try
            {
                List <UserTreeNode> copiednodes;

                if (HttpContext.Current.Session["CopiedNodes"] == null)
                {
                    copiednodes = new List <UserTreeNode>();
                    copiednodes.Add(utn);
                }
                else
                {
                    copiednodes = HttpContext.Current.Session["CopiedNodes"] as List <UserTreeNode>;
                    //extid - może być userid lub usertreenodeid w zależności od mainuser 1 - userid, 0 - usertreenodeid
                    bool alreadyexists = copiednodes.Where(x => x.ExtID == utn.ExtID && x.MainUser == utn.MainUser).Count() == 0 ? false : true;

                    if (alreadyexists)
                    {
                        return(1); //istnieje już skopiowany ten węzeł -> wychodzimy
                    }
                    copiednodes.Add(utn);
                }

                HttpContext.Current.Session["CopiedNodes"] = copiednodes;
                return(0); //bez błędu
            }
            catch (Exception e)
            {
                DbContext db = new DbContext();
                db.Errors.Add(new Error {
                    Message = "Błąd ResourceManager, metoda:setCopiedNode - " + e.Message, StackTrace = e.StackTrace, DateThrow = DateTime.Now
                });
                db.SaveChanges();
            }

            return(2); // nieznany błąd
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectionChanged(object sender, EventArgs e)
        {
            UserTreeNode Node = MainTreeView.SelectedNode == null ? null : MainTreeView.SelectedNode.Tag as UserTreeNode;

            bool hasFullPermission = Program.NetClient.Permissions.HasPermission(UserPermissionType.ModifyUsers, "", false, true);

            deleteMenuItem.Enabled = false;
            addMenuItem.Text       = "Add User Group ...";
            deleteMenuItem.Text    = "Delete User Group";

            addMenuItem.Enabled = hasFullPermission;

            if (Node != null)
            {
                if (Node.IsPermission || Node.IsPermissionFolder)
                {
                    deleteMenuItem.Text    = "Delete Permission";
                    deleteMenuItem.Enabled = Node.IsPermission && hasFullPermission;

                    addMenuItem.Text    = "Add Permission ...";
                    addMenuItem.Enabled = hasFullPermission;
                }
                else if (Node.IsUser || Node.IsUserFolder)
                {
                    deleteMenuItem.Text    = "Remove User From Group ...";
                    deleteMenuItem.Enabled = (Node.IsUser && Node.Group.Name != "All Users") && (Program.NetClient.Permissions.HasPermission(UserPermissionType.AddUsersToGroup, Node.Group.Name) || hasFullPermission);

                    addMenuItem.Text    = "Add User To Group ...";
                    addMenuItem.Enabled = Program.NetClient.Permissions.HasPermission(UserPermissionType.AddUsersToGroup, Node.Group.Name) || hasFullPermission;
                }
                else if (Node.IsGroup)
                {
                    deleteMenuItem.Enabled = (Node.Name != "All Users") && hasFullPermission;
                    addMenuItem.Enabled    = hasFullPermission;
                }
            }
        }
Esempio n. 11
0
        public int saveCopyNode()
        {
            try
            {
                int id  = int.Parse(Request.Headers.GetValues("nodeid").First());
                int mid = int.Parse(Request.Headers.GetValues("mainuser").First());

                using (var db = new DbContext())
                {
                    UserTreeNode utn;

                    if (mid == 1) // użytkownik serwisu
                    {
                        User user = db.Users.Find(id);
                        utn = new UserTreeNode(user.UserID, user.Name, user.Surname, user.DateBorn, null, "", 1); //mainuser 1 - bo pochodzi z tabelki User, extid - tutaj wpisujemy userid
                    }
                    else
                    {
                        utn          = db.UserTreeNodes.Find(id);
                        utn.ExtID    = utn.UserTreeNodeID; //extid tutaj wpisujemy usertreenodeid -> i co za tym idzie mainuser na 0
                        utn.MainUser = 0;
                    }

                    return(ResourceManager.setCopiedNode(utn));
                }
            }catch (Exception e)
            {
                DbContext db = new DbContext();
                db.Errors.Add(new Error()
                {
                    Message = "Błąd kopiowanie węzła, metoda:saveCopyNode, controller:HomeController - " + e.Message, StackTrace = e.StackTrace, DateThrow = DateTime.Now
                });
                db.SaveChanges();
            }

            return(2); //nieznany błąd
        }
        public async Task <HtmlTreeModel> BuildUserTree()
        {
            HtmlTreeModel htm = new HtmlTreeModel();

            try
            {
                User         user = null;
                UserTreeNode usertreenodecaller = null;                                             // ten węzeł na którym klikneliśmy dodaj kolejnego partnera
                UserTreeNode usertreenodenew    = null;                                             //partner obecnie tworzony jako nowy partner danej osoby

                int    id                = int.Parse(this.Request.Headers.GetValues("id").First()); //nid -> usertreenodeid węzeł dla którego jest stworzone drzewo
                int    mainuser          = int.Parse(this.Request.Headers.GetValues("mainuser").First());
                string namenew           = this.Request.Headers.GetValues("name").First();
                string surnamenew        = this.Request.Headers.GetValues("surname").First();
                string datebornnew       = this.Request.Headers.GetValues("dateborn").First();
                string datedeadnew       = this.Request.Headers.GetValues("datedead").First();
                string additionalinfonew = this.Request.Headers.GetValues("additionalinfo").First();
                int    withimage         = int.Parse(this.Request.Headers.GetValues("withimage").First());

                using (var db = new DAL.DbContext())
                {
                    //----
                    // wyszukiwanie czy poprawne dane
                    if (mainuser == 1) //tabela users
                    {
                        user = db.Users.Find(id);

                        //korzeń naszego drzewa
                        htm.Rootid            = user.UserID;
                        htm.Mainuserroot      = 1;
                        htm.NameSurnameCaller = user.NameSurname;

                        if (user == null) // błędne podane user id
                        {
                            return(new HtmlTreeModel());
                        }
                    }
                    else if (mainuser == 0) //mainuser - 0 - szukamy czy istnieje taki node o podanym id
                    {
                        usertreenodecaller = db.UserTreeNodes.Find(id);

                        //korzeń naszego drzewa zapisujemy id
                        htm.Rootid            = usertreenodecaller.UserTreeNodeID;
                        htm.Mainuserroot      = 0;
                        htm.NameSurnameCaller = usertreenodecaller.NameSurname;

                        if (usertreenodecaller == null) // błędny podany node id
                        {
                            return(new HtmlTreeModel());
                        }

                        user = db.UserTreesUserTreeNodes.Where(x => x.UserTreeNodeID == id).First().UserTree.User;

                        if (user == null) //usera nie ma wychodzimy -> każde drzewo/poddrzewo musi mieć przypisanego usera
                        {
                            return(new HtmlTreeModel());
                        }
                    }
                    //----


                    //------
                    //Wstawianie do bazy nowego noda
                    byte[] filebytes = null;
                    if (withimage == 1)
                    {
                        var provider = new MultipartMemoryStreamProvider();
                        await this.Request.Content.ReadAsMultipartAsync(provider);

                        filebytes = await provider.Contents[0].ReadAsByteArrayAsync();
                    }

                    DateTime?dateborn = null;
                    DateTime?datedead = null;

                    if (datebornnew != "") //podano date born
                    {
                        var tabDateborn = datebornnew.Split('-');
                        dateborn = new DateTime(int.Parse(tabDateborn[0]), int.Parse(tabDateborn[1]), int.Parse(tabDateborn[2]));
                    }
                    if (datedeadnew != "") //podano date death
                    {
                        var tabDatedead = datedeadnew.Split('-');
                        datedead = new DateTime(int.Parse(tabDatedead[0]), int.Parse(tabDatedead[1]), int.Parse(tabDatedead[2]));
                    }

                    usertreenodenew = new UserTreeNode
                    {
                        Name           = namenew,
                        Surname        = surnamenew,
                        DateBorn       = dateborn,
                        DateDead       = datedead,
                        AdditionalInfo = additionalinfonew,
                        Image          = filebytes,
                    };

                    db.UserTreeNodes.Add(usertreenodenew);
                    db.SaveChanges();
                    //-----


                    string ageLabelX;
                    string dateDeadX;
                    string ageValueX;
                    if (user.LanguageID == 1)
                    {
                        ageLabelX = "147";
                        dateDeadX = "174";
                        ageValueX = "162";
                    }
                    else
                    {
                        ageLabelX = "145";
                        dateDeadX = "173";
                        ageValueX = "163";
                    }

                    //html -- połączenie między węzłami + 2x węzły
                    htm.HtmlTree =
                        "<path  d=\"M300 100 Q360 250 420 100\" fill=\"transparent\" stroke=\"black\" data-left=\"" + id + "\" data-right=\"" + usertreenodenew.UserTreeNodeID + "\"/>" +        //przeliczone na stałe z myscripts.js tam dynamicznie
                        "<g class=\"tree-elements\" id=\"" + id + "\" onmousedown=\"mousedowntreeelement(evt)\" transform=\"matrix(1 0 0 1 0 0)\" data-mainuser=\"" + mainuser + "\" data-haveRightLine=\"1\" data-haveLeftLine=\"0\" data-haveUpLine=\"1\">" +
                        "<rect class=\"tree-element-frames\" width=\"200\" height=\"100\" x=\"100\" y=\"50\" fill=\"white\" stroke=\"black\"/>" +
                        "<text class=\"tree-element-texts\" x=\"200\" y=\"65\" font-family=\"verdana\" font-size=\"12\" fill=\"blue\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>" +

                        "<rect class=\"addparents\" width=\"180\" height=\"20\" x=\"110\" y=\"30\" fill=\"white\" stroke=\"#428bca\" visibility=\"hidden\" data-have=\"0\" onclick=\"addNewNodeToTreeClick(this)\"/>" +
                        "<text class=\"addparents-dbt\" x=\"200\" y=\"40\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" visibility=\"hidden\" data-tag=\"20\" data-have=\"0\"></text>" +

                        "<rect class=\"addchildren\" width=\"180\" height=\"20\" x=\"110\" y=\"150\" fill=\"white\" stroke=\"#428bca\" visibility=\"hidden\" data-have=\"0\" onclick=\"addNewNodeToTreeClick(this)\"/>" +
                        "<text class=\"addchildren-dbt\" x=\"200\" y=\"160\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" visibility=\"hidden\" data-tag=\"24\" data-have=\"0\"></text>" +

                        "<image class=\"nodeImage\" xlink:href=\"\" x=\"230\" y=\"80\" height=\"60\" width=\"60\"/>" +

                        "<text class=\"datebirthLabel-dbt\" x=\"138\" y=\"100\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"29\"></text>" +
                        "<text class=\"datedeadLabel-dbt\" x=\"138\" y=\"110\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"30\"></text>" +
                        "<text class=\"ageLabel-dbt\" x=\"" + ageLabelX + ".5\" y=\"120\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"31\"></text>" +
                        "<text class=\"maininfoLabel-dbt\" x=\"165\" y=\"86\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"32\"></text>" +

                        "<text class=\"datebirthValue\" x=\"170\" y=\"100\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>" +
                        "<text class=\"datedeadValue\" x=\"" + dateDeadX + "\" y=\"110\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>" +
                        "<text class=\"ageValue\" x=\"" + ageValueX + "\" y=\"120\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>";

                    if (mainuser == 0) // gdy nie mainuser -> mają być pola do edycji/usuwania/kopiowania/widoku innych partnerów
                    {
                        htm.HtmlTree +=
                            "<image class=\"editImage\" xlink:href=\"\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickEdit(this)\"/>" +
                            "<rect class=\"editImageBorder\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                            "<image class=\"trashImage\" xlink:href=\"\" x=\"120\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickDelete(this)\"/>" +
                            "<rect class=\"trashImageBorder\" x=\"120\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                            "<image class=\"copyImage\" xlink:href=\"\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickCopy(this)\"/>" +
                            "<rect class=\"copyImageBorder\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                            "<image class=\"otherpartnersImage\" xlink:href=\"\" x=\"138\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickOtherPartners(this)\"/>" +
                            "<rect class=\"otherpartnersImageBorder\" x=\"138\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>";
                    }
                    else if (mainuser == 1)
                    {
                        htm.HtmlTree +=
                            "<image class=\"copyImage\" xlink:href=\"\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickCopy(this)\"/>" +
                            "<rect class=\"copyImageBorder\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                            "<image class=\"otherpartnersImage\" xlink:href=\"\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickOtherPartners(this)\"/>" +
                            "<rect class=\"otherpartnersImageBorder\" x=\"102\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>";
                    }

                    htm.HtmlTree +=
                        "</g>" +

                        //drugi nowy węzeł
                        "<g class=\"tree-elements\" id=\"" + usertreenodenew.UserTreeNodeID + "\" onmousedown=\"mousedowntreeelement(evt)\" transform=\"matrix(1 0 0 1 0 0)\" data-mainuser=\"0\" data-haveRightLine=\"0\" data-haveLeftLine=\"1\" data-haveUpLine=\"1\">" +
                        "<rect class=\"tree-element-frames\" width=\"200\" height=\"100\" x=\"420\" y=\"50\" fill=\"white\" stroke=\"black\"/>" +
                        "<text class=\"tree-element-texts\" x=\"520\" y=\"65\" font-family=\"verdana\" font-size=\"12\" fill=\"blue\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>" +

                        "<rect class=\"addparents\" width=\"180\" height=\"20\" x=\"430\" y=\"30\" fill=\"white\" stroke=\"#428bca\" visibility=\"hidden\" data-have=\"0\" onclick=\"addNewNodeToTreeClick(this)\"/>" +
                        "<text class=\"addparents-dbt\" x=\"520\" y=\"40\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" visibility=\"hidden\" data-tag=\"20\" data-have=\"0\"></text>" +

                        "<rect class=\"addpartnerR\" width=\"20\" height=\"80\" x=\"620\" y=\"60\" fill=\"white\" stroke=\"#428bca\" visibility=\"hidden\" data-have=\"1\" onclick=\"addNewNodeToTreeClick(this)\"/>" +
                        "<text class=\"addpartnerR-dbt\" transform=\"rotate(90)\" x=\"100\" y=\"-630\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" visibility=\"hidden\" data-tag=\"22\" data-have=\"1\"></text>" +

                        "<rect class=\"addpartnerL\" width=\"20\" height=\"80\" x=\"400\" y=\"60\" fill=\"white\" stroke=\"#428bca\" visibility=\"hidden\" data-have=\"1\" onclick=\"addNewNodeToTreeClick(this)\"/>" +
                        "<text class=\"addpartnerL-dbt\" transform=\"rotate(90)\" x=\"100\" y=\"-410\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\"text-anchor=\"middle\" visibility=\"hidden\" data-tag=\"23\" data-have=\"1\"></text>" +

                        "<rect class=\"addchildren\" width=\"180\" height=\"20\" x=\"430\" y=\"150\" fill=\"white\" stroke=\"#428bca\" visibility=\"hidden\" data-have=\"0\" onclick=\"addNewNodeToTreeClick(this)\"/>" +
                        "<text class=\"addchildren-dbt\" x=\"520\" y=\"160\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" visibility=\"hidden\" data-tag=\"24\" data-have=\"0\"></text>" +

                        "<image class=\"nodeImage\" xlink:href=\"\" x=\"550\" y=\"80\" height=\"60\" width=\"60\"/>" +

                        "<text class=\"datebirthLabel-dbt\" x=\"458\" y=\"100\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"29\"></text>" +
                        "<text class=\"datedeadLabel-dbt\" x=\"458\" y=\"110\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"30\"></text>" +
                        "<text class=\"ageLabel-dbt\" x=\"" + (int.Parse(ageLabelX) + 320) + ".5\" y=\"120\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"31\"></text>" +
                        "<text class=\"maininfoLabel-dbt\" x=\"485\" y=\"86\" font-family=\"verdana\" font-size=\"6\" fill=\"black\" alignment-baseline=\"middle\" text-anchor=\"middle\" data-tag=\"32\"></text>" +

                        "<text class=\"datebirthValue\" x=\"490\" y=\"100\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>" +
                        "<text class=\"datedeadValue\" x=\"" + (int.Parse(dateDeadX) + 320) + "\" y=\"110\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>" +
                        "<text class=\"ageValue\" x=\"" + (int.Parse(ageValueX) + 320) + "\" y=\"120\" font-family=\"verdana\" font-size=\"5\" fill=\"grey\" alignment-baseline=\"middle\" text-anchor=\"middle\"></text>" +

                        //opcje edytuj/usuń/kopiuj/inni partnerzy
                        "<image class=\"editImage\" xlink:href=\"\" x=\"422\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickEdit(this)\"/>" +
                        "<rect class=\"editImageBorder\" x=\"422\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                        "<image class=\"trashImage\" xlink:href=\"\" x=\"440\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickDelete(this)\"/>" +
                        "<rect class=\"trashImageBorder\" x=\"440\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                        "<image class=\"copyImage\" xlink:href=\"\" x=\"422\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickCopy(this)\"/>" +
                        "<rect class=\"copyImageBorder\" x=\"422\" y=\"455\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                        "<image class=\"otherpartnersImage\" xlink:href=\"\" x=\"458\" y=\"135\" height=\"13\" width=\"13\" visibility=\"hidden\" onclick=\"onClickOtherPartners(this)\"/>" +
                        "<rect class=\"otherpartnersImageBorder\" x=\"458\" y=\"135\" height=\"13\" width=\"13\" fill=\"none\" stroke=\"#428bca\" stroke-width=\"0.2\" visibility=\"hidden\"/>" +
                        "</g>";

                    int?usertreenodeid = usertreenodecaller == null ? (int?)null : usertreenodecaller.UserTreeNodeID;

                    //nowe drzewo
                    UserTree newtree = new UserTree
                    {
                        isMainTree            = false,
                        TransformMatrix       = "matrix(2 0 0 2 0 0)",
                        TreeHtmlCode          = htm.HtmlTree,
                        UserID                = user.UserID,
                        UserTreeNodeID        = usertreenodeid,
                        UserTreeNodePartnerID = usertreenodenew.UserTreeNodeID
                    };

                    db.UserTrees.Add(newtree);
                    db.SaveChanges();

                    //id stworzonego drzewa
                    htm.Tid = newtree.UserTreeID;

                    //łączenie nowego node z tree
                    UserTreeUserTreeNode ututn = new UserTreeUserTreeNode
                    {
                        UserTreeID     = newtree.UserTreeID,
                        UserTreeNodeID = usertreenodenew.UserTreeNodeID
                    };
                    db.UserTreesUserTreeNodes.Add(ututn);

                    //łączenie nodecaller z tree jeżeli jest -> jak nie ma caller jest z tabelki user więc jest zapisywany jak zapisujemy do UserTree wyżej
                    if (usertreenodeid != null)
                    {
                        UserTreeUserTreeNode ututn2 = new UserTreeUserTreeNode
                        {
                            UserTreeID     = newtree.UserTreeID,
                            UserTreeNodeID = (int)usertreenodeid
                        };
                        db.UserTreesUserTreeNodes.Add(ututn2);
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                DAL.DbContext db = new DAL.DbContext();
                db.Errors.Add(new Error
                {
                    Message    = "Błąd w generowaniu drzewa kolejnego partnera, HtmlBuilderController metoda:BuildUserTree() - " + e.Message,
                    StackTrace = e.StackTrace,
                    DateThrow  = DateTime.Now
                });
                db.SaveChanges();
            }

            return(htm);
        }
Esempio n. 13
0
        /// <summary>
        /// </summary>
        private void RefreshUsers(List <User> Users, List <UserGroup> UserGroups)
        {
            // Add all users group.
            foreach (UserGroup Group in UserGroups)
            {
                if (GetUsergroupNode(Group.Name) != null)
                {
                    continue;
                }

                UserTreeNode GroupNode = new UserTreeNode();
                GroupNode.Name    = Group.Name;
                GroupNode.Icon    = Resources.appbar_group;
                GroupNode.IsGroup = true;
                GroupNode.Group   = Group;
                Model.Root.Nodes.Add(GroupNode);

                UserTreeNode GroupPermissionsNode = new UserTreeNode();
                GroupPermissionsNode.Name               = "Permissions";
                GroupPermissionsNode.Icon               = Resources.appbar_folder_star;
                GroupPermissionsNode.IsFolder           = true;
                GroupPermissionsNode.IsPermissionFolder = true;
                GroupPermissionsNode.Group              = Group;
                GroupNode.Nodes.Add(GroupPermissionsNode);

                UserTreeNode GroupUsersNode = new UserTreeNode();
                GroupUsersNode.Name         = "Users";
                GroupUsersNode.Icon         = Resources.appbar_folder_people;
                GroupUsersNode.IsFolder     = true;
                GroupUsersNode.IsUserFolder = true;
                GroupUsersNode.Group        = Group;
                GroupNode.Nodes.Add(GroupUsersNode);

                GroupNode.GroupPermissionsNode = GroupPermissionsNode;
                GroupNode.GroupUsersNode       = GroupUsersNode;
            }

            // Remove old user groups.
            for (int i = 0; i < Model.Root.Nodes.Count; i++)
            {
                UserTreeNode Node = Model.Root.Nodes[i] as UserTreeNode;
                if (Node.IsGroup)
                {
                    bool Found = false;
                    foreach (UserGroup Group in UserGroups)
                    {
                        if (Group.Name == Node.Name)
                        {
                            RefreshGroup(Group, Node, Users);

                            Found = true;
                            break;
                        }
                    }

                    if (!Found)
                    {
                        Model.Root.Nodes.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Group"></param>
        /// <param name="Users"></param>
        private void RefreshGroup(UserGroup Group, UserTreeNode GroupNode, List <User> Users)
        {
            // Add all new users.
            foreach (User User in Users)
            {
                if (!User.Groups.Contains(Group.Name))
                {
                    continue;
                }

                if (GetUserNode(User.Username, GroupNode.GroupUsersNode) != null)
                {
                    continue;
                }

                UserTreeNode UserNode = new UserTreeNode();
                UserNode.Name   = User.Username;
                UserNode.Icon   = Resources.appbar_people;
                UserNode.IsUser = true;
                UserNode.Group  = Group;
                GroupNode.GroupUsersNode.Nodes.Add(UserNode);
            }

            // Remove old users.
            for (int i = 0; i < GroupNode.GroupUsersNode.Nodes.Count; i++)
            {
                UserTreeNode Node = GroupNode.GroupUsersNode.Nodes[i] as UserTreeNode;
                if (Node.IsUser)
                {
                    bool Found = false;
                    foreach (User user in Users)
                    {
                        if (!user.Groups.Contains(Group.Name))
                        {
                            continue;
                        }

                        if (user.Username == Node.Name)
                        {
                            Found = true;
                            break;
                        }
                    }

                    if (!Found)
                    {
                        GroupNode.GroupUsersNode.Nodes.RemoveAt(i);
                        i--;
                    }
                }
            }

            // All all new permissions.
            foreach (UserPermission Permission in Group.Permissions.Permissions)
            {
                if (GetPermissionNode(Permission, GroupNode.GroupPermissionsNode) != null)
                {
                    continue;
                }

                UserTreeNode PermissionNode = new UserTreeNode();
                PermissionNode.Name           = Permission.Type.GetAttributeOfType <DescriptionAttribute>().Description;
                PermissionNode.PermissionType = Permission.Type;
                PermissionNode.PermissionPath = Permission.VirtualPath;
                PermissionNode.Icon           = Resources.appbar_star;
                PermissionNode.IsPermission   = true;
                PermissionNode.Group          = Group;
                GroupNode.GroupPermissionsNode.Nodes.Add(PermissionNode);
            }

            // Remove old permissions.
            for (int i = 0; i < GroupNode.GroupPermissionsNode.Nodes.Count; i++)
            {
                UserTreeNode Node = GroupNode.GroupPermissionsNode.Nodes[i] as UserTreeNode;
                if (Node.IsPermission)
                {
                    bool Found = false;
                    foreach (UserPermission Permission in Group.Permissions.Permissions)
                    {
                        if (Permission.Type == Node.PermissionType &&
                            Permission.VirtualPath == Node.PermissionPath)
                        {
                            Found = true;
                            break;
                        }
                    }

                    if (!Found)
                    {
                        GroupNode.GroupPermissionsNode.Nodes.RemoveAt(i);
                        i--;
                    }
                }
            }
        }