// lay danh sach san pham theo ngay thang nam public List <SanPham_ThongKe> layDSSPTheo(DateTime fromday, DateTime today) { var dsChitiet = from hd in qlhd.QL_HoaDon_BanHangs from chitiet in qlhd.QL_ChiTietHoaDons where hd.MaHD == chitiet.MaHD && hd.NgayLap >= fromday && hd.NgayLap <= today select chitiet; List <SanPham_ThongKe> lstSP = new List <SanPham_ThongKe>(); List <QL_ChiTietHoaDon> lstChiTiet = dsChitiet.ToList(); foreach (QL_ChiTietHoaDon chitiet in lstChiTiet) { // kiem tra sp trung if (lstSP.Count(t => t.Masp == chitiet.MaSP) == 0) { SanPham_ThongKe sptk = new SanPham_ThongKe(); sptk.Masp = chitiet.MaSP; sptk.Soluong += (int)chitiet.Soluong; sptk.Dongia = (int)chitiet.DonGia; lstSP.Add(sptk); } else { SanPham_ThongKe sptk = lstSP.SingleOrDefault(t => t.Masp == chitiet.MaSP); sptk.Soluong += (int)chitiet.Soluong; } } return(lstSP); }
// lay danh sach san pham theo ngay thang nam public List <SanPham_ThongKe> layDSSPTheo(DateTime fromday, DateTime today) { var dsChitiet = from hdon in hd.HOADONs from chitiet in hd.CT_HOADONs where hdon.MAHD == chitiet.MAHD && hdon.NGAYLAP >= fromday && hdon.NGAYLAP <= today select chitiet; List <SanPham_ThongKe> lstSP = new List <SanPham_ThongKe>(); List <CT_HOADON> lstChiTiet = dsChitiet.ToList(); foreach (CT_HOADON chitiet in lstChiTiet) { // kiem tra sp trung if (lstSP.Count(t => t.MASP == chitiet.MASP) == 0) { SanPham_ThongKe sptk = new SanPham_ThongKe(); sptk.MASP = chitiet.MASP; sptk.SOLUONG += (int)chitiet.SOLUONG; sptk.DONGIA = (int)chitiet.THANHTIEN; lstSP.Add(sptk); } else { SanPham_ThongKe sptk = lstSP.SingleOrDefault(t => t.MASP == chitiet.MASP); sptk.SOLUONG += (int)chitiet.SOLUONG; } } return(lstSP); }