Пример #1
0
        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();
                }
            }
        }
Пример #2
0
        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();
        }