Esempio n. 1
0
        private void GenerateSelectViews(string ProcedureName, DataSet FieldList, bool WriteFiles, bool WriteSP, string schemaName)
        {
            var           viewGen       = new ViewGenerator();
            string        tableName     = FieldList.Tables[0].TableName;
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("@model List<" + AppName + ".Core.Models." + tableName.Replace("_", "") + ">\n\n");

            stringBuilder.Append(this.GetViewHeader("Manage " + tableName));

            stringBuilder.Append("\n");
            stringBuilder.Append("<table class=\"table table-striped table-bordered DataTable\">\n");
            stringBuilder.Append("   <thead>\n");
            List <DataColumn> selectableColumns = this.GetUpdatableColumns(FieldList);

            // Build Table Header
            for (int index = 0; index < selectableColumns.Count; ++index)
            {
                if (index == 0)
                {
                    stringBuilder.Append("     <tr>");
                    stringBuilder.Append("\n      <th>");
                }
                DataColumn dataColumn = selectableColumns[index];
                stringBuilder.Append(dataColumn.ColumnName.Replace("_", " ").Replace("-", " "));
                if (index < selectableColumns.Count - 1)
                {
                    stringBuilder.Append("</th>\n      <th>");
                }
            }
            stringBuilder.Append("</th>\n      <th>Functions</th>");
            stringBuilder.Append("\n     </tr>\n   </thead>\n   <tbody>");
            stringBuilder.Append("\n");
            stringBuilder.Append("@{\n     foreach(var item in Model){");
            stringBuilder.Append("\n          <tr>\n");

            for (int index = 0; index < selectableColumns.Count; ++index)
            {
                DataColumn dataColumn = selectableColumns[index];
                stringBuilder.Append("             <td>@Html.DisplayFor(modelItem => item." + dataColumn.ColumnName + ")</td>");
                stringBuilder.Append("\n");
            }
            stringBuilder.Append("             <td>\n");
            stringBuilder.Append("                @if(User.IsInRole(\"user.edit.example\"))\n");
            stringBuilder.Append("                {\n");
            stringBuilder.Append("                   <a href=\"@Url.Action(\"Edit\", new { id = item.Id })\" class=\"btn btn-xs btn-default\">Edit</a>\n");
            stringBuilder.Append("                }\n");
            stringBuilder.Append("                @if(User.IsInRole(\"user.delete.example\"))\n");
            stringBuilder.Append("                {\n");
            stringBuilder.Append("                   <a href=\"@Url.Action(\"Delete\", new { id = item.Id })\" class=\"btn btn-xs btn-danger\">Delete</a>\n");
            stringBuilder.Append("                }\n");
            stringBuilder.Append("             </td>");

            stringBuilder.Append("\n");
            stringBuilder.Append("          </tr>\n       } \n}");
            stringBuilder.Append("\n    </tbody>");
            stringBuilder.Append("\n</table>\n\n");
            stringBuilder.Append("<a href = \"@Url.Action(\"Insert\",\"" + tableName.Replace("_", "") + "\")\" class=\"btn btn-primary pull-right\">Add " + tableName.Replace("_", " ") + "</a>");
            stringBuilder.Append("</div>\n");
            stringBuilder.Append("</div>\n");
            stringBuilder.Append("</div>\n");
            stringBuilder.Append("</div>\n\n");

            stringBuilder.Append(viewGen.AddDataTablesJS());

            string CommandText = stringBuilder.ToString().Replace("\n", Environment.NewLine);

            CreateOutput(tableName, WriteFiles, false, CommandText, "view", "Index.cshtml");
        }