private void btnLuu_Click(object sender, EventArgs e)
        {
            if (KiemTraTextBox())
            {
                //kiểm tra trùng tên sp
                if (clsSanPham_BUS.KiemTraTrungSanPham(txtTenSP.Text))
                {
                    MessageBox.Show("Sản phẩm đã tồn tại, vui lòng kiểm tra lại ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else
                {
                    try
                    {
                        string _maSanPhamMoi = Helper.GetTimestamp(DateTime.Now);
                        txtCTMaSP.Text  = _maSanPhamMoi;
                        txtCTTenSP.Text = txtTenSP.Text;

                        EnableSanPham(false);
                        EnableChiTiet(true);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Dữ liệu nhập không chính xác, vui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
        private void taoTaiKhoan()
        {
            showValidateLabel(false);

            if (kiemTraTextbox())
            {
                // Hop le
                if (clsTaiKhoan_BUS.KiemTraTaiKhoanDaTonTai(txtDangNhap.Text))
                {
                    // tai khoan da ton tai
                    DialogResult = MessageBox.Show("Tên tài khoản đã tồn tại, vui lòng nhập tên khác.", "Thông báo", MessageBoxButtons.OK);
                    if (DialogResult == DialogResult.OK)
                    {
                        txtDangNhap.Text = "";
                    }
                }
                else
                {
                    // Lưu ảnh vào database
                    clsHinhAnh_DTO hinhAnh       = new clsHinhAnh_DTO(pictureHinhAnh.ImageLocation, clsHinhAnh_DTO.LoaiHinhAnh.Avatar);
                    object         resultHinhAnh = clsHinhAnh_BUS.ThemHinhAnh(hinhAnh);

                    if (resultHinhAnh is bool)
                    {
                        // Lưu nhân viên vào database
                        clsNhanVien_DTO nhanVien     = new clsNhanVien_DTO(Helper.GetTimestamp(DateTime.Now), txtHoTen.Text, pckNgaySinh.Value, txtQueQuan.Text, txtDiaChi.Text, txtSoDienThoai.Text, hinhAnh, DateTime.Now);
                        object          resultThemNV = clsNhanVien_BUS.ThemNhanVien(nhanVien);
                        if (resultThemNV is bool)
                        {
                            // Lưu Tài Khoản vào database
                            int             maLoaiTK           = (int)cboLoaiTK.SelectedValue;
                            string          moTa               = ((DataRowView)cboLoaiTK.Items[cboLoaiTK.SelectedIndex])["MoTa"].ToString();
                            clsTaiKhoan_DTO taiKhoan           = new clsTaiKhoan_DTO(txtDangNhap.Text, txtMatKhau.Text, nhanVien, new clsPhanLoaiTK_DTO(maLoaiTK, moTa));
                            object          resultThemTaiKhoan = clsTaiKhoan_BUS.ThemTaiKhoan(taiKhoan);

                            if (resultThemTaiKhoan is bool)
                            {
                                if ((bool)resultThemTaiKhoan)
                                {
                                    // Copy image file vào folder data/avatar
                                    string fileName = Path.GetFileName(pictureHinhAnh.ImageLocation);
                                    string destPath = Directory.GetCurrentDirectory() + "\\data\\avatar\\" + fileName;
                                    File.Copy(pictureHinhAnh.ImageLocation, destPath, true);

                                    MessageBox.Show("Tạo tài khoản thành công");
                                    loadBangTK();
                                }
                                else
                                {
                                    MessageBox.Show("Tạo tài khoản thất bại");
                                }
                            }
                            else
                            {
                                MessageBox.Show((string)resultThemTaiKhoan);
                            }
                        }
                        else
                        {
                            MessageBox.Show((string)resultThemNV);
                        }
                    }
                    else
                    {
                        MessageBox.Show((string)resultHinhAnh);
                    }
                }
            }
            else
            {
                DialogResult = MessageBox.Show("Đã xảy ra lỗi, vui lòng kiểm tra lại thông tin nhập.", "Thông báo", MessageBoxButtons.OK);
            }
        }
        private void btnHoanThanh_Click(object sender, EventArgs e)
        {
            string _maChiTietSanPham;
            string _mauSac;
            string _soLuong;
            string _hinhAnh;
            string _maSanPham;

            if (DialogResult.Yes == MessageBox.Show("Bạn có muốn lưu hóa đơn không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
            {
                try
                {
                    //Lưu vào PhieuNhapKho
                    string _maPhieuNhapKho           = Helper.GetTimestamp(DateTime.Now);
                    clsPhieuNhapKho_DTO phieuNhapKho = new clsPhieuNhapKho_DTO(_maPhieuNhapKho, Validation.LayMaNhanVien(), txtGhiChu.Text, DateTime.Now, 1, cboNCC.SelectedValue.ToString());
                    object resultPhieuNhapKho        = clsPhieuNhapKho_BUS.ThemPhieuNhapKho(phieuNhapKho);
                    if (resultPhieuNhapKho is bool)
                    {
                        if ((bool)(resultPhieuNhapKho))
                        {
                            //Thành công
                            //Vòng lặp thêm các sản phẩm trong dgvHDSanPham
                            for (int i = 0; i < dgvHDSanPham.Rows.Count; i++)
                            {
                                _maChiTietSanPham = dgvHDSanPham.Rows[i].Cells["colMaChiTiet"].Value.ToString();
                                _mauSac           = dgvHDSanPham.Rows[i].Cells["colMauSac"].Value.ToString();
                                _soLuong          = dgvHDSanPham.Rows[i].Cells["colSoLuong"].Value.ToString();
                                _hinhAnh          = dgvHDSanPham.Rows[i].Cells["colHinhAnh"].Value.ToString();
                                _maSanPham        = dgvHDSanPham.Rows[i].Cells["colMaSanPham"].Value.ToString();
                                //kiem tra ton tai san pham ==> chua ton tai ==> thêm mới sản phẩm ==> thêm từng chi tiết ==> lưu hóa đơn nhập
                                if (clsSanPham_BUS.KiemTonTaiSanPham(_maSanPham))
                                {
                                    /* sản phẩm đã tồn tại */
                                    //kiem tra ton tai chi tiet trong db ==> update
                                    if (clsChiTietSanPham_BUS.KiemTraTonTaiMaCT(_maChiTietSanPham))
                                    {
                                        /* chi tiết đã tồn tại */
                                        //Lấy số lượng cũ để cập nhật
                                        int           SoLuongSanPhamCu = 0;
                                        SqlDataReader dr = clsChiTietSanPham_BUS.LayChiTiet(_maSanPham, _mauSac.Trim());
                                        if (dr != null)
                                        {
                                            while (dr.Read())
                                            {
                                                SoLuongSanPhamCu = int.Parse(dr["SoLuong"].ToString());
                                            }
                                        }
                                        SoLuongSanPhamCu += int.Parse(_soLuong);
                                        //Lưu chi tiết sản phẩm
                                        clsChiTietSP_DTO chiTietSanPham  = new clsChiTietSP_DTO(_maChiTietSanPham, _mauSac, SoLuongSanPhamCu);
                                        object           resultChiTietSP = clsChiTietSanPham_BUS.CapNhatSoLuong(chiTietSanPham);
                                        if (resultChiTietSP is bool)
                                        {
                                            if ((bool)resultChiTietSP)
                                            {
                                            }
                                            else
                                            {
                                                MessageBox.Show("Thêm chi tiết thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show((string)resultChiTietSP);
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        /* không tồn tại chi tiết */
                                        //tạo mới chi tiết ==> lưu ảnh vào database
                                        clsHinhAnh_DTO hinhAnh       = new clsHinhAnh_DTO(_hinhAnh, clsHinhAnh_DTO.LoaiHinhAnh.Product);
                                        object         resultHinhAnh = clsHinhAnh_BUS.ThemHinhAnh(hinhAnh);
                                        if (resultHinhAnh is bool)
                                        {
                                            //Lưu chi tiết sản phẩm mới
                                            clsChiTietSP_DTO chiTietSanPham  = new clsChiTietSP_DTO(_maSanPham, _maChiTietSanPham, _mauSac, int.Parse(_soLuong), hinhAnh.MaHinhAnh, 1);
                                            object           resultChiTietSP = clsChiTietSanPham_BUS.ThemChiTietSanPham(chiTietSanPham);
                                            if (resultChiTietSP is bool)
                                            {
                                                if ((bool)resultChiTietSP)
                                                {
                                                    // lưu chi tiết thành công ==> copy hình
                                                    string fileName = Path.GetFileName(_hinhAnh);
                                                    string destPath = Directory.GetCurrentDirectory() + "\\data\\product\\" + fileName;
                                                    File.Copy(_hinhAnh, destPath, true);
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Thêm chi tiết mới thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                MessageBox.Show((string)resultChiTietSP);
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show((string)resultHinhAnh);
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    /* không tồn tại sản phẩm */

                                    string _maSP       = dgvHDSanPham.Rows[i].Cells["colMaSanPham"].Value.ToString();
                                    string _tenSP      = dgvHDSanPham.Rows[i].Cells["colTenCTSP"].Value.ToString();
                                    string _thuongHieu = dgvHDSanPham.Rows[i].Cells["colThuongHieuu"].Value.ToString();
                                    string _chatLieu   = dgvHDSanPham.Rows[i].Cells["colChatLieuu"].Value.ToString();
                                    int    _giaVon     = int.Parse(dgvHDSanPham.Rows[i].Cells["colGiaVonNhap"].Value.ToString().Replace(",", ""));
                                    int    _giaBanLe   = int.Parse(dgvHDSanPham.Rows[i].Cells["colGiaBanLe"].Value.ToString().Replace(",", ""));
                                    bool   _chongNuoc  = bool.Parse(dgvHDSanPham.Rows[i].Cells["colChongNuoc"].Value.ToString());
                                    float  _trongLuong = float.Parse(dgvHDSanPham.Rows[i].Cells["colKichCo"].Value.ToString());
                                    string _maDanhMuc  = dgvHDSanPham.Rows[i].Cells["colMauMaa"].Value.ToString();
                                    int    _namBH      = int.Parse(dgvHDSanPham.Rows[i].Cells["colNamBaoHanh"].Value.ToString());

                                    //Thêm sản phẩm
                                    clsSanPham_DTO sanPham       = new clsSanPham_DTO(_maSP, _tenSP, _thuongHieu, _chatLieu, _giaVon, _giaBanLe, _chongNuoc, _trongLuong, _maDanhMuc, _namBH);
                                    object         resultSanPham = clsSanPham_BUS.ThemSanPham(sanPham);
                                    if (resultSanPham is bool)
                                    {
                                        if ((bool)resultSanPham)
                                        {
                                            //thêm chi tiết sản phẩm vừa thêm
                                            clsHinhAnh_DTO hinhAnh       = new clsHinhAnh_DTO(_hinhAnh, clsHinhAnh_DTO.LoaiHinhAnh.Product);
                                            object         resultHinhAnh = clsHinhAnh_BUS.ThemHinhAnh(hinhAnh);
                                            if (resultHinhAnh is bool)
                                            {
                                                if ((bool)(resultHinhAnh))
                                                {
                                                    //Lưu chi tiết sản phẩm mới
                                                    clsChiTietSP_DTO chiTietSanPham  = new clsChiTietSP_DTO(_maSanPham, _maChiTietSanPham, _mauSac, int.Parse(_soLuong), hinhAnh.MaHinhAnh, 1);
                                                    object           resultChiTietSP = clsChiTietSanPham_BUS.ThemChiTietSanPham(chiTietSanPham);
                                                    if (resultChiTietSP is bool)
                                                    {
                                                        if ((bool)resultChiTietSP)
                                                        {
                                                            // Copy image file vào folder data/product
                                                            string fileName = Path.GetFileName(_hinhAnh);
                                                            string destPath = Directory.GetCurrentDirectory() + "\\data\\product\\" + fileName;
                                                            File.Copy(_hinhAnh, destPath, true);
                                                        }
                                                        else
                                                        {
                                                            MessageBox.Show("Thêm chi tiết mới thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                            return;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show((string)resultChiTietSP);
                                                        return;
                                                    }
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Thêm hình ảnh mới thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                MessageBox.Show((string)resultHinhAnh);
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Thêm sản phẩm thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show((string)resultSanPham);
                                        return;
                                    }
                                }

                                //Lưu ChiTietNhapKho
                                clsChiTietPhieuNhapKho_DTO chiTiet = new clsChiTietPhieuNhapKho_DTO(Helper.GetTimestamp(DateTime.Now), _maChiTietSanPham, int.Parse(_soLuong), _maPhieuNhapKho);
                                object resultChiTiet = clsChiTietPhieuNhapKho_BUS.ThemChiTietPhieuNhapKho(chiTiet);
                                if (resultChiTiet is bool)
                                {
                                    if ((bool)(resultChiTiet))
                                    {
                                        //MessageBox.Show("Đã lưu vào chi tiết hóa đơn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        _KiemTraThemChiTiet = true;
                                    }
                                    else
                                    {
                                        _KiemTraThemChiTiet = false;
                                        MessageBox.Show("Thêm chi tiết thất bại, vui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        return;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show((string)resultChiTiet);
                                    return;
                                }
                            }//end for
                        }
                        else
                        {
                            MessageBox.Show("Thêm thất bại");
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show((string)resultPhieuNhapKho);
                        return;
                    }

                    //lưu thành công
                    if (_KiemTraThemChiTiet)
                    {
                        loadSanPham();
                        lblSoLuongSP.Text  = "0";
                        lblTongTien.Text   = "0";
                        txtCTMaSP.Text     = null;
                        txtCTTenSP.Text    = null;
                        btnThemMoi.Enabled = false;
                        EnableChiTiet(false);
                        EnableSanPham(true);
                        EnableThongTinHD(false);
                        RefreshChiTietSanPham();
                        RefreshHoaDon();
                        RefreshSanPham();
                        dgvHDSanPham.Rows.Clear();
                        MessageBox.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Lưu thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (IOException msg)
                {
                    MessageBox.Show(msg.Message);
                }
                catch (Exception msg)
                {
                    MessageBox.Show(msg.Message);
                }
            }
        }
        private void btnLuuCT_Click(object sender, EventArgs e)
        {
            ShowLabelCT(false);
            if (KiemTraTextBoxCT())
            {
                bool chongNuoc = (rdCo.Checked) ? true : false;
                //Lấy số lượng sản phẩm
                int    SoLuongSanPhamCu = 0;
                string maChiTietSanPham = null;
                string hinhAnh          = null;
                try
                {
                    //Kiểm tra tồn tại màu trong chitiet ==> nếu tồn tại ==> không cần thêm hình,
                    if (clsChiTietSanPham_BUS.KiemTraTonTaiMau(txtCTMaSP.Text, txtCTMauSac.Text.Trim()))
                    {
                        SqlDataReader dr = clsChiTietSanPham_BUS.LayChiTiet(txtCTMaSP.Text, txtCTMauSac.Text.Trim());
                        if (dr != null)
                        {
                            while (dr.Read())
                            {
                                SoLuongSanPhamCu = int.Parse(dr["SoLuong"].ToString());
                                maChiTietSanPham = dr["MaCTSP"].ToString();
                                hinhAnh          = dr["MaHinhAnh"].ToString();
                            }
                        }

                        //Kiễm tra đã tồn tại dòng trong dgv chưa ==> cập nhật số lượng
                        if (dgvHDSanPham.Rows.Count > 0)
                        {
                            bool found = false;
                            for (int i = 0; i < dgvHDSanPham.Rows.Count; i++)
                            {
                                //kiểm tra  sp và màu
                                if (dgvHDSanPham.Rows[i].Cells["colTenCTSP"].Value.ToString() == txtCTTenSP.Text && dgvHDSanPham.Rows[i].Cells["colMauSac"].Value.ToString() == txtCTMauSac.Text.ToString().Trim())
                                {
                                    found = true;
                                    dgvHDSanPham.Rows[i].Cells["colSoLuong"].Value = int.Parse(txtCTSoLuong.Text) + int.Parse(dgvHDSanPham.Rows[i].Cells["colSoLuong"].Value.ToString());
                                    RefreshChiTietSanPham();
                                    EnableThongTinHD(true);
                                    btnThemMoi.Enabled = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                //Lưu số lương mới vào dgv
                                dgvHDSanPham.Rows.Add(maChiTietSanPham, txtCTMaSP.Text, txtCTTenSP.Text, SoLuongSanPhamCu, txtCTSoLuong.Text, txtCTMauSac.Text, hinhAnh, txtGiaVon.Text, txtKichCo.Text, txtThuongHieu.Text, txtNamBH.Text, cboMauMa.SelectedValue.ToString(), txtChatLieu.Text, txtGiaBanLe.Text, chongNuoc);
                                RefreshChiTietSanPham();
                                EnableThongTinHD(true);
                                btnThemMoi.Enabled = true;
                            }
                        }
                        else
                        {
                            //Lưu số lương mới vào dgv
                            dgvHDSanPham.Rows.Add(maChiTietSanPham, txtCTMaSP.Text, txtCTTenSP.Text, SoLuongSanPhamCu, txtCTSoLuong.Text, txtCTMauSac.Text, hinhAnh, txtGiaVon.Text, txtKichCo.Text, txtThuongHieu.Text, txtNamBH.Text, cboMauMa.SelectedValue.ToString(), txtChatLieu.Text, txtGiaBanLe.Text, chongNuoc);
                            RefreshChiTietSanPham();
                            EnableThongTinHD(true);
                            btnThemMoi.Enabled = true;
                        }
                    }
                    // Nếu không tồn tại ==> phải chọn hình
                    else if (string.IsNullOrEmpty(picHinhAnh.ImageLocation))
                    {
                        MessageBox.Show("Chưa thêm hình ảnh", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        //tao moi chi tiet
                        string maChiTietSanPhamMoi = Helper.GetTimestamp(DateTime.Now);

                        //Kiễm tra đã tồn tại dòng trong dgv chưa ==> cập nhật số lượng
                        if (dgvHDSanPham.Rows.Count > 0)
                        {
                            bool found = false;
                            for (int i = 0; i < dgvHDSanPham.Rows.Count; i++)
                            {
                                //kiểm tra  sp và màu
                                if (dgvHDSanPham.Rows[i].Cells["colTenCTSP"].Value.ToString() == txtCTTenSP.Text && dgvHDSanPham.Rows[i].Cells["colMauSac"].Value.ToString() == txtCTMauSac.Text.ToString().Trim())
                                {
                                    found = true;
                                    dgvHDSanPham.Rows[i].Cells["colSoLuong"].Value = int.Parse(txtCTSoLuong.Text) + int.Parse(dgvHDSanPham.Rows[i].Cells["colSoLuong"].Value.ToString());
                                    RefreshChiTietSanPham();
                                    EnableThongTinHD(true);
                                    btnThemMoi.Enabled = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                //Lưu số lương mới vào dgv
                                dgvHDSanPham.Rows.Add(maChiTietSanPhamMoi, txtCTMaSP.Text, txtCTTenSP.Text, 0, txtCTSoLuong.Text, txtCTMauSac.Text, picHinhAnh.ImageLocation, txtGiaVon.Text, txtKichCo.Text, txtThuongHieu.Text, txtNamBH.Text, cboMauMa.SelectedValue.ToString(), txtChatLieu.Text, txtGiaBanLe.Text, chongNuoc);
                                RefreshChiTietSanPham();
                                EnableThongTinHD(true);
                                btnThemMoi.Enabled = true;
                            }
                        }
                        else
                        {
                            //Lưu số lương mới vào dgv
                            dgvHDSanPham.Rows.Add(maChiTietSanPhamMoi, txtCTMaSP.Text, txtCTTenSP.Text, 0, txtCTSoLuong.Text, txtCTMauSac.Text, picHinhAnh.ImageLocation, txtGiaVon.Text, txtKichCo.Text, txtThuongHieu.Text, txtNamBH.Text, cboMauMa.SelectedValue.ToString(), txtChatLieu.Text, txtGiaBanLe.Text, chongNuoc);
                            RefreshChiTietSanPham();
                            EnableThongTinHD(true);
                            btnThemMoi.Enabled = true;
                        }
                        //lbTongSoLuong.Text = (int.Parse(txtCTSoLuong.Text) + int.Parse(lbTongSoLuong.Text)).ToString();
                    }
                }
                catch (Exception msg)
                {
                    MessageBox.Show(msg.Message);
                }
            }
            thayDoiDgv();
        }
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            if (khachHang == null)
            {
                // Khách hàng mới
                khachHang = new clsKhachHang_DTO(txtTenKH.Text, txtSDT.Text, Helper.GetTimestamp(DateTime.Now));
                clsKhachHang_BUS.Them(khachHang);
            }

            hoaDonHienTai = new clsHoaDon_DTO(
                Helper.GetTimestamp(DateTime.Now),
                Validation.LayMaNhanVien(),
                string.IsNullOrWhiteSpace(txtGhiChu.Text) ? "Không" : txtGhiChu.Text,
                double.Parse(lblGiamTru.Text),
                double.Parse(lblThanhTien.Text),
                khachHang,
                khuyenMai);

            if (clsHoaDon_BUS.Them(hoaDonHienTai))
            {
                // Chi tiet hoa don
                foreach (DataRow row in dtSanPham.Rows)
                {
                    clsKhuyenMai_DTO km = new clsKhuyenMai_DTO
                                          (
                        row["TenKhuyenMai"].ToString(),
                        row["GiamTru"].ToString(),
                        false, null, null, 1, int.Parse(row["MaKhuyenMai"].ToString())
                                          );

                    clsChiTietHD_DTO cthd = new clsChiTietHD_DTO
                                            (
                        Helper.GetTimestamp(DateTime.Now),
                        row["MaCTSP"].ToString(),
                        double.Parse(row["GiamTru"].ToString()),
                        double.Parse(row["TongTien"].ToString()),
                        int.Parse(row["SoLuong"].ToString()),
                        km,
                        hoaDonHienTai
                                            );

                    if (!clsChiTietHD_BUS.Them(cthd))
                    {
                        MessageBox.Show("Đã xảy ra lỗi khi tạo chi tiết hóa đơn, vui lòng thử lại hoặc liên hệ Admin để xử lý.");
                        // TODO: Xóa hóa đơn đã tạo ở trên

                        return;
                    }
                    else
                    {
                        // TODO: Giam so luong ton kho trong database
                        if (!clsChiTietSanPham_BUS.CapNhatSoLuong(cthd.MaCTSP, cthd.SoLuong))
                        {
                            MessageBox.Show("Đã xảy ra lỗi khi cập nhật số lượng, vui lòng thử lại hoặc liên hệ Admin để xử lý.");
                            return;
                        }
                    }

                    int milliseconds = 100;
                    Thread.Sleep(milliseconds);
                }

                DialogResult result = MessageBox.Show("Tạo hóa đơn thành công, bạn có muốn In ngay bây giờ?", "Thông báo", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    In();
                }
                btnIn.Enabled = true;
                XacNhanHoaDon(false);
            }
            else
            {
                MessageBox.Show("Thêm hóa đơn thất bại.");
            }
        }
Beispiel #6
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            HienLabel(false);

            if (KiemTraTextBox())
            {
                try
                {
                    //Kiểm tra trùng tên ncc
                    if (clsNhaCungCap_BUS.KiemTraTonTaiTenNCC(txtTenNCC.Text))
                    {
                        MessageBox.Show("Tên nhà cung cấp đã tồn tại \nVui lòng chọn tên khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        txtTenNCC.Text = "";
                    }
                    else
                    {
                        // Lưu ảnh vào database
                        clsHinhAnh_DTO hinhAnh       = new clsHinhAnh_DTO(picHinhAnh.ImageLocation, clsHinhAnh_DTO.LoaiHinhAnh.Avatar);
                        object         resultHinhAnh = clsHinhAnh_BUS.ThemHinhAnh(hinhAnh);
                        if (resultHinhAnh is bool)
                        {
                            if ((bool)resultHinhAnh)
                            {
                                clsNhaCungCap_DTO dtoNcc = new clsNhaCungCap_DTO();
                                //
                                dtoNcc.MaNhaCungCap  = Helper.GetTimestamp(DateTime.Now);
                                dtoNcc.TenNhaCungCap = txtTenNCC.Text;
                                dtoNcc.DiaChi        = txtDiaChi.Text;
                                dtoNcc.SoDienThoai   = int.Parse(txtSDT.Text);
                                dtoNcc.TrangThai     = 1;
                                dtoNcc.MaHinhAnh     = hinhAnh.MaHinhAnh;
                                object resultNCC = clsNhaCungCap_BUS.ThemNhaCungCap(dtoNcc);
                                if (resultNCC is bool)
                                {
                                    if ((bool)resultNCC)
                                    {
                                        // Copy image file vào folder data/avatar
                                        string fileName = Path.GetFileName(picHinhAnh.ImageLocation);
                                        string destPath = Directory.GetCurrentDirectory() + "\\data\\avatar\\" + fileName;
                                        File.Copy(picHinhAnh.ImageLocation, destPath, true);
                                        MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        LoadNCC();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Thêm nhà cung cấp thất bại! \nVui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show((string)resultNCC);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Thêm thất bại! \nVui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            }
                        }
                        else
                        {
                            MessageBox.Show((string)resultHinhAnh);
                        }
                    }
                }catch (IOException msg)
                {
                    MessageBox.Show(msg.Message);
                }
                catch (Exception msg)
                {
                    MessageBox.Show(msg.Message);
                }
            }
        }