public void InsertBudgetRD(int UserID, int PositionID, int OrganizationUnitID, int CustomerChannelID, int BrandID, int ExpenseSubCategoryID, string FPeriod, decimal? AOPBudget, decimal? AOPRBudget, decimal? ProjectionBudget, object AdjustBudgetStr, string ModifyReason) { SqlTransaction transaction = null; try { ////事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TABudgetRD); TableAdapterHelper.SetTransaction(this.TABudgetRDHistory, transaction); //增加重复验证 if ((int)this.TABudgetRD.SearchBudgetRDByIns(OrganizationUnitID, CustomerChannelID, BrandID, DateTime.Parse(FPeriod.Substring(0, 4) + "-" + FPeriod.Substring(4, 2) + "-01"), ExpenseSubCategoryID) > 0) { throw new MyException("预算重复设置", "budget exists "); } //增加重复验证 if ((int)this.TABudgetRD.SearchBudgetRDByTreePath(GetTreePathByOUID(OrganizationUnitID), DateTime.Parse(FPeriod.Substring(0, 4) + "-" + FPeriod.Substring(4, 2) + "-01"), OrganizationUnitID) > 0) { throw new MyException("预算重复设置或者上级或下级部门已经设置预算", "budget exists"); } // 父表 Budget.BudgetRDDataTable table = new Budget.BudgetRDDataTable(); Budget.BudgetRDRow row = table.NewBudgetRDRow(); 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.ExpenseSubCategoryID = ExpenseSubCategoryID; 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.AddBudgetRDRow(row); this.TABudgetRD.Update(table); // 子表 Budget.BudgetRDHistoryDataTable tableDetail = new Budget.BudgetRDHistoryDataTable(); Budget.BudgetRDHistoryRow rowDetail = tableDetail.NewBudgetRDHistoryRow(); rowDetail.OrganizationUnitID = row.OrganizationUnitID; rowDetail.CustomerChannelID = row.CustomerChannelID; rowDetail.BrandID = row.BrandID; rowDetail.ExpenseSubCategoryID = row.ExpenseSubCategoryID; 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.BudgetRDID = row.BudgetRDID; tableDetail.AddBudgetRDHistoryRow(rowDetail); this.TABudgetRDHistory.Update(tableDetail); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); } }
public void UpdateBudgetRD(int BudgetRDID, decimal? ProjectionBudget, decimal? AdjustBudget, string ModifyReason, int UserID, int PositionID) { SqlTransaction transaction = null; try { //事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TABudgetRD); TableAdapterHelper.SetTransaction(this.TABudgetRDHistory, transaction); // 父表 Budget.BudgetRDRow row = this.TABudgetRD.GetDataByID(BudgetRDID)[0]; if (row.ProjectionBudget > ProjectionBudget) { decimal[] calculateAssistant = this.GetRDBudgetByOUID(row.OrganizationUnitID, row.FPeriod, row.CustomerChannelID, row.BrandID, row.ExpenseSubCategoryID); 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.TABudgetRD.Update(row); // 子表 Budget.BudgetRDHistoryDataTable tableDetail = new Budget.BudgetRDHistoryDataTable(); Budget.BudgetRDHistoryRow rowDetail = tableDetail.NewBudgetRDHistoryRow(); rowDetail.OrganizationUnitID = row.OrganizationUnitID; rowDetail.CustomerChannelID = row.CustomerChannelID; rowDetail.BrandID = row.BrandID; rowDetail.ExpenseSubCategoryID = row.ExpenseSubCategoryID; 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.BudgetRDID = row.BudgetRDID; tableDetail.AddBudgetRDHistoryRow(rowDetail); this.TABudgetRDHistory.Update(tableDetail); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); } }