public ActionResult ViewChange(string Parameters) { string isSingleView; int id, leftId, rightId; Response response = new Response(); if (!string.IsNullOrEmpty(Parameters)) { Parameters = StringCipher.Decrypt(Parameters.Replace(Utility.Utility.urlseparator, "+"), General.passPhrase); isSingleView = Utility.Utility.SplitParameters(Parameters, Utility.Utility.Colonseparator, 0, 1); id = Convert.ToInt32(Utility.Utility.SplitParameters(Parameters, Utility.Utility.Colonseparator, 1, 1)); leftId = Convert.ToInt32(Utility.Utility.SplitParameters(Parameters, Utility.Utility.Colonseparator, 2, 1)); rightId = Convert.ToInt32(Utility.Utility.SplitParameters(Parameters, Utility.Utility.Colonseparator, 3, 1)); if (isSingleView == "1") { FamilyTreeParentModel model = new FamilyTreeParentModel(); CompanyFacade fac = new CompanyFacade(this.CurrentClient.ApplicationDBConnectionString, Helper.UserName); DataTable dtFamilyTree = fac.GetListFamilyTree(); DataView view = new DataView(dtFamilyTree); DataTable distinctValues = view.ToTable(true, "FamilyTreeType"); model.lstFamilyTreeType = new SelectList(distinctValues.AsDataView(), "FamilyTreeType", "FamilyTreeType"); model.lstFamilyTree = new SelectList(dtFamilyTree.AsDataView(), "FamilyTreeId", "FamilyTreeName"); if (dtFamilyTree != null && dtFamilyTree.Rows.Count > 0) { if (id > 0) { model.FamilyTreeId = id; } else { model.FamilyTreeId = Convert.ToInt32(dtFamilyTree.Rows[0]["FamilyTreeId"]); } DataTable dtFamilyTreeById = fac.GetFamilyTreeById(model.FamilyTreeId.ToString()); if (dtFamilyTreeById != null) { model.FamilyTreeDetails = new FamilyTreeModel(); foreach (DataRow row in dtFamilyTreeById.Rows) { DataRow[] result = dtFamilyTree.Select("FamilyTreeType = '" + row["FamilyTreeType"].ToString() + "'"); model.lstFamilyTree = new SelectList(result.CopyToDataTable().AsDataView(), "FamilyTreeId", "FamilyTreeName"); model.FamilyTreeDetails.FamilyTreeId = row["FamilyTreeId"].ToString(); model.FamilyTreeDetails.FamilyTreeName = row["FamilyTreeName"].ToString(); model.FamilyTreeDetails.FamilyTreeType = row["FamilyTreeType"].ToString(); model.FamilyTreeType = model.FamilyTreeDetails.FamilyTreeType; model.FamilyTreeDetails.Editable = (string.IsNullOrEmpty(row["Editable"].ToString()) ? false : Convert.ToBoolean(row["Editable"].ToString())); model.FamilyTreeDetails.LockForEdit = (string.IsNullOrEmpty(row["LockForEdit"].ToString()) ? false : Convert.ToBoolean(row["LockForEdit"].ToString())); if (!string.IsNullOrEmpty(row["LastRefreshedDate"].ToString())) { model.FamilyTreeDetails.LastRefreshedDate = Convert.ToDateTime(row["LastRefreshedDate"].ToString()); } if (!string.IsNullOrEmpty(row["AlternateId"].ToString())) { model.FamilyTreeDetails.AlternateId = Convert.ToString(row["AlternateId"].ToString()); } if (!string.IsNullOrEmpty(row["LastModifiedUserId"].ToString())) { model.FamilyTreeDetails.LastModifiedUserName = Convert.ToString(row["LastModifiedUserId"].ToString()); } } } DataTable dt = fac.GetFamilyTree(model.FamilyTreeId); List <FamilyTreeDetailModel> treeLst = new List <FamilyTreeDetailModel>(); treeLst = (from DataRow dr in dt.Rows where dr["ParentFamilyTreeDetailId"].ToString() == string.Empty select new FamilyTreeDetailModel() { DetailId = dr["DetailId"].ToString(), FamilyTreeDetailId = dr["FamilyTreeDetailId"].ToString(), NodeName = dr["NodeName"].ToString(), ParentFamilyTreeDetailId = dr["ParentFamilyTreeDetailId"].ToString(), NodeDisplayDetail = dr["NodeDisplayDetail"].ToString(), NodeType = dr["NodeType"].ToString(), cntChildren = 1 //GetChildren(dt, dr["FamilyTreeDetailId"].ToString()) /* Recursively grab the children */ }).ToList(); model.lstMenu = treeLst; } else { model = new FamilyTreeParentModel(); } response.Success = true; response.ResponseString = RenderViewAsString.RenderPartialViewToString(this, "~/Views/FamilyTree/_DetailFamilyTreeView.cshtml", model); } else { SideBySideModel model = new SideBySideModel(); CompanyFacade fac = new CompanyFacade(this.CurrentClient.ApplicationDBConnectionString, Helper.UserName); DataTable dtFamilyTree = fac.GetListFamilyTree(); if (dtFamilyTree != null && dtFamilyTree.Rows != null && dtFamilyTree.Rows.Count > 0) { if (dtFamilyTree.Select("LockForEdit = 1").Length > 0) { DataTable dtLefFamilyTree = dtFamilyTree.Select("LockForEdit = 1").CopyToDataTable(); #region Left View model.LeftView = new FamilyTreeParentModel(); DataView viewLeft = new DataView(dtLefFamilyTree); DataTable distinctValuesLeft = viewLeft.ToTable(true, "FamilyTreeType"); model.LeftView.lstFamilyTreeType = new SelectList(distinctValuesLeft.AsDataView(), "FamilyTreeType", "FamilyTreeType"); model.LeftView.lstFamilyTree = new SelectList(dtLefFamilyTree.AsDataView(), "FamilyTreeId", "FamilyTreeName"); if (dtLefFamilyTree != null && dtLefFamilyTree.Rows.Count > 0) { if (leftId > 0) { model.LeftView.FamilyTreeId = leftId; } DataTable dtFamilyTreeById = fac.GetFamilyTreeById(model.LeftView.FamilyTreeId.ToString()); if (dtFamilyTreeById != null) { model.LeftView.FamilyTreeDetails = new FamilyTreeModel(); foreach (DataRow row in dtFamilyTreeById.Rows) { DataRow[] result = dtFamilyTree.Select("FamilyTreeType = '" + row["FamilyTreeType"].ToString() + "'"); model.LeftView.lstFamilyTree = new SelectList(result.CopyToDataTable().AsDataView(), "FamilyTreeId", "FamilyTreeName"); model.LeftView.FamilyTreeDetails.FamilyTreeId = row["FamilyTreeId"].ToString(); model.LeftView.FamilyTreeDetails.FamilyTreeName = row["FamilyTreeName"].ToString(); model.LeftView.FamilyTreeDetails.FamilyTreeType = row["FamilyTreeType"].ToString(); model.LeftView.FamilyTreeType = model.LeftView.FamilyTreeDetails.FamilyTreeType; model.LeftView.FamilyTreeDetails.Editable = (string.IsNullOrEmpty(row["Editable"].ToString()) ? false : Convert.ToBoolean(row["Editable"].ToString())); model.LeftView.FamilyTreeDetails.LockForEdit = (string.IsNullOrEmpty(row["LockForEdit"].ToString()) ? false : Convert.ToBoolean(row["LockForEdit"].ToString())); if (!string.IsNullOrEmpty(row["LastRefreshedDate"].ToString())) { model.LeftView.FamilyTreeDetails.LastRefreshedDate = Convert.ToDateTime(row["LastRefreshedDate"].ToString()); } if (!string.IsNullOrEmpty(row["AlternateId"].ToString())) { model.LeftView.FamilyTreeDetails.AlternateId = Convert.ToString(row["AlternateId"].ToString()); } if (!string.IsNullOrEmpty(row["LastModifiedUserId"].ToString())) { model.LeftView.FamilyTreeDetails.LastModifiedUserName = Convert.ToString(row["LastModifiedUserId"].ToString()); } } } DataTable dt = fac.GetFamilyTree(model.LeftView.FamilyTreeId); List <FamilyTreeDetailModel> treeLst = new List <FamilyTreeDetailModel>(); treeLst = (from DataRow dr in dt.Rows where dr["ParentFamilyTreeDetailId"].ToString() == string.Empty select new FamilyTreeDetailModel() { DetailId = dr["DetailId"].ToString(), FamilyTreeDetailId = dr["FamilyTreeDetailId"].ToString(), NodeName = dr["NodeName"].ToString(), ParentFamilyTreeDetailId = dr["ParentFamilyTreeDetailId"].ToString(), NodeDisplayDetail = dr["NodeDisplayDetail"].ToString(), NodeType = dr["NodeType"].ToString(), cntChildren = 1 //Children = GetChildren(dt, dr["FamilyTreeDetailId"].ToString()) /* Recursively grab the children */ }).ToList(); model.LeftView.lstMenu = treeLst; } #endregion #region Right View model.RightView = new FamilyTreeParentModel(); DataView viewRight = new DataView(dtFamilyTree); DataTable distinctValuesRight = viewRight.ToTable(true, "FamilyTreeType"); model.RightView.lstFamilyTreeType = new SelectList(distinctValuesRight.AsDataView(), "FamilyTreeType", "FamilyTreeType"); model.RightView.lstFamilyTree = new SelectList(dtFamilyTree.AsDataView(), "FamilyTreeId", "FamilyTreeName"); if (dtFamilyTree != null && dtFamilyTree.Rows.Count > 0) { if (rightId > 0) { model.RightView.FamilyTreeId = rightId; } DataTable dtFamilyTreeById = fac.GetFamilyTreeById(model.RightView.FamilyTreeId.ToString()); if (dtFamilyTreeById != null) { model.RightView.FamilyTreeDetails = new FamilyTreeModel(); foreach (DataRow row in dtFamilyTreeById.Rows) { DataRow[] result = dtFamilyTree.Select("FamilyTreeType = '" + row["FamilyTreeType"].ToString() + "'"); model.RightView.lstFamilyTree = new SelectList(result.CopyToDataTable().AsDataView(), "FamilyTreeId", "FamilyTreeName"); model.RightView.FamilyTreeDetails.FamilyTreeId = row["FamilyTreeId"].ToString(); model.RightView.FamilyTreeDetails.FamilyTreeName = row["FamilyTreeName"].ToString(); model.RightView.FamilyTreeDetails.FamilyTreeType = row["FamilyTreeType"].ToString(); model.RightView.FamilyTreeType = model.RightView.FamilyTreeDetails.FamilyTreeType; model.RightView.FamilyTreeDetails.Editable = (string.IsNullOrEmpty(row["Editable"].ToString()) ? false : Convert.ToBoolean(row["Editable"].ToString())); model.RightView.FamilyTreeDetails.LockForEdit = (string.IsNullOrEmpty(row["LockForEdit"].ToString()) ? false : Convert.ToBoolean(row["LockForEdit"].ToString())); if (!string.IsNullOrEmpty(row["LastRefreshedDate"].ToString())) { model.RightView.FamilyTreeDetails.LastRefreshedDate = Convert.ToDateTime(row["LastRefreshedDate"].ToString()); } if (!string.IsNullOrEmpty(row["AlternateId"].ToString())) { model.RightView.FamilyTreeDetails.AlternateId = Convert.ToString(row["AlternateId"].ToString()); } if (!string.IsNullOrEmpty(row["LastModifiedUserId"].ToString())) { model.RightView.FamilyTreeDetails.LastModifiedUserName = Convert.ToString(row["LastModifiedUserId"].ToString()); } } } DataTable dt = fac.GetFamilyTree(model.RightView.FamilyTreeId); List <FamilyTreeDetailModel> treeLst = (from DataRow dr in dt.Rows where dr["ParentFamilyTreeDetailId"].ToString() == string.Empty select new FamilyTreeDetailModel() { DetailId = dr["DetailId"].ToString(), FamilyTreeDetailId = dr["FamilyTreeDetailId"].ToString(), NodeName = dr["NodeName"].ToString(), ParentFamilyTreeDetailId = dr["ParentFamilyTreeDetailId"].ToString(), NodeDisplayDetail = dr["NodeDisplayDetail"].ToString(), NodeType = dr["NodeType"].ToString(), cntChildren = 1 //Children = GetChildren(dt, dr["FamilyTreeDetailId"].ToString()) /* Recursively grab the children */ }).ToList(); model.RightView.lstMenu = treeLst; } #endregion } else { model = new SideBySideModel(); model.LeftView = new FamilyTreeParentModel(); model.RightView = new FamilyTreeParentModel(); model.LeftView.lstMenu = new List <FamilyTreeDetailModel>(); model.RightView.lstMenu = new List <FamilyTreeDetailModel>(); } } else { model = new SideBySideModel(); model.LeftView = new FamilyTreeParentModel(); model.RightView = new FamilyTreeParentModel(); model.LeftView.lstMenu = new List <FamilyTreeDetailModel>(); model.RightView.lstMenu = new List <FamilyTreeDetailModel>(); } response.Success = true; response.ResponseString = RenderViewAsString.RenderPartialViewToString(this, "~/Views/FamilyTree/_SIdeBySide.cshtml", model); } } return(Json(response)); }
public ActionResult Index(int?id) { CompanyFacade fac = new CompanyFacade(this.CurrentClient.ApplicationDBConnectionString, Helper.UserName); DataTable dtFamilyTree = fac.GetListFamilyTree(); FamilyTreeParentModel model = new FamilyTreeParentModel(); DataView view = new DataView(dtFamilyTree); DataTable distinctValues = view.ToTable(true, "FamilyTreeType"); model.lstFamilyTreeType = new SelectList(distinctValues.AsDataView(), "FamilyTreeType", "FamilyTreeType"); if (dtFamilyTree != null && dtFamilyTree.Rows.Count > 0) { if (id != null && id > 0) { model.FamilyTreeId = Convert.ToInt32(id); } else { model.FamilyTreeId = Convert.ToInt32(dtFamilyTree.Rows[0]["FamilyTreeId"]); } DataTable dtFamilyTreeById = fac.GetFamilyTreeById(model.FamilyTreeId.ToString()); if (dtFamilyTreeById != null) { model.FamilyTreeDetails = new FamilyTreeModel(); foreach (DataRow row in dtFamilyTreeById.Rows) { DataRow[] result = dtFamilyTree.Select("FamilyTreeType = '" + row["FamilyTreeType"].ToString() + "'"); model.lstFamilyTree = new SelectList(result.CopyToDataTable().AsDataView(), "FamilyTreeId", "FamilyTreeName"); model.FamilyTreeDetails.FamilyTreeId = row["FamilyTreeId"].ToString(); model.FamilyTreeDetails.FamilyTreeName = row["FamilyTreeName"].ToString(); model.FamilyTreeDetails.FamilyTreeType = row["FamilyTreeType"].ToString(); model.FamilyTreeType = model.FamilyTreeDetails.FamilyTreeType; model.FamilyTreeDetails.Editable = (string.IsNullOrEmpty(row["Editable"].ToString()) ? false : Convert.ToBoolean(row["Editable"].ToString())); model.FamilyTreeDetails.LockForEdit = (string.IsNullOrEmpty(row["LockForEdit"].ToString()) ? false : Convert.ToBoolean(row["LockForEdit"].ToString())); if (!string.IsNullOrEmpty(row["LastRefreshedDate"].ToString())) { model.FamilyTreeDetails.LastRefreshedDate = Convert.ToDateTime(row["LastRefreshedDate"].ToString()); } if (!string.IsNullOrEmpty(row["AlternateId"].ToString())) { model.FamilyTreeDetails.AlternateId = Convert.ToString(row["AlternateId"].ToString()); } if (!string.IsNullOrEmpty(row["LastModifiedUserId"].ToString())) { model.FamilyTreeDetails.LastModifiedUserName = Convert.ToString(row["LastModifiedUserId"].ToString()); } } } DataTable dt = fac.GetFamilyTree(model.FamilyTreeId); List <FamilyTreeDetailModel> treeLst = new List <FamilyTreeDetailModel>(); treeLst = (from DataRow dr in dt.Rows where dr["ParentFamilyTreeDetailId"].ToString() == string.Empty select new FamilyTreeDetailModel() { DetailId = dr["DetailId"].ToString(), FamilyTreeDetailId = dr["FamilyTreeDetailId"].ToString(), NodeName = dr["NodeName"].ToString(), ParentFamilyTreeDetailId = dr["ParentFamilyTreeDetailId"].ToString(), NodeDisplayDetail = dr["NodeDisplayDetail"].ToString(), NodeType = dr["NodeType"].ToString(), cntChildren = 1 /* Recursively grab the children */ }).ToList(); model.lstMenu = treeLst; } return(View(model)); }