Example #1
0
        public void InsertBudgetPurchase(int OrganizationUnitID, int PurchaseBudgetTypeID, int FYear, decimal? AOPBudget, decimal? AOPRBudget, int UserID, int PositionID, string ModifyReason)
        {
            SqlTransaction transaction = null;
            try {
                ////事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TABudgetPurchase);
                TableAdapterHelper.SetTransaction(this.TABudgetPurchaseHistory, transaction);

                //增加重复验证
                if ((int)this.TABudgetPurchase.SearchBudgetPurchaseByIns(OrganizationUnitID, FYear, PurchaseBudgetTypeID) > 0) {
                    throw new MyException("预算重复设置", "budget exists ");
                }

                //增加上级或下级部门重复验证
                if ((int)this.TABudgetPurchase.SearchBudgetPurchaseByTreePath(GetTreePathByOUID(OrganizationUnitID), FYear, OrganizationUnitID) > 0) {
                    throw new MyException("本财月预算重复(上级或下级部门已设置预算)!", "Budget of this month exists!");
                }

                // 父表
                Budget.BudgetPurchaseDataTable table = new Budget.BudgetPurchaseDataTable();
                Budget.BudgetPurchaseRow row = table.NewBudgetPurchaseRow();

                row.OrganizationUnitID = OrganizationUnitID;
                row.PurchaseBudgetTypeID = PurchaseBudgetTypeID;
                row.FYear = FYear;
                row.AOPBudget = AOPBudget.GetValueOrDefault();
                row.AOPRBudget = AOPRBudget.GetValueOrDefault();
                if (ModifyReason != null) {
                    row.ModifyReason = ModifyReason;
                }
                table.AddBudgetPurchaseRow(row);
                this.TABudgetPurchase.Update(table);

                // 子表
                Budget.BudgetPurchaseHistoryDataTable tableDetail = new Budget.BudgetPurchaseHistoryDataTable();
                Budget.BudgetPurchaseHistoryRow rowDetail = tableDetail.NewBudgetPurchaseHistoryRow();

                rowDetail.OrganizationUnitID = row.OrganizationUnitID;
                rowDetail.PurchaseBudgetTypeID = row.PurchaseBudgetTypeID;
                rowDetail.FYear = row.FYear;
                rowDetail.AOPBudget = row.AOPBudget;
                rowDetail.AOPRBudget = row.AOPRBudget;
                rowDetail.AdjustBudget = row.AdjustBudget;
                rowDetail.Action = "Create";
                rowDetail.ModifyDate = DateTime.Now;
                rowDetail.PositionID = PositionID;
                rowDetail.UserID = UserID;
                if (ModifyReason != null) {
                    rowDetail.ModifyReason = ModifyReason;
                }
                rowDetail.BudgetPurchaseID = row.BudgetPurchaseID;
                tableDetail.AddBudgetPurchaseHistoryRow(rowDetail);
                this.TABudgetPurchaseHistory.Update(tableDetail);

                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw ex;
            } finally {
                transaction.Dispose();
            }
        }
Example #2
0
        public void UpdateBudgetPurchase(int BudgetPurchaseID, decimal? AOPBudget, decimal? AOPRBudget,
            int UserID, int PositionID, string ModifyReason)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TABudgetPurchase);
                TableAdapterHelper.SetTransaction(this.TABudgetPurchaseHistory, transaction);

                // 父表
                Budget.BudgetPurchaseRow row = this.TABudgetPurchase.GetDataByID(BudgetPurchaseID)[0];

                //删除前检查是否会超预算
                if (row.AOPRBudget > AOPRBudget) {
                    decimal[] calculateAssistant = this.GetManagingBudgetByOUID(row.OrganizationUnitID, row.FYear, row.PurchaseBudgetTypeID);
                    if (row.AOPRBudget - AOPRBudget > calculateAssistant[5]) {
                        throw new MyException("本次修改导致原有记录超预算,不能修改,目前部门剩余预算为:" + calculateAssistant[5], "Over budget,modify failed,current remain budget is :" + calculateAssistant[5]);
                    }
                }

                row.AOPBudget = AOPBudget.GetValueOrDefault();
                row.AOPRBudget = AOPRBudget.GetValueOrDefault();
                if (ModifyReason != null) {
                    row.ModifyReason = ModifyReason;
                }
                this.TABudgetPurchase.Update(row);

                // 子表
                Budget.BudgetPurchaseHistoryDataTable tableDetail = new Budget.BudgetPurchaseHistoryDataTable();
                Budget.BudgetPurchaseHistoryRow rowDetail = tableDetail.NewBudgetPurchaseHistoryRow();

                rowDetail.OrganizationUnitID = row.OrganizationUnitID;
                rowDetail.PurchaseBudgetTypeID = row.PurchaseBudgetTypeID;
                rowDetail.FYear = row.FYear;
                rowDetail.AOPBudget = row.AOPBudget;
                rowDetail.AOPRBudget = row.AOPRBudget;
                rowDetail.AdjustBudget = row.AdjustBudget;
                rowDetail.Action = "Modify";
                rowDetail.ModifyDate = DateTime.Now;
                rowDetail.PositionID = PositionID;
                rowDetail.UserID = UserID;
                if (ModifyReason != null) {
                    rowDetail.ModifyReason = ModifyReason;
                }
                rowDetail.BudgetPurchaseID = row.BudgetPurchaseID;

                tableDetail.AddBudgetPurchaseHistoryRow(rowDetail);
                this.TABudgetPurchaseHistory.Update(tableDetail);

                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw ex;
            } finally {
                transaction.Dispose();
            }
        }