コード例 #1
0
 private void rdbtimkiem3_CheckedChanged(object sender, EventArgs e)
 {
     try
     {
         if (hienthi == null)
         {
             dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
             return;
         }
         ///////////////////////////////MRK FIX
         List <Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List <Entities.BCXuatNhapTonTheoLoaiHang>();
         double tong0 = 0;
         double tong1 = 0;
         double tong2 = 0;
         double tong3 = 0;
         foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
         tem1.TenLoaiHang = "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();
     }
 }
コード例 #2
0
        private void rdbtimkiem3_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (hienthi == null)
                {
                    dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
                    return;
                }
                ///////////////////////////////MRK FIX
                List<Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List<Entities.BCXuatNhapTonTheoLoaiHang>();
                double tong0 = 0;
                double tong1 = 0;
                double tong2 = 0;
                double tong3 = 0;
                foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
                tem1.TenLoaiHang = "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();

            }
        }
コード例 #3
0
        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.BCXuatNhapTonTheoLoaiHang[loaihanghoa.Length];
                List<Entities.BCXuatNhapTonTheoLoaiHangChiTiet> list = new List<Entities.BCXuatNhapTonTheoLoaiHangChiTiet>();

                // For Loai Hang
                for (int i = 0; i < loaihanghoa.Length; i++)
                {
                    sdck = sddk = tongxuat = tongnhap = 0;
                    // Lay tat ca nhom hang thuoc loai hang tren
                    var query = from nh in nhomhang
                                where nh.MaLoaiHang.Equals(loaihanghoa[i].MaLoaiHang)
                                select nh;

                    Entities.NhomHang[] nhomHangArr = query.ToArray();

                    // lay hang hoa trong nhom hang
                    var queryhh = from s1 in nhomHangArr
                                  join s2 in hanghoa
                                  on s1.MaNhomHang equals s2.MaNhomHangHoa
                                  select s2;

                    Entities.HangHoa[] hangHoaArr = queryhh.ToArray();

                    for (int k = 0; k < hangHoaArr.Length; k++)
                    {
                        sdckhh = sddkhh = 0;
                        // số dư đầu kỳ
                        for (int l = 0; l < sodukho.Length; l++)
                        {
                            if (sodukho[l].MaHangHoa == hangHoaArr[k].MaHangHoa)
                            {
                                sddkhh = sodukho[l].SoDuDauKy;
                                sddk += sodukho[l].SoDuDauKy;
                                break;
                            }
                        }
                        // xuất hàng - phiếu xuất hủy
                        nhapmua = nhaptralai = nhapkhac = xuatban = xuattralai = xuatkhac = 0;
                        // lay cac phieu xuat huy trong thang
                        var querypxh = from pxh in phieuxuathuy
                                       where nam.Equals(pxh.NgayLap.Year) && thang.Equals(pxh.NgayLap.Month) && pxh.TrangThai.Equals(true)
                                       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 += chitietxuathuyArr[o].SoLuong;
                                xuatkhac += chitietxuathuyArr[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)
                                           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();

                        foreach (Entities.ChiTietHDBanHang item3 in chitiethdbanhangArr)
                        {
                            if (hangHoaArr[k].MaHangHoa.Equals(item3.MaHangHoa))
                            {
                                tongxuat += item3.SoLuong;
                                xuatban += item3.SoLuong;
                            }
                            else
                            {
                                foreach (Entities.ChiTietGoiHang item5 in chitietgoihang)
                                {
                                    if (item5.MaGoiHang.Equals(item3.MaHangHoa))
                                    {
                                        if (hangHoaArr[k].MaHangHoa.Equals(item5.MaHangHoa))
                                        {
                                            tongxuat += (item5.SoLuong * item3.SoLuong);
                                            xuatban += (item5.SoLuong * item3.SoLuong);
                                        }
                                    }

                                }
                            }
                        }
                        // xuất hàng - trả lại nhà cung cấp
                        var querytralaincc = from tl in tralaincc
                                             where tl.Ngaytra.Month.Equals(thang) && tl.Ngaytra.Year.Equals(nam)
                                             select tl;

                        Entities.TraLaiNCC[] tralainccArr = querytralaincc.ToArray();
                        // lay chitiet tra lai ncc
                        var querycttralaincc = from s1 in tralainccArr
                                               join s2 in chitiettralaincc
                                               on s1.MaHDTraLaiNCC equals s2.MaHDTraLaiNCC
                                               select s2;

                        Entities.ChiTietTraLaiNhaCungCap[] cttralainccArr = querycttralaincc.ToArray();

                        for (int o = 0; o < cttralainccArr.Length; o++)
                        {
                            if (cttralainccArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa)
                            {
                                tongxuat += cttralainccArr[o].SoLuong;
                                xuattralai += cttralainccArr[o].SoLuong;
                            }
                        }
                        // 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)
                                              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)
                                                   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();

                        foreach (Entities.ChiTietKhachHangTraLai item3 in ctkhtralaiArr)
                        {
                            if (hangHoaArr[k].MaHangHoa.Equals(item3.MaHangHoa))
                            {
                                tongnhap += item3.SoLuong;
                                nhaptralai += item3.SoLuong;
                            }
                            else
                            {
                                foreach (Entities.ChiTietGoiHang item5 in chitietgoihang)
                                {
                                    if (item5.MaGoiHang.Equals(item3.MaHangHoa))
                                    {
                                        if (hangHoaArr[k].MaHangHoa.Equals(item5.MaHangHoa))
                                        {
                                            tongnhap += (item5.SoLuong * item3.SoLuong);
                                            nhaptralai += (item5.SoLuong * item3.SoLuong);
                                        }
                                    }
                                }
                            }
                        }

                        sdckhh = sddkhh + nhapkhac + nhapmua + nhaptralai - xuatkhac - xuatban - xuattralai;
                        Entities.BCXuatNhapTonTheoLoaiHangChiTiet item = new Entities.BCXuatNhapTonTheoLoaiHangChiTiet(loaihanghoa[i].MaLoaiHang, loaihanghoa[i].TenLoaiHang, hangHoaArr[k].MaHangHoa, hangHoaArr[k].TenHangHoa, sddkhh, nhapmua, nhaptralai, nhapkhac, xuatban, xuattralai, xuatkhac, sdckhh);
                        list.Add(item);
                    }

                    sdck = sddk + tongnhap - tongxuat;
                    hienthi[i] = new Entities.BCXuatNhapTonTheoLoaiHang("", loaihanghoa[i].MaLoaiHang, loaihanghoa[i].TenLoaiHang, sddk.ToString(), tongnhap.ToString(), tongxuat.ToString(), sdck.ToString());
                }

                hienthibaocao = list.ToArray();

                Entities.BCXuatNhapTonTheoLoaiHang[] temp = new Entities.BCXuatNhapTonTheoLoaiHang[hienthi.Length];
                int soluong = 0;
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (Convert.ToDouble(hienthi[i].TongNhap) != 0 || Convert.ToDouble(hienthi[i].TongXuat) != 0)
                    {
                        temp[soluong] = hienthi[i];
                        soluong++;
                    }
                }
                hienthi = new Entities.BCXuatNhapTonTheoLoaiHang[soluong];
                for (int i = 0; i < soluong; i++)
                {
                    hienthi[i] = temp[i];
                }
                ///////////////////////////////MRK FIX
                List<Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List<Entities.BCXuatNhapTonTheoLoaiHang>();
                double tong0 = 0;
                double tong1 = 0;
                double tong2 = 0;
                double tong3 = 0;
                foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
                tem1.TenLoaiHang = "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();
            }
        }
コード例 #4
0
        private void txttimkiem_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (rdbtimkiem3.Checked == true)
                {
                    return;
                }
                if (txttimkiem.Text.Length == 0)
                {
                    dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
                    return;
                }
                int soluong = 0;
                if (hienthi != null)
                {
                    if (rdbtimkiem1.Checked == true)
                    {
                        for (int i = 0; i < hienthi.Length; i++)
                        {
                            int kiemtra = hienthi[i].MaLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                soluong++;
                            }
                        }
                        if (soluong == 0)
                        {
                            dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
                            return;
                        }
                        Entities.BCXuatNhapTonTheoLoaiHang[] hienthitheoid = new Entities.BCXuatNhapTonTheoLoaiHang[soluong];
                        soluong = 0;
                        for (int i = 0; i < hienthi.Length; i++)
                        {
                            int kiemtra = hienthi[i].MaLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                hienthitheoid[soluong] = hienthi[i];
                                soluong++;
                            }
                        }
                        ///////////////////////////////MRK FIX
                        List<Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List<Entities.BCXuatNhapTonTheoLoaiHang>();
                        double tong0 = 0;
                        double tong1 = 0;
                        double tong2 = 0;
                        double tong3 = 0;
                        foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
                        tem1.TenLoaiHang = "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].TenLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                soluong++;
                            }
                        }
                        if (soluong == 0)
                        {
                            dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
                            return;
                        }
                        Entities.BCXuatNhapTonTheoLoaiHang[] hienthitheoma = new Entities.BCXuatNhapTonTheoLoaiHang[soluong];
                        soluong = 0;
                        for (int i = 0; i < hienthi.Length; i++)
                        {
                            int kiemtra = hienthi[i].TenLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                hienthitheoma[soluong] = hienthi[i];
                                soluong++;
                            }
                        }
                        ///////////////////////////////MRK FIX
                        List<Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List<Entities.BCXuatNhapTonTheoLoaiHang>();
                        double tong0 = 0;
                        double tong1 = 0;
                        double tong2 = 0;
                        double tong3 = 0;
                        foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
                        tem1.TenLoaiHang = "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();

                    }
                    if (dtgvhienthi.RowCount > 0)
                    {
                        tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                    }
                    else
                    {
                        tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                    }
                }
            }
            finally
            {
                fix();
            }
        }
コード例 #5
0
 private void txttimkiem_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (rdbtimkiem3.Checked == true)
         {
             return;
         }
         if (txttimkiem.Text.Length == 0)
         {
             dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
             return;
         }
         int soluong = 0;
         if (hienthi != null)
         {
             if (rdbtimkiem1.Checked == true)
             {
                 for (int i = 0; i < hienthi.Length; i++)
                 {
                     int kiemtra = hienthi[i].MaLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         soluong++;
                     }
                 }
                 if (soluong == 0)
                 {
                     dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
                     return;
                 }
                 Entities.BCXuatNhapTonTheoLoaiHang[] hienthitheoid = new Entities.BCXuatNhapTonTheoLoaiHang[soluong];
                 soluong = 0;
                 for (int i = 0; i < hienthi.Length; i++)
                 {
                     int kiemtra = hienthi[i].MaLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         hienthitheoid[soluong] = hienthi[i];
                         soluong++;
                     }
                 }
                 ///////////////////////////////MRK FIX
                 List <Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List <Entities.BCXuatNhapTonTheoLoaiHang>();
                 double tong0 = 0;
                 double tong1 = 0;
                 double tong2 = 0;
                 double tong3 = 0;
                 foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
                 tem1.TenLoaiHang = "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].TenLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         soluong++;
                     }
                 }
                 if (soluong == 0)
                 {
                     dtgvhienthi.DataSource = new Entities.BCXuatNhapTonTheoLoaiHang[0];
                     return;
                 }
                 Entities.BCXuatNhapTonTheoLoaiHang[] hienthitheoma = new Entities.BCXuatNhapTonTheoLoaiHang[soluong];
                 soluong = 0;
                 for (int i = 0; i < hienthi.Length; i++)
                 {
                     int kiemtra = hienthi[i].TenLoaiHang.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         hienthitheoma[soluong] = hienthi[i];
                         soluong++;
                     }
                 }
                 ///////////////////////////////MRK FIX
                 List <Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List <Entities.BCXuatNhapTonTheoLoaiHang>();
                 double tong0 = 0;
                 double tong1 = 0;
                 double tong2 = 0;
                 double tong3 = 0;
                 foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
                 tem1.TenLoaiHang = "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();
             }
             if (dtgvhienthi.RowCount > 0)
             {
                 tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
             }
             else
             {
                 tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
             }
         }
     }
     finally
     {
         fix();
     }
 }
コード例 #6
0
        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.BCXuatNhapTonTheoLoaiHang[loaihanghoa.Length];
                List <Entities.BCXuatNhapTonTheoLoaiHangChiTiet> list = new List <Entities.BCXuatNhapTonTheoLoaiHangChiTiet>();

                // For Loai Hang
                for (int i = 0; i < loaihanghoa.Length; i++)
                {
                    sdck = sddk = tongxuat = tongnhap = 0;
                    // Lay tat ca nhom hang thuoc loai hang tren
                    var query = from nh in nhomhang
                                where nh.MaLoaiHang.Equals(loaihanghoa[i].MaLoaiHang)
                                select nh;

                    Entities.NhomHang[] nhomHangArr = query.ToArray();

                    // lay hang hoa trong nhom hang
                    var queryhh = from s1 in nhomHangArr
                                  join s2 in hanghoa
                                  on s1.MaNhomHang equals s2.MaNhomHangHoa
                                  select s2;

                    Entities.HangHoa[] hangHoaArr = queryhh.ToArray();

                    for (int k = 0; k < hangHoaArr.Length; k++)
                    {
                        sdckhh = sddkhh = 0;
                        // số dư đầu kỳ
                        for (int l = 0; l < sodukho.Length; l++)
                        {
                            if (sodukho[l].MaHangHoa == hangHoaArr[k].MaHangHoa)
                            {
                                sddkhh = sodukho[l].SoDuDauKy;
                                sddk  += sodukho[l].SoDuDauKy;
                                break;
                            }
                        }
                        // xuất hàng - phiếu xuất hủy
                        nhapmua = nhaptralai = nhapkhac = xuatban = xuattralai = xuatkhac = 0;
                        // lay cac phieu xuat huy trong thang
                        var querypxh = from pxh in phieuxuathuy
                                       where nam.Equals(pxh.NgayLap.Year) && thang.Equals(pxh.NgayLap.Month) && pxh.TrangThai.Equals(true)
                                       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 += chitietxuathuyArr[o].SoLuong;
                                xuatkhac += chitietxuathuyArr[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)
                                           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();

                        foreach (Entities.ChiTietHDBanHang item3 in chitiethdbanhangArr)
                        {
                            if (hangHoaArr[k].MaHangHoa.Equals(item3.MaHangHoa))
                            {
                                tongxuat += item3.SoLuong;
                                xuatban  += item3.SoLuong;
                            }
                            else
                            {
                                foreach (Entities.ChiTietGoiHang item5 in chitietgoihang)
                                {
                                    if (item5.MaGoiHang.Equals(item3.MaHangHoa))
                                    {
                                        if (hangHoaArr[k].MaHangHoa.Equals(item5.MaHangHoa))
                                        {
                                            tongxuat += (item5.SoLuong * item3.SoLuong);
                                            xuatban  += (item5.SoLuong * item3.SoLuong);
                                        }
                                    }
                                }
                            }
                        }
                        // xuất hàng - trả lại nhà cung cấp
                        var querytralaincc = from tl in tralaincc
                                             where tl.Ngaytra.Month.Equals(thang) && tl.Ngaytra.Year.Equals(nam)
                                             select tl;

                        Entities.TraLaiNCC[] tralainccArr = querytralaincc.ToArray();
                        // lay chitiet tra lai ncc
                        var querycttralaincc = from s1 in tralainccArr
                                               join s2 in chitiettralaincc
                                               on s1.MaHDTraLaiNCC equals s2.MaHDTraLaiNCC
                                               select s2;

                        Entities.ChiTietTraLaiNhaCungCap[] cttralainccArr = querycttralaincc.ToArray();

                        for (int o = 0; o < cttralainccArr.Length; o++)
                        {
                            if (cttralainccArr[o].MaHangHoa == hangHoaArr[k].MaHangHoa)
                            {
                                tongxuat   += cttralainccArr[o].SoLuong;
                                xuattralai += cttralainccArr[o].SoLuong;
                            }
                        }
                        // 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)
                                              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)
                                                   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();

                        foreach (Entities.ChiTietKhachHangTraLai item3 in ctkhtralaiArr)
                        {
                            if (hangHoaArr[k].MaHangHoa.Equals(item3.MaHangHoa))
                            {
                                tongnhap   += item3.SoLuong;
                                nhaptralai += item3.SoLuong;
                            }
                            else
                            {
                                foreach (Entities.ChiTietGoiHang item5 in chitietgoihang)
                                {
                                    if (item5.MaGoiHang.Equals(item3.MaHangHoa))
                                    {
                                        if (hangHoaArr[k].MaHangHoa.Equals(item5.MaHangHoa))
                                        {
                                            tongnhap   += (item5.SoLuong * item3.SoLuong);
                                            nhaptralai += (item5.SoLuong * item3.SoLuong);
                                        }
                                    }
                                }
                            }
                        }

                        sdckhh = sddkhh + nhapkhac + nhapmua + nhaptralai - xuatkhac - xuatban - xuattralai;
                        Entities.BCXuatNhapTonTheoLoaiHangChiTiet item = new Entities.BCXuatNhapTonTheoLoaiHangChiTiet(loaihanghoa[i].MaLoaiHang, loaihanghoa[i].TenLoaiHang, hangHoaArr[k].MaHangHoa, hangHoaArr[k].TenHangHoa, sddkhh, nhapmua, nhaptralai, nhapkhac, xuatban, xuattralai, xuatkhac, sdckhh);
                        list.Add(item);
                    }

                    sdck       = sddk + tongnhap - tongxuat;
                    hienthi[i] = new Entities.BCXuatNhapTonTheoLoaiHang("", loaihanghoa[i].MaLoaiHang, loaihanghoa[i].TenLoaiHang, sddk.ToString(), tongnhap.ToString(), tongxuat.ToString(), sdck.ToString());
                }

                hienthibaocao = list.ToArray();

                Entities.BCXuatNhapTonTheoLoaiHang[] temp = new Entities.BCXuatNhapTonTheoLoaiHang[hienthi.Length];
                int soluong = 0;
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (Convert.ToDouble(hienthi[i].TongNhap) != 0 || Convert.ToDouble(hienthi[i].TongXuat) != 0)
                    {
                        temp[soluong] = hienthi[i];
                        soluong++;
                    }
                }
                hienthi = new Entities.BCXuatNhapTonTheoLoaiHang[soluong];
                for (int i = 0; i < soluong; i++)
                {
                    hienthi[i] = temp[i];
                }
                ///////////////////////////////MRK FIX
                List <Entities.BCXuatNhapTonTheoLoaiHang> tem0 = new List <Entities.BCXuatNhapTonTheoLoaiHang>();
                double tong0 = 0;
                double tong1 = 0;
                double tong2 = 0;
                double tong3 = 0;
                foreach (Entities.BCXuatNhapTonTheoLoaiHang 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.BCXuatNhapTonTheoLoaiHang tem1 = new Entities.BCXuatNhapTonTheoLoaiHang();
                tem1.TenLoaiHang = "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();
            }
        }