Пример #1
0
 private void CaptionEvents()
 {
     try {
         Caption.MouseEnter += (s, e) => {
             try {
                 Caption.BackColor     = System.Drawing.Color.FromArgb(0x33, 0x33, 0x33);
                 LogInButton.BackColor = System.Drawing.Color.FromArgb(0x00, 0x7A, 0xCC);
             }
             catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
         };
         Caption.MouseLeave += (s, e) => {
             try {
                 Caption.BackColor     = PCaption.Drawing.BackColor;
                 LogInButton.BackColor = PLogInButton.Drawing.BackColor;
             }
             catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
         };
         Caption.Click += (s, e) => {
             try {
                 string                login    = CLogInForm.PTextBoxLogin.Text;
                 string                pass     = CLogInForm.PTextBoxPass.Text;
                 CDatabaseCon          DataConn = new CDatabaseCon();
                 System.Data.DataTable table    = new System.Data.DataTable();
                 MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter();
                 string com = "SELECT * FROM Права WHERE Логин = @UsLogin AND Пароль = @UsPass;";
                 MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand(com, DataConn.GetConnection());
                 command.Parameters.Add("@UsLogin", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = login;
                 command.Parameters.Add("@UsPass", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value  = pass;
                 adapter.SelectCommand = command;
                 adapter.Fill(table);
                 if (table.Rows.Count > 0)
                 {
                     CLogInPanel.PCaption.Text     = table.Rows[0].ItemArray[1].ToString();
                     CLogInForm.PTextBoxLogin.Text = "";
                     CLogInForm.PTextBoxPass.Text  = "";
                     LogInForm.LInForm.Close();
                 }
                 else
                 {
                     System.Windows.Forms.MessageBox.Show("Логин или пароль введены неверно", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                 }
             }
             catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
         };
     }
     catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
 }
Пример #2
0
        private void BorderEventrs()
        {
            try {
                CDatabaseCon DataConn = new CDatabaseCon();
                MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter();
                System.Data.DataTable table = new System.Data.DataTable();
                string com = "SHOW TABLES;";
                MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand(com, DataConn.GetConnection());
                adapter.SelectCommand = command;
                adapter.Fill(table);

                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        labels.Add(new System.Windows.Forms.Label()
                        {
                            AutoSize  = false,
                            Size      = new System.Drawing.Size(250, 23),
                            Location  = new System.Drawing.Point(0, i * 23),
                            TextAlign = System.Drawing.ContentAlignment.MiddleLeft,
                            BackColor = PBorderEvents.Drawing.BackColor,
                            ForeColor = PBorderEvents.Drawing.ForeColor,
                            Text      = table.Rows[i].ItemArray[0].ToString()
                        });
                    }
                    foreach (System.Windows.Forms.Label label in labels)
                    {
                        ListTables.Controls.Add(label);
                    }
                    foreach (System.Windows.Forms.Label label in labels)
                    {
                        label.MouseEnter += (s, e) => {
                            try {
                                label.BackColor = System.Drawing.Color.FromArgb(0x33, 0x33, 0x34);
                            }
                            catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
                        };
                        label.MouseLeave += (s, e) => {
                            try {
                                label.BackColor = PBorderEvents.Drawing.BackColor;
                            }
                            catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
                        };
                        label.Click += (s, e) => {
                            try {
                                CDatabaseCon DataConn1 = new CDatabaseCon();
                                MySql.Data.MySqlClient.MySqlDataAdapter adapter1 = new MySql.Data.MySqlClient.MySqlDataAdapter();
                                System.Data.DataTable table1 = new System.Data.DataTable();
                                string com1 = $"SELECT * FROM {label.Text};";
                                MySql.Data.MySqlClient.MySqlCommand command1 = new MySql.Data.MySqlClient.MySqlCommand(com1, DataConn1.GetConnection());
                                adapter.SelectCommand = command1;
                                adapter.Fill(table1);
                                CDataTable.PDataBase.DataGridView.DataSource = table1;
                                CDataTable.PDataBase.DataGridView.Columns[0].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
                                CDataTable.PDataBase.DataGridView.Columns[0].Resizable    = System.Windows.Forms.DataGridViewTriState.False;
                                CDataTable.PDataBase.DataGridView.Columns[0].Width        = 25;
                                foreach (System.Windows.Forms.DataGridViewColumn column in CDataTable.PDataBase.DataGridView.Columns)
                                {
                                    column.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
                                }
                            }
                            catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
                        };
                    }
                }
            }
            catch (System.Exception Ex) { System.Windows.Forms.MessageBox.Show(Ex.Message); }
        }