private void DataPointDialog_FormClosing(object sender, FormClosingEventArgs e) { try { if (e.Cancel) { return; } else { DialogHMData dataPointDialog = sender as DialogHMData; Stopwatch sw = new Stopwatch(); if (dataPointDialog != null && dataPointDialog.ValueWasSet && dataPointDialog.HMElement != null) { bool wasSuccessful = false; if (dataPointDialog.HMElement.GetType() == typeof(HMSystemVariable)) { sw.Start(); wasSuccessful = hmWrapper.SetVariable(dataPointDialog.HMElement, dataPointDialog.ValueToSet); sw.Stop(); } else if (dataPointDialog.HMElement.GetType() == typeof(HMDeviceChannel) || dataPointDialog.HMElement.GetType() == typeof(HMDeviceDataPoint)) { sw.Start(); wasSuccessful = hmWrapper.SetState(dataPointDialog.HMElement, dataPointDialog.ValueToSet); sw.Stop(); } else { WriteStatus(String.Format("Was not able to operate a type of {0}", dataPointDialog.HMElement.GetType().Name), null, 0); return; } WriteStatus(String.Format("Operation of {0} {1}", dataPointDialog.HMElement.GetType().Name, wasSuccessful ? "successful" : "failed"), String.Format("- OPERATE({0}) @ {1}: Executed in {2}ms", dataPointDialog.HMElement.Address, DateTime.Now, sw.ElapsedMilliseconds), sw.ElapsedMilliseconds); RefreshTreeView(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error operating channel...", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void treeView_DoubleClick(object sender, EventArgs e) { try { if (treeView.SelectedNode != null && treeView.SelectedNode.Tag != null) { HMBase hmElement = treeView.SelectedNode.Tag as HMBase; if (hmElement != null) { DialogHMData dataPointDialog = new DialogHMData(hmElement); dataPointDialog.FormClosing += DataPointDialog_FormClosing; dataPointDialog.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error obtaining Homematic element...", MessageBoxButtons.OK, MessageBoxIcon.Error); } }