private void CheckNodeIdMI_Click(object sender, EventArgs e) { try { string nodeId = new Opc.Ua.Client.Controls.StringValueEditDlg().ShowDialog(""); if (nodeId == null) { return; } string[] parts = nodeId.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); ushort ns = Convert.ToUInt16(parts[0].Substring(2)); uint id = Convert.ToUInt32(parts[2]); using (Session session = CreateSession()) { new SelectNodesDlg().ShowDialog(session, new NodeId(id, ns), null); } } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
/// <summary> /// Displays a dialog that allows a use to edit a value. /// </summary> public static object EditValue(Session session, object value, NodeId datatypeId, int valueRank) { if (value == null) { value = GuiUtils.GetDefaultValue(datatypeId, valueRank); } if (valueRank >= 0) { return new ComplexValueEditDlg().ShowDialog(value); } BuiltInType builtinType = TypeInfo.GetBuiltInType(datatypeId, session.TypeTree); switch (builtinType) { case BuiltInType.Boolean: case BuiltInType.Byte: case BuiltInType.SByte: case BuiltInType.Int16: case BuiltInType.UInt16: case BuiltInType.Int32: case BuiltInType.UInt32: case BuiltInType.Int64: case BuiltInType.UInt64: case BuiltInType.Float: case BuiltInType.Double: case BuiltInType.Enumeration: { return new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(builtinType, valueRank)); } case BuiltInType.Number: { return new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(BuiltInType.Double, valueRank)); } case BuiltInType.Integer: { return new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(BuiltInType.Int64, valueRank)); } case BuiltInType.UInteger: { return new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(BuiltInType.UInt64, valueRank)); } case BuiltInType.NodeId: { return new NodeIdValueEditDlg().ShowDialog(session, (NodeId)value); } case BuiltInType.ExpandedNodeId: { return new NodeIdValueEditDlg().ShowDialog(session, (ExpandedNodeId)value); } case BuiltInType.DateTime: { DateTime datetime = (DateTime)value; if (new DateTimeValueEditDlg().ShowDialog(ref datetime)) { return datetime; } return null; } case BuiltInType.QualifiedName: { QualifiedName qname = (QualifiedName)value; string name = new StringValueEditDlg().ShowDialog(qname.Name); if (name != null) { return new QualifiedName(name, qname.NamespaceIndex); } return null; } case BuiltInType.String: { return new StringValueEditDlg().ShowDialog((string)value); } case BuiltInType.LocalizedText: { LocalizedText ltext = (LocalizedText)value; string text = new StringValueEditDlg().ShowDialog(ltext.Text); if (text != null) { return new LocalizedText(ltext.Locale, text); } return null; } } return new ComplexValueEditDlg().ShowDialog(value); }
/// <summary> /// Displays a dialog that allows a use to edit a value. /// </summary> public static object EditValue(Session session, object value, NodeId datatypeId, int valueRank) { if (value == null) { value = GetDefaultValue(datatypeId, valueRank); } if (valueRank >= 0) { return(new ComplexValueEditDlg().ShowDialog(value)); } BuiltInType builtinType = TypeInfo.GetBuiltInType(datatypeId, session.TypeTree); switch (builtinType) { case BuiltInType.Boolean: case BuiltInType.Byte: case BuiltInType.SByte: case BuiltInType.Int16: case BuiltInType.UInt16: case BuiltInType.Int32: case BuiltInType.UInt32: case BuiltInType.Int64: case BuiltInType.UInt64: case BuiltInType.Float: case BuiltInType.Double: case BuiltInType.Enumeration: { return(new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(builtinType, valueRank))); } case BuiltInType.Number: { return(new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(BuiltInType.Double, valueRank))); } case BuiltInType.Integer: { return(new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(BuiltInType.Int64, valueRank))); } case BuiltInType.UInteger: { return(new NumericValueEditDlg().ShowDialog(value, TypeInfo.GetSystemType(BuiltInType.UInt64, valueRank))); } case BuiltInType.NodeId: { return(new NodeIdValueEditDlg().ShowDialog(session, (NodeId)value)); } case BuiltInType.ExpandedNodeId: { return(new NodeIdValueEditDlg().ShowDialog(session, (ExpandedNodeId)value)); } case BuiltInType.DateTime: { DateTime datetime = (DateTime)value; if (new DateTimeValueEditDlg().ShowDialog(ref datetime)) { return(datetime); } return(null); } case BuiltInType.QualifiedName: { QualifiedName qname = (QualifiedName)value; string name = new StringValueEditDlg().ShowDialog(qname.Name); if (name != null) { return(new QualifiedName(name, qname.NamespaceIndex)); } return(null); } case BuiltInType.String: { return(new StringValueEditDlg().ShowDialog((string)value)); } case BuiltInType.LocalizedText: { LocalizedText ltext = (LocalizedText)value; string text = new StringValueEditDlg().ShowDialog(ltext.Text); if (text != null) { return(new LocalizedText(ltext.Locale, text)); } return(null); } } return(new ComplexValueEditDlg().ShowDialog(value)); }
private void EditMI_Click(object sender, EventArgs e) { try { if (ItemsLV.SelectedItems.Count != 1) { return; } ValueState state = ItemsLV.SelectedItems[0].Tag as ValueState; if (!IsEditableType(state.Component)) { return; } object value = null; if (state.Component is LocalizedText) { value = new StringValueEditDlg().ShowDialog(state.Component.ToString()); if (value != null) { value = new LocalizedText(((LocalizedText)state.Component).Key, ((LocalizedText)state.Component).Locale, value.ToString()); } } else { value = new SimpleValueEditDlg().ShowDialog(state.Component, state.Component.GetType()); } if (value == null) { return; } if (state.Value is IEncodeable) { PropertyInfo property = (PropertyInfo)state.ComponentId; MethodInfo[] accessors = property.GetAccessors(); for (int ii = 0; ii < accessors.Length; ii++) { if (accessors[ii].ReturnType == typeof(void)) { accessors[ii].Invoke(state.Value, new object[] { value }); state.Component = value; break; } } } DataValue datavalue = state.Value as DataValue; if (datavalue != null) { int component = (int)state.ComponentId; switch (component) { case 0: { datavalue.Value = value; break; } } } if (state.Value is IList) { int ii = (int)state.ComponentId; ((IList)state.Value)[ii] = value; state.Component = value; } m_expanding = false; int index = (int)state.ComponentIndex; int indentCount = ItemsLV.Items[index].IndentCount; while (ItemsLV.Items[index - 1].IndentCount == indentCount) { --index; } bool overwrite = true; ShowValue(ref index, ref overwrite, state.Value); } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
private void ViewMI_Click(object sender, EventArgs e) { try { string value = SelectedTag as string; if (value == null) { return; } value = new StringValueEditDlg().ShowDialog(value); if (String.IsNullOrEmpty(value)) { return; } value = new Uri(value).ToString(); // UpdateItem(ItemsLV.SelectedItems[0], value); AdjustColumns(); } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }