Пример #1
0
        public void Update()
        {
            //Update: Jan 2005
            //We are refreshing the dataset now. We are extracting the row versions and
            //updating the updated rows. This will keep the selected row in the view.
            //Updated: August 29, 2005
            //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
                ShipScheduleDS trips = (ShipScheduleDS)this.mTrips.GetChanges(DataRowState.Modified);
                if (trips != null && trips.ShipScheduleTable.Rows.Count > 0)
                {
                    //Update each modified trip
                    foreach (ShipScheduleDS.ShipScheduleTableRow row in trips.ShipScheduleTable.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 (isLoadNumberOrCarrierChanged(row))
                        {
                            DataSet loadNumberDS = this.mMediator.FillDataset(Lib.USP_TRIP, Lib.TBL_TRIP, new object[] { row.ScheduleDate, System.DBNull.Value, row.LoadNumber.Trim() });
                            if (loadNumberDS.Tables[0].Rows.Count > 0)
                            {
                                throw new DuplicateLoadNumberException("Duplicate load# found in ship schedule for " + loadNumberDS.Tables[0].Rows[0][1].ToString() + ".");
                            }
                        }

                        //Save trip details
                        ShipScheduleDS _trip = updateTrip(populateTrip(row));
                        try {
                            //Refresh the details of the current trip (instead of a full refresh)
                            ShipScheduleDS.ShipScheduleTableRow trip = this.mTrips.ShipScheduleTable.FindByTripID(row.TripID);
                            trip.SCDERowVersion = _trip.ShipScheduleTripTable[0].RowVersion;
                            trip.S1RowVersion   = _trip.ShipScheduleStopTable[0].RowVersion;
                            if (_trip.ShipScheduleStopTable.Rows.Count == 2)
                            {
                                trip.S2RowVersion = _trip.ShipScheduleStopTable[1].RowVersion;
                            }
                            this.mTrips.AcceptChanges();
                        }
                        catch (Exception ex) { throw new ApplicationException("Failed to partially refresh the ship schedule.", 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("Failed to update ship schedule.", ex); }
        }
Пример #2
0
        private ShipScheduleDS populateTrip(ShipScheduleDS.ShipScheduleTableRow sourceRow)
        {
            //Updated with new fields - TractorNumber and FreightAssinged
            ShipScheduleDS detailDS = new ShipScheduleDS();

            //Trip
            ShipScheduleDS.ShipScheduleTripTableRow tripRow = detailDS.ShipScheduleTripTable.NewShipScheduleTripTableRow();
            tripRow.CarrierServiceID   = sourceRow.CarrierServiceID;
            tripRow.LastUpdated        = System.DateTime.Now;
            tripRow.LoadNumber         = sourceRow.LoadNumber.Trim();
            tripRow.TractorNumber      = sourceRow.TractorNumber.Trim();
            tripRow.DriverName         = sourceRow.DriverName.Trim();
            tripRow.RowVersion         = sourceRow.SCDERowVersion;
            tripRow.ScheduledClose     = sourceRow.ScheduledClose;
            tripRow.ScheduledDeparture = sourceRow.ScheduledDeparture;
            tripRow.TrailerNumber      = sourceRow.TrailerNumber.Trim();
            tripRow.TripID             = sourceRow.TripID;
            tripRow.UserID             = Environment.UserName;
            if (!sourceRow.IsFreightAssignedNull())
            {
                tripRow.FreightAssigned = sourceRow.FreightAssigned;
            }
            if (!sourceRow.IsTrailerCompleteNull())
            {
                tripRow.TrailerComplete = sourceRow.TrailerComplete;
            }
            if (!sourceRow.IsTrailerDispatchedNull())
            {
                tripRow.TrailerDispatched = sourceRow.TrailerDispatched;
            }
            if (!sourceRow.IsPaperworkCompleteNull())
            {
                tripRow.PaperworkComplete = sourceRow.PaperworkComplete;
            }
            if (!sourceRow.IsCanceledNull())
            {
                tripRow.Canceled = sourceRow.Canceled;
            }
            detailDS.ShipScheduleTripTable.AddShipScheduleTripTableRow(tripRow);

            //Associated stops
            ShipScheduleDS.ShipScheduleStopTableRow stop1Row = detailDS.ShipScheduleStopTable.NewShipScheduleStopTableRow();
            stop1Row.LastUpdated      = System.DateTime.Now;
            stop1Row.Notes            = sourceRow.Notes;
            stop1Row.RowVersion       = sourceRow.S1RowVersion;
            stop1Row.ScheduledArrival = sourceRow.ScheduledArrival;
            stop1Row.ScheduledOFD1    = sourceRow.ScheduledOFD1;
            stop1Row.StopID           = sourceRow.StopID;
            stop1Row.UserID           = sourceRow.S1UserID;
            detailDS.ShipScheduleStopTable.AddShipScheduleStopTableRow(stop1Row);
            if (sourceRow.S2MainZone != null & sourceRow.S2MainZone.Trim() != "")
            {
                ShipScheduleDS.ShipScheduleStopTableRow stop2Row = detailDS.ShipScheduleStopTable.NewShipScheduleStopTableRow();
                stop2Row.LastUpdated      = System.DateTime.Now;
                stop2Row.Notes            = sourceRow.S2Notes;
                stop2Row.RowVersion       = sourceRow.S2RowVersion;
                stop2Row.ScheduledArrival = sourceRow.S2ScheduledArrival;
                stop2Row.ScheduledOFD1    = sourceRow.S2ScheduledOFD1;
                stop2Row.StopID           = sourceRow.S2StopID;
                stop2Row.UserID           = sourceRow.S2UserID;
                detailDS.ShipScheduleStopTable.AddShipScheduleStopTableRow(stop2Row);
            }
            return(detailDS);
        }