// When the Add button is clicked, // the form for adding a monitoring item opens private void btnAdd_Click(object sender, EventArgs e) { SimpleQueryEditor simpleEditor = new SimpleQueryEditor(true); simpleEditor.MyQueryManager = this; simpleEditor.ShowDialog(); }
// Edit an existing monitored item // Don't allow editing of active (running) items private void btnEdit_Click(object sender, EventArgs e) { if (lstMonitoringItems.SelectedItems.Count == 1) { MonitoringItem item = null; MyEventViewer.MonitoringItems.TryGetValue( lstMonitoringItems.SelectedItems[0].Text, out item); if (item.State != MonitoringItemState.Running) { SimpleQueryEditor simpleEditor = new SimpleQueryEditor(false); simpleEditor.Controls["txtName"].Text = item.Name; simpleEditor.Controls["txtQuery"].Text = item.WqlQuery.QueryString; simpleEditor.MyQueryManager = this; simpleEditor.ShowDialog(); } else { MessageBox.Show("You need to stop monitoring" + " before you can edit an item properties."); } } }
private void finishButton_Click(object sender, EventArgs e) { string exitChoice = null; foreach (RadioButton radio in GetActivePage().Controls["groupExitOptions"].Controls) { if (radio.Checked) { exitChoice = radio.Name; } } switch (exitChoice) { case "radioAdd": MonitoringItem item = new MonitoringItem( Query, NewItemName(GetActivePage().Controls["txtQueryName"].Text)); MyParent.MyEventViewer.AddItemToDictionary(item.Name, item); MyParent.AddItemToListView(item); MyParent.UpdateQueryListView(); MyParent.lstMonitoringItems.Items[item.Name].Selected = true; break; case "radioEdit": SimpleQueryEditor simpleEditor = new SimpleQueryEditor(true); simpleEditor.MyQueryManager = MyParent; simpleEditor.Controls["txtName"].Text = GetActivePage().Controls["txtQueryName"].Text; simpleEditor.Controls["txtQuery"].Text = Query.QueryString; simpleEditor.ShowDialog(); break; case "radioClose": break; } }