/// <summary> /// Render query and set current table tab /// </summary> /// <param name="query"></param> /// <param name="qt"></param> public void Render( QueryTable qt) { QueryTable qt2; MetaTable mt; int i1; if (Query == null) { return; } try { Tabs.TabPages.Clear(); if (Query.Tables.Count > 0 && ShowCriteriaTab) { AddCriteriaTab(); // insert initial tab } for (i1 = 0; i1 < Query.Tables.Count; i1++) { qt2 = Query.Tables[i1]; AddQueryTableTab(qt2); } //if (Query.KeyCriteria.ToUpper().Trim() == "IN LIST CURRENT") // update current list count // Query.KeyCriteriaDisplay = "In current search results list (" + SS.I.CurrentCountNotNull.ToString() + ")"; if (qt == null) { qt = Query.CurrentTable; } if (qt != null) { int qti = SelectQueryTableTab(qt); if (qti >= 0) { Tabs.TabPages[qti].Controls.Add(TableControlPrototype); // store the prototype control RenderQueryTable(qt); CurrentQt = qt; // make this the current query table if (QueryEngineStatsForm.ShowStats) { QueryEngineStatsForm.StartNewQueryExecution(Query); } return; } } CurrentQt = null; if (Query.Tables.Count > 0) { if (ShowCriteriaTab) { RenderCriteriaTab(); } else { Tabs.TabPages[0].Controls.Add(TableControlPrototype); // store the prototype control qt = Query.Tables[0]; RenderQueryTable(qt); CurrentQt = qt; // make this the current query table } } else // render empty query table { qt = new QueryTable(); qt.MetaTable = new MetaTable(); RenderQueryTable(qt); } if (QueryEngineStatsForm.ShowStats) { QueryEngineStatsForm.StartNewQueryExecution(Query); } return; } catch (Exception ex) { string msg = DebugLog.FormatExceptionMessage(ex); QueryEngine.LogExceptionAndSerializedQuery(msg, Query); throw new Exception(ex.Message, ex); // pass it up } }
/// <summary> /// Execute search & get hit list /// </summary> /// <param name="saveHitlist"></param> /// <returns></returns> public bool ExecuteSearch(bool saveHitlist) { int voi, ti, fi; ResultsTable rt; ResultsField rfld; MetaTable mt; MetaColumn mc, mc2; if (saveHitlist) // clear current list { SessionManager.CurrentResultKeys = new List <string>(); if (QueryManager.StatusBarManager != null) { QueryManager.StatusBarManager.DisplayCurrentCount(); } } // Start thread running the query QueryResultsAvailable = false; QueryEngineException = null; ThreadStart ts = new ThreadStart(ExecuteQueryThreadMethod); Thread executeQueryThread = new Thread(ts); executeQueryThread.Name = "ExecuteSearch"; executeQueryThread.IsBackground = true; executeQueryThread.SetApartmentState(ApartmentState.STA); executeQueryThread.Start(); // Put up message for user if (((Query.ResultKeys != null && Query.UseResultKeys) || // already have list ResultsFormat.SessionOutputFormContext) && !QueryEngineStatsForm.ShowStats) { Progress.Show("Retrieving data...", UmlautMobius.String, true, "Cancelling retrieval..."); } else // normal type search { Progress.Show("Searching database - 0:00", UmlautMobius.String, true, "Cancelling search..."); if (QueryEngineStatsForm.ShowStats) { QueryEngineStatsForm.StartNewQueryExecution(Query); QueryEngineStatsForm.StartingSearch(); } } // Wait until results available or the query is cancelled by the user while (true) { Thread.Sleep(100); Application.DoEvents(); if (QueryResultsAvailable) // completed normally { ResultsKeys = QueryEngine.GetKeys(); if (saveHitlist) // store for session manager also (may differ but probably shouldn't) { SessionManager.CurrentResultKeys = ResultsKeys; } //Progress.Hide(); break; } else if (QueryEngineException != null) { Progress.Hide(); if (QueryEngineException is QueryException || QueryEngineException is UserQueryException) { throw QueryEngineException; } else { throw new Exception(QueryEngineException.Message, QueryEngineException); } } else if (Progress.CancelRequested) { if (QueryEngine != null) { QueryEngine.Cancel(false); // start the cancel } Thread.Sleep(250); Application.DoEvents(); if (executeQueryThread != null) { executeQueryThread.Abort(); // kill the local thread executing the query } Progress.Hide(); return(false); } } // If the query contains tables marked for remapping then build new expanded query & use going forward // modifiedQuery = QueryEngine.DoPresearchChecksAndTransforms(Query); // do any presearch transforms OriginalQuery = Query; if (TransformedQuery != null) { //ResultsPages qrp = query.ResultsPages; //ResultsPages mqrp = modifiedQuery.ResultsPages; // use same set of results pages so view changes propagate back to original query Query.PresearchDerivedQuery = TransformedQuery; // link original query to the transformed query Query = TransformedQuery; // replace original query with this query } else { Query.PresearchDerivedQuery = null; } InitializeQueryManager(QueryManager, Query, QueryManager.ResultsFormat, QueryEngine, ResultsKeys); // Save the hit list as needed if (saveHitlist) { CidList currentList = new CidList(ResultsKeys); CidListCommand.WriteCurrentList(currentList); SessionManager.DisplayCurrentCount(); } return(true); }