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); }
private void generateBangThuTienKhoanThu(int bangThuTienId, int khoiId, DateTime ngayTinh, ViewBangThuTienRow preMonthViewBangThuTien) { KhoanThuHangNamTableAdapter khoanThuHangNamTableAdapter = (KhoanThuHangNamTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterKhoanThuHangNam); BangThuTienTableAdapter bangThuTienTableAdapter = (BangThuTienTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterBangThuTien); BangThuTienKhoanThuTableAdapter bangThuTienKhoanThuTableAdapter = (BangThuTienKhoanThuTableAdapter)StaticDataFacade.Get(StaticDataKeys.AdapterBangThuTienKhoanThu); int[] khoanThuIds = new int[] { BangThuTienConstant.KhoanThuIdBanTru, BangThuTienConstant.KhoanThuIdHocPhi, BangThuTienConstant.KhoanThuIdPhuPhi, BangThuTienConstant.KhoanThuIdTienAnSua, BangThuTienConstant.KhoanThuIdAnSang, BangThuTienConstant.KhoanThuIdAnToi }; List <int> ignoreKhoanThuIds = getKhoanThuIdsToIgnoreGenerating(preMonthViewBangThuTien); QLMamNon.Dao.QLMamNonDs.KhoanThuHangNamDataTable khoanThuHangNamTable = khoanThuHangNamTableAdapter.GetKhoanThuHangNamByParams(String.Join(",", khoanThuIds), khoiId, ngayTinh); BangThuTienDataTable bangThuTienTable = bangThuTienTableAdapter.GetDataById(bangThuTienId); QLMamNon.Dao.QLMamNonDs.BangThuTienRow bangThuTienRow = bangThuTienTable[0]; foreach (QLMamNon.Dao.QLMamNonDs.KhoanThuHangNamRow row in khoanThuHangNamTable) { long soTien = 0; if (!ignoreKhoanThuIds.Contains(row.KhoanThuId)) { soTien = BangThuTienUtil.CalculateSoTienPhi(khoiId, 0, row.SoTien, row.KhoanThuId); } bangThuTienKhoanThuTableAdapter.Insert(row.KhoanThuId, bangThuTienId, soTien); if (soTien != 0) { switch (row.KhoanThuId) { case BangThuTienConstant.KhoanThuIdAnSang: bangThuTienRow.SoTienAnSangThangNay = soTien; break; case BangThuTienConstant.KhoanThuIdAnToi: bangThuTienRow.SoTienAnToiThangNay = soTien; break; default: break; } } } bangThuTienTableAdapter.Update(bangThuTienRow); }
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); }
private void gvMain_CellValueChanged(object sender, CellValueChangedEventArgs e) { GridView gv = sender as GridView; List <String> fieldsToEvaluate = new List <string>() { ViewBangThuTienFieldName.SXThangTruoc, ViewBangThuTienFieldName.AnSangThangTruoc, ViewBangThuTienFieldName.SoTienAnSangThangNay, ViewBangThuTienFieldName.AnToiThangTruoc, ViewBangThuTienFieldName.SoTienAnToiThangNay, ViewBangThuTienFieldName.SoTienNangKhieu, ViewBangThuTienFieldName.SoTienTruyThu, ViewBangThuTienFieldName.SoTienDieuHoa, ViewBangThuTienFieldName.SoTienDoDung, ViewBangThuTienFieldName.TienAnVaSua, ViewBangThuTienFieldName.PhuPhi, ViewBangThuTienFieldName.BanTru, ViewBangThuTienFieldName.HocPhi }; if (fieldsToEvaluate.Contains(e.Column.FieldName) && e.RowHandle != DevExpress.XtraGrid.GridControl.InvalidRowHandle) { if (e.Value != DBNull.Value) { DataRowView rowView = gv.GetRow(e.RowHandle) as DataRowView; ViewBangThuTienRow row = rowView.Row as ViewBangThuTienRow; BangThuTienUtil.EvaluateValuesForViewBangThuTienRow(row, prevMonthRowDictionary != null && prevMonthRowDictionary.ContainsKey(row.HocSinhId) ? prevMonthRowDictionary[row.HocSinhId] : null, bTTKTDataTable, phieuThuDataTable, false, false, false); if (ViewBangThuTienFieldName.SXThangTruoc.Equals(e.Column.FieldName)) { BangThuTienUtil.RecalculateBangThuTienKhoanThuList(lopKhoiTableAdapter, khoanThuHangNamTableAdapter, row); } } } }
private void loadViewBangThuTiens(DateTime ngayTinh, int lop) { if (this.isNeedToGenerateSoThuTiens(ngayTinh, lop, false)) { this.showFormGenerateSoThuTiens(true); return; } ViewBangThuTienDataTable table = viewBangThuTienTableAdapter.GetViewBangThuTienByNgayTinhAndLop(ngayTinh, lop); List <int> bangThuTienIds = new List <int>(table.Rows.Count); foreach (ViewBangThuTienRow row in table) { bangThuTienIds.Add(row.BangThuTienId); } if (!ListUtil.IsEmpty(bangThuTienIds)) { bTTKTDataTable = bangThuTienKhoanThuTableAdapter.GetBangThuTienKhoanThuByBangThuTienIds(String.Join(",", bangThuTienIds)); phieuThuDataTable = phieuThuTableAdapter.GetDataByHocSinhIdAndNgayTinh(-1, ngayTinh); SoThuTienService soThuTienService = new SoThuTienService(); prevMonthRowDictionary = soThuTienService.EvaluatePrevMonthViewBangThuTienTable(ngayTinh.AddMonths(-1), lop); 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); row.AcceptChanges(); } } this.viewBangThuTienRowBindingSource.DataSource = table; this.DataTable = table; }
protected override void onSaving() { ViewBangThuTienDataTable table = this.DataTable as ViewBangThuTienDataTable; List <int> bangThuTienIds = new List <int>(); foreach (ViewBangThuTienRow viewBangThuTienRow in table) { viewBangThuTienRow.SoTienSXThangTruoc = BangThuTienUtil.SXToSoTienSX(viewBangThuTienRow.SXThangTruoc, Settings.Default.TienAnChinh); viewBangThuTienRow.SoTienAnSangThangTruoc = BangThuTienUtil.SXAnSangToSoTienAnSang(viewBangThuTienRow.AnSangThangTruoc, Settings.Default.TienAnSang); viewBangThuTienRow.SoTienAnToiThangTruoc = BangThuTienUtil.SXAnToiToSoTienAnToi(viewBangThuTienRow.AnToiThangTruoc, Settings.Default.TienAnToi); if (this.isNeedToUpdateBangThuTienKhoanThu(viewBangThuTienRow)) { bangThuTienIds.Add(viewBangThuTienRow.BangThuTienId); } } if (!ListUtil.IsEmpty(bangThuTienIds)) { QLMamNon.Dao.QLMamNonDs.BangThuTienKhoanThuDataTable bangThuTienKhoanThuDataTable = bangThuTienKhoanThuTableAdapter.GetBangThuTienKhoanThuByBangThuTienIds(StringUtil.Join(bangThuTienIds, ",")); foreach (QLMamNon.Dao.QLMamNonDs.BangThuTienKhoanThuRow bangThuTienKhoanThuRow in bangThuTienKhoanThuDataTable) { ViewBangThuTienRow[] viewBangThuTienRows = (ViewBangThuTienRow[])table.Select(String.Format("BangThuTienId={0}", bangThuTienKhoanThuRow.BangThuTienId)); ViewBangThuTienRow viewBangThuTienRow = viewBangThuTienRows[0]; switch (bangThuTienKhoanThuRow.KhoanThuId) { case BangThuTienConstant.KhoanThuIdTienAnSua: bangThuTienKhoanThuRow.SoTien = viewBangThuTienRow.TienAnSua; break; case BangThuTienConstant.KhoanThuIdPhuPhi: bangThuTienKhoanThuRow.SoTien = viewBangThuTienRow.PhuPhi; break; case BangThuTienConstant.KhoanThuIdBanTru: bangThuTienKhoanThuRow.SoTien = viewBangThuTienRow.BanTru; break; case BangThuTienConstant.KhoanThuIdHocPhi: bangThuTienKhoanThuRow.SoTien = viewBangThuTienRow.HocPhi; break; case BangThuTienConstant.KhoanThuIdAnSang: bangThuTienKhoanThuRow.SoTien = viewBangThuTienRow.SoTienAnSangThangNay; break; case BangThuTienConstant.KhoanThuIdAnToi: bangThuTienKhoanThuRow.SoTien = viewBangThuTienRow.SoTienAnToiThangNay; break; default: break; } } bangThuTienKhoanThuTableAdapter.Update(bangThuTienKhoanThuDataTable); } // Start Updating SoTienTruyThu for each BangThuTienRow QLMNDaoJobInvoker qlmnDaoJobInvoker = new QLMNDaoJobInvoker(); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand = new UpdateSoTienTruyThuOfBangThuTienCommand(); qlmnDaoJobInvoker.UpdateSoTienTruyThuOfBangThuTienCommand.CommandParameter.Add(UpdateSoTienTruyThuOfBangThuTienCommand.ParameterViewBangThuTienTableAdapter, this.viewBangThuTienTableAdapter); foreach (ViewBangThuTienRow viewBangThuTienRow in table) { 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(); } } } // Finished Updating SoTienTruyThu for each BangThuTien base.onSaving(); }