Exemplo n.º 1
0
        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); }
        }