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(); }
public void cellButtonClick(object sender, CellClickEventArgs e) { Debug.WriteLine(String.Format("Button clicked: ({0}, {1}, {2})", e.RowIndex, e.SubItem, e.Model)); // Take some action on e.Model based on which button (e.ColumnIndex) was clicked ShieldProperty property = (ShieldProperty)e.Model; if (property.Name.Equals(property_TemperatureSensor_Temperature)) { Shield shield = shields.shieldFromNodeId(property.NodeId); shield.sendSensorsStatus(); } else if (property.Name.Equals(property_ShieldId)) { Shield shield = shields.shieldFromNodeId(property.NodeId); shield.registerShield(); } else if (property.Name.Equals(property_Enabled)) { Shield shield = shields.shieldFromNodeId(property.ShieldNodeId); if (shield != null) { Sensor sensor = (Sensor)shield.sensorFromNodeId(property.NodeId); if (sensor != null) { sensor.enabled = !sensor.enabled; if (sensor.enabled) { property.Value = "true"; property.Action = "Disable"; } else { property.Value = "false"; property.Action = "Enable"; } shield.sendSensorsStatus(); } } } else if (property.Name.Equals(property_DoorSensor_Open)) { Shield shield = shields.shieldFromNodeId(property.ShieldNodeId); DoorSensor doorSensor = (DoorSensor)shield.sensorFromNodeId(property.NodeId); doorSensor.setStatusOpen(!doorSensor.getStatusOpen()); if (doorSensor.getStatusOpen()) { property.Value = "open"; property.Action = "close"; } else { property.Value = "closed"; property.Action = "open"; } shield.sendSensorsStatus(); } // If something about the object changed, you probably want to refresh the model this.objectListView1.RefreshObject(e.Model); //this.objectListView1.Update(); //this.objectListView1.SetObjects(propertyList); //this.objectListView1.Refresh(); }