private void DeviceManagement_FormClosed(object sender, FormClosedEventArgs e) { var objChanged = new ObjChanged(); objChanged.ListBlockIdChanged = new List <int>(); objChanged.ListSensorIdChanged = new List <int>(); foreach (TabPage tab in tabMngt.Controls) { var device = (tab.Controls.Count > 0 ? tab.Controls[0] : null) as DeviceLayout; if (device != null) { if (device.BlockChange != null) { objChanged.ListBlockIdChanged.Add(device.BlockChange.BlockId); } if (device.ListSensorChange != null && device.ListSensorChange.Count > 0) { objChanged.ListSensorIdChanged.AddRange(device.ListSensorChange.Select(i => i.SensorId)); } } } objChanged.ListBlockIdChanged = objChanged.ListBlockIdChanged.Distinct().ToList(); objChanged.ListSensorIdChanged = objChanged.ListSensorIdChanged.Distinct().ToList(); this.ResultData = objChanged; }
private void OnSettingChanged(object sender, EventArgs e) { ObjChanged obj = sender as ObjChanged; Block bl = this.Tag as Block; if (obj.ListBlockIdChanged.Contains(bl.BlockId)) { Block blUpdate = AppManager.ListBlock.FirstOrDefault(b => b.BlockId == bl.BlockId); this.Tag = blUpdate; RefreshBlockInfo(); } }
private void OnSettingChanged(object sender, EventArgs e) { ObjChanged obj = sender as ObjChanged; SensorInfo info = this.Tag as SensorInfo; if (obj.ListSensorIdChanged.Contains(info.SensorId)) { SensorInfo sensorUpdate = AppManager.ListSensor.FirstOrDefault(i => i.SensorId == info.SensorId); this.Tag = sensorUpdate; DrawValue(sensorUpdate); } }
private void UpdateInfoChanged(ObjChanged objChanged) { if (objChanged == null) { return; } var lstBlockActive = AppManager.ListBlock.Where(i => i.Active == (int)clsConst.emBlockStatus.Active).OrderBy(i => i.BlockId).ToList(); if (lstBlockActive != null && lstBlockActive.Count > 0) { BlockActiceId = lstBlockActive.First().BlockId; lblBlockName.Text = lstBlockActive.First().BlockName; this.UpdateChildControl(plnLocation, clsConst.PREFIX_BTN_BLOCK + BlockActiceId, (c) => { c.Text = lstBlockActive.First().BlockName; btnBlock_Click((Button)c, null); }); } if (objChanged.ListBlockIdChanged != null) { var listBlockUpdate = AppManager.ListBlock.Where(i => objChanged.ListBlockIdChanged.Contains(i.BlockId)); var listSensorUpdate = AppManager.ListSensor.Where(i => objChanged.ListSensorIdChanged.Contains(i.SensorId)); foreach (var sensor in listSensorUpdate) { this.UpdateSafeControl(tabGraphMain, (c) => { var objChildControl = _plnMain.Controls.ContainsKey(clsConst.PREFIX_LBL_SENSOR + sensor.SensorId) ? _plnMain.Controls[clsConst.PREFIX_LBL_SENSOR + sensor.SensorId] : null; if (objChildControl != null) { objChildControl.Text = sensor.SensorName; objChildControl.BackColor = sensor.Active == (int)clsConst.emBlockStatus.Active ? Color.DarkCyan : Color.DarkGray; } }); } foreach (var block in listBlockUpdate) { this.UpdateChildControl(plnLocation, clsConst.PREFIX_BTN_BLOCK + block.BlockId, (c) => { c.Text = block.BlockName; if (block.Active == (int)clsConst.emBlockStatus.Inactive) { c.BackColor = btnUpdate.BackColor; } c.Enabled = block.Active == (int)clsConst.emBlockStatus.Active ? true : false; }); this.UpdateSafeControl(tabGraphMain, (c) => { var objChildControl = _plnMain.Controls.ContainsKey(clsConst.PREFIX_LBL_BLOCK + block.BlockId) ? _plnMain.Controls[clsConst.PREFIX_LBL_BLOCK + block.BlockId] : null; if (objChildControl != null) { objChildControl.Text = block.BlockName; //objChildControl.BackColor = block.Active == (int)clsConst.emBlockStatus.Active ? Color.DarkCyan : Color.DarkGray; if (block.Active == (int)clsConst.emBlockStatus.Active) { objChildControl.BackColor = Color.DarkCyan; } else { objChildControl.BackColor = Color.DarkGray; var listSensor = AppManager.ListSensor.Where(i => i.OfBlock == block.BlockId).ToList(); foreach (var sensor in listSensor) { this.UpdateSafeControl(tabGraphMain, (s) => { var objSensorControl = _plnMain.Controls.ContainsKey(clsConst.PREFIX_LBL_SENSOR + sensor.SensorId) ? _plnMain.Controls[clsConst.PREFIX_LBL_SENSOR + sensor.SensorId] : null; if (objSensorControl != null) { objSensorControl.BackColor = Color.DarkGray; } }); } } } }); } Application.DoEvents(); } }