Esempio n. 1
0
        //根据项目编码,获取数据库以及表信息(用于主页展示目录)
        public void PreviewTable()
        {
            NameValueCollection Params       = HttpContext.Request.Form;//参数
            IList <Database>    databaselist = DDatabase.GetDatabase(new Guid(Params["projectCode"].ToString()));
            StringBuilder       Json         = new StringBuilder();

            Json.Append("{ projectName: '" + Params["projectName"] + "',");
            Json.Append("copyright:'DBVortaro',");
            Json.Append("time: '" + DateTime.Now.ToString("yyyy年MM月dd日") + "',list: [");
            int databaseNumber = 0;//数据库计数器

            for (int i = 0; i < databaselist.Count; i++)
            {
                DataTable tableslist = DTables.GetTables2(databaselist[i].Code);
                if (tableslist.Rows.Count > 0)//判断数据库下面是否存在表信息
                {
                    if (databaseNumber > 0)
                    {
                        Json.Append(",");
                    }
                    Json.Append("{ databaseName: '" + databaselist[i].Name
                                + "',serverName: '" + databaselist[i].ServerName
                                + "',list: [");
                    for (int j = 0; j < tableslist.Rows.Count; j++)
                    {
                        if (j > 0)
                        {
                            Json.Append(",");
                        }
                        Json.Append("{ Name: '" + tableslist.Rows[j]["Name"].ToString() + "',");
                        Json.Append("Url: 'Items/items.html?code=" + tableslist.Rows[j]["Code"].ToString() + "',");
                        Json.Append("Alias: '" + tableslist.Rows[j]["Alias"].ToString() + "',");
                        Json.Append("Author: '" + tableslist.Rows[j]["Author"].ToString() + "',");
                        Json.Append("GroupName: '" + DGroup.GetGroupName(new Guid(tableslist.Rows[j]["GroupCode"].ToString())) + "'");
                        Json.Append("}");
                    }
                    Json.Append("]}");
                    databaseNumber++;
                }
            }
            Json.Append("]}");
            Response.Write(Json.ToString());
            Response.End();
        }
Esempio n. 2
0
        /// <summary>
        /// 生成HTML首页
        /// </summary>
        /// <param name="projectCode">项目编码</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="directory">输出路径</param>
        /// <param name="indexPath">首页模板路径</param>
        /// <param name="itemsPath">子页模板路径</param>
        private static void BuildIndex(string projectCode, string fileName, string directory, string indexPath, string itemsPath)
        {
            string           tableStr     = string.Empty; //表格
            IList <Database> databaselist = DDatabase.GetDatabase(new Guid(projectCode));
            int  rowspan = 0;                             //分组跨行计数
            bool merger  = false;                         //是否合并

            for (int k = 0; k < databaselist.Count; k++)
            {
                DataTable tableslist = DTables.GetTables2(databaselist[k].Code);
                if (tableslist.Rows.Count > 0)//是否存在表字段
                {
                    tableStr += @"
                    <table style=""width: 100%;"">
		            <tr><td colspan=""5"" style=""font-weight:bold;line-height:20px;"">服务器:"         + databaselist[k].ServerName + "<br/>数据库:" + databaselist[k].Name + @"</td></tr>
		            <tr class=""text-center""><th style=""width:60px"">序号</th><th>分组</th><th>表名</th><th>别名</th><th>作者</th></tr>"        ;
                    for (int q = 0; q < tableslist.Rows.Count; q++)
                    {
                        string url = string.Format("Items/{0}_{1}.html", databaselist[k].Name, tableslist.Rows[q]["Name"].ToString());
                        tableStr += string.Format(@"<tr><td style=""padding-left:10px;"">{0}</td>", q + 1);
                        string GroupName = string.Empty,
                               TempName  = DGroup.GetGroupName(new Guid(tableslist.Rows[q]["GroupCode"].ToString()));
                        //名称竖排
                        for (int Q = 0; Q < TempName.Length; Q++)
                        {
                            GroupName += TempName[Q].ToString() + "<br/>";
                        }
                        //分组跨行处理
                        if (rowspan == 0)
                        {
                            for (int j = q; j < tableslist.Rows.Count; j++)
                            {
                                if (tableslist.Rows[j]["GroupCode"].ToString() == tableslist.Rows[q]["GroupCode"].ToString())
                                {
                                    rowspan++;
                                }
                            }
                            merger = true;
                        }
                        if (rowspan > 0 && merger == true)
                        {
                            tableStr += string.Format(@"<td class=""text-center"" style=""width:60px;"" rowspan=""{0}"">{1}</td>", rowspan, GroupName);
                            merger    = false; //停用合并
                            rowspan--;         //合并行计数
                        }
                        else if (rowspan > 0)
                        {
                            rowspan--;//合并行计数
                        }
                        else
                        {
                            tableStr += string.Format(@"<td class=""text-center"" style=""width:60px;"">{0}</td>", GroupName);
                        }
                        tableStr += string.Format(@"<td><a href=""{0}"">{1}</a></td><td><a href=""{0}"">{2}</a></td>
	                        <td class=""text-center"">{3}</td></tr>"    ,
                                                  url, tableslist.Rows[q]["Name"].ToString(),
                                                  tableslist.Rows[q]["Alias"].ToString(),
                                                  tableslist.Rows[q]["Author"].ToString());
                        BuildItems(new Guid(tableslist.Rows[q]["Code"].ToString()),
                                   tableslist.Rows[q]["Name"].ToString(),
                                   tableslist.Rows[q]["Alias"].ToString(),
                                   directory + "/" + url, itemsPath);
                    }
                    tableStr += "</table><br/>";
                }
            }
            string[] indexTemp = new string[] { "@title", "@table", "@footer" };
            string[] indexHtml = new string[] { fileName, tableStr, "DBVortaro" };
            DTemplates.WriteHtml(indexTemp, indexHtml, indexPath, directory + "/index.html");
        }