/**
         *  Copy Lines From other Project
         *	@param project project
         *	@return number of lines copied
         */
        public int CopyLinesFrom(MProject project)
        {
            if (IsProcessed() || project == null)
            {
                return(0);
            }
            int count = 0;

            MProjectLine[] fromLines = project.GetLines();
            for (int i = 0; i < fromLines.Length; i++)
            {
                MProjectLine line = new MProjectLine(GetCtx(), 0, project.Get_TrxName());
                PO.CopyValues(fromLines[i], line, GetAD_Client_ID(), GetAD_Org_ID());
                line.SetC_Project_ID(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++;
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Lines difference - Project=" + fromLines.Length + " <> Saved=" + count);
            }

            return(count);
        }
Exemplo n.º 2
0
        /// <summary>
        /// To copy the task lines from project template Standard Task lines tab
        /// </summary>
        /// <param name="Task_ID">ID of tasks</param>
        /// <param name="C_ProjectTask_ID">Project task ID</param>
        /// <returns>No of lines created</returns>
        public int CopyMTaskLines(int Task_ID, int C_ProjectTask_ID)
        {
            MProjectLine  taskline      = null;
            ValueNamePair pp            = null;
            int           tasklinecount = 0;
            StringBuilder msg           = new StringBuilder();
            String        sql           = "SELECT M_Product_ID, Description, StandardQty, SeqNo FROM C_TaskLine WHERE IsActive='Y' AND C_Task_ID =" + Task_ID + " ORDER BY SeqNo";

            try
            {
                DataSet ds = DataBase.DB.ExecuteDataset(sql, null, Get_TrxName());
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        taskline = new MProjectLine(GetCtx(), 0, Get_TrxName());
                        taskline.SetC_ProjectTask_ID(C_ProjectTask_ID);
                        taskline.SetDescription(Util.GetValueOfString(ds.Tables[0].Rows[i]["Description"]));
                        taskline.SetM_Product_ID(Util.GetValueOfInt(ds.Tables[0].Rows[i]["M_Product_ID"]));
                        taskline.SetPlannedQty(Util.GetValueOfDecimal(ds.Tables[0].Rows[i]["StandardQty"]));
                        taskline.Set_ValueNoCheck("TaskLineNo", Util.GetValueOfInt(ds.Tables[0].Rows[i]["SeqNo"]));
                        if (taskline.Save())
                        {
                            tasklinecount++;
                        }
                        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_TaskLineNotSaved"));
                            }
                            else
                            {
                                msg.Append(Msg.GetMsg(GetCtx(), "VIS_TaskLineNotSaved") + "," + msg.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, sql, ex);
            }
            //
            return(tasklinecount);
        }
        /**************************************************************************
         *  Get Project Lines
         *	@return Array of lines
         */
        public MProjectLine[] GetLines()
        {
            List <MProjectLine> list = new List <MProjectLine>();
            String      sql          = "SELECT * FROM C_ProjectLine WHERE C_Project_ID=" + GetC_Project_ID() + " ORDER BY Line";
            DataTable   dt           = null;
            IDataReader idr          = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, Get_TrxName());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MProjectLine(GetCtx(), dr, Get_TrxName()));
                }
            }
            catch (Exception ex)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, ex);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }

            MProjectLine[] retValue = new MProjectLine[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
        /// <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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// To copy the task lines from project template Standard Task lines tab
        /// </summary>
        /// <param name="Task_ID">ID of tasks</param>
        /// <param name="C_ProjectTask_ID">Project task ID</param>
        /// <returns>No of lines created</returns>
        public int CopyMTaskLinesFromProjectTask(MProjectTask fromTask, MProjectTask toTask, int To_Project_ID)
        {
            ValueNamePair pp            = null;
            int           tasklinecount = 0;
            StringBuilder msg           = new StringBuilder();

            try
            {
                MProjectLine[]      fromLines = null;
                List <MProjectLine> list      = new List <MProjectLine>();

                DataSet projDs = DB.ExecuteDataset(" SELECT C_ProjectLine_ID FROM C_ProjectLine WHERE " +
                                                   " C_ProjectPhase_ID =" + fromTask.GetC_ProjectPhase_ID() + " AND C_ProjectTask_ID =" + fromTask.GetC_ProjectTask_ID() +
                                                   " AND IsActive='Y' ORDER BY Line ");

                if (projDs != null && projDs.Tables[0].Rows.Count > 0)
                {
                    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)
                {
                    for (int j = 0; j < fromLines.Length; j++)
                    {
                        MProjectLine line = new MProjectLine(GetCtx(), 0, Get_TrxName());
                        PO.CopyValues(fromLines[j], line, GetAD_Client_ID(), GetAD_Org_ID());
                        line.SetC_Project_ID(To_Project_ID);
                        line.SetC_ProjectTask_ID(toTask.GetC_ProjectTask_ID());
                        line.SetC_ProjectPhase_ID(toTask.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())
                        {
                            tasklinecount++;
                        }
                        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());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, "", ex);
            }
            //
            return(tasklinecount);
        }