public void ExpandRootNode(int maxLevel) { levels = 0; MyTrees.OpenDB(); ExpandNode(memberTreeView.Items[0] as TreeViewItem, maxLevel); MyTrees.CloseDB(); }
//显示到顶级根节点 private void btnUpRootNode_Click(object sender, RoutedEventArgs e) { TreeViewItem oldRootItem = memberTreeView.Items[0] as TreeViewItem; MyTreeNode oldRootNode = oldRootItem.Tag as MyTreeNode; MyTreeNode newRootNode = MyTrees.GetNodeBySysId(oldRootNode.TopId); if (isRingClose(newRootNode.SysId)) { return; } List <MyTreeNode> parentNodes = MyTrees.FindToRootNodeList(oldRootNode.TopId); if (parentNodes.Count > 0) { //先移除旧的根节点 memberTreeView.Items.Remove(oldRootItem); for (int i = 0; i < parentNodes.Count; i++) { MyTreeNode node = parentNodes[i]; //添加新的根节点 TreeViewItem newRootItem = NewTreeViewItem(parentNodes[i]); newRootItem.IsExpanded = true; newRootItem.Items.Add(oldRootItem); oldRootItem = newRootItem; } } memberTreeView.Items.Add(oldRootItem); btnUpLevelNode.IsEnabled = false; btnUpRootNode.IsEnabled = false; }
//展开选中项的子项 private void item_Expand(object sender, RoutedEventArgs e) { TreeViewItem treeItem = memberTreeView.SelectedItem as TreeViewItem; if (treeItem != null) { MenuItem menu = sender as MenuItem; int expLevel = int.Parse(menu.Tag.ToString()); MyTreeNode node = treeItem.Tag as MyTreeNode; if (expLevel > 1000 && node.ChildrenCountAll > 10000) { string warnTxt = "你确定要一次性展开全部子节点吗?\n展开层级过大可能会由于数据量太大而造成程序卡死。"; MessageBoxResult result = MessageBox.Show(warnTxt, "警告", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { return; } } levels = 0; TimingUtil.StartTiming(); MyTrees.OpenDB(); WindowView.notify.SetProcessBarVisible(true); ExpandNode(treeItem, expLevel); WindowView.notify.SetProcessBarVisible(false); MyTrees.CloseDB(); WindowView.notify.SetStatusMessage(TimingUtil.EndTiming()); } }
/// <summary> /// 分页控件回调函数 /// </summary> /// <param name="pageNo">页码,由分页控件传入</param> /// <param name="pageSize">每页记录数</param> /// <returns></returns> private void LoadPageData(int pageNo, int pageSize) { nodeList.Items.Clear(); List <string> nodes = new List <string>(); if (dsType == "conflict") { grpHeader.Text = "ID重复的节点"; nodes = MyTrees.GetIdConflictNodes(pageNo, pageSize); } else if (dsType == "leaf") { grpHeader.Text = "孤立的叶子节点"; nodes = MyTrees.GetLeafAloneNodes(pageNo, pageSize).Values.ToList(); } else if (dsType == "ring") { grpHeader.Text = "构成闭环的节点"; nodes = MyTrees.GetRingNodes(pageNo, pageSize).Values.ToList().ToList(); } foreach (string node in nodes) { string[] nodeProp = node.Split(new String[] { "," }, StringSplitOptions.None); nodeList.Items.Add(nodeProp); } }
//节点太多,点击加载更多未显示的节点 void moreNode_Load(object sender, RoutedEventArgs e) { TreeViewItem moreItem = sender as TreeViewItem; MyTreeNode node = moreItem.Tag as MyTreeNode; TreeViewItem parentItem = moreItem.Parent as TreeViewItem; if (parentItem != null) { parentItem.Items.Remove(moreItem); MyTrees.OpenDB(); List <MyTreeNode> childrenNodes = MyTrees.GetNodesByTopIdPage(node.TopId, node.ChildrenCount); MyTrees.CloseDB(); foreach (MyTreeNode subNode in childrenNodes) { TreeViewItem subItem = NewTreeViewItem(subNode); parentItem.Items.Add(subItem); //如果子节点还有孙子节点,则添加一个虚假的孙节点,使该子节点具有折叠的"+" if (subNode.ChildrenCount > 0) { subItem.Items.Add(NewTreeViewItem(null)); } WindowView.notify.SetStatusMessage("正在展开节点" + subItem.Header); } //表示分页加载更多的节点 node.ChildrenCount = node.ChildrenCount + MyTrees.getNodePageSize; if (node.ChildrenCount < node.ChildrenCountAll) { parentItem.Items.Add(NewTreeViewItem(node)); } } }
void item_Expanded(object sender, RoutedEventArgs e) { TreeViewItem item = e.Source as TreeViewItem; if (item.HasItems && (item.Items[0] as TreeViewItem).Header.ToString() == "更多") { //先移除为使该节点具有折叠的"+"而添加的虚假的子节点 item.Items.Clear(); MyTreeNode node = item.Tag as MyTreeNode; List <MyTreeNode> childrenNodes = MyTrees.GetNodes_ByTopId(node.SysId); foreach (MyTreeNode subNode in childrenNodes) { TreeViewItem subItem = NewTreeViewItem(subNode); item.Items.Add(subItem); //如果子节点还有孙子节点,则添加一个虚假的孙节点,使该子节点具有折叠的"+" if (subNode.ChildrenCount > 0) { subItem.Items.Add(NewTreeViewItem(null)); } WindowView.notify.SetStatusMessage("正在展开节点" + subItem.Header); } } }
//导出所有父节点 private static void ExportAllParents2CSV(StreamWriter mysw, StringBuilder allLines, MyTreeNode node) { WindowView.notify.SetStatusMessage("正在导出该节点的所有父节点。。。"); List <MyTreeNode> parentNodes = MyTrees.FindToRootNodeList(node.TopId); parentNodes.Reverse(); allRow += parentNodes.Count; for (int i = 0; i < parentNodes.Count; i++) { MyTreeNode parentNode = parentNodes[i]; allLines.Clear(); allLines.Append(parentNode.SysId); allLines.Append(","); allLines.Append(parentNode.TopId); allLines.Append(","); allLines.Append(parentNode.Name); allLines.Append(","); allLines.Append(parentNode.Level); allLines.Append(","); allLines.Append(parentNode.ChildrenLevels); allLines.Append(","); allLines.Append(parentNode.ChildrenNodes.Count); allLines.Append(","); allLines.Append(parentNode.ChildrenCount); foreach (string otherProp in parentNode.OtherProps) { allLines.Append(","); allLines.Append(otherProp); } mysw.WriteLine(allLines.ToString()); } }
public string GetSearchSql() { searchParams = new List <string>(); StringBuilder sb = new StringBuilder(); AddFilter(sb, "sysid", txtSysid, comboSysid); AddFilter(sb, "topid", txtTopid, comboTopid); AddFilter(sb, "name", txtName, comboName); AddFilter(sb, "level", txtLevel, comboLevel); AddFilter(sb, "sublevel", txtSubLevels, comboSubLevels); AddFilter(sb, "subcount", txtSubCount, comboSubCount); AddFilter(sb, "subcountall", txtAllSubCount, comboAllSubCount); List <string> optCols = MyTrees.GetTableOptCols(); for (int i = 0; i < optCols.Count; i++) { AddFilter(sb, optCols[i], txtCols[i], comboCols[i]); } if (sb.Length > 0) { return("select sysid,topid,name,level,sublevel,subcount,subcountall from " + MyTrees.treeDB.TableName + "_calc where 1=1" + sb + " order by subcountall desc limit 0, 100"); } else { return(null); } }
public void SetRootNode(MyTreeNode rootNode) { pager.Visibility = Visibility.Hidden; memberTreeView.Items.Clear(); ringNodeIds.Clear(); if (rootNode != null) { TreeViewItem rootItem = NewTreeViewItem(rootNode); memberTreeView.Items.Add(rootItem); //如果还有子节点,则添加一个节点,使该节点具有折叠的"+" if (rootNode.ChildrenCount > 0) { rootItem.Items.Add(NewTreeViewItem(null)); } MyTrees.OpenDB(); //判断当前根节点是否存在父节点 if (MyTrees.GetNodeBySysId(rootNode.TopId) != null) { btnUpLevelNode.IsEnabled = true; btnUpRootNode.IsEnabled = true; } else { btnUpLevelNode.IsEnabled = false; btnUpRootNode.IsEnabled = false; } MyTrees.CloseDB(); } }
//显示上一级节点 private void btnUpLevelNode_Click(object sender, RoutedEventArgs e) { TreeViewItem oldRootItem = memberTreeView.Items[0] as TreeViewItem; MyTreeNode oldRootNode = oldRootItem.Tag as MyTreeNode; MyTreeNode newRootNode = MyTrees.GetNodeBySysId(oldRootNode.TopId); if (isRingClose(newRootNode.SysId)) { return; } //先移除旧的根节点 memberTreeView.Items.Remove(oldRootItem); //添加新的根节点 TreeViewItem newRootItem = NewTreeViewItem(newRootNode); memberTreeView.Items.Add(newRootItem); newRootItem.IsExpanded = true; //新的根节点添加子节点 List <MyTreeNode> childrenNodes = MyTrees.GetNodes_ByTopId(newRootNode.SysId); bool hasNotAdded = true; foreach (MyTreeNode subNode in childrenNodes) { if (hasNotAdded) { if (oldRootNode.SysId == subNode.SysId) { newRootItem.Items.Add(oldRootItem); hasNotAdded = false; continue; } } TreeViewItem subItem = NewTreeViewItem(subNode); newRootItem.Items.Add(subItem); //如果子节点还有孙子节点,则添加一个虚假的孙节点,使该子节点具有折叠的"+" if (subNode.ChildrenCount > 0) { subItem.Items.Add(NewTreeViewItem(null)); } } //判断当前根节点是否存在父节点 if (MyTrees.GetNodeBySysId(newRootNode.TopId) != null) { btnUpLevelNode.IsEnabled = true; btnUpRootNode.IsEnabled = true; } else { btnUpLevelNode.IsEnabled = false; btnUpRootNode.IsEnabled = false; } }
internal static int GetIdConflictNodesCount() { MyTrees.OpenDB(); string sql = "select count(*) from " + treeDB.TableName + "_calc where sysid in (select v from " + treeDB.TableName + "_profile where k='Conflict')"; int count = treeDB.SearchCount(sql); MyTrees.CloseDB(); return(count); }
internal static List <string> GetLeafAloneNodeIds() { if (leafAloneNodeIds == null) { leafAloneNodeIds = new List <string>(); MyTrees.OpenDB(); string sql = "select v from " + treeDB.TableName + "_profile where k='Leaf'"; leafAloneNodeIds = treeDB.SearchString(sql); MyTrees.CloseDB(); } return(leafAloneNodeIds); }
internal static List <string> GetRingNodeIds() { if (ringNodes == null) { ringNodes = new List <string>(); MyTrees.OpenDB(); string sql = "select v from " + treeDB.TableName + "_profile where k='Ring'"; ringNodes = treeDB.SearchString(sql); MyTrees.CloseDB(); } return(ringNodes); }
internal static List <MyTreeNode> GetTreeRootNodes(int pageNo, int pageSize) { MyTrees.OpenDB(); string sql = "select sysid,topid,name,level,sublevel,subcount,subcountall from " + treeDB.TableName + "_calc where sysid in (select v from " + treeDB.TableName + "_profile where k='Tree') order by subcountall desc limit " + (pageNo * pageSize) + ", " + pageSize; List <MyTreeNode> treeRootNodes = treeDB.SearchNode(sql); MyTrees.CloseDB(); return(treeRootNodes); }
internal static List <string> GetIdConflictNodes(int pageNo, int pageSize) { MyTrees.OpenDB(); string sql = "select * from " + treeDB.TableName + "_calc where sysid in (select v from " + treeDB.TableName + "_profile where k='Conflict') limit " + (pageNo * pageSize) + ", " + pageSize; List <string> conflictNodes = treeDB.SearchString(sql); MyTrees.CloseDB(); return(conflictNodes); }
public void InitCols() { List <string> tableOptCols = MyTrees.GetTableOptCols(); for (int i = 0; i < tableOptCols.Count; i++) { GridViewColumn col = new GridViewColumn(); col.Header = tableOptCols[i]; col.DisplayMemberBinding = new Binding("[" + (i + 7) + "]"); gridView.Columns.Add(col); } }
//导出所有父节点 private static void ExportAllParents2CSV(StreamWriter mysw, StringBuilder allLines, MyTreeNode node) { WindowView.notify.SetStatusMessage("正在导出该节点的所有父节点。。。"); List <string> parentNodes = MyTrees.FindToRootAllList(node.TopId); parentNodes.Reverse(); allRow += parentNodes.Count; for (int i = 0; i < parentNodes.Count; i++) { mysw.WriteLine(parentNodes[i]); } }
private static void ExportAllImgs(MyTreeView mytreeview, MyTreeNode node) { mytreeview.BeginExportImg(); exportNodes.Clear(); exportNodes.Add(node); MyTrees.OpenDB(); while (exportNodes.Count > 0) { ExportImg(mytreeview, exportNodes[0]); } mytreeview.EndExportImg(); MyTrees.CloseDB(); }
internal static List <string> GetTableOptCols() { if (tableOptCols == null) { MyTrees.OpenDB(); string sql = "select v from " + treeDB.TableName + "_profile where k='TableOptCol'"; tableOptCols = treeDB.SearchString(sql); MyTrees.CloseDB(); } return(tableOptCols); }
void item_Expanded(object sender, RoutedEventArgs e) { TreeViewItem item = e.Source as TreeViewItem; if (item.HasItems && (item.Items[0] as TreeViewItem).Header.ToString() == "none") { //先移除为使该节点具有折叠的"+"而添加的虚假的子节点 item.Items.Clear(); if ((e.Source as TreeViewItem).IsSelected) { MyTrees.OpenDB(); } MyTreeNode node = item.Tag as MyTreeNode; List <MyTreeNode> childrenNodes = MyTrees.GetNodesByTopIdPage(node.SysId, 0); foreach (MyTreeNode subNode in childrenNodes) { TreeViewItem subItem = NewTreeViewItem(subNode); item.Items.Add(subItem); //如果子节点还有孙子节点,则添加一个虚假的孙节点,使该子节点具有折叠的"+" if (subNode.ChildrenCount > 0) { subItem.Items.Add(NewTreeViewItem(null)); } WindowView.notify.SetStatusMessage("正在展开节点" + subItem.Header); } //表示分页加载更多的节点 if (node.ChildrenCount > MyTrees.getNodePageSize) { MyTreeNode moreNode = new MyTreeNode(); moreNode.SysId = "moreNode"; moreNode.Name = node.Name; moreNode.TopId = node.SysId; moreNode.ChildrenCount = MyTrees.getNodePageSize; moreNode.ChildrenCountAll = node.ChildrenCount; item.Items.Add(NewTreeViewItem(moreNode)); } if ((e.Source as TreeViewItem).IsSelected) { MyTrees.CloseDB(); } } }
private void btnCompute_Click(object sender, RoutedEventArgs e) { if (!Directory.Exists(MemData.MemDataTemp)) { Directory.CreateDirectory(MemData.MemDataTemp); } string expName = MemData.MemDataTemp + "/exp_" + txtTable.SelectedValue + ".tab"; if (ExportData(expName)) { this.Close(); MyTrees.OpenDBFile(expName, "\t", false); File.Delete(expName); } }
//判断闭环是否关闭 private static bool isRingClose(string id) { if (MyTrees.GetRingNodeIds().Contains(id)) { if (ringNodeIds.Contains(id)) { return(true); } else { ringNodeIds.Add(id); } } return(false); }
//查找 private void ButtonSearch_Click(object sender, RoutedEventArgs e) { List <string> searchParams = mySearchFilter.GetSearchParams(); if (searchParams != null) { TimingUtil.StartTiming(); WindowView.notify.SetStatusMessage("正在查询,请稍后。。。"); WindowView.notify.SetProcessBarVisible(true); searchResults.NodeListView.ItemsSource = MyTrees.FindBySql(searchParams); WindowView.notify.SetStatusMessage("查询完成!"); WindowView.notify.SetProcessBarVisible(false); WindowView.notify.SetStatusMessage(TimingUtil.EndTiming()); } }
void item_Expanded(TreeNode tn) { MyTreeNode node = tn.Tag as MyTreeNode; if (node != null) { List <MyTreeNode> childrenNodes = MyTrees.GetNodes_ByTopId(node.SysId);; foreach (MyTreeNode subNode in childrenNodes) { Button grandson = NewTreeViewItem(subNode); TreeNode newNode = memberTreeView.AddNode(grandson, tn); newNode.Tag = subNode; newNode.Collapsed = true; } } }
internal void InitCols() { addCol("会员ID:"); addCol("父级ID:"); addCol("会员姓名:"); addCol("所在等级:"); addCol("下线层级数:"); addCol("直接下级数:"); addCol("下级总数:"); List <string> optCols = MyTrees.GetTableOptCols(); for (int i = 0; i < optCols.Count; i++) { addCol(optCols[i] + ":"); } }
private static void Export2CSVImp(StreamWriter mysw, StringBuilder allLines, MyTreeNode node, bool recu) { if (isRingClose(node.SysId)) { return; } allLines.Clear(); allLines.Append(node.SysId); allLines.Append(","); allLines.Append(node.TopId); allLines.Append(","); allLines.Append(node.Name); allLines.Append(","); allLines.Append(node.Level); allLines.Append(","); allLines.Append(node.ChildrenLevels); allLines.Append(","); allLines.Append(node.ChildrenCount); allLines.Append(","); allLines.Append(node.ChildrenCountAll); allLines.Append(","); foreach (string otherProp in node.OtherProps) { allLines.Append(","); allLines.Append(otherProp); } mysw.WriteLine(allLines.ToString()); row++; if (row % 100 == 0) { WindowView.notify.SetProcessBarValue((int)(100.0 * row / allRow)); WindowView.notify.SetStatusMessage("正在导出第" + row + "个节点(总共" + allRow + "个节点)"); } if (recu) { List <MyTreeNode> childrenNodes = MyTrees.GetNodesByTopId(node.SysId); foreach (MyTreeNode subNode in childrenNodes) { Export2CSVImp(mysw, allLines, subNode, recu); } } }
void item_Expanded(object sender, RoutedEventArgs e) { TreeViewItem item = e.Source as TreeViewItem; foreach (TreeViewItem subItem in item.Items) { MyTreeNode node = subItem.Tag as MyTreeNode; if (node != null) { List <MyTreeNode> childrenNodes = MyTrees.GetNodesByTopId(node.SysId); foreach (MyTreeNode subNode in childrenNodes) { TreeViewItem grandson = NewTreeViewItem(subNode); subItem.Items.Add(grandson); } } } }
/// <summary> /// 分页控件回调函数 /// </summary> /// <param name="pageNo">页码,由分页控件传入</param> /// <param name="pageSize">每页记录数</param> /// <returns></returns> private void LoadPageData(int pageNo, int pageSize) { List <MyTreeNode> treeRootNodes = MyTrees.GetTreeRootNodes(pageNo, pageSize); TreeViewItem rootItem = memberTreeView.Items[0] as TreeViewItem; rootItem.Items.Clear(); if (rootItem != null && treeRootNodes.Count > 0) { for (int i = 0; i < treeRootNodes.Count; i++) { TreeViewItem subItem = NewTreeViewItem(treeRootNodes[i]); rootItem.Items.Add(subItem); //如果还有子节点,则添加一个节点,使该节点具有折叠的"+" subItem.Items.Add(NewTreeViewItem(null)); } } }
//打开文件 private void ButtonOpen_Click(object sender, RoutedEventArgs e) { bool csv_or_tab = (sender == btnImportCsv); OpenFileDialog openfileDlg = new OpenFileDialog(); openfileDlg.Title = "打开要作为会员树数据源的文件"; openfileDlg.Filter = csv_or_tab ? "CSV逗号分隔文件|*.csv" : "TAB键分割文件|*.tab"; if (openfileDlg.ShowDialog() == true) { windowAdmin.progressView.SetCsvFile(openfileDlg.FileName); TextUtil.enUpperLower = (EnumUpperLower)comboToLower.SelectedIndex; TextUtil.enDBCSBC = (EnumDBCSBC)comboToHalf.SelectedIndex; TextUtil.enTrim = (EnumTrim)comboTrim.SelectedIndex; string separator = csv_or_tab ? "," : "\t"; MyTrees.OpenDBFile(openfileDlg.FileName, separator, true); datasetListView.RefreshDB(MyTrees.treeDB, ""); } }
//导出所有子孙节点 private static void ExportAllChildren2CSV(StreamWriter mysw, StringBuilder allLines, MyTreeNode node) { List <string> topIds = new List <string>(); List <string> subNodes = MyTrees.GetAllByTopIds("'" + node.SysId + "'"); int levelNum = 1; while (subNodes.Count > 0) { topIds.Clear(); for (int i = 0; i < subNodes.Count; i++) { mysw.WriteLine(subNodes[i]); topIds.Add("'" + subNodes[i].Substring(0, subNodes[i].IndexOf(",")) + "'"); } WindowView.notify.SetStatusMessage("正在导出该节点的第" + levelNum + "层(共" + subNodes.Count + "个)子节点,共有" + node.ChildrenLevels + "层子节点"); WindowView.notify.SetProcessBarValue((int)(100.0 * levelNum / node.ChildrenLevels)); levelNum++; subNodes = MyTrees.GetAllByTopIds(string.Join(",", topIds)); } }