private Dictionary <int, QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow> evaluatePrevMonthViewBangThuTienTable(DateTime ngayTinh, int hocSinhId) { ViewBangThuTienTableAdapter viewBangThuTienTableAdapter = (ViewBangThuTienTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterViewBangThuTien); BangThuTienKhoanThuTableAdapter bangThuTienKhoanThuTableAdapter = (BangThuTienKhoanThuTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterBangThuTienKhoanThu); PhieuThuTableAdapter phieuThuTableAdapter = (PhieuThuTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterPhieuThu); Dictionary <int, QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow> prevMonthRowDictionary = null; QLMamNon.Dao.QLMamNonDs.ViewBangThuTienDataTable prevMonthBangThuTienTable = viewBangThuTienTableAdapter.GetDataByNgayTinhAndHocSinhId(ngayTinh, hocSinhId); List <int> prevMonthBangThuTienIds = new List <int>(prevMonthBangThuTienTable.Rows.Count); foreach (QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow row in prevMonthBangThuTienTable) { prevMonthBangThuTienIds.Add(row.BangThuTienId); } if (!ListUtil.IsEmpty(prevMonthBangThuTienIds)) { QLMamNon.Dao.QLMamNonDs.BangThuTienKhoanThuDataTable prevMonthBTTKTDataTable = bangThuTienKhoanThuTableAdapter.GetBangThuTienKhoanThuByBangThuTienIds(String.Join(",", prevMonthBangThuTienIds)); QLMamNon.Dao.QLMamNonDs.PhieuThuDataTable prevMonthPhieuThuDataTable = phieuThuTableAdapter.GetDataByHocSinhIdAndNgayTinh(-1, ngayTinh); prevMonthRowDictionary = new Dictionary <int, Dao.QLMamNonDs.ViewBangThuTienRow>(); foreach (QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow row in prevMonthBangThuTienTable) { BangThuTienUtil.EvaluateValuesForViewBangThuTienRow(row, null, prevMonthBTTKTDataTable, prevMonthPhieuThuDataTable, true, false, true); prevMonthRowDictionary.Add(row.HocSinhId, row); } } return(prevMonthRowDictionary); }
protected override void onExecute() { QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow currentViewBangThuTien = this.CommandParameter[ParameterCurrentViewBangThuTien] as QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow; ViewBangThuTienTableAdapter viewBangThuTienTableAdapter = this.CommandParameter[ParameterViewBangThuTienTableAdapter] as ViewBangThuTienTableAdapter; long soTienAdded = (long)this.CommandParameter[ParameterSoTienAdded]; viewBangThuTienTableAdapter.UpdateSoTienTruyThuByHocSinhAndNgayUpdated(currentViewBangThuTien.HocSinhId, currentViewBangThuTien.NgayTinh, soTienAdded); }
private void updateSoTienTruyThuForBangThuTienNextMonths(DateTime ngay, int hocSinhId) { ViewBangThuTienTableAdapter viewBangThuTienTableAdapter = (ViewBangThuTienTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterViewBangThuTien); BangThuTienKhoanThuTableAdapter bangThuTienKhoanThuTableAdapter = (BangThuTienKhoanThuTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterBangThuTienKhoanThu); PhieuThuTableAdapter phieuThuTableAdapter = (PhieuThuTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterPhieuThu); QLMNDaoJobInvoker qlmnDaoJobInvoker = new QLMNDaoJobInvoker(); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand = new UpdateSoTienTruyThuOfBangThuTienCommand(); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand.CommandParameter.Add(UpdateSoTienTruyThuOfBangThuTienCommand.ParameterViewBangThuTienTableAdapter, viewBangThuTienTableAdapter); QLMamNon.Dao.QLMamNonDs.ViewBangThuTienDataTable table = viewBangThuTienTableAdapter.GetDataByNgayTinhAndHocSinhId(ngay.AddMonths(1), hocSinhId); if (ListUtil.IsEmpty(table.Rows)) { return; } QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow viewBangThuTienRow = table[0]; QLMamNon.Dao.QLMamNonDs.BangThuTienKhoanThuDataTable bTTKTDataTable = bangThuTienKhoanThuTableAdapter.GetBangThuTienKhoanThuByBangThuTienIds(viewBangThuTienRow.BangThuTienId.ToString()); QLMamNon.Dao.QLMamNonDs.PhieuThuDataTable phieuThuDataTable = phieuThuTableAdapter.GetDataByHocSinhIdAndNgayTinh(-1, ngay); Dictionary <int, QLMamNon.Dao.QLMamNonDs.ViewBangThuTienRow> prevMonthRowDictionary = evaluatePrevMonthViewBangThuTienTable(ngay.AddMonths(-1), hocSinhId); BangThuTienUtil.EvaluateValuesForViewBangThuTienRow(viewBangThuTienRow, prevMonthRowDictionary != null && prevMonthRowDictionary.ContainsKey(viewBangThuTienRow.HocSinhId) ? prevMonthRowDictionary[viewBangThuTienRow.HocSinhId] : null, bTTKTDataTable, phieuThuDataTable, false, false, true); if (viewBangThuTienRow[ViewBangThuTienFieldName.ThanhTien, DataRowVersion.Original] != DBNull.Value && viewBangThuTienRow[ViewBangThuTienFieldName.ThanhTien, DataRowVersion.Current] != DBNull.Value) { long originalVersionToCompare = (long)viewBangThuTienRow[ViewBangThuTienFieldName.ThanhTien, DataRowVersion.Original]; long currentVersionToCompare = (long)viewBangThuTienRow[ViewBangThuTienFieldName.ThanhTien, DataRowVersion.Current]; if (originalVersionToCompare != currentVersionToCompare) { qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand.CommandParameter.Remove(UpdateSoTienTruyThuOfBangThuTienCommand.ParameterCurrentViewBangThuTien); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand.CommandParameter.Remove(UpdateSoTienTruyThuOfBangThuTienCommand.ParameterSoTienAdded); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand.CommandParameter.Add(UpdateSoTienTruyThuOfBangThuTienCommand.ParameterCurrentViewBangThuTien, viewBangThuTienRow); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand.CommandParameter.Add(UpdateSoTienTruyThuOfBangThuTienCommand.ParameterSoTienAdded, currentVersionToCompare - originalVersionToCompare); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTien(); } } }
private List <ViewBangThuTienRow> loadViewBangThuTiensToanTruong(DateTime toDate, int?lopId) { ViewBangThuTienTableAdapter viewBangThuTienTableAdapter = (ViewBangThuTienTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterViewBangThuTien); BangThuTienKhoanThuTableAdapter bangThuTienKhoanThuTableAdapter = (BangThuTienKhoanThuTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterBangThuTienKhoanThu); PhieuThuTableAdapter phieuThuTableAdapter = (PhieuThuTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterPhieuThu); ViewBangThuTienDataTable table = viewBangThuTienTableAdapter.GetViewBangThuTienByNgayTinhAndLop(toDate, lopId); List <int> bangThuTienIds = new List <int>(table.Rows.Count); foreach (ViewBangThuTienRow row in table) { bangThuTienIds.Add(row.BangThuTienId); } if (!ListUtil.IsEmpty(bangThuTienIds)) { QLMamNon.Dao.QLMamNonDs.BangThuTienKhoanThuDataTable bTTKTDataTable = bangThuTienKhoanThuTableAdapter.GetBangThuTienKhoanThuByBangThuTienIds(String.Join(",", bangThuTienIds)); QLMamNon.Dao.QLMamNonDs.PhieuThuDataTable phieuThuDataTable = phieuThuTableAdapter.GetDataByHocSinhIdAndNgayTinh(-1, toDate); Dictionary <int, ViewBangThuTienRow> prevMonthRowDictionary = this.EvaluatePrevMonthViewBangThuTienTable(toDate.AddMonths(-1), lopId); HocSinhDataTable hocSinhDataTable = this.getHocSinhData(); foreach (ViewBangThuTienRow row in table) { row.HoTen = StaticDataUtil.GetHocSinhFullNameByHocSinhId(hocSinhDataTable, row.HocSinhId); BangThuTienUtil.EvaluateValuesForViewBangThuTienRow(row, prevMonthRowDictionary != null && prevMonthRowDictionary.ContainsKey(row.HocSinhId) ? prevMonthRowDictionary[row.HocSinhId] : null, bTTKTDataTable, phieuThuDataTable, false, false, true); } } List <ViewBangThuTienRow> viewBangThuTienRows = new List <Dao.QLMamNonDs.ViewBangThuTienRow>(); foreach (ViewBangThuTienRow row in table) { viewBangThuTienRows.Add(row); } return(viewBangThuTienRows); }
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); }
private static Dictionary <int, Dictionary <int, ViewBangThuTienRow> > getAndSortPrevMonthViewBangThuTienRows(DateTime ngayTinh, ViewBangThuTienTableAdapter viewBangThuTienTableAdapter, List <int> hocSinhIds, Dictionary <int, HocSinhLopRow> hocSinhIdsToHocSinhLops, Dictionary <int, Dictionary <int, ViewBangThuTienRow> > lopToHocSinhToViewBangThuTienRowsMap) { ViewBangThuTienDataTable prevMonthViewBangThuTienTable = viewBangThuTienTableAdapter.GetViewBangThuTienByNgayTinhAndLop(ngayTinh.AddMonths(-1), null); Dictionary <int, Dictionary <int, ViewBangThuTienRow> > lopToHocSinhViewBangThuTienRows = new Dictionary <int, Dictionary <int, ViewBangThuTienRow> >(); foreach (ViewBangThuTienRow viewBangThuTienRow in prevMonthViewBangThuTienTable) { if (!hocSinhIds.Contains(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); } // Sort HocSinh in each Lop by STT ASC foreach (KeyValuePair <int, Dictionary <int, ViewBangThuTienRow> > lopToHocSinhViewBangThuTienRow in lopToHocSinhViewBangThuTienRows) { int lopId = lopToHocSinhViewBangThuTienRow.Key; Dictionary <int, ViewBangThuTienRow> hocSinhViewBangThuTienRows = lopToHocSinhToViewBangThuTienRowsMap.ContainsKey(lopId) ? lopToHocSinhToViewBangThuTienRowsMap[lopId] : null; SortedList <int, ViewBangThuTienRow> sortedViewBangThuTienRows = new SortedList <int, ViewBangThuTienRow>(); int currentMaxSTT = ListUtil.IsEmpty(hocSinhViewBangThuTienRows) ? 0 : hocSinhViewBangThuTienRows.Count; foreach (KeyValuePair <int, ViewBangThuTienRow> hocSinhIdToViewBangThuTienRow in lopToHocSinhViewBangThuTienRow.Value) { if (!sortedViewBangThuTienRows.ContainsKey(hocSinhIdToViewBangThuTienRow.Value.STT)) { sortedViewBangThuTienRows.Add(hocSinhIdToViewBangThuTienRow.Value.STT, hocSinhIdToViewBangThuTienRow.Value); } } for (int i = 0; i < sortedViewBangThuTienRows.Count; i++) { sortedViewBangThuTienRows.Values[i].STT = i + currentMaxSTT + 1; } } return(lopToHocSinhViewBangThuTienRows); }