private void btnSearch_Click(object sender, EventArgs e) { try { if (txtTimMaSo.Text == "" && txtTimUsername.Text == "") { MessageBox.Show("Chưa nhập thông tin về quản thư cần tìm"); return; } if (rdbUsername.Checked == true) { QuanThuBUS quanthuBUS = new QuanThuBUS(); QuanThuDTO quanthuDTO = null; quanthuDTO = quanthuBUS.Search(txtTimUsername.Text.ToString()); if (quanthuDTO == null) { MessageBox.Show("Không tìm thấy thông tin"); return; } else { txtUsername.Text = quanthuDTO.Username; txtHoTen.Text = quanthuDTO.HoTen; txtDiaChi.Text = quanthuDTO.DiaChi; txtDienThoai.Text = quanthuDTO.DienThoai; } } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void btnDangNhap_Click(object sender, EventArgs e) { try { if (txtUsername.Text == "") { MessageBox.Show("Chưa nhập username"); return; } if (txtPassword.Text == "") { MessageBox.Show("Chưa nhập password"); return; } QuanThuDTO quanthuDTO = null; QuanThuBUS quanthuBUS = new QuanThuBUS(); string username = txtUsername.Text; quanthuDTO = quanthuBUS.Search(username); byte[] plainTextBytes = ASCIIEncoding.ASCII.GetBytes(txtPassword.Text.ToString()); MD5CryptoServiceProvider myMD5 = new MD5CryptoServiceProvider(); byte[] byteHash = myMD5.ComputeHash(plainTextBytes); StringBuilder sOutput = new StringBuilder(byteHash.Length); for (int i = 0; i < byteHash.Length; i++) { sOutput.Append(byteHash[i].ToString("X2")); // X2 formats to hexadecimal } if (quanthuDTO == null) { MessageBox.Show("Không tìm thấy quản thư có username là : " + txtUsername.Text); return; } else { if (quanthuDTO.Password == sOutput.ToString() && quanthuDTO.Loai == 1) { //this.Visible = false; kiemTraDangNhap = true; this.Close(); frmQuanLySach frm = new frmQuanLySach(); frm.ShowDialog(); } else { if (quanthuDTO.Password == sOutput.ToString() && quanthuDTO.Loai == 2) { kiemTraDangNhap = true; frmQuanTriVien frm = new frmQuanTriVien(); frm.ShowDialog(); } else { MessageBox.Show("Password không hợp lệ"); return; } } } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void btnTaoTaiKhoan_Click(object sender, EventArgs e) { try { if (txtUsername.Text == "") { MessageBox.Show("Chưa nhập Username"); return; } if (txtPass.Text == "") { MessageBox.Show("Chưa nhập Password"); return; } if (txtRePass.Text == "") { MessageBox.Show("Chưa nhập lại Password"); return; } if (txtHoTen.Text == "") { MessageBox.Show("Chưa nhập họ tên"); return; } if (txtDiaChi.Text == "") { MessageBox.Show("Chưa nhập địa chỉ"); return; } if (txtDienThoai.Text == "") { MessageBox.Show("Chưa nhập số điện thoại"); return; } if (txtPass.Text != txtRePass.Text) { MessageBox.Show("Password chưa khớp"); return; } byte[] plainTextBytes = ASCIIEncoding.ASCII.GetBytes(txtPass.Text.ToString()); MD5CryptoServiceProvider myMD5 = new MD5CryptoServiceProvider(); byte[] byteHash = myMD5.ComputeHash(plainTextBytes); StringBuilder sOutput = new StringBuilder(byteHash.Length); for (int i = 0; i < byteHash.Length; i++) { sOutput.Append(byteHash[i].ToString("X2")); // X2 formats to hexadecimal } QuanThuBUS quanthuBUS = new QuanThuBUS(); QuanThuDTO quanthuDTO = new QuanThuDTO(); quanthuDTO.Username = txtUsername.Text; quanthuDTO.Password = sOutput.ToString(); quanthuDTO.DiaChi = txtDiaChi.Text; quanthuDTO.DienThoai = txtDienThoai.Text; quanthuDTO.HoTen = txtHoTen.Text; quanthuDTO.Loai = 1; quanthuBUS.Insert(quanthuDTO); MessageBox.Show("Tài khoản đã được tạo"); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }