示例#1
0
        //
        //====================================================================================================
        /// <summary>
        /// Run manual query
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public static string get(CPClass cp)
        {
            string         returnHtml = "";
            CoreController core       = cp.core;

            try {
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                Stream.add(AdminUIController.getHeaderTitleDescription("Run Manual Query", "This tool runs an SQL statement on a selected datasource. If there is a result set, the set is printed in a table."));
                //
                // Get the members SQL Queue
                //
                string SQLFilename = core.userProperty.getText("SQLArchive");
                if (string.IsNullOrEmpty(SQLFilename))
                {
                    SQLFilename = "SQLArchive" + core.session.user.id.ToString("000000000") + ".txt";
                    core.userProperty.setProperty("SQLArchive", SQLFilename);
                }
                string SQLArchive = core.cdnFiles.readFileText(SQLFilename);
                //
                // Read in arguments if available
                //
                int Timeout = core.docProperties.getInteger("Timeout");
                if (Timeout == 0)
                {
                    Timeout = 30;
                }
                //
                int pageSize = core.docProperties.getInteger("PageSize");
                if (pageSize == 0)
                {
                    pageSize = 10;
                }
                //
                int pageNumber = core.docProperties.getInteger("PageNumber");
                if (pageNumber == 0)
                {
                    pageNumber = 1;
                }
                //
                string SQL = core.docProperties.getText("SQL");
                if (string.IsNullOrEmpty(SQL))
                {
                    SQL = core.docProperties.getText("SQLList");
                }
                DataSourceModel datasource = DataSourceModel.create(core.cpParent, core.docProperties.getInteger("dataSourceid"));
                //
                if ((core.docProperties.getText("button")) == ButtonRun)
                {
                    //
                    // Add this SQL to the members SQL list
                    //
                    if (!string.IsNullOrEmpty(SQL))
                    {
                        string SQLArchiveOld = SQLArchive.Replace(SQL + Environment.NewLine, "");
                        SQLArchive = SQL.Replace(Environment.NewLine, " ") + Environment.NewLine;
                        int LineCounter = 0;
                        while ((LineCounter < 10) && (!string.IsNullOrEmpty(SQLArchiveOld)))
                        {
                            string line = getLine(ref SQLArchiveOld).Trim();
                            if (!string.IsNullOrWhiteSpace(line))
                            {
                                SQLArchive += line + Environment.NewLine;
                            }
                        }
                        core.cdnFiles.saveFile(SQLFilename, SQLArchive);
                    }
                    //
                    // Run the SQL
                    //
                    string errBefore = ErrorController.getDocExceptionHtmlList(core);
                    if (!string.IsNullOrWhiteSpace(errBefore))
                    {
                        // -- error in interface, should be fixed before attempting query
                        Stream.add("<br>" + core.dateTimeNowMockable + " SQL NOT executed. The following errors were detected before execution");
                        Stream.add(errBefore);
                    }
                    else
                    {
                        Stream.add("<p>" + core.dateTimeNowMockable + " Executing sql [" + SQL + "] on DataSource [" + datasource.name + "]");
                        DataTable dt = null;
                        try {
                            dt = core.db.executeQuery(SQL, DbController.getStartRecord(pageSize, pageNumber), pageSize);
                        } catch (Exception ex) {
                            //
                            // ----- error
                            Stream.add("<br>" + core.dateTimeNowMockable + " SQL execution returned the following error");
                            Stream.add("<br>" + ex.Message);
                        }
                        string errSql = ErrorController.getDocExceptionHtmlList(core);
                        if (!string.IsNullOrWhiteSpace(errSql))
                        {
                            Stream.add("<br>" + core.dateTimeNowMockable + " SQL execution returned the following error");
                            Stream.add("<br>" + errSql);
                            core.doc.errorList.Clear();
                        }
                        else
                        {
                            Stream.add("<br>" + core.dateTimeNowMockable + " SQL executed successfully");
                            if (dt == null)
                            {
                                Stream.add("<br>" + core.dateTimeNowMockable + " SQL returned invalid data.");
                            }
                            else if (dt.Rows == null)
                            {
                                Stream.add("<br>" + core.dateTimeNowMockable + " SQL returned invalid data rows.");
                            }
                            else if (dt.Rows.Count == 0)
                            {
                                Stream.add("<br>" + core.dateTimeNowMockable + " The SQL returned no data.");
                            }
                            else
                            {
                                //
                                // ----- print results
                                //
                                Stream.add("<br>" + core.dateTimeNowMockable + " The following results were returned");
                                Stream.add("<br></p>");
                                //
                                // --- Create the Fields for the new table
                                //
                                int FieldCount = dt.Columns.Count;
                                Stream.add("<table class=\"table table-bordered table-hover table-sm table-striped\">");
                                Stream.add("<thead class=\"thead - inverse\"><tr>");
                                foreach (DataColumn dc in dt.Columns)
                                {
                                    Stream.add("<th>" + dc.ColumnName + "</th>");
                                }
                                Stream.add("</tr></thead>");
                                //
                                string[,] resultArray = core.db.convertDataTabletoArray(dt);
                                //
                                int    RowMax      = resultArray.GetUpperBound(1);
                                int    ColumnMax   = resultArray.GetUpperBound(0);
                                string RowStart    = "<tr>";
                                string RowEnd      = "</tr>";
                                string ColumnStart = "<td>";
                                string ColumnEnd   = "</td>";
                                int    RowPointer  = 0;
                                for (RowPointer = 0; RowPointer <= RowMax; RowPointer++)
                                {
                                    Stream.add(RowStart);
                                    int ColumnPointer = 0;
                                    for (ColumnPointer = 0; ColumnPointer <= ColumnMax; ColumnPointer++)
                                    {
                                        string CellData = resultArray[ColumnPointer, RowPointer];
                                        if (isNull(CellData))
                                        {
                                            Stream.add(ColumnStart + "[null]" + ColumnEnd);
                                        }
                                        else if (string.IsNullOrEmpty(CellData))
                                        {
                                            Stream.add(ColumnStart + "[empty]" + ColumnEnd);
                                        }
                                        else
                                        {
                                            Stream.add(ColumnStart + HtmlController.encodeHtml(GenericController.encodeText(CellData)) + ColumnEnd);
                                        }
                                    }
                                    Stream.add(RowEnd);
                                }
                                Stream.add("</table>");
                            }
                        }
                    }
                    Stream.add("<p>" + core.dateTimeNowMockable + " Done</p>");
                }
                //
                // Display form
                {
                    //
                    // -- sql form
                    int SQLRows = core.docProperties.getInteger("SQLRows");
                    if (SQLRows == 0)
                    {
                        SQLRows = core.userProperty.getInteger("ManualQueryInputRows", 5);
                    }
                    else
                    {
                        core.userProperty.setProperty("ManualQueryInputRows", SQLRows.ToString());
                    }
                    Stream.add(AdminUIEditorController.getHtmlCodeEditor(core, "SQL", SQL, false, "SQL", false));
                    Stream.add("&nbsp;<INPUT TYPE=\"Text\" TabIndex=-1 NAME=\"SQLRows\" SIZE=\"3\" VALUE=\"" + SQLRows + "\" ID=\"\"  onchange=\"SQL.rows=SQLRows.value; return true\"> Rows");
                }
                //
                // -- data source
                bool isEmptyList = false;
                Stream.add(AdminUIController.getToolFormInputRow(core, "Data Source", AdminUIEditorController.getLookupContentEditor(core, "DataSourceID", datasource.id, ContentMetadataModel.getContentId(core, "data sources"), ref isEmptyList, false, "", "", false, "")));
                {
                    //
                    // -- sql list
                    string        js          = "var e = document.getElementById('SQLList');SQL.value=e.options[e.selectedIndex].text;";
                    List <string> lookupList  = SQLArchive.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    string        inputSelect = AdminUIEditorController.getLookupListEditor(core, "SQLList", 0, lookupList, false, "SQLList", "", false);
                    inputSelect = inputSelect.Replace("<select ", "<select onChange=\"" + js + "\" ");
                    Stream.add(AdminUIController.getToolFormInputRow(core, "Previous Queries", inputSelect));
                }
                //
                // -- page size
                if (isNull(pageSize))
                {
                    pageSize = 100;
                }
                Stream.add(AdminUIController.getToolFormInputRow(core, "Page Size", AdminUIEditorController.getTextEditor(core, "PageSize", pageSize.ToString())));
                //
                // -- page number
                if (isNull(pageNumber))
                {
                    pageNumber = 1;
                }
                Stream.add(AdminUIController.getToolFormInputRow(core, "Page Number", AdminUIEditorController.getTextEditor(core, "PageNumber", pageNumber.ToString())));
                //
                // -- timeout
                if (isNull(Timeout))
                {
                    Timeout = 30;
                }
                Stream.add(AdminUIController.getToolFormInputRow(core, "Timeout (sec)", AdminUIEditorController.getTextEditor(core, "Timeout", Timeout.ToString())));
                //
                // -- assemble form
                returnHtml = AdminUIController.getToolForm(core, Stream.text, ButtonCancel + "," + ButtonRun);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnHtml);
        }
        //
        //====================================================================================================
        //
        public static string get(CoreController core)
        {
            string result = "";

            try {
                //
                int    ContentId   = 0;
                string TableName   = "";
                string ContentName = "";
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                string          ButtonList           = null;
                string          Description          = null;
                string          Caption     = null;
                int             NavId       = 0;
                int             ParentNavId = 0;
                DataSourceModel datasource  = DataSourceModel.create(core.cpParent, core.docProperties.getInteger("DataSourceID"));
                //
                ButtonList  = ButtonCancel + "," + ButtonRun;
                Caption     = "Create Content Definition";
                Description = "This tool creates a Content Definition. If the SQL table exists, it is used. If it does not exist, it is created. If records exist in the table with a blank ContentControlID, the ContentControlID will be populated from this new definition. A Navigator Menu entry will be added under Manage Site Content - Advanced.";
                //
                //   print out the submit form
                //
                if (core.docProperties.getText("Button") != "")
                {
                    //
                    // Process input
                    //
                    ContentName = core.docProperties.getText("ContentName");
                    TableName   = core.docProperties.getText("TableName");
                    //
                    Stream.add(SpanClassAdminSmall);
                    Stream.add("<P>Creating content [" + ContentName + "] on table [" + TableName + "] on Datasource [" + datasource.name + "].</P>");
                    if ((!string.IsNullOrEmpty(ContentName)) && (!string.IsNullOrEmpty(TableName)) && (!string.IsNullOrEmpty(datasource.name)))
                    {
                        using (var db = new DbController(core, datasource.name)) {
                            db.createSQLTable(TableName);
                        }
                        ContentMetadataModel.createFromSQLTable(core, datasource, TableName, ContentName);
                        core.cache.invalidateAll();
                        core.clearMetaData();
                        ContentId   = Processor.Models.Domain.ContentMetadataModel.getContentId(core, ContentName);
                        ParentNavId = MetadataController.getRecordIdByUniqueName(core, NavigatorEntryModel.tableMetadata.contentName, "Manage Site Content");
                        if (ParentNavId != 0)
                        {
                            ParentNavId = 0;
                            using (var csSrc = new CsModel(core)) {
                                if (csSrc.open(NavigatorEntryModel.tableMetadata.contentName, "(name=" + DbController.encodeSQLText("Advanced") + ")and(parentid=" + ParentNavId + ")"))
                                {
                                    ParentNavId = csSrc.getInteger("ID");
                                }
                            }
                            if (ParentNavId != 0)
                            {
                                using (var csDest = new CsModel(core)) {
                                    csDest.open(NavigatorEntryModel.tableMetadata.contentName, "(name=" + DbController.encodeSQLText(ContentName) + ")and(parentid=" + NavId + ")");
                                    if (!csDest.ok())
                                    {
                                        csDest.close();
                                        csDest.insert(NavigatorEntryModel.tableMetadata.contentName);
                                    }
                                    if (csDest.ok())
                                    {
                                        csDest.set("name", ContentName);
                                        csDest.set("parentid", ParentNavId);
                                        csDest.set("contentid", ContentId);
                                    }
                                }
                            }
                        }
                        ContentId = ContentMetadataModel.getContentId(core, ContentName);
                        Stream.add("<P>Content Definition was created. An admin menu entry for this definition has been added under 'Site Content', and will be visible on the next page view. Use the [<a href=\"?af=105&ContentID=" + ContentId + "\">Edit Content Definition Fields</a>] tool to review and edit this definition's fields.</P>");
                    }
                    else
                    {
                        Stream.add("<P>Error, a required field is missing. Content not created.</P>");
                    }
                    Stream.add("</SPAN>");
                }
                Stream.add(SpanClassAdminNormal);
                Stream.add("Data Source<br>");
                Stream.add(core.html.selectFromContent("DataSourceID", datasource.id, "Data Sources", "", "Default"));
                Stream.add("<br><br>");
                Stream.add("Content Name<br>");
                Stream.add(HtmlController.inputText_Legacy(core, "ContentName", ContentName, 1, 40));
                Stream.add("<br><br>");
                Stream.add("Table Name<br>");
                Stream.add(HtmlController.inputText_Legacy(core, "TableName", TableName, 1, 40));
                Stream.add("<br><br>");
                Stream.add("</SPAN>");
                result = AdminUIController.getToolBody(core, Caption, ButtonList, "", false, false, Description, "", 10, Stream.text);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
示例#3
0
        //
        //=============================================================================
        //   Print the manual query form
        //=============================================================================
        //
        public static string get(CoreController core)
        {
            string result = "";

            try {
                bool   StatusOK      = false;
                int    FieldCount    = 0;
                object Retries       = null;
                int    RowMax        = 0;
                int    RowPointer    = 0;
                int    ColumnMax     = 0;
                int    ColumnPointer = 0;
                string ColumnStart   = null;
                string ColumnEnd     = null;
                string RowStart      = null;
                string RowEnd        = null;
                string[,] arrayOfSchema = null;
                string CellData  = null;
                string TableName = "";
                StringBuilderLegacyController Stream = new StringBuilderLegacyController();
                string    ButtonList       = null;
                DataTable RSSchema         = null;
                var       tmpList          = new List <string> {
                };
                DataSourceModel datasource = DataSourceModel.create(core.cpParent, core.docProperties.getInteger("DataSourceID"), ref tmpList);
                //
                ButtonList = ButtonCancel + "," + ButtonRun;
                //
                Stream.add(AdminUIController.getHeaderTitleDescription("Query Database Schema", "This tool examines the database schema for all tables available."));
                //
                StatusOK = true;
                if ((core.docProperties.getText("button")) != ButtonRun)
                {
                    //
                    // First pass, initialize
                    //
                    Retries = 0;
                }
                else
                {
                    //
                    // Read in arguments
                    //
                    TableName = core.docProperties.getText("TableName");
                    //
                    // Run the SQL
                    Stream.add(SpanClassAdminSmall + "<br><br>");
                    Stream.add(core.dateTimeNowMockable + " Opening Table Schema on DataSource [" + datasource.name + "]<br>");
                    //
                    RSSchema = core.db.getTableSchemaData(TableName);
                    Stream.add(core.dateTimeNowMockable + " GetSchema executed successfully<br>");
                    if (!DbController.isDataTableOk(RSSchema))
                    {
                        //
                        // ----- no result
                        //
                        Stream.add(core.dateTimeNowMockable + " A schema was returned, but it contains no records.<br>");
                    }
                    else
                    {
                        //
                        // ----- print results
                        //
                        Stream.add(core.dateTimeNowMockable + " The following results were returned<br>");
                        //
                        // --- Create the Fields for the new table
                        //
                        FieldCount = RSSchema.Columns.Count;
                        Stream.add("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">");
                        Stream.add("<tr>");
                        foreach (DataColumn RecordField in RSSchema.Columns)
                        {
                            Stream.add("<TD><B>" + SpanClassAdminSmall + RecordField.ColumnName + "</b></SPAN></td>");
                        }
                        Stream.add("</tr>");
                        //
                        arrayOfSchema = core.db.convertDataTabletoArray(RSSchema);
                        //
                        RowMax      = arrayOfSchema.GetUpperBound(1);
                        ColumnMax   = arrayOfSchema.GetUpperBound(0);
                        RowStart    = "<tr>";
                        RowEnd      = "</tr>";
                        ColumnStart = "<td class=\"ccadminsmall\">";
                        ColumnEnd   = "</td>";
                        for (RowPointer = 0; RowPointer <= RowMax; RowPointer++)
                        {
                            Stream.add(RowStart);
                            for (ColumnPointer = 0; ColumnPointer <= ColumnMax; ColumnPointer++)
                            {
                                CellData = arrayOfSchema[ColumnPointer, RowPointer];
                                if (isNull(CellData))
                                {
                                    Stream.add(ColumnStart + "[null]" + ColumnEnd);
                                }
                                else if ((CellData == null))
                                {
                                    Stream.add(ColumnStart + "[empty]" + ColumnEnd);
                                }
                                else if (string.IsNullOrEmpty(CellData))
                                {
                                    Stream.add(ColumnStart + "[empty]" + ColumnEnd);
                                }
                                else
                                {
                                    Stream.add(ColumnStart + CellData + ColumnEnd);
                                }
                            }
                            Stream.add(RowEnd);
                        }
                        Stream.add("</TABLE>");
                        RSSchema.Dispose();
                        RSSchema = null;
                    }
                    //
                    // Index Schema
                    //
                    //    RSSchema = DataSourceConnectionObjs(DataSourcePointer).Conn.OpenSchema(SchemaEnum.adSchemaColumns, Array(Empty, Empty, TableName, Empty))
                    Stream.add(SpanClassAdminSmall + "<br><br>");
                    Stream.add(core.dateTimeNowMockable + " Opening Index Schema<br>");
                    //
                    RSSchema = core.db.getIndexSchemaData(TableName);
                    if (!DbController.isDataTableOk(RSSchema))
                    {
                        //
                        // ----- no result
                        //
                        Stream.add(core.dateTimeNowMockable + " A schema was returned, but it contains no records.<br>");
                    }
                    else
                    {
                        //
                        // ----- print results
                        //
                        Stream.add(core.dateTimeNowMockable + " The following results were returned<br>");
                        //
                        // --- Create the Fields for the new table
                        //
                        FieldCount = RSSchema.Columns.Count;
                        Stream.add("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">");
                        Stream.add("<tr>");
                        foreach (DataColumn RecordField in RSSchema.Columns)
                        {
                            Stream.add("<TD><B>" + SpanClassAdminSmall + RecordField.ColumnName + "</b></SPAN></td>");
                        }
                        Stream.add("</tr>");
                        //

                        arrayOfSchema = core.db.convertDataTabletoArray(RSSchema);
                        //
                        RowMax      = arrayOfSchema.GetUpperBound(1);
                        ColumnMax   = arrayOfSchema.GetUpperBound(0);
                        RowStart    = "<tr>";
                        RowEnd      = "</tr>";
                        ColumnStart = "<td class=\"ccadminsmall\">";
                        ColumnEnd   = "</td>";
                        for (RowPointer = 0; RowPointer <= RowMax; RowPointer++)
                        {
                            Stream.add(RowStart);
                            for (ColumnPointer = 0; ColumnPointer <= ColumnMax; ColumnPointer++)
                            {
                                CellData = arrayOfSchema[ColumnPointer, RowPointer];
                                if (isNull(CellData))
                                {
                                    Stream.add(ColumnStart + "[null]" + ColumnEnd);
                                }
                                else if ((CellData == null))
                                {
                                    Stream.add(ColumnStart + "[empty]" + ColumnEnd);
                                }
                                else if (string.IsNullOrEmpty(CellData))
                                {
                                    Stream.add(ColumnStart + "[empty]" + ColumnEnd);
                                }
                                else
                                {
                                    Stream.add(ColumnStart + CellData + ColumnEnd);
                                }
                            }
                            Stream.add(RowEnd);
                        }
                        Stream.add("</TABLE>");
                        RSSchema.Dispose();
                        RSSchema = null;
                    }
                    //
                    // Column Schema
                    //
                    Stream.add(SpanClassAdminSmall + "<br><br>");
                    Stream.add(core.dateTimeNowMockable + " Opening Column Schema<br>");
                    //
                    RSSchema = core.db.getColumnSchemaData(TableName);
                    Stream.add(core.dateTimeNowMockable + " GetSchema executed successfully<br>");
                    if (DbController.isDataTableOk(RSSchema))
                    {
                        //
                        // ----- no result
                        //
                        Stream.add(core.dateTimeNowMockable + " A schema was returned, but it contains no records.<br>");
                    }
                    else
                    {
                        //
                        // ----- print results
                        //
                        Stream.add(core.dateTimeNowMockable + " The following results were returned<br>");
                        //
                        // --- Create the Fields for the new table
                        //
                        FieldCount = RSSchema.Columns.Count;
                        Stream.add("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">");
                        Stream.add("<tr>");
                        foreach (DataColumn RecordField in RSSchema.Columns)
                        {
                            Stream.add("<TD><B>" + SpanClassAdminSmall + RecordField.ColumnName + "</b></SPAN></td>");
                        }
                        Stream.add("</tr>");
                        //
                        arrayOfSchema = core.db.convertDataTabletoArray(RSSchema);
                        //
                        RowMax      = arrayOfSchema.GetUpperBound(1);
                        ColumnMax   = arrayOfSchema.GetUpperBound(0);
                        RowStart    = "<tr>";
                        RowEnd      = "</tr>";
                        ColumnStart = "<td class=\"ccadminsmall\">";
                        ColumnEnd   = "</td>";
                        for (RowPointer = 0; RowPointer <= RowMax; RowPointer++)
                        {
                            Stream.add(RowStart);
                            for (ColumnPointer = 0; ColumnPointer <= ColumnMax; ColumnPointer++)
                            {
                                CellData = arrayOfSchema[ColumnPointer, RowPointer];
                                if (isNull(CellData))
                                {
                                    Stream.add(ColumnStart + "[null]" + ColumnEnd);
                                }
                                else if ((CellData == null))
                                {
                                    Stream.add(ColumnStart + "[empty]" + ColumnEnd);
                                }
                                else if (string.IsNullOrEmpty(CellData))
                                {
                                    Stream.add(ColumnStart + "[empty]" + ColumnEnd);
                                }
                                else
                                {
                                    Stream.add(ColumnStart + CellData + ColumnEnd);
                                }
                            }
                            Stream.add(RowEnd);
                        }
                        Stream.add("</TABLE>");
                        RSSchema.Dispose();
                        RSSchema = null;
                    }
                    if (!StatusOK)
                    {
                        Stream.add("There was a problem executing this query that may have prevented the results from printing.");
                    }
                    Stream.add(core.dateTimeNowMockable + " Done</SPAN>");
                }
                //
                // Display form
                //
                Stream.add(SpanClassAdminNormal);
                //
                Stream.add("<br>");
                Stream.add("Table Name<br>");
                Stream.add(HtmlController.inputText_Legacy(core, "Tablename", TableName));
                //
                Stream.add("<br><br>");
                Stream.add("Data Source<br>");
                Stream.add(core.html.selectFromContent("DataSourceID", datasource.id, "Data Sources", "", "Default"));
                //
                Stream.add("</SPAN>");
                //
                result = AdminUIController.getToolForm(core, Stream.text, ButtonList);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
示例#4
0
        //
        //=============================================================================
        //   Export the Admin List form results
        //=============================================================================
        //
        public static string get(CoreController core, AdminDataModel adminData)
        {
            string result = "";

            try {
                //
                bool   AllowContentAccess                    = false;
                string ButtonCommaList                       = "";
                string ExportName                            = null;
                string Description                           = null;
                string Content                               = "";
                string Button                                = null;
                int    RecordLimit                           = 0;
                int    recordCnt                             = 0;
                string sqlFieldList                          = "";
                string SQLFrom                               = "";
                string SQLWhere                              = "";
                string SQLOrderBy                            = "";
                bool   IsLimitedToSubContent                 = false;
                string ContentAccessLimitMessage             = "";
                Dictionary <string, bool> FieldUsedInColumns = new Dictionary <string, bool>();
                Dictionary <string, bool> IsLookupFieldValid = new Dictionary <string, bool>();
                IndexConfigClass          IndexConfig        = null;
                string          SQL                          = null;
                bool            IsRecordLimitSet             = false;
                string          RecordLimitText              = null;
                var             cacheNameList                = new List <string>();
                DataSourceModel datasource                   = DataSourceModel.create(core.cpParent, adminData.adminContent.dataSourceId, ref cacheNameList);
                //
                // ----- Process Input
                //
                Button = core.docProperties.getText("Button");
                if (Button == ButtonCancelAll)
                {
                    //
                    // Cancel out to the main page
                    //
                    return(core.webServer.redirect("?", "CancelAll button pressed on Index Export"));
                }
                else if (Button != ButtonCancel)
                {
                    //
                    // get content access rights
                    //
                    var userContentPermissions = PermissionController.getUserContentPermissions(core, adminData.adminContent);
                    if (!userContentPermissions.allowEdit)
                    {
                        //
                        // You must be a content manager of this content to use this tool
                        //
                        Content = ""
                                  + "<p>You must be a content manager of " + adminData.adminContent.name + " to use this tool. Hit Cancel to return to main admin page.</p>"
                                  + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                        ButtonCommaList = ButtonCancelAll;
                    }
                    else
                    {
                        IsRecordLimitSet = false;
                        if (string.IsNullOrEmpty(Button))
                        {
                            //
                            // Set Defaults
                            //
                            ExportName      = "";
                            RecordLimit     = 0;
                            RecordLimitText = "";
                        }
                        else
                        {
                            ExportName      = core.docProperties.getText("ExportName");
                            RecordLimitText = core.docProperties.getText("RecordLimit");
                            if (!string.IsNullOrEmpty(RecordLimitText))
                            {
                                IsRecordLimitSet = true;
                                RecordLimit      = GenericController.encodeInteger(RecordLimitText);
                            }
                        }
                        if (string.IsNullOrEmpty(ExportName))
                        {
                            ExportName = adminData.adminContent.name + " export for " + core.session.user.name;
                        }
                        //
                        // Get the SQL parts
                        //
                        IndexConfig = IndexConfigClass.get(core, adminData);
                        ListView.setIndexSQL(core, adminData, IndexConfig, ref AllowContentAccess, ref sqlFieldList, ref SQLFrom, ref SQLWhere, ref SQLOrderBy, ref IsLimitedToSubContent, ref ContentAccessLimitMessage, ref FieldUsedInColumns, IsLookupFieldValid);
                        if (!AllowContentAccess)
                        {
                            //
                            // This should be caught with check earlier, but since I added this, and I never make mistakes, I will leave this in case there is a mistake in the earlier code
                            //
                            Processor.Controllers.ErrorController.addUserError(core, "Your account does not have access to any records in '" + adminData.adminContent.name + "'.");
                        }
                        else
                        {
                            //
                            // Get the total record count
                            //
                            SQL = "select count(" + adminData.adminContent.tableName + ".ID) as cnt from " + SQLFrom + " where " + SQLWhere;
                            using (var csData = new CsModel(core)) {
                                csData.openSql(SQL, datasource.name);
                                if (csData.ok())
                                {
                                    recordCnt = csData.getInteger("cnt");
                                }
                            }
                            //
                            // Build the SQL
                            //
                            SQL = "select";
                            if (IsRecordLimitSet && (datasource.dbTypeId != DataSourceTypeODBCMySQL))
                            {
                                SQL += " Top " + RecordLimit;
                            }
                            SQL += " " + adminData.adminContent.tableName + ".* From " + SQLFrom + " WHERE " + SQLWhere;
                            if (!string.IsNullOrEmpty(SQLOrderBy))
                            {
                                SQL += " Order By" + SQLOrderBy;
                            }
                            if (IsRecordLimitSet && (datasource.dbTypeId == DataSourceTypeODBCMySQL))
                            {
                                SQL += " Limit " + RecordLimit;
                            }
                            //
                            // Assumble the SQL
                            //
                            if (recordCnt == 0)
                            {
                                //
                                // There are no records to request
                                //
                                Content = ""
                                          + "<p>This selection has no records. Hit Cancel to return to the " + adminData.adminContent.name + " list page.</p>"
                                          + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                                ButtonCommaList = ButtonCancel;
                            }
                            else if (Button == ButtonRequestDownload)
                            {
                                //
                                // Request the download
                                //
                                var ExportCSVAddon = DbBaseModel.create <AddonModel>(core.cpParent, addonGuidExportCSV);
                                if (ExportCSVAddon == null)
                                {
                                    LogController.logError(core, new GenericException("ExportCSV addon not found. Task could not be added to task queue."));
                                }
                                else
                                {
                                    var docProperties = new Dictionary <string, string> {
                                        { "sql", SQL },
                                        { "datasource", "default" }
                                    };
                                    var cmdDetail = new TaskModel.CmdDetailClass {
                                        addonId   = ExportCSVAddon.id,
                                        addonName = ExportCSVAddon.name,
                                        args      = docProperties
                                    };
                                    TaskSchedulerController.addTaskToQueue(core, cmdDetail, false, ExportName, "export_" + adminData.adminContent.name.Replace(" ", "_") + ".csv");
                                }
                                //
                                Content = ""
                                          + "<p>Your export has been requested and will be available shortly in the <a href=\"?" + rnAdminForm + "=" + AdminFormDownloads + "\">Download Manager</a>. Hit Cancel to return to the " + adminData.adminContent.name + " list page.</p>"
                                          + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                                //
                                ButtonCommaList = ButtonCancel;
                            }
                            else
                            {
                                //
                                // no button or refresh button, Ask are you sure
                                //
                                Content += HtmlController.div(
                                    HtmlController.label("Export Name", "export-name")
                                    + HtmlController.inputText(core, "ExportName", ExportName, "form-control", "export-name")
                                    , "form-group");
                                Content += HtmlController.div(
                                    HtmlController.label("Records Found", "records-found")
                                    + HtmlController.inputText(core, "RecordCnt", recordCnt.ToString(), "form-control", "records-found", true)
                                    , "form-group");
                                Content += HtmlController.div(
                                    HtmlController.label("Record Limit", "record-limit")
                                    + HtmlController.inputText(core, "RecordLimit", RecordLimitText, "form-control", "record-limit")
                                    , "form-group");
                                if (core.session.isAuthenticatedDeveloper())
                                {
                                    Content += HtmlController.div(
                                        HtmlController.label("Results SQL", "export-query")
                                        + HtmlController.inputTextarea(core, "sql", SQL, 4, -1, "export-query", false, false, "form-control")
                                        , "form-group");
                                }
                                //
                                Content = ""
                                          //+ "\r<style>"
                                          //+ cr2 + ".exportTblCaption {width:100px;}"
                                          //+ cr2 + ".exportTblInput {}"
                                          //+ "\r</style>"
                                          + Content + HtmlController.inputHidden(RequestNameAdminSubForm, AdminFormIndex_SubFormExport) + "";
                                ButtonCommaList = ButtonCancel + "," + ButtonRequestDownload;
                                if (core.session.isAuthenticatedDeveloper())
                                {
                                    ButtonCommaList = ButtonCommaList + "," + ButtonRefresh;
                                }
                            }
                        }
                    }
                    //
                    Description = "<p>This tool creates an export of the current admin list page results. If you would like to download the current results, select a format and press OK. Your search results will be submitted for export. Your download will be ready shortly in the download manager. To exit without requesting an output, hit Cancel.</p>";
                    result      = AdminUIController.getToolBody(core, adminData.adminContent.name + " Export", ButtonCommaList, "", false, false, Description, "", 10, Content);
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }