Exemplo n.º 1
0
        /// <summary>
        /// 生成表结构 html文件
        /// </summary>
        private void Builder()
        {
            //使用目录
            string useDir = string.Empty;

            //if (CkRetainHtml.Checked)//保留html文件
            //{
            useDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            //}
            //else
            //{
            //    useDir = Path.GetTempPath();
            //}


            chm_html_path = Path.Combine(useDir, txtCHM_Name.Text);
            string tempPath = chm_html_path;

            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            else
            {
                Directory.Delete(tempPath, true);
                Directory.CreateDirectory(tempPath);
            }

            indexHtmlpath = Path.Combine(tempPath, defaultHtml);

            DB     db     = new DB(connectionModel.DbType, connectionModel.ConnectionString);
            DBInfo dbInfo = db.Info;

            Dictionary <string, string> dict_tabComment = dbInfo.GetAllTableComment();

            ChmHtmlHelper.CreateDirHtml("数据库表目录", dict_tabComment, indexHtmlpath);


            //创建表结构的html
            tempPath = Path.Combine(tempPath, "表结构");
            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            else
            {
                Directory.Delete(tempPath, true);
                Directory.CreateDirectory(tempPath);
            }

            List <TableInfo> lstTableInfo = dbInfo.GetAllTableInfos();

            ChmHtmlHelper.CreateHtml(lstTableInfo, tempPath);
        }
Exemplo n.º 2
0
        private void CrateCHM(object phs)
        {
            try
            {
                if (phs == null)
                {
                    return;
                }

                List <string> pdmPaths = phs as List <string>;

                var    lstTabs     = GetTables(pdmPaths);
                string defaultpage = filename + ".html";
                string fullPath    = System.IO.Path.GetFullPath("tmp");

                if (!Directory.Exists(fullPath))
                {
                    Directory.CreateDirectory(fullPath);
                }
                else
                {
                    Directory.Delete(fullPath, true);
                    Directory.CreateDirectory(fullPath);
                }
                ChmHtmlHelper.CreateDirHtml(filename, lstTabs, System.IO.Path.Combine(fullPath, defaultpage));
                fullPath = System.IO.Path.GetFullPath("tmp\\表结构");
                if (!Directory.Exists(fullPath))
                {
                    Directory.CreateDirectory(fullPath);
                }
                BLL.CHMUtil.ChmHtmlHelper.CreateHtml(lstTabs, fullPath, defaultpage);
                ChmHelp chmHelp = new ChmHelp();
                chmHelp.DefaultPage = defaultpage;


                chmHelp.Title = filename;

                chmHelp.ChmFileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), chmHelp.Title + ".chm");
                chmHelp.SourcePath  = "tmp";
                chmHelp.Compile();
                this.txtDbToChmFile.Dispatcher.Invoke(() =>
                {
                    this.txtDbToChmFile.Text = chmHelp.ChmFileName;
                });

                MessageBox.Show("生成成功!文件路径:" + chmHelp.ChmFileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void ExportToChm()
        {
            #region 使用 HTML Help Workshop 的 hhc.exe 编译 ,先判断系统中是否已经安装有  HTML Help Workshop

            string hhcPath = string.Empty;

            if (!ConfigUtils.CheckInstall("HTML Help Workshop", "hhc.exe", out hhcPath))
            {
                string htmlhelpPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "htmlhelp.exe");
                if (File.Exists(htmlhelpPath))
                {
                    if (MessageBox.Show("导出CHM文档需安装 HTML Help Workshop ,是否现在安装?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                    {
                        var proc = Process.Start(htmlhelpPath);
                    }
                }
                return;
            }

            #endregion

            SaveFileDialog saveDia = new SaveFileDialog();
            saveDia.Filter             = "(*.chm)|*.chm";
            saveDia.Title              = "另存文件为";
            saveDia.CheckPathExists    = true;
            saveDia.AddExtension       = true;
            saveDia.AutoUpgradeEnabled = true;
            saveDia.DefaultExt         = ".chm";
            saveDia.InitialDirectory   = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            saveDia.OverwritePrompt    = true;
            saveDia.ValidateNames      = true;
            saveDia.FileName           = DBUtils.Instance.Info.DBName + "表结构信息.chm";
            if (saveDia.ShowDialog(this) == DialogResult.OK)
            {
                chm_path = saveDia.FileName;

                System.Diagnostics.Process process;
                if (IsExistProcess(Path.GetFileName(saveDia.FileName), out process))
                {
                    var dia = MessageBox.Show("文件已打开,导出前需关闭,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    if (dia == DialogResult.OK)
                    {
                        process.Kill();
                    }
                }

                try
                {
                    //创建临时文件夹,存在则删除,防止已经存在的文件 会导致生成出来的chm 有问题
                    dirPath = Path.Combine(ConfigUtils.AppPath, DBUtils.Instance.DBType + "_" + DBUtils.Instance.Info.DBName);
                    if (ZetaLongPaths.ZlpIOHelper.DirectoryExists(dirPath))
                    {
                        ZetaLongPaths.ZlpIOHelper.DeleteDirectory(dirPath, true);
                    }
                    ZetaLongPaths.ZlpIOHelper.CreateDirectory(dirPath);
                    ConfigUtils.AddSecurityControll2Folder(dirPath);
                }
                catch (Exception ex)
                {
                    LogUtils.LogError("文件目录创建出错", Developer.SysDefault, ex, dirPath);
                    return;
                }

                //设置要 进度条 对应的执行方法,以及进度条最大值
                FormUtils.ProgArg = new ProgressArg(() =>
                {
                    try
                    {
                        System.Collections.Generic.List <TableDto> tableDtos = DBInstanceTransToDto();

                        //生成数据库目录文件
                        indexHtmlpath = Path.Combine(dirPath, defaultHtml);
                        //ChmHtmlHelper.CreateDirHtml("数据库表目录", DBUtils.Instance.Info.TableComments, indexHtmlpath);
                        ChmHtmlHelper.CreateDirHtml("数据库表目录", tableDtos, indexHtmlpath);

                        string structPath = Path.Combine(dirPath, "表结构");
                        if (!ZetaLongPaths.ZlpIOHelper.DirectoryExists(structPath))
                        {
                            ZetaLongPaths.ZlpIOHelper.CreateDirectory(structPath);
                        }

                        bgWork.ReportProgress(2);

                        //生成每张表列结构的html
                        //ChmHtmlHelper.CreateHtml(DBUtils.Instance.Info.TableInfoDict, structPath);
                        ChmHtmlHelper.CreateHtml(tableDtos, structPath);

                        bgWork.ReportProgress(3);

                        ChmHelp c3     = new ChmHelp();
                        c3.HHCPath     = hhcPath;
                        c3.DefaultPage = defaultHtml;
                        c3.Title       = Path.GetFileName(chm_path);
                        c3.ChmFileName = chm_path;
                        c3.SourcePath  = dirPath;
                        c3.Compile();

                        bgWork.ReportProgress(4);

                        if (MessageBox.Show("生成CHM文档成功,是否打开?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                        {
                            System.Diagnostics.Process.Start(saveDia.FileName);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogUtils.LogError("DBCHM执行出错", Developer.MJ, ex);
                        bgWork.ReportProgress(4, ex);
                    }
                }, 4);

                bgWork.RunWorkerAsync();
            }
        }