protected override void OnPostSave() { try { if (this.State == EntityState.Modified) { string isActiveCheck; if (IsActive == true) { isActiveCheck = "active"; } else { isActiveCheck = "inactive"; } //read new keys after update ReadNewKeys(); DataSet ds = new DataSet(); DBWorkPackage dbWorkPackage = new DBWorkPackage(base.CurrentConnectionManager); ds = dbWorkPackage.SelectObject(this); string strFunction = "Project Manager"; if (ds.Tables[0].Rows[0]["IdProjectFunction"] != DBNull.Value && (int)ds.Tables[0].Rows[0]["IdProjectFunction"] == ApplicationConstants.PROJECT_FUNCTION_PROGRAM_ASSISTANT) { strFunction = "Program Assistant"; } string mailSubject = String.Format("Project update {0}", this.ProjectName); string mailText = "The work package " + this.Name + " of the project " + this.ProjectName + " has been turned to " + isActiveCheck + " by " + this.LastUserUpdate + ", " + strFunction + ". Please check your local system and see if you have something to invoice. This is an automatically sent email, please do not respond to it."; //Send the email only if the current user is program manager for this project if ((bool)ds.Tables[0].Rows[0]["IsProgramManager"] == true) { if (IsActive != lastIsActive) { SendMail(mailSubject, mailText); } } } } //The exception can occur if the email was not sent. In this case, in addition to the exception message, we must add that //that the work package was not saved catch (Exception exc) { throw new IndException(exc.Message + " Work Package was not saved."); } }
public override void Initialize() { base.Initialize(); dbEntity = new DBWorkPackage(connManager); }
public void VerifyInitialBudget() { IInitialBudget initialBudget = BusinessObjectInitializer.CreateInitialBudget(); ICostCenter costCenter = BusinessObjectInitializer.CreateCostCenter(); IWorkPackage workPackage = BusinessObjectInitializer.CreateWorkPackage(); IProject project = BusinessObjectInitializer.CreateProject(); IProjectCoreTeamMember coreTeamMembers = BusinessObjectInitializer.CreateProjectCoreTeamMember(); DBInitialBudget dbInitialBudget = new DBInitialBudget(connManager); DBGenericEntity dbCostCenterEntity = new DBCostCenter(connManager); DBGenericEntity dbWorkPackageEntity = new DBWorkPackage(connManager); DBGenericEntity dbProjectEntity = new DBProject(connManager); DBProjectCoreTeamMember dbCoreteamMember = new DBProjectCoreTeamMember(connManager); Random random = new Random(); initialBudget.IdAssociate = DATestUtils.DEFAULT_ASSOCIATE; initialBudget.IdPhase = random.Next(1, 9); costCenter.Id = random.Next(1000, 2000); costCenter.Name = DATestUtils.GenerateString(50, true, false); costCenter.Code = DATestUtils.GenerateString(10, true, true); costCenter.IdDepartment = random.Next(1, 1); costCenter.IdInergyLocation = random.Next(1, 2); costCenter.IsActive = true; workPackage.IdPhase = initialBudget.IdPhase; workPackage.Code = DATestUtils.GenerateString(3, true, true); workPackage.Name = DATestUtils.GenerateString(30, true, false); workPackage.Rank = random.Next(1, 100); workPackage.IsActive = true; workPackage.StartYearMonth = random.Next(2000, 2079) * 100 + random.Next(1, 12); workPackage.EndYearMonth = random.Next(2000, 2079) * 100 + random.Next(1, 12); workPackage.LastUpdate = DateTime.Today; workPackage.IdLastUserUpdate = DATestUtils.DEFAULT_ASSOCIATE; project.Name = DATestUtils.GenerateString(50, true, false); project.Code = DATestUtils.GenerateString(10, true, true); project.IdProgram = random.Next(1, 2); project.IdProjectType = random.Next(1, 2); project.IsActive = true; initialBudget.Sales = random.Next(50000, 1000000); initialBudget.TotalHours = random.Next(1, 100); initialBudget.ValuedHours = random.Next(1, 100); initialBudget.YearMonth = DATestUtils.DEFAULT_YEAR_MONTH; int newId = InsertCostCenterTest(costCenter, dbCostCenterEntity); //Verifies that the id returned by the insert method is greater than 0 Assert.Greater(newId, 0); initialBudget.IdCostCenter = newId; newId = InsertProjectTest(project, dbProjectEntity); //Verifies that the id returned by the insert method is greater than 0 Assert.Greater(newId, 0); initialBudget.IdProject = newId; workPackage.IdProject = initialBudget.IdProject; coreTeamMembers.IdProject = initialBudget.IdProject; newId = InsertWorkPackageTest(workPackage, dbWorkPackageEntity); //Verifies that the id returned by the insert method is greater than 0 Assert.Greater(newId, 0); initialBudget.IdWP = newId; InsertInitialBudgetMasterTest(initialBudget, dbInitialBudget); coreTeamMembers.IdAssociate = DATestUtils.DEFAULT_ASSOCIATE; coreTeamMembers.IdFunction = DATestUtils.DEFAULT_PROJECT_FUNCTION; //verify if have core team member DataTable dsCoreMember = SelectProjectCoreTeamMemberTest(coreTeamMembers, dbCoreteamMember).Tables[0]; if (dsCoreMember.Rows.Count == 0) { int IdCoreteammember = InsertProjectCoreTeamMemberTest(coreTeamMembers, dbCoreteamMember); } InsertInitialBudgetTest(initialBudget, dbInitialBudget); UpdateInitialBudgetTest(initialBudget, dbInitialBudget); DBWPPreselection tempTable = new DBWPPreselection(connManager); tempTable.BulkInsert("CREATE TABLE #BUDGET_PRESELECTION_TEMP (IdProject INT NOT NULL, IdPhase INT NOT NULL, IdWP INT NOT NULL)"); tempTable.BulkInsert("INSERT INTO #BUDGET_PRESELECTION_TEMP (IdProject,IdPhase,IdWP) VALUES (" + initialBudget.IdProject.ToString() + "," + initialBudget.IdPhase.ToString() + "," + initialBudget.IdWP.ToString() + ")"); DataSet InitialBudgetDS = SelectInitialBudgetTest(initialBudget, dbInitialBudget); //Verifies that the table is not null DataTable tableVerifyPhases = InitialBudgetDS.Tables[0]; DataTable tableVerifyWorkPackages = InitialBudgetDS.Tables[1]; DataTable tableVerifyCostCenters = InitialBudgetDS.Tables[2]; Assert.IsNotNull(tableVerifyPhases, "The table returned should not be null"); Assert.IsNotNull(tableVerifyWorkPackages, "The table returned should not be null"); Assert.IsNotNull(tableVerifyCostCenters, "The table returned should not be null"); //Verifies that the first table is not null Assert.IsNotNull(tableVerifyPhases, "The table returned should not be null"); //Verifies that the table returns the correcty columns DATestUtils.CheckColumn(tableVerifyPhases, 0, "IdProject"); DATestUtils.CheckColumn(tableVerifyPhases, 1, "IdPhase"); DATestUtils.CheckColumn(tableVerifyPhases, 2, "PhaseName"); DATestUtils.CheckColumn(tableVerifyPhases, 3, "TotalHours"); DATestUtils.CheckColumn(tableVerifyPhases, 4, "Averate"); DATestUtils.CheckColumn(tableVerifyPhases, 5, "ValuedHours"); DATestUtils.CheckColumn(tableVerifyPhases, 6, "OtherCosts"); DATestUtils.CheckColumn(tableVerifyPhases, 7, "Sales"); DATestUtils.CheckColumn(tableVerifyPhases, 8, "NetCosts"); //Verifies that the second table is not null Assert.IsNotNull(tableVerifyWorkPackages, "The table returned should not be null"); //Verifies that the table returns the correcty columns DATestUtils.CheckColumn(tableVerifyWorkPackages, 0, "IdProject"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 1, "IdPhase"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 2, "IdWP"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 3, "WPName"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 4, "StartYearMonth"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 5, "EndYearMonth"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 6, "TotalHours"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 7, "Averate"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 8, "ValuedHours"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 9, "OtherCosts"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 10, "Sales"); DATestUtils.CheckColumn(tableVerifyWorkPackages, 11, "NetCosts"); //Verifies that the third table is not null Assert.IsNotNull(tableVerifyWorkPackages, "The table returned should not be null"); //Verifies that the table returns the correcty columns DATestUtils.CheckColumn(tableVerifyCostCenters, 0, "IdProject"); DATestUtils.CheckColumn(tableVerifyCostCenters, 1, "IdPhase"); DATestUtils.CheckColumn(tableVerifyCostCenters, 2, "IdWP"); DATestUtils.CheckColumn(tableVerifyCostCenters, 3, "IdCostCenter"); DATestUtils.CheckColumn(tableVerifyCostCenters, 4, "CostCenterName"); DATestUtils.CheckColumn(tableVerifyCostCenters, 5, "TotalHours"); DATestUtils.CheckColumn(tableVerifyCostCenters, 6, "Averate"); DATestUtils.CheckColumn(tableVerifyCostCenters, 7, "ValuedHours"); DATestUtils.CheckColumn(tableVerifyCostCenters, 8, "OtherCosts"); DATestUtils.CheckColumn(tableVerifyCostCenters, 9, "Sales"); DATestUtils.CheckColumn(tableVerifyCostCenters, 10, "NetCosts"); DATestUtils.CheckColumn(tableVerifyCostCenters, 11, "IdCurrency"); DATestUtils.CheckColumn(tableVerifyCostCenters, 12, "CurrencyCode"); DeleteInitialBudgetTest(initialBudget, dbInitialBudget); int rowCount = DeleteCostCenterTest(costCenter, dbCostCenterEntity); //Verifies that one and only one row is affected by the delete Assert.AreEqual(1, rowCount); rowCount = DeleteWorkPackageTest(workPackage, dbWorkPackageEntity); //Verifies that one and only one row is affected by the delete Assert.AreEqual(1, rowCount); //Verifies that one and only one row is affected by the delete rowCount = DeleteProjectCoreTeamMemberTest(coreTeamMembers, dbCoreteamMember); Assert.AreEqual(1, rowCount); rowCount = DeleteProjectTest(project, dbProjectEntity); //Verifies that one and only one row is affected by the delete Assert.AreEqual(1, rowCount); }