Beispiel #1
0
/// <summary>
/// Setup the form with existing criteria
/// </summary>
/// <param name="qc"></param>

        void Setup(
            QueryColumn qc)
        {
            string    op, tok, val;
            CheckEdit option    = null;
            CheckEdit subOption = null;
            int       i1;

            MetaColumn mc = qc.MetaColumn;

            string prompt = "Select the search criteria that you want to apply to " + qc.ActiveLabel +
                            " from the list below and enter the limiting value(s).";

            bool removeDuplicates = mc.IgnoreCase;                                                             // remove dups if ignoring case

            UIMisc.SetListControlItemsFromDictionary(Value.Properties.Items, mc.Dictionary, removeDuplicates); // setup dropdown

            switch (mc.DataType)
            {
            case MetaColumnType.Integer:
            case MetaColumnType.Number:
            case MetaColumnType.QualifiedNo:
                Setup(true, true, false, false);
                break;

            case MetaColumnType.String:
                Setup(true, true, true, false);
                break;

            case MetaColumnType.Date:
                prompt += " Dates can be entered in the common standard ways: e.g. 12/31/2004 or 31-Dec-04.";
                Setup(true, true, false, true);
                break;

            case MetaColumnType.DictionaryId:
                Setup(false, false, false, false);
                break;
            }

            // Fill in the form with the current criteria

            Instance.Text        = "Search Criteria for " + qc.ActiveLabel;
            Instance.Prompt.Text = prompt;

            ParsedSingleCriteria psc = MqlUtil.ParseSingleCriteria(qc.Criteria);

            if (psc == null)
            {             // create default values
                psc    = new ParsedSingleCriteria();
                psc.Op = "=";
            }

            if (mc.DataType == MetaColumnType.Date && psc.OpEnum != CompareOp.Within)             // format dates for user if not within clause
            {
                if (psc.Value != "")
                {
                    psc.Value = DateTimeMx.Format(psc.Value);
                }
                if (psc.Value2 != "")
                {
                    psc.Value2 = DateTimeMx.Format(psc.Value2);
                }
                if (psc.ValueList != null)
                {
                    for (i1 = 0; i1 < psc.ValueList.Count; i1++)
                    {
                        tok = (string)psc.ValueList[i1];
                        if (tok != null && tok != "")
                        {
                            psc.ValueList[i1] = DateTimeMx.Format(tok);
                        }
                    }
                }
            }

            else if (mc.DataType == MetaColumnType.DictionaryId && psc.Value != "")
            {             // transform database value to dictionary value
                val = DictionaryMx.LookupWordByDefinition(mc.Dictionary, psc.Value);
                if (val != null && val != "")
                {
                    psc.Value = val;
                }
            }

            op = psc.Op;

            // Fill fields based on criteria types

            if (op == "" || op.IndexOf("=") >= 0 || op.IndexOf("<") >= 0 || op.IndexOf(">") >= 0)
            {
                option = BasicOp;
                if (op == "=" || op == "")
                {
                    BasicOpBut.Text = "Equals";
                }
                else if (op == "<")
                {
                    BasicOpBut.Text = "<";
                }
                else if (op == "<=")
                {
                    BasicOpBut.Text = UnicodeString.LessOrEqual;
                }
                else if (op == "<>")
                {
                    BasicOpBut.Text = UnicodeString.NotEqual;
                }
                else if (op == ">")
                {
                    BasicOpBut.Text = ">";
                }
                else if (op == ">=")
                {
                    BasicOpBut.Text = UnicodeString.GreaterOrEqual;
                }

                Value.Text = psc.Value;                 // put in current value
            }

            else if (Lex.Eq(op, "Between"))
            {
                option      = Between;
                Limit1.Text = psc.Value;
                Limit2.Text = psc.Value2;
            }

            else if (Lex.Eq(op, "In"))
            {
                option = InList;
                StringBuilder sb = new StringBuilder();
                for (i1 = 0; i1 < psc.ValueList.Count; i1++)
                {
                    if (i1 > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append((string)psc.ValueList[i1]);
                }
                ValueList.Text = sb.ToString();                 // set value
            }

            else if (Lex.Eq(op, "Like"))
            {
                option         = Like;
                tok            = psc.Value.Replace("%", "");      // remove sql wildcard characters
                Substring.Text = tok;
            }

            else if (Lex.Eq(op, "Within"))
            {
                option           = Within;
                WithinValue.Text = psc.Value;

                string value2 = psc.Value2;

                if (Lex.Contains(value2, "Day"))                 // translate alternative values
                {
                    value2 = "Day(s)";
                }
                else if (Lex.Contains(value2, "Week"))
                {
                    value2 = "Week(s)";
                }
                else if (Lex.Contains(value2, "Month"))
                {
                    value2 = "Month(s)";
                }
                else if (Lex.Contains(value2, "Year"))
                {
                    value2 = "Year(s)";
                }

                WithinUnits.Text = value2;
            }

            else if (Lex.Eq(op, "is not null"))
            {
                option = IsNotNull;
            }

            else if (Lex.Eq(op, "is null"))
            {
                option = IsNull;
            }

            else if (Lex.Eq(op, "is not null or is null"))
            {
                option = All;
            }

            else             // oops
            {
                MessageBoxMx.ShowError("Unrecognized criteria type");
                qc.Criteria = qc.CriteriaDisplay = "";
                return;
            }

            option.Checked = true;

            return;
        }