private void txttimkiem_TextChanged(object sender, EventArgs e) { try { if (rdbtimkiem3.Checked == true) { return; } if (txttimkiem.Text.Length == 0) { dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoKho[0]; return; } int soluong = 0; if (hienthi != null) { if (rdbtimkiem1.Checked == true) { for (int i = 0; i < hienthi.Length; i++) { int kiemtra = hienthi[i].MaKho.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper()); if (kiemtra >= 0) { soluong++; } } if (soluong == 0) { dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoKho[0]; return; } Entities.BCXuatNhapTonTheoKho[] hienthitheoid = new Entities.BCXuatNhapTonTheoKho[soluong]; soluong = 0; for (int i = 0; i < hienthi.Length; i++) { int kiemtra = hienthi[i].MaKho.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper()); if (kiemtra >= 0) { hienthitheoid[soluong] = hienthi[i]; soluong++; } } ///////////////////////////////MRK FIX List<Entities.BCXuatNhapTonTheoKho> tem0 = new List<Entities.BCXuatNhapTonTheoKho>(); double tong0 = 0; double tong1 = 0; double tong2 = 0; double tong3 = 0; foreach (Entities.BCXuatNhapTonTheoKho item in hienthitheoid) { tong0 += double.Parse(item.SoDuDauKy); tong1 += double.Parse(item.TongNhap); tong2 += double.Parse(item.TongXuat); tong3 += double.Parse(item.SoDuCuoiKy); tem0.Add(item); } Entities.BCXuatNhapTonTheoKho tem1 = new Entities.BCXuatNhapTonTheoKho(); tem1.TenKho = "Tổng: "; tem1.SoDuDauKy = tong0.ToString(); tem1.TongNhap = tong1.ToString(); tem1.TongXuat = tong2.ToString(); tem1.SoDuCuoiKy = tong3.ToString(); tem0.Add(tem1); ////////////////////////////////////// //dtgvhienthi.DataSource = hienthitheoid; dtgvhienthi.DataSource = tem0.ToArray(); } if (rdbtimkiem2.Checked == true) { for (int i = 0; i < hienthi.Length; i++) { int kiemtra = hienthi[i].TenKho.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper()); if (kiemtra >= 0) { soluong++; } } if (soluong == 0) { dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoKho[0]; return; } Entities.BCXuatNhapTonTheoKho[] hienthitheoma = new Entities.BCXuatNhapTonTheoKho[soluong]; soluong = 0; for (int i = 0; i < hienthi.Length; i++) { int kiemtra = hienthi[i].TenKho.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper()); if (kiemtra >= 0) { hienthitheoma[soluong] = hienthi[i]; soluong++; } } ///////////////////////////////MRK FIX List<Entities.BCXuatNhapTonTheoKho> tem0 = new List<Entities.BCXuatNhapTonTheoKho>(); double tong0 = 0; double tong1 = 0; double tong2 = 0; double tong3 = 0; foreach (Entities.BCXuatNhapTonTheoKho item in hienthitheoma) { tong0 += double.Parse(item.SoDuDauKy); tong1 += double.Parse(item.TongNhap); tong2 += double.Parse(item.TongXuat); tong3 += double.Parse(item.SoDuCuoiKy); tem0.Add(item); } Entities.BCXuatNhapTonTheoKho tem1 = new Entities.BCXuatNhapTonTheoKho(); tem1.TenKho = "Tổng: "; tem1.SoDuDauKy = tong0.ToString(); tem1.TongNhap = tong1.ToString(); tem1.TongXuat = tong2.ToString(); tem1.SoDuCuoiKy = tong3.ToString(); tem0.Add(tem1); ////////////////////////////////////// //dtgvhienthi.DataSource = hienthitheoma; dtgvhienthi.DataSource = tem0.ToArray(); } } } finally { fix(); } }
public void TongTienNhanVien() { try { nam = int.Parse(cbbnam.Text); thang = int.Parse(cbbthang.Text); double sddk, sddkhh, sdckhh, sdck, tongxuat, tongnhap; double nhapmua, nhaptralai, nhapkhac; double xuatban, xuattralai, xuatkhac; nhapmua = nhaptralai = nhapkhac = xuatban = xuattralai = xuatkhac = 0; sdckhh = sddkhh = sdck = sddk = 0; int sotang = 0; hienthi = new Entities.BCXuatNhapTonTheoKho[khohang.Length]; for (int i = 0; i < khohang.Length; i++) { for (int j = 0; j < chitietkhohang.Length; j++) { if (chitietkhohang[j].Makho == khohang[i].MaKho) { for (int k = 0; k < hanghoa.Length; k++) { if (hanghoa[k].MaHangHoa == chitietkhohang[j].Mahanghoa) { sotang++; //Đếm số hàng hóa trong kho } } } } } int sohanghoatrongkho = sotang; hienthibaocao = new Entities.BCXuatNhapTonTheoKhoChiTiet[sotang]; sotang = 0; for (int i = 0; i < khohang.Length; i++) { tongxuat = tongnhap = sddk = 0; for (int j = 0; j < chitietkhohang.Length; j++) { if (chitietkhohang[j].Makho == khohang[i].MaKho) { for (int k = 0; k < hanghoa.Length; k++) { if (hanghoa[k].MaHangHoa == chitietkhohang[j].Mahanghoa) { sdckhh = sddkhh = sdck = 0; // số dư đầu kỳ for (int l = 0; l < sodukho.Length; l++) { if (sodukho[l].MaHangHoa == hanghoa[k].MaHangHoa) { int namphieu = sodukho[l].NgayKetChuyen.Year; int thangphieu = sodukho[l].NgayKetChuyen.Month; if (nam == namphieu && thang == thangphieu) { sddk += sodukho[l].SoDuDauKy; sddkhh = sodukho[l].SoDuDauKy; break; } } } // xuất hàng - phiếu xuất hủy nhapmua = nhaptralai = nhapkhac = xuatban = xuattralai = xuatkhac = 0; for (int l = 0; l < phieuxuathuy.Length; l++) { for (int o = 0; o < chitietxuathuy.Length; o++) { int namphieu = phieuxuathuy[l].NgayLap.Year; int thangphieu = phieuxuathuy[l].NgayLap.Month; if (phieuxuathuy[l].MaPhieuXuatHuy == chitietxuathuy[o].MaPhieuXuatHuy && nam == namphieu && thang == thangphieu && phieuxuathuy[l].TrangThai == true && phieuxuathuy[l].MaKho == khohang[i].MaKho) { if (chitietxuathuy[o].MaHangHoa == hanghoa[k].MaHangHoa) { tongxuat += chitietxuathuy[o].SoLuong; xuatkhac += chitietxuathuy[o].SoLuong; } } } } // xuất hàng - hóa đơn bán hàng for (int l = 0; l < hdbanhang.Length; l++) { for (int o = 0; o < chitiethdbanhang.Length; o++) { int namphieu = hdbanhang[l].NgayBan.Year; int thangphieu = hdbanhang[l].NgayBan.Month; if (chitiethdbanhang[o].MaHDBanHang == hdbanhang[l].MaHDBanHang && nam == namphieu && thang == thangphieu &&hdbanhang[l].MaKho== khohang[i].MaKho) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(chitiethdbanhang[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(chitiethdbanhang[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hanghoa[k].MaHangHoa) { tongxuat += (chitietgoihang[for7].SoLuong * chitiethdbanhang[o].SoLuong); xuatban += (chitietgoihang[for7].SoLuong * chitiethdbanhang[o].SoLuong); } } } } } else { //là hàng hóa if (chitiethdbanhang[o].MaHangHoa == hanghoa[k].MaHangHoa) { tongxuat += chitiethdbanhang[o].SoLuong; xuatban += chitiethdbanhang[o].SoLuong; } } //End kiểm tra } } } // xuất hàng - trả lại nhà cung cấp for (int l = 0; l < tralaincc.Length; l++) { for (int o = 0; o < chitiettralaincc.Length; o++) { int namphieu = tralaincc[l].Ngaytra.Year; int thangphieu = tralaincc[l].Ngaytra.Month; if (chitiettralaincc[o].MaHDTraLaiNCC == tralaincc[l].MaHDTraLaiNCC && nam == namphieu && thang == thangphieu && tralaincc[l].MaKho == khohang[i].MaKho) { if (chitiettralaincc[o].MaHangHoa == hanghoa[k].MaHangHoa) { tongxuat += chitiettralaincc[o].SoLuong; xuattralai += chitiettralaincc[o].SoLuong; } } } } // xuất hàng - phiếu điều chuyển kho nội bộ for (int l = 0; l < phieudieuchuyenkhonoibo.Length; l++) { if (phieudieuchuyenkhonoibo[l].TuKho == khohang[i].MaKho) { 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 && phieudieuchuyenkhonoibo[l].TuKho == khohang[i].MaKho) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(chitietphieudieuchuyenkho[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(chitietphieudieuchuyenkho[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hanghoa[k].MaHangHoa) { tongxuat += (chitietgoihang[for7].SoLuong * chitietphieudieuchuyenkho[o].SoLuong); ; xuatban += (chitietgoihang[for7].SoLuong * chitietphieudieuchuyenkho[o].SoLuong); ; } } } } } else { //là hàng hóa if (chitietphieudieuchuyenkho[o].MaHangHoa == hanghoa[k].MaHangHoa) { tongxuat += chitietphieudieuchuyenkho[o].SoLuong; xuatkhac += chitietphieudieuchuyenkho[o].SoLuong; } } //End kiểm tra } } } } // 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 && hoadonnhap[l].MaKho == khohang[i].MaKho) { if (chitiethoadonnhap[o].MaHangHoa == hanghoa[k].MaHangHoa) { tongnhap += chitiethoadonnhap[o].SoLuong; nhapmua += 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 && khachhangtralai[l].MaKho == khohang[i].MaKho) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(chitietkhachhangtralai[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(chitietkhachhangtralai[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hanghoa[k].MaHangHoa) { tongnhap += (chitietgoihang[for7].SoLuong * chitietkhachhangtralai[o].SoLuong); nhaptralai += (chitietgoihang[for7].SoLuong * chitietkhachhangtralai[o].SoLuong); } } } } } else { //là hàng hóa if (chitietkhachhangtralai[o].MaHangHoa == hanghoa[k].MaHangHoa) { tongnhap += chitietkhachhangtralai[o].SoLuong; nhaptralai += chitietkhachhangtralai[o].SoLuong; } } //End kiểm tra } } } // nhập hàng - phiếu điều chuyển kho nội bộ for (int l = 0; l < phieudieuchuyenkhonoibo.Length; l++) { if (phieudieuchuyenkhonoibo[l].DenKho == khohang[i].MaKho) { 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 && phieudieuchuyenkhonoibo[l].DenKho == khohang[i].MaKho) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(chitietphieudieuchuyenkho[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(chitietphieudieuchuyenkho[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hanghoa[k].MaHangHoa) { tongnhap += (chitietgoihang[for7].SoLuong * chitietphieudieuchuyenkho[o].SoLuong); nhapkhac += (chitietgoihang[for7].SoLuong * chitietphieudieuchuyenkho[o].SoLuong); } } } } } else { //là hàng hóa if (chitietphieudieuchuyenkho[o].MaHangHoa == hanghoa[k].MaHangHoa) { tongnhap += chitietphieudieuchuyenkho[o].SoLuong; nhapkhac += chitietphieudieuchuyenkho[o].SoLuong; } } //End kiểm tra } } } } sdckhh = sddkhh + nhapkhac + nhapmua + nhaptralai - xuatkhac - xuatban - xuattralai; hienthibaocao[sotang] = new Entities.BCXuatNhapTonTheoKhoChiTiet(khohang[i].MaKho, khohang[i].TenKho, hanghoa[k].MaHangHoa, hanghoa[k].TenHangHoa, sddkhh, nhapmua, nhaptralai, nhapkhac, xuatban, xuattralai, xuatkhac, sdckhh); sotang++; } } } } sdck = sddk + tongnhap - tongxuat; hienthi[i] = new Entities.BCXuatNhapTonTheoKho("", khohang[i].MaKho, khohang[i].TenKho, sddk.ToString(), tongnhap.ToString(), tongxuat.ToString(), sdck.ToString()); } Entities.BCXuatNhapTonTheoKho[] temp = new Entities.BCXuatNhapTonTheoKho[hienthi.Length]; int soluong = 0; for (int i = 0; i < hienthi.Length; i++) { if (hienthi[i].TongNhap != "0" || hienthi[i].TongXuat != "0") { temp[soluong] = hienthi[i]; soluong++; } } hienthi = new Entities.BCXuatNhapTonTheoKho[soluong]; for (int i = 0; i < soluong; i++) { hienthi[i] = temp[i]; } ///////////////////////////////MRK FIX List<Entities.BCXuatNhapTonTheoKho> tem0 = new List<Entities.BCXuatNhapTonTheoKho>(); double tong0 = 0; double tong1 = 0; double tong2 = 0; double tong3 = 0; foreach (Entities.BCXuatNhapTonTheoKho item in hienthi) { tong0 += double.Parse(item.SoDuDauKy); tong1 += double.Parse(item.TongNhap); tong2 += double.Parse(item.TongXuat); tong3 += double.Parse(item.SoDuCuoiKy); tem0.Add(item); } Entities.BCXuatNhapTonTheoKho tem1 = new Entities.BCXuatNhapTonTheoKho(); tem1.TenKho = "Tổng: "; tem1.SoDuDauKy = tong0.ToString(); tem1.TongNhap = tong1.ToString(); tem1.TongXuat = tong2.ToString(); tem1.SoDuCuoiKy = tong3.ToString(); tem0.Add(tem1); ////////////////////////////////////// //dtgvhienthi.DataSource = hienthi; dtgvhienthi.DataSource = tem0.ToArray(); } catch { } finally { fix(); } }
private void rdbtimkiem3_CheckedChanged(object sender, EventArgs e) { try { if (hienthi == null) { dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoKho[0]; return; } ///////////////////////////////MRK FIX List<Entities.BCXuatNhapTonTheoKho> tem0 = new List<Entities.BCXuatNhapTonTheoKho>(); double tong0 = 0; double tong1 = 0; double tong2 = 0; double tong3 = 0; foreach (Entities.BCXuatNhapTonTheoKho item in hienthi) { if (item == null) { continue; } tong0 += double.Parse(item.SoDuDauKy); tong1 += double.Parse(item.TongNhap); tong2 += double.Parse(item.TongXuat); tong3 += double.Parse(item.SoDuCuoiKy); tem0.Add(item); } Entities.BCXuatNhapTonTheoKho tem1 = new Entities.BCXuatNhapTonTheoKho(); tem1.TenKho = "Tổng: "; tem1.SoDuDauKy = tong0.ToString(); tem1.TongNhap = tong1.ToString(); tem1.TongXuat = tong2.ToString(); tem1.SoDuCuoiKy = tong3.ToString(); tem0.Add(tem1); ////////////////////////////////////// //dtgvhienthi.DataSource = hienthi; dtgvhienthi.DataSource = tem0.ToArray(); } catch { } finally { fix(); } }
public void TongTienNhanVien() { try { nam = int.Parse(cbbnam.Text); thang = int.Parse(cbbthang.Text); double sddk, sddkhh, sdckhh, sdck, tongxuat, tongnhap; double nhapmua, nhaptralai, nhapkhac; double xuatban, xuattralai, xuatkhac; nhapmua = nhaptralai = nhapkhac = xuatban = xuattralai = xuatkhac = 0; sdckhh = sddkhh = sdck = sddk = 0; hienthi = new Entities.BCXuatNhapTonTheoKho[khohang.Length]; List<Entities.BCXuatNhapTonTheoKhoChiTiet> list = new List<Entities.BCXuatNhapTonTheoKhoChiTiet>(); for (int i = 0; i < khohang.Length; i++) { tongxuat = tongnhap = sddk = 0; // lay chi tiet kho hang theo kho var queryctkho = from ct in chitietkhohang where ct.Makho.Equals(khohang[i].MaKho) select ct; Entities.ChiTietKhoHangTheoHoaHonNhap[] ctkhohangArr = queryctkho.ToArray(); // lay hang hoa thoe ctkho var queryhanghoa = from s1 in ctkhohangArr join s2 in hanghoa on s1.Mahanghoa equals s2.MaHangHoa select s2; Entities.HangHoa[] hangHoaArr = queryhanghoa.ToArray(); for (int k = 0; k < hangHoaArr.Length; k++) { sdckhh = sddkhh = sdck = 0; // số dư đầu kỳ for (int l = 0; l < sodukho.Length; l++) { if (sodukho[l].MaHangHoa == hangHoaArr[k].MaHangHoa) { int namphieu = sodukho[l].NgayKetChuyen.Year; int thangphieu = sodukho[l].NgayKetChuyen.Month; if (nam == namphieu && thang == thangphieu) { sddk += sodukho[l].SoDuDauKy; sddkhh = sodukho[l].SoDuDauKy; break; } } } // lay cac phieu xuat huy trong thang nhapmua = nhaptralai = nhapkhac = xuatban = xuattralai = xuatkhac = 0; var querypxh = from pxh in phieuxuathuy where nam.Equals(pxh.NgayLap.Year) && thang.Equals(pxh.NgayLap.Month) && pxh.TrangThai.Equals(true) && pxh.MaKho.Equals(khohang[i].MaKho) select pxh; Entities.PhieuXuatHuy[] phieuxuathuyArr = querypxh.ToArray(); // lay chitietphieuxuathuy var queryctpxh = from s1 in phieuxuathuyArr join s2 in chitietxuathuy on s1.MaPhieuXuatHuy equals s2.MaPhieuXuatHuy select s2; Entities.ChiTietXuatHuy[] chitietxuathuyArr = queryctpxh.ToArray(); for (int o = 0; o < chitietxuathuyArr.Length; o++) { if (chitietxuathuyArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongxuat += chitietxuathuy[o].SoLuong; xuatkhac += chitietxuathuy[o].SoLuong; } } // xuất hàng - hóa đơn bán hàng var querybanhang = from bh in hdbanhang where bh.NgayBan.Month.Equals(thang) && bh.NgayBan.Year.Equals(nam) && bh.MaKho.Equals(khohang[i].MaKho) select bh; Entities.HDBanHang[] hdbanhangArr = querybanhang.ToArray(); // lay ct hoa don ban hang var queryctbanhang = from s1 in hdbanhangArr join s2 in chitiethdbanhang on s1.MaHDBanHang equals s2.MaHDBanHang select s2; Entities.ChiTietHDBanHang[] chitiethdbanhangArr = queryctbanhang.ToArray(); for (int o = 0; o < chitiethdbanhangArr.Length; o++) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(chitiethdbanhangArr[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(chitiethdbanhangArr[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongxuat += (chitietgoihang[for7].SoLuong * chitiethdbanhangArr[o].SoLuong); xuatban += (chitietgoihang[for7].SoLuong * chitiethdbanhangArr[o].SoLuong); } } } } } else { //là hàng hóa if (chitiethdbanhangArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongxuat += chitiethdbanhangArr[o].SoLuong; xuatban += chitiethdbanhangArr[o].SoLuong; } } //End kiểm tra } // xuất hàng - trả lại nhà cung cấp for (int l = 0; l < tralaincc.Length; l++) { for (int o = 0; o < chitiettralaincc.Length; o++) { int namphieu = tralaincc[l].Ngaytra.Year; int thangphieu = tralaincc[l].Ngaytra.Month; if (chitiettralaincc[o].MaHDTraLaiNCC == tralaincc[l].MaHDTraLaiNCC && nam == namphieu && thang == thangphieu && tralaincc[l].MaKho == khohang[i].MaKho) { if (chitiettralaincc[o].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongxuat += chitiettralaincc[o].SoLuong; xuattralai += chitiettralaincc[o].SoLuong; } } } } // xuất hàng - phiếu điều chuyển kho nội bộ var querydieuchuyen = from dc in phieudieuchuyenkhonoibo where dc.NgayDieuChuyen.Month.Equals(thang) && dc.NgayDieuChuyen.Year.Equals(nam) && dc.TuKho.Equals(khohang[i].MaKho) select dc; Entities.PhieuDieuChuyenKhoNoiBo[] phieudieuchuyenArr = querydieuchuyen.ToArray(); // lay chi tiet phieu dieu chuyen kho var queryctdieuchuyen = from s1 in phieudieuchuyenArr join s2 in chitietphieudieuchuyenkho on s1.MaPhieuDieuChuyenKho equals s2.MaPhieuDieuChuyenKho select s2; Entities.ChiTietPhieuDieuChuyenKho[] ctphieudieuchuyenArr = queryctdieuchuyen.ToArray(); for (int o = 0; o < ctphieudieuchuyenArr.Length; o++) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(ctphieudieuchuyenArr[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(ctphieudieuchuyenArr[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongxuat += (chitietgoihang[for7].SoLuong * ctphieudieuchuyenArr[o].SoLuong); ; xuatban += (chitietgoihang[for7].SoLuong * ctphieudieuchuyenArr[o].SoLuong); ; } } } } } else { //là hàng hóa if (ctphieudieuchuyenArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongxuat += ctphieudieuchuyenArr[o].SoLuong; xuatkhac += ctphieudieuchuyenArr[o].SoLuong; } } //End kiểm tra } // nhập hàng - hóa đơn nhập var queryhoadonnhap = from nh in hoadonnhap where nh.NgayNhap.Month.Equals(thang) && nh.NgayNhap.Year.Equals(nam) && nh.MaKho.Equals(khohang[i].MaKho) select nh; Entities.HoaDonNhap[] hoadonnhapArr = queryhoadonnhap.ToArray(); // lay chitiet hoa don nhap var querycthoadonnhap = from s1 in hoadonnhap join s2 in chitiethoadonnhap on s1.MaHoaDonNhap equals s2.MaHoaDonNhap select s2; Entities.ChiTietHoaDonNhap[] cthoadonnhapArr = querycthoadonnhap.ToArray(); for (int o = 0; o < cthoadonnhapArr.Length; o++) { if (cthoadonnhapArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongnhap += cthoadonnhapArr[o].SoLuong; nhapmua += cthoadonnhapArr[o].SoLuong; } } // nhập hàng - khách hàng trả lại var querykhachhangtralai = from tl in khachhangtralai where tl.NgayNhap.Month.Equals(thang) && tl.NgayNhap.Year.Equals(nam) && tl.MaKho.Equals(khohang[i].MaKho) select tl; Entities.KhachHangTraLai[] khachhangtralaiArr = querykhachhangtralai.ToArray(); // lay chi tiet khach hang tra lai var queryctkhtralai = from s1 in khachhangtralaiArr join s2 in chitietkhachhangtralai on s1.MaKhachHangTraLai equals s2.MaKhachHangTraLai select s2; Entities.ChiTietKhachHangTraLai[] ctkhtralaiArr = queryctkhtralai.ToArray(); for (int o = 0; o < ctkhtralaiArr.Length; o++) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(ctkhtralaiArr[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(ctkhtralaiArr[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongnhap += (chitietgoihang[for7].SoLuong * ctkhtralaiArr[o].SoLuong); nhaptralai += (chitietgoihang[for7].SoLuong * ctkhtralaiArr[o].SoLuong); } } } } } else { //là hàng hóa if (ctkhtralaiArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongnhap += ctkhtralaiArr[o].SoLuong; nhaptralai += ctkhtralaiArr[o].SoLuong; } } //End kiểm tra } //} // nhập hàng - phiếu điều chuyển kho nội bộ var querydieuchuyend = from dc in phieudieuchuyenkhonoibo where dc.NgayDieuChuyen.Month.Equals(thang) && dc.NgayDieuChuyen.Year.Equals(nam) && dc.DenKho.Equals(khohang[i].MaKho) select dc; Entities.PhieuDieuChuyenKhoNoiBo[] phieudieuchuyendArr = querydieuchuyen.ToArray(); // lay chi tiet phieu dieu chuyen kho var queryctdieuchuyend = from s1 in phieudieuchuyenArr join s2 in chitietphieudieuchuyenkho on s1.MaPhieuDieuChuyenKho equals s2.MaPhieuDieuChuyenKho select s2; Entities.ChiTietPhieuDieuChuyenKho[] ctphieudieuchuyendArr = queryctdieuchuyen.ToArray(); for (int o = 0; o < ctphieudieuchuyendArr.Length; o++) { //kiểm tra nó là hàng hóa hay mã hàng if (this.GoiHangOrHangHoa(ctphieudieuchuyendArr[o].MaHangHoa)) { //là gói hàng for (int for6 = 0; for6 < goihang.Length; for6++) { for (int for7 = 0; for7 < chitietgoihang.Length; for7++) { if (goihang[for6].MaGoiHang.Equals(chitietgoihang[for7].MaGoiHang) && chitietgoihang[for7].MaGoiHang.Equals(ctphieudieuchuyendArr[o].MaHangHoa)) { //------- if (chitietgoihang[for7].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongnhap += (chitietgoihang[for7].SoLuong * ctphieudieuchuyendArr[o].SoLuong); nhapkhac += (chitietgoihang[for7].SoLuong * ctphieudieuchuyendArr[o].SoLuong); } } } } } else { //là hàng hóa if (ctphieudieuchuyendArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa) { tongnhap += ctphieudieuchuyendArr[o].SoLuong; nhapkhac += ctphieudieuchuyendArr[o].SoLuong; } } //End kiểm tra } sdckhh = sddkhh + nhapkhac + nhapmua + nhaptralai - xuatkhac - xuatban - xuattralai; Entities.BCXuatNhapTonTheoKhoChiTiet item = new Entities.BCXuatNhapTonTheoKhoChiTiet(khohang[i].MaKho, khohang[i].TenKho, hangHoaArr[k].MaHangHoa, hangHoaArr[k].TenHangHoa, sddkhh, nhapmua, nhaptralai, nhapkhac, xuatban, xuattralai, xuatkhac, sdckhh); list.Add(item); } hienthibaocao = list.ToArray(); sdck = sddk + tongnhap - tongxuat; hienthi[i] = new Entities.BCXuatNhapTonTheoKho("", khohang[i].MaKho, khohang[i].TenKho, sddk.ToString(), tongnhap.ToString(), tongxuat.ToString(), sdck.ToString()); } Entities.BCXuatNhapTonTheoKho[] temp = new Entities.BCXuatNhapTonTheoKho[hienthi.Length]; int soluong = 0; for (int i = 0; i < hienthi.Length; i++) { if (hienthi[i].TongNhap != "0" || hienthi[i].TongXuat != "0") { temp[soluong] = hienthi[i]; soluong++; } } hienthi = new Entities.BCXuatNhapTonTheoKho[soluong]; for (int i = 0; i < soluong; i++) { hienthi[i] = temp[i]; } ///////////////////////////////MRK FIX List<Entities.BCXuatNhapTonTheoKho> tem0 = new List<Entities.BCXuatNhapTonTheoKho>(); double tong0 = 0; double tong1 = 0; double tong2 = 0; double tong3 = 0; foreach (Entities.BCXuatNhapTonTheoKho item in hienthi) { tong0 += double.Parse(item.SoDuDauKy); tong1 += double.Parse(item.TongNhap); tong2 += double.Parse(item.TongXuat); tong3 += double.Parse(item.SoDuCuoiKy); tem0.Add(item); } Entities.BCXuatNhapTonTheoKho tem1 = new Entities.BCXuatNhapTonTheoKho(); tem1.TenKho = "Tổng: "; tem1.SoDuDauKy = tong0.ToString(); tem1.TongNhap = tong1.ToString(); tem1.TongXuat = tong2.ToString(); tem1.SoDuCuoiKy = tong3.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(); } }