Skip to content

Commit

Permalink
修正数据文档无法修正的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
loamen committed Nov 1, 2018
1 parent 5ab0d16 commit a781c2b
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 134 deletions.
5 changes: 5 additions & 0 deletions Update.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 更新日志
2018-11-01

+ 添加终端窗口;
+ 修正无法生成数据库文档的问题;
* 优化其他一些细节;

2018-08-31

Expand Down
4 changes: 2 additions & 2 deletions src/Kalman.Studio/Kalman.Studio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
<Reference Include="ICSharpCode.TextEditor, Version=3.2.1.6466, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a, processorArchitecture=MSIL">
<HintPath>..\packages\ICSharpCode.TextEditor.3.2.1.6466\lib\Net20\ICSharpCode.TextEditor.dll</HintPath>
</Reference>
<Reference Include="itextsharp, Version=5.5.13.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\iTextSharp.5.5.13\lib\itextsharp.dll</HintPath>
<Reference Include="itextsharp, Version=4.1.6.16, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\RedGate.iTextSharp.4.1.6.16\lib\net40\itextsharp.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=4.1.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>..\packages\LiteDB.4.1.4\lib\net40\LiteDB.dll</HintPath>
Expand Down
265 changes: 137 additions & 128 deletions src/Kalman.Studio/Library/Export.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
using Aspose.Cells;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Kalman.Data;
using System.IO;
using Kalman.Command;
using ICSharpCode.TextEditor.Util;
using iTextSharp.text.rtf;
using iTextSharp.text.html;
using Kalman.Data.SchemaObject;
using Kalman.Data;
using Kalman.PdmParser;
using System;
using System.Collections.Generic;
using System.IO;

/// <summary>
/// 由于删除了版权DLL,导致该功能无法使用。可在QQ群:122161138中下载source_lib.zip
/// </summary>
namespace Kalman.Studio
{
public class iTextExporter
{
enum ExportTyep
{
PDF = 0,
RTF = 1
//HTML = 2
RTF = 1,
HTML = 2
}

string fileName = string.Empty;
//Table t = null;
Table t = null;
BaseFont baseFont = BaseFont.CreateFont("c:\\windows\\fonts\\STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font;
Font font;

public iTextExporter(string path)
{
Expand All @@ -38,25 +40,25 @@ public iTextExporter(string path)

//BaseFont baseFont = BaseFont.CreateFont("C:\\WINDOWS\\FONTS\\SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//BaseFont baseFont = BaseFont.CreateFont("c:\\windows\\fonts\\STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
font = new iTextSharp.text.Font(baseFont,12);
font = new Font(baseFont, 12);
}

public void PDModel2Pdf(IList<PDTable> tableList, string title)
{
Export(tableList,title, ExportTyep.PDF);
Export(tableList, title, ExportTyep.PDF);
}

public void PDModel2Rtf(IList<PDTable> tableList, string title)
{
Export(tableList,title, ExportTyep.RTF);
Export(tableList, title, ExportTyep.RTF);
}

//public void PDModel2Html(PDModel m)
//{
// Export(m, ExportTyep.HTML);
//}

private void Export(IList<PDTable> tableList,string title, ExportTyep exportType)
private void Export(IList<PDTable> tableList, string title, ExportTyep exportType)
{
Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20);
DocWriter w;
Expand All @@ -67,11 +69,11 @@ private void Export(IList<PDTable> tableList,string title, ExportTyep exportType
w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
break;
case ExportTyep.RTF:
//w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
break;
case ExportTyep.HTML:
w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
break;
//case ExportTyep.HTML:
// w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
//break;
default:
break;
}
Expand All @@ -94,85 +96,84 @@ private void Export(IList<PDTable> tableList,string title, ExportTyep exportType

foreach (PDTable table in tableList)
{
//sec = cpt.AddSection(new Paragraph(string.Format("{0}[{1}]", table.Name, table.Code), font));
sec = cpt.AddSection(new Paragraph(string.Format("{0}[{1}]", table.Name, table.Code)));
sec = cpt.AddSection(new Paragraph(string.Format("{0}[{1}]", table.Name, table.Code), font));

if (string.IsNullOrEmpty(table.Comment) == false)
{
Chunk chunk = new Chunk(table.Comment, font);
sec.Add(chunk);
}

//t = new Table(9, table.ColumnList.Count);

////t.Border = 15;
////t.BorderColor = Color.BLACK;
////t.BorderWidth = 1.0f;
//t.AutoFillEmptyCells = true;
//t.CellsFitPage = true;
//t.TableFitsPage = true;
//t.Cellpadding = 3;
////if (exportType == ExportTyep.PDF) t.Cellspacing = 2;
//t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE;

//t.SetWidths(new int[] { 200, 200, 150, 50, 50, 50, 50, 50, 300 });

//t.AddCell(BuildHeaderCell("名称"));
//t.AddCell(BuildHeaderCell("代码"));
//t.AddCell(BuildHeaderCell("数据类型"));
//t.AddCell(BuildHeaderCell("长度"));
//t.AddCell(BuildHeaderCell("精度"));
//t.AddCell(BuildHeaderCell("主键"));
//t.AddCell(BuildHeaderCell("外键"));
//t.AddCell(BuildHeaderCell("可空"));
//t.AddCell(BuildHeaderCell("注释"));

//foreach (PDColumn column in table.ColumnList)
//{
// t.AddCell(BuildCell(column.Name));
// t.AddCell(BuildCell(column.Code));
// t.AddCell(BuildCell(column.DataType));
// t.AddCell(BuildCell(column.Length == 0 ? "" : column.Length.ToString()));
// t.AddCell(BuildCell(column.Precision == 0 ? "" : column.Precision.ToString()));
// t.AddCell(BuildCell(column.IsPK ? " √" : ""));
// t.AddCell(BuildCell(column.IsFK ? " √" : ""));
// t.AddCell(BuildCell(column.Mandatory ? "" : " √"));
// t.AddCell(BuildCell(column.Comment));
//}

//sec.Add(t);
t = new Table(9, table.ColumnList.Count);

//t.Border = 15;
//t.BorderColor = Color.BLACK;
//t.BorderWidth = 1.0f;
t.AutoFillEmptyCells = true;
t.CellsFitPage = true;
t.TableFitsPage = true;
t.Cellpadding = 3;
//if (exportType == ExportTyep.PDF) t.Cellspacing = 2;
t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE;

t.SetWidths(new int[] { 200, 200, 150, 50, 50, 50, 50, 50, 300 });

t.AddCell(BuildHeaderCell("名称"));
t.AddCell(BuildHeaderCell("代码"));
t.AddCell(BuildHeaderCell("数据类型"));
t.AddCell(BuildHeaderCell("长度"));
t.AddCell(BuildHeaderCell("精度"));
t.AddCell(BuildHeaderCell("主键"));
t.AddCell(BuildHeaderCell("外键"));
t.AddCell(BuildHeaderCell("可空"));
t.AddCell(BuildHeaderCell("注释"));

foreach (PDColumn column in table.ColumnList)
{
t.AddCell(BuildCell(column.Name));
t.AddCell(BuildCell(column.Code));
t.AddCell(BuildCell(column.DataType));
t.AddCell(BuildCell(column.Length == 0 ? "" : column.Length.ToString()));
t.AddCell(BuildCell(column.Precision == 0 ? "" : column.Precision.ToString()));
t.AddCell(BuildCell(column.IsPK ? " √" : ""));
t.AddCell(BuildCell(column.IsFK ? " √" : ""));
t.AddCell(BuildCell(column.Mandatory ? "" : " √"));
t.AddCell(BuildCell(column.Comment));
}

sec.Add(t);
}

doc.Add(cpt);
doc.Close();
}

//private Cell BuildHeaderCell(string title)
//{
// Phrase phrase = new Phrase(title, font);
// Cell cell = new Cell(phrase);
// cell.Header = true;
// cell.BackgroundColor = Color.LIGHT_GRAY;
// cell.VerticalAlignment = Element.ALIGN_MIDDLE;
// cell.HorizontalAlignment = Element.ALIGN_LEFT;
// //cell.Border = 15;
// //cell.BorderWidth = 0.2f;
// //cell.BorderColor = Color.BLACK;
// return cell;
//}
private Cell BuildHeaderCell(string title)
{
Phrase phrase = new Phrase(title, font);
Cell cell = new Cell(phrase);
cell.Header = true;
cell.BackgroundColor = Color.LIGHT_GRAY;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
//cell.Border = 15;
//cell.BorderWidth = 0.2f;
//cell.BorderColor = Color.BLACK;
return cell;
}

//Cell BuildCell(string text)
//{
// Phrase phrase = new Phrase(text, font);
// Cell cell = new Cell(phrase);
// cell.VerticalAlignment = Element.ALIGN_MIDDLE;
// cell.HorizontalAlignment = Element.ALIGN_LEFT;
// //cell.Border = 15;
// //cell.BorderWidth = 0.2f;
// //cell.BorderColor = Color.BLACK;

// return cell;
//}
Cell BuildCell(string text)
{
Phrase phrase = new Phrase(text, font);
Cell cell = new Cell(phrase);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
//cell.Border = 15;
//cell.BorderWidth = 0.2f;
//cell.BorderColor = Color.BLACK;

return cell;
}

/// <summary>
///
Expand All @@ -185,6 +186,11 @@ public void DbSchema2Pdf(DbSchema schema, SODatabase db, List<SOTable> tableList
tableList = Export(schema, db, tableList, ExportTyep.PDF);
}

public void DbSchema2Html(DbSchema schema, SODatabase db, List<SOTable> tableList)
{
tableList = Export(schema, db, tableList, ExportTyep.HTML);
}

public void DbSchema2Rtf(DbSchema schema, SODatabase db, List<SOTable> tableList)
{
tableList = Export(schema, db, tableList, ExportTyep.RTF);
Expand All @@ -204,11 +210,11 @@ private List<SOTable> Export(DbSchema schema, SODatabase db, List<SOTable> table
w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
break;
case ExportTyep.RTF:
//w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
break;
case ExportTyep.HTML:
w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
break;
//case ExportTyep.HTML:
// w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
//break;
default:
break;
}
Expand All @@ -220,17 +226,19 @@ private List<SOTable> Export(DbSchema schema, SODatabase db, List<SOTable> table

Chapter cpt = new Chapter(db.Name, 1);
Section sec;

doc.AddTitle(db.Name);
doc.AddAuthor("Kalman");
doc.AddCreationDate();
doc.AddCreator("Kalman");
doc.AddSubject("数据库文档");
#region
if (exportType != ExportTyep.HTML)
{
doc.AddTitle(db.Name);
doc.AddAuthor("Kalman");
doc.AddCreationDate();
doc.AddCreator("Kalman");
doc.AddSubject("数据库文档");
}

foreach (SOTable table in tableList)
{
//sec = cpt.AddSection(new Paragraph(table.Name, font));
sec = cpt.AddSection(new Paragraph(table.Name));
sec = cpt.AddSection(new Paragraph(table.Name, font));

if (string.IsNullOrEmpty(table.Comment) == false)
{
Expand All @@ -240,41 +248,42 @@ private List<SOTable> Export(DbSchema schema, SODatabase db, List<SOTable> table

List<SOColumn> columnList = schema.GetTableColumnList(table);

//t = new Table(7, columnList.Count);

//t.AutoFillEmptyCells = true;
//t.CellsFitPage = true;
//t.TableFitsPage = true;
//t.Cellpadding = 3;
////if (exportType == ExportTyep.PDF) t.Cellspacing = 2;
//t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE;

//t.SetWidths(new int[] { 200, 150, 50, 50, 50, 100, 300 });

//t.AddCell(BuildHeaderCell("名称"));
//t.AddCell(BuildHeaderCell("数据类型"));
//t.AddCell(BuildHeaderCell("主键"));
//t.AddCell(BuildHeaderCell("标志"));
//t.AddCell(BuildHeaderCell("可空"));
//t.AddCell(BuildHeaderCell("默认值"));
//t.AddCell(BuildHeaderCell("注释"));

//foreach (SOColumn column in columnList)
//{
// t.AddCell(BuildCell(column.Name));
// t.AddCell(BuildCell(GetDbColumnType(column)));
// t.AddCell(BuildCell(column.PrimaryKey ? " √" : ""));
// t.AddCell(BuildCell(column.Identify ? " √" : ""));
// t.AddCell(BuildCell(column.Nullable ? " √" : ""));
// t.AddCell(BuildCell(column.DefaultValue == null ? "" : column.DefaultValue.ToString()));
// t.AddCell(BuildCell(column.Comment));
//}

//sec.Add(t);
t = new Table(7, columnList.Count);

t.AutoFillEmptyCells = true;
t.CellsFitPage = true;
t.TableFitsPage = true;
t.Cellpadding = 3;
//if (exportType == ExportTyep.PDF) t.Cellspacing = 2;
t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE;

t.SetWidths(new int[] { 200, 150, 50, 50, 50, 100, 300 });

t.AddCell(BuildHeaderCell("名称"));
t.AddCell(BuildHeaderCell("数据类型"));
t.AddCell(BuildHeaderCell("主键"));
t.AddCell(BuildHeaderCell("标志"));
t.AddCell(BuildHeaderCell("可空"));
t.AddCell(BuildHeaderCell("默认值"));
t.AddCell(BuildHeaderCell("注释"));

foreach (SOColumn column in columnList)
{
t.AddCell(BuildCell(column.Name));
t.AddCell(BuildCell(GetDbColumnType(column)));
t.AddCell(BuildCell(column.PrimaryKey ? " √" : ""));
t.AddCell(BuildCell(column.Identify ? " √" : ""));
t.AddCell(BuildCell(column.Nullable ? " √" : ""));
t.AddCell(BuildCell(column.DefaultValue == null ? "" : column.DefaultValue.ToString()));
t.AddCell(BuildCell(column.Comment));
}

sec.Add(t);
}

doc.Add(cpt);
doc.Close();
#endregion
return tableList;
}

Expand Down
Loading

0 comments on commit a781c2b

Please sign in to comment.