Example #1
0
        /// <summary>
        /// 导出全部表结构到WORD文档
        /// </summary>
        /// <param name="filename"></param>
        public void SetTableSchemaToWord(string filename)
        {
            TabStruCollection tsc  = new TabStruCollection();
            TableSchemaInOut  tsio = new TableSchemaInOut(this.m_handler);

            tsc = tsio.getTabStruAllCollection();
            this.ConvertInfoToWord(filename, tsc);
        }
Example #2
0
        /// <summary>
        /// 导出部分表结构到WORD文档
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="tblnamelist"></param>
        public void SetTableSchemaSomeToWord(string filename, List <string> tblnamelist)
        {
            TabStruCollection tsc  = new TabStruCollection();
            TableSchemaInOut  tsio = new TableSchemaInOut(this.m_handler);

            tsc = tsio.getTabStruSomeCollection(tblnamelist);
            this.ConvertInfoToWord(filename, tsc);
        }
        /// <summary>
        /// 获取部分待序列化的表结构集合
        /// </summary>
        /// <returns></returns>
        public TabStruCollection getTabStruSomeCollection(List <string> tblnamelist)
        {
            List <Table>      tlist = this.getSomeTableStru(tblnamelist);
            TabStruCollection tsc   = new TabStruCollection();

            for (int i = 0; i < tlist.Count; i++)
            {
                Table tb = tlist[i];
                tsc.List.Add(tb);
            }
            return(tsc);
        }
        /// <summary>
        /// 获取全部待序列化的表结构集合
        /// </summary>
        /// <returns></returns>
        public TabStruCollection getTabStruAllCollection()
        {
            List <Table>      tlist = this.getAllTableStru();
            TabStruCollection tsc   = new TabStruCollection();

            for (int i = 0; i < tlist.Count; i++)
            {
                Table tb = tlist[i];
                tsc.List.Add(tb);
            }
            return(tsc);
        }
        /// <summary>
        /// 协调导入表结构
        /// </summary>
        /// <param name="filename"></param>
        public void tableSchemaInput(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("无法找到文件:" + filename);
            }
            StreamReader      fs  = new StreamReader(filename);
            TabStruCollection tsc = this.LoadDataFromXMLToTabStruCollection(fs);
            string            sql = tsc.GetFixTableStuSqlByFile(this.m_handler);

            fs.Dispose();
            ExecuteSqlFile esf = new ExecuteSqlFile(this.m_handler);

            esf.ExecuteSqlScript(sql, ExecuteSqlFile.SqlSplitChars);
        }
        /// <summary>
        /// 导出部分表结构
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="tblnamelist"></param>
        public void tableSchemaSomeOutput(string filename, List <string> tblnamelist)
        {
            if (!File.Exists(filename))
            {
                File.Create(filename);
            }
            if (filename.Trim().Length == 0)
            {
                return;
            }
            StreamWriter      fs  = new StreamWriter(filename);
            TabStruCollection tsc = this.getTabStruSomeCollection(tblnamelist);

            tsc.SaveAsXML(fs);
            fs.Dispose();
        }
 /// <summary>
 /// 从配置文件中读取表结构数据到表结构集合中(反序列化)
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public TabStruCollection LoadDataFromXMLToTabStruCollection(TextReader s)
 {
     return(TabStruCollection.LoadFromXML(s));
 }
 /// <summary>
 /// 从配置文件中读取表结构数据到表结构集合中(反序列化)
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public TabStruCollection LoadDataFromXMLToTabStruCollection(Stream s)
 {
     return(TabStruCollection.LoadFromXML(s));
 }
Example #9
0
        /// <summary>
        /// 转化表数据集合为Word文档
        /// </summary>
        /// <param name="filewordPath"></param>
        /// <param name="tsc"></param>
        public void ConvertInfoToWord(string filewordPath, TabStruCollection tsc)
        {
            if (tsc.List == null || tsc.List.Count == 0)
            {
                return;
            }
            StringBuilder rtn    = new StringBuilder();
            object        wdtype = WdNewDocumentType.wdNewBlankDocument;

            this.m_wddoc = this.m_wdapp.Documents.Add(ref nouseref, ref nouseref, ref wdtype,
                                                      ref nouseref);

            try
            {
                foreach (Draco.DB.QuickDataBase.Schema.Vendor.Implementation.Table table in tsc.List)
                {
                    Draco.DB.QuickDataBase.Schema.Vendor.Implementation.Table tbl = table;
                    Microsoft.Office.Interop.Word.Range range = this.m_wdapp.Selection.Range;
                    object tblbehavior = WdDefaultTableBehavior.wdWord9TableBehavior;
                    object fitbehavite = WdAutoFitBehavior.wdAutoFitFixed;
                    Microsoft.Office.Interop.Word.Table wdtbl = this.m_wddoc.Tables.Add(range, tbl.Columns.Count + 3, 4,
                                                                                        ref tblbehavior,
                                                                                        ref fitbehavite);

                    MergeTblCell(wdtbl, 1, 2, 4);
                    Microsoft.Office.Interop.Word.Cell cell = wdtbl.Cell(1, 1);
                    SetTblCellShading(cell);
                    SetCellValue(cell, "表名:");

                    SetCellValue(wdtbl.Cell(1, 2), tbl.TableName);
                    MergeTblCell(wdtbl, 2, 2, 4);
                    cell = wdtbl.Cell(2, 1);
                    SetTblCellShading(cell);
                    SetCellValue(cell, "表名含义:");
                    SetCellValue(wdtbl.Cell(2, 2), tbl.TableName);

                    cell = wdtbl.Cell(3, 1);
                    SetTblCellShading(cell);
                    SetCellValue(cell, "字段名称");
                    cell = wdtbl.Cell(3, 2);
                    SetTblCellShading(cell);
                    SetCellValue(cell, "字段类型(长度)");
                    cell = wdtbl.Cell(3, 3);
                    SetTblCellShading(cell);
                    SetCellValue(cell, "字段含义");
                    cell = wdtbl.Cell(3, 4);
                    SetTblCellShading(cell);
                    SetCellValue(cell, "备注");

                    for (int i = 0; i < tbl.Columns.Count; i++)
                    {
                        SetCellValue(wdtbl.Cell(i + 4, 1), tbl.Columns[i].ColumnName);
                        string typeAndLen = tbl.Columns[i].FullType.ToString();
                        if (tbl.Columns[i].Length != null && tbl.Columns[i].Length.ToString().Length > 0)
                        {
                            typeAndLen += "(" + tbl.Columns[i].Length + ")";
                        }
                        SetCellValue(wdtbl.Cell(i + 4, 2), typeAndLen);
                        SetCellValue(wdtbl.Cell(i + 4, 3), tbl.Columns[i].Comment);
                        string fieldAtt = "";
                        if (tbl.Columns[i].PrimaryKey != null && (bool)tbl.Columns[i].PrimaryKey)
                        {
                            fieldAtt += "主键;";
                        }
                        else
                        {
                            if (!tbl.Columns[i].Nullable)
                            {
                                fieldAtt += "非空;";
                            }
                            if (tbl.Columns[i].Generated != null && (bool)tbl.Columns[i].Generated)
                            {
                                fieldAtt += "索引;";
                            }
                        }

                        if (tbl.Columns[i].Generated != null && (bool)tbl.Columns[i].Generated)
                        {
                            fieldAtt += "自增;";
                        }

                        if (tbl.Columns[i].Generated != null && (bool)tbl.Columns[i].Generated)
                        {
                            fieldAtt += "唯一;";
                        }

                        if (tbl.Columns[i].DefaultValue != null && tbl.Columns[i].DefaultValue.Trim().Length > 0)
                        {
                            fieldAtt += "默认=" + tbl.Columns[i].DefaultValue + ";";
                        }

                        SetCellValue(wdtbl.Cell(i + 4, 4), fieldAtt);
                    }
                    object unit  = Microsoft.Office.Interop.Word.WdUnits.wdCharacter;
                    object count = 1;
                    wdtbl.Select();
                    this.m_wdapp.Selection.MoveRight(ref unit, ref count, ref nouseref);

                    object br = Microsoft.Office.Interop.Word.WdBreakType.wdLineBreak;
                    this.m_wdapp.Selection.InsertBreak(ref br);
                }
                SaveDoc(filewordPath);
            }
            catch (Exception ex)
            {
                //释放资源
                if (this.m_wdapp != null)
                {
                    m_wdapp.Quit(ref nouseref, ref nouseref, ref nouseref);
                }
                throw ex;
            }
        }