public void InsertBudgetSale(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.TABudgetSale); TableAdapterHelper.SetTransaction(this.TABudgetSaleHistory, transaction); //增加重复验证 if ((int)this.TABudgetSale.SearchBudgetSaleByTreePath(GetTreePathByOUID(OrganizationUnitID), DateTime.Parse(FPeriod.Substring(0, 4) + "-" + FPeriod.Substring(4, 2) + "-01"),OrganizationUnitID) > 0) { throw new MyException("本财月预算重复(上级或下级部门已设置预算)!", "Budget of this month exists!"); } //增加上级或下级预算重复验证 if ((int)this.TABudgetSale.SearchBudgetSaleByIns(OrganizationUnitID, CustomerChannelID, BrandID, ExpenseCategoryID, DateTime.Parse(FPeriod.Substring(0, 4) + "-" + FPeriod.Substring(4, 2) + "-01")) > 0) { throw new MyException("预算重复设置", "budget exists "); } // 父表 Budget.BudgetSaleDataTable table = new Budget.BudgetSaleDataTable(); Budget.BudgetSaleRow row = table.NewBudgetSaleRow(); 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.AddBudgetSaleRow(row); this.TABudgetSale.Update(table); // 子表 Budget.BudgetSaleHistoryDataTable tableDetail = new Budget.BudgetSaleHistoryDataTable(); Budget.BudgetSaleHistoryRow rowDetail = tableDetail.NewBudgetSaleHistoryRow(); 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.AdjustBudget = AdjustBudget.GetValueOrDefault(); rowDetail.Action = "Create"; rowDetail.ModifyDate = DateTime.Now; rowDetail.PositionID = PositionID; rowDetail.UserID = UserID; if (ModifyReason != null) { rowDetail.ModifyReason = ModifyReason; } rowDetail.BudgetSaleID = row.BudgetSaleID; tableDetail.AddBudgetSaleHistoryRow(rowDetail); this.TABudgetSaleHistory.Update(tableDetail); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); } }
public void UpdateBudgetSale(int BudgetSaleID, decimal? ProjectionBudget, decimal? AdjustBudget, string ModifyReason, int UserID, int PositionID) { SqlTransaction transaction = null; try { ////事务开始 transaction = TableAdapterHelper.BeginTransaction(this.TABudgetSale); TableAdapterHelper.SetTransaction(this.TABudgetSaleHistory, transaction); // 父表 Budget.BudgetSaleRow row = this.TABudgetSale.GetDataByID(BudgetSaleID)[0]; if (row.ProjectionBudget > ProjectionBudget) { decimal[] calculateAssistant = this.GetSalesBudgetByOUID(row.OrganizationUnitID, row.FPeriod, row.ExpenseCategoryID, row.CustomerChannelID, row.BrandID); if (row.ProjectionBudget - ProjectionBudget > calculateAssistant[5]) { throw new MyException("本次修改导致原有记录超预算,不能修改,目前部门剩余预算为:" + calculateAssistant[5], "Over budget,modify failed,current remain budget is :" + calculateAssistant[5]); } } row.ProjectionBudget = ProjectionBudget.GetValueOrDefault(); row.AdjustBudget = AdjustBudget.GetValueOrDefault(); if (ModifyReason != null) { row.ModifyReason = ModifyReason; } this.TABudgetSale.Update(row); // 子表 Budget.BudgetSaleHistoryDataTable tableDetail = new Budget.BudgetSaleHistoryDataTable(); Budget.BudgetSaleHistoryRow rowDetail = tableDetail.NewBudgetSaleHistoryRow(); 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.AdjustBudget = AdjustBudget.GetValueOrDefault(); rowDetail.Action = "Modify"; rowDetail.ModifyDate = DateTime.Now; rowDetail.PositionID = PositionID; rowDetail.UserID = UserID; if (ModifyReason != null) { rowDetail.ModifyReason = ModifyReason; } rowDetail.BudgetSaleID = row.BudgetSaleID; tableDetail.AddBudgetSaleHistoryRow(rowDetail); this.TABudgetSaleHistory.Update(tableDetail); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); } }