private void TemplateCb_DrawItem(object sender, DrawItemEventArgs e) { // If the index is invalid then simply exit. if (e.Index == -1 || e.Index >= TemplateCb.Items.Count) { return; } // Draw the background of the item. e.DrawBackground(); // Should we draw the focus rectangle? if ((e.State & DrawItemState.Focus) != 0) { e.DrawFocusRectangle(); } Font f = new Font(e.Font, FontStyle.Regular); // Create a new background brush. Brush b = new SolidBrush(e.ForeColor); // Draw the item. GXDeviceTemplate target = (GXDeviceTemplate)TemplateCb.Items[e.Index]; if (target == null) { return; } string name = target.Name; SizeF s = e.Graphics.MeasureString(name, f); e.Graphics.DrawString(name, f, b, e.Bounds); }
public TestDevicesDlg(GXDeviceTemplate device, GXDeviceTemplate[] templates) { InitializeComponent(); TemplateCb.Items.AddRange(templates); if (device != null) { TemplateCb.SelectedItem = device; } TemplateCb.DrawMode = DrawMode.OwnerDrawFixed; IndexTb.Text = "1"; CountTb.Text = "1000"; }
private void PropertiesRemove_Click(object sender, EventArgs e) { try { if (MessageBox.Show(panel1.Parent, Properties.Resources.TemplateRemoveWarning, "GXDLMSDirector", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) { GXDeviceTemplate meter = (GXDeviceTemplate)TemplatesView.SelectedItems[0].Tag; List <GXAttributeTemplate> list = new List <GXAttributeTemplate>(); List <ListViewItem> nodes = new List <ListViewItem>(); foreach (ListViewItem it in PropertiesView.SelectedItems) { list.Add((GXAttributeTemplate)it.Tag); nodes.Add(it); } if (list.Count != 0) { ami.RemoveAttributeTemplates(list.ToArray()); foreach (ListViewItem it in nodes) { PropertiesView.Items.Remove(it); } foreach (GXAttributeTemplate it in list) { bool found = false; foreach (GXObjectTemplate o in meter.Objects) { foreach (GXAttributeTemplate a in o.Attributes) { if (a.Id == it.Id) { o.Attributes.Remove(a); found = true; break; } } if (found) { break; } } } } } } catch (Exception Ex) { MessageBox.Show(panel1.Parent, Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Accept new settings. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OkBtn_Click(object sender, EventArgs e) { try { if (TemplateCb.SelectedItem == null) { throw new Exception("Invalid target."); } target = (GXDeviceTemplate)TemplateCb.SelectedItem; Index = UInt16.Parse(IndexTb.Text); Count = UInt16.Parse(CountTb.Text); } catch (Exception ex) { DialogResult = DialogResult.None; MessageBox.Show(this, ex.Message, "Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void TemplatesView_SelectedIndexChanged(object sender, EventArgs e) { try { if (TemplatesView.SelectedItems.Count == 1) { PropertiesView.Items.Clear(); GXDeviceTemplate meter = (GXDeviceTemplate)TemplatesView.SelectedItems[0].Tag; if (meter.Objects != null) { foreach (GXObjectTemplate it in meter.Objects) { GXDLMSObject obj = GXDLMSClient.CreateObject((ObjectType)it.ObjectType); foreach (GXAttributeTemplate a in it.Attributes) { ListViewItem li = PropertiesView.Items.Add(it.Name); li.SubItems.Add(it.LogicalName); li.SubItems.Add(((ObjectType)it.ObjectType).ToString()); if (string.IsNullOrEmpty(a.Name)) { a.Name = ((IGXDLMSBase)obj).GetNames()[a.Index - 1]; } li.SubItems.Add(a.Index.ToString() + ": " + a.Name); li.SubItems.Add(a.DataType == 0 ? "" : ((DataType)a.DataType).ToString()); li.SubItems.Add(a.UIDataType == 0 ? "" : ((DataType)a.UIDataType).ToString()); if (a.ExpirationTime == 0xFFFFFFFF) { li.SubItems.Add("Static"); } else { li.SubItems.Add(a.ExpirationTime == 0 ? "" : TimeSpan.FromSeconds(a.ExpirationTime).ToString()); } li.Tag = a; } } } } } catch (Exception Ex) { MessageBox.Show(panel1.Parent, Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ActionResult <UpdateDeviceTemplateResponse> Post(UpdateDeviceTemplate request) { GXDeviceTemplate dev = request.Device; if (dev == null) { return(BadRequest("Device is null.")); } bool newDevice = dev.Id == 0; if (dev.DeviceSystemTitle != null) { dev.DeviceSystemTitle = dev.DeviceSystemTitle.Replace(" ", ""); } if (dev.AuthenticationKey != null) { dev.AuthenticationKey = dev.AuthenticationKey.Replace(" ", ""); } if (dev.BlockCipherKey != null) { dev.BlockCipherKey = dev.BlockCipherKey.Replace(" ", ""); } dev.Generation = DateTime.Now; if (newDevice) { //Add new DC. List <GXObjectTemplate> tmp = dev.Objects; dev.Objects = null; DateTime now = DateTime.Now; dev.Generation = now; host.Connection.Insert(GXInsertArgs.Insert(dev)); if (tmp != null) { //Add default objects. foreach (GXObjectTemplate it in tmp) { List <GXAttributeTemplate> tmp2 = it.Attributes; it.Attributes = null; it.DeviceTemplateId = dev.Id; it.Generation = now; host.Connection.Insert(GXInsertArgs.Insert(it)); if (it.Attributes != tmp2) { foreach (GXAttributeTemplate a in tmp2) { a.Generation = now; a.ObjectTemplateId = it.Id; } host.Connection.Insert(GXInsertArgs.InsertRange(tmp2)); } } } host.SetChange(TargetType.Object, DateTime.Now); } else { host.Connection.Update(GXUpdateArgs.Update(dev)); host.SetChange(TargetType.DeviceTemplate, DateTime.Now); } return(new UpdateDeviceTemplateResponse() { DeviceId = dev.Id }); }