/** * Set Project Type and Category. * If Service Project copy Projet Type Phase/Tasks * @param type project type */ public void SetProjectType(MProjectType type) { if (type == null) { return; } SetC_ProjectType_ID(type.GetC_ProjectType_ID()); SetProjectCategory(type.GetProjectCategory()); //vikas Mantis Issue 0000529 5 dec 2014 // if (PROJECTCATEGORY_ServiceChargeProject.Equals(GetProjectCategory())) CopyPhasesFrom(type); }
/** * Set Project Type and Category. * If Service Project copy Projet Type Phase/Tasks * @param type project type */ public void SetProjectType(MProjectType type) { if (type == null) { return; } SetC_ProjectType_ID(type.GetC_ProjectType_ID()); SetProjectCategory(type.GetProjectCategory()); if (PROJECTCATEGORY_ServiceChargeProject.Equals(GetProjectCategory())) { CopyPhasesFrom(type); } }
/// <summary> /// Get MProjectType from Cache /// </summary> /// <param name="ctx">context</param> /// <param name="C_ProjectType_ID">id</param> /// <returns>MProjectType</returns> public static MProjectType Get(Ctx ctx, int C_ProjectType_ID) { int key = C_ProjectType_ID; MProjectType retValue = (MProjectType)_cache[key]; if (retValue != null) { return(retValue); } retValue = new MProjectType(ctx, C_ProjectType_ID, null); if (retValue.Get_ID() != 0) { _cache.Add(key, retValue); } return(retValue); }
/** * Copy Phases from Type * @param type Project Type * @return count */ public int CopyPhasesFrom(MProjectType type) { // create phases int count = 0; int taskCount = 0; MProjectTypePhase[] typePhases = type.GetPhases(); for (int i = 0; i < typePhases.Length; i++) { MProjectPhase toPhase = new MProjectPhase(this, typePhases[i]); if (toPhase.Save()) { count++; taskCount += toPhase.CopyTasksFrom(typePhases[i]); } } log.Fine("#" + count + "/" + taskCount + " - " + type); if (typePhases.Length != count) { log.Log(Level.SEVERE, "Count difference - Type=" + typePhases.Length + " <> Saved=" + count); } return(count); }
/** * Update/save Goals with Projects * @return true if updated */ private Boolean UpdateProjects() { if (!MEASURETYPE_Project.Equals(GetMeasureType()) || GetC_ProjectType_ID() == 0) { return(false); } MGoal[] goals = MGoal.GetMeasureGoals(GetCtx(), GetPA_Measure_ID()); for (int i = 0; i < goals.Length; i++) { MGoal goal = goals[i]; // Find Role MRole role = null; if (goal.GetAD_Role_ID() != 0) { role = MRole.Get(GetCtx(), goal.GetAD_Role_ID()); } else if (goal.GetAD_User_ID() != 0) { MUser user = MUser.Get(GetCtx(), goal.GetAD_User_ID()); MRole[] roles = user.GetRoles(goal.GetAD_Org_ID()); if (roles.Length > 0) { role = roles[0]; } } if (role == null) { role = MRole.GetDefault(GetCtx(), false); // could result in wrong data } // Decimal? ManualActual = null; MProjectType pt = MProjectType.Get(GetCtx(), GetC_ProjectType_ID()); String sql = pt.GetSqlPI(goal.GetRestrictions(false), goal.GetMeasureScope(), GetMeasureDataType(), null, role); IDataReader idr = null; try // SQL statement could be wrong { idr = DataBase.DB.ExecuteReader(sql, null, null); if (idr.Read()) { ManualActual = Utility.Util.GetValueOfDecimal(idr[0]); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } // SQL may return no rows or null if (ManualActual == null) { ManualActual = Env.ZERO; log.Fine("No Value = " + sql); } goal.SetMeasureActual(ManualActual); goal.Save(); } return(true); }