Esempio n. 1
0
        public async Task <ActionResult> tvonDemand(int?nodeID, int?Level, int?rootID, CancellationToken ct)
        {
            List <DBTreeDataProfile> root        = new List <DBTreeDataProfile>();
            DBTreeDataProfile        treeProfile = new DBTreeDataProfile();
            var taskID = TaskID;
            await Task.Delay(3000);

            //cts = new CancellationTokenSource();
            var rootItem = await Task.Run(() => treeProfile.getAccDepView());

            if (ct.IsCancellationRequested)
            {
                ct.ThrowIfCancellationRequested();
                throw new OperationCanceledException(cts.Token);
            }
            int pid    = 0;
            int rootid = 0;

            if (nodeID == null && Level == null)
            {
                var items = rootItem.Select(x => new
                {
                    nodeID      = x.MasterID,
                    text        = x.OrgSN,
                    Level       = 0,
                    hasChildren = true,
                    ParentName  = "Company"
                }).OrderBy(q => q.text).Distinct().Select(x => new
                {
                    ID = Guid.NewGuid().ToString().Replace("-", ""),
                    x.nodeID,
                    x.text,
                    x.Level,
                    x.hasChildren,
                    x.ParentName,
                    TaskID = taskID
                }
                                                          ).ToList();
                var data = new { items = items };
                if (ct.IsCancellationRequested)
                {
                    ct.ThrowIfCancellationRequested();
                    throw new OperationCanceledException(cts.Token);
                }
                return(await Task.Run(() => Json(data, JsonRequestBehavior.AllowGet)));
            }
            else
            {
                if (nodeID.HasValue)
                {
                    if (Level.Value.Equals(0))
                    {
                        pid = nodeID.Value;
                        var subItems = rootItem.Where(x => x.MasterID.Equals(pid)).Select(x => new
                        {
                            nodeID      = x.DepartID,
                            text        = x.DepartName,
                            Level       = 1,
                            hasChildren = true,
                            ParentName  = "Department",
                            rootID      = pid
                        }).Distinct()
                                       .OrderBy(a => a.text).Select(x => new {
                            ID = Guid.NewGuid().ToString().Replace("-", ""),
                            x.nodeID,
                            x.Level,
                            x.text,
                            x.hasChildren,
                            x.rootID,
                            x.ParentName,
                            TaskID = taskID
                        }).ToList();
                        var data = new { items = subItems };
                        if (ct.IsCancellationRequested)
                        {
                            ct.ThrowIfCancellationRequested();
                            throw new OperationCanceledException(cts.Token);
                        }
                        return(await Task.Run(() => Json(data, JsonRequestBehavior.AllowGet)));
                    }
                    if (Level.Value.Equals(1))
                    {
                        pid    = nodeID.Value;
                        rootid = rootID.Value;
                        var subItems = rootItem.Where(x => x.DepartID.Equals(pid) && x.MasterID.Equals(rootid)).Select(x => new
                        {
                            nodeID      = x.UserID,
                            text        = x.FirstName + " " + x.LastName,
                            Level       = 2,
                            hasChildren = false,
                            ParentName  = "User"
                        }).Distinct()
                                       .OrderBy(a => a.text).Select(x => new {
                            ID = Guid.NewGuid().ToString().Replace("-", ""),
                            x.nodeID,
                            x.Level,
                            x.text,
                            x.hasChildren,
                            x.ParentName,
                            TaskID = taskID
                        }).ToList();
                        var data = new { items = subItems };
                        if (ct.IsCancellationRequested)
                        {
                            ct.ThrowIfCancellationRequested();
                            throw new OperationCanceledException(cts.Token);
                        }
                        return(await Task.Run(() => Json(data, JsonRequestBehavior.AllowGet)));
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(null);
            }
        }
Esempio n. 2
0
        public async Task <JsonResult> TreeViewNode(int?node, int?Level, int?rootID)
        {
            List <DBTreeDataProfile> root        = new List <DBTreeDataProfile>();
            DBTreeDataProfile        treeProfile = new DBTreeDataProfile();

            var rootItem = await Task.Run(() => treeProfile.getAccDepView()).ConfigureAwait(false);

            int pid    = 0,
                rootid = 0;

            if (node == null && Level == null)
            {
                var items = rootItem.Select(x => new
                {
                    nodeID      = x.MasterID,
                    text        = x.OrgSN,
                    Level       = 0,
                    hasChildren = true,
                    ParentName  = "Company"
                }).OrderBy(q => q.text).Distinct().Select(x => new
                {
                    ID = Guid.NewGuid().ToString().Replace("-", ""),
                    x.nodeID,
                    x.text,
                    x.Level,
                    x.hasChildren,
                    x.ParentName
                }).ToList();
                var data = new { item = items };
                return(await Task.Run(() => Json(data, JsonRequestBehavior.AllowGet)).ConfigureAwait(false));
            }
            else
            {
                if (node.HasValue)
                {
                    if (Level.Value.Equals(0))
                    {
                        pid = node.Value;
                        var subItems = rootItem.Where(x => x.MasterID.Equals(pid)).Select(x => new
                        {
                            nodeID      = x.DepartID,
                            text        = x.DepartName,
                            Level       = 1,
                            hasChildren = true,
                            ParentName  = "Department",
                            rootID      = pid
                        }).Distinct().OrderBy(x => x.text).Select(x => new
                        {
                            ID = Guid.NewGuid().ToString().Replace("-", ""),
                            x.nodeID,
                            x.Level,
                            x.text,
                            x.ParentName,
                            x.hasChildren,
                            x.rootID
                        }).ToList();
                        var data = new { item = subItems };
                        return(await Task.Run(() => Json(data, JsonRequestBehavior.AllowGet)).ConfigureAwait(false));
                    }
                    if (Level.Value.Equals(1))
                    {
                        pid    = node.Value;
                        rootid = rootID.Value;
                        var subItems = rootItem.Where(x => x.DepartID.Equals(pid) && x.MasterID.Equals(rootid)).Select(x => new
                        {
                            nodeID      = x.UserID,
                            text        = x.FirstName + " " + x.LastName,
                            Level       = 2,
                            hasChildren = false,
                            ParentName  = "User"
                        }).Distinct().OrderBy(q => q.text).Select(x => new
                        {
                            ID = Guid.NewGuid().ToString().Replace("-", ""),
                            x.nodeID,
                            x.Level,
                            x.text,
                            x.hasChildren,
                            x.ParentName
                        }).ToList();
                        var data = new { items = subItems };
                        return(await Task.Run(() => Json(data, JsonRequestBehavior.AllowGet)).ConfigureAwait(false));
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(null);
            }
        }