public static List <FunctionUsersViewModel> getTreeUserFunctions(string funccode) { var data = bFunctionReport.getUsersFunctionReports(); List <EmployeeMaster> allUsers = bEmployeeMaster.getAllEmployees(); List <FunctionUsersViewModel> funcList = new List <FunctionUsersViewModel>(); FunctionUsersViewModel func = data.Where(p => p.FUNCCODE == funccode).FirstOrDefault(); if (func == null) { return(funcList); } FunctionUsersViewModel geo = Recursive(func, data, allUsers); FunctionUsersViewModel current = func; List <FunctionUsersViewModel> result = new List <FunctionUsersViewModel>(); List <FunctionUsersViewModel> userfuncreport = new List <FunctionUsersViewModel>(); result.Add(current); while (current.childs.Count() > 0) { current = current.childs[0]; result.Add(current); } result.Reverse(); foreach (FunctionUsersViewModel userfunc in result) { List <FunctionUsersViewModel> georeports = data.Where(g => g.FUNCCODE == userfunc.FUNCCODE).ToList(); var users = allUsers.Join(georeports, u => u.SYS_EMPID, g => g.SYS_EMPID, ((u, g) => new { User = u, Geo = g })); userfunc.childs.Clear(); userfunc.Display = userfunc.FUNCNAME; userfunc.Key = userfunc.FUNCCODE; foreach (var user in users) { FunctionUsersViewModel obj = new FunctionUsersViewModel(); obj.FUNCCODE = userfunc.FUNCCODE; obj.Display = user.User.EMPNAME; obj.Key = user.Geo.SYS_EMPID; obj.Flag = 1; obj.EMPID = user.User.EMPID; if (userfunc.childs.Where(e => e.Key == obj.Key).FirstOrDefault() == null) { userfunc.childs.Add(obj); } } } for (int i = 0; i < result.Count - 1; i++) { result[i].childs.Add(result[i + 1]); } userfuncreport.Add(result[0]); return(userfuncreport); }
public static FunctionUsersViewModel Recursive(FunctionUsersViewModel func, List <FunctionUsersViewModel> funcList, List <EmployeeMaster> allUsers) { if (funcList.Where(c => c.FUNCCODE == func.FUNCPARENT).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(func); } } else { List <FunctionUsersViewModel> newList = new List <FunctionUsersViewModel>(); foreach (FunctionUsersViewModel ca in funcList.Where(c => c.FUNCCODE == func.FUNCPARENT)) { FunctionUsersViewModel funct = Recursive(ca, funcList, allUsers); if (funct != 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(funct); } } } func.childs = newList; return(func); } }
public static List <FunctionUsersViewModel> getUsersFunctionReports() { List <FunctionUsersViewModel> funcReports = new List <FunctionUsersViewModel>(); FunctionReportAccess access = new FunctionReportAccess(); DataTable dtResult = access.GetTreeFunctionReports(); foreach (DataRow dtr in dtResult.Rows) { FunctionUsersViewModel item = new FunctionUsersViewModel { Display = dtr["FUNCNAME"].ToString(), Key = dtr["FUNCPORTCD"].ToString(), Flag = 0, FUNCPORTCD = dtr["FUNCPORTCD"].ToString(), SYS_EMPID = dtr["SYS_EMPID"].ToString(), FUNCNAME = dtr["FUNCNAME"].ToString(), FUNCCODE = dtr["FUNCCODE"].ToString(), FUNCPARENT = dtr["FUNCPARENT"].ToString() }; funcReports.Add(item); } return(funcReports); }