예제 #1
0
 public static bool themTien(string tentk, float soTienThem)
 {
     if (soTienThem > 0)
     {
         XuLyDAL.themTien(tentk, soTienThem);
         return(true);
     }
     return(false);
 }
        private void btnThucHien_Click(object sender, EventArgs e)
        {
            if (yeuCau == "XOA")
            {
                if (txbTenTK.Text == "admin")
                {
                    MessageBox.Show("Bạn không thể xóa tài khoản quản lý!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    if (XuLuTK_BUS.xoaTK(txbTenTK.Text) == false)
                    {
                        MessageBox.Show("Tài khoản không tồn tại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else if (XuLuTK_BUS.xoaTK(txbTenTK.Text))
                    {
                        if (DialogResult.Yes == MessageBox.Show("Bạn có muốn xóa tài khoản này ?", "Chú ý", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                            XuLyDAL.xoaTK(txbTenTK.Text);

                            //trangThaiBanDau();
                            MessageBox.Show("Đã xóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            trangThaiTextBoxBanDau();
                            trangThaiBanDau();
                        }
                    }
                }
            }
            else if (yeuCau == "THEM_TK")
            {
                if (txbTenTK.Text == "")
                {
                    MessageBox.Show("Tên tài khoản không được bỏ trống !", "Chú ý !", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //btnThemTK_Click(sender, e);
                    return;
                }

                else if (txbMatKhau.Text == "")
                {
                    MessageBox.Show("Mật khẩu không được bỏ trống !", "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!XuLuTK_BUS.themTK(txbTenTK.Text))
                {
                    MessageBox.Show("Tên tài khoản đã tồn tại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    if (XuLyDAL.ktMatKhauHopLe(txbMatKhau.Text))
                    {
                        float tienThem = 0;

                        if (txbSoTienThem.Text.Replace(" ", string.Empty) != "")
                        {
                            tienThem = float.Parse(txbSoTienThem.Text.Replace(" ", string.Empty));
                        }

                        if (txbSDT.Text.Trim() != "")
                        {
                            if (txbSDT.Text.Replace(" ", string.Empty).Length != 10)
                            {
                                MessageBox.Show("Số điện thoại không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                        }

                        //if(txbSDT.Text)

                        if (txbEmail.Text != "")
                        {
                            if (!TaiKhoanDAL.ktEmailHopLe(txbEmail.Text))
                            {
                                MessageBox.Show("Email không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }


                        XuLyDAL.themTK(txbTenTK.Text, /*XuLyDAL.maHoaMK(txbMatKhau.Text)*/ txbMatKhau.Text, tienThem);


                        XuLyDAL.themThongTin(txbTenTK.Text, txbSDT.Text.Replace(" ", string.Empty), txbEmail.Text);



                        MessageBox.Show("Tài khoản đã được thêm !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        trangThaiTextBoxBanDau();
                        trangThaiBanDau();
                    }
                    else
                    {
                        MessageBox.Show("                          Mật khẩu không hợp lệ \n ( Mật khẩu phải có ít nhất 8 kí tự, phải bao gồm cả chữ và số)", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
            else if (yeuCau == "CHINH_SUA")
            {
                if (XuLuTK_BUS.suaThongTin(txbTenTK.Text, txbMatKhau.Text))
                {
                    float tienThem = 0;
                    if (txbSoTienThem.Text.Replace(" ", string.Empty) != "")
                    {
                        tienThem = float.Parse(txbSoTienThem.Text.Replace(" ", string.Empty));
                    }

                    if (txbSDT.Text.Trim() != "")
                    {
                        if (txbSDT.Text.Replace(" ", string.Empty).Length != 10)
                        {
                            MessageBox.Show("Số điện thoại không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }

                    //if(txbSDT.Text)

                    if (txbEmail.Text != "")
                    {
                        if (!TaiKhoanDAL.ktEmailHopLe(txbEmail.Text))
                        {
                            MessageBox.Show("Email không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    XuLyDAL.suaThongTin(txbTenTK.Text, txbMatKhau.Text, txbSDT.Text.Replace(" ", string.Empty), txbEmail.Text, tienThem);

                    MessageBox.Show("Chỉnh sữa hoàn tất !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    trangThaiTextBoxBanDau();
                    trangThaiBanDau();
                }
                else
                {
                    MessageBox.Show("Mật khẩu không hợp lệ !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            else if (yeuCau == "THEM_TIEN")
            {
                float tienThem = 0;
                if (txbSoTienThem.Text.Replace(" ", string.Empty) != "")
                {
                    tienThem = float.Parse(txbSoTienThem.Text.Replace(" ", string.Empty));
                    XuLyDAL.themTien(txbTenTK.Text, tienThem);
                    trangThaiBanDau();
                    trangThaiTextBoxBanDau();
                    MessageBox.Show("Nạp tiền thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            yeuCau = "";

            lsvShow.Clear();
            showData();
        }