public bool IsHoaDonCoNCC(RecordThongKeBanHang Record, string NCCFilter)
 {
     try
     {
         if (NCCFilter == "")
         {
             return(true);
         }
         var listct = _CTHoaDonBanHang.GetListFromHDBH(Record.MaHDBH.Trim());
         if (listct == null)
         {
             return(false);
         }
         foreach (CTHoaDonBanHang vari in listct)
         {
             if (TextinText(vari.TenNCC.Trim(), NCCFilter, false))
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public RecordThongKeBanHang GetNullRecord()
        {
            RecordThongKeBanHang record = new RecordThongKeBanHang();

            record.MaHDBH = null;
            return(record);
        }
 // null nếu hóa đơn truyền vào lỗi
 public RecordThongKeBanHang GetRecord(HoaDonBanHang HoaDon)
 {
     try
     {
         RecordThongKeBanHang record = new RecordThongKeBanHang();
         if (HoaDon == null) // Có lỗi hóa đơn truyền vào
         {
             return(GetNullRecord());
         }
         else // Tính toán
         {
             record.MaHDBH   = HoaDon.MaHDBH.Trim();
             record.NgayGiao = HoaDon.NgayBan;
             {
                 record.MaNV = HoaDon.MaNV.Trim();
                 var nhanvien = _NhanVien.GetObjectFromID(record.MaNV);
                 if (nhanvien == null)
                 {
                     return(GetNullRecord());
                 }
                 record.TenNV = nhanvien.TenNV.Trim();
             }
             {
                 record.MaKH = HoaDon.MaKH.Trim();
                 var khachhang = _KhachHang.GetObjectFromID(record.MaKH);
                 if (khachhang == null)
                 {
                     return(GetNullRecord());
                 }
                 record.TenKH = khachhang.TenKH.Trim();
             }
             record.NgayLap   = (DateTime)HoaDon.NgayLap;
             record.GhiChu    = HoaDon.GhiChu.Trim();
             record.TrangThai = HoaDon.TrangThai.Trim();
             {
                 var listcthd = _CTHoaDonBanHang.GetListFromHDBH(record.MaHDBH);
                 if (listcthd == null)
                 {
                     return(GetNullRecord());
                 }
                 record.SoVatLieu = record.TienVatLieu = record.TienKhuyenMai = record.TienKMKH = record.TongTien = record.LaiSuat = record.Von = 0;
                 foreach (CTHoaDonBanHang var in listcthd)
                 {
                     record.TienVatLieu   += (int)var.TienKMKH;
                     record.TienKhuyenMai += (int)var.TienKM;
                     var vatlieu = _VatLieu.GetObjectFromTenVL(var.TenVL.Trim());
                     if (vatlieu == null)
                     {
                         return(GetNullRecord());
                     }
                     record.Von += (int)(vatlieu.GiaMua) * (int)(var.TongSL);
                 }
                 record.SoVatLieu = listcthd.Count;
                 record.TongTien  = record.TienVatLieu - record.TienKhuyenMai;
                 record.TienKMKH  = Math.Abs(_HoaDonBanHang.GetTienKMKH(record.TongTien, record.MaKH, record.MaHDBH));
                 record.TongTien -= record.TienKMKH;
                 record.LaiSuat   = record.TongTien - record.Von;
             }
         }
         return(record);
     }
     catch (Exception) // Lỗi ngoài ý
     {
         return(GetNullRecord());
     }
 }
        public RecordThongKeBanHang GetRecord(HoaDonBanHang HoaDon)
        {
            try
            {
                RecordThongKeBanHang record = new RecordThongKeBanHang();


                if (HoaDon == null)
                {
                    return(GetNullRecord());
                }
                else
                {
                    record.MaHDBH   = HoaDon.MaHDBH.Trim();
                    record.NgayGiao = HoaDon.NgayLap.Value;
                    {
                        record.MaNV = HoaDon.MaNV.Trim();
                        var nhanvien = _NhanVien.GetObjectFromID(record.MaNV);
                        if (nhanvien == null)
                        {
                            return(GetNullRecord());
                        }
                        record.TenNV = nhanvien.TenNV.Trim();
                    }
                    {
                        record.MaKH = HoaDon.MaKH.Trim();
                        var khachhang = _KhachHang.GetObjectFromID(record.MaKH);
                        if (khachhang == null)
                        {
                            return(GetNullRecord());
                        }
                        record.TenKH = khachhang.TenKH.Trim();
                    }
                    record.NgayLap   = (DateTime)HoaDon.NgayLap;
                    record.TrangThai = HoaDon.TrangThai.Trim();
                    {
                        var listcthd = _CTHoaDonBanHang.GetListFromHDBH(record.MaHDBH);
                        if (listcthd == null)
                        {
                            return(GetNullRecord());
                        }
                        record.SoVatLieu = record.TienVatLieu = record.TienKhuyenMai = record.TienKMKH = record.TongTien = 0;
                        foreach (CTHoaDonBanHang var in listcthd)
                        {
                            var vatlieu = _VatLieu.GetObjectFromID(var.MaVL.Trim());
                            record.TienVatLieu += (int)(var.SoLuong * vatlieu.GiaBan.Value);
                            if (vatlieu == null)
                            {
                                return(GetNullRecord());
                            }
                        }
                        var khachhang = _KhachHang.GetObjectFromID(record.MaKH);
                        record.TienKhuyenMai = (long)(record.TienVatLieu * (new BLL_LoaiKhachHang()).GetObjectFromID(khachhang.MaLoaiKH).PhanTramGiam.Value / 100);
                        record.SoVatLieu     = listcthd.Count;
                        record.TongTien      = record.TienVatLieu - record.TienKhuyenMai;
                    }
                }
                return(record);
            }
            catch (Exception) // Lỗi ngoài ý
            {
                return(GetNullRecord());
            }
        }