Example #1
0
        private void GetCheckedNode(IEnumerable <TreeModel> list)
        {
            var checkedNodes = list.Where(x => x.IsChecked);

            foreach (var node in checkedNodes)
            {
                if (node.Children.Count > 0)
                {
                    GetCheckedNode(node.Children);
                }
                else
                {
                    TreeModelChecked.Add(node);
                }
            }
        }
Example #2
0
        private void BtnConvert_OnClick(object sender, RoutedEventArgs e)
        {
            var strFontSize = TxtPdfFontSize.Text;
            int iFontSize;

            if (int.TryParse(strFontSize, out iFontSize))
            {
                PdfFontSize = iFontSize;
            }
            else
            {
                this.ShowMessageAsync("提示", "PDF字体大小必须是数字");
                return;
            }
            var strPath = TxtPdfSaveFolder.Text;

            if (string.IsNullOrEmpty(strPath))
            {
                this.ShowMessageAsync("提示", "请选择PDF文件保存位置");
                return;
            }
            PdfBaseFolder = new DirectoryInfo(strPath).Parent.FullName;
            var dialog   = new Ookii.Dialogs.Wpf.ProgressDialog();
            var tabIndex = MyTabs.SelectedIndex;

            if (tabIndex == 1)  //scrapbook
            {
                TreeModelChecked.Clear();
                GetCheckedNode(TreeModelList);
                if (!TreeModelChecked.Any())
                {
                    this.ShowMessageAsync("提示", "请选择需要转换的节点");
                    return;
                }
                HtmlBaseFolder = Path.Combine(TxtScrapbookDataPath.Text, "Data");
                dialog.DoWork += DoScrapbookConvert;
            }
            else if (tabIndex == 0)
            {
                HtmlBaseFolder = TxtHtmlFilesFolder.Text;
                if (string.IsNullOrEmpty(HtmlBaseFolder))
                {
                    this.ShowMessageAsync("提示", "请选择Html文件所在目录");
                    return;
                }
                var isSearchSub  = !(RbtnNoSub.IsChecked.HasValue && RbtnNoSub.IsChecked.Value);
                var searchOption = isSearchSub ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
                HtmlFiles = "*.html".Split('|').SelectMany(filter => Directory.GetFiles(HtmlBaseFolder, filter, searchOption)).ToArray();

                if (!HtmlFiles.Any())
                {
                    this.ShowMessageAsync("提示", "所选目录没有搜索到任何Html文件:" + HtmlBaseFolder);
                    return;
                }
                dialog.DoWork += DoHtmlConvert;
            }
            PdfFolderTemp = Path.Combine(PdfBaseFolder, Guid.NewGuid().ToString());
            if (!Directory.Exists(PdfFolderTemp))
            {
                Directory.CreateDirectory(PdfFolderTemp);
            }
            dialog.ShowCancelButton    = false;
            dialog.Text                = "正在转换,请稍后";
            dialog.RunWorkerCompleted += DoConvertCompleted;
            dialog.ShowDialog();
        }