Пример #1
0
        public static List <OriganizationUsersViewModel> getUserGeoDeptsFormTree(string depcode)
        {
            var data = bGeoReport.getUsersGeoDeptReports();
            List <EmployeeMaster> allUsers = bEmployeeMaster.getAllEmployees();

            List <OriganizationUsersViewModel> deptList = new List <OriganizationUsersViewModel>();
            OriganizationUsersViewModel        org      = data.Where(p => p.DEPTCODE == depcode).FirstOrDefault();

            if (org == null)
            {
                return(deptList);
            }
            OriganizationUsersViewModel        geo           = Recursive(org, data, allUsers);
            OriganizationUsersViewModel        current       = org;
            List <OriganizationUsersViewModel> result        = new List <OriganizationUsersViewModel>();
            List <OriganizationUsersViewModel> dataTree      = new List <OriganizationUsersViewModel>();
            List <OriganizationUsersViewModel> usergeoreport = new List <OriganizationUsersViewModel>();

            current.leaf = false;
            result.Add(current);
            dataTree.Add(current);
            while (current.childs.Count() > 0)
            {
                current      = current.childs[0];
                current.leaf = false;
                result.Add(current);
                dataTree.Add(current);
            }
            foreach (OriganizationUsersViewModel usergeo in result)
            {
                List <OriganizationUsersViewModel> georeports = data.Where(g => g.DEPTCODE == usergeo.DEPTCODE).ToList();
                var users = allUsers.Join(georeports, u => u.SYS_EMPID, g => g.SYS_EMPID, ((u, g) => new { User = u, Geo = g }));
                usergeo.Display    = usergeo.DEPTNAME;
                usergeo.Key        = usergeo.DEPTCODE;
                usergeo.DEPTPARENT = usergeo.DEPTPARENT;
                foreach (var user in users)
                {
                    OriganizationUsersViewModel obj = new OriganizationUsersViewModel();
                    obj.Display    = user.User.EMPNAME;
                    obj.Key        = user.Geo.SYS_EMPID;
                    obj.Flag       = 1;
                    obj.DEPTPARENT = usergeo.DEPTCODE;
                    obj.leaf       = true;
                    obj.EMPID      = user.User.EMPID;
                    if (dataTree.Where(e => e.Key == obj.Key).FirstOrDefault() == null)
                    {
                        dataTree.Add(obj);
                    }
                }
            }
            return(dataTree);
        }
Пример #2
0
        public static OriganizationUsersViewModel Recursive(OriganizationUsersViewModel geo, List <OriganizationUsersViewModel> deptList, List <EmployeeMaster> allUsers)
        {
            if (deptList.Where(c => c.DEPTCODE == geo.DEPTPARENT).Count() < 1)
            {
                //if (string.IsNullOrEmpty(geo.GEOREPORTCD))
                //    return null;
                //else
                {
                    //EmployeeMaster user = allUsers.Where(u => u.SYS_EMPID.Trim() == geo.SYS_EMPID.Trim()).FirstOrDefault();
                    //if (user != null)
                    //{
                    //    OriganizationUsersViewModel obj = new OriganizationUsersViewModel();
                    //    obj.Display = user.EMPNAME;
                    //    obj.Key = user.SYS_EMPID;
                    //    obj.Flag = 0;
                    //    geo.childs.Add(obj);
                    //}
                    return(geo);
                }
            }
            else
            {
                List <OriganizationUsersViewModel> newList = new List <OriganizationUsersViewModel>();
                foreach (OriganizationUsersViewModel ca in deptList.Where(c => c.DEPTCODE == geo.DEPTPARENT))
                {
                    OriganizationUsersViewModel org = Recursive(ca, deptList, allUsers);
                    if (org != null)
                    {
                        //EmployeeMaster user = allUsers.Where(u => u.SYS_EMPID.Trim() == org.SYS_EMPID.Trim()).FirstOrDefault();

                        //OriganizationUsersViewModel eObj = newList.Where(p => p.DEPTCODE == org.DEPTCODE).FirstOrDefault();
                        //if (eObj != null)
                        {
                            //if (user != null)
                            //{
                            //    OriganizationUsersViewModel obj = new OriganizationUsersViewModel();
                            //    obj.Display = user.EMPNAME;
                            //    obj.Key = user.SYS_EMPID;
                            //    obj.Flag = 0;
                            //    eObj.childs.Add(obj);
                            //}
                        }
                        //else if (eObj == null)
                        {
                            newList.Add(org);
                        }
                    }
                }
                geo.childs = newList;
                return(geo);
            }
        }
Пример #3
0
        //public static List<OriganizationUsersViewModel> getTreeGeoDepts()
        //{
        //    var data = bGeoReport.getUsersGeoDeptReports();
        //    List<EmployeeMaster> allUsers = bEmployeeMaster.getAllEmployees();
        //    List<OriganizationUsersViewModel> deptList = new List<OriganizationUsersViewModel>();
        //    OriganizationUsersViewModel currNode = null;
        //    OriganizationUsersViewModel org = data.Where(p => p.DEPTPARENT == null || p.DEPTPARENT == string.Empty).FirstOrDefault();
        //    currNode = org;
        //    OriganizationUsersViewModel geo = Recursive(org, data, allUsers);
        //    if (geo != null)
        //    {
        //        EmployeeMaster user = allUsers.Where(u => u.SYS_EMPID.Trim() == geo.SYS_EMPID.Trim()).FirstOrDefault();
        //        if (user != null)
        //        {
        //            OriganizationUsersViewModel obj = new OriganizationUsersViewModel();
        //            obj.Display = user.EMPNAME;
        //            obj.Key = user.SYS_EMPID;
        //            obj.Flag = 0;
        //            geo.childs.Reverse();
        //            geo.childs.Add(obj);
        //            geo.childs.Reverse();
        //        }
        //        deptList.Add(geo);
        //    }
        //    return deptList;
        //}
        public static List <OriganizationUsersViewModel> getTreeUserGeoDepts(string depcode)
        {
            var data = bGeoReport.getUsersGeoDeptReports();
            List <EmployeeMaster> allUsers = bEmployeeMaster.getAllEmployees();

            List <OriganizationUsersViewModel> deptList = new List <OriganizationUsersViewModel>();
            OriganizationUsersViewModel        org      = data.Where(p => p.DEPTCODE == depcode).FirstOrDefault();

            if (org == null)
            {
                return(deptList);
            }
            OriganizationUsersViewModel        geo           = Recursive(org, data, allUsers);
            OriganizationUsersViewModel        current       = org;
            List <OriganizationUsersViewModel> result        = new List <OriganizationUsersViewModel>();
            List <OriganizationUsersViewModel> usergeoreport = new List <OriganizationUsersViewModel>();

            result.Add(current);
            while (current.childs.Count() > 0)
            {
                current = current.childs[0];
                result.Add(current);
            }
            result.Reverse();
            foreach (OriganizationUsersViewModel usergeo in result)
            {
                List <OriganizationUsersViewModel> georeports = data.Where(g => g.DEPTCODE == usergeo.DEPTCODE).ToList();
                var users = allUsers.Join(georeports, u => u.SYS_EMPID, g => g.SYS_EMPID, ((u, g) => new { User = u, Geo = g }));
                usergeo.childs.Clear();
                usergeo.Display = usergeo.DEPTNAME;
                usergeo.Key     = usergeo.DEPTCODE;
                foreach (var user in users)
                {
                    OriganizationUsersViewModel obj = new OriganizationUsersViewModel();
                    obj.DEPTCODE = usergeo.DEPTCODE;
                    obj.Display  = user.User.EMPNAME;
                    obj.Key      = user.Geo.SYS_EMPID;
                    obj.Flag     = 1;
                    obj.EMPID    = user.User.EMPID;
                    if (usergeo.childs.Where(e => e.Key == obj.Key).FirstOrDefault() == null)
                    {
                        usergeo.childs.Add(obj);
                    }
                }
            }
            for (int i = 0; i < result.Count - 1; i++)
            {
                result[i].childs.Add(result[i + 1]);
            }
            usergeoreport.Add(result[0]);
            return(usergeoreport);
        }
Пример #4
0
        public static List <OriganizationUsersViewModel> getUsersGeoDeptReports()
        {
            List <OriganizationUsersViewModel> geoReports = new List <OriganizationUsersViewModel>();
            GeoReportAccess access   = new GeoReportAccess();
            DataTable       dtResult = access.GetTreeGeoReports();

            foreach (DataRow dtr in dtResult.Rows)
            {
                OriganizationUsersViewModel item = new OriganizationUsersViewModel
                {
                    Display     = dtr["DEPTNAME"].ToString(),
                    Key         = dtr["REPORTCD"].ToString(),
                    Flag        = 0,
                    GEOREPORTCD = dtr["REPORTCD"].ToString(),
                    SYS_EMPID   = dtr["SYS_EMPID"].ToString(),
                    DEPTNAME    = dtr["DEPTNAME"].ToString(),
                    DEPTCODE    = dtr["DEPTCODE"].ToString(),
                    DEPTPARENT  = dtr["DEPTPARENT"].ToString()
                };
                geoReports.Add(item);
            }
            return(geoReports);
        }