private void buttonX3_Click(object sender, EventArgs e) { frmSach_DG g = new frmSach_DG(); g.Show(); this.Hide(); }
private void btnDangNhat_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(Connect.GetConnect()); con.Open(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = @"select *from TaiKhoan where ID =@ID AND PASS=@PASS"; cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.VarChar, 10)).Value = txtUser.Text; cmd.Parameters.Add(new SqlParameter("@PASS", SqlDbType.VarChar, 50)).Value = txtPass.Text; da.SelectCommand = cmd; da.Fill(dt); if (dt.Rows.Count > 0) { id = txtUser.Text; if (txtPass.Text == "admin") { frmMenu fm = new frmMenu(); fm.Show(); this.Hide(); } else { frmSach_DG fs = new frmSach_DG(); fs.Show(); this.Hide(); } } else if (MessageBox.Show("Đăng nhập thất bại, bạn có muốn đăng nhập lại không?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes) { txtUser.Focus(); txtUser.Clear(); txtPass.Clear(); } else { Close(); System.Windows.Forms.Application.Exit(); } con.Close(); }
private void btnDangNhat_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(Connect.GetConnect()); con.Open(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText= @"select *from TaiKhoan where ID =@ID AND PASS=@PASS"; cmd.Parameters.Add(new SqlParameter("@ID",SqlDbType.VarChar,10)).Value = txtUser.Text; cmd.Parameters.Add(new SqlParameter("@PASS", SqlDbType.VarChar, 50)).Value = txtPass.Text; da.SelectCommand = cmd; da.Fill(dt); if (dt.Rows.Count > 0) { id = txtUser.Text; if (txtPass.Text == "admin") { frmMenu fm = new frmMenu(); fm.Show(); this.Hide(); } else { frmSach_DG fs = new frmSach_DG(); fs.Show(); this.Hide(); } } else if (MessageBox.Show("Đăng nhập thất bại, bạn có muốn đăng nhập lại không?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes) { txtUser.Focus(); txtUser.Clear(); txtPass.Clear(); } else { Close(); System.Windows.Forms.Application.Exit(); } con.Close(); }