//public void PDModel2Html(PDModel m) //{ // Export(m, ExportTyep.HTML); //} private void Export(IList <PDTable> tableList, string title, ExportTyep exportType) { Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: 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)); break; case ExportTyep.HTML: w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; default: break; } doc.Open(); doc.NewPage(); //IList<PDTable> tableList = m.AllTableList; //Chapter cpt = new Chapter(m.Name, 1); Chapter cpt = new Chapter(title, 1); Section sec; //doc.AddTitle(m.Name); doc.AddTitle(title); doc.AddAuthor("Kalman"); doc.AddCreationDate(); doc.AddCreator("Kalman"); doc.AddSubject("PDM数据库文档"); foreach (PDTable table in tableList) { 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); } doc.Add(cpt); doc.Close(); }
//public void PDModel2Html(PDModel m) //{ // Export(m, ExportTyep.HTML); //} private void Export(IList<PDTable> tableList,string title, ExportTyep exportType) { Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: 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)); break; //case ExportTyep.HTML: // w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); //break; default: break; } doc.Open(); doc.NewPage(); //IList<PDTable> tableList = m.AllTableList; //Chapter cpt = new Chapter(m.Name, 1); Chapter cpt = new Chapter(title, 1); Section sec; //doc.AddTitle(m.Name); doc.AddTitle(title); doc.AddAuthor("Kalman"); doc.AddCreationDate(); doc.AddCreator("Kalman"); doc.AddSubject("PDM数据库文档"); foreach (PDTable table in tableList) { 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); } doc.Add(cpt); doc.Close(); }
private List <SOTable> Export(DbSchema schema, SODatabase db, List <SOTable> tableList, ExportTyep exportType) { if (schema == null) { throw new ArgumentException("参数schema不能为空", "schema"); } if (db == null) { throw new ArgumentException("参数dbName不能为空", "dbName"); } Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: 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)); break; case ExportTyep.HTML: w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; default: break; } doc.Open(); doc.NewPage(); if (tableList == null) { tableList = schema.GetTableList(db); } Chapter cpt = new Chapter(db.Name, 1); Section sec; #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)); if (string.IsNullOrEmpty(table.Comment) == false) { Chunk chunk = new Chunk(table.Comment, font); sec.Add(chunk); } 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); } doc.Add(cpt); doc.Close(); #endregion return(tableList); }
private List<SOTable> Export(DbSchema schema, SODatabase db, List<SOTable> tableList, ExportTyep exportType) { if (schema == null) throw new ArgumentException("参数schema不能为空", "schema"); if (db == null) throw new ArgumentException("参数dbName不能为空", "dbName"); Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: 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)); break; //case ExportTyep.HTML: // w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); //break; default: break; } doc.Open(); doc.NewPage(); if (tableList == null) tableList = schema.GetTableList(db); Chapter cpt = new Chapter(db.Name, 1); Section sec; 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)); if (string.IsNullOrEmpty(table.Comment) == false) { Chunk chunk = new Chunk(table.Comment, font); sec.Add(chunk); } 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); } doc.Add(cpt); doc.Close(); return tableList; }