示例#1
0
/// Edit criteria for a query column
/// </summary>
/// <param name="qc"></param>
/// <returns>True if criteria has been successfully edited</returns>

        public static bool EditCriteria(
            QueryColumn qc)
        {
            MetaColumn mc    = qc.MetaColumn;
            Query      Query = qc.QueryTable.Query;
            bool       sameQ = Query == QueriesControl.Instance.CurrentQuery;       // debug

            if (Lex.Contains(qc.MetaColumn.ColumnMap, ToolUtil.ToolParametersColumnMapValue))
            {
                DialogResult dr = ToolHelper.InvokeToolCriteriaEditor(qc);
                return(dr == DialogResult.OK);
            }

            try
            {
                if (!mc.IsSearchable)
                {
                    MessageBoxMx.ShowError("The " + qc.ActiveLabel + " data item is not currently searchable.");
                    return(false);
                }

                if (mc.IsKey)                              // edit key criteria
                {
                    qc.CopyCriteriaFromQueryKeyCriteria(); // be sure qc is in sync with Query.KeyCriteria
                    if (!CriteriaCompoundId.Edit(qc))
                    {
                        return(false);
                    }

                    qc.CopyCriteriaToQueryKeyCritera();                     // update Query.KeyCriteria
                    return(true);
                }

                switch (mc.DataType)
                {
                // Compound Number criteria

                case MetaColumnType.CompoundId:

                    if (!CriteriaCompoundId.Edit(qc))
                    {
                        return(false);
                    }
                    else
                    {
                        break;
                    }

                // Structure criteria

                case MetaColumnType.Structure:
                    if (!CriteriaStructure.Edit(qc))
                    {
                        return(false);
                    }
                    break;

                // Mol. formula criteria

                case MetaColumnType.MolFormula:
                    if (!CriteriaMolFormula.Edit(qc))
                    {
                        return(false);
                    }
                    break;


                // General criteria

                case MetaColumnType.Integer:
                case MetaColumnType.Number:
                case MetaColumnType.QualifiedNo:
                case MetaColumnType.String:
                case MetaColumnType.Date:
                case MetaColumnType.DictionaryId:

                    if (!CriteriaDialog.Edit(qc))
                    {
                        return(false);
                    }
                    else
                    {
                        break;
                    }

                default:
                    MessageBoxMx.ShowError("The " + qc.ActiveLabel + " data item is not currently searchable.");
                    return(false);
                }

                return(true);
            }

            catch (Exception ex)
            {
                string msg = "Unexpected error editing criteria: \r\n\r\n" +
                             DebugLog.FormatExceptionMessage(ex);
                ServicesLog.Message(msg);
                MessageBoxMx.ShowError(msg);
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Invoke the editor
        /// </summary>
        /// <param name="qc">QueryColumn to edit</param>
        /// <returns></returns>

        public static bool Edit(
            QueryColumn qc)
        {
            ParsedSingleCriteria psc;

            if (qc.MetaColumn.DictionaryMultipleSelect)
            {
                return(CriteriaDictMultSelect.Edit(qc));
            }

            if (Instance == null)
            {
                Instance = new CriteriaMolFormula();
            }

            if (qc.Criteria != "")
            {
                psc = MqlUtil.ParseQueryColumnCriteria(qc);
            }

            else
            {
                psc        = new ParsedSingleCriteria();
                psc.OpEnum = CompareOp.FormulaEqual;
            }

            Instance.Formula.Text = psc.Value;
            if (psc.OpEnum == CompareOp.FormulaEqual)
            {
                Instance.ExactMF.Checked = true;
            }
            else
            {
                Instance.PartialMF.Checked = true;
            }

            DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm);

            if (dr == DialogResult.Cancel)
            {
                return(false);
            }

            string val = Instance.Formula.Text.Trim();

            if (val == "")             // no criteria
            {
                qc.Criteria = qc.CriteriaDisplay = "";
                return(true);
            }

            if (Instance.ExactMF.Checked)
            {
                qc.Criteria        = qc.MetaColumn.Name + " fmla_eq " + Lex.AddSingleQuotes(val);;
                qc.CriteriaDisplay = "= " + val;
            }

            else
            {
                qc.Criteria        = qc.MetaColumn.Name + " fmla_like " + Lex.AddSingleQuotes(val);
                qc.CriteriaDisplay = "like " + val;
            }

            return(true);
        }