public ActionResult _OrgChartGeo(string empId) { if (string.IsNullOrEmpty(empId)) { return(Json(0, JsonRequestBehavior.AllowGet)); } EmployeeMaster employeeMaster = bEmployeeMaster.getEmployeeByEmpId(empId); List <EmployeeDiagramViewModel> data = bEmployeeMasterReport.getDiagramGEO(employeeMaster); if (data == null && employeeMaster != null) { data = new List <EmployeeDiagramViewModel>(); EmployeeDiagramViewModel root = new EmployeeDiagramViewModel(); root.EMPNAME = employeeMaster.EMPNAME; root.EMPID = employeeMaster.EMPID; root.SYS_EMPID = employeeMaster.SYS_EMPID; root.ColorScheme = "#ee587b"; if (string.IsNullOrEmpty(employeeMaster.IMAGE)) { root.Image = "default.jpg" + "?" + (new Random()).Next(0, 100); } else { root.Image = employeeMaster.IMAGE + "?" + (new Random()).Next(0, 100); } data.Add(root); } return(Json(data, JsonRequestBehavior.AllowGet)); }
public static EmployeeDiagramViewModel Recursive(EmployeeDiagramViewModel node, string SYS_EMPID, List <EmployeeMasterReport> list) { if (list.Where(c => c.SYS_EMPIDFUN == node.SYS_EMPID).Count() < 1) { return(node); } else { List <EmployeeDiagramViewModel> newList = new List <EmployeeDiagramViewModel>(); List <EmployeeMaster> employeeMaster = bEmployeeMaster.getAllEmployees(); foreach (EmployeeMasterReport ca in list.Where(c => c.SYS_EMPIDFUN == node.SYS_EMPID)) { EmployeeDiagramViewModel child = new EmployeeDiagramViewModel(); EmployeeMaster echild = employeeMaster.Where(emp => emp.SYS_EMPID == ca.SYS_EMPID).FirstOrDefault(); child.EMPNAME = echild.EMPNAME; child.EMPID = echild.EMPID; child.SYS_EMPID = echild.SYS_EMPID; child.SYS_EMPIDGEO = ca.SYS_EMPIDGEO; child.SYS_EMPIDFUN = ca.SYS_EMPIDFUN; if (string.IsNullOrEmpty(echild.IMAGE)) { child.Image = "default.jpg" + "?" + (new Random()).Next(0, 100); } else { child.Image = echild.IMAGE + "?" + (new Random()).Next(0, 100); } if (SYS_EMPID == child.SYS_EMPID) { child.ColorScheme = "#ee587b"; } else { child.ColorScheme = "#1696d3"; } EmployeeDiagramViewModel org = Recursive(child, SYS_EMPID, list); if (org != null) { newList.Add(org); } } node.Items = newList; return(node); } }
//END GEO //Version 2.0 public static List <EmployeeDiagramViewModel> getDiagram(EmployeeMaster e) { if (e == null) { return(null); } List <EmployeeMasterReport> employeeMasterReport = bEmployeeMasterReport.getEmployeeReportBySysEmpID(e.SYS_EMPID); List <EmployeeMaster> employeeMaster = bEmployeeMaster.getAllEmployees(); List <EmployeeMasterReport> allEmployeeReport = bEmployeeMasterReport.GetEmployeeReports(); List <EmployeeMasterReport> result = new List <EmployeeMasterReport>(); EmployeeMasterReport iterate = new EmployeeMasterReport(); iterate.SYS_EMPID = e.SYS_EMPID; iterate.SYS_EMPIDFUN = e.FUNCDIRECTREPORT; iterate.SYS_EMPIDGEO = e.GEODIRECTREPORT; while (iterate != null) { if (result.Where(i => i.SYS_EMPID == iterate.SYS_EMPID).FirstOrDefault() == null) { result.Add(iterate); } iterate = allEmployeeReport.Where(erp => erp.SYS_EMPID == iterate.SYS_EMPIDFUN).FirstOrDefault(); } result.Reverse(); if (result.Count == 0) { return(null); } List <EmployeeDiagramViewModel> data = new List <EmployeeDiagramViewModel>(); if (result.Count == 1) { if (!string.IsNullOrEmpty(e.FUNCDIRECTREPORT)) { EmployeeDiagramViewModel parent = new EmployeeDiagramViewModel(); EmployeeMaster eOldParent = employeeMaster.Where(emp => emp.SYS_EMPID == e.FUNCDIRECTREPORT).FirstOrDefault(); parent.EMPNAME = eOldParent.EMPNAME; parent.EMPID = eOldParent.EMPID; parent.SYS_EMPID = eOldParent.SYS_EMPID; parent.SYS_EMPIDGEO = e.GEODIRECTREPORT; parent.SYS_EMPIDFUN = e.FUNCDIRECTREPORT; if (string.IsNullOrEmpty(eOldParent.IMAGE)) { parent.Image = "default.jpg" + "?" + (new Random()).Next(0, 100); } else { parent.Image = eOldParent.IMAGE + "?" + (new Random()).Next(0, 100); } parent.ColorScheme = "#1696d3"; EmployeeDiagramViewModel current = new EmployeeDiagramViewModel(); EmployeeMaster eCurrent = employeeMaster.Where(emp => emp.SYS_EMPID == result[0].SYS_EMPID).FirstOrDefault(); current.EMPNAME = eCurrent.EMPNAME; current.EMPID = eCurrent.EMPID; current.SYS_EMPID = eCurrent.SYS_EMPID; current.SYS_EMPIDGEO = e.GEODIRECTREPORT; current.SYS_EMPIDFUN = e.FUNCDIRECTREPORT; if (string.IsNullOrEmpty(eCurrent.IMAGE)) { current.Image = "default.jpg" + "?" + (new Random()).Next(0, 100); } else { current.Image = eCurrent.IMAGE + "?" + (new Random()).Next(0, 100); } current.ColorScheme = "#ee587b"; parent.Items = new List <EmployeeDiagramViewModel>(); parent.Items.Add(current); data.Add(parent); return(data); } else { EmployeeDiagramViewModel current = new EmployeeDiagramViewModel(); EmployeeMaster eCurrent = employeeMaster.Where(emp => emp.SYS_EMPID == result[0].SYS_EMPID).FirstOrDefault(); if (eCurrent != null) { current.EMPNAME = eCurrent.EMPNAME; current.EMPID = eCurrent.EMPID; current.SYS_EMPID = eCurrent.SYS_EMPID; current.SYS_EMPIDGEO = e.GEODIRECTREPORT; current.SYS_EMPIDFUN = e.FUNCDIRECTREPORT; if (string.IsNullOrEmpty(eCurrent.IMAGE)) { current.Image = "default.jpg" + "?" + (new Random()).Next(0, 100); } else { current.Image = eCurrent.IMAGE + "?" + (new Random()).Next(0, 100); } current.ColorScheme = "#ee587b"; data.Add(current); } return(data); } } else { EmployeeDiagramViewModel parent = new EmployeeDiagramViewModel(); EmployeeMaster eOldParent = employeeMaster.Where(emp => emp.SYS_EMPID == result[0].SYS_EMPID).FirstOrDefault(); parent.EMPNAME = eOldParent.EMPNAME; parent.EMPID = eOldParent.EMPID; parent.SYS_EMPID = eOldParent.SYS_EMPID; parent.SYS_EMPIDGEO = result[0].SYS_EMPIDGEO; parent.SYS_EMPIDFUN = result[0].SYS_EMPIDFUN; if (string.IsNullOrEmpty(eOldParent.IMAGE)) { parent.Image = "default.jpg" + "?" + (new Random()).Next(0, 100); } else { parent.Image = eOldParent.IMAGE + "?" + (new Random()).Next(0, 100); } parent.ColorScheme = "#1696d3"; EmployeeDiagramViewModel firtChild = Recursive(parent, e.SYS_EMPID, result); EmployeeDiagramViewModel child = null; if (firtChild != null && !string.IsNullOrEmpty(firtChild.SYS_EMPIDFUN)) { child = new EmployeeDiagramViewModel(); EmployeeMaster echild = employeeMaster.Where(emp => emp.SYS_EMPID == firtChild.SYS_EMPIDFUN).FirstOrDefault(); child.EMPNAME = echild.EMPNAME; child.EMPID = echild.EMPID; child.SYS_EMPID = echild.SYS_EMPID; //child.SYS_EMPIDGEO = ca.SYS_EMPIDGEO; //child.SYS_EMPIDFUN = ca.SYS_EMPIDFUN; if (string.IsNullOrEmpty(echild.IMAGE)) { child.Image = "default.jpg" + "?" + (new Random()).Next(0, 100); } else { child.Image = echild.IMAGE + "?" + (new Random()).Next(0, 100); } child.ColorScheme = "#1696d3"; child.Items = new List <EmployeeDiagramViewModel>(); child.Items.Add(firtChild); //node.Items = new List<EmployeeDiagramViewModel>(); //node.Items.Add(child); } if (child != null) { data.Add(child); } else { data.Add(firtChild); } } return(data); }