private void AddDefaultFilter(List <FilterDeclarationField> fields, string browsePath, bool displayInList) { FilterDeclarationField field = new FilterDeclarationField(); field.InstanceDeclaration = new InstanceDeclaration(); field.InstanceDeclaration.BrowsePathDisplayText = browsePath; field.DisplayInList = displayInList; fields.Add(field); }
/// <summary> /// Creates a new instance of a FilterDeclarationField. /// </summary> public FilterDeclarationField(FilterDeclarationField field) { Selected = field.Selected; DisplayInList = field.DisplayInList; FilterEnabled = field.FilterEnabled; FilterOperator = field.FilterOperator; FilterValue = field.FilterValue; InstanceDeclaration = field.InstanceDeclaration; }
/// <summary> /// Updates the filter from the controls. /// </summary> private void UpdateFilter() { // get selected declarations. List <InstanceDeclaration> declarations = new List <InstanceDeclaration>(); NodeId eventTypeId = CollectInstanceDeclarations(declarations); if (m_filter == null) { m_filter = new FilterDeclaration(); } if (m_filter.Fields == null || m_filter.Fields.Count == 0) { m_filter.Fields = new List <FilterDeclarationField>(); // select some default values to display in the list. AddDefaultFilter(m_filter.Fields, Opc.Ua.BrowseNames.EventType, true); AddDefaultFilter(m_filter.Fields, Opc.Ua.BrowseNames.SourceName, true); AddDefaultFilter(m_filter.Fields, Opc.Ua.BrowseNames.SourceNode, true); AddDefaultFilter(m_filter.Fields, Opc.Ua.BrowseNames.Time, true); AddDefaultFilter(m_filter.Fields, Opc.Ua.BrowseNames.Severity, true); AddDefaultFilter(m_filter.Fields, Opc.Ua.BrowseNames.Message, true); } // copy settings from existing filter. List <FilterDeclarationField> fields = new List <FilterDeclarationField>(); foreach (InstanceDeclaration declaration in declarations) { if (declaration.NodeClass != NodeClass.Variable) { continue; } FilterDeclarationField field = new FilterDeclarationField(declaration); foreach (FilterDeclarationField field2 in m_filter.Fields) { if (field2.InstanceDeclaration.BrowsePathDisplayText == field.InstanceDeclaration.BrowsePathDisplayText) { field.DisplayInList = field2.DisplayInList; field.FilterEnabled = field2.FilterEnabled; field.FilterOperator = field2.FilterOperator; field.FilterValue = field2.FilterValue; break; } } fields.Add(field); } // update filter. m_filter.EventTypeId = eventTypeId; m_filter.Fields = fields; }
/// <summary> /// Creates a new instance of a FilterDeclaration. /// </summary> public FilterDeclaration(TypeDeclaration eventType, FilterDeclaration template) { EventTypeId = eventType.NodeId; Fields = new List <FilterDeclarationField>(); foreach (InstanceDeclaration instanceDeclaration in eventType.Declarations) { if (instanceDeclaration.NodeClass == NodeClass.Method) { continue; } if (NodeId.IsNull(instanceDeclaration.ModellingRule)) { continue; } FilterDeclarationField element = new FilterDeclarationField(instanceDeclaration); Fields.Add(element); // set reasonable defaults. if (template == null) { if (instanceDeclaration.RootTypeId == Opc.Ua.ObjectTypeIds.BaseEventType && instanceDeclaration.BrowseName != Opc.Ua.BrowseNames.EventId) { element.DisplayInList = true; } } // preserve filter settings. else { foreach (FilterDeclarationField field in template.Fields) { if (field.InstanceDeclaration.BrowsePathDisplayText == element.InstanceDeclaration.BrowsePathDisplayText) { element.DisplayInList = field.DisplayInList; element.FilterEnabled = field.FilterEnabled; element.FilterOperator = field.FilterOperator; element.FilterValue = field.FilterValue; break; } } } } }
/// <summary> /// Updates the row. /// </summary> public void UpdateRow(DataRow row, FilterDeclarationField field) { row[0] = field; row[1] = ImageList.Images[ClientUtils.GetImageIndex(m_session, field.InstanceDeclaration.NodeClass, field.InstanceDeclaration.RootTypeId, false)]; row[2] = field.InstanceDeclaration.BrowsePathDisplayText; row[3] = field.Selected; row[4] = field.DisplayInList; row[5] = field.FilterEnabled; if (field.FilterEnabled) { row[6] = field.FilterOperator; row[7] = field.FilterValue; } row[8] = m_counter++; }
/// <summary> /// Adds a simple field to the declaration. /// </summary> public void AddSimpleField(QualifiedName[] browseNames, NodeClass nodeClass, BuiltInType dataType, int valueRank, bool displayInList) { FilterDeclarationField field = new FilterDeclarationField(); field.DisplayInList = displayInList; field.InstanceDeclaration = new InstanceDeclaration(); field.InstanceDeclaration.NodeClass = nodeClass; if (browseNames != null) { field.InstanceDeclaration.BrowseName = browseNames[browseNames.Length - 1]; field.InstanceDeclaration.BrowsePath = new QualifiedNameCollection(); StringBuilder path = new StringBuilder(); for (int ii = 0; ii < browseNames.Length; ii++) { if (path.Length > 0) { path.Append('/'); } path.Append(browseNames[ii]); field.InstanceDeclaration.BrowsePath.Add(browseNames[ii]); } field.InstanceDeclaration.BrowsePathDisplayText = path.ToString(); } field.InstanceDeclaration.BuiltInType = dataType; field.InstanceDeclaration.DataType = (uint)dataType; field.InstanceDeclaration.ValueRank = valueRank; field.InstanceDeclaration.DataTypeDisplayText = dataType.ToString(); if (valueRank >= 0) { field.InstanceDeclaration.DataTypeDisplayText += "[]"; } field.InstanceDeclaration.DisplayName = field.InstanceDeclaration.BrowseName.Name; field.InstanceDeclaration.DisplayPath = field.InstanceDeclaration.BrowsePathDisplayText; field.InstanceDeclaration.RootTypeId = ObjectTypeIds.BaseEventType; Fields.Add(field); }
private void FilterDV_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex == -1) { return; } DataRowView source = FilterDV.Rows[e.RowIndex].DataBoundItem as DataRowView; FilterDeclarationField field = (FilterDeclarationField)source.Row[0]; if (e.ColumnIndex == 2) { field.Selected = !field.Selected; source.Row[3] = field.Selected; return; } if (e.ColumnIndex == 3) { field.DisplayInList = !field.DisplayInList; source.Row[4] = field.DisplayInList; return; } if (e.ColumnIndex == 4) { field.FilterEnabled = !field.FilterEnabled; source.Row[5] = field.FilterEnabled; return; } } catch (Exception exception) { ClientUtils.HandleException(this.Text, exception); } }
private void FilterDV_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { try { if (e.ColumnIndex == 2) { bool state = false; if (m_dataset.Tables[0].DefaultView.Count > 0) { state = (bool)m_dataset.Tables[0].DefaultView[0].Row[3]; } state = !state; foreach (DataRowView row in m_dataset.Tables[0].DefaultView) { FilterDeclarationField field = (FilterDeclarationField)row.Row[0]; row.Row[3] = field.Selected = state; } } } catch (Exception exception) { ClientUtils.HandleException(this.Text, exception); } }
private void FilterDV_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex == -1) { return; } DataRowView source = FilterDV.Rows[e.RowIndex].DataBoundItem as DataRowView; FilterDeclarationField field = (FilterDeclarationField)source.Row[0]; if (e.ColumnIndex == 5) { FilterOperator filterOperator = field.FilterOperator; if (new SetFilterOperatorDlg().ShowDialog(ref filterOperator)) { field.FilterEnabled = true; source.Row[5] = field.FilterEnabled; field.FilterOperator = filterOperator; source.Row[6] = field.FilterOperator; } return; } if (e.ColumnIndex == 6) { if (field.FilterOperator == FilterOperator.IsNull) { field.FilterValue = Variant.Null; return; } InstanceDeclaration declaration = field.InstanceDeclaration; object result = new EditComplexValueDlg().ShowDialog( m_session, declaration.DisplayName, declaration.DataType, declaration.ValueRank, field.FilterValue.Value, "Edit Filter Value"); if (result != null) { field.FilterEnabled = true; source.Row[5] = field.FilterEnabled; source.Row[6] = field.FilterOperator; field.FilterValue = new Variant(result); source.Row[7] = field.FilterValue; } return; } } catch (Exception exception) { ClientUtils.HandleException(this.Text, exception); } }