protected void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { //currentNode = null; this.objectListView1.ClearObjects(); propertyList = new List <ShieldProperty>(); currentNode = e.Node; if (e.Node is ShieldTreeNode) { ShieldTreeNode node = (ShieldTreeNode)e.Node; Shield shield = shields.shieldFromNodeId((String)node.Tag); // name ShieldProperty sp = new ShieldProperty(); sp.Name = property_ShieldName; sp.Description = "Shield name"; sp.Value = shield.shieldName; propertyList.Add(sp); // started sp = new ShieldProperty(); sp.Name = property_ShieldStarted; sp.Description = "Scheda avviata"; if (shield.started) { sp.Value = "Started"; } else { sp.Value = "Not Started"; } propertyList.Add(sp); objectListView1.DisableObject(sp); // id sp = new ShieldProperty(); sp.Name = property_ShieldId; sp.Description = "Shield id"; sp.Value = "" + shield.id; sp.Action = "register"; propertyList.Add(sp); // port sp = new ShieldProperty(); sp.Name = property_Port; sp.Description = "local port"; sp.Value = "" + shield.localPort; propertyList.Add(sp); // mac addrress sp = new ShieldProperty(); sp.Name = property_MACAddress; sp.Description = "MAC Address"; sp.Value = shield.MACAddress; propertyList.Add(sp); // temperaturesensorsenabled sp = new ShieldProperty(); sp.Name = property_TemperatureSensorEnabled; sp.Description = "Temperature sensor enabled"; if (shield.temperatureSensorsEnabled) { sp.Value = "Enabled"; } else { sp.Value = "Disabled"; } propertyList.Add(sp); } else if (e.Node is SensorTreeNode) { SensorTreeNode node = (SensorTreeNode)e.Node; Shield shield = shields.shieldFromNodeId(node.shieldNodeId); Sensor sensor = shield.sensorFromNodeId((String)node.Tag); ShieldProperty sp = new ShieldProperty(); sp.ShieldNodeId = node.shieldNodeId; sp.NodeId = (String)node.Tag; sp.Name = property_SensorName; sp.Description = "Sensor name"; sp.Value = sensor.sensorname; propertyList.Add(sp); sp = new ShieldProperty(); sp.ShieldNodeId = node.shieldNodeId; sp.NodeId = (String)node.Tag; sp.Name = property_Enabled; sp.Description = "Enabled"; if (sensor.enabled) { sp.Value = "true"; sp.Action = "Disable"; } else { sp.Value = "false"; sp.Action = "Enable"; } propertyList.Add(sp); if (sensor is DS18S20Sensor) { sp = new ShieldProperty(); sp.ShieldNodeId = node.shieldNodeId; sp.NodeId = (String)node.Tag; sp.Name = property_TemperatureSensor_Temperature; sp.Description = "Temperature"; DS18S20Sensor dsSensor = (DS18S20Sensor)sensor; sp.Value = "" + dsSensor.temperature; sp.Action = "Update"; propertyList.Add(sp); } else if (sensor is DoorSensor) { sp = new ShieldProperty(); sp.ShieldNodeId = node.shieldNodeId; sp.NodeId = (String)node.Tag; sp.Name = property_DoorSensor_Open; sp.Description = "Status"; DoorSensor doorSensor = (DoorSensor)sensor; if (doorSensor.getStatusOpen()) { sp.Value = "open"; sp.Action = "close"; } else { sp.Value = "closed"; sp.Action = "open"; } propertyList.Add(sp); } } else if (e.Node is ActuatorTreeNode) { ActuatorTreeNode node = (ActuatorTreeNode)e.Node; Shield shield = shields.shieldFromNodeId(node.shieldNodeId); Sensor actuator = shield.actuatorFromNodeId((String)node.Tag); ShieldProperty sp = new ShieldProperty(); sp.ShieldNodeId = node.shieldNodeId; sp.NodeId = (String)node.Tag; sp.Name = property_ActuatorName; sp.Description = "Actuator name"; sp.Value = actuator.sensorname; propertyList.Add(sp); } else if (e.Node is SettingsTreeNode) { SettingsTreeNode node = (SettingsTreeNode)e.Node; ShieldProperty sp = new ShieldProperty(); sp.Name = property_ServerIp; sp.Value = Settings.serverIpAddress; sp.Description = "Server Ip Address"; propertyList.Add(sp); sp = new ShieldProperty(); sp.Name = property_ServerPort; sp.Description = "Server Port"; sp.Value = "" + Settings.serverPort; propertyList.Add(sp); } this.objectListView1.SetObjects(propertyList); this.objectListView1.Refresh(); }
private void objectListView1_CellEditFinished(object sender, BrightIdeasSoftware.CellEditEventArgs e) { if (currentNode != null && e.Column.Text.Equals("Value")) { if (currentNode is ShieldTreeNode) { ShieldTreeNode node = (ShieldTreeNode)currentNode; Shield shield = shields.shieldFromNodeId((String)node.Tag); ShieldProperty property = (ShieldProperty)e.RowObject; if (property.Name.Equals(property_ShieldName)) { shield.shieldName = (string)e.NewValue; } else if (property.Name.Equals(property_MACAddress)) { shield.MACAddress = (string)e.NewValue; } else if (property.Name.Equals(property_Port)) { shield.localPort = (string)e.NewValue; } else if (property.Name.Equals(property_TemperatureSensorEnabled)) { if (e.NewValue.Equals("Enabled")) { shield.temperatureSensorsEnabled = true; } else { shield.temperatureSensorsEnabled = false; } } } else if (currentNode is SensorTreeNode) { SensorTreeNode node = (SensorTreeNode)currentNode; Shield shield = shields.shieldFromNodeId(node.shieldNodeId); Sensor sensor = shield.sensorFromNodeId((String)node.Tag); ShieldProperty property = (ShieldProperty)e.RowObject; if (property.Name.Equals(property_SensorName)) { sensor.sensorname = (string)e.NewValue; } else if (sensor is DS18S20Sensor) { DS18S20Sensor tempSensor = (DS18S20Sensor)sensor; if (property.Name.Equals(property_TemperatureSensor_Temperature)) { tempSensor.temperature = float.Parse((string)e.NewValue); } } } else if (currentNode is ActuatorTreeNode) { ActuatorTreeNode node = (ActuatorTreeNode)currentNode; Shield shield = shields.shieldFromNodeId(node.shieldNodeId); Sensor actuator = shield.sensorFromNodeId((String)node.Tag); ShieldProperty property = (ShieldProperty)e.RowObject; if (property.Name.Equals(property_ActuatorName)) { actuator.sensorname = (string)e.NewValue; } } else if (currentNode is SettingsTreeNode) { SettingsTreeNode node = (SettingsTreeNode)currentNode; ShieldProperty property = (ShieldProperty)e.RowObject; if (property.Name.Equals(property_ServerIp)) { Settings.serverIpAddress = (string)e.NewValue; Settings.serverIpAddress = (string)e.NewValue; } else if (property.Name.Equals(property_ServerPort)) { Settings.serverPort = Int32.Parse((string)e.NewValue); } } } }
private void InitializeTreeView() { treeView1.BeginUpdate(); treeView1.Nodes.Clear(); SettingsTreeNode settingsNode = new SettingsTreeNode("Settings"); settingsNode.settings = settings; settingsNode.ImageIndex = iconHome; settingsNode.SelectedImageIndex = iconHome; treeView1.Nodes.Add(settingsNode); foreach (Shield shield in shields.shieldList) { ShieldTreeNode shieldNode = new ShieldTreeNode(shield); shieldNode.Tag = shield.nodeId; if (shield.started) { shieldNode.ImageIndex = iconCheck; shieldNode.SelectedImageIndex = iconCheck; } else { shieldNode.ImageIndex = iconCancel; shieldNode.SelectedImageIndex = iconCancel; } foreach (Sensor sensor in shield.sensorList) { SensorTreeNode sensorNode = new SensorTreeNode(sensor); sensorNode.shieldNodeId = shield.nodeId; sensorNode.Tag = sensor.nodeId; int sensorIconIndex = 0; if (sensor is DS18S20Sensor) { sensorIconIndex = iconTemperature; } else if (sensor is DoorSensor) { sensorIconIndex = iconDoorSensor; } else if (sensor is CurrentSensor) { sensorIconIndex = iconCurrentSensor; } else if (sensor is PIRSensor) { sensorIconIndex = iconPIRSensor; } else if (sensor is HumiditySensor) { sensorIconIndex = iconHumiditySensor; } else if (sensor is PressureSensor) { sensorIconIndex = iconPressureSensor; } sensorNode.ImageIndex = sensorIconIndex; sensorNode.SelectedImageIndex = sensorIconIndex; shieldNode.Nodes.Add(sensorNode); } foreach (Sensor actuator in shield.actuatorList) { ActuatorTreeNode actuatorNode = new ActuatorTreeNode(actuator); actuatorNode.shieldNodeId = shield.nodeId; actuatorNode.Tag = actuator.nodeId; int sensorIconIndex = 0; if (actuator is Heater) { sensorIconIndex = iconHeater; } else if (actuator is ReleActuator) { sensorIconIndex = iconReleActuator; } actuatorNode.ImageIndex = sensorIconIndex; actuatorNode.SelectedImageIndex = sensorIconIndex; shieldNode.Nodes.Add(actuatorNode); } treeView1.Nodes[0].Nodes.Add(shieldNode); } treeView1.EndUpdate(); treeView1.ExpandAll(); }