private void addItem_frm_Load(object sender, EventArgs e) { server.setTableFields(this, tableName, ref totalFieldCount, ref fieldNames, ref textboxes, change, changeId); Array.Resize(ref values, textboxes.Length); for (int i = 0; i < textboxes.Length; i++) { values[i] = textboxes[i].Text; } foreach (Form f in Application.OpenForms) { if (f.Name == "admin_frm") { admin = f as admin_frm; } } }
//АВТОРИЗОВАТЬ ПОЛЬЗОВАТЕЛЯ private void btn_login_pictureBox_Click(object sender, EventArgs e) { string sql = "SELECT * FROM sotrudnik"; // Строка запроса MySqlConnection connection = new MySqlConnection(server.connectionStr); MySqlCommand sqlCom = new MySqlCommand(sql, connection); try { connection.Open(); } catch (Exception) { MessageBox.Show(this, "Ошибка подключения к серверу, задайте новые параметры", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); forms.authorize.setNewServerSettings setNew = new forms.authorize.setNewServerSettings(); this.Hide(); setNew.ShowDialog(); password_textBox.Clear(); login_textBox.Clear(); return; } MySqlDataReader reader = sqlCom.ExecuteReader(); string login = login_textBox.Text; string parol = password_textBox.Text; string username = ""; bool foundUser = false; int foundUserId = 0; int counter = 0; if (reader.HasRows) { while (reader.Read()) { counter++; if ((reader.GetString("login") == login) && (reader.GetString("parol") == parol)) { username = reader.GetString("familiya") + " " + reader.GetString("imya")[0] + ". " + reader.GetString("otchestvo")[0] + "."; foundUser = true; foundUserId = reader.GetInt32("id"); break; } } } else { MessageBox.Show("Нет совпадений", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } reader.Close(); if (foundUser) { if (password_textBox.Text == "admin") { //MessageBox.Show("Здравствуйте " + username, "Добро пожаловать!", MessageBoxButtons.OK, MessageBoxIcon.Information); admin_frm adminForm = new admin_frm(); this.Hide(); adminForm.Show(); } else { manager_frm managerForm = new manager_frm(); managerForm.sotrudnikId = foundUserId; this.Hide(); managerForm.Show(); } } else { MessageBox.Show("Неверная комбинация логина и пароля!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); login_textBox.Text = ""; password_textBox.Text = ""; } connection.Close(); }