public Entities.BCNhapHangTheoNhomChiTiet[] ChiTietKho(string makho)
 {
     try
     {
         int sl = 0;
         Entities.BCNhapHangTheoNhomChiTiet[] temp = new Entities.BCNhapHangTheoNhomChiTiet[hienthibaocao.Length];
         for (int i = 0; i < hienthibaocao.Length; i++)
         {
             if (hienthibaocao[i].MaNhomHang == makho)
             {
                 if (hienthibaocao[i].SoLuong > 0)
                 {
                     temp[sl] = hienthibaocao[i];
                     sl++;
                 }
             }
         }
         Entities.BCNhapHangTheoNhomChiTiet[] baocao = new Entities.BCNhapHangTheoNhomChiTiet[sl];
         for (int i = 0; i < sl; i++)
         {
             baocao[i] = temp[i];
         }
         return(baocao);
     }
     catch
     {
         return(new Entities.BCNhapHangTheoNhomChiTiet[0]);
     }
 }
        public void TongTienNhanVien()
        {
            try
            {
                nam = int.Parse(cbbnam.Text);
                thang = int.Parse(cbbthang.Text);
                double tongnhap, nhap;
                int sotang = 0;
                hienthi = new Entities.BCNhapHangTheoNhom[nhomhang.Length];
                for (int i = 0; i < nhomhang.Length; i++)
                {
                    for (int k = 0; k < hanghoa.Length; k++)
                    {
                        if (hanghoa[k].MaNhomHangHoa == nhomhang[i].MaNhomHang)
                        {
                            sotang++;
                        }
                    }
                }

                hienthibaocao = new Entities.BCNhapHangTheoNhomChiTiet[sotang];
                sotang = 0;
                for (int i = 0; i < nhomhang.Length; i++)
                {
                    tongnhap = 0;
                    for (int k = 0; k < hanghoa.Length; k++)
                    {
                        nhap = 0;
                        if (hanghoa[k].MaNhomHangHoa == nhomhang[i].MaNhomHang)
                        {
                            // nhập hàng - hóa đơn nhập
                            for (int l = 0; l < hoadonnhap.Length; l++)
                            {
                                for (int o = 0; o < chitiethoadonnhap.Length; o++)
                                {
                                    int namphieu = hoadonnhap[l].NgayNhap.Year;
                                    int thangphieu = hoadonnhap[l].NgayNhap.Month;

                                    if (chitiethoadonnhap[o].MaHoaDonNhap == hoadonnhap[l].MaHoaDonNhap && nam == namphieu && thang == thangphieu)
                                    {
                                        if (chitiethoadonnhap[o].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            tongnhap += chitiethoadonnhap[o].SoLuong;
                                            nhap += chitiethoadonnhap[o].SoLuong;
                                        }
                                    }
                                }
                            }
                            // nhập hàng - khách hàng trả lại
                            for (int l = 0; l < khachhangtralai.Length; l++)
                            {
                                for (int o = 0; o < chitietkhachhangtralai.Length; o++)
                                {
                                    int namphieu = khachhangtralai[l].NgayNhap.Year;
                                    int thangphieu = khachhangtralai[l].NgayNhap.Month;
                                    if (chitietkhachhangtralai[o].MaKhachHangTraLai == khachhangtralai[l].MaKhachHangTraLai && nam == namphieu && thang == thangphieu)
                                    {
                                        if (chitietkhachhangtralai[o].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            tongnhap += chitietkhachhangtralai[o].SoLuong;
                                            nhap += chitietkhachhangtralai[o].SoLuong;
                                        }
                                        ////////////////////////////////////////////////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[o].MaHangHoa) && ctgh.MaHangHoa.Equals(hanghoa[k].MaHangHoa))
                                                    {
                                                        tongnhap += (chitietkhachhangtralai[o].SoLuong * ctgh.SoLuong);
                                                        nhap += (chitietkhachhangtralai[o].SoLuong * ctgh.SoLuong);
                                                    }
                                                }
                                            }
                                        }
                                        ////////////////////////////////////////////////MRK FIX
                                    }
                                }
                            }
                            // nhập hàng - phiếu điều chuyển kho nội bộ
                            for (int l = 0; l < phieudieuchuyenkhonoibo.Length; l++)
                            {
                                for (int o = 0; o < chitietphieudieuchuyenkho.Length; o++)
                                {
                                    int namphieu = phieudieuchuyenkhonoibo[l].NgayDieuChuyen.Year;
                                    int thangphieu = phieudieuchuyenkhonoibo[l].NgayDieuChuyen.Month;
                                    if (chitietphieudieuchuyenkho[o].MaPhieuDieuChuyenKho == phieudieuchuyenkhonoibo[l].MaPhieuDieuChuyenKho && nam == namphieu && thang == thangphieu)
                                    {
                                        if (chitietphieudieuchuyenkho[o].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            tongnhap += chitietphieudieuchuyenkho[o].SoLuong;
                                            nhap += chitietphieudieuchuyenkho[o].SoLuong;
                                        }
                                        ////////////////////////////////////////////////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(chitietphieudieuchuyenkho[o].MaHangHoa) && ctgh.MaHangHoa.Equals(hanghoa[k].MaHangHoa))
                                                    {
                                                        tongnhap += (chitietphieudieuchuyenkho[o].SoLuong * ctgh.SoLuong);
                                                        nhap += (chitietphieudieuchuyenkho[o].SoLuong * ctgh.SoLuong);
                                                    }
                                                }
                                            }
                                        }
                                        ////////////////////////////////////////////////MRK FIX
                                    }
                                }
                            }
                            hienthibaocao[sotang] = new Entities.BCNhapHangTheoNhomChiTiet(nhomhang[i].MaNhomHang, nhomhang[i].TenNhomHang, hanghoa[k].MaHangHoa, hanghoa[k].TenHangHoa, nhap);
                            sotang++;
                        }
                    }
                    hienthi[i] = new Entities.BCNhapHangTheoNhom("", nhomhang[i].MaNhomHang, nhomhang[i].TenNhomHang, tongnhap.ToString());
                }
                Entities.BCNhapHangTheoNhom[] temp = new Entities.BCNhapHangTheoNhom[hienthi.Length];
                int soluong = 0;
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (hienthi[i].TongNhap != "0")
                    {
                        temp[soluong] = hienthi[i];
                        soluong++;
                    }
                }
                hienthi = new Entities.BCNhapHangTheoNhom[soluong];
                for (int i = 0; i < soluong; i++)
                {
                    hienthi[i] = temp[i];
                }
                ///////////////////////////////MRK FIX
                List<Entities.BCNhapHangTheoNhom> tem0 = new List<Entities.BCNhapHangTheoNhom>();
                double tong0 = 0;
                foreach (Entities.BCNhapHangTheoNhom item in hienthi)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    tong0 += double.Parse(item.TongNhap);
                    tem0.Add(item);
                }
                Entities.BCNhapHangTheoNhom tem1 = new Entities.BCNhapHangTheoNhom();
                tem1.TenNhomHang = "Tổng: ";
                tem1.TongNhap = tong0.ToString();
                tem0.Add(tem1);
                //////////////////////////////////////
                //dtgvhienthi.DataSource = hienthi;
                dtgvhienthi.DataSource = tem0.ToArray();

                if (hienthi.Length > 0)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
            }
            catch { }
            finally
            {
                fix();
            }
        }
        public void TongTienNhanVien()
        {
            try
            {
                nam   = int.Parse(cbbnam.Text);
                thang = int.Parse(cbbthang.Text);
                double tongnhap, nhap;
                int    sotang = 0;
                hienthi = new Entities.BCNhapHangTheoNhom[nhomhang.Length];
                for (int i = 0; i < nhomhang.Length; i++)
                {
                    for (int k = 0; k < hanghoa.Length; k++)
                    {
                        if (hanghoa[k].MaNhomHangHoa == nhomhang[i].MaNhomHang)
                        {
                            sotang++;
                        }
                    }
                }

                hienthibaocao = new Entities.BCNhapHangTheoNhomChiTiet[sotang];
                sotang        = 0;
                for (int i = 0; i < nhomhang.Length; i++)
                {
                    tongnhap = 0;
                    for (int k = 0; k < hanghoa.Length; k++)
                    {
                        nhap = 0;
                        if (hanghoa[k].MaNhomHangHoa == nhomhang[i].MaNhomHang)
                        {
                            // nhập hàng - hóa đơn nhập
                            for (int l = 0; l < hoadonnhap.Length; l++)
                            {
                                for (int o = 0; o < chitiethoadonnhap.Length; o++)
                                {
                                    int namphieu   = hoadonnhap[l].NgayNhap.Year;
                                    int thangphieu = hoadonnhap[l].NgayNhap.Month;

                                    if (chitiethoadonnhap[o].MaHoaDonNhap == hoadonnhap[l].MaHoaDonNhap && nam == namphieu && thang == thangphieu)
                                    {
                                        if (chitiethoadonnhap[o].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            tongnhap += chitiethoadonnhap[o].SoLuong;
                                            nhap     += chitiethoadonnhap[o].SoLuong;
                                        }
                                    }
                                }
                            }
                            // nhập hàng - khách hàng trả lại
                            for (int l = 0; l < khachhangtralai.Length; l++)
                            {
                                for (int o = 0; o < chitietkhachhangtralai.Length; o++)
                                {
                                    int namphieu   = khachhangtralai[l].NgayNhap.Year;
                                    int thangphieu = khachhangtralai[l].NgayNhap.Month;
                                    if (chitietkhachhangtralai[o].MaKhachHangTraLai == khachhangtralai[l].MaKhachHangTraLai && nam == namphieu && thang == thangphieu)
                                    {
                                        if (chitietkhachhangtralai[o].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            tongnhap += chitietkhachhangtralai[o].SoLuong;
                                            nhap     += chitietkhachhangtralai[o].SoLuong;
                                        }
                                        ////////////////////////////////////////////////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[o].MaHangHoa) && ctgh.MaHangHoa.Equals(hanghoa[k].MaHangHoa))
                                                    {
                                                        tongnhap += (chitietkhachhangtralai[o].SoLuong * ctgh.SoLuong);
                                                        nhap     += (chitietkhachhangtralai[o].SoLuong * ctgh.SoLuong);
                                                    }
                                                }
                                            }
                                        }
                                        ////////////////////////////////////////////////MRK FIX
                                    }
                                }
                            }
                            // nhập hàng - phiếu điều chuyển kho nội bộ
                            for (int l = 0; l < phieudieuchuyenkhonoibo.Length; l++)
                            {
                                for (int o = 0; o < chitietphieudieuchuyenkho.Length; o++)
                                {
                                    int namphieu   = phieudieuchuyenkhonoibo[l].NgayDieuChuyen.Year;
                                    int thangphieu = phieudieuchuyenkhonoibo[l].NgayDieuChuyen.Month;
                                    if (chitietphieudieuchuyenkho[o].MaPhieuDieuChuyenKho == phieudieuchuyenkhonoibo[l].MaPhieuDieuChuyenKho && nam == namphieu && thang == thangphieu)
                                    {
                                        if (chitietphieudieuchuyenkho[o].MaHangHoa == hanghoa[k].MaHangHoa)
                                        {
                                            tongnhap += chitietphieudieuchuyenkho[o].SoLuong;
                                            nhap     += chitietphieudieuchuyenkho[o].SoLuong;
                                        }
                                        ////////////////////////////////////////////////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(chitietphieudieuchuyenkho[o].MaHangHoa) && ctgh.MaHangHoa.Equals(hanghoa[k].MaHangHoa))
                                                    {
                                                        tongnhap += (chitietphieudieuchuyenkho[o].SoLuong * ctgh.SoLuong);
                                                        nhap     += (chitietphieudieuchuyenkho[o].SoLuong * ctgh.SoLuong);
                                                    }
                                                }
                                            }
                                        }
                                        ////////////////////////////////////////////////MRK FIX
                                    }
                                }
                            }
                            hienthibaocao[sotang] = new Entities.BCNhapHangTheoNhomChiTiet(nhomhang[i].MaNhomHang, nhomhang[i].TenNhomHang, hanghoa[k].MaHangHoa, hanghoa[k].TenHangHoa, nhap);
                            sotang++;
                        }
                    }
                    hienthi[i] = new Entities.BCNhapHangTheoNhom("", nhomhang[i].MaNhomHang, nhomhang[i].TenNhomHang, tongnhap.ToString());
                }
                Entities.BCNhapHangTheoNhom[] temp = new Entities.BCNhapHangTheoNhom[hienthi.Length];
                int soluong = 0;
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (hienthi[i].TongNhap != "0")
                    {
                        temp[soluong] = hienthi[i];
                        soluong++;
                    }
                }
                hienthi = new Entities.BCNhapHangTheoNhom[soluong];
                for (int i = 0; i < soluong; i++)
                {
                    hienthi[i] = temp[i];
                }
                ///////////////////////////////MRK FIX
                List <Entities.BCNhapHangTheoNhom> tem0 = new List <Entities.BCNhapHangTheoNhom>();
                double tong0 = 0;
                foreach (Entities.BCNhapHangTheoNhom item in hienthi)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    tong0 += double.Parse(item.TongNhap);
                    tem0.Add(item);
                }
                Entities.BCNhapHangTheoNhom tem1 = new Entities.BCNhapHangTheoNhom();
                tem1.TenNhomHang = "Tổng: ";
                tem1.TongNhap    = tong0.ToString();
                tem0.Add(tem1);
                //////////////////////////////////////
                //dtgvhienthi.DataSource = hienthi;
                dtgvhienthi.DataSource = tem0.ToArray();

                if (hienthi.Length > 0)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
            }
            catch { }
            finally
            {
                fix();
            }
        }
 public Entities.BCNhapHangTheoNhomChiTiet[] ChiTietKho(string makho)
 {
     try
     {
         int sl = 0;
         Entities.BCNhapHangTheoNhomChiTiet[] temp = new Entities.BCNhapHangTheoNhomChiTiet[hienthibaocao.Length];
         for (int i = 0; i < hienthibaocao.Length; i++)
         {
             if (hienthibaocao[i].MaNhomHang == makho)
             {
                 if (hienthibaocao[i].SoLuong > 0)
                 {
                     temp[sl] = hienthibaocao[i];
                     sl++;
                 }
             }
         }
          Entities.BCNhapHangTheoNhomChiTiet[] baocao = new Entities.BCNhapHangTheoNhomChiTiet[sl];
         for (int i = 0; i < sl; i++)
         {
             baocao[i] = temp[i];
         }
         return baocao;
     }
     catch
     {
         return new Entities.BCNhapHangTheoNhomChiTiet[0];
     }
 }