Esempio n. 1
0
 private void SaveCurrentList_Click(object sender, EventArgs e)
 {
     CidListCommand.ReadCurrentListRemote();             // get the current list from server
     MainMenuControl.SetupTempListMenu(SaveCurrentListContextMenu.Items, false, SaveTempListMenuItem_Click);
     SaveCurrentListContextMenu.Show(SaveCurrent, 0, SaveCurrent.Height);
     return;
 }
Esempio n. 2
0
        /// <summary>
        /// Edit given a list name
        /// </summary>
        /// <returns></returns>

        public static CidList Edit(
            string inListName,
            MetaTable rootTable)
        {
            CidList cnList;

            if (Lex.Eq(inListName, "Current"))
            {
                inListName = CidList.CurrentListInternalName;
            }

            if (inListName == "")
            {
                cnList = new CidList();                 // new list
                cnList.UserObject.Name = "New List";
            }

            else
            {
                cnList = CidListCommand.Read(inListName, rootTable);
                if (cnList == null)
                {
                    return(null);                                // doesn't exist
                }
                if (!cnList.UserObject.IsTempObject && MainMenuControl != null)
                {
                    MainMenuControl.UpdateMruList(cnList.UserObject.InternalName);
                }
            }

            cnList = Edit(cnList, rootTable);
            return(cnList);
        }
Esempio n. 3
0
        /// <summary>
        /// If query uses the current list be sure the server has the proper current list
        /// </summary>
        /// <param name="query"></param>

        static void WriteCurrentListToServerIfNeeded(
            Query q)
        {
            if (Lex.Contains(q.KeyCriteria, UserObject.TempFolderName + ".Current"))
            {
                CidListCommand.WriteCurrentList();
            }
        }
Esempio n. 4
0
        private void EditTempList_Click(object sender, EventArgs e)
        {
            if (Lex.IsNullOrEmpty(TempListName.Text))
            {
                MessageBoxMx.ShowError("A temporary list name must be selected first");
                return;
            }

            CidListCommand.EditTemp(TempListName.Text);
        }
Esempio n. 5
0
        private void SavedListMenuItem_Click(object sender, EventArgs e)
        {
            UserObject uo = CidListCommand.SaveTempList("Current");

            if (uo == null)
            {
                return;
            }
            RemoveAddedNodes();             // rebuild the full trees
            Setup();
        }
Esempio n. 6
0
        /// <summary>
        /// Copy a temp list to the current list
        /// </summary>
        /// <returns></returns>

        static string CopyTempToCurrentCommand(
            string tempListName)
        {
            SessionManager.DisplayStatusMessage("Copying List " + tempListName + "...");
            UserObject uo    = new UserObject(UserObjectType.CnList, SS.I.UserName, UserObject.TempFolderName, tempListName);
            UserObject uo2   = new UserObject(UserObjectType.CnList, SS.I.UserName, UserObject.TempFolderName, "Current");
            int        count = CidListDao.CopyList(uo, uo2);

            CidListCommand.UpdateTempListCollection(uo2);
            SessionManager.CurrentResultKeys = ReadCurrentListRemote().ToStringList();             // get from server
            SessionManager.DisplayCurrentCount();
            return("");
        }
Esempio n. 7
0
/// <summary>
/// Show the form
/// </summary>

        public static new void Show()
        {
            if (Instance == null)
            {
                Instance = new ListLogic();
            }
            Instance.Setup();

            CidListCommand.WriteCurrentList();             // be sure current is on the server
            DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm);

            return;
        }
Esempio n. 8
0
        private void InSavedList_Click(object sender, EventArgs e)
        {
            Criteria.Focus();
            UserObject uo = CidListCommand.SelectListDialog("In Saved List");

            if (uo == null)
            {
                return;
            }
            string listName = uo.InternalName;
            string criteria = "In List " + Lex.AddSingleQuotes(listName);

            Instance.InsertCriteria(criteria);
        }
Esempio n. 9
0
        private void Combine_Click(object sender, EventArgs e)
        {
            ListLogicType op;

            MetaTreeNode mtn1 = GetListMetaTreeNode(ListTree1.TreeList.FocusedNode);

            if (mtn1 == null)
            {
                return;
            }

            MetaTreeNode mtn2 = GetListMetaTreeNode(ListTree2.TreeList.FocusedNode);

            if (mtn2 == null)
            {
                return;
            }

            if (ListAnd.Checked)
            {
                op = ListLogicType.Intersect;
            }
            else if (ListOr.Checked)
            {
                op = ListLogicType.Union;
            }
            else
            {
                op = ListLogicType.Difference;
            }
            int count = CidListDao.ExecuteListLogic(mtn1.Target, mtn2.Target, op);

            UserObject  uo = CidListCommand.ReadCurrentListHeader();
            TempCidList tl = CidListCommand.GetTempList("Current");

            if (uo != null && tl != null)
            {
                tl.Count = uo.Count;
                tl.Id    = uo.Id;
            }

            UpdateNode("Current");             // refresh the node to show the new count

            StatusMessage.Caption = count + " " + MetaTable.PrimaryKeyColumnLabel +
                                    "s have passed the combine and have been saved in *Current";

            SessionManager.CurrentResultKeys = CidListCommand.ReadCurrentListRemote().ToStringList();
            SessionManager.DisplayCurrentCount();
            return;
        }
Esempio n. 10
0
        /// <summary>
        /// Copy a saved list to the current list
        /// </summary>
        /// <returns></returns>

        static string CopySavedToCurrentCommand()
        {
            UserObject uo = SelectListDialog("Copy a Saved List to the Current list");

            if (uo == null)
            {
                return("");
            }

            SessionManager.DisplayStatusMessage("Copying List " + uo.Name + "...");
            UserObject uo2   = new UserObject(UserObjectType.CnList, SS.I.UserName, UserObject.TempFolderName, "Current");
            int        count = CidListDao.CopyList(uo, uo2);

            CidListCommand.UpdateTempListCollection(uo2);
            SessionManager.CurrentResultKeys = ReadCurrentListRemote().ToStringList();             // get from server
            SessionManager.DisplayCurrentCount();
            return("");
        }
Esempio n. 11
0
/// <summary>
/// Open the specified query or copy the list
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void GridView_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            StreamReader sr;

            int         r  = e.RowHandle;
            int         c  = e.Column.AbsoluteIndex;
            HistoryItem hi = SS.I.History[r]; // get item allowing for header row

            if (c == 0)                       // open query
            {
                sr = new StreamReader(hi.QueryFileName);
                string queryText = sr.ReadToEnd();
                Query  q         = Query.Deserialize(queryText);
                q.UserObject.Name =                   // append time to name
                                    q.UserObject.Name + " - " + hi.DateTime.ToLongTimeString();
                q.Mode = QueryMode.Build;             // want to be in build mode
                q.UserObject.Content = q.Serialize(); // set content so not prompted for save when closed

                QbUtil.AddQueryAndRender(q, false);
            }

            // Copy list to current list

            sr = new StreamReader(hi.ListFileName);
            string  listText = sr.ReadToEnd();
            CidList cidList  = new CidList(listText);

            CidListCommand.WriteCurrentList(cidList);
            SessionManager.CurrentResultKeys = cidList.ToStringList();
            SessionManager.DisplayCurrentCount();

            if (c == 1)             // return message if just copying list to current
            {
                string msg = "The list has been copied to the current list (" + SessionManager.CurrentResultKeysCount + ")";
                MessageBoxMx.Show(msg);
            }

            HistoryList_Deactivate(null, null);
            return;
        }
Esempio n. 12
0
        /// <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);
        }
Esempio n. 13
0
        /// <summary>
        /// Run the query
        /// </summary>
        /// <param name="browseExistingResults">If true browse existing results</param>
        /// <returns></returns>

        public string RunQuery3(
            ResultsFormat rf,
            bool saveHitlist,
            bool browseExistingResults)
        {
            Query        modifiedQuery;
            QueryTable   qt;
            QueryColumn  qc;
            ResultsTable rt;
            ResultsField rfld;
            MetaTable    mt;
            MetaColumn   mc;
            string       txt, msg;
            DialogResult dr;
            bool         success;
            CellGraphic  cg;
            Lex          lex = new Lex();
            string       tempfile, tok, command, unrecognizedCommand, response;
            int          ti, gi, rc, i1, i2;

            // Begin execution

            if (rf == null)
            {
                throw new Exception("QueryExec.Run - Null ResultsFormat");
            }

            if (ResultsFormatter == null)
            {
                throw new Exception("QueryExec.Run - Null ResultsFormatter");
            }

            if (rf.Segments == null)
            {
                throw new Exception("QueryExec.Run - Null ResultsFormat.Segments");
            }

            if (Query == null)
            {
                throw new Exception("QueryExec.Run - Null Rf.Query");
            }

            if (Query.Tables == null || Query.Tables.Count <= 0)
            {
                throw new QueryException("QueryExec.Run - No Query Tables");
            }

            QueryManager qm = QueryManager;

            ReturnMsg = "";

            //bool useExistingQueryEngine = Rf.ParentQe != null;
            //bool useExistingDataTable = Query.BrowseExistingResultsWhenOpened && Query.SerializeResults &&
            //  qm.DataTable != null && qm.DataTable.Rows.Count > 0;

            try
            {
                //if (Math.Sqrt(4) == 2) throw new Exception("test"); // debug

                if (!browseExistingResults)                 // normal open of search
                {
                    Progress.Show("Analyzing query...");    // put up a status message to the user as soon as possible to let them know something is happening...

                    dr = ValidateQuery(Query);
                    if (dr == DialogResult.Cancel)
                    {
                        return("");
                    }

                    WriteCurrentListToServerIfNeeded(Query);

                    if (rf.OutputDestination == OutputDest.WinForms)                     // update access stats if grid
                    {
                        UpdateTableUsageStatistics(Query);
                    }

                    Query.ResultsDataTable = null;                     // be sure to get new results

                    qm = BuildQueryManager(Query, rf);

                    Query.ResetViewStates();                     // reset state of views for proper operation

                    if (Rf.ParentQe == null)                     // open search unless using existing query engine
                    {
                        if (!ExecuteSearch(saveHitlist))         // returns false if cancelled by user
                        {
                            Progress.Hide();
                            return("");
                        }
                    }

                    if ((ResultsKeys == null || ResultsKeys.Count == 0) &&                      // nothing for search
                        !Query.Preview &&
                        !MqlUtil.SingleStepExecution(Query) &&
                        qm.DataTable.Rows.Count == 0 &&
                        Query.RetrievesDataFromQueryEngine)
                    {
                        // if (!Rf.PopupDisplay)
                        Progress.Hide();
                        if (qm.StatusBarManager != null)
                        {
                            qm.StatusBarManager.DisplayStatusMessage("");
                        }
                        // if (QueryEngine.Cancelled) return ""; // cancelled by user
                        msg = "No data have been found that matches your query.";
                        if (ResultsFormat.PopupOutputFormContext && !ResultsFormat.SuppressNoDataMessage)
                        {
                            MessageBoxMx.Show(msg, "Search Result",
                                              MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return("Command EditQuery");                            // return to edit query menu
                        }
                        else
                        {
                            return(msg);
                        }
                    }

                    //if (ResultsFormat.PopupDisplay)
                    //  SessionManager.DisplayStatusMessage("Retrieving data...");
                    //else Progress.Show("Retrieving data...", UmlautMobius.Value, true, "Cancelling Retrieval...");

                    //Progress.Show("Retrieving data...", UmlautMobius.String, true, "Cancelling Retrieval...");
                    Progress.Hide();                     // hide progress - "Retrieving data..." message now appears as bottom line of grid

                    if (ResultsFormat.Grid)
                    {
                        if (ResultsFormat.SessionOutputFormContext)              // if normal main session form grid display, set browse mode & view state
                        {
                            Query.ResetViewStates();                             // reset view state for all views
                            QbUtil.SetMode(QueryMode.Browse, Query);

                            if (ResultsFormat.Query.LogicType == QueryLogicType.And)                             // log grid query by logic type
                            {
                                UsageDao.LogEvent("QueryGridAnd", "");
                            }
                            else if (ResultsFormat.Query.LogicType == QueryLogicType.Or)
                            {
                                UsageDao.LogEvent("QueryGridOr", "");
                            }
                            else if (ResultsFormat.Query.LogicType == QueryLogicType.Complex)
                            {
                                UsageDao.LogEvent("QueryGridComplex", "");
                            }
                        }

                        else if (ResultsFormat.PopupOutputFormContext)                         // create popup window & configure
                        {
                            PopupResults.Show(qm);
                            //MoleculeGridPanel.ConfigureAndShow(qm, null);
                        }

                        else if (ResultsFormat.ToolOutputFormContext)
                        {
                            ContainerControl    cc;
                            QueryResultsControl qrc = ResultsFormat.OutputContainerControl as QueryResultsControl;
                            AssertMx.IsTrue(qrc != null, "ResultsFormat.OutputContainerControl must be a QueryResultsControl");
                            if (!WindowsHelper.FindContainerControl(qrc, typeof(ToolResultsContainer), out cc))
                            {
                                throw new Exception("ToolResultsContainer not found");
                            }

                            ToolResultsContainer trc = cc as ToolResultsContainer;
                            trc.SetupQueryResultsControlForResultsDisplay(qm);
                        }

                        else
                        {
                            throw new Exception("Invalid OutputformContext: " + ResultsFormat.OutputFormContext);
                        }
                    }
                }

                else                 // reentering display switch to browse tab
                {
                    QbUtil.SetMode(QueryMode.Browse, Query);
                }

                response = ResultsFormatter.BeginFormatting(browseExistingResults); // format the data

                if (ResultsFormat.SessionOutputFormContext)                         // normal display
                {
                    if (MqlUtil.SingleStepExecution(Query))
                    {                     // be sure hit count display is up to date
                        if (ResultsKeys != null)
                        {
                            if (qm.StatusBarManager != null)
                            {
                                qm.StatusBarManager.DisplayCurrentCount();
                            }
                        }
                    }

                    if (saveHitlist)
                    {
                        CidList hitList = new CidList(ResultsKeys);
                        rc = CidListCommand.WriteCurrentList(hitList);
                        SessionManager.DisplayCurrentCount();
                    }
                }

                return(response);
            }             // end of surrounding try

            catch (Exception ex)
            {
                Progress.Hide();
                if (ex is UserQueryException)                 // exception that can occur from user error
                {
                    throw new UserQueryException(ex.Message, ex);
                }

                else
                {
                    msg = DebugLog.FormatExceptionMessage(ex);
                    if (!Lex.Contains(msg, "QueryLogged:"))                     // exception & query
                    {
                        QueryEngine.LogExceptionAndSerializedQuery(msg, Query);
                    }
                    else
                    {
                        ServicesLog.Message(msg);                      // just log exception
                    }
                    throw new Exception(ex.Message, ex);               // pass it up
                }
            }
        }
Esempio n. 14
0
/// <summary>
/// Save/SaveAs the list
/// </summary>
/// <param name="saveAs">SaveAs under another list name</param>
/// <param name="saveAsTempList">Save as a temp list</param>
/// <param name="tempListName">Temp list name to save under, prompt if null</param>
/// <returns></returns>

        bool Save(
            bool saveAs,
            bool saveAsTempList,
            string tempListName)
        {
            if (!ValidateList())
            {
                return(false);                             // Validate the list if requested
            }
// Get list name if needed & check that user can modify it

            if (saveAs || CidList.UserObject.Id == 0)
            {
                CidList.UserObject.Id = 0;                 // assign new id
                if (saveAsTempList)
                {
                    if (tempListName == null)                     // prompt for name
                    {
                        tempListName = CidListCommand.PromptForNewTempListName();
                        if (tempListName == null)
                        {
                            return(false);
                        }
                    }
                    CidList.UserObject = new UserObject(UserObjectType.CnList);
                    CidList.UserObject.ParentFolder = UserObject.TempFolderName;
                    CidList.UserObject.Name         = tempListName;
                    CidList.UserObject.Owner        = SS.I.UserName;
                }

                else                 // save as permanent list
                {
                    UserObject existingUo = CidList.UserObject;
                    if (CidList.UserObject.Id == 0)
                    {
                        existingUo = new UserObject(UserObjectType.CnList);
                    }
                    UserObject listUo = UserObjectSaveDialog.Show("Save As", existingUo);
                    if (listUo == null)
                    {
                        return(false);
                    }
                    CidList.UserObject = listUo;
                }
            }

            if (!UserObjectUtil.UserHasWriteAccess(CidList.UserObject))
            {             // is the user authorized to save this list?
                MessageBoxMx.ShowError("You are not authorized to save this list");
                return(false);
            }

// Write out the list

            DisplayStatusMsg("Saving list...");

            if (CidList.UserObject.HasDefinedParentFolder)
            {
                MetaTreeNode targetFolder = UserObjectTree.GetValidUserObjectTypeFolder(CidList.UserObject);
                if (targetFolder == null)
                {                 // shouldn't happen
                    MessageBoxMx.ShowError("The list could not be saved because the folder it was in no longer exists.  Please try SaveAs instead.");
                    return(false);
                }
            }

            GetNormalizedListFromControl(CidList);

            if (!CidList.UserObject.IsCurrentObject)             // normal list?
            {
                CidListCommand.Write(CidList);
            }

            else                                       // special processing for current list
            {
                SessionManager.LockResultsKeys = true; // avoid possible overwrite of ResultsKeys if in single step query
                int           rc            = CidListCommand.Write(CidList);
                List <string> curListString = CidListCommand.ReadCurrentListLocal().ToStringList();
                SessionManager.CurrentResultKeys = curListString;
                SessionManager.DisplayCurrentCount();
                SessionManager.LockResultsKeys = false;
            }

            //string cFile = SS.I.ClientDefaultDir + @"\Previous.lst"
            //if (UIMisc.CanWriteFileToDefaultDir(cFile))
            //{
            //  StreamWriter sw = new StreamWriter(cFile); // save copy to disk
            //  sw.Write(CidList.UserObject.Content);
            //  sw.Close();
            //}

            int cncnt = CidList.Count;

            DisplayStatusMsg("List saved");

            Before = CidListCtl.Text;
            string tok = UserObjectUtil.GetName(ListName);

            Text = "Edit List - [" + CidList.UserObject.Name + "]";
            return(true);
        }
Esempio n. 15
0
 private void EditCurrent_Click(object sender, EventArgs e)
 {
     CidListCommand.ReadCurrentListRemote();             // get the current list from server
     CidListEditor.Edit("Current");
     return;
 }