Esempio n. 1
0
 public MovingAverageWrapper(MovingAverage movingAverage, ViewerListViewItem viewerListViewItem, Collector collector)
 {
     MovingAverage      = movingAverage;
     ViewerListViewItem = viewerListViewItem;
     Collector          = collector;
 }
        private bool ValidateStatistics(Control control)
        {
            bool errorOccurred = false;

            Debug.Assert(errorProvider != null, "ValidateStatistics - errorProvider not set.");

            if (lvCollectors.SelectedItems.Count < 1)
            {
                return(false);
            }

            errorProvider.SetError(control, "");

            Collector collector = ((CollectorListViewItem)lvCollectors.SelectedItems[0]).Collector;

            switch (control.Name)
            {
            case "rbAvgHide":
            case "rbAvgWatts":
            case "rbAvgWkg":
                try
                {
                    RadioButton b = (RadioButton)control;

                    if (b.Checked)
                    {
                        collector.FieldAvgDesc = (string)b.Tag;
                    }
                }
                catch (Exception ex)
                {
                    errorProvider.SetError(control, ex.Message);
                    errorOccurred = true;
                }
                break;

            case "rbAvgMaxHide":
            case "rbAvgMaxWatts":
            case "rbAvgMaxWkg":
                try
                {
                    RadioButton b = (RadioButton)control;

                    if (b.Checked)
                    {
                        collector.FieldAvgMaxDesc = (string)b.Tag;
                    }
                }
                catch (Exception ex)
                {
                    errorProvider.SetError(control, ex.Message);
                    errorOccurred = true;
                }
                break;

            case "rbFtpHide":
            case "rbFtpWatts":
            case "rbFtpWkg":
                try
                {
                    RadioButton b = (RadioButton)control;

                    if (b.Checked)
                    {
                        collector.FieldFtpDesc = (string)b.Tag;
                    }
                }
                catch (Exception ex)
                {
                    errorProvider.SetError(control, ex.Message);
                    errorOccurred = true;
                }
                break;


            default:
                Debug.Assert(1 == 0, $"Unknown control {control.Name} passed to validate method.");
                break;
            }

            return(errorOccurred);
        }
            //public CollectorListViewItem() : base(new string[] { "*** New Collector ***" })
            //{
            //    m_collector = new Collector();
            //}

            public CollectorListViewItem(Collector collector) : base(SubItemStrings(collector))
            {
                m_collector = (Collector)collector.Clone();
            }
        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;
                }
            }
        }