示例#1
0
        }       //	layoutSlots

        /**
         *  Layout Y axis
         *  @param mas assignment slot
         */
        private void LayoutY(MAssignmentSlot mas)
        {
            int timeSlotStart = GetTimeSlotIndex(mas.GetStartTime(), false);
            int timeSlotEnd   = GetTimeSlotIndex(mas.GetEndTime(), true);

            if (TimeUtil.IsAllDay(mas.GetStartTime(), mas.GetEndTime()))
            {
                timeSlotEnd = _timeSlots.Length - 1;
            }
            //
            mas.SetY(timeSlotStart, timeSlotEnd);
        }       //	layoutY
示例#2
0
        }       //	inSlot

        /*************************************************************************/

        /**
         * Compares its two arguments for order.  Returns a negative integer,
         * zero, or a positive integer as the first argument is less than, equal
         * to, or greater than the second.
         *
         * @param obj the first object to be compared.
         * @param o2 the second object to be compared.
         * @return a negative integer, zero, or a positive integer as the
         *         first argument is less than, equal to, or greater than the
         *	       second.
         * @throws ClassCastException if the arguments' types prevent them from
         *         being compared by this Comparator.
         */
        public int CompareTo(Object obj)
        {
            MAssignmentSlot slot = (MAssignmentSlot)obj;

            //	Start Date
            int result = GetStartTime().Value.CompareTo(slot.GetStartTime());

            if (result != 0)
            {
                return(result);
            }
            //	Status
            result = slot.GetStatus() - GetStatus();
            if (result != 0)
            {
                return(result);
            }
            //	End Date
            result = GetEndTime().Value.CompareTo(slot.GetEndTime());
            if (result != 0)
            {
                return(result);
            }
            //	Name
            result = GetName().CompareTo(slot.GetName());
            if (result != 0)
            {
                return(result);
            }
            //	Description
            return(GetDescription().CompareTo(slot.GetDescription()));
        }       //	compare
示例#3
0
        }       //	compare

        /**
         * Indicates whether some other object is "equal to" this
         * Comparator.
         * @param   obj   the reference object with which to compare.
         * @return  <code>true</code> only if the specified object is also
         *		a comparator and it imposes the same ordering as this
         *		comparator.
         * @see     java.lang.Object#equals(java.lang.Object)
         * @see java.lang.Object#hashCode()
         */
        public override bool Equals(Object obj)
        {
            if (obj is MAssignmentSlot)
            {
                MAssignmentSlot cmp = (MAssignmentSlot)obj;
                if (_startTime.Equals(cmp.GetStartTime()) &&
                    _endTime.Equals(cmp.GetEndTime()) &&
                    _status == cmp.GetStatus() &&
                    _name.Equals(cmp.GetName()) &&
                    _description.Equals(cmp.GetDescription()))
                {
                    return(true);
                }
            }
            return(false);
        }       //	equals
示例#4
0
        /**************************************************************************
         *  Get Assignments for timeframe.
         *  <pre>
         *      - Resource is Active and Available
         *      - Resource UnAvailability
         *      - NonBusinessDay
         *      - ResourceType Available
         *  </pre>
         *  @param S_Resource_ID resource
         *  @param start_Date start date
         *  @param end_Date optional end date, need to provide qty to calculate it
         *  @param qty optional qty in ResourceType UOM - ignored, if end date is not null
         *  @param getAll if true return all errors
         *	@param trxName transaction
         *  @return Array of existing Assigments or null - if free
         */
        //@SuppressWarnings("unchecked")
        public MAssignmentSlot[] GetAssignmentSlots(int S_Resource_ID,
                                                    DateTime?start_Date, DateTime?end_Date,
                                                    Decimal?qty, bool getAll, Trx trxName)
        {
            log.Config(start_Date.ToString());
            if (_S_Resource_ID != S_Resource_ID)
            {
                GetBaseInfo(S_Resource_ID);
            }
            //
            List <MAssignmentSlot> list = new List <MAssignmentSlot>();
            MAssignmentSlot        ma   = null;

            if (!_isAvailable)
            {
                ma = new MAssignmentSlot(EARLIEST, LATEST,
                                         Msg.GetMsg(_ctx, "ResourceNotAvailable"), "", MAssignmentSlot.STATUS_NotAvailable);
                if (!getAll)
                {
                    return new MAssignmentSlot[] { ma }
                }
                ;
                list.Add(ma);
            }

            _startDate = start_Date;
            _endDate   = end_Date;
            if (_endDate == null)
            {
                _endDate = MUOMConversion.GetEndDate(_ctx, _startDate, _C_UOM_ID, qty);
            }
            log.Fine("- EndDate=" + _endDate);


            //	Resource Unavailability -------------------------------------------
            //	log.fine( "- Unavailability -");
            String sql = "SELECT Description, DateFrom, DateTo "
                         + "FROM S_ResourceUnavailable "
                         + "WHERE S_Resource_ID=@1"                             //	#1
                         + " AND DateTo >= @2"                                  //	#2	start
                         + " AND DateFrom <= @3"                                //	#3	end
                         + " AND IsActive='Y'";

            IDataReader dr = null;

            System.Data.SqlClient.SqlParameter[] param = null;
            try
            {
                //		log.fine( sql, "ID=" + S_Resource_ID + ", Start=" + m_startDate + ", End=" + m_endDate);
                param    = new System.Data.SqlClient.SqlParameter[3];
                param[0] = new System.Data.SqlClient.SqlParameter("@1", _S_Resource_ID);
                param[1] = new System.Data.SqlClient.SqlParameter("@2", _startDate);
                param[2] = new System.Data.SqlClient.SqlParameter("@3", _endDate);
                dr       = DataBase.DB.ExecuteReader(sql, param, trxName);

                while (dr.Read())
                {
                    ma = new MAssignmentSlot(TimeUtil.GetDay(dr.GetDateTime(1)),
                                             TimeUtil.GetNextDay(dr.GetDateTime(2)), //	user entered date need to convert to not including end time
                                             Msg.GetMsg(_ctx, "ResourceUnAvailable"), dr.GetString(1),
                                             MAssignmentSlot.STATUS_UnAvailable);

                    //	log.fine( "- Unavailable", ma);
                    if (getAll)
                    {
                        CreateDaySlot(list, ma);
                    }
                    else
                    {
                        list.Add(ma);
                    }
                }
                dr.Close();
                dr    = null;
                param = null;
            }
            catch (Exception e)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                dr    = null;
                param = null;
                log.Log(Level.SEVERE, sql, e);
                ma = new MAssignmentSlot(EARLIEST, LATEST,
                                         Msg.GetMsg(_ctx, "ResourceUnAvailable"), e.ToString(),
                                         MAssignmentSlot.STATUS_UnAvailable);
            }
            if (ma != null && !getAll)
            {
                return new MAssignmentSlot[] { ma }
            }
            ;


            //	NonBusinessDay ----------------------------------------------------
            //	log.fine( "- NonBusinessDay -");
            //	"WHERE TRUNC(Date1) BETWEEN TRUNC(?) AND TRUNC(?)"   causes
            //	ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP
            sql = MRole.GetDefault(_ctx, false).AddAccessSQL(
                "SELECT Name, Date1 FROM C_NonBusinessDay "
                + "WHERE TRUNC(Date1,'DD') BETWEEN @1 AND @2",
                "C_NonBusinessDay", false, false);              // not qualified - RO
            try
            {
                DateTime?startDay = TimeUtil.GetDay(_startDate);

                DateTime?endDay = TimeUtil.GetDay(_endDate);
                //		log.fine( sql, "Start=" + startDay + ", End=" + endDay);
                param    = new System.Data.SqlClient.SqlParameter[2];
                param[0] = new System.Data.SqlClient.SqlParameter("@1", startDay);
                param[1] = new System.Data.SqlClient.SqlParameter("@2", endDay);

                dr = DataBase.DB.ExecuteReader(sql, param, trxName);
                while (dr.Read())
                {
                    ma = new MAssignmentSlot(TimeUtil.GetDay(dr.GetDateTime(1)),
                                             TimeUtil.GetNextDay(dr.GetDateTime(1)), //	user entered date need to convert to not including end time
                                             Msg.GetMsg(_ctx, "NonBusinessDay"), dr.GetString(0),
                                             MAssignmentSlot.STATUS_NonBusinessDay);
                    log.Finer("- NonBusinessDay " + ma);
                    list.Add(ma);
                }
                dr.Close();
                dr    = null;
                param = null;
            }
            catch (Exception e)
            {
                if (dr != null)
                {
                    dr.Close();
                    dr = null;
                }
                param = null;

                log.Log(Level.SEVERE, sql, e);
                ma = new MAssignmentSlot(EARLIEST, LATEST,
                                         Msg.GetMsg(_ctx, "NonBusinessDay"), e.ToString(),
                                         MAssignmentSlot.STATUS_NonBusinessDay);
            }
            if (ma != null && !getAll)
            {
                return new MAssignmentSlot[] { ma }
            }
            ;


            //	ResourceType Available --------------------------------------------
            //	log.fine( "- ResourceTypeAvailability -");
            sql = "SELECT Name, IsTimeSlot,TimeSlotStart,TimeSlotEnd, "         //	1..4
                  + "IsDateSlot,OnMonday,OnTuesday,OnWednesday,"                //	5..8
                  + "OnThursday,OnFriday,OnSaturday,OnSunday "                  //	9..12
                  + "FROM S_ResourceType "
                  + "WHERE S_ResourceType_ID=@1";
            try
            {
                param = new System.Data.SqlClient.SqlParameter[1];

                param[0] = new System.Data.SqlClient.SqlParameter("@1", _S_ResourceType_ID);

                dr = DataBase.DB.ExecuteReader(sql, param, trxName);

                if (dr.Read())
                {
                    _typeName = dr.GetString(0);
                    //	TimeSlot
                    if ("Y".Equals(dr.GetString(1)))
                    {
                        _slotStartTime = TimeUtil.GetDayTime(_startDate, dr.GetDateTime(2));
                        _slotEndTime   = TimeUtil.GetDayTime(_endDate, dr.GetDateTime(3));
                        if (TimeUtil.InRange(_startDate, _endDate, _slotStartTime, _slotEndTime))
                        {
                            ma = new MAssignmentSlot(_slotStartTime, _slotEndTime,
                                                     Msg.GetMsg(_ctx, "ResourceNotInSlotTime"), _typeName,
                                                     MAssignmentSlot.STATUS_NotInSlotTime);
                            if (getAll)
                            {
                                CreateTimeSlot(list,
                                               dr.GetDateTime(2), dr.GetDateTime(3));
                            }
                        }
                    }                   //	TimeSlot

                    //	DaySlot
                    if ("Y".Equals(dr.GetString(4)))
                    {
                        if (TimeUtil.InRange(_startDate, _endDate,
                                             "Y".Equals(dr.GetString(5)), "Y".Equals(dr.GetString(6)),                                  //	Mo..Tu
                                             "Y".Equals(dr.GetString(7)), "Y".Equals(dr.GetString(8)), "Y".Equals(dr.GetString(9)),     //  We..Fr
                                             "Y".Equals(dr.GetString(10)), "Y".Equals(dr.GetString(11))))
                        {
                            ma = new MAssignmentSlot(_startDate, _endDate,
                                                     Msg.GetMsg(_ctx, "ResourceNotInSlotDay"), _typeName,
                                                     MAssignmentSlot.STATUS_NotInSlotDay);
                            if (getAll)
                            {
                                CreateDaySlot(list,
                                              "Y".Equals(dr.GetString(5)), "Y".Equals(dr.GetString(6)),                                 //	Mo..Tu
                                              "Y".Equals(dr.GetString(7)), "Y".Equals(dr.GetString(8)), "Y".Equals(dr.GetString(9)),    //  We..Fr
                                              "Y".Equals(dr.GetString(10)), "Y".Equals(dr.GetString(11)));
                            }
                        }
                    }                   //	DaySlot
                }
                dr.Close();
                dr    = null;
                param = null;
            }
            catch (Exception e)
            {
                if (dr != null)
                {
                    dr.Close();
                    dr = null;
                }
                param = null;

                log.Log(Level.SEVERE, sql, e);
                ma = new MAssignmentSlot(EARLIEST, LATEST,
                                         Msg.GetMsg(_ctx, "ResourceNotInSlotDay"), e.ToString(),
                                         MAssignmentSlot.STATUS_NonBusinessDay);
            }
            if (ma != null && !getAll)
            {
                return new MAssignmentSlot[] { ma }
            }
            ;

            //	Assignments -------------------------------------------------------
            sql = "SELECT S_ResourceAssignment_ID "
                  + "FROM S_ResourceAssignment "
                  + "WHERE S_Resource_ID=@1"                                    //	#1
                  + " AND AssignDateTo >= @2"                                   //	#2	start
                  + " AND AssignDateFrom <= @3"                                 //	#3	end
                  + " AND IsActive='Y'";
            try
            {
                param = new System.Data.SqlClient.SqlParameter[3];

                param[0] = new System.Data.SqlClient.SqlParameter("@1", _S_Resource_ID);
                param[1] = new System.Data.SqlClient.SqlParameter("@2", _startDate);
                param[2] = new System.Data.SqlClient.SqlParameter("@3", _endDate);

                dr = DataBase.DB.ExecuteReader(sql, param, trxName);
                while (dr.Read())
                {
                    MResourceAssignment mAssignment =
                        new MResourceAssignment(_ctx, Utility.Util.GetValueOfInt(dr[0]), trxName);
                    ma = new MAssignmentSlot(mAssignment);
                    if (!getAll)
                    {
                        break;
                    }
                    list.Add(ma);
                }
                dr.Close();
                dr = null;
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, sql, e);
                ma = new MAssignmentSlot(EARLIEST, LATEST,
                                         Msg.Translate(_ctx, "S_R"), e.ToString(),
                                         MAssignmentSlot.STATUS_NotConfirmed);
            }
            if (ma != null && !getAll)
            {
                return new MAssignmentSlot[] { ma }
            }
            ;

            /*********************************************************************/

            //	fill m_timeSlots (required for layout)
            CreateTimeSlots();

            //	Clean list - date range
            List <MAssignmentSlot> clean = new List <MAssignmentSlot>(list.Count);

            for (int i = 0; i < list.Count; i++)
            {
                MAssignmentSlot mas = (MAssignmentSlot)list[i];
                if ((mas.GetStartTime().Equals(_startDate) || mas.GetStartTime() > _startDate) &&
                    (mas.GetEndTime().Equals(_endDate)) || mas.GetEndTime() < _endDate)
                {
                    clean.Add(mas);
                }
            }
            //	Delete Unavailability TimeSlots when all day assigments exist
            MAssignmentSlot[] sorted = new MAssignmentSlot[clean.Count];
            sorted = clean.ToArray();
            Array.Sort(sorted); //	sorted by start/end date
            list.Clear();       //	used as day list
            clean.Clear();      //	cleaned days
            DateTime?sortedDay = null;

            for (int i = 0; i < sorted.Length; i++)
            {
                if (sortedDay == null)
                {
                    sortedDay = TimeUtil.GetDay(sorted[i].GetStartTime());
                }
                if (sortedDay.Equals(TimeUtil.GetDay(sorted[i].GetStartTime())))
                {
                    list.Add(sorted[i]);
                }
                else
                {
                    //	process info list -> clean
                    LayoutSlots(list, clean);
                    //	prepare next
                    list.Clear();
                    list.Add(sorted[i]);
                    sortedDay = TimeUtil.GetDay(sorted[i].GetStartTime());
                }
            }
            //	process info list -> clean
            LayoutSlots(list, clean);

            //	Return
            MAssignmentSlot[] retValue = new MAssignmentSlot[clean.Count];
            retValue = clean.ToArray();
            Array.Sort(retValue); //	sorted by start/end date
            return(retValue);
        }                         //	getAssignmentSlots