private void configurationTreeView_AfterSelect(object sender, TreeViewEventArgs e) { AFTreeNode node = (AFTreeNode)e.Node; AFElement selectedCalculation = (AFElement)node.AFObject; if (!selectedCalculation.IsRoot) { calculationName.Text = selectedCalculation.Name; CalculationPreference preference = CalculationPreference.CalculationPreferenceFromJSON((string)selectedCalculation.Attributes["configuration"].GetValue().Value); queryTextBox.Text = preference.eventFrameQuery; Dictionary <AFAttributeTrait, string> limitCalculations = preference.getTraitDictionary(); foreach (AFAttributeTrait trait in AFAttributeTrait.AllLimits) { ComboBox comboBox = (ComboBox)panel1.Controls[trait.Name]; comboBox.Text = "None"; } foreach (KeyValuePair <AFAttributeTrait, string> pair in limitCalculations) { ComboBox comboBox = (ComboBox)panel1.Controls[pair.Key.Name]; comboBox.Text = pair.Value; } offsetSetting.Text = preference.offset.ToString(); AFAttribute sensor = AFAttribute.FindAttribute(preference.sensorPath, db); afDatabasePicker.AFDatabase = sensor.Database; afTreeView.AFRoot = sensor.Database.Elements; afTreeView.AFSelect(sensor, db, preference.sensorPath); afTreeView.SelectedNode.EnsureVisible(); afTreeView.Focus(); } }
private void addToPreference_Click(object sender, EventArgs e) { if (calculationName.Text == "") { MessageBox.Show("Please specify the name of the calculation", "No Name specified", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } AFTreeNode node = (AFTreeNode)afTreeView.SelectedNode; string path = node.AFPath; if (path == "" || path == null) { MessageBox.Show("Please select a attribute", "No attribute specified", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string query = queryTextBox.Text; double offset = Convert.ToDouble(offsetSetting.Text); Dictionary <string, string> limits = new Dictionary <string, string> { }; foreach (AFAttributeTrait limit in AFAttributeTrait.AllLimits) { ComboBox comboBox = (ComboBox)panel1.Controls[limit.Name]; if (comboBox.Text != "None") { limits[limit.Name] = comboBox.Text; } } CalculationPreference preference = new CalculationPreference(path, query, offset, limits); AFElement preferenceRoot = ((AFElement)configurationTreeView.AFRoot); AFValue configurationValue = new AFValue(preference.JSON()); AFElement preferenceElement = preferenceRoot.Elements[calculationName.Text]; if (preferenceElement == null) { preferenceElement = new AFElement(calculationName.Text); preferenceElement.Attributes.Add("Configuration"); preferenceElement.Attributes["Configuration"].Type = typeof(string); preferenceRoot.Elements.Add(preferenceElement); preferenceRoot.CheckIn(); } preferenceElement.Attributes["Configuration"].SetValue(configurationValue); preferenceElement.CheckIn(); configurationTreeView.Refresh(); configurationTreeView.AFSelect(preferenceElement, preferenceElement.Database, preferenceElement.GetPath()); }
private void button1_Click(object sender, EventArgs e) { AFTreeNode node = (AFTreeNode)afTreeView.SelectedNode; string path = node.AFPath; MessageBox.Show($"{node.AFObject.GetType()}"); if (path != "" && path != null) { try { afAttributesPage1.AFAttribute = (AFAttribute)node.AFObject; } catch (InvalidCastException) { // 属性では無かった } } }