/// <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; }
/// <summary> /// Setup the options from psc /// </summary> /// <param name="psc"></param> public void Setup( SmallWorldPredefinedParameters swpArg) { try { InSetup = true; bool t = true, f = false; Swp = swpArg; // save reference to parameters if (SwDbDict == null) { SwDbDict = DictionaryMx.Get("SmallWorldDatabases"); if (SwDbDict != null) { UIMisc.SetListControlItemsFromDictionary(DatabaseComboBox.Properties.Items, SwDbDict.Name, true); } GetDefaultSmallWorldOptions(); // also get any default options for user } if (Swp == null) // get initial option values { SmallWorldPredefinedParameters swp = FindStandardPresetMatchingCustomSettings(); if (swp == null) // if no match then use my preferred { swp = CustomSettings; } if (swp.MaxHits <= 0) // be sure maxhits is defined { swp.MaxHits = SmallWorldPredefinedParameters.DefaultMaxHits; } Swp = swp.Clone(); // make copy } List <string> dbList = GetDbSetList(); string dbs = ""; foreach (string dbName in dbList) { if (SwDbDict.LookupDefinition(dbName) == null) { continue; } if (dbs != "") { dbs += ", "; } dbs += dbName; } Swp.Database = dbs; if (Lex.IsUndefined(Swp.Database)) // default to first entry in dict { Swp.Database = SwDbDict.Words[0]; // assign first database as default if not defined } DatabaseComboBox.Text = Swp.Database; PresetsComboBox.Text = Swp.PresetName; CriteriaStructureRangeCtl.SetRange(DistanceRange, "", DistanceRangeLabel, null, Swp.Distance); if (Swp.MaxHits < 0) { MaxHits.Text = ""; } else { MaxHits.Text = Swp.MaxHits.ToString(); } // Set the Defined and Enabled attributes for each range based on search type Swp.TerminalUp.Enabled = Swp.TerminalDown.Enabled = true; Swp.RingUp.Enabled = Swp.RingDown.Enabled = true; Swp.LinkerUp.Enabled = Swp.LinkerDown.Enabled = true; Swp.MutationMinor.Enabled = Swp.MutationMajor.Enabled = true; Swp.SubstitutionRange.Enabled = Swp.HybridisationChange.Enabled = true; if (Lex.Eq(Swp.PresetName, SmallWorld.PresetName) || Lex.Eq(Swp.PresetName, CustomSettings.PresetName)) { ; } else if (Lex.Eq(Swp.PresetName, Substructure.PresetName)) { Swp.TerminalDown.Enabled = false; Swp.RingDown.Enabled = false; Swp.LinkerDown.Enabled = false; Swp.MutationMinor.Enabled = Swp.MutationMajor.Enabled = false; } else if (Lex.Eq(Swp.PresetName, SuperStructure.PresetName)) { Swp.TerminalUp.Enabled = false; Swp.RingUp.Enabled = false; Swp.LinkerUp.Enabled = false; Swp.MutationMinor.Enabled = Swp.MutationMajor.Enabled = false; } else if (Lex.Eq(Swp.PresetName, BemisMurckoFramework.PresetName)) { Swp.RingUp.Enabled = Swp.RingDown.Enabled = false; Swp.LinkerUp.Enabled = Swp.LinkerDown.Enabled = false; } else if (Lex.Eq(Swp.PresetName, NqMCS.PresetName)) { Swp.LinkerUp.Enabled = Swp.LinkerDown.Enabled = false; Swp.MutationMinor.Enabled = Swp.MutationMajor.Enabled = false; } else if (Lex.Eq(Swp.PresetName, ElementGraph.PresetName)) { Swp.TerminalUp.Enabled = Swp.TerminalDown.Enabled = false; Swp.RingUp.Enabled = Swp.RingDown.Enabled = false; Swp.LinkerUp.Enabled = Swp.LinkerDown.Enabled = false; Swp.MutationMinor.Enabled = Swp.MutationMajor.Enabled = false; } MatchAtomTypes.Checked = Swp.MatchAtomTypes; bool e = Swp.MatchAtomTypes; Swp.LinkerUp.Active = Swp.LinkerDown.Active = !e; Swp.MutationMinor.Active = Swp.MutationMajor.Active = e; Swp.SubstitutionRange.Active = Swp.HybridisationChange.Active = e; // Set the range controls TerminalRangeUp.Set(Swp.TerminalUp); TerminalRangeDown.Set(Swp.TerminalDown); RingRangeUp.Set(Swp.RingUp); RingRangeDown.Set(Swp.RingDown); LinkerRangeUp.Set(Swp.LinkerUp); LinkerRangeDown.Set(Swp.LinkerDown); MutationRangeMinor.Set(Swp.MutationMinor); MutationRangeMajor.Set(Swp.MutationMajor); SubstitutionRange.Set(Swp.SubstitutionRange); HybridizationRange.Set(Swp.HybridisationChange); ShowColors.Checked = Swp.Highlight; SetControlBackgroundColors(ShowColors.Checked); AlignStructs.Checked = Swp.Align; } finally { InSetup = false; } return; }