private static ObservableCollection <TreeViewNode> ProcessXamlItemGroups(XamlItemGroup xamlItemGroups) { var rootNodes = new ObservableCollection <TreeViewNode>(); foreach (var xamlItemGroup in xamlItemGroups.Children.OrderBy(xig => xig.Name)) { var label = new Label { VerticalOptions = LayoutOptions.Center, TextColor = Color.Black }; label.SetBinding(Label.TextProperty, "Name"); var groupTreeViewNode = TreeViewHelper.CreateTreeViewNode(xamlItemGroup, label, false); rootNodes.Add(groupTreeViewNode); groupTreeViewNode.Children = ProcessXamlItemGroups(xamlItemGroup); foreach (var xamlItem in xamlItemGroup.XamlItems) { TreeViewHelper.CreateXamlItem(groupTreeViewNode.Children, xamlItem); } } return(rootNodes); }
public XamlItemGroup GroupData(IList <AccountingModel> accountingOptions) { var accountings = accountingOptions.OrderBy(x => x.ParentId); var accountingGroup = new XamlItemGroup(); foreach (var dept in accountings) { var itemGroup = new XamlItemGroup { Name = dept.Name, GroupId = dept.Number }; if (dept.ParentId <= 0) { accountingGroup.Children.Add(itemGroup); } else { XamlItemGroup parentGroup = null; foreach (var group in accountingGroup.Children) { parentGroup = FindParent(group, dept); if (parentGroup != null) { if (parentGroup.Children.Count == 0) { var item = new XamlItem { ItemId = dept.Number, ParentId = dept.ParentId, Key = dept.Name, SelectedCommand = ReactiveCommand.Create <XamlItem>(r => { if (r == null) { return; } //r.Selected = r.Selected; return; }) }; parentGroup.XamlItems.Add(item); } else { parentGroup.Children.Add(itemGroup); break; } } } } } return(accountingGroup); }
public static void ProcessXamlItems(TreeViewNode node, XamlItemGroup xamlItemGroup) { var children = new ObservableCollection <TreeViewNode>(); foreach (var xamlItem in xamlItemGroup.XamlItems.OrderBy(xi => xi.Key)) { CreateXamlItem(children, xamlItem); } node.Children = children; }
public static XamlItemGroup GroupData() { var company = GetCompany(); var departments = GetDepartments().OrderBy(x => x.ParentDepartmentId); var employees = GetEmployees(); var companyGroup = new XamlItemGroup(); companyGroup.Name = company.CompanyName; foreach (var dept in departments) { var itemGroup = new XamlItemGroup(); itemGroup.Name = dept.DepartmentName; itemGroup.GroupId = dept.DepartmentId; // Employees first var employeesDepartment = employees.Where(x => x.DepartmentId == dept.DepartmentId); foreach (var emp in employeesDepartment) { var item = new XamlItem(); item.ItemId = emp.EmployeeId; item.Key = emp.EmployeeName; itemGroup.XamlItems.Add(item); } // Departments now if (dept.ParentDepartmentId == -1) { companyGroup.Children.Add(itemGroup); } else { XamlItemGroup parentGroup = null; foreach (var group in companyGroup.Children) { parentGroup = FindParentDepartment(group, dept); if (parentGroup != null) { parentGroup.Children.Add(itemGroup); break; } } } } return(companyGroup); }
/// <summary> /// 递归结构 /// </summary> /// <param name="xamlItemGroups"></param> /// <returns></returns> private static ObservableCollection <TreeViewNode> ProcessXamlItemGroups(XamlItemGroup xamlItemGroups) { var rootNodes = new ObservableCollection <TreeViewNode>(); foreach (var xamlItemGroup in xamlItemGroups.Children.OrderBy(xig => xig.Name)) { var label = new Label { VerticalOptions = LayoutOptions.Center, TextColor = Color.Black, Text = xamlItemGroup.Name }; label.SetBinding(Label.TextProperty, "Name"); label.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => { // }) }); var checkBox = new CheckBox() { Margin = new Thickness(10, 5, 10, 0), HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, IsVisible = false }; checkBox.SetBinding(CheckBox.IsCheckedProperty, "Selected", mode: BindingMode.TwoWay); var groupTreeViewNode = CreateTreeViewNode(xamlItemGroup, label, checkBox, false); rootNodes.Add(groupTreeViewNode); //添加Children groupTreeViewNode.Children = ProcessXamlItemGroups(xamlItemGroup); foreach (var xamlItem in xamlItemGroup.XamlItems) { CreateXamlItem(groupTreeViewNode.Children, xamlItem); } } return(rootNodes); }
public XamlItemGroup FindParent(XamlItemGroup group, AccountingModel account) { if (group.GroupId == account.ParentId) { return(group); } if (group.Children != null) { foreach (var currentGroup in group.Children) { var search = FindParent(currentGroup, account); if (search != null) { return(search); } } } return(null); }
private static XamlItemGroup FindParentDepartment(XamlItemGroup group, Department department) { if (group.GroupId == department.ParentDepartmentId) { return(group); } if (group.Children != null) { foreach (var currentGroup in group.Children) { var search = FindParentDepartment(currentGroup, department); if (search != null) { return(search); } } } return(null); }
private static ObservableCollection <TreeViewNode> ProcessXamlItemGroups(XamlItemGroup xamlItemGroups, Boolean isRoot) { var rootNodes = new ObservableCollection <TreeViewNode>(); Stopwatch sw1 = new Stopwatch(); Stopwatch sw2 = new Stopwatch(); Stopwatch sw3 = new Stopwatch(); Stopwatch sw4 = new Stopwatch(); Stopwatch swTotal = new Stopwatch(); swTotal.Start(); foreach (var xamlItemGroup in xamlItemGroups.Children.OrderBy(xig => xig.Name)) { sw1.Start(); var label = new Label { VerticalOptions = LayoutOptions.Center, TextColor = Color.Black }; label.SetBinding(Label.TextProperty, "Name"); sw1.Stop(); //创建当前分类节点 sw2.Start(); var groupTreeViewNode = CreateTreeViewNode(xamlItemGroup, label, false); rootNodes.Add(groupTreeViewNode); sw2.Stop(); //创建当前分类节点下的子分类节点,递归调用 sw3.Start(); groupTreeViewNode.Children = ProcessXamlItemGroups(xamlItemGroup, false); sw3.Stop(); //创建当前分类下的普通节点(不可展开的,非分类节点), 循环调用 sw4.Start(); foreach (var xamlItem in xamlItemGroup.XamlItems) { CreateXamlItem(groupTreeViewNode.Children, xamlItem); } sw4.Stop(); } swTotal.Stop(); if (isRoot) { Console.WriteLine("sw1 cost: {0} ms", sw1.ElapsedMilliseconds); Console.WriteLine("sw2 cost: {0} ms", sw2.ElapsedMilliseconds); Console.WriteLine("sw3 cost: {0} ms", sw3.ElapsedMilliseconds); Console.WriteLine("sw4 cost: {0} ms", sw4.ElapsedMilliseconds); Console.WriteLine("total cost: {0} ms", swTotal.ElapsedMilliseconds); } return(rootNodes); }