private void btnStatsCancel_Click(object sender, EventArgs e) { ZAMsettings.RollbackCachedConfiguration(); errorProvider.Clear(); if (lvCollectors.SelectedItems.Count > 0) { CollectorListViewItem itemBeingEdited = (CollectorListViewItem)lvCollectors.SelectedItems[0]; Collector userBeingEdited = itemBeingEdited.Collector; // If a newly added row, remove it and select the first one in list if (1 == 0) { //lvCollectors.Items.Remove(itemBeingEdited); //if (lvCollectors.Items.Count > 0) //{ // lvCollectors.Items[0].Selected = true; //} } else { // Refresh user from rolled back configuration Collector refreshCollector = ZAMsettings.Settings.Collectors[userBeingEdited.Name]; Collectors_LoadFields(refreshCollector); // This will clone the Collector so that the listview doesn't have a direct link to the configuration itemBeingEdited.Collector = refreshCollector; } } EditingCollectors = false; }
private void btnStatsSave_Click(object sender, EventArgs e) { bool errorOccurred = false; // this should not happen if (lvCollectors.SelectedItems.Count < 1) { ZAMsettings.RollbackCachedConfiguration(); EditingCollectors = false; return; } CollectorListViewItem itemBeingEdited = (CollectorListViewItem)lvCollectors.SelectedItems[0]; Collector collectorBeingEdited = itemBeingEdited.Collector; errorOccurred = (errorOccurred || ValidateStatistics(rbAvgHide)); errorOccurred = (errorOccurred || ValidateStatistics(rbAvgWatts)); errorOccurred = (errorOccurred || ValidateStatistics(rbAvgWkg)); errorOccurred = (errorOccurred || ValidateStatistics(rbAvgMaxHide)); errorOccurred = (errorOccurred || ValidateStatistics(rbAvgMaxWatts)); errorOccurred = (errorOccurred || ValidateStatistics(rbAvgMaxWkg)); errorOccurred = (errorOccurred || ValidateStatistics(rbFtpHide)); errorOccurred = (errorOccurred || ValidateStatistics(rbFtpWatts)); errorOccurred = (errorOccurred || ValidateStatistics(rbFtpWkg)); if (!errorOccurred) { try { // Add or Update the Collector dictionary in the configuration. ZAMsettings.Settings.UpsertCollector(collectorBeingEdited); ZAMsettings.CommitCachedConfiguration(); lvCollectors.BeginUpdate(); // Refresh the fields and the list view Collectors_LoadFields(collectorBeingEdited); itemBeingEdited.Refresh(); //CollectorListViewItem lvi = new CollectorListViewItem(collectorBeingEdited); //lvCollectors.Items.Add(lvi); //lvi.Selected = true; //lvCollectors.Items.Remove(itemBeingEdited); lvCollectors.EndUpdate(); } catch (Exception ex) { MessageBox.Show("Exception occurred: " + ex.ToString(), "Error saving Collector", MessageBoxButtons.OK, MessageBoxIcon.Warning); errorOccurred = true; } finally { EditingCollectors = false; } } }