コード例 #1
0
        public void ReadConfiguration(XmlDocument config)
        {
            XmlElement root = config.DocumentElement;

            DatabaseEntries.Clear();
            foreach (XmlElement databaseNode in root.SelectNodes("databases/database"))
            {
                DatabaseEntry databaseEntry = new DatabaseEntry();
                databaseEntry.Name               = databaseNode.ReadXmlElementAttr("name", "");
                databaseEntry.SqlServer          = databaseNode.ReadXmlElementAttr("server", "");
                databaseEntry.IntegratedSecurity = bool.Parse(databaseNode.ReadXmlElementAttr("integratedSec", "True"));
                databaseEntry.UserName           = databaseNode.ReadXmlElementAttr("userName", "");
                databaseEntry.Password           = databaseNode.ReadXmlElementAttr("password", "");

                foreach (XmlElement tableNode in databaseNode.SelectNodes("table"))
                {
                    TableSizeEntry tableSizeEntry = new TableSizeEntry();
                    tableSizeEntry.TableName    = tableNode.ReadXmlElementAttr("name", "");
                    tableSizeEntry.WarningValue = long.Parse(tableNode.ReadXmlElementAttr("warningValue", "1"));
                    tableSizeEntry.ErrorValue   = long.Parse(tableNode.ReadXmlElementAttr("errorValue", "2"));
                    databaseEntry.TableSizeEntries.Add(tableSizeEntry);
                }
                DatabaseEntries.Add(databaseEntry);
            }
        }
コード例 #2
0
ファイル: EditTableSizeEntry.cs プロジェクト: utobe/QuickMon
        private void LoadTables()
        {
            string sql = "select t.name, i.[rows] from sys.sysindexes i inner join sys.tables t on t.object_id = i.id where i.indid in (0, 1, 255) order by t.name";

            try
            {
                lvwTables.Items.Clear();
                if (cboDatabase.Text.Length > 0)
                {
                    SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
                    scsb.DataSource         = txtServer.Text;
                    scsb.InitialCatalog     = cboDatabase.Text;
                    scsb.IntegratedSecurity = chkIntegratedSec.Checked;
                    scsb.UserID             = txtUserName.Text;
                    scsb.Password           = txtPassword.Text;
                    using (SqlConnection conn = new SqlConnection(scsb.ConnectionString))
                    {
                        conn.Open();
                        using (SqlCommand cmnd = new SqlCommand(sql, conn))
                        {
                            cmnd.CommandType = CommandType.Text;
                            using (SqlDataReader r = cmnd.ExecuteReader())
                            {
                                while (r.Read())
                                {
                                    string         tableName    = r[0].ToString();
                                    long           currentCount = long.Parse(r[1].ToString());
                                    long           warning      = 0;
                                    long           error        = 0;
                                    ListViewItem   lvi          = new ListViewItem(tableName);
                                    TableSizeEntry table        = (from t in DatabaseEntry.TableSizeEntries
                                                                   where t.TableName == tableName
                                                                   select t).FirstOrDefault();
                                    if (table != null)
                                    {
                                        warning     = table.WarningValue;
                                        error       = table.ErrorValue;
                                        lvi.Checked = true;
                                    }
                                    lvi.SubItems.Add(warning.ToString());
                                    lvi.SubItems.Add(error.ToString());
                                    lvi.SubItems.Add(currentCount.ToString());
                                    lvwTables.Items.Add(lvi);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            CheckOKEnabled();
        }
コード例 #3
0
ファイル: EditTableSizeEntry.cs プロジェクト: utobe/QuickMon
 private void cmdOK_Click(object sender, EventArgs e)
 {
     DatabaseEntry.TableSizeEntries   = new List <TableSizeEntry>();
     DatabaseEntry.SqlServer          = txtServer.Text;
     DatabaseEntry.IntegratedSecurity = chkIntegratedSec.Checked;
     DatabaseEntry.UserName           = txtUserName.Text;
     DatabaseEntry.Password           = txtPassword.Text;
     DatabaseEntry.Name = cboDatabase.Text;
     foreach (ListViewItem lvi in lvwTables.CheckedItems)
     {
         TableSizeEntry tableSizeEntry = new TableSizeEntry();
         tableSizeEntry.TableName    = lvi.Text;
         tableSizeEntry.WarningValue = long.Parse(lvi.SubItems[1].Text);
         tableSizeEntry.ErrorValue   = long.Parse(lvi.SubItems[2].Text);
         DatabaseEntry.TableSizeEntries.Add(tableSizeEntry);
     }
     DialogResult = System.Windows.Forms.DialogResult.OK;
     Close();
 }