public void Create() { //Persist this definition try { //Validate if (this.mSortCenterID == 0) { throw new ApplicationException("Failed to create new ship schedule: must have a valid sort center ID."); } //Create a new ship schedule for this SortCenterID and ScheduleDate this.mScheduleID = ShipScheduleGateway.CreateShipSchedule(this.mSortCenterID, this.mScheduleDate, DateTime.Now, Environment.UserName); for (int i = 0; i < this.mTemplates.TemplateViewTable.Rows.Count; i++) { //Add all mandatory loads only to the new schedule if (this.mTemplates.TemplateViewTable[i].IsMandatory == 1) { ShipScheduleGateway.CreateShipScheduleTrip(this.mScheduleID, this.mTemplates.TemplateViewTable[i].TemplateID, DateTime.Now, Environment.UserName); } } Refresh(); } catch (ApplicationException aex) { throw aex; } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }
public static void RefreshSchedules() { //Update a collection of all ship schedules for single terminal try { //Clear and update ship schedules _Schedules.Clear(); DateTime dateMin = DateTime.Today.AddDays(-App.Config.ScheduleDaysBack); DateTime dateMax = DateTime.Today.AddDays(App.Config.ScheduleDaysForward); DateTime date = DateTime.Today; for (int i = 0; i < App.Config.PastBusinessDays; i++) { date = date.AddDays(-1); while (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday) { date = date.AddDays(-1); } } ShipScheduleDataset schedules = ShipScheduleGateway.GetShipSchedules(date); _Schedules.Merge(schedules.ShipScheduleTable.Select("ScheduleDate >= '" + dateMin + "' AND ScheduleDate <= '" + dateMax + "'")); } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } finally { if (SchedulesChanged != null) { SchedulesChanged(null, EventArgs.Empty); } } }
private void OnAutoRefresh(object sender, DoWorkEventArgs e) { //Event handler for background worker thread DoWork event; runs on worker thread try { ShipScheduleDataset ds = new ShipScheduleDataset(); ds.Merge(ShipScheduleGateway.GetShipSchedule(this.mSortCenterID, this.mScheduleDate)); ds.Merge(ShipScheduleGateway.GetShipScheduleTemplates(this.mSortCenterID, this.mScheduleDate)); e.Result = ds; } catch { } }
public void Update() { //Extract the row versions and update the updated rows. This will keep the selected row in the view //Checks for duplicate load number within the same carrier during the past and future 7 days try { //Determine changes made to the trips in this ship schedule ShipScheduleDataset trips = (ShipScheduleDataset)this.mTrips.GetChanges(DataRowState.Modified); if (trips != null && trips.ShipScheduleViewTable.Rows.Count > 0) { //Update each modified trip foreach (ShipScheduleDataset.ShipScheduleViewTableRow row in trips.ShipScheduleViewTable.Rows) { //Check to see if load# or carrier has changed; if so, then make sure it's unique within the same //carrier (updated once if it's updated along with load#) and during the past one week schedule if (row.LoadNumber.Trim() != row["LoadNumber", DataRowVersion.Original].ToString().Trim() && row.CarrierServiceID.ToString().Trim() == row["CarrierServiceID", DataRowVersion.Original].ToString().Trim()) { string tripID = ShipScheduleGateway.FindShipScheduleTrip(row.ScheduleDate, 0, row.LoadNumber.Trim()); if (tripID.Trim().Length > 0) { throw new DuplicateLoadNumberException("Duplicate load# found in ship schedule for " + tripID + "."); } } //Save trip details ShipScheduleGateway.UpdateShipSchedule(row); try { //Refresh the details of the current trip (instead of a full refresh) ShipScheduleDataset viewItems = ShipScheduleGateway.GetShipSchedule(row.SortCenterID, row.ScheduleDate); if (viewItems.ShipScheduleViewTable.Rows.Count > 0) { ShipScheduleDataset.ShipScheduleViewTableRow viewItem = viewItems.ShipScheduleViewTable.FindByTripID(row.TripID); ShipScheduleDataset.ShipScheduleViewTableRow trip = this.mTrips.ShipScheduleViewTable.FindByTripID(row.TripID); trip.SCDERowVersion = viewItem.SCDERowVersion; trip.S1RowVersion = viewItem.S1RowVersion; if (!row.IsS2StopIDNull()) { trip.S2RowVersion = viewItem.S2RowVersion; } this.mTrips.AcceptChanges(); } } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } } //Refresh(); Doing partial refresh above for performance reasons (i.e. cell editing) } } catch (DuplicateLoadNumberException ex) { throw ex; } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }
public void AddLoads() { //Add selected template loads to this schedule try { for (int i = 0; i < this.mTemplates.TemplateViewTable.Rows.Count; i++) { if (this.mTemplates.TemplateViewTable[i].Selected) { ShipScheduleGateway.CreateShipScheduleTrip(this.mScheduleID, this.mTemplates.TemplateViewTable[i].TemplateID, DateTime.Now, Environment.UserName); } } Refresh(); } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }
private void OnFormLoad(object sender, System.EventArgs e) { //Event handler for form load event this.Cursor = Cursors.WaitCursor; try { this.cboSortCenter.DisplayMember = "TerminalTable.Description"; this.cboSortCenter.ValueMember = "TerminalTable.ID"; this.cboSortCenter.DataSource = ShipScheduleGateway.GetSortCenters(); if (this.cboSortCenter.Items.Count > 0) { this.cboSortCenter.SelectedIndex = 0; } this.calDate.MinDate = System.DateTime.Today; OnValidateForm(null, null); } catch (Exception ex) { App.ReportError(ex, true, LogLevel.Error); } finally { this.Cursor = Cursors.Default; } }
public void Refresh() { //Update a collection (dataset) of all ship schedule trips for the terminal and schedule date try { //Clear and update trips for this schedule this.mTrips.Clear(); this.mTemplates.Clear(); this.mTrips.Merge(ShipScheduleGateway.GetShipSchedule(this.mSortCenterID, this.mScheduleDate)); this.mTemplates.Merge(ShipScheduleGateway.GetShipScheduleTemplates(this.mSortCenterID, this.mScheduleDate)); foreach (ShipScheduleDataset.TemplateViewTableRow row in this.mTemplates.TemplateViewTable.Rows) { row.Selected = (row.IsMandatory == 1); } this.mTemplates.AcceptChanges(); } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } finally { if (this.Changed != null) { this.Changed(this, EventArgs.Empty); } } }
public static ShipSchedule SchedulesArchiveItem(long sortCenterID, string sortCenter, DateTime scheduleDate) { //Return an archived ship schedule ShipSchedule schedule = null; try { // ShipScheduleDataset schedules = new ShipScheduleDataset(); schedules.Merge(ShipScheduleGateway.GetShipSchedules(scheduleDate)); if (schedules.ShipScheduleTable.Rows.Count > 0) { DataRow[] rows = schedules.ShipScheduleTable.Select("SortCenterID=" + sortCenterID + " AND ScheduleDate='" + scheduleDate + "'"); if (rows.Length > 0) { ShipScheduleDataset scheduleDS = new ShipScheduleDataset(); scheduleDS.ShipScheduleTable.AddShipScheduleTableRow("", sortCenterID, sortCenter, scheduleDate, DateTime.Now, Environment.UserName); schedule = new ShipSchedule(scheduleDS.ShipScheduleTable[0]); schedule.Changed += new EventHandler(OnShipScheduleChanged); } } } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } return(schedule); }