private void cmdOK_Click(object sender, EventArgs e)
        {
            SqlTableSizeCollectorEntry selectedEntry = (SqlTableSizeCollectorEntry)SelectedEntry;

            selectedEntry.SqlServer          = txtServer.Text;
            selectedEntry.Database           = cboDatabase.Text;
            selectedEntry.IntegratedSecurity = chkIntegratedSec.Checked;
            selectedEntry.UserName           = txtUserName.Text;
            selectedEntry.Password           = txtPassword.Text;
            selectedEntry.SqlCmndTimeOutSec  = (int)numericUpDownCmndTimeOut.Value;
            selectedEntry.Tables.Clear();
            foreach (ListViewItem lvi in lvwTables.CheckedItems)
            {
                TableSizeEntry tse = new TableSizeEntry()
                {
                    TableName    = lvi.Text,
                    WarningValue = int.Parse(lvi.SubItems[1].Text),
                    ErrorValue   = int.Parse(lvi.SubItems[2].Text),
                    RowCount     = int.Parse(lvi.SubItems[3].Text)
                };
                selectedEntry.Tables.Add(tse);
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
        private void LoadTables()
        {
            try
            {
                string serverName   = ApplyConfigVarsOnField(txtServer.Text);
                string databaseName = ApplyConfigVarsOnField(cboDatabase.Text);
                string username     = ApplyConfigVarsOnField(txtUserName.Text);
                string password     = ApplyConfigVarsOnField(txtPassword.Text);

                if (serverName.Trim().Length > 0 && databaseName.Length > 0)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    lvwTables.Items.Clear();
                    List <TableSizeInfo> tables = SqlTableSizeCollectorEntry.GetAllTableRowCounts(serverName, databaseName, chkIntegratedSec.Checked, username, password, (int)numericUpDownCmndTimeOut.Value);
                    foreach (var table in tables)
                    {
                        ListViewItem lvi = new ListViewItem(table.Name);
                        lvi.SubItems.Add("0");
                        lvi.SubItems.Add("0");
                        lvi.SubItems.Add(table.Rows.ToString());
                        lvi.Tag = table;

                        SqlTableSizeCollectorEntry selectedEntry = (SqlTableSizeCollectorEntry)SelectedEntry;

                        if (selectedEntry != null && selectedEntry.Tables != null)
                        {
                            TableSizeEntry tse = (from t in selectedEntry.Tables
                                                  where t.TableName.ToLower() == table.Name.ToLower()
                                                  select t).FirstOrDefault();
                            if (tse != null)
                            {
                                lvi.Checked          = true;
                                lvi.SubItems[1].Text = tse.WarningValue.ToString();
                                lvi.SubItems[2].Text = tse.ErrorValue.ToString();
                            }
                        }
                        lvwTables.Items.Add(lvi);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Loading tables", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            Cursor.Current = Cursors.Default;
        }