Ejemplo n.º 1
0
        private void btnThemTK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtTaiKhoan.Text == "" || txtTaiKhoan.Text == null ||
                    txtMatKhau.Text == "" || txtMatKhau.Text == null)
                {
                    MessageBox.Show("Yêu cầu điền thông tin tài khoản");
                    return;
                }

                TaiKhoan taiKhoan   = new TaiKhoan();
                string   maNhanVien = CNhanVien_BUS.findTenbyMa(cmbTenNhanVien.SelectedItem.ToString());
                if (maNhanVien == "")
                {
                    MessageBox.Show("Vui lòng chọn nhân viên");
                    return;
                }
                taiKhoan.maNhanVien = maNhanVien;

                if (taiKhoan.maNhanVien == null || taiKhoan.maNhanVien == "")
                {
                    MessageBox.Show("Không lấy được mã nhân viên");
                    return;
                }
                if ((txtTaiKhoan.Text == null || txtTaiKhoan.Text == "") &&
                    (txtMatKhau.Text == null || txtMatKhau.Text == ""))
                {
                    MessageBox.Show("Điền đầy đủ thông tin tài khoản");
                    return;
                }
                if (CTaiKhoan_BUS.findTK(txtTaiKhoan.Text))
                {
                    MessageBox.Show("Tên tài khoản đã tồn tại");
                    return;
                }

                foreach (char item in txtTaiKhoan.Text)
                {
                    if ((item < 65 || item > 90) && (item < 97 || item > 122) && (item < 0 || item > 57))
                    {
                        MessageBox.Show("Tên tài khoản chỉ có các chữ cái in hoa hoặc thường và số");
                        return;
                    }
                }

                taiKhoan.tenTaiKhoan = txtTaiKhoan.Text;
                taiKhoan.matKhau     = CTaiKhoan_BUS.Encrypt(txtMatKhau.Text);
                taiKhoan.maTaiKhoan  = CServices.taoMa <TaiKhoan>(CTaiKhoan_BUS.toList());

                taiKhoan.trangThai = 0;

                if (CServices.kiemTraThongTin(taiKhoan)) //Kiểm tra thông tin tài khoản hợp lệ
                {
                    CTaiKhoan_BUS.add(taiKhoan);         //Thêm tài khoản
                    MessageBox.Show("Thêm thành công");
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Bạn chưa chọn mã nhân viên cần cấp tài khoản");
            }

            hienthiDStaikhoan();
            load();
            cmbTenNhanVien_Loaded(sender, e);
        }