public static void RefreshSchedules() { //Update a collection (dataset) of all ship schedules for all terminals try { //Clear and update ship schedules _Schedules.Clear(); DateTime date = DateTime.Today; for (int i = 0; i < ShipScheduleFactory.PastBusinessDays; i++) { date = date.AddDays(-1); while (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday) { date = date.AddDays(-1); } } DataSet ds = Mediator.FillDataset(Lib.USP_SCHEDULES, Lib.TBL_SCHEDULES, new object[] { date }); if (ds.Tables[Lib.TBL_SCHEDULES].Rows.Count > 0) { //Filter out old schedules DateTime dateMin = DateTime.Today.AddDays(-ShipScheduleFactory.ScheduleDaysBack); DateTime dateMax = DateTime.Today.AddDays(ShipScheduleFactory.ScheduleDaysForward); //NOTE: Following statement not working since ported- replaced with next 3 lines //_Schedules.Merge(ds.Tables[Lib.TBL_SCHEDULES].Select("ScheduleDate >= '" + dateMin + "'"), true, MissingSchemaAction.Ignore); DataSet _ds = new DataSet(); _ds.Merge(ds.Tables[Lib.TBL_SCHEDULES].Select("ScheduleDate >= '" + dateMin + "' AND ScheduleDate <= '" + dateMax + "'")); _Schedules.Merge(_ds); } } catch (Exception ex) { throw new ApplicationException("Failed to refresh ship schedule list.", ex); } finally { if (SchedulesChanged != null) { SchedulesChanged(null, EventArgs.Empty); } } }
public static void RefreshTrips() { //Update a collection (dataset) of all ship schedule trips for the terminal on the local LAN database try { //Clear and update cached trips/stops for current schedule date _ScheduleID = ""; _Trips.Clear(); DataSet trips = new DataSet(); string filter1 = _AgentTerminalID > 0 ? "AgentTerminalID=" + _AgentTerminalID + " OR S2AgentTerminalID=" + _AgentTerminalID : ""; string filter2 = _AgentTerminalID > 0 ? "AgentTerminalID=" + _AgentTerminalID : ""; DataSet ds = App.Mediator.FillDataset(USP_SHIPSCHEDULE_SCHEDULE, TBL_SHIPSCHEDULE_SCHEDULE, new object[] { _ScheduleDate }); if (ds.Tables[TBL_SHIPSCHEDULE_SCHEDULE].Rows.Count > 0) { //Capture scheduleID; then merge in trips- filter as required _ScheduleID = ds.Tables[TBL_SHIPSCHEDULE_SCHEDULE].Rows[0]["ScheduleID"].ToString(); if (filter1.Length > 0) { trips.Merge(ds.Tables[TBL_SHIPSCHEDULE_SCHEDULE].Select(filter1)); } else { trips.Merge(ds); } if (trips.Tables[TBL_SHIPSCHEDULE_SCHEDULE] != null && trips.Tables[TBL_SHIPSCHEDULE_SCHEDULE].Rows.Count > 0) { //Merge in stops- filter as required ds = App.Mediator.FillDataset(USP_SHIPSCHEDULE_FREIGHT, TBL_SHIPSCHEDULE_FREIGHT, new object[] { _ScheduleID }); if (ds.Tables[TBL_SHIPSCHEDULE_FREIGHT].Rows.Count > 0) { if (filter2.Length > 0) { trips.Merge(ds.Tables[TBL_SHIPSCHEDULE_FREIGHT].Select(filter2)); } else { trips.Merge(ds); } } } } _Trips.Merge(trips); } catch (ConstraintException ex) { throw new ApplicationException("Failed to refresh ship schedule- constraint exception.", ex); } catch (Exception ex) { throw new ApplicationException("Failed to refresh ship schedule.", ex); } finally { if (Changed != null) { Changed(null, EventArgs.Empty); } } }