示例#1
0
 private void quảnLýToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //doc file kiem tra user name & pass . if trùng -> frmNoiDung else -> "Bạn chưa dang nhap"
     //Đọc file
     try
     {
         FileStream   fs       = new FileStream(@"D:\Project_UD\Project LTUD\account.txt", FileMode.Open, FileAccess.Read, FileShare.None);
         StreamReader sr       = new StreamReader(fs);
         string       username = sr.ReadLine();
         string       password = sr.ReadLine();
         MessageBox.Show("Tài khoản: " + username + " tồn tại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         fs.Close();
         //sw.Close();
         SqlConnection conn      = new SqlConnection("Data Source=.;Initial Catalog=QuanLyHang;Integrated Security=True");
         string        sqlselect = "select * from THONGTINNV  where MaNV='" + username + "'and MatKhau='" + password + "'";
         conn.Open();
         SqlCommand    cmd    = new SqlCommand(sqlselect, conn);
         SqlDataReader reader = cmd.ExecuteReader();
         if (reader.Read() == true)
         {
             frmNoiDung tp = new frmNoiDung();
             tp.MdiParent = this;
             tp.Show();
         }
         else
         {
             MessageBox.Show("Bạn chưa đăng nhập!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(" " + ex);
     }
 }
        private void btnDangnhap_Click(object sender, EventArgs e)
        {
            SqlConnection conn      = new SqlConnection("Data Source=.;Initial Catalog=QuanLyHang;Integrated Security=True");
            string        sqlselect = "select * from THONGTINNV  where MaNV='" + txtTenDangNhap.Text + "'and MatKhau='" + txtMatKhau.Text + "'";

            conn.Open();
            SqlCommand    cmd    = new SqlCommand(sqlselect, conn);
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.Read() == true)
            {
                Write(path);
                this.Hide();
                frmNoiDung tp = new frmNoiDung();
                tp.Show();
            }
            else
            {
                MessageBox.Show("Sai ten dang nhap hoac mat khau!!!!");
                txtMatKhau.Text     = "";
                txtTenDangNhap.Text = "";
                txtTenDangNhap.Focus();
            }
        }