示例#1
0
        public static void Export2CSV(MyTreeNode node, string outputfile)
        {
            ringNodeIds.Clear();
            WindowView.notify.SetProcessBarVisible(true);
            WindowView.notify.SetStatusMessage("开始导出文件......");
            TimingUtil.StartTiming();

            StreamWriter mysw = new StreamWriter(outputfile, true, Encoding.Default);

            List <string> optCols = MyTrees.TableOptCols;
            string        header  = string.Join(",", optCols.ToArray());

            header = "会员ID,父级ID,会员姓名,所在层级,下级层数,直接下级会员数,下级会员总数," + header;
            mysw.WriteLine(header);

            StringBuilder allLines = new StringBuilder();

            row    = 2;
            allRow = node.ChildrenCount + 1;

            //导出所有父节点
            ExportAllParents2CSV(mysw, allLines, node);

            Export2CSVImp(mysw, allLines, node, true);

            mysw.Close();

            WindowView.notify.SetStatusMessage(TimingUtil.EndTiming());
            WindowView.notify.SetProcessBarVisible(false);
        }
示例#2
0
        //展开选中项的子项
        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());
            }
        }
示例#3
0
        //查找
        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());
            }
        }
示例#4
0
        public static void OpenDBFile(string filepath, string separator, bool checkHead)
        {
            List <string> dbs      = treeDB.GetDatasetNames();
            FileInfo      fileInfo = new FileInfo(filepath);
            string        dbName   = fileInfo.Name.Replace(fileInfo.Extension, "").ToLower();

            if (dbs.Contains(dbName))
            {
                MessageBoxResult msgResult = MessageBox.Show("该数据文件已经存在,是否重新计算并覆盖旧文件?", "提示", MessageBoxButton.OKCancel);
                if (msgResult == MessageBoxResult.OK)
                {
                    treeDB.DeleteDB(dbName);
                }
                else
                {
                    return;
                }
            }

            TimingUtil.StartTiming();

            //读取文件数据并构造树节点-------------------------------------
            bool readSuccess = ReadLine2Node(filepath, separator, checkHead);

            if (readSuccess)
            {
                //将树节点计算并构造树结构-------------------------------------
                ConstructTree();
                //写入数据库-------------------------------------------------
                Write2DB(filepath, dbName, separator);

                WindowAdmin.notify.SetStatusMessage(TimingUtil.EndTiming());
            }
            else
            {
                WindowAdmin.notify.SetProcessBarVisible(false);
            }
            allNodes.Clear();
            NoParentNodes.Clear();
            IdConflictNodes.Clear();
            TreeRootNodes.Clear();
            RingNodes.Clear();
        }
示例#5
0
//		private const string TMP_DIR = "temp";

        public static void Export2PDF(MyTreeView mytreeview, MyTreeNode node)
        {
            if (node == null)
            {
                MessageBox.Show("必须选中一个节点!");
                return;
            }
            // disable once SuggestUseVarKeywordEvident
            SaveFileDialog openfileDlg = new SaveFileDialog();

            openfileDlg.Title    = "选择将会员树导出为pdf文件的位置";
            openfileDlg.Filter   = "pdf文件|*.pdf";
            openfileDlg.FileName = node.ToString();
            if (openfileDlg.ShowDialog() == true)
            {
                TimingUtil.StartTiming();
                Directory.CreateDirectory(MemData.MemDataTemp);
                ExportAllImgs(mytreeview, node);

                //定义一个Document,并设置页面大小为A4,竖向
                //			Document doc = new Document(PageSize.A4);
                Document doc = new Document();
                PdfWriter.GetInstance(doc, new FileStream(openfileDlg.FileName, FileMode.Create));

                //设置PDF的头信息,一些属性设置,在Document.Open 之前完成
                doc.AddAuthor("TomChen");
                doc.AddCreationDate();
                doc.AddCreator("湖南警察学院");
                doc.AddSubject("将选中的会员树导出为PDF格式,如果数据量大,则导出为多张PDF页面");
                doc.AddTitle("将选中的会员树导出为PDF");
                doc.AddKeywords("会员树,会员层级,PDF");
                //自定义头
                //doc.AddHeader("Expires", "0");

                doc.Open();

                string[] imgfiles = Directory.GetFiles(MemData.MemDataTemp, "*.png");

                //首页
                //写入文字
                Paragraph paragraph = new Paragraph("ID:" + node.SysId, new Font(Font.FontFamily.TIMES_ROMAN, 30, 0, BaseColor.BLUE));
                doc.Add(paragraph);
                paragraph = new Paragraph("TopID:" + node.TopId, new Font(Font.FontFamily.TIMES_ROMAN, 30, 0, BaseColor.BLUE));
                doc.Add(paragraph);
                paragraph = new Paragraph("Level:" + node.Level, new Font(Font.FontFamily.TIMES_ROMAN, 30, 0, BaseColor.BLUE));
                doc.Add(paragraph);
                paragraph = new Paragraph("Sub1:" + node.ChildrenCount, new Font(Font.FontFamily.TIMES_ROMAN, 30, 0, BaseColor.BLUE));
                doc.Add(paragraph);
                paragraph = new Paragraph("SubLevel:" + node.ChildrenLevels, new Font(Font.FontFamily.TIMES_ROMAN, 30, 0, BaseColor.BLUE));
                doc.Add(paragraph);
                paragraph = new Paragraph("SubAll:" + node.ChildrenCount, new Font(Font.FontFamily.TIMES_ROMAN, 30, 0, BaseColor.BLUE));
                doc.Add(paragraph);
                paragraph = new Paragraph("----------------------------------------", new Font(Font.FontFamily.COURIER, 20, 0, BaseColor.GREEN));
                doc.Add(paragraph);
                paragraph = new Paragraph("Export pictures count:" + imgfiles.Length, new Font(Font.FontFamily.COURIER, 20, 0, BaseColor.GREEN));
                doc.Add(paragraph);

                WindowView.notify.SetProcessBarVisible(true);

                for (int i = 0; i < imgfiles.Length; i++)
                {
                    //写入图片
                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgfiles[i]);
                    doc.SetPageSize(new Rectangle(img.Width, img.Height));
                    //新建一页
                    doc.NewPage();
                    //img.ScaleAbsoluteWidth(PageSize.A4.Width);
                    //img.ScaleAbsoluteHeight(PageSize.A4.Height - 100);
                    //img.SetAbsolutePosition((PageSize.POSTCARD.Width - img.ScaledWidth) / 2, (PageSize.POSTCARD.Height - img.ScaledHeight) / 2);
                    doc.Add(img);
                    WindowView.notify.SetStatusMessage("正在生成PDF文件" + i + "/" + imgfiles.Length);
                    WindowView.notify.SetProcessBarValue(i * 100.0 / imgfiles.Length);
                }

                doc.Close();
                Directory.Delete(MemData.MemDataTemp, true);
                WindowView.notify.SetProcessBarVisible(false);
                WindowView.notify.SetStatusMessage(TimingUtil.EndTiming());
                MessageBox.Show("导出PDF完成!");
            }
        }