private void cmdOK_Click(object sender, EventArgs e)
        {
            SqlDatabaseSizeEntry selectedEntry;

            if (SelectedEntry != null)
            {
                selectedEntry = (SqlDatabaseSizeEntry)SelectedEntry;
            }
            else if (SelectedSqlDatabaseSizeEntry != null)
            {
                selectedEntry = (SqlDatabaseSizeEntry)SelectedSqlDatabaseSizeEntry;
            }
            else
            {
                selectedEntry = new SqlDatabaseSizeEntry();
                SelectedEntry = selectedEntry;
            }

            selectedEntry.SqlServer          = txtServer.Text;
            selectedEntry.IntegratedSecurity = chkIntegratedSec.Checked;
            selectedEntry.UserName           = txtUserName.Text;
            selectedEntry.Password           = txtPassword.Text;
            selectedEntry.SqlCmndTimeOutSec  = (int)numericUpDownCmndTimeOut.Value;
            selectedEntry.Database           = cboDatabase.Text;
            selectedEntry.WarningSizeMB      = (int)warningNumericUpDown.Value;
            selectedEntry.ErrorSizeMB        = (int)errorNumericUpDown.Value;
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
        public override void OKClicked()
        {
            if (SelectedConfig == null)
            {
                SelectedConfig = new SqlDatabaseSizeCollectorConfig();
            }
            SqlDatabaseSizeCollectorConfig sqlDbSizeConfig = (SqlDatabaseSizeCollectorConfig)SelectedConfig;

            sqlDbSizeConfig.Entries.Clear();
            foreach (ListViewItem lvi in lvwEntries.Items)
            {
                SqlDatabaseSizeEntry sqlDBSizeEntry = (SqlDatabaseSizeEntry)lvi.Tag;
                sqlDbSizeConfig.Entries.Add(sqlDBSizeEntry);
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
 private void cmdTest_Click(object sender, EventArgs e)
 {
     try
     {
         SqlDatabaseSizeEntry test = new SqlDatabaseSizeEntry();
         test.SqlServer          = txtServer.Text;
         test.Database           = cboDatabase.Text;
         test.IntegratedSecurity = chkIntegratedSec.Checked;
         test.UserName           = txtUserName.Text;
         test.Password           = txtPassword.Text;
         test.SqlCmndTimeOutSec  = (int)numericUpDownCmndTimeOut.Value;
         test.WarningSizeMB      = (int)warningNumericUpDown.Value;
         test.ErrorSizeMB        = (int)errorNumericUpDown.Value;
         long currentSize = test.GetDBSize();
         MessageBox.Show(string.Format("Current database size: {0} MB", currentSize), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        //public List<SqlDatabaseSizeEntry> Entries = new List<SqlDatabaseSizeEntry>();

        #region IAgentConfig Members
        public void ReadConfiguration(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            XmlElement root = config.DocumentElement;

            Entries.Clear();
            foreach (XmlElement databaseNode in root.SelectNodes("databases/database"))
            {
                SqlDatabaseSizeEntry databaseEntry = new SqlDatabaseSizeEntry();
                databaseEntry.Database           = databaseNode.ReadXmlElementAttr("name", "");
                databaseEntry.SqlServer          = databaseNode.ReadXmlElementAttr("server", "");
                databaseEntry.IntegratedSecurity = databaseNode.ReadXmlElementAttr("integratedSec", true);
                databaseEntry.UserName           = databaseNode.ReadXmlElementAttr("userName", "");
                databaseEntry.Password           = databaseNode.ReadXmlElementAttr("password", "");
                databaseEntry.SqlCmndTimeOutSec  = databaseNode.ReadXmlElementAttr("sqlCmndTimeOutSec", 30);
                databaseEntry.WarningSizeMB      = databaseNode.ReadXmlElementAttr("warningValueMB", 1024);
                databaseEntry.ErrorSizeMB        = databaseNode.ReadXmlElementAttr("errorValueMB", 4096);
                Entries.Add(databaseEntry);
            }
        }
 public override void RefreshDisplayData()
 {
     try
     {
         lvwEntries.BeginUpdate();
         Cursor.Current = Cursors.WaitCursor;
         foreach (ListViewItem lvi in lvwEntries.Items)
         {
             SqlDatabaseSizeEntry dbSizeEntry = (SqlDatabaseSizeEntry)lvi.Tag;
             long size = dbSizeEntry.GetDBSize();
             lvi.SubItems[1].Text = size.ToString();
             CollectorState currentState = dbSizeEntry.GetState(size);
             if (currentState == CollectorState.Good)
             {
                 lvi.ImageIndex = 0;
             }
             else if (currentState == CollectorState.Warning)
             {
                 lvi.ImageIndex = 1;
             }
             else
             {
                 lvi.ImageIndex = 2;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Refresh", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         Cursor.Current = Cursors.Default;
         lvwEntries.EndUpdate();
     }
     base.RefreshDisplayData();
 }