コード例 #1
0
        private static Dictionary <int, Dictionary <int, ViewBangThuTienRow> > buildLopToHocSinhToViewBangThuTienRowsMap(ViewBangThuTienDataTable viewBangThuTienTable, DateTime ngayTinh)
        {
            List <int> hocSinhIds = new List <int>();

            foreach (ViewBangThuTienRow viewBangThuTienRow in viewBangThuTienTable)
            {
                hocSinhIds.Add(viewBangThuTienRow.HocSinhId);
            }

            Dictionary <int, HocSinhLopRow> hocSinhIdsToHocSinhLops = StaticDataUtil.GetHocSinhLopsByHocSinhIds(hocSinhIds, ngayTinh);
            Dictionary <int, Dictionary <int, ViewBangThuTienRow> > lopToHocSinhViewBangThuTienRows = new Dictionary <int, Dictionary <int, ViewBangThuTienRow> >();

            foreach (ViewBangThuTienRow viewBangThuTienRow in viewBangThuTienTable)
            {
                if (!hocSinhIdsToHocSinhLops.ContainsKey(viewBangThuTienRow.HocSinhId))
                {
                    continue;
                }

                int lopId = hocSinhIdsToHocSinhLops[viewBangThuTienRow.HocSinhId].LopId;

                if (!lopToHocSinhViewBangThuTienRows.ContainsKey(lopId))
                {
                    lopToHocSinhViewBangThuTienRows.Add(lopId, new Dictionary <int, ViewBangThuTienRow>());
                }

                Dictionary <int, ViewBangThuTienRow> hocSinhToViewBangThuTienRows = lopToHocSinhViewBangThuTienRows[lopId];
                hocSinhToViewBangThuTienRows.Add(viewBangThuTienRow.HocSinhId, viewBangThuTienRow);
            }

            return(lopToHocSinhViewBangThuTienRows);
        }
コード例 #2
0
        public int GenerateSoThuTienByHocSinhRows(DateTime ngayTinh, List <HocSinhRow> hocSinhRows)
        {
            ViewBangThuTienTableAdapter viewBangThuTienTableAdapter = (ViewBangThuTienTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterViewBangThuTien);
            ViewBangThuTienDataTable    viewBangThuTienTable        = viewBangThuTienTableAdapter.GetViewBangThuTienByNgayTinhAndLop(ngayTinh, null);

            List <int>        hocSinhIds = new List <int>();
            List <HocSinhRow> needToGenerateHocSinhRows = new List <Dao.QLMamNonDs.HocSinhRow>();

            foreach (HocSinhRow hocSinh in hocSinhRows)
            {
                DataRow[] rows = viewBangThuTienTable.Select(String.Format("HocSinhId={0}", hocSinh.HocSinhId));

                if (ArrayUtil.IsEmpty(rows))
                {
                    hocSinhIds.Add(hocSinh.HocSinhId);
                    needToGenerateHocSinhRows.Add(hocSinh);
                }
            }

            Dictionary <int, HocSinhLopRow> hocSinhIdsToHocSinhLops = StaticDataUtil.GetHocSinhLopsByHocSinhIds(hocSinhIds, ngayTinh);
            Dictionary <int, Dictionary <int, ViewBangThuTienRow> > lopToHocSinhToViewBangThuTienRowsMap          = buildLopToHocSinhToViewBangThuTienRowsMap(viewBangThuTienTable, ngayTinh);
            Dictionary <int, Dictionary <int, ViewBangThuTienRow> > prevMonthLopToHocSinhToViewBangThuTienRowsMap = getAndSortPrevMonthViewBangThuTienRows(ngayTinh, viewBangThuTienTableAdapter, hocSinhIds, hocSinhIdsToHocSinhLops, lopToHocSinhToViewBangThuTienRowsMap);
            Dictionary <int, int> generatedLopToSTTs = buildGeneratedLopIdToSTTMap(lopToHocSinhToViewBangThuTienRowsMap);

            // Generate SoThuTien for HocSinhs that exist in previous month
            foreach (HocSinhRow hocSinh in needToGenerateHocSinhRows)
            {
                if (hocSinhIdsToHocSinhLops.ContainsKey(hocSinh.HocSinhId))
                {
                    int lopId = hocSinhIdsToHocSinhLops[hocSinh.HocSinhId].LopId;
                    ViewBangThuTienRow preMonthViewBangThuTien = null;

                    if (prevMonthLopToHocSinhToViewBangThuTienRowsMap.ContainsKey(lopId))
                    {
                        Dictionary <int, ViewBangThuTienRow> prevMonthhocSinhToViewBangThuTienRowsMap = prevMonthLopToHocSinhToViewBangThuTienRowsMap[lopId];

                        if (prevMonthhocSinhToViewBangThuTienRowsMap.ContainsKey(hocSinh.HocSinhId))
                        {
                            preMonthViewBangThuTien = prevMonthhocSinhToViewBangThuTienRowsMap[hocSinh.HocSinhId];
                        }
                    }

                    if (preMonthViewBangThuTien != null)
                    {
                        GenerateSoThuTienByHocSinhAndLopAndNgayTinh(hocSinh.HocSinhId, lopId, ngayTinh, preMonthViewBangThuTien.STT, preMonthViewBangThuTien);

                        if (!generatedLopToSTTs.ContainsKey(lopId))
                        {
                            generatedLopToSTTs.Add(lopId, 0);
                        }

                        int currentSTT = generatedLopToSTTs[lopId];

                        if (currentSTT < preMonthViewBangThuTien.STT)
                        {
                            generatedLopToSTTs[lopId] = preMonthViewBangThuTien.STT;
                        }
                    }
                }
            }

            // Generate SoThuTien for HocSinhs that NOT exist in previous month
            foreach (HocSinhRow hocSinh in needToGenerateHocSinhRows)
            {
                if (hocSinhIdsToHocSinhLops.ContainsKey(hocSinh.HocSinhId))
                {
                    int lopId = hocSinhIdsToHocSinhLops[hocSinh.HocSinhId].LopId;
                    ViewBangThuTienRow preMonthViewBangThuTien = null;

                    if (prevMonthLopToHocSinhToViewBangThuTienRowsMap.ContainsKey(lopId))
                    {
                        Dictionary <int, ViewBangThuTienRow> prevMonthhocSinhToViewBangThuTienRowsMap = prevMonthLopToHocSinhToViewBangThuTienRowsMap[lopId];

                        if (prevMonthhocSinhToViewBangThuTienRowsMap.ContainsKey(hocSinh.HocSinhId))
                        {
                            preMonthViewBangThuTien = prevMonthhocSinhToViewBangThuTienRowsMap[hocSinh.HocSinhId];
                        }
                    }

                    if (preMonthViewBangThuTien == null)
                    {
                        if (!generatedLopToSTTs.ContainsKey(lopId))
                        {
                            generatedLopToSTTs.Add(lopId, 0);
                        }

                        int stt = generatedLopToSTTs[lopId] + 1;
                        GenerateSoThuTienByHocSinhAndLopAndNgayTinh(hocSinh.HocSinhId, lopId, ngayTinh, stt, preMonthViewBangThuTien);
                        generatedLopToSTTs[lopId] = stt;
                    }
                }
            }

            return(hocSinhIds.Count);
        }