private void btnSearchChungTu_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtSoPhieuXuat.Text) || !string.IsNullOrEmpty(txtSoGiaoDich.Text) || !string.IsNullOrEmpty(txtSoHoaDon.Text))
                {
                    List <ChungTuBanHangInfor> lstsbh = BHangDoiMaDataProvider.Instance.SearchChungTuBanHangBySoPhieu(
                        txtSoPhieuXuat.Text.Trim().ToUpper(), txtSoGiaoDich.Text.Trim().ToUpper(),
                        txtSoHoaDon.Text.Trim().ToUpper());

                    if (lstsbh.Count > 0)
                    {
                        if (CommonProvider.Instance.Lock_ChungTu(lstsbh[0]))
                        {
                            lockInfo = lstsbh[0].Clone() as ChungTuBanHangInfor;
                            Business = new DoiMaBussiness(lstsbh[0]);
                            LoadOldChungTuInfor(Business.ChungTu);
                            LoadChiTietThanhToan(Business.ChungTu.IdChungTu);
                            LoadOldChiTietHangBan(Business.ChungTu.IdChungTu);
                            Business.ChungTu.IdChungTu = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Delete(int rowhandle)
        {
            if (rowhandle < 0)
            {
                return;
            }
            if (clsUtils.MsgXoa("Bạn có muốn xóa dữ liệu này không?") == System.Windows.Forms.DialogResult.Yes)
            {
                BHangDoiMaInfor item = (BHangDoiMaInfor)grvDanhSach.GetRow(rowhandle);
                if (item.Draft == 0)
                {
                    throw new InvalidOperationException("Đề nghị đã được xác nhận, không thể xóa!");
                }
                ChungTuBanHangInfor odel = new ChungTuBanHangInfor();
                odel.IdChungTu = item.IdChungTu;

                DoiMaBussiness bussiness = new DoiMaBussiness(odel);
                bussiness.DeleteChungTu();
                clsUtils.MsgThongBao(Declare.msgDeleteSucc);
                LoadDataSource();
            }
        }
        //Tìm kiếm phiếu xuất bán qua mã vạch(khuyến mãi or hàng mua)
        private void SearchByMaVach()
        {
            if (string.IsNullOrEmpty(txtMaVach.Text))
            {
                throw new InvalidOperationException("Bạn chưa nhập mã vạch, không thể kiểm tra!");
            }
            List <BHangDoiMaInfor> lst =
                BHangDoiMaDataProvider.Instance.SearchChungTuBanHangByMaVach(txtMaVach.Text.Trim());

            if (lst.Count == 1)
            {
                txtTenSanPham.Text = lst[0].TenSanPham;
                //Business = new DoiMaBussiness(BanHangDataProvider.Instance.LoadChungTuById(lst[0].IdChungTu));
                Business = new DoiMaBussiness(lst[0]);
                LoadOldChungTuInfor(Business.ChungTu);
                LoadChiTietThanhToan(Business.ChungTu.IdChungTu);
                grcHangBan.DataSource      = null;
                Business.ChungTu.IdChungTu = 0;//de tao moi phieu nhap
            }
            else if (lst.Count > 1)
            {
                txtTenSanPham.Text = lst[0].TenSanPham;
                frmMutilPhieuXuatBan frm = new frmMutilPhieuXuatBan(lst);
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    //Business = new DoiMaBussiness(BanHangDataProvider.Instance.LoadChungTuById(frm.SelectItem.IdChungTu));
                    Business = new DoiMaBussiness(frm.SelectItem);
                    LoadOldChungTuInfor(Business.ChungTu);
                    LoadChiTietThanhToan(Business.ChungTu.IdChungTu);
                    grcHangBan.DataSource      = null;
                    Business.ChungTu.IdChungTu = 0;//de tao moi phieu nhap
                }
            }
            else
            {
                throw new InvalidOperationException("Mã vạch này không có!");
            }
        }
        private void btnSearchPhieuNhap_Click(object sender, EventArgs e)
        {
            try
            {
                if (Updating)
                {
                    if (MessageBox.Show("Dữ liệu đang cập nhật, bạn có muốn hủy bỏ không?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }
                }
                BHangDoiMaInfor ct = BHangDoiMaDataProvider.Instance.SearchChungTuBanHangByPN(txtSoPhieuNhap.Text.Trim().ToUpper(), (int)TransactionType.DOIMAHANGMUA);
                if (ct != null)
                {
                    Business = new DoiMaBussiness(ct);
                    LoadChungTuInstance();
                }
                else
                {
                    MessageBox.Show("Không tìm thấy chứng từ thích hợp!");
                    txtSoPhieuNhap.Text = Business.ChungTu.SoChungTu;
                }
            }
            catch (Exception ex)
            {
                EventLogProvider.Instance.WriteLog(ex.ToString()
                                                   + "\nUser: "******"\nMay: " + Declare.TenMay,
                                                   this.Name);
#if DEBUG
                MessageBox.Show("Lỗi thao tác\n" + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show("Lỗi thao tác", Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
        }
 public frmChiTietDeNghiDoiMa(ChungTuBanHangInfor ctu)
 {
     InitializeComponent();
     Common.LoadStyle(this);
     this.Business = new DoiMaBussiness(ctu);
 }
 public frmChiTietDeNghiDoiMa()
 {
     InitializeComponent();
     Common.LoadStyle(this);
     Business = new DoiMaBussiness();
 }
 private void ResetAllText()
 {
     clsUtils.ResetAllText(this);
     Business = new DoiMaBussiness();
 }