protected void tlData_Init(object sender, EventArgs e) { ASPxTreeList treeList = sender as ASPxTreeList; treeList.DataSource = GetData(); treeList.DataBind(); }
protected void trvEmpleados_CustomCallback(object sender, TreeListCustomCallbackEventArgs e) { string strKey = ""; List <TreeListNode> lstSelectedNodes = trlEmpresaRep.GetSelectedNodes(); foreach (TreeListNode Node in lstSelectedNodes) { strKey += Node.Key + ","; } strKey = strKey.Substring(0, strKey.Length - 1); Session["DepartamentoSelected"] = strKey; DataTable dtbEmpleados = (DataTable)Session[Constantes.SesionTblEmpleadosSm]; String strFilter = Constantes.ColumnaEmpleadoDefaultDepId + " in (" + strKey + ")"; DataRow[] dtrFilter = dtbEmpleados.Select(strFilter); DataTable dtbFilter = dtbEmpleados.Clone(); foreach (DataRow row in dtrFilter) { dtbFilter.ImportRow(row); } Session[Constantes.SesionTblEmpleadosSm1] = dtbFilter; ASPxTreeList treeList = (sender as ASPxTreeList); treeList.DataSource = dtbFilter; treeList.DataBind(); treeList.ExpandAll(); }
protected void trlItemUnit_OnInit(object sender, EventArgs e) { ASPxTreeList treeList = sender as ASPxTreeList; object keyValue = GetMasterRowKeyValue(treeList); dsItemUnit.CriteriaParameters["ItemId"].DefaultValue = keyValue.ToString(); treeList.DataBind(); }
// drag-and-drop to reorder nodes protected void ASPxTreeList1_CustomCallback(object sender, DevExpress.Web.ASPxTreeList.TreeListCustomCallbackEventArgs e) { ASPxTreeList tl = (ASPxTreeList)sender; if (e.Argument.StartsWith("reorder:")) { string[] arg = e.Argument.Split(':'); SwapNodes(tl.FindNodeByKeyValue(arg[1]), tl.FindNodeByKeyValue(arg[2])); tl.DataBind(); } }
private void RenderTree(ASPxPopupControl container) { container.Controls.Clear(); ASPxTreeList tree = new ASPxTreeList(); tree.ID = "ASPxTreeList"; container.Controls.Add(tree); tree.Width = Unit.Percentage(100); tree.DataBinding += (sender, e) => { (sender as ASPxTreeList).ParentFieldName = "Parent"; (sender as ASPxTreeList).DataSource = Enumerable.Range(0, 10).Select(i => new { Id = i, Name = "Name" + i, Parent = i % 3 }).ToList(); }; tree.DataBind(); }
public static ASPxTreeList SetSmartDataSource <T>(this ASPxTreeList source, Action <SmartDataSourceConfiguration <T> > configurationAction) where T : class { var smartDataSourceConfiguration = new SmartDataSourceConfiguration <T>() .SetKeyPropertyName(source.KeyFieldName) .SetPageSize(source.SettingsPager.PageSize); if (configurationAction != null) { configurationAction.Invoke(smartDataSourceConfiguration); } source.DataSource = new SmartDataSource <T>(smartDataSourceConfiguration.EnsureComplete()); source.DataBind(); return(source); }
public void InstantiateIn(Control container) { ASPxTreeList treeList = new ASPxTreeList(); treeList.ID = treeList.ClientInstanceName = $"{_parentControlId}_TreeList"; treeList.DataSource = _treeListCollection; treeList.ParentFieldName = ParentFieldName; treeList.KeyFieldName = KeyFieldName; treeList.DataBind(); treeList.ClientSideEvents.NodeClick = $"function TreeListNodeClickHandler(s, e) {{ {_parentControlId}.SetKeyValue(e.nodeKey); {_parentControlId}.SetValue(e.nodeKey); " + $"{_parentControlId}.SetText({_parentControlId}_TreeList.{DropDownHashtableId}[e.nodeKey]); " + $"{_parentControlId}.RaiseValueChanged(); {_parentControlId}.HideDropDown(); {_parentControlId}.Validate(); }}"; treeList.ClientSideEvents.EndCallback = $"function(s, e){{ {_parentControlId}.ShowDropDown(); }}"; treeList.CustomJSProperties += TreeList_CustomJSProperties; treeList.Settings.ShowColumnHeaders = false; treeList.CustomCallback += TreeList_CustomCallback; container.Controls.Add(treeList); }
public override void DataBind() { base.DataBind(); this.SetSQLDataSource(); tree.DataBind(); }
void detailView_Load(object sender, EventArgs e) { ASPxTreeList detailView = (ASPxTreeList)sender; detailView.DataBind(); }
protected void tlData_CustomCallback(object sender, TreeListCustomCallbackEventArgs e) { TreeListNodeCollection siblingNodes; ASPxTreeList treeList = sender as ASPxTreeList; Dictionary <string, int> SortIndex = Session[treeList.UniqueID + "_Sort"] as Dictionary <string, int>; if (e.Argument == "MOVEUP" || e.Argument == "MOVEDOWN") { siblingNodes = (treeList.FocusedNode.ParentNode == null) ? treeList.Nodes : treeList.FocusedNode.ParentNode.ChildNodes; int siblingCount = siblingNodes.Count; int Index = SortIndex[treeList.FocusedNode.Key]; int NewIndex = Index; if (e.Argument == "MOVEUP") { NewIndex = (Index == 0) ? Index : Index - 1; } if (e.Argument == "MOVEDOWN") { NewIndex = (Index == (siblingCount - 1)) ? Index : Index + 1; } foreach (TreeListNode node in siblingNodes) { if (SortIndex[node.Key] == NewIndex) { SortIndex[treeList.FocusedNode.Key] = NewIndex; SortIndex[node.Key] = Index; break; } } } if (e.Argument.Contains("DRAGNODE")) { string[] swapKeys = e.Argument.Remove(0, 8).Split('|'); TreeListNode draggingNode = treeList.FindNodeByKeyValue(swapKeys[0]); TreeListNode targetNode = treeList.FindNodeByKeyValue(swapKeys[1]); if ((draggingNode != null) && (targetNode != null)) { siblingNodes = (targetNode.ParentNode == null) ? treeList.Nodes : targetNode.ParentNode.ChildNodes; int targetIndex = SortIndex[targetNode.Key]; int draggingIndex = SortIndex[draggingNode.Key]; int draggingDirection = (targetIndex < draggingIndex) ? 1 : -1; foreach (TreeListNode node in siblingNodes) { if ((SortIndex[node.Key] > Math.Min(targetIndex, draggingIndex)) && (SortIndex[node.Key] < Math.Max(targetIndex, draggingIndex))) { SortIndex[node.Key] += draggingDirection; } } SortIndex[draggingNode.Key] = targetIndex; SortIndex[targetNode.Key] = targetIndex + draggingDirection; } } treeList.DataBind(); UpdateTreeListButtons(treeList); }
protected void treelistCurrency_NodeUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { e.Cancel = true; using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) try { ASPxTreeList treelistCurrency = sender as ASPxTreeList; object keyValue = GetMasterRowKeyValue(treelistCurrency); #region Check ExchangeRate bool CanInsert = true; CurrencyType type = session.GetObjectByKey <CurrencyType>(keyValue); NAS.DAL.Accounting.Currency.Currency defaultCurrency = bo.get_Currency_true_master(session, type.CurrencyTypeId.ToString(), true, Constant.ROWSTATUS_ACTIVE); if (e.NewValues["IsDefault"] != null) { if (e.NewValues["IsDefault"].Equals(true)) { if (defaultCurrency != null) { if (bo.IsUsedInExchangeRate(session, defaultCurrency.CurrencyId)) { CanInsert = false; } } else { CanInsert = true; } } else { CanInsert = true; } if (!CanInsert) { throw new Exception(String.Format("Không được chọn Đơn Vị Mặc Định! Vì Đơn Vị Tiền Tệ {0} đã sử dụng trong Tỷ Giá", defaultCurrency.Code)); } } #endregion #region CHECK CODE CurrencyType cur = uow.GetObjectByKey <CurrencyType>(Guid.Parse(keyValue.ToString())); if (!e.OldValues["Code"].Equals(e.NewValues["Code"])) { if (bo.checkCurrency_Code(session, e.NewValues["Code"].ToString().Trim(), cur.CurrencyTypeId.ToString())) { e.Cancel = true; throw new Exception(String.Format("Lỗi Đơn Vị Tiền Tệ đã có")); } } #endregion object MasterKey = GetMasterRowKeyValue(treelistCurrency); Guid key = Guid.Parse(e.Keys[0].ToString()); if (e.NewValues["IsDefault"] == null) { e.NewValues["IsDefault"] = false; } bool IsDefault = bool.Parse(e.NewValues["IsDefault"].ToString()); NAS.DAL.Accounting.Currency.Currency currency = uow.GetObjectByKey <NAS.DAL.Accounting.Currency.Currency>(key); #region Currency.IsDefault if (IsDefault) { //if (bo.changeIsDefaultCurrency(uow))//, Guid.Parse(treelistCurrency.FocusedNode.Key.ToString()) //{ currency.IsDefault = true; //} //bo.changeCoefficientCurrency(uow); // Coefficient = 0; if (IsDefault) { bo.updateIsDefaultCurrency(uow, Guid.Parse(MasterKey.ToString()), key, IsDefault); } //if (cur != null) //{ // if (bo.changeIsMasterCurrencyType(uow)) // cur.IsMaster = true; // cur.Save(); //} } else { bo.updateIsDefaultCurrency(uow, Guid.Parse(MasterKey.ToString()), key, IsDefault); currency.IsDefault = false; e.NewValues["Description"] = ""; } #endregion currency.Code = e.NewValues["Code"].ToString(); currency.Name = e.NewValues["Name"].ToString(); currency.NumRequired = double.Parse(e.NewValues["NumRequired"].ToString()); uow.FlushChanges(); treelistCurrency.CancelEdit(); treelistCurrency.DataBind(); GridCurrencyUnit.DataBind(); treelistCurrency.JSProperties.Add("cpSaved", true); } catch (Exception) { uow.RollbackTransaction(); throw; } }
private void NavigatorsUpdateRemoveTrees(object fromTreeVal, object toTreeVal) { ASPxTreeList fromTree = (ASPxTreeList)fromTreeVal; ASPxTreeList toTree = (ASPxTreeList)toTreeVal; DataTable dataFrom = new DataTable(); string[] fieldValues = new string[5]; List <string> fieldValuesID = new List <string>(); List <string> fieldValuesDisplayText = new List <string>(); List <string> fieldValuesOrderNum = new List <string>(); List <string> fieldValuesParentID = new List <string>(); List <string> fieldValuesPageLink = new List <string>(); List <TreeListNode> selectItemsNavID = fromTree.GetSelectedNodes(); foreach (TreeListNode selectItemNavID in selectItemsNavID) { //If selected node is not already in the list, add it to the list if (fieldValuesID != null) { if (!fieldValuesID.Contains(selectItemNavID.GetValue("ID").ToString())) { fieldValuesID.Add(selectItemNavID.GetValue("ID").ToString()); fieldValuesDisplayText.Add(selectItemNavID.GetValue("DisplayText").ToString()); fieldValuesOrderNum.Add(selectItemNavID.GetValue("OrderNum").ToString()); fieldValuesParentID.Add(selectItemNavID.GetValue("ParentID").ToString()); fieldValuesPageLink.Add(selectItemNavID.GetValue("PageLink").ToString()); } } } //Build data table based on the existing nodes in the tree dataFrom = NavigatorBuildDataTable(fromTree); dataFrom.PrimaryKey = new DataColumn[] { dataFrom.Columns["ID"] }; DataRow dr; //Remove values from the data table, then re-assign the data table to the navigator for (int i = 0; i < fieldValuesID.Count; i++) { fieldValues[0] = fieldValuesID[i]; fieldValues[1] = fieldValuesDisplayText[i]; fieldValues[2] = fieldValuesOrderNum[i];; fieldValues[3] = fieldValuesParentID[i]; fieldValues[4] = fieldValuesPageLink[i]; if (dataFrom.Rows.Contains(fieldValues[0])) { if (fieldValues[3] != "") { DataRow[] foundRows = dataFrom.Select("ParentID = '" + fieldValues[3].ToString() + "'", "ParentID ASC", DataViewRowState.Added); if (foundRows.Length == 1) { //DataTable dtmenus = foundRows.CopyToDataTable(); //foreach (DataRow row in dtmenus.Rows) //{ // dr = dataFrom.Rows.Find(row[0].ToString()); // dataFrom.Rows.Remove(dr); //} dr = dataFrom.Rows.Find(fieldValues[3]); if (dr != null) { dataFrom.Rows.Remove(dr); } } } dr = dataFrom.Rows.Find(fieldValues[0]); dataFrom.Rows.Remove(dr); } } Session["DataNotVisible"] = dataFrom; /* * IEnumerable<TreeListNode> list = fromTree.GetAllNodes(); * foreach (TreeListNode node in list) * { * int ind = fieldValuesID.IndexOf(node.GetValue("ID").ToString()); * if (ind == -1) * { * fieldValues[0] = node.GetValue("ID").ToString(); * fieldValues[1] = node.GetValue("DisplayText").ToString(); * fieldValues[2] = node.GetValue("OrderNum").ToString(); * fieldValues[3] = node.GetValue("ParentID").ToString(); * fieldValues[4] = node.GetValue("PageLink").ToString(); * dataFrom.Rows.Add(fieldValues); * } * } * fromTree.DataSource = dataFrom; * fromTree.KeyFieldName = "ID"; * fromTree.ParentFieldName = "ParentID"; * fromTree.DataBind(); */ fromTree.UnselectAll(); fromTree.DataSource = dataFrom; fromTree.KeyFieldName = "ID"; fromTree.ParentFieldName = "ParentID"; fromTree.DataBind(); }
private void NavigatorsRebuildTrees(object fromTreeVal, object toTreeVal) { ASPxTreeList fromTree = (ASPxTreeList)fromTreeVal; ASPxTreeList toTree = (ASPxTreeList)toTreeVal; DataTable dataTo = new DataTable(); string[] fieldValues = new string[5]; List <string> fieldValuesID = new List <string>(); List <string> fieldValuesDisplayText = new List <string>(); List <string> fieldValuesOrderNum = new List <string>(); List <string> fieldValuesParentID = new List <string>(); List <string> fieldValuesPageLink = new List <string>(); List <TreeListNode> selectItemsNavID = fromTree.GetSelectedNodes(); foreach (TreeListNode selectItemNavID in selectItemsNavID) { //Check if a selected node has a parent if (selectItemNavID.ParentNode != null && selectItemNavID.ParentNode.Key != "") { //If the parent node is not already in the list, add it to the list //if (fieldValuesID != null) //{ // if (!fieldValuesID.Contains(selectItemNavID.ParentNode.GetValue("ID").ToString())) // { // fieldValuesID.Add(selectItemNavID.ParentNode.GetValue("ID").ToString()); // fieldValuesDisplayText.Add(selectItemNavID.ParentNode.GetValue("DisplayText").ToString()); // fieldValuesOrderNum.Add(selectItemNavID.ParentNode.GetValue("OrderNum").ToString()); // fieldValuesParentID.Add(selectItemNavID.ParentNode.GetValue("ParentID").ToString()); // fieldValuesPageLink.Add(selectItemNavID.ParentNode.GetValue("PageLink").ToString()); // } //} } //If selected node is not already in the list, add it to the list if (fieldValuesID != null) { if (!fieldValuesID.Contains(selectItemNavID.GetValue("ID").ToString())) { fieldValuesID.Add(selectItemNavID.GetValue("ID").ToString()); fieldValuesDisplayText.Add(selectItemNavID.GetValue("DisplayText").ToString()); fieldValuesOrderNum.Add(selectItemNavID.GetValue("OrderNum").ToString()); fieldValuesParentID.Add(selectItemNavID.GetValue("ParentID").ToString()); fieldValuesPageLink.Add(selectItemNavID.GetValue("PageLink").ToString()); } } } //Build data table based on the existing nodes in the tree dataTo = NavigatorBuildDataTable(toTree); dataTo.PrimaryKey = new DataColumn[] { dataTo.Columns["ID"] }; //Add new values to the data table, then re-assign the data table to the navigator for (int i = 0; i < fieldValuesID.Count; i++) { fieldValues[0] = fieldValuesID[i]; fieldValues[1] = fieldValuesDisplayText[i]; fieldValues[2] = fieldValuesOrderNum[i];; fieldValues[3] = fieldValuesParentID[i]; fieldValues[4] = fieldValuesPageLink[i]; if (!dataTo.Rows.Contains(fieldValues[0])) { dataTo.Rows.Add(fieldValues); } } Session["DataNotVisible"] = dataTo; /* * IEnumerable<TreeListNode> list = fromTree.GetAllNodes(); * foreach (TreeListNode node in list) * { * int ind = fieldValuesID.IndexOf(node.GetValue("ID").ToString()); * if (ind == -1) * { * fieldValues[0] = node.GetValue("ID").ToString(); * fieldValues[1] = node.GetValue("DisplayText").ToString(); * fieldValues[2] = node.GetValue("OrderNum").ToString(); * fieldValues[3] = node.GetValue("ParentID").ToString(); * fieldValues[4] = node.GetValue("PageLink").ToString(); * dataFrom.Rows.Add(fieldValues); * } * } * fromTree.DataSource = dataFrom; * fromTree.KeyFieldName = "ID"; * fromTree.ParentFieldName = "ParentID"; * fromTree.DataBind(); */ //fromTree.UnselectAll(); NavigatorVisibleTreeList.UnselectAll(); toTree.DataSource = dataTo; toTree.KeyFieldName = "ID"; toTree.ParentFieldName = "ParentID"; toTree.DataBind(); }