Exemple #1
0
        private void CtComplexCriteria_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)             // right button ContextMenu
            {
                Point p = new Point(e.X, e.Y);
                CriteriaComplexRtClickContextMenu.Show(CtComplexCriteria, p);
            }

            else
            {
                if (CriteriaComplex.Edit(Query))
                {
                    LabeledCriteria labeledCriteria = CriteriaEditor.ConvertComplexCriteriaToEditable(Query, false);
                    RichTextBox     coloredCriteria = CriteriaEditor.ColorCodeCriteria(labeledCriteria.Text, Query);
                    CtComplexCriteria.Rtf = coloredCriteria.Rtf;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Convert labeled criteria to complex checking for errors
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="q"></param>
        /// <param name="complexCriteriaCtl"></param>

        public static bool ConvertEditableCriteriaToComplex(
            LabeledCriteria labeledCriteria,
            Query q,
            RichTextBox complexCriteriaCtl)
        {
            QueryTable  qt;
            QueryColumn qc;

            Lex lex = new Lex();

            lex.SetDelimiters(" , ; ( ) < = > <= >= <> != !> !< [ ]");
            lex.OpenString(labeledCriteria.Text);
            StringBuilder   sb      = new StringBuilder();
            PositionedToken lastTok = null;

            List <PositionedToken> tokens = new List <PositionedToken>();           // list of tokens seen

            int parenDepth = 0;

            while (true)
            {
                PositionedToken pTok = lex.GetPositionedToken();
                if (pTok == null)
                {
                    break;
                }

                tokens.Add(pTok);

                if (lastTok != null)
                {                 // include same white space between tokens
                    int wsBeg = lastTok.Position + lastTok.Text.Length;
                    sb.Append(labeledCriteria.Text.Substring(wsBeg, pTok.Position - wsBeg));
                }

                string tok = pTok.Text;

                if (MqlUtil.IsKeyWord(pTok.Text))                 // ok if keyword, operator, etc
                {
                    if (pTok.Text == "(")
                    {
                        parenDepth++;
                    }
                    else if (pTok.Text == ")")
                    {
                        parenDepth--;
                    }
                }

                else if (pTok.Text.StartsWith("'"))                 // string constant
                {
                    if (tokens.Count >= 3 && Lex.Eq(tokens[tokens.Count - 2].Text, "In") &&
                        Lex.Eq(tokens[tokens.Count - 1].Text, "List"))
                    {                     // saved list reference
                        UserObject uo = QueryEngine.ResolveCnListReference(tok);
                        if (uo != null)
                        {
                            tok = "CNLIST_" + uo.Id.ToString();
                        }
                        else
                        {
                            tok = "Nonexistant list";
                        }
                        tok = Lex.AddSingleQuotes(tok);
                    }
                }

                else if (Lex.IsDouble(pTok.Text))
                {
                }                                                     // numeric constant

                else if (tok == "[")
                {                 // translate editable structure reference
                    pTok = lex.GetPositionedToken();
                    if (!MatchToken(pTok, "Edit", complexCriteriaCtl))
                    {
                        return(false);
                    }

                    pTok = lex.GetPositionedToken();
                    if (!MatchToken(pTok, "Structure", complexCriteriaCtl))
                    {
                        return(false);
                    }

                    pTok = lex.GetPositionedToken();
                    tok  = Lex.RemoveSingleQuotes(pTok.Text.ToUpper());
                    if (!labeledCriteria.Structures.ContainsKey(tok))
                    {
                        ConvertLabeledCriteriaError("Structure \"" + pTok.Text + "\" not defined", pTok, complexCriteriaCtl);
                        return(false);
                    }
                    tok = Lex.AddSingleQuotes(labeledCriteria.Structures[tok]);                     // replace with chime

                    pTok = lex.GetPositionedToken();
                    if (!MatchToken(pTok, "]", complexCriteriaCtl))
                    {
                        return(false);
                    }
                }

                else if (Lex.Eq(pTok.Text, "structure_field"))
                {                 // check for user failing to define structure_field in structure search criteria
                    ConvertLabeledCriteriaError("\"Structure_field\" must be replaced with a real field name", pTok, complexCriteriaCtl);
                    return(false);
                }

                else              // must be a column reference or invalid token
                {                 // translate labeled column name
                    tok = TranslateLabeledColumnName(pTok, q, complexCriteriaCtl);
                    if (tok == null)
                    {
                        return(false);
                    }
                }

                sb.Append(tok);
                lastTok = pTok;
            }

            tokens = tokens;             // debug

            if (parenDepth != 0)         // parens balance?
            {
                if (parenDepth > 0)
                {
                    MessageBoxMx.ShowError("Unbalanced parentheses: left parentheses exceed right by " + parenDepth.ToString());
                }

                else
                {
                    MessageBoxMx.ShowError("Unbalanced parentheses: right parentheses exceed left by " + (-parenDepth).ToString());
                }

                if (complexCriteriaCtl != null)
                {
                    complexCriteriaCtl.Focus();
                }
                return(false);
            }

            q.ComplexCriteria = sb.ToString();             // store back in query
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Convert complex criteria to labeled form suitable for editing in complex criteria editor
        /// </summary>
        /// <param name="q"></param>
        /// <param name="structures">Dictionary of structure names & connection tables</param>

        public static LabeledCriteria ConvertComplexCriteriaToEditable(
            Query q,
            bool includeEditButtons)
        {
            bool insertBreaks = false;

            if (q.ComplexCriteria.IndexOf("\n") < 0)
            {
                insertBreaks = true;
            }

            Dictionary <string, string> tAliasMap = GetAliasMap(q);

            if (tAliasMap != null && !includeEditButtons)
            {             // fixup aliases properly first using editable criteria
                ConvertComplexCriteriaToEditable(q, true);
                tAliasMap = null;
            }

            Lex lex = new Lex();

            lex.SetDelimiters(" , ; ( ) < = > <= >= <> != !> !<");
            string criteria = q.ComplexCriteria;

            lex.OpenString(criteria);
            StringBuilder   sb      = new StringBuilder();
            PositionedToken lastTok = null;

            List <PositionedToken> tokens = new List <PositionedToken>();           // list of tokens seen

            LabeledCriteria lc = new LabeledCriteria();

            lc.Structures = new Dictionary <string, string>();

            while (true)
            {
                PositionedToken tok = lex.GetPositionedToken();
                if (tok == null)
                {
                    break;
                }

                tokens.Add(tok);

                if (lastTok != null)
                {                 // include same white space between tokens
                    int wsBeg = lastTok.Position + lastTok.Text.Length;
                    sb.Append(criteria.Substring(wsBeg, tok.Position - wsBeg));
                }

                QueryColumn qc = MqlUtil.GetQueryColumn(tok.Text, q); // see if token is column ref
                if (qc != null)
                {                                                     //query column, map to labeled columns
                    string label = GetUniqueColumnLabel(qc);

                    QueryTable qt = qc.QueryTable;
                    string     tName, cName;
                    MqlUtil.ParseColumnIdentifier(tok.Text, out tName, out cName);
                    if (tName != null && tName != "")                     // any table name supplied?
                    {
                        if (tAliasMap != null && tAliasMap.ContainsKey(tName.ToUpper()))
                        {
                            tName = tAliasMap[tName.ToUpper()];
                        }
                        label = tName + "." + label;
                    }

                    sb.Append(Lex.Dq(label));
                }

                else
                {                 // not a query column reference
                    string tokText = tok.Text;

                    string txt = Lex.RemoveSingleQuotes(tokText).ToUpper();
                    if (UserObject.IsCompoundIdListName(txt))
                    {
                        string     listName = null;
                        int        objectId = int.Parse(txt.Substring(7));
                        UserObject uo       = UserObjectDao.ReadHeader(objectId);
                        if (uo != null)
                        {
                            listName = uo.InternalName;
                        }
                        else
                        {
                            listName = "Unknown";
                        }
                        tokText = Lex.AddSingleQuotes(listName);
                    }

                    if (tokens.Count >= 5)
                    {                     // see if this is a chime string
                        string sFuncCand = tokens[tokens.Count - 5].Text.ToLower();
                        if ((Lex.Eq(sFuncCand, "SSS") || Lex.Eq(sFuncCand, "FSS") || Lex.Eq(sFuncCand, "MolSim")) &&
                            tokText.StartsWith("'") && tokText.EndsWith("'"))                             // single-quoted chime?
                        {
                            string sAlias = "S" + (lc.Structures.Count + 1).ToString();
                            lc.Structures[sAlias] = Lex.RemoveSingleQuotes(tokText);                             // save structure in dictionary
                            if (includeEditButtons)
                            {
                                tokText = "[Edit Structure " + sAlias + "]";                                 // use alias in labeled query
                            }
                            else
                            {
                                tokText = Lex.AddSingleQuotes(sAlias);
                            }
                        }
                    }

                    if ((Lex.Eq(tokText, "And") || Lex.Eq(tokText, "Or")) &&
                        tokens.Count >= 3 && !Lex.Eq(tokens[tokens.Count - 3].Text, "Between") &&
                        insertBreaks)
                    {
                        sb.Append("\n");                    // start new line for each and/or
                    }
                    sb.Append(tokText);                     // not query column identifier
                }

                lastTok = tok;
            }

            sb.Append(" ");             // include final space so additional text is black, also to get correct font
            lc.Text = sb.ToString();

            // If a table alias changes then update aliases & complex criteria but only if going
            // to editable text since ConvertEditableCriteriaToComplex fails otherwise.

            if (tAliasMap != null)
            {
                for (int qti = 0; qti < q.Tables.Count; qti++)
                {                 // set new table aliases
                    QueryTable qt    = q.Tables[qti];
                    string     alias = "T" + (qti + 1).ToString();
                    qt.Alias = alias;
                }

                ConvertEditableCriteriaToComplex(lc, q, null);                 // update q.ComplexCriteria also
            }

            return(lc);
        }
Exemple #4
0
        internal void Render()
        {
            Query q             = Query;
            int   criteriaCount = 0;

            if (q == null || q.Tables.Count <= 0)
            {
                return;
            }
            //if (q.Tables.Count <= 0 || !SS.I.ShowCriteriaTab) return;

            Rendering = true;
            Clear();
            CriteriaTabYPos = 0;

            bool shownKeyCriteria = false;
            int  summarizable = 0, summarized = 0;

            for (int ti = 0; ti < q.Tables.Count; ti++)
            {
                QueryTable qt = q.Tables[ti];
                string     txt;
                bool       shownTableLabel = false;

                if (qt.MetaTable.SummarizedExists)
                {
                    summarizable++;
                }
                if (qt.MetaTable.UseSummarizedData)
                {
                    summarized++;
                }

                if (q.LogicType == QueryLogicType.Complex)
                {
                    continue;                     // if complex logic don't show simple criteria
                }
                if (qt.MetaTable.IgnoreCriteria)
                {
                    continue;                     // skip if criteria should be ignored
                }
                foreach (QueryColumn qc in qt.QueryColumns)
                {
                    if (qc.IsKey)
                    {
                        if (shownKeyCriteria)
                        {
                            continue;                                           // skip if already shown
                        }
                        shownKeyCriteria = true;
                    }

                    else if (qc.Criteria == "" && !qc.ShowOnCriteriaForm)
                    {
                        continue;
                    }

                    if (qc.MetaColumn.IsDatabaseSetColumn)
                    {
                        continue;                                                        // don't show db list
                    }
                    if (!shownTableLabel)
                    {
                        shownTableLabel = true;
                        if (!qt.MetaTable.IsRootTable || ti > 0)
                        {
                            AddCriteriaTabTableLabel(qt);
                        }
                    }

                    if (qc.MetaColumn.DataType == MetaColumnType.Structure)
                    {
                        AddCriteriaTabStructureItem(qc);
                        criteriaCount++;
                    }

                    else                     // other column types
                    {
                        if (qc.IsKey)
                        {
                            txt = q.KeyCriteriaDisplay;
                        }

                        else
                        {
                            txt = qc.CriteriaDisplay;
                            if (txt != "")
                            {
                                if (qc.FilterSearch && !qc.FilterRetrieval)
                                {
                                    txt += " (Search only)";
                                }
                                else if (!qc.FilterSearch && qc.FilterRetrieval)
                                {
                                    txt += " (Retrieve only)";
                                }
                                else if (!qc.FilterSearch && !qc.FilterRetrieval)
                                {
                                    txt += " (Disabled)";
                                }
                            }
                        }

                        AddCriteriaTabItem(qc, txt);
                        if (qc.IsKey)
                        {
                            criteriaCount++;
                        }
                    }
                }
            }

            if (q.LogicType == QueryLogicType.Complex)
            {             // convert & show complex logic
                AddComplexCriteriaPanel();
                LabeledCriteria labeledCriteria = CriteriaEditor.ConvertComplexCriteriaToEditable(q, false);
                RichTextBox     coloredCriteria = CriteriaEditor.ColorCodeCriteria(labeledCriteria.Text, q);
                CtComplexCriteria.Rtf = coloredCriteria.Rtf;

                MenuComplexApplyCriteriaToRetrieval.Checked = q.FilterResults;
            }

            AddCriteriaLogicPanel(q.LogicType);                      // add criteria type panel
            AddQueryDescription(q.UserObject.Description.TrimEnd()); // add description panel
            Rendering = false;
            return;
        }