/// <summary> /// Select the specified tab (e.g. query) /// </summary> /// <param name="tabIndex"></param> public void SelectQuery(int queryIndex) { if (queryIndex >= DocumentList.Count) { return; // shouldn't happen } SS.I.UISetupLevel++; CurrentQueryIndex = queryIndex; Document doc = DocumentList[queryIndex]; CurrentQuery = (Query)doc.Content; // restore query Query q = CurrentQuery; if (q.PresearchDerivedQuery != null) // restore any browse query { CurrentBrowseQuery = q.PresearchDerivedQuery; } else { CurrentBrowseQuery = q; } Tabs.TabPages[CurrentQueryIndex].Text = q.UserObject.Name; // make sure tab title is correct SessionManager.SetShellTitle(q.UserObject.Name); // set main window title Tabs.SelectedTabPageIndex = queryIndex; // select the tab if not done yet SS.I.UISetupLevel--; if (q.Mode == QueryMode.Unknown || q.Mode == QueryMode.Build) { QbUtil.SetMode(QueryMode.Build); // check & adjust build mode details Qtc.Render(q); SessionManager.DisplayCurrentCount(); } else // reenter browse mode { QbUtil.SetMode(QueryMode.Browse); // check & adjust build mode details QueryExec.RunQuery(q, OutputDest.WinForms, OutputFormContext.Session, browseExistingResults: true); SessionManager.DisplayFilterCountsAndString(); } }
/// <summary> /// Method to run query in background and save the results for later retrieval /// </summary> /// <param name="q"></param> /// <param name="emailSubject">Send email if defined</param> /// <param name="templateName"></param> /// <returns></returns> public static string RunBackgroundQuery( Query q, string emailSubject, string templateName) { ResultsFormat rf; QueryManager qm; DataTableManager dtm; string msg = "", html = "", resultsFileName; string viewCmd = "View Background Query Results"; bool notifyUserByEmail = !Lex.IsNullOrEmpty(emailSubject); try // execute the query & read in all results { QbUtil.AddQueryAndRender(q, false); // add it to the query builder q.BrowseSavedResultsUponOpen = false; // be sure query is run rather than using existing results msg = QueryExec.RunQuery(q, OutputDest.WinForms); qm = q.QueryManager as QueryManager; dtm = qm.DataTableManager; DialogResult dr = dtm.CompleteRetrieval(); } catch (Exception ex) // some exceptions are normal, e.g. no criteria, others may be bugs { msg = "RunQueryInBackground could not complete due to an unexpected exception: " + DebugLog.FormatExceptionMessage(ex); ServicesLog.Message(msg); if (notifyUserByEmail) { Email.Send(null, SS.I.UserInfo.EmailAddress, emailSubject, msg); } return(msg); } if (dtm.KeyCount == 0) { msg = "Query " + Lex.Dq(q.UserObject.Name) + " returned no results."; if (notifyUserByEmail) { Email.Send(null, SS.I.UserInfo.EmailAddress, emailSubject, msg); } return(msg); } try { resultsFileName = q.ResultsDataTableFileName; // see if name supplied in query if (Lex.IsNullOrEmpty(resultsFileName)) { resultsFileName = "Query_" + q.UserObject.Id + "_Results.bin"; } resultsFileName = ServicesIniFile.Read("BackgroundExportDirectory") + @"\" + resultsFileName; dtm.WriteBinaryResultsFile(resultsFileName); // write the file UserObject cidListUo = SaveBackgroundQueryResultsReferenceObject(qm, "BkgrndQry", resultsFileName); if (!Lex.IsNullOrEmpty(templateName)) { html = ReadTemplateFile(templateName); } if (notifyUserByEmail) { AlertUtil.MailResultsAvailableMessage( // send the mail q, dtm.KeyCount, SS.I.UserInfo.EmailAddress, emailSubject, viewCmd, cidListUo.Id, null, html); } else { html = SubstituteBackgroundExportParameters(html, "", "", dtm.RowCount, dtm.KeyCount, false, ""); return(html); // return the html } } catch (Exception ex) { msg = "Error sending background query results: " + DebugLog.FormatExceptionMessage(ex); ServicesLog.Message(msg); } return(msg); }
/////////////////////////////////////////////////////////////// ////////////////////// Event code ///////////////////////// /////////////////////////////////////////////////////////////// //private void FormattingButton_Click(object sender, EventArgs e) //{ // QueryColumn qc = TableControlPrototype.CurrentQc; // if (TableControlPrototype.CurrentQc == null) // { // MessageBoxMx.Show( // "Before using this button to define formatting for a field\r\n" + // "you must select the row in the grid corresponding to the field\r\n" + // "that you want to define formatting for.\r\n\r\n" + // "You can also define formatting for a field by clicking on\r\n" + // "one of the small arrows in the Data Field column.", // UmlautMobius.String, MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } // QueryTableControl.SetupColumnFormattingContextMenu(TableControlPrototype.ColumnFormattingContextMenu, qc, TableControlPrototype.UseNamedCfMenuItem_Click); // TableControlPrototype.ColumnFormattingContextMenu.Show(FormattingButton, // new System.Drawing.Point(0, FormattingButton.Height)); //} // RunQuery click & dropdown menu item clicks private void RunQueryButton_Click(object sender, EventArgs e) { SessionManager.LogCommandUsage("QueryTablesRunQuery"); QueryExec.RunQuery(Query, OutputDest.WinForms); }