public void LayChiTiet_HangHoaXuat_TheoNhomHang()
        {
            try
            {
                int sl = 0;

                temp = new Entities.BCNhapHangTheoThoiGian[hienthi.Length];
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (hienthi[i].SoLuong != 0)
                    {
                        temp[sl] = hienthi[i];
                        sl++;
                    }
                }
                Entities.BCNhapHangTheoThoiGian[] baocao = new Entities.BCNhapHangTheoThoiGian[sl];
                for (int i = 0; i < sl; i++)
                {
                    baocao[i] = temp[i];
                }
            }
            catch
            {
            }
        }
        private void toolStripStatusLabel2_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            try
            {
                if (KiemTra())
                {
                    LayNgay();
                    PhieuXuatHuy();
                    ChiTietXuatHuy();
                    HDBanHang1();
                    ChiTietHDBanHang();
                    TraLaiNCC();
                    ChiTietTraLaiNCC();

                    HangHoa1();
                    GoiHang();
                    ChiTietGoiHang();
                    TongTienNhanVien();

                    LayChiTiet_HangHoaXuat_TheoNhomHang();

                    ///////////////////////////////MRK FIX
                    List <Entities.BCNhapHangTheoThoiGian> tem0 = new List <Entities.BCNhapHangTheoThoiGian>();
                    int tong0 = 0;
                    foreach (Entities.BCNhapHangTheoThoiGian item in temp)
                    {
                        tong0 += item.SoLuong;
                        tem0.Add(item);
                    }
                    Entities.BCNhapHangTheoThoiGian tem1 = new Entities.BCNhapHangTheoThoiGian();
                    tem1.TenChungTu = "Tổng: ";
                    tem1.SoLuong    = tong0;
                    tem0.Add(tem1);
                    //////////////////////////////////////
                    //dtgvhienthi.DataSource = temp;
                    dtgvHienThi.DataSource = tem0.ToArray();

                    FixDatagridview();
                }
            }
            catch
            {
            }
            finally
            {
                this.Enabled = true;
                this.Focus();
            }
        }
Exemple #3
0
        public void HienThi()
        {
            try
            {
                hienthi       = new List <Entities.BCNhapHangTheoThoiGian>();
                hienthibaocao = new List <Entities.BCNhapHangTheoThoiGianChiTiet>();
                int sotangbaocao  = 0;
                int sotanghienthi = 0;
                // hóa đơn nhập
                for (int i = 0; i < hoadonnhap.Length; i++)
                {
                    int      soluong   = 0;
                    DateTime ngayphieu = hoadonnhap[i].NgayNhap;
                    if (ngayphieu >= truoc && ngayphieu <= sau)
                    {
                        for (int j = 0; j < chitiethoadonnhap.Length; j++)
                        {
                            if (hoadonnhap[i].MaHoaDonNhap == chitiethoadonnhap[j].MaHoaDonNhap)
                            {
                                for (int k = 0; k < hanghoa.Length; k++)
                                {
                                    if (chitiethoadonnhap[j].MaHangHoa == hanghoa[k].MaHangHoa)
                                    {
                                        int sl = chitiethoadonnhap[j].SoLuong;
                                        soluong += sl;
                                        Entities.BCNhapHangTheoThoiGianChiTiet ct = new Entities.BCNhapHangTheoThoiGianChiTiet(hoadonnhap[i].MaHoaDonNhap, "Hóa Đơn Nhập", hoadonnhap[i].NgayNhap, hanghoa[k].MaHangHoa, hanghoa[k].TenHangHoa, sl);
                                        hienthibaocao.Add(ct);
                                    }
                                }
                            }
                        }
                        Entities.BCNhapHangTheoThoiGian tg = new Entities.BCNhapHangTheoThoiGian(hoadonnhap[i].MaHoaDonNhap, "Hóa Đơn Nhập", hoadonnhap[i].NgayNhap, soluong);
                        hienthi.Add(tg);
                    }
                }
                // khách hàng trả lại
                for (int i = 0; i < khachhangtralai.Length; i++)
                {
                    int      soluong   = 0;
                    DateTime ngayphieu = khachhangtralai[i].NgayNhap;
                    if (ngayphieu >= truoc && ngayphieu <= sau)
                    {
                        for (int j = 0; j < chitietkhachhangtralai.Length; j++)
                        {
                            if (khachhangtralai[i].MaKhachHangTraLai == chitietkhachhangtralai[j].MaKhachHangTraLai)
                            {
                                for (int k = 0; k < hanghoa.Length; k++)
                                {
                                    if (!GoiHangOrHangHoa(chitietkhachhangtralai[j].MaHangHoa))
                                    {
                                        if (chitietkhachhangtralai[j].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            int sl = chitietkhachhangtralai[j].SoLuong;
                                            soluong += sl;
                                            Entities.BCNhapHangTheoThoiGianChiTiet ct = new Entities.BCNhapHangTheoThoiGianChiTiet(khachhangtralai[i].MaKhachHangTraLai, "Khách Hàng Trả Lại", khachhangtralai[i].NgayNhap, hanghoa[k].MaHangHoa, hanghoa[k].TenHangHoa, sl);
                                            hienthibaocao.Add(ct);
                                        }
                                    }
                                    ////////////////////////////////////////////////MRK FIX
                                    else
                                    {//là gói hàng
                                        foreach (Entities.GoiHang gh in goihang)
                                        {
                                            foreach (Entities.ChiTietGoiHang ctgh in chitietgoihang)
                                            {
                                                if (gh.MaGoiHang.Equals(ctgh.MaGoiHang) && ctgh.MaGoiHang.Equals(chitietkhachhangtralai[j].MaHangHoa) && ctgh.MaHangHoa.Equals(hanghoa[k].MaHangHoa))
                                                {
                                                    int sl = chitietkhachhangtralai[j].SoLuong * ctgh.SoLuong;
                                                    soluong += sl;
                                                    Entities.BCNhapHangTheoThoiGianChiTiet ct = new Entities.BCNhapHangTheoThoiGianChiTiet(khachhangtralai[i].MaKhachHangTraLai, "Khách Hàng Trả Lại", khachhangtralai[i].NgayNhap, hanghoa[k].MaHangHoa + " (" + ctgh.MaGoiHang + ")", hanghoa[k].TenHangHoa, sl);
                                                    hienthibaocao.Add(ct);
                                                }
                                            }
                                        }
                                    }
                                    ////////////////////////////////////////////////MRK FIX
                                }
                            }
                        }
                        Entities.BCNhapHangTheoThoiGian tg = new Entities.BCNhapHangTheoThoiGian(khachhangtralai[i].MaKhachHangTraLai, "Khách Hàng Trả Lại", khachhangtralai[i].NgayNhap, soluong);
                        hienthi.Add(tg);
                    }
                }


                ///////////////////////////////MRK FIX
                List <Entities.BCNhapHangTheoThoiGian> tem0 = new List <Entities.BCNhapHangTheoThoiGian>();
                int tong0 = 0;
                foreach (Entities.BCNhapHangTheoThoiGian item in hienthi.ToArray())
                {
                    tong0 += item.SoLuong;
                    tem0.Add(item);
                }
                Entities.BCNhapHangTheoThoiGian tem1 = new Entities.BCNhapHangTheoThoiGian();
                tem1.TenChungTu = "Tổng: ";
                tem1.SoLuong    = tong0;
                tem0.Add(tem1);
                //////////////////////////////////////
                //dtgvhienthi.DataSource = hienthi;
                dtgvHienThi.DataSource = tem0.ToArray();

                if (hienthi.ToArray().Length > 0)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
                fix();
            }
            catch
            {
            }
        }
        public void HienThi()
        {
            try
            {
                hienthi = new List<Entities.BCNhapHangTheoThoiGian>();
                hienthibaocao = new List<Entities.BCNhapHangTheoThoiGianChiTiet>();
                int sotangbaocao = 0;
                int sotanghienthi = 0;
                // hóa đơn nhập
                for (int i = 0; i < hoadonnhap.Length; i++)
                {
                    int soluong = 0;
                    DateTime ngayphieu = hoadonnhap[i].NgayNhap;
                    if (ngayphieu >= truoc && ngayphieu <= sau)
                    {
                        for (int j = 0; j < chitiethoadonnhap.Length; j++)
                        {
                            if (hoadonnhap[i].MaHoaDonNhap == chitiethoadonnhap[j].MaHoaDonNhap)
                            {
                                for (int k = 0; k < hanghoa.Length; k++)
                                {
                                    if (chitiethoadonnhap[j].MaHangHoa == hanghoa[k].MaHangHoa)
                                    {
                                        int sl = chitiethoadonnhap[j].SoLuong;
                                        soluong += sl;
                                        Entities.BCNhapHangTheoThoiGianChiTiet ct = new Entities.BCNhapHangTheoThoiGianChiTiet(hoadonnhap[i].MaHoaDonNhap, "Hóa Đơn Nhập", hoadonnhap[i].NgayNhap, hanghoa[k].MaHangHoa, hanghoa[k].TenHangHoa, sl);
                                        hienthibaocao.Add(ct);
                                    }
                                }
                            }
                        }
                        Entities.BCNhapHangTheoThoiGian tg = new Entities.BCNhapHangTheoThoiGian(hoadonnhap[i].MaHoaDonNhap, "Hóa Đơn Nhập", hoadonnhap[i].NgayNhap, soluong);
                        hienthi.Add(tg);
                    }
                }
                // khách hàng trả lại
                for (int i = 0; i < khachhangtralai.Length; i++)
                {
                    int soluong = 0;
                    DateTime ngayphieu = khachhangtralai[i].NgayNhap;
                    if (ngayphieu >= truoc && ngayphieu <= sau)
                    {
                        for (int j = 0; j < chitietkhachhangtralai.Length; j++)
                        {
                            if (khachhangtralai[i].MaKhachHangTraLai == chitietkhachhangtralai[j].MaKhachHangTraLai)
                            {
                                for (int k = 0; k < hanghoa.Length; k++)
                                {
                                    if (!GoiHangOrHangHoa(chitietkhachhangtralai[j].MaHangHoa))
                                    {
                                        if (chitietkhachhangtralai[j].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            int sl = chitietkhachhangtralai[j].SoLuong;
                                            soluong += sl;
                                            Entities.BCNhapHangTheoThoiGianChiTiet ct = new Entities.BCNhapHangTheoThoiGianChiTiet(khachhangtralai[i].MaKhachHangTraLai, "Khách Hàng Trả Lại", khachhangtralai[i].NgayNhap, hanghoa[k].MaHangHoa, hanghoa[k].TenHangHoa, sl);
                                            hienthibaocao.Add(ct);
                                        }
                                    }
                                    ////////////////////////////////////////////////MRK FIX
                                    else
                                    {//là gói hàng
                                        foreach (Entities.GoiHang gh in goihang)
                                        {
                                            foreach (Entities.ChiTietGoiHang ctgh in chitietgoihang)
                                            {
                                                if (gh.MaGoiHang.Equals(ctgh.MaGoiHang) && ctgh.MaGoiHang.Equals(chitietkhachhangtralai[j].MaHangHoa) && ctgh.MaHangHoa.Equals(hanghoa[k].MaHangHoa))
                                                {
                                                    int sl = chitietkhachhangtralai[j].SoLuong * ctgh.SoLuong;
                                                    soluong += sl;
                                                    Entities.BCNhapHangTheoThoiGianChiTiet ct = new Entities.BCNhapHangTheoThoiGianChiTiet(khachhangtralai[i].MaKhachHangTraLai, "Khách Hàng Trả Lại", khachhangtralai[i].NgayNhap, hanghoa[k].MaHangHoa + " (" + ctgh.MaGoiHang + ")", hanghoa[k].TenHangHoa, sl);
                                                    hienthibaocao.Add(ct);
                                                }
                                            }
                                        }
                                    }
                                    ////////////////////////////////////////////////MRK FIX
                                }
                            }
                        }
                        Entities.BCNhapHangTheoThoiGian tg = new Entities.BCNhapHangTheoThoiGian(khachhangtralai[i].MaKhachHangTraLai, "Khách Hàng Trả Lại", khachhangtralai[i].NgayNhap, soluong);
                        hienthi.Add(tg);
                    }
                }

                ///////////////////////////////MRK FIX
                List<Entities.BCNhapHangTheoThoiGian> tem0 = new List<Entities.BCNhapHangTheoThoiGian>();
                int tong0 = 0;
                foreach (Entities.BCNhapHangTheoThoiGian item in hienthi.ToArray())
                {
                    tong0 += item.SoLuong;
                    tem0.Add(item);
                }
                Entities.BCNhapHangTheoThoiGian tem1 = new Entities.BCNhapHangTheoThoiGian();
                tem1.TenChungTu = "Tổng: ";
                tem1.SoLuong = tong0;
                tem0.Add(tem1);
                //////////////////////////////////////
                //dtgvhienthi.DataSource = hienthi;
                dtgvHienThi.DataSource = tem0.ToArray();

                if (hienthi.ToArray().Length > 0)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
                fix();
            }
            catch
            {
            }
        }
        private void toolStripStatusLabel2_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            try
            {
                if (KiemTra())
                {
                    LayNgay();
                    PhieuXuatHuy();
                    ChiTietXuatHuy();
                    HDBanHang1();
                    ChiTietHDBanHang();
                    TraLaiNCC();
                    ChiTietTraLaiNCC();

                    HangHoa1();
                    GoiHang();
                    ChiTietGoiHang();
                    TongTienNhanVien();

                    LayChiTiet_HangHoaXuat_TheoNhomHang();

                    ///////////////////////////////MRK FIX
                    List<Entities.BCNhapHangTheoThoiGian> tem0 = new List<Entities.BCNhapHangTheoThoiGian>();
                    int tong0 = 0;
                    foreach (Entities.BCNhapHangTheoThoiGian item in temp)
                    {
                        tong0 += item.SoLuong;
                        tem0.Add(item);
                    }
                    Entities.BCNhapHangTheoThoiGian tem1 = new Entities.BCNhapHangTheoThoiGian();
                    tem1.TenChungTu = "Tổng: ";
                    tem1.SoLuong = tong0;
                    tem0.Add(tem1);
                    //////////////////////////////////////
                    //dtgvhienthi.DataSource = temp;
                    dtgvHienThi.DataSource = tem0.ToArray();

                    FixDatagridview();

                }
            }
            catch
            {
            }
            finally
            {
                this.Enabled = true;
                this.Focus();
            }
        }
        public void TongTienNhanVien()
        {
            try
            {
                List<Entities.BCNhapHangTheoThoiGian> l = new List<Entities.BCNhapHangTheoThoiGian>();
                List<Entities.BCNhapHangTheoThoiGianChiTiet> lhienthi = new List<Entities.BCNhapHangTheoThoiGianChiTiet>();

                foreach (Entities.HangHoa hh in this.hanghoa)
                {
                    int tongxuat = 0;

                    //Xuất Hủy
                    foreach (Entities.PhieuXuatHuy item in this.phieuxuathuy)
                    {
                        DateTime tem = item.NgayLap;
                        if ((tem >= truoc) && (tem <= sau) && (item.TrangThai == true))
                        {
                            foreach (Entities.ChiTietXuatHuy item1 in this.chitietxuathuy)
                            {
                                if (item1.MaPhieuXuatHuy.Equals(item.MaPhieuXuatHuy) && (item1.MaHangHoa.Equals(hh.MaHangHoa)))
                                {
                                    tongxuat += item1.SoLuong;
                                    lhienthi.Add(new Entities.BCNhapHangTheoThoiGianChiTiet(item.MaPhieuXuatHuy,"Phiếu xuất hủy",item.NgayLap,hh.MaHangHoa,hh.TenHangHoa,item1.SoLuong));
                                }
                            }
                        }
                    }
                    //Hóa đơn bán hàng
                    foreach (Entities.HDBanHang item in this.hdbanhang)
                    {
                        DateTime tem = item.NgayBan;
                        if ((tem >= truoc) && (tem <= sau))
                        {
                            foreach (Entities.ChiTietHDBanHang item1 in this.chitiethdbanhang)
                            {
                                if (item1.MaHDBanHang.Equals(item.MaHDBanHang))
                                {
                                    bool runBC = false;
                                    int tongxuatBC = 0;
                                    if (GoiHangOrHangHoa(item1.MaHangHoa))
                                    {//là gói hàng
                                        foreach (Entities.GoiHang gh in this.goihang)
                                        {
                                            foreach (Entities.ChiTietGoiHang ctgh in this.chitietgoihang)
                                            {
                                                if (gh.MaGoiHang.Equals(ctgh.MaGoiHang) && (item1.MaHangHoa.Equals(ctgh.MaGoiHang)))
                                                {
                                                    if (ctgh.MaHangHoa.Equals(hh.MaHangHoa))
                                                    {
                                                        tongxuat += item1.SoLuong * ctgh.SoLuong;
                                                        tongxuatBC += item1.SoLuong * ctgh.SoLuong;
                                                        runBC = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {//là hàng hóa
                                        if (item1.MaHangHoa.Equals(hh.MaHangHoa))
                                        {
                                            tongxuat += item1.SoLuong;
                                            tongxuatBC += item1.SoLuong;
                                            runBC = true;
                                        }
                                    }
                                    if (runBC)
                                    {
                                        lhienthi.Add(new Entities.BCNhapHangTheoThoiGianChiTiet(item.MaHDBanHang, "Hóa Đơn Bán Hàng", item.NgayBan, hh.MaHangHoa, hh.TenHangHoa, tongxuatBC));
                                    }
                                }
                            }
                        }
                    }
                    //Trả lại nhà cung cấp
                    foreach (Entities.TraLaiNCC item in this.tralaincc)
                    {
                        DateTime tem = item.Ngaytra;
                        if ((tem >= truoc) && (tem <= sau))
                        {
                            foreach (Entities.ChiTietTraLaiNhaCungCap item1 in this.chitiettralaincc)
                            {
                                if (item1.MaHDTraLaiNCC.Equals(item.MaHDTraLaiNCC) && item1.MaHangHoa.Equals(hh.MaHangHoa))
                                {
                                    tongxuat += item1.SoLuong;
                                }
                            }
                        }
                    }

                    if (tongxuat == 0)
                    {//Nếu hàng hóa này không có sự xuất đi thì không hiển thị
                        continue;
                    }
                    else
                    {
                        Entities.BCNhapHangTheoThoiGian bientam = new Entities.BCNhapHangTheoThoiGian();
                        bientam.MaChungTu = hh.MaHangHoa;
                        bientam.TenChungTu = hh.TenHangHoa;
                        bientam.NgayLap = new DateTime(1753, 1, 1);
                        bientam.SoLuong = tongxuat;
                        l.Add(bientam);
                    }
                }

                hienthi = new Entities.BCNhapHangTheoThoiGian[l.Count];

                for (int i = 0; i < l.Count; i++)
                {
                    hienthi[i] = l[i];
                }

                hienthibaocao = new Entities.BCNhapHangTheoThoiGianChiTiet[lhienthi.Count];

                for (int i = 0; i < lhienthi.Count; i++)
                {
                    hienthibaocao[i] = lhienthi[i];
                }

                ///////////////////////////////MRK FIX
                List<Entities.BCNhapHangTheoThoiGian> tem0 = new List<Entities.BCNhapHangTheoThoiGian>();
                int tong0 = 0;
                foreach (Entities.BCNhapHangTheoThoiGian item in hienthi)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    tong0 += item.SoLuong;
                    tem0.Add(item);
                }
                Entities.BCNhapHangTheoThoiGian tem1 = new Entities.BCNhapHangTheoThoiGian();
                tem1.TenChungTu = "Tổng: ";
                tem1.SoLuong = tong0;
                tem0.Add(tem1);
                //////////////////////////////////////
                //dtgvhienthi.DataSource = hienthibaocao;
                dtgvHienThi.DataSource = tem0.ToArray();
                FixDatagridview();

                if (tem0.ToArray().Length > 0)
                {
                    enable();
                }
                else
                {
                    disable();
                }

            }
            catch { }
        }
        public void LayChiTiet_HangHoaXuat_TheoNhomHang()
        {
            try
            {
                int sl = 0;

                temp = new Entities.BCNhapHangTheoThoiGian[hienthi.Length];
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (hienthi[i].SoLuong != 0)
                    {
                        temp[sl] = hienthi[i];
                        sl++;
                    }
                }
                Entities.BCNhapHangTheoThoiGian[] baocao = new Entities.BCNhapHangTheoThoiGian[sl];
                for (int i = 0; i < sl; i++)
                {
                    baocao[i] = temp[i];
                }

            }
            catch
            {
            }
        }
        public void TongTienNhanVien()
        {
            try
            {
                List <Entities.BCNhapHangTheoThoiGian>        l        = new List <Entities.BCNhapHangTheoThoiGian>();
                List <Entities.BCNhapHangTheoThoiGianChiTiet> lhienthi = new List <Entities.BCNhapHangTheoThoiGianChiTiet>();

                foreach (Entities.HangHoa hh in this.hanghoa)
                {
                    int tongxuat = 0;

                    //Xuất Hủy
                    foreach (Entities.PhieuXuatHuy item in this.phieuxuathuy)
                    {
                        DateTime tem = item.NgayLap;
                        if ((tem >= truoc) && (tem <= sau) && (item.TrangThai == true))
                        {
                            foreach (Entities.ChiTietXuatHuy item1 in this.chitietxuathuy)
                            {
                                if (item1.MaPhieuXuatHuy.Equals(item.MaPhieuXuatHuy) && (item1.MaHangHoa.Equals(hh.MaHangHoa)))
                                {
                                    tongxuat += item1.SoLuong;
                                    lhienthi.Add(new Entities.BCNhapHangTheoThoiGianChiTiet(item.MaPhieuXuatHuy, "Phiếu xuất hủy", item.NgayLap, hh.MaHangHoa, hh.TenHangHoa, item1.SoLuong));
                                }
                            }
                        }
                    }
                    //Hóa đơn bán hàng
                    foreach (Entities.HDBanHang item in this.hdbanhang)
                    {
                        DateTime tem = item.NgayBan;
                        if ((tem >= truoc) && (tem <= sau))
                        {
                            foreach (Entities.ChiTietHDBanHang item1 in this.chitiethdbanhang)
                            {
                                if (item1.MaHDBanHang.Equals(item.MaHDBanHang))
                                {
                                    bool runBC      = false;
                                    int  tongxuatBC = 0;
                                    if (GoiHangOrHangHoa(item1.MaHangHoa))
                                    {//là gói hàng
                                        foreach (Entities.GoiHang gh in this.goihang)
                                        {
                                            foreach (Entities.ChiTietGoiHang ctgh in this.chitietgoihang)
                                            {
                                                if (gh.MaGoiHang.Equals(ctgh.MaGoiHang) && (item1.MaHangHoa.Equals(ctgh.MaGoiHang)))
                                                {
                                                    if (ctgh.MaHangHoa.Equals(hh.MaHangHoa))
                                                    {
                                                        tongxuat   += item1.SoLuong * ctgh.SoLuong;
                                                        tongxuatBC += item1.SoLuong * ctgh.SoLuong;
                                                        runBC       = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {//là hàng hóa
                                        if (item1.MaHangHoa.Equals(hh.MaHangHoa))
                                        {
                                            tongxuat   += item1.SoLuong;
                                            tongxuatBC += item1.SoLuong;
                                            runBC       = true;
                                        }
                                    }
                                    if (runBC)
                                    {
                                        lhienthi.Add(new Entities.BCNhapHangTheoThoiGianChiTiet(item.MaHDBanHang, "Hóa Đơn Bán Hàng", item.NgayBan, hh.MaHangHoa, hh.TenHangHoa, tongxuatBC));
                                    }
                                }
                            }
                        }
                    }
                    //Trả lại nhà cung cấp
                    foreach (Entities.TraLaiNCC item in this.tralaincc)
                    {
                        DateTime tem = item.Ngaytra;
                        if ((tem >= truoc) && (tem <= sau))
                        {
                            foreach (Entities.ChiTietTraLaiNhaCungCap item1 in this.chitiettralaincc)
                            {
                                if (item1.MaHDTraLaiNCC.Equals(item.MaHDTraLaiNCC) && item1.MaHangHoa.Equals(hh.MaHangHoa))
                                {
                                    tongxuat += item1.SoLuong;
                                }
                            }
                        }
                    }

                    if (tongxuat == 0)
                    {//Nếu hàng hóa này không có sự xuất đi thì không hiển thị
                        continue;
                    }
                    else
                    {
                        Entities.BCNhapHangTheoThoiGian bientam = new Entities.BCNhapHangTheoThoiGian();
                        bientam.MaChungTu  = hh.MaHangHoa;
                        bientam.TenChungTu = hh.TenHangHoa;
                        bientam.NgayLap    = new DateTime(1753, 1, 1);
                        bientam.SoLuong    = tongxuat;
                        l.Add(bientam);
                    }
                }

                hienthi = new Entities.BCNhapHangTheoThoiGian[l.Count];

                for (int i = 0; i < l.Count; i++)
                {
                    hienthi[i] = l[i];
                }

                hienthibaocao = new Entities.BCNhapHangTheoThoiGianChiTiet[lhienthi.Count];

                for (int i = 0; i < lhienthi.Count; i++)
                {
                    hienthibaocao[i] = lhienthi[i];
                }

                ///////////////////////////////MRK FIX
                List <Entities.BCNhapHangTheoThoiGian> tem0 = new List <Entities.BCNhapHangTheoThoiGian>();
                int tong0 = 0;
                foreach (Entities.BCNhapHangTheoThoiGian item in hienthi)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    tong0 += item.SoLuong;
                    tem0.Add(item);
                }
                Entities.BCNhapHangTheoThoiGian tem1 = new Entities.BCNhapHangTheoThoiGian();
                tem1.TenChungTu = "Tổng: ";
                tem1.SoLuong    = tong0;
                tem0.Add(tem1);
                //////////////////////////////////////
                //dtgvhienthi.DataSource = hienthibaocao;
                dtgvHienThi.DataSource = tem0.ToArray();
                FixDatagridview();

                if (tem0.ToArray().Length > 0)
                {
                    enable();
                }
                else
                {
                    disable();
                }
            }
            catch { }
        }