private void btExpand_Click(object sender, System.Web.UI.ImageClickEventArgs e) { int parentId = Convert.ToInt32(ddlParentList.SelectedValue); Trace.Warn("btExpand_Click and parentId = " + parentId.ToString()); if (parentId >= 0) { BuildParent(ContainerGroup.GetByKey(parentId).Childs[0].Id); } else { using (ContainerGroupList cgAll = ContainerGroup.GetAll("ContainerGroupParentId = -1")) { BuildParent(cgAll[0].Id); } } }
private void UpdateDataView() { string sSql = string.Empty; webTab.Visible = false; string filter = txtFilter.Text; if (filter != string.Empty) { string cleanFilter = filter.Replace("'", "''").ToLower(); cleanFilter = cleanFilter.Replace("[", "[[]"); cleanFilter = cleanFilter.Replace("_", "[_]"); cleanFilter = cleanFilter.Replace("%", "[%]"); sSql += " LOWER(ContainerGroup) like '%" + cleanFilter + "%'"; } using (ContainerGroupList groups = ContainerGroup.GetAll(sSql)) { if (groups != null) { if (groups.Count > 0) { dg.DataSource = groups; Utils.InitGridSort(ref dg, false); dg.DataBind(); dg.Visible = true; lbNoresults.Visible = false; } else { if (txtFilter.Text.Length > 0) { lbNoresults.Text = "No record match your search (" + txtFilter.Text + ")"; } dg.Visible = false; lbNoresults.Visible = true; } panelGrid.Visible = true; lbTitle.Text = UITools.GetTranslation("Container groups list"); } } }
/// <summary> /// /// </summary> /// <param name="parentId"></param> /// <param name="id"></param> /// Can move or change an container group even if it has children: Decision business review 09/05/06 private void BuildParent(int parentId) { Trace.Warn("BuildParent(" + parentId.ToString() + ")"); Trace.Warn(" GroupId = " + groupId.ToString()); ViewState["nbParents"] = 0; lParentName.Text = string.Empty; bool bCanMove = true; ContainerGroup cg = ContainerGroup.GetByKey(groupId); // Retrieve container based on parentId parameter ContainerGroup cgComboDisplayLevel = ContainerGroup.GetByKey(parentId); ContainerGroupList cgChildren = null; ddlParentList.Items.Clear(); if (cgComboDisplayLevel == null) { if (cg != null) { Trace.Warn(" cgComboDisplayLevel is null [#maxDepth =" + maxDepth.ToString() + ", cg.ChildDepth=" + cg.ChildDepth.ToString() + "]"); } else { Trace.Warn(" cgComboDisplayLevel is null [#maxDepth =" + maxDepth.ToString() + ", cg is null]"); } ddlParentList.Items.Clear(); ddlParentList.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Root", "-1")); if (cg != null) { btExpand.Visible = maxDepth > cg.ChildDepth; } else { btExpand.Visible = maxDepth > 0; } } else { if (cg != null) { Trace.Warn("[cg.ChildDepth=" + cg.ChildDepth.ToString() + "]"); } if (cgComboDisplayLevel.Parent == null) { using (ContainerGroupList cgAll = ContainerGroup.GetAll("ContainerGroupParentId = -1 and ContainersCount=0 AND ContainerGroupId <> " + groupId.ToString())) { cgChildren = cgAll; } } else { cgChildren = cgComboDisplayLevel.Parent.Childs; } // If container group has children if (cgChildren != null && cgChildren.Count > 0) { ddlParentList.DataSource = cgChildren; ddlParentList.DataBind(); // Remove the current item from the drop down list ddlParentList.Items.Remove(ddlParentList.Items.FindByValue(txtGroupId.Text)); ddlParentList.Visible = ddlParentList.Items.Count > 0; if (cg == null) // User is creating a new container group { ddlParentList.SelectedIndex = 0; } else { // Select the current parent if (ddlParentList.Items.FindByValue(cg.ParentId.ToString()) != null) { ddlParentList.SelectedValue = cg.ParentId.ToString(); } } int nbChilds = cgChildren[0].Childs.Count; foreach (ContainerGroup cgc in cgChildren[0].Childs) { if (cgc.Id == groupId) { nbChilds--; break; } } btExpand.Visible = nbChilds > 0; } #region maxDepth // If the maxDepth < 0 impossible to add child to a container group if (maxDepth <= 0) { panelParent.Visible = false; } else { if (cgComboDisplayLevel != null) { string[] parents = cgComboDisplayLevel.Path.Split('/'); int nbParents = parents.Length - 1; ViewState["nbParents"] = nbParents; if (btExpand.Visible) { btExpand.Visible = nbParents < maxDepth; } } } #endregion #region Build Label path ContainerGroup cgParent = cgComboDisplayLevel.Parent; while (cgParent != null) { lParentName.Text = bCanMove ? "<A HREF=javascript:__doPostBack('Path','" + cgParent.Id.ToString() + "')>" + cgParent.Name + "</A>/" + lParentName.Text : cgParent.Name + "/" + lParentName.Text; if (cgParent.ParentId != -1) { cgParent = cgParent.Parent; } else { cgParent = null; } } lParentName.Text = bCanMove ? "<A HREF=javascript:__doPostBack('Path','-1')>Root</A>/" + lParentName.Text : "Root/" + lParentName.Text; if (parentId != -1) { lParentName.Visible = true; } else { lParentName.Visible = false; } #endregion } }