private void btnLogIn_Click(object sender, EventArgs e) { if (tbLog.Text != "") { if (tbPass.Text != "") { var sqlconection = new SqlConnection(ConnectionString); using (sqlconection) { sqlconection.Open(); var command = new SqlCommand { Connection = sqlconection, CommandText = "SELECT * FROM Login WHERE Login.Login= '******'", CommandType = CommandType.Text }; SqlDataReader dr = command.ExecuteReader(); if (dr.Read()) { string log = dr[0].ToString(); string pass = dr[1].ToString(); if (pass == tbPass.Text) { bool adm = Convert.ToBoolean(dr[2]); Main newMain = new Main(adm, log); appendText = DateTime.Now.ToString() + ": пользователь " + log + " вошел в систему.\n"; File.AppendAllText(path, appendText, Encoding.UTF8); newMain.Show(); this.Hide(); } else { tbPass.Clear(); lblErrPass.Text = "Неверный пароль"; } } else { tbLog.Clear(); tbPass.Clear(); lblErrLog.Text = "Неверный логин"; }; dr.Close(); } } else { lblErrPass.Text = "Введите пароль";} } else { lblErrLog.Text = "Введите логин"; } }
private void frmAdd_FormClosed(object sender, FormClosedEventArgs e) { Main newMain = new Main(true, log); newMain.Show(); }