} // beforeSave /// <summary> /// After Save /// </summary> /// <param name="newRecord">new</param> /// <param name="success">success</param> /// <returns> success</returns> protected override Boolean AfterSave(Boolean newRecord, Boolean success) { if (success) { UpdateHeader(); if (newRecord || Is_ValueChanged("S_ResourceAssignment_ID")) { int S_ResourceAssignment_ID = GetS_ResourceAssignment_ID(); int old_S_ResourceAssignment_ID = 0; if (!newRecord) { Object ii = Get_ValueOld("S_ResourceAssignment_ID"); //if (ii instanceof Integer) if (ii is int) { //old_S_ResourceAssignment_ID = ((Integer)ii).intValue(); old_S_ResourceAssignment_ID = Util.GetValueOfInt((int)ii); // Changed Assignment if (old_S_ResourceAssignment_ID != S_ResourceAssignment_ID && old_S_ResourceAssignment_ID != 0) { MResourceAssignment ra = new MResourceAssignment(GetCtx(), old_S_ResourceAssignment_ID, Get_TrxName()); ra.Delete(false); } } } // Sync Assignment if (S_ResourceAssignment_ID != 0) { MResourceAssignment ra = new MResourceAssignment(GetCtx(), S_ResourceAssignment_ID, Get_TrxName()); if (GetQty().CompareTo(ra.GetQty()) != 0) { ra.SetQty(GetQty()); if (GetDescription() != null && GetDescription().Length > 0) { ra.SetDescription(GetDescription()); } ra.Save(); } } } } return(success); } // afterSave
/*************************************************************************/ /** * Set Assignment * @param assignment MAssignment */ public void SetMAssignment(MResourceAssignment assignment) { if (assignment == null) { return; } if (!IsAssignment()) { throw new ArgumentException("Assignment Slot not an Assignment"); } // _mAssignment = assignment; SetStartTime(_mAssignment.GetAssignDateFrom()); SetEndTime(_mAssignment.GetAssignDateTo()); SetName(_mAssignment.GetName()); SetDescription(_mAssignment.GetDescription()); SetStatus(_mAssignment.IsConfirmed() ? STATUS_Confirmed : STATUS_NotConfirmed); } // setMAssignment
} // afterSave /// <summary> /// After Delete /// </summary> /// <param name="success">success</param> /// <returns>success</returns> protected override Boolean AfterDelete(Boolean success) { if (success) { UpdateHeader(); // Object ii = Get_ValueOld("S_ResourceAssignment_ID"); if (ii is int) { int old_S_ResourceAssignment_ID = Util.GetValueOfInt((int)ii); // Deleted Assignment if (old_S_ResourceAssignment_ID != 0) { MResourceAssignment ra = new MResourceAssignment(GetCtx(), old_S_ResourceAssignment_ID, Get_TrxName()); ra.Delete(false); } } } return(success); } // afterDelete
} // MAssignmentSlot /** * Assignment Constructor * @param assignment MAssignment */ public MAssignmentSlot(MResourceAssignment assignment) { SetStatus(assignment.IsConfirmed() ? STATUS_Confirmed : STATUS_NotConfirmed); SetMAssignment(assignment); // log.fine( toString()); } // MAssignmentSlot
/************************************************************************** * 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