/// <summary> ///生成数据库文档 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_build_dbdoc_Click(object sender, EventArgs e) { //校验一波 if (string.IsNullOrEmpty(txt_dbdoc_path.Text)) { MessageBox.Show("数据库文档导出路径不能为空"); return; } var allTables = AppContext.CurrentDatabase.TableInfos; var db = AppContext.CurrentDatabase; List <WordTableOption> options = new List <WordTableOption>(); allTables.ForEach((table, i) => { string title = string.IsNullOrEmpty(table.TableComment) ? $"表名:{table.TableName}": $"表名:{table.TableName}({ table.TableComment})"; WordTableOption option = new WordTableOption() { Title = title }; option.Headers.AddRange(new[] { "序号", "名称", "类型", "默认值", "主键", "允许空", "描述" }); var columns = Utils.GetColumns(AppContext.DatabaseInfo, db.DatabaseName, table.TableName); columns.ForEach((row, j) => { option.Rows.Add(new List <string>() { j.ToString(), row.ColumnName, row.ColumnType, row.DefaultValue, row.IsPrimary?"是":"", row.IsNullAble?"是":"否", row.ColumnComment }); }); options.Add(option); }); string mainTitle = $"数据库名:{db.DatabaseName}"; bool result = WordHelper.CreateTable(options, mainTitle, txt_dbdoc_path.Text); if (result) { MessageBox.Show("数据库文档生成成功"); return; } MessageBox.Show("数据库文档生成失败!"); }