/** * Copy Phases/Tasks from other Project * @param fromProject project * @return number of items copied */ public int CopyPhasesFrom(MProject fromProject) { if (IsProcessed() || fromProject == null) { return(0); } int count = 0; int taskCount = 0; // Get Phases MProjectPhase[] myPhases = GetPhases(); MProjectPhase[] fromPhases = fromProject.GetPhases(); // Copy Phases for (int i = 0; i < fromPhases.Length; i++) { // Check if Phase already exists int C_Phase_ID = fromPhases[i].GetC_Phase_ID(); bool exists = false; if (C_Phase_ID == 0) { exists = false; } else { for (int ii = 0; ii < myPhases.Length; ii++) { if (myPhases[ii].GetC_Phase_ID() == C_Phase_ID) { exists = true; break; } } } // Phase exist if (exists) { log.Info("Phase already exists here, ignored - " + fromPhases[i]); } else { MProjectPhase toPhase = new MProjectPhase(GetCtx(), 0, Get_TrxName()); PO.CopyValues(fromPhases[i], toPhase, GetAD_Client_ID(), GetAD_Org_ID()); toPhase.SetC_Project_ID(GetC_Project_ID()); toPhase.SetC_Order_ID(0); toPhase.SetIsComplete(false); if (toPhase.Save()) { count++; taskCount += toPhase.CopyTasksFrom(fromPhases[i]); } } } if (fromPhases.Length != count) { log.Warning("Count difference - Project=" + fromPhases.Length + " <> Saved=" + count); } return(count + taskCount); }
/** * 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); }
/// <summary> /// To copy details from one project to another /// </summary> /// <param name="fromProject">From Project</param> /// <param name="toProject">To Project</param> /// <returns>No Of Lines copied</returns> public int CopyDetailsFrom(MProject fromProject, MProject toProject) { if (IsProcessed() || fromProject == null || toProject == null) { return(0); } int count = 0; ValueNamePair pp = null; StringBuilder msg = new StringBuilder(); #region create lines for project if (toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Project)) { MProjectLine[] fromLines = fromProject.GetLines(); MProjectLine line = null; for (int i = 0; i < fromLines.Length; i++) { line = new MProjectLine(GetCtx(), 0, fromProject.Get_TrxName()); PO.CopyValues(fromLines[i], line, GetAD_Client_ID(), GetAD_Org_ID()); line.SetC_Project_ID(toProject.GetC_Project_ID()); line.SetInvoicedAmt(Env.ZERO); line.SetInvoicedQty(Env.ZERO); line.SetC_OrderPO_ID(0); line.SetC_Order_ID(0); line.SetProcessed(false); if (line.Save()) { count++; } else { pp = VLogger.RetrieveError(); if (pp != null) { msg.Append(pp.GetName()); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg("", pp.GetValue())); } } if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved")); } else { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved") + "," + msg.ToString()); } } } } #endregion if (toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Phase) || toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Task) || toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_TaskLine)) { #region if project line level is Project then create lines for phase only MProjectPhase[] myPhases = GetPhases(); MProjectPhase[] fromPhases = fromProject.GetPhases(); int C_Phase_ID = 0; bool exists = false; MProjectPhase toPhase = null; MProjectLine[] fromLines = null; List <MProjectLine> list = null; // Copy Phases for (int i = 0; i < fromPhases.Length; i++) { // Check if Phase already exists C_Phase_ID = fromPhases[i].GetC_Phase_ID(); exists = false; if (C_Phase_ID == 0) { exists = false; } else { for (int ii = 0; ii < myPhases.Length; ii++) { if (myPhases[ii].GetC_Phase_ID() == C_Phase_ID) { exists = true; break; } } } // Phase exist if (exists) { log.Info("Phase already exists here, ignored - " + fromPhases[i]); } else { toPhase = new MProjectPhase(GetCtx(), 0, Get_TrxName()); PO.CopyValues(fromPhases[i], toPhase, GetAD_Client_ID(), GetAD_Org_ID()); toPhase.SetC_Project_ID(toProject.GetC_Project_ID()); toPhase.SetC_Order_ID(0); toPhase.SetIsComplete(false); if (toPhase.Save()) { count++; if (toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_Task) || toProject.GetProjectLineLevel().Equals(PROJECTLINELEVEL_TaskLine)) { toPhase.CopyTasksFrom(fromPhases[i], toPhase); } else { DataSet projDs = DB.ExecuteDataset(" SELECT C_ProjectLine_ID FROM C_ProjectLine WHERE " + " C_ProjectPhase_ID=" + fromPhases[i].GetC_ProjectPhase_ID() + " AND " + " C_Project_ID = " + fromPhases[i].GetC_Project_ID() + " ORDER BY Line "); if (projDs != null && projDs.Tables[0].Rows.Count > 0) { list = new List <MProjectLine>(); for (int k = 0; k < projDs.Tables[0].Rows.Count; k++) { list.Add(new MProjectLine(GetCtx(), Util.GetValueOfInt(projDs.Tables[0].Rows[k]["C_ProjectLine_ID"]), Get_TrxName())); } fromLines = new MProjectLine[list.Count]; fromLines = list.ToArray(); } if (fromLines != null && fromLines.Length > 0) { MProjectLine line = null; for (int j = 0; j < fromLines.Length; j++) { line = new MProjectLine(GetCtx(), 0, fromProject.Get_TrxName()); PO.CopyValues(fromLines[j], line, GetAD_Client_ID(), GetAD_Org_ID()); line.SetC_Project_ID(toProject.GetC_Project_ID()); line.SetC_ProjectPhase_ID(toPhase.GetC_ProjectPhase_ID()); line.SetInvoicedAmt(Env.ZERO); line.SetInvoicedQty(Env.ZERO); line.SetC_OrderPO_ID(0); line.SetC_Order_ID(0); line.SetProcessed(false); if (line.Save()) { count++; } else { pp = VLogger.RetrieveError(); if (pp != null) { msg.Append(pp.GetName()); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg("", pp.GetValue())); } } if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved")); } else { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved") + "," + msg.ToString()); } } } } } } else { pp = VLogger.RetrieveError(); if (pp != null) { msg.Append(pp.GetName()); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg("", pp.GetValue())); } } if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved")); } else { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved") + "," + msg.ToString()); } } } } #endregion } // count = CopyLinesFrom(fromProject) //+ CopyPhasesFrom(fromProject); return(count); }