/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the filter so it can check for matches. This must be called once before /// calling <see cref="MatchesCriteria"/>. /// </summary> /// ------------------------------------------------------------------------------------ public void InitCriteria() { lock (SyncRoot) { m_filteredFieldTypes.Clear(); m_filteredFlids.Clear(); m_cells.Clear(); // Get the filter's essential details string[] columns = ColumnInfo.Split('|'); ICmRow row = RowsOS[0]; for (int i = 0; i < row.CellsOS.Count; i++) { string[] columnInfo = columns[i].Split(new char[] { ',' }, 2); m_filteredFlids.Add(Int32.Parse(columnInfo[1])); m_filteredFieldTypes.Add((CellarPropertyType)m_cache.MetaDataCache.GetFieldType(m_filteredFlids[i])); ICmCell tempCell = row.CellsOS[i]; m_cells.Add(tempCell); // Determine the field value this filter wants to match switch (m_filteredFieldTypes[i]) { case CellarPropertyType.Integer: // ENHANCE: Someday handle prompting user Debug.Assert(ShowPrompt == 0, "Can't prompt for int values yet."); tempCell.ParseIntegerMatchCriteria(); break; case CellarPropertyType.ReferenceAtomic: case CellarPropertyType.ReferenceSequence: case CellarPropertyType.ReferenceCollection: InitReferenceCriteria(tempCell, m_filteredFlids[i]); break; default: throw new Exception("Attempt to filter on unexpected type of field."); } } } }
public void ParseIntegerMatchCriteria_Equality() { // Set the matching criteria for this filter cell m_cell.Contents = TsStringUtils.MakeString("= 0", Cache.DefaultUserWs); m_cell.ParseIntegerMatchCriteria(); Assert.AreEqual(ComparisonTypes.kEquals, m_cell.ComparisonType); Assert.AreEqual(0, m_cell.MatchValue); // repeat test with a different value m_cell.Contents = TsStringUtils.MakeString("= 1", Cache.DefaultUserWs); m_cell.ParseIntegerMatchCriteria(); Assert.AreEqual(ComparisonTypes.kEquals, m_cell.ComparisonType); Assert.AreEqual(1, m_cell.MatchValue); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes the form's controls from the settings in the filter. /// </summary> /// ------------------------------------------------------------------------------------ private void InitializeFromFilter() { if (m_filter == null || m_filter.RowsOS.Count == 0 || m_filter.RowsOS[0].CellsOS.Count == 0) { return; } // Get the pairs of class ids and flids. string[] pairs = m_filter.ColumnInfo.Split('|'); Debug.Assert(m_filter.RowsOS[0].CellsOS.Count == pairs.Length); for (int i = 0; i < pairs.Length; i++) { ICmCell cell = m_filter.RowsOS[0].CellsOS[i]; // Get the flid for this cell. string[] pair = pairs[i].Split(','); int flid = 0; int.TryParse(pair[1], out flid); switch (flid) { case ScrScriptureNoteTags.kflidResolutionStatus: chkStatus.Checked = true; cell.ParseIntegerMatchCriteria(); rbResolved.Checked = (cell.MatchValue == 1); rbUnresolved.Checked = (cell.MatchValue == 0); break; case CmAnnotationTags.kflidAnnotationType: chkType.Checked = true; cell.ParseObjectMatchCriteria(); Guid guid = TsStringUtils.GetGuidFromRun(cell.Contents, 1); rbConsultant.Checked = (guid == CmAnnotationDefnTags.kguidAnnConsultantNote); rbTranslator.Checked = (guid == CmAnnotationDefnTags.kguidAnnTranslatorNote); break; case CmBaseAnnotationTags.kflidBeginRef: chkScrRange.Checked = true; cell.ParseIntegerMatchCriteria(); ScrReference scrRef = new ScrReference(cell.MatchValue, m_scr.Versification); // If the reference was adjusted to 0:0 to include notes in the title and // introduction, adjust it back to 1:1 so we don't confuse the user. if (scrRef.Chapter == 0) { scrRef.Chapter = 1; } if (scrRef.Verse == 0) { scrRef.Verse = 1; } if (cell.ComparisonType == ComparisonTypes.kGreaterThanEqual) { scrBookFrom.ScReference = scrRef; } else { scrBookTo.ScReference = scrRef; } break; } } }