private void Filter_Changed(object newValue) { // Update the effective filter. If the filter is provided as content, the content filter will be recreated when needed. _activeFilter = newValue as IContentFilter; // Notify the filter to update the view. FilterHost?.OnFilterChanged(); }
/// <summary> /// Perform filter initialitazion and raises the FilterInitializing event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param> /// <remarks> /// When this <i>column filter</i> control is added to the <i>column filters</i> array of the <i>filter manager</i>, /// the latter calls the <see cref="DgvBaseColumnFilter.Init"/> method which, in turn, calls this method. /// You can ovverride this method to provide initialization code or you can create an event handler and /// set the <i>Cancel</i> property of event argument to true, to skip standard initialization. /// </remarks> protected override void OnFilterInitializing(object sender, CancelEventArgs e) { base.OnFilterInitializing(sender, e); if (e.Cancel) { return; } comboBoxOperator.Items.AddRange(new object[] { "[...]", "=", "<>", ">", "<", "<=", ">=", "= Ø", "<> Ø" }); comboBoxOperator.SelectedIndex = 0; FilterHost.RegisterComboBox(comboBoxOperator); }
internal void Filter_Changed(object newValue) { // Update the effective filter. If the filter is provided as content, the content filter will be recreated when needed. _filterValues = newValue; if (FilterHost == null) { FilterHost = DataGrid.GetFilter(); } FilterHost.Filter(); }
private void self_Loaded(object sender, RoutedEventArgs e) { if (FilterHost == null) { // Find the ancestor column header and data grid controls. ColumnHeader = this.FindAncestorOrSelf <DataGridColumnHeader>(); if (ColumnHeader == null) { throw new InvalidOperationException("DataGridFilterColumnControl must be a child element of a DataGridColumnHeader."); } DataGrid = ColumnHeader.FindAncestorOrSelf <DataGrid>(); if (DataGrid == null) { throw new InvalidOperationException("DataGridColumnHeader must be a child element of a DataGrid"); } // Find our host and attach ourself. FilterHost = DataGrid.GetFilter(); } FilterHost.AddColumn(this); DataGrid.SourceUpdated += DataGrid_SourceOrTargetUpdated; DataGrid.TargetUpdated += DataGrid_SourceOrTargetUpdated; DataGrid.RowEditEnding += DataGrid_RowEditEnding; // Must set a non-null empty template here, else we won't get the coerce value callback when the columns attached property is null! Template = _emptyControlTemplate; // Bind our IsFilterVisible and Template properties to the corresponding properties attached to the // DataGridColumnHeader.Column property. Use binding instead of simple assignment since columnHeader.Column is still null at this point. var isFilterVisiblePropertyPath = new PropertyPath("Column.(0)", DataGridFilterColumn.IsFilterVisibleProperty); BindingOperations.SetBinding(this, VisibilityProperty, new Binding() { Path = isFilterVisiblePropertyPath, Source = ColumnHeader, Mode = BindingMode.OneWay, Converter = _booleanToVisibilityConverter }); var templatePropertyPath = new PropertyPath("Column.(0)", DataGridFilterColumn.TemplateProperty); BindingOperations.SetBinding(this, TemplateProperty, new Binding() { Path = templatePropertyPath, Source = ColumnHeader, Mode = BindingMode.OneWay }); var filterPropertyPath = new PropertyPath("Column.(0)", DataGridFilterColumn.FilterProperty); BindingOperations.SetBinding(this, FilterProperty, new Binding() { Path = filterPropertyPath, Source = ColumnHeader, Mode = BindingMode.TwoWay }); }
/// <summary> /// Perform filter initialitazion and raises the FilterInitializing event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param> /// <remarks> /// When this <i>column filter</i> control is added to the <i>column filters</i> array of the <i>filter manager</i>, /// the latter calls the <see cref="DgvBaseColumnFilter.Init"/> method which, in turn, calls this method. /// You can ovverride this method to provide initialization code or you can create an event handler and /// set the <i>Cancel</i> property of event argument to true, to skip standard initialization. /// </remarks> protected override void OnFilterInitializing(object sender, CancelEventArgs e) { base.OnFilterInitializing(sender, e); if (e.Cancel) { return; } comboBoxMonth.SelectedValueChanged += new EventHandler(onFilterChanged); comboBoxYear.SelectedValueChanged += new EventHandler(onFilterChanged); comboBoxYear.SelectedIndex = comboBoxYear.Items.Count - 1; FilterHost.RegisterComboBox(comboBoxMonth); FilterHost.RegisterComboBox(comboBoxYear); }
/// <summary> /// Returns true if the given item matches the filter condition for this column. /// </summary> internal bool Matches(object item) { if ((Filter == null) || (FilterHost == null)) { return(true); } if (_activeFilter == null) { _activeFilter = FilterHost.CreateContentFilter(Filter); } return(_activeFilter.IsMatch(GetCellContent(item))); }
private void Self_Unloaded(object sender, RoutedEventArgs e) { if (FilterHost != null) { FilterHost.RemoveColumn(this); } if (DataGrid != null) { DataGrid.SourceUpdated -= DataGrid_SourceOrTargetUpdated; DataGrid.TargetUpdated -= DataGrid_SourceOrTargetUpdated; DataGrid.RowEditEnding -= DataGrid_RowEditEnding; } //BindingOperations.ClearBinding((DependencyObject)this, UIElement.VisibilityProperty); BindingOperations.ClearBinding(this, TemplateProperty); //BindingOperations.ClearBinding((DependencyObject)this, DataGridFilterColumnControl.FilterProperty); }
private void self_Unloaded(object sender, RoutedEventArgs e) { // Detach from host. // Must check for null, unloaded event might be raised even if no loaded event has been raised before! FilterHost?.RemoveColumn(this); if (DataGrid != null) { DataGrid.SourceUpdated -= DataGrid_SourceOrTargetUpdated; DataGrid.TargetUpdated -= DataGrid_SourceOrTargetUpdated; DataGrid.RowEditEnding -= DataGrid_RowEditEnding; } // Clear all bindings generated during load. BindingOperations.ClearBinding(this, VisibilityProperty); BindingOperations.ClearBinding(this, TemplateProperty); BindingOperations.ClearBinding(this, FilterProperty); }
/// <summary> /// Perform filter initialitazion and raises the FilterInitializing event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param> /// <remarks> /// When this <i>column filter</i> control is added to the <i>column filters</i> array of the <i>filter manager</i>, /// the latter calls the <see cref="DgvBaseColumnFilter.Init"/> method which, in turn, calls this method. /// You can ovverride this method to provide initialization code or you can create an event handler and /// set the <i>Cancel</i> property of event argument to true, to skip standard initialization. /// </remarks> protected override void OnFilterInitializing(object sender, CancelEventArgs e) { base.OnFilterInitializing(sender, e); if (e.Cancel) { return; } if (ColumnDataType == typeof(string)) { comboBoxOperator.Items.AddRange(new object[] { "..xxx..", "xxx..", "..xxx", "=", "<>", "= Ø", "<> Ø" }); } else { comboBoxOperator.Items.AddRange(new object[] { "=", "<>", ">", "<", "<=", ">=", "= Ø", "<> Ø" }); } comboBoxOperator.SelectedIndex = 0; FilterHost.RegisterComboBox(comboBoxOperator); }
private void Self_Unloaded([NotNull] object sender, [NotNull] RoutedEventArgs e) { // Detach from host. // Must check for null, unloaded event might be raised even if no loaded event has been raised before! FilterHost?.RemoveColumn(this); var dataGrid = DataGrid; if (dataGrid != null) { dataGrid.SourceUpdated -= DataGrid_SourceOrTargetUpdated; dataGrid.TargetUpdated -= DataGrid_SourceOrTargetUpdated; dataGrid.RowEditEnding -= DataGrid_RowEditEnding; } // Clear all bindings generated during load. // ReSharper disable once AssignNullToNotNullAttribute BindingOperations.ClearBinding(this, VisibilityProperty); // ReSharper disable once AssignNullToNotNullAttribute BindingOperations.ClearBinding(this, TemplateProperty); BindingOperations.ClearBinding(this, FilterProperty); }
/// <summary> /// Perform filter initialitazion and raises the FilterInitializing event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param> /// <remarks> /// When this <i>column filter</i> control is added to the <i>column filters</i> array of the <i>filter manager</i>, /// the latter calls the <see cref="DgvBaseColumnFilter.Init"/> method which, in turn, calls this method. /// You can ovverride this method to provide initialization code or you can create an event handler and /// set the <i>Cancel</i> property of event argument to true, to skip standard initialization. /// </remarks> protected override void OnFilterInitializing(object sender, CancelEventArgs e) { base.OnFilterInitializing(sender, e); if (e.Cancel) { return; } comboBoxOperator.Items.AddRange(new object[] { "=", "<>", "= Ø", "<> Ø" }); comboBoxOperator.SelectedIndex = 0; if (DataGridViewColumn is DataGridViewComboBoxColumn) { comboBoxValue.ValueMember = ((DataGridViewComboBoxColumn)DataGridViewColumn).ValueMember; comboBoxValue.DisplayMember = ((DataGridViewComboBoxColumn)DataGridViewColumn).DisplayMember; comboBoxValue.DataSource = ((DataGridViewComboBoxColumn)DataGridViewColumn).DataSource; } else { comboBoxValue.ValueMember = DataGridViewColumn.DataPropertyName; comboBoxValue.DisplayMember = DataGridViewColumn.DataPropertyName; RefreshValues(); } FilterHost.RegisterComboBox(comboBoxOperator); FilterHost.RegisterComboBox(comboBoxValue); }
public int PrepareMarcFilter( FilterHost host, string strFilterFileName, out LoanFilterDocument filter, out string strError) { strError = ""; // 看看是否有现成可用的对象 filter = (LoanFilterDocument)this.Filters.GetFilter(strFilterFileName); if (filter != null) { filter.FilterHost = host; return 1; } // 新创建 // string strFilterFileContent = ""; filter = new LoanFilterDocument(); filter.FilterHost = host; filter.strOtherDef = "FilterHost Host = null;"; filter.strPreInitial = " LoanFilterDocument doc = (LoanFilterDocument)this.Document;\r\n"; filter.strPreInitial += " Host = (" + "FilterHost" + ")doc.FilterHost;\r\n"; // filter.Load(strFilterFileName); try { filter.Load(strFilterFileName); } catch (Exception ex) { strError = ex.Message; return -1; } string strCode = ""; // c#代码 int nRet = filter.BuildScriptFile(out strCode, out strError); if (nRet == -1) goto ERROR1; string[] saAddRef1 = { this.BinDir + "\\digitalplatform.marcdom.dll", this.BinDir + "\\digitalplatform.marckernel.dll", this.BinDir + "\\digitalplatform.OPAC.Server.dll", this.BinDir + "\\digitalplatform.dll", this.BinDir + "\\digitalplatform.Text.dll", this.BinDir + "\\digitalplatform.IO.dll", this.BinDir + "\\digitalplatform.Xml.dll", this.BinDir + "\\digitalplatform.script.dll", this.BinDir + "\\digitalplatform.marcquery.dll", /*strMainCsDllName*/ }; Assembly assembly = null; string strWarning = ""; string strLibPaths = ""; string[] saRef2 = filter.GetRefs(); string[] saRef = new string[saRef2.Length + saAddRef1.Length]; Array.Copy(saRef2, saRef, saRef2.Length); Array.Copy(saAddRef1, 0, saRef, saRef2.Length, saAddRef1.Length); // 创建Script的Assembly // 本函数内对saRef不再进行宏替换 nRet = ScriptManager.CreateAssembly_1(strCode, saRef, strLibPaths, out assembly, out strError, out strWarning); if (nRet == -2) goto ERROR1; if (nRet == -1) { if (strWarning == "") { goto ERROR1; } // MessageBox.Show(this, strWarning); } filter.Assembly = assembly; return 0; ERROR1: return -1; }
// 将种记录数据从XML格式转换为HTML格式 public int ConvertBiblioXmlToHtml( string strFilterFileName, string strBiblioXml, string strRecPath, out string strBiblio, out KeyValueCollection result_params, out string strError) { strBiblio = ""; strError = ""; result_params = null; OpacApplication app = this; FilterHost host = new FilterHost(); host.RecPath = strRecPath; host.App = this; host.ResultParams = new KeyValueCollection(); // 如果必要,转换为MARC格式,调用filter string strOutMarcSyntax = ""; string strMarc = ""; // 将MARCXML格式的xml记录转换为marc机内格式字符串 // parameters: // bWarning ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换 // strMarcSyntax 指示marc语法,如果=="",则自动识别 // strOutMarcSyntax out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值 int nRet = MarcUtil.Xml2Marc(strBiblioXml, true, "", // this.CurMarcSyntax, out strOutMarcSyntax, out strMarc, out strError); if (nRet == -1) goto ERROR1; LoanFilterDocument filter = null; nRet = app.PrepareMarcFilter( host, strFilterFileName, out filter, out strError); if (nRet == -1) goto ERROR1; try { nRet = filter.DoRecord(null, strMarc, 0, out strError); if (nRet == -1) goto ERROR1; strBiblio = host.ResultString; result_params = host.ResultParams; } catch (Exception ex) { strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex); return -1; } finally { // 归还对象 app.Filters.SetFilter(strFilterFileName, filter); } return 0; ERROR1: return -1; }
public int PrepareMarcFilter( FilterHost host, string strFilterFileName, out LoanFilterDocument filter, out string strError) { strError = ""; // 看看是否有现成可用的对象 filter = (LoanFilterDocument)this.Filters.GetFilter(strFilterFileName); if (filter != null) { filter.FilterHost = host; return 1; } // 新创建 filter = new LoanFilterDocument(); filter.FilterHost = host; filter.strOtherDef = "FilterHost Host = null;"; filter.strPreInitial = " LoanFilterDocument doc = (LoanFilterDocument)this.Document;\r\n"; filter.strPreInitial += " Host = (" + "FilterHost" + ")doc.FilterHost;\r\n"; try { filter.Load(strFilterFileName); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return -1; } string strCode = ""; // c#代码 int nRet = filter.BuildScriptFile(out strCode, out strError); if (nRet == -1) return -1; try { string[] saRef2 = filter.GetRefs(); filter.Assembly = this.AssemblyCache.GetObject(strFilterFileName, () => { string[] saAddRef1 = { this.BinDir + "\\digitalplatform.marcdom.dll", this.BinDir + "\\digitalplatform.marckernel.dll", this.BinDir + "\\digitalplatform.OPAC.Server.dll", this.BinDir + "\\digitalplatform.dll", this.BinDir + "\\digitalplatform.Text.dll", this.BinDir + "\\digitalplatform.IO.dll", this.BinDir + "\\digitalplatform.Xml.dll", this.BinDir + "\\digitalplatform.script.dll", this.BinDir + "\\digitalplatform.marcquery.dll", }; string strError1 = ""; string strWarning = ""; // string strLibPaths = ""; string[] saRef = StringUtil.Append(saRef2, saAddRef1); #if NO string[] saRef = new string[saRef2.Length + saAddRef1.Length]; Array.Copy(saRef2, saRef, saRef2.Length); Array.Copy(saAddRef1, 0, saRef, saRef2.Length, saAddRef1.Length); #endif Assembly assembly1 = null; // 创建Script的Assembly // 本函数内对saRef不再进行宏替换 nRet = ScriptManager.CreateAssembly_1(strCode, saRef, "", // strLibPaths, out assembly1, out strError1, out strWarning); if (nRet == -2) throw new Exception(strError1); if (nRet == -1) { if (string.IsNullOrEmpty(strWarning) == true) throw new Exception(strError1); } return assembly1; }); } catch (Exception ex) { strError = ex.Message; return -1; } return 0; }
// 创建MARC格式记录的浏览格式 // paramters: // strMARC MARC机内格式 public int BuildMarcBrowseText( string strSytaxOID, string strMARC, out string strBrowseText, out string strError) { strBrowseText = ""; strError = ""; FilterHost host = new FilterHost(); host.ID = ""; host.MainForm = this.MainForm; BrowseFilterDocument filter = null; string strFilterFileName = this.MainForm.DataDir + "\\" + strSytaxOID.Replace(".", "_") + "\\marc_browse.fltx"; int nRet = this.PrepareMarcFilter( host, strFilterFileName, out filter, out strError); if (nRet == -1) goto ERROR1; try { nRet = filter.DoRecord(null, strMARC, 0, out strError); if (nRet == -1) goto ERROR1; strBrowseText = host.ResultString; } finally { // 归还对象 filter.FilterHost = null; // 2016/1/23 this.Filters.SetFilter(strFilterFileName, filter); } return 0; ERROR1: // 不让缓存,因为可能出现了编译错误 // TODO: 精确区分编译错误 this.Filters.ClearFilter(strFilterFileName); return -1; }
private void DataGridFilterColumnControl_Loaded(object sender, System.Windows.RoutedEventArgs e) { if (FilterHost == null) { // Find the ancestor column header and data grid controls. ColumnHeader = this.FindColumnHeader <DataGridColumnHeader>(); if (ColumnHeader == null) { throw new InvalidOperationException("DataGridFilterColumnControl must be a child element of a DataGridColumnHeader."); } DataGrid = ColumnHeader.FindColumnHeader <DataGrid>(); if (DataGrid == null) { throw new InvalidOperationException("DataGridColumnHeader must be a child element of a DataGrid"); } // Find our host and attach ourself. FilterHost = DataGrid.GetFilter(); } Template = _emptyControlTemplate; var isFilterVisiblePropertyPath = new PropertyPath("Column.(0)", DataGridFilterColumn.IsFilterVisibleProperty); BindingOperations.SetBinding(this, VisibilityProperty, new Binding() { Path = isFilterVisiblePropertyPath, Source = ColumnHeader, Mode = BindingMode.OneWay, Converter = _booleanToVisibilityConverter }); var templatePropertyPath = new PropertyPath("Column.(0)", DataGridFilterColumn.TemplateProperty); BindingOperations.SetBinding(this, TemplateProperty, new Binding() { Path = templatePropertyPath, Source = ColumnHeader, Mode = BindingMode.OneWay }); var filterPropertyPath = new PropertyPath("Column.(0)", DataGridFilterColumn.FilterProperty); BindingOperations.SetBinding(this, FilterProperty, new Binding() { Path = filterPropertyPath, Source = ColumnHeader, Mode = BindingMode.TwoWay }); //1.获取datagridcolumnheader中Column是什么类型 //2.根据不同的类型修改自己的样式 //ColumnHeader = this.FindColumnHeader<DataGridColumnHeader>(); //if (ColumnHeader == null) // throw new Exception(); var template = ColumnHeader.Column.GetType(); if (template == typeof(DataGridCheckBoxColumn)) { var tem = this.FindResource("DataGridCheckBoxColumn") as ControlTemplate; var count = VisualTreeHelper.GetChildrenCount(new CheckBox()); // CheckBox c = VisualTreeHelper.GetChild(new CheckBox()) as CheckBox; // CheckBox c = tem.c("_chebox_",new Grid()) as CheckBox; // BindingOperations.SetBinding(c, CheckBox.IsCheckedProperty, new Binding(nameof(FilterValues)) { Source = this }); this.Template = tem; this.Visibility = FilterHost._isFilteringVisibility ? Visibility.Visible : Visibility.Hidden; } else { this.Template = this.FindResource("DataGridTextColumn") as ControlTemplate; this.Visibility = FilterHost._isFilteringVisibility ? Visibility.Visible : Visibility.Hidden; } FilterHost.AddColumn(this); }