예제 #1
0
파일: BudgetBLL.cs 프로젝트: hijoy/CPL_ERS
        public void InsertBudgetMarketing(int OrganizationUnitID, int CustomerChannelID, int BrandID, int ExpenseCategoryID,
            string FPeriod, decimal? AOPBudget, decimal? AOPRBudget, decimal? ProjectionBudget, object AdjustBudgetStr, string ModifyReason, int UserID,
            int PositionID)
        {
            SqlTransaction transaction = null;
            try {
                ////事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TABudgetMarketing);
                TableAdapterHelper.SetTransaction(this.TABudgetMarketingHistory, transaction);

                //增加重复验证
                if ((int)this.TABudgetMarketing.SearchBudgetMarketingByIns(OrganizationUnitID, CustomerChannelID, BrandID, DateTime.Parse(FPeriod.Substring(0, 4) + "-" + FPeriod.Substring(4, 2) + "-01"), ExpenseCategoryID) > 0) {
                    throw new MyException("预算重复设置", "budget exists ");
                }

                //增加上级或下级部门重复验证
                if ((int)this.TABudgetMarketing.SearchBudgetMarketingByTreePath(GetTreePathByOUID(OrganizationUnitID), DateTime.Parse(FPeriod.Substring(0, 4) + "-" + FPeriod.Substring(4, 2) + "-01"), OrganizationUnitID) > 0) {
                    throw new MyException("本财月预算重复(上级或下级部门已设置预算)!", "Budget of this month exists!");
                }

                // 父表
                Budget.BudgetMarketingDataTable table = new Budget.BudgetMarketingDataTable();
                Budget.BudgetMarketingRow row = table.NewBudgetMarketingRow();

                decimal? AdjustBudget = null;
                if (AdjustBudgetStr != null && !string.IsNullOrEmpty(AdjustBudgetStr.ToString())) {
                    AdjustBudget = decimal.Parse(AdjustBudgetStr.ToString());
                }

                row.OrganizationUnitID = OrganizationUnitID;
                row.CustomerChannelID = CustomerChannelID;
                row.BrandID = BrandID;
                row.ExpenseCategoryID = ExpenseCategoryID;
                row.FPeriod = DateTime.Parse(FPeriod.Substring(0, 4) + "-" + FPeriod.Substring(4, 2) + "-01");
                row.AOPBudget = AOPBudget.GetValueOrDefault();
                row.AOPRBudget = AOPRBudget.GetValueOrDefault();
                row.ProjectionBudget = ProjectionBudget.GetValueOrDefault();
                row.AdjustBudget = AdjustBudget.GetValueOrDefault();
                if (ModifyReason != null) {
                    row.ModifyReason = ModifyReason;
                }
                table.AddBudgetMarketingRow(row);
                this.TABudgetMarketing.Update(table);

                // 子表
                Budget.BudgetMarketingHistoryDataTable tableDetail = new Budget.BudgetMarketingHistoryDataTable();
                Budget.BudgetMarketingHistoryRow rowDetail = tableDetail.NewBudgetMarketingHistoryRow();

                rowDetail.OrganizationUnitID = row.OrganizationUnitID;
                rowDetail.CustomerChannelID = row.CustomerChannelID;
                rowDetail.BrandID = row.BrandID;
                rowDetail.ExpenseCategoryID = row.ExpenseCategoryID;
                rowDetail.FPeriod = row.FPeriod;
                rowDetail.AOPBudget = row.AOPBudget;
                rowDetail.AOPRBudget = row.AOPRBudget;
                rowDetail.ProjectionBudget = row.ProjectionBudget;
                rowDetail.AdjustBudget = row.AdjustBudget;
                rowDetail.Action = "Create";
                rowDetail.ModifyDate = DateTime.Now;
                rowDetail.PositionID = PositionID;
                rowDetail.UserID = UserID;
                if (ModifyReason != null) {
                    rowDetail.ModifyReason = ModifyReason;
                }
                rowDetail.BudgetMarketingID = row.BudgetMarketingID;
                tableDetail.AddBudgetMarketingHistoryRow(rowDetail);
                this.TABudgetMarketingHistory.Update(tableDetail);

                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw ex;
            } finally {
                transaction.Dispose();
            }
        }
예제 #2
0
파일: BudgetBLL.cs 프로젝트: hijoy/CPL_ERS
        public void UpdateBudgetMarketing(int BudgetMarketingID, decimal? ProjectionBudget, decimal? AdjustBudget, string ModifyReason,
            int UserID, int PositionID)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TABudgetMarketing);
                TableAdapterHelper.SetTransaction(this.TABudgetMarketingHistory, transaction);

                // 父表
                Budget.BudgetMarketingRow row = this.TABudgetMarketing.GetDataByID(BudgetMarketingID)[0];

                if (row.ProjectionBudget > ProjectionBudget) {
                    decimal[] calculateAssistant = this.GetMarketingBudgetByOUID(row.OrganizationUnitID, row.FPeriod, row.CustomerChannelID, row.BrandID, row.ExpenseCategoryID);
                    if (row.ProjectionBudget - ProjectionBudget > calculateAssistant[4]) {
                        throw new MyException("本次修改导致原有记录超预算,不能修改,目前部门剩余预算为:" + calculateAssistant[4], "Over budget,modify failed,current remain budget is :" + calculateAssistant[4]);
                    }
                }

                row.ProjectionBudget = ProjectionBudget.GetValueOrDefault();
                row.AdjustBudget = AdjustBudget.GetValueOrDefault();
                if (ModifyReason != null) {
                    row.ModifyReason = ModifyReason;
                }
                this.TABudgetMarketing.Update(row);

                // 子表
                Budget.BudgetMarketingHistoryDataTable tableDetail = new Budget.BudgetMarketingHistoryDataTable();
                Budget.BudgetMarketingHistoryRow rowDetail = tableDetail.NewBudgetMarketingHistoryRow();

                rowDetail.OrganizationUnitID = row.OrganizationUnitID;
                rowDetail.CustomerChannelID = row.CustomerChannelID;
                rowDetail.BrandID = row.BrandID;
                rowDetail.ExpenseCategoryID = row.ExpenseCategoryID;
                rowDetail.FPeriod = row.FPeriod;
                rowDetail.AOPBudget = row.AOPBudget;
                rowDetail.AOPRBudget = row.AOPRBudget;
                rowDetail.ProjectionBudget = row.ProjectionBudget;
                rowDetail.AdjustBudget = row.AdjustBudget;
                rowDetail.Action = "Modify";
                rowDetail.ModifyDate = DateTime.Now;
                rowDetail.PositionID = PositionID;
                rowDetail.UserID = UserID;
                if (ModifyReason != null) {
                    rowDetail.ModifyReason = ModifyReason;
                }
                rowDetail.BudgetMarketingID = row.BudgetMarketingID;

                tableDetail.AddBudgetMarketingHistoryRow(rowDetail);
                this.TABudgetMarketingHistory.Update(tableDetail);

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