/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ private FilterExpression GetExpressionFromRow(DataGridViewRow row) { FilterExpression expression = new FilterExpression(); string fieldName = row.Cells[kFieldCol].Value as string; if (fieldName != FilterExpression.OtherFilterField) { PaFieldInfo fieldInfo = PaApp.FieldInfo.GetFieldFromDisplayText(fieldName); if (fieldInfo != null) { fieldName = fieldInfo.FieldName; } } expression.FieldName = fieldName; expression.Operator = m_textToOperator[row.Cells[kOpCol].Value as string]; expression.Pattern = row.Cells[kValueCol].Value as string; expression.ExpressionType = m_textToExpType[row.Cells[kTypeCol].Value as string]; if (expression.ExpressionType == ExpressionType.PhoneticSrchPtrn) { SearchQuery query = row.Cells[kTypeCol].Tag as SearchQuery; expression.SearchQuery = (query == null ? new SearchQuery() : query); expression.SearchQuery.Pattern = expression.Pattern; } return(expression); }
///// ------------------------------------------------------------------------------------ ///// <summary> ///// ///// </summary> ///// ------------------------------------------------------------------------------------ //protected bool OnAfterLoadingDataSources(object args) //{ // PaProject project = args as PaProject; // if (project != null && project.DataSources != null && project.DataSources.Count > 0) // { // // Go through all the data sources and if any one is not an SA data source, then // // do not bother fixing up the project so it treats references specially for SA // // data sources. // bool fixRefs = true; // foreach (PaDataSource source in project.DataSources) // { // if (source.DataSourceType != DataSourceType.SA) // { // fixRefs = false; // break; // } // } // if (fixRefs) // FixReferenceForSAProject(project); // } // return false; //} /// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ private void FixReferenceForSAProject(PaProject project) { PaFieldInfo refFieldInfo = project.FieldInfo.ReferenceField; if (!refFieldInfo.IsParsed || refFieldInfo.SaFieldName != "Reference") { refFieldInfo.IsParsed = true; refFieldInfo.SaFieldName = "Reference"; project.FieldInfo.Save(project); project.ReloadDataSources(); } // Setting the parse type for each of the SA data sources has no bearing on how // the data is parsed, but it is a back-handed way of keeping the PaWordListGrid // from displaying all the reference fields for a transcription for those entries // that don't have a reference specified. foreach (PaDataSource source in project.DataSources) { source.ParseType = DataSourceParseType.OneToOne; } FixedAudioDocReader reader = new FixedAudioDocReader(); foreach (RecordCacheEntry recEntry in PaApp.RecordCache) { if (recEntry.DataSource.DataSourceType == DataSourceType.SA) { reader.Read(recEntry); } } PaApp.RecordCache.BuildWordCache(null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public SFMarkerMapping(PaFieldInfo fieldInfo) { m_fieldInfo = fieldInfo; if (m_fieldInfo != null) { m_fieldName = m_fieldInfo.FieldName; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ private void m_grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 2) { string fieldName = m_grid[kFieldCol, e.RowIndex].Value as string; PaFieldInfo fieldInfo = PaApp.FieldInfo[fieldName]; e.CellStyle.Font = (fieldInfo != null ? fieldInfo.Font : FontHelper.UIFont); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Checks the specified mapping list for the specified PA field. If a mapping for the /// field cannot be found, then one is created and added to the specified mappings /// list. /// </summary> /// ------------------------------------------------------------------------------------ public static SFMarkerMapping VerifyMappingForField(List <SFMarkerMapping> mappingList, PaFieldInfo fieldInfo) { foreach (SFMarkerMapping mapping in mappingList) { if (mapping.FieldName == fieldInfo.FieldName) { return(null); } } // At this point, we know we didn't find the mapping SFMarkerMapping newMapping = new SFMarkerMapping(fieldInfo); mappingList.Add(newMapping); return(newMapping); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ internal void Show(DataGridViewCell cell, string field) { PaFieldInfo fieldInfo = PaApp.FieldInfo[field]; if (fieldInfo == null) { return; } Items.Clear(); Font = fieldInfo.Font; SortedDictionary <string, bool> list = new SortedDictionary <string, bool>(); foreach (WordCacheEntry entry in PaApp.WordCache) { string val = entry[field]; if (!string.IsNullOrEmpty(val)) { list[val] = true; } } // Make sure to include values that are filtered out. foreach (WordCacheEntry entry in FilterHelper.UnusedWordsCache) { string val = entry[field]; if (!string.IsNullOrEmpty(val)) { list[val] = true; } } string cellValue = cell.Value as string; foreach (string val in list.Keys) { Items.Add(val); if (cellValue == val) { SelectedIndex = Items.Count - 1; } } if (SelectedIndex < 0 && list.Count > 0) { SelectedIndex = 0; } m_cell = cell; int col = cell.ColumnIndex; int row = cell.RowIndex; IntegralHeight = (list.Count > 0); Width = Math.Max(150, cell.DataGridView.Columns[col].Width); Height = (list.Count == 0 ? 18 : (Math.Min(Items.Count, 15) * Font.Height) + 4); Rectangle rc = cell.DataGridView.GetCellDisplayRectangle(col, row, false); rc.Y += rc.Height; m_dropDown.Show(cell.DataGridView.PointToScreen(rc.Location)); Focus(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public bool Matches(WordCacheEntry entry) { // If this expression is to match the entry against a filter, then find // the filter and return whether or not the entry matches the filter. if (m_fieldName == OtherFilterField) { return(MatchesFilter(entry)); } if (m_expTypep == ExpressionType.PhoneticSrchPtrn) { return(MatchesSearchPattern(entry)); } if (!m_fieldTypeDetermined) { PaFieldInfo fieldInfo = PaApp.FieldInfo[m_fieldName]; if (fieldInfo != null) { m_fieldIsDate = fieldInfo.IsDate; m_fieldIsNumeric = fieldInfo.IsNumeric || fieldInfo.IsAudioLength || fieldInfo.IsAudioOffset; m_fieldTypeDetermined = true; } } string entryValue = (entry[m_fieldName] ?? string.Empty); if (m_expTypep == ExpressionType.RegExp) { return(Regex.IsMatch(entryValue, m_pattern)); } if (m_fieldIsNumeric || m_operator == FilterOperator.GreaterThan || m_operator == FilterOperator.GreaterThanOrEqual || m_operator == FilterOperator.LessThan || m_operator == FilterOperator.LessThanOrEqual) { return(MatchesNumeric(entryValue)); } if (m_fieldIsDate) { return(MatchesDate(entryValue)); } switch (m_operator) { case FilterOperator.Matches: case FilterOperator.Equals: return(entryValue.Equals(m_pattern, StringComparison.InvariantCulture)); case FilterOperator.NotEquals: return(!entryValue.Equals(m_pattern, StringComparison.InvariantCulture)); case FilterOperator.Contains: return(entryValue.Contains(m_pattern)); case FilterOperator.DoesNotContain: return(!entryValue.Contains(m_pattern)); case FilterOperator.BeginsWith: return(entryValue.StartsWith(m_pattern, StringComparison.InvariantCulture)); case FilterOperator.EndsWith: return(entryValue.EndsWith(m_pattern, StringComparison.InvariantCulture)); case FilterOperator.DoesNotBeginsWith: return(!entryValue.StartsWith(m_pattern, StringComparison.InvariantCulture)); case FilterOperator.DoesNotEndsWith: return(!entryValue.EndsWith(m_pattern, StringComparison.InvariantCulture)); case FilterOperator.PathExists: return(File.Exists(entryValue)); case FilterOperator.PathDoesNotExist: return(!File.Exists(entryValue)); case FilterOperator.GreaterThan: case FilterOperator.GreaterThanOrEqual: case FilterOperator.LessThan: case FilterOperator.LessThanOrEqual: return(MatchesNumeric(entryValue)); default: break; } return(false); }