public void BuildChmAndExport(object obj) { #region 编译CHM文件 Dispatcher.Invoke(new Action(() => { lblMessage.Content = "正在编译CHM文件..."; })); if (obj == null) { Dispatcher.Invoke(new Action(() => { lblMessage.Content = "编译CHM文件失败..."; })); Dispatcher.Invoke(new Action <bool>(this.EnableControl), true); return; } try { ChmHelp chmhlp = (obj as ChmHelp); chmhlp.Compile(); Dispatcher.Invoke(new Action(() => { lblMessage.Content = "导出完毕 文件存储在:" + chmhlp.ChmFileName; })); Directory.Delete("./tmp", true); } catch (Exception ex) { Dispatcher.Invoke(new Action(() => { lblMessage.Content = "导出发生异常"; })); MessageBox.Show(ex.Message); } finally { Dispatcher.Invoke(new Action <bool>(this.EnableControl), true); } #endregion }
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); } }
private void CHMCompile() { if (string.IsNullOrWhiteSpace(chm_html_path)) { string useDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); chm_html_path = Path.Combine(useDir, txtCHM_Name.Text); if (!Directory.Exists(chm_html_path)) { Builder(); } } txtCHM_Name.Enabled = false; btnMakeCHM.Enabled = false; btnMakeCHM.Text = "导出中..."; try { //编译CHM文档 ChmHelp c3 = new ChmHelp(); c3.DefaultPage = defaultHtml; c3.Title = txtCHM_Name.Text; c3.ChmFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), c3.Title + ".chm"); c3.SourcePath = chm_html_path; string result = c3.Compile(true); if (string.IsNullOrWhiteSpace(result)) { MessageBox.Show("导出CHM成功!"); this.Close(); Process.Start(c3.ChmFileName); } else { MessageBox.Show(result); this.Close(); Process.Start(indexHtmlpath); } } catch (Exception ex) { MessageBox.Show("导出CHM失败!" + ex.Message); } txtCHM_Name.Enabled = true; btnMakeCHM.Enabled = true; btnMakeCHM.Text = "导出"; }
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(); } }
public void Export() { Directory.CreateDirectory(".//tmp"); //定义目录DataTable 结构 var dtMenus = new DataTable("<b>数据库表目录</b>"); dtMenus.Columns.Add("序号", typeof(int)); dtMenus.Columns.Add("表名", typeof(string)); dtMenus.Columns.Add("表说明", typeof(string)); //将选中项的总数 设置为进度条最大值 +1项是表目录文件 tpbExport.Value = 0; tpbExport.Maximum = ckbData.CheckedItems.Count + ckbTables.CheckedItems.Count + 1; //获取需要导出的表结构 选中项 List <string> lst = new List <string>(); foreach (var item in ckbTables.CheckedItems) { lst.Add(item.ToString()); } #region 导出表结构 if (lst.Count > 0) { lblMessage.Text = "准备表结构文件..."; //得到选中的表结构的字段信息 var lstDt = dal.GetTableStruct(lst); var pathTables = "./tmp/表结构"; Directory.CreateDirectory(pathTables); var tableIndex = 1; foreach (var dt in lstDt) { //得到表描述 var drs = dal.GetTables().Select("表名='" + dt.TableName + "'"); var desp = string.Empty; if (drs.Length > 0) { desp = drs[0]["表说明"].ToString(); } //创建表字段信息的html DbCommon.CreateHtml(dt, true, Path.Combine(pathTables, dt.TableName + " " + desp + ".html"), true, desp); //构建表目录 DataRow dr = dtMenus.NewRow(); dr["序号"] = tableIndex++; dr["表说明"] = desp; dr["表名"] = "<a href=\"表结构\\{0} {1}.html\">{0}</a>".FormatString(dt.TableName, desp); dtMenus.Rows.Add(dr); //改变进度 tpbExport.Value++; } //导出表目录 DbCommon.CreateHtml(dtMenus, false, "./tmp/" + defaultHtml, false); tpbExport.Value++; } #endregion #region 导出表数据 //传递需要导出数据的table选中项 得到数据内容 lst.Clear(); foreach (var item in ckbData.CheckedItems) { lst.Add(item.ToString()); } if (lst.Count > 0) { lblMessage.Text = "正在生成表数据数据..."; var lstDt = dal.GetTableData(lst); //创建常用数据的html var pathTables = "./tmp/常用数据"; Directory.CreateDirectory(pathTables); foreach (var dt in lstDt) { DbCommon.CreateHtml2(dt, true, Path.Combine(pathTables, dt.TableName + ".html")); tpbExport.Value++; } } #endregion try { lblMessage.Text = "正在编译CHM文件..."; //编译CHM文档 ChmHelp c3 = new ChmHelp(); c3.DefaultPage = defaultHtml; c3.Title = txtTitle.Text; c3.ChmFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), c3.Title + ".chm"); c3.RootPath = @"./tmp"; c3.Compile(); lblMessage.Text = "导出完毕 文件存储在:" + c3.ChmFileName; Directory.Delete("./tmp", true); } catch (Exception ex) { lblMessage.Text = "导出发生异常"; MessageBox.Show(ex.Message); } finally { this.EnableControl(true); } }
/// <summary> /// 导出 /// </summary> /// <param name="o"></param> public void Export(object o) { Directory.CreateDirectory(".//tmp"); //将日志文件复制到tmp文件夹下 if (txtLogPath.Text.Length > 0 && File.Exists(txtLogPath.Text)) { File.Copy(txtLogPath.Text, ".//tmp/更新日志.txt", true); } //定义目录DataTable 结构 var dtMenus = new DataTable("<b>数据库表目录</b>"); dtMenus.Columns.Add("序号", typeof(int)); dtMenus.Columns.Add("表名", typeof(string)); dtMenus.Columns.Add("表说明", typeof(string)); //将选中项的总数 设置为进度条最大值 +1项是表目录文件 tpbExport.Value = 0; tpbExport.Maximum = ckbData.CheckedItems.Count + ckbTables.CheckedItems.Count + 1; //获取需要导出的表结构 选中项 List <string> lst = new List <string>(); foreach (var item in ckbTables.CheckedItems) { lst.Add(item.ToString()); } #region 导出表结构 if (lst.Count > 0) { lblMessage.Text = "准备表结构文件..."; //得到选中的表结构的字段信息 var lstDt = dal.GetTableStruct(lst); var pathTables = "./tmp/表结构"; Directory.CreateDirectory(pathTables); var tableIndex = 1; foreach (var dt in lstDt) { //得到表描述 var drs = dal.GetTables().Select("表名='" + dt.TableName + "'"); var desp = string.Empty; if (drs.Length > 0) { desp = drs[0]["表说明"].ToString().RemoveValidFileChar(); } //创建表字段信息的html //得到文件存储路径 var tabPath = Path.Combine(pathTables, dt.TableName + ".html"); //指定table标题 将表的名称设置为超链接并返回 var title = "<a href='../" + defaultHtml + "'>" + dt.TableName + "</a>"; if (desp.Trim().Length > 0) { title += "(" + drs[0]["表说明"].ToString() + ")"; } DbCommon.CreateHtml(dt, true, tabPath, title); //构建表目录 DataRow dr = dtMenus.NewRow(); dr["序号"] = tableIndex++; dr["表说明"] = desp; dr["表名"] = "<a href=\"表结构\\{0}.html\">{0}</a>".FormatString(dt.TableName); dtMenus.Rows.Add(dr); //改变进度 tpbExport.Value++; } //导出表目录 DbCommon.CreateHtml(dtMenus, false, "./tmp/" + defaultHtml, "<b>数据库表目录</b>"); tpbExport.Value++; } #endregion #region 导出表数据 //传递需要导出数据的table选中项 得到数据内容 lst.Clear(); foreach (var item in ckbData.CheckedItems) { lst.Add(item.ToString()); } if (lst.Count > 0) { lblMessage.Text = "正在生成表数据数据..."; var lstDt = dal.GetTableData(lst); //创建常用数据的html var pathTables = "./tmp/常用数据"; Directory.CreateDirectory(pathTables); foreach (var dt in lstDt) { var tabPath = Path.Combine(pathTables, dt.TableName + ".html"); //指定table标题 将表的名称设置为超链接并返回 var title = "<a href='../" + defaultHtml + "'>" + dt.TableName + "</a>"; //得到表描述 var drs = dal.GetTables().Select("表名='" + dt.TableName + "'"); var desp = string.Empty; if (drs.Length > 0) { desp = drs[0]["表说明"].ToString(); } if (desp.Trim().Length > 0) { title += "(" + drs[0]["表说明"].ToString() + ")"; } DbCommon.CreateHtml(dt, true, tabPath, title); tpbExport.Value++; } } #endregion try { lblMessage.Text = "正在编译CHM文件..."; //编译CHM文档 ChmHelp c3 = new ChmHelp { DefaultPage = defaultHtml, Title = txtTitle.Text }; c3.ChmFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), c3.Title + ".chm"); c3.RootPath = @"./tmp"; c3.Compile(); lblMessage.Text = DateTime.Now.ToString() + " 导出成功"; Process.Start(c3.ChmFileName); Directory.Delete("./tmp", true); } catch (Exception ex) { lblMessage.Text = "导出发生异常"; MessageBox.Show(ex.Message); } finally { this.CloseLoading(); } }
public void ExportCHM() { Directory.CreateDirectory(".//tmp"); //定义目录DataTable 结构 var dtMenus = new DataTable("<b>数据库表目录</b>"); dtMenus.Columns.Add("序号", typeof(int)); dtMenus.Columns.Add("表名", typeof(string)); dtMenus.Columns.Add("表说明", typeof(string)); //将选中项的总数 设置为进度条最大值 +1项是表目录文件 tpbExport.Value = 0; tpbExport.Maximum = ckbData.CheckedItems.Count + ckbTables.CheckedItems.Count + 1; //获取需要导出的表结构 选中项 List<string> lst = new List<string>(); foreach (var item in ckbTables.CheckedItems) { lst.Add(item.ToString()); } #region 导出表结构 if (lst.Count > 0) { lblMessage.Text = "准备表结构文件..."; //得到选中的表结构的字段信息 var lstDt = dal.GetTableStruct(lst); var pathTables = "./tmp/表结构"; Directory.CreateDirectory(pathTables); var tableIndex = 1; foreach (var dt in lstDt) { //得到表描述 var drs = dal.GetTables().Select("表名='" + dt.TableName + "'"); var desp = string.Empty; if (drs.Length > 0) desp = drs[0]["表说明"].ToString(); //创建表字段信息的html DbCommon.CreateHtml(dt, true, Path.Combine(pathTables, dt.TableName + " " + desp + ".html"), true, desp); //构建表目录 DataRow dr = dtMenus.NewRow(); dr["序号"] = tableIndex++; dr["表说明"] = desp; dr["表名"] = "<a href=\"表结构\\{0} {1}.html\">{0}</a>".FormatString(dt.TableName, desp); dtMenus.Rows.Add(dr); //改变进度 tpbExport.Value++; } //导出表目录 DbCommon.CreateHtml(dtMenus, false, "./tmp/" + defaultHtml, false); tpbExport.Value++; } #endregion #region 导出表数据 //传递需要导出数据的table选中项 得到数据内容 //lst.Clear(); //foreach (var item in ckbData.CheckedItems) //{ // lst.Add(item.ToString()); //} //if (lst.Count > 0) //{ // lblMessage.Text = "正在生成表数据数据..."; // var lstDt = dal.GetTableData(lst); // //创建常用数据的html // var pathTables = "./tmp/常用数据"; // Directory.CreateDirectory(pathTables); // foreach (var dt in lstDt) // { // DbCommon.CreateHtml2(dt, true, Path.Combine(pathTables, dt.TableName + ".html")); // tpbExport.Value++; // } //} #endregion try { lblMessage.Text = "正在编译CHM文件..."; //编译CHM文档 ChmHelp c3 = new ChmHelp(); c3.DefaultPage = defaultHtml; c3.Title = txtTitle.Text; c3.ChmFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), c3.Title + ".chm"); c3.RootPath = @"./tmp"; c3.Compile(); lblMessage.Text = "导出完毕 文件存储在:" + c3.ChmFileName; Directory.Delete("./tmp", true); } catch (Exception ex) { lblMessage.Text = "导出发生异常"; MessageBox.Show(ex.Message); } finally { this.EnableControl(true); } }