コード例 #1
0
ファイル: DbDocBuilder.cs プロジェクト: Leafney/Kalman.Studio
        //改变连接
        void ChangeConnection(string csName)
        {
            ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[csName];
            currentSchema = DbSchemaFactory.Create(css.Name);

            List<SODatabase> dbList = currentSchema.GetDatabaseList();
            cbDatabase.Items.Clear();
            foreach (SODatabase db in dbList)
            {
                if (db.IsSystemDatabase) continue;
                cbDatabase.Items.Add(db);
            }

            //if (cbDatabase.Items.Count > 0)
            //{
            //    DbName = cbDatabase.Items[0].ToString();
            //    cbDatabase.SelectedIndex = 0;
            //}
            //else
            //{
            //    DbName = string.Empty;
            //}

            foreach (object item in cbConnectionStrings.Items)
            {
                if (item.ToString() == CSName)
                {
                    cbConnectionStrings.SelectedItem = item;
                    break;
                }
            }
        }
コード例 #2
0
        private void cbConnectionStrings_SelectedIndexChanged(object sender, EventArgs e)
        {
            tvDatabase.Nodes.Clear();

            ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[cbConnectionStrings.SelectedItem.ToString()];
            dbSchema = DbSchemaFactory.Create(css.Name);
            DbSchemaHelper.Instance.CurrentSchema = dbSchema;

            TreeNode root = new TreeNode(css.Name, 0, 0);
            root.ToolTipText = css.ConnectionString;
            tvDatabase.Nodes.Add(root);

            Main m = this.ParentForm as Main;
            m.ClearDbList();

            this.Cursor = Cursors.WaitCursor;
            IList<SODatabase> dbList = dbSchema.GetDatabaseList();
            this.Cursor = Cursors.Default;

            foreach (SODatabase db in dbList)
            {
                TreeNode dbNode = new TreeNode(db.Name, 1, 1);
                dbNode.Tag = db;
                dbNode.ToolTipText = string.IsNullOrEmpty(db.Comment) ? db.Name : db.Comment;
                dbNode.ContextMenuStrip = cmsDatabase;
                root.Nodes.Add(dbNode);

                MainForm.AddDbListItem(db);
            }

            root.Expand();
        }
コード例 #3
0
        /// <summary>
        /// 创建一个数据库架构实例
        /// </summary>
        /// <param name="db">数据提供程序实例</param>
        /// <returns></returns>
        public static DbSchema Create(Database db)
        {
            DbSchema schema = null;

            switch (db.DatabaseType)
            {
            case DatabaseType.SqlServer:
                //schema = new SqlServerSchema(db);
                schema = new SqlServerSchema(db);
                break;

            case DatabaseType.Oracle:
                schema = new OracleSchema(db);
                break;

            case DatabaseType.MySql:
                schema = new MySqlSchema(db);
                break;

            case DatabaseType.DB2:
                schema = new DB2Schema(db);
                break;

            case DatabaseType.SQLite:
                schema = new SQLiteSchema(db);
                break;

            default:
                break;
            }

            return(schema);
        }
コード例 #4
0
ファイル: Export.cs プロジェクト: Leafney/Kalman.Studio
        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;
        }
コード例 #5
0
ファイル: Export.cs プロジェクト: Leafney/Kalman.Studio
 public void DbSchema2Rtf(DbSchema schema, SODatabase db, List<SOTable> tableList)
 {
     tableList = Export(schema, db, tableList, ExportTyep.RTF);
 }