public void OnValueChanged(int index, object value, bool user) { GXDLMSAutoAnswer target = Target as GXDLMSAutoAnswer; if (index == 3) { ListeningWindowLV.Items.Clear(); if (target.ListeningWindow != null) { foreach (var it in target.ListeningWindow) { ListViewItem li = ListeningWindowLV.Items.Add(it.Key.ToString()); li.SubItems.Add(GXHelpers.ConvertDLMS2String(it.Value.ToString())); } } } else if (index == 5) { if (target.NumberOfCalls == 0) { NumberOfCallsTB.Value = "No limit."; } else { NumberOfCallsTB.Value = target.NumberOfCalls.ToString(); } } else if (index == 6) { if (target.NumberOfRingsInListeningWindow == 0) { this.RingCountInWindowTB.Text = "No connect."; } else { this.RingCountInWindowTB.Text = target.NumberOfRingsInListeningWindow.ToString(); } if (target.NumberOfRingsOutListeningWindow == 0) { this.RingCountOutOfWindowTB.Text = "No connect."; } else { this.RingCountOutOfWindowTB.Text = target.NumberOfRingsOutListeningWindow.ToString(); } } }
void OnUpdateValue(object value) { string str; if (value != null && value.GetType().IsArray) { str = Convert.ToString(GXHelpers.ConvertFromDLMS(value, DataType.None, DataType.None, true)); } else { str = GXHelpers.ConvertDLMS2String(value); } if (Type == GXValueFieldType.TextBox) { textBox1.TextChanged -= new EventHandler(textBox1_TextChanged); this.textBox1.Text = str; textBox1.TextChanged += new EventHandler(textBox1_TextChanged); } else if (Type == GXValueFieldType.CompoBox) { if (comboBox1.Items.Count != 0) { if (value != null) { if (Items != null && Items.Count != 0) { foreach (GXObisValueItem it in Items) { if (it.Value.Equals(Convert.ChangeType(value, it.Value.GetType()))) { int pos = comboBox1.Items.IndexOf(it.UIValue); if (pos != -1) { comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged); comboBox1.SelectedIndex = pos; comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); return; } } } } else if (value is Enum) { comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged); comboBox1.SelectedItem = value; comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); return; } } else { comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged); comboBox1.SelectedIndex = -1; comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); return; } } this.comboBox1.Text = str; } else if (Type == GXValueFieldType.ListBox) { if (value is Array) { this.listBox1.Items.Clear(); foreach (Array it in (Array)value) { List <byte> arr = new List <byte>(); foreach (object item in it) { if (item is Array) { foreach (byte b in (Array)item) { arr.Add(b); } } else { arr.Add((byte)item); } } listBox1.Items.Add(ASCIIEncoding.ASCII.GetString((byte[])arr.ToArray())); } } else if (value is Enum) { listBox1.SelectedItem = value; return; } } else if (Type == GXValueFieldType.CheckedListBox) { if (value is Enum) { checkedlistBox1.ItemCheck -= CheckedlistBox1_ItemCheck; //Uncheck all items. for (int pos = 0; pos != checkedlistBox1.Items.Count; ++pos) { checkedlistBox1.SetItemChecked(pos, false); } foreach (var it in Enum.GetValues(value.GetType())) { if (((int)it & (int)value) != 0 || ((int)it == (int)value)) { checkedlistBox1.SetItemChecked(checkedlistBox1.Items.IndexOf(it), true); } } checkedlistBox1.ItemCheck += CheckedlistBox1_ItemCheck; return; } } else { throw new InvalidExpressionException(); } }