Beispiel #1
0
        private void ExportHtml()
        {
            string tableDataDirName      = "表数据示例";
            string tableStructureDirName = "表结构说明";

            Directory.CreateDirectory(".//tmp");

            Directory.CreateDirectory(".//tmp//resources");


            //定义目录DataTable 结构
            Synyi.DBChmCreater.Entity.DataTableCollection dataTableStructures = new Synyi.DBChmCreater.Entity.DataTableCollection("<b>数据库表目录</b>");

            //将选中项的总数 设置为进度条最大值 +1项是表目录文件
            Dispatcher.Invoke(new Action(() =>
            {
                tpbExport.Value   = 0;
                tpbExport.Maximum = ckbData.SelectedItems.Count + ckbTables.SelectedItems.Count + 1;// ckbData.CheckedItems.Count + ckbTables.CheckedItems.Count + 1;
            }));

            //获取需要导出的表结构 选中项
            List <string> selectTabStructList = new List <string>();

            foreach (var item in ckbTables.SelectedItems) // CheckedItems)
            {
                selectTabStructList.Add(item.ToString());
            }

            #region 导出表结构 数据字典部分 导出为html
            if (selectTabStructList.Count > 0)
            {
                lblMessage.Content = "准备表结构文件...";
                //得到选中的表结构的字段信息
                var lstDt      = dal.GetTableStruct(selectTabStructList);
                var pathTables = $"./tmp/{tableStructureDirName}";
                Directory.CreateDirectory(pathTables);
                var tables     = dal.GetTables();
                var allSchemas = tables.Select(p => p.Domain).Distinct();
                foreach (var item in allSchemas)
                {
                    Directory.CreateDirectory(System.IO.Path.Combine(pathTables, item));
                }
                var tableIndex = 1;
                foreach (var dt in lstDt)
                {
                    //得到表描述
                    var array   = dt.TableName.Split('.');
                    var domain  = array[0];
                    var tabname = array[1];
                    var drs     = tables.Where(p => p.TableName == tabname).Where(p => p.Domain == domain).FirstOrDefault();// Select("表名='" + tabname + "' and 域='" + domain + "'");
                    var desp    = string.Empty;
                    if (drs != null)
                    {
                        desp = drs.TableDescription;
                    }
                    //创建表字段信息的html
                    HtmlHelp.CreateHtml(dt, true, System.IO.Path.Combine(pathTables, dt[0].tableschema, $"{dt.TableName}.html"), true, desp, true);
                    //构建表目录
                    dataTableStructures.Add(new DataTableItem {
                        TableNo = tableIndex++, Domain = drs.Domain, TableName = $"<a href=\"{tableStructureDirName}\\{drs.Domain}\\{ dt.TableName}.html\">{ dt.TableName.Split('.').GetValue(1)}</a>", TableDescription = desp
                    });
                    //改变进度
                    Dispatcher.Invoke(new Action(() => { tpbExport.Value++; }));
                }
                //导出表目录
                HtmlHelp.CreateHtml(dataTableStructures, false, "./tmp/" + defaultHtml, false, string.Empty, false); //默认页面
                Dispatcher.Invoke(new Action(() => { tpbExport.Value++; }));
            }
            #endregion

            #region 导出表数据  表中的数据示例 导出为html
            //传递需要导出数据的table选中项  得到数据内容
            selectTabStructList.Clear();
            foreach (var item in ckbData.SelectedItems)  //CheckedItems)
            {
                selectTabStructList.Add(item.ToString());
            }
            if (selectTabStructList.Count > 0)
            {
                Dispatcher.Invoke(new Action(() => { lblMessage.Content = "正在生成表数据数据..."; }));

                //读取ini
                int result = ini.GetInt32("Set", "maxrow", -1);

                var lstDt = dal.GetTableData(selectTabStructList, result);
                //创建常用数据的html
                var pathTables = $"./tmp/{tableDataDirName}";
                Directory.CreateDirectory(pathTables);
                var selecttabdataschemas = selectTabStructList.Select(p => p.Split('.')[0]).Distinct();
                foreach (var item in selecttabdataschemas)
                {
                    Directory.CreateDirectory(System.IO.Path.Combine(pathTables, item));
                }

                foreach (var dt in lstDt)
                {
                    HtmlHelp.CreateHtml2(dt, true, System.IO.Path.Combine(System.IO.Path.Combine(pathTables, dt.TableName.Split('.')[0]), dt.TableName + ".html"), true);
                    Dispatcher.Invoke(new Action(() => { tpbExport.Value++; }));
                }
            }

            Dispatcher.Invoke(new Action(() => { lblMessage.Content = "成功生成HTML..."; }));
            #endregion
        }