Exemple #1
0
 public TripWaypointLite(TripWaypoint wpt)
 {
     RowID        = wpt.RowID;
     WaypointType = wpt.WaypointType;
     SetNumber    = wpt.SetNumber;
     Waypoint     = wpt.Waypoint;
     TripID       = wpt.Trip.TripID;
 }
Exemple #2
0
        public bool AddRecordToRepo(TripWaypoint tw)
        {
            if (tw == null)
            {
                throw new ArgumentNullException("Error: The argument is Null");
            }

            TripWaypointCollection.Add(tw);

            return(_operationSucceeded);
        }
Exemple #3
0
 public TripWaypoint GetTripWaypoint(TripWaypoint tpw)
 {
     if (tpw.WaypointName.Length == 0)
     {
         return(null);
     }
     else
     {
         return(TripWaypointCollection
                .Where(t => t.Trip.GPS.DeviceID == tpw.Trip.GPS.DeviceID &&
                       t.Trip.TripID == tpw.Trip.TripID &&
                       t.WaypointName == tpw.WaypointName).FirstOrDefault());
     }
 }
Exemple #4
0
        public EntityValidationResult ValidateTripWaypoint(TripWaypoint tw, bool isNew, Waypoint oldWaypoint = null)
        {
            EntityValidationResult evr = new EntityValidationResult();

            if (tw.WaypointName == null || tw.WaypointName.Length < 1)
            {
                evr.AddMessage("Waypoint name must be at least 1 character long");
            }

            if (tw.TimeStamp == null)
            {
                evr.AddMessage("Waypoint timestamp cannot be emppty");
            }
            else
            {
                var wptAdjustedTime = ((DateTime)tw.TimeStamp).AddHours(Global.Settings.HoursOffsetGMT);
                if (wptAdjustedTime <= tw.Trip.DateTimeDeparture || wptAdjustedTime >= tw.Trip.DateTimeArrival)
                {
                    evr.AddMessage("Waypoint timestamp must be within departure and arrival time of trip");
                }
            }

            if (tw.WaypointType == null || tw.WaypointType != "Set" && tw.WaypointType != "Haul")
            {
                evr.AddMessage("Waypoint type is not valid");
            }

            if (tw.SetNumber == 0)
            {
                evr.AddMessage("Set number is not valid");
            }

            if (!isNew && oldWaypoint != null && tw.Waypoint.Name != oldWaypoint.Name)
            {
                if (GetTripWaypoint(tw) != null)
                {
                    evr.AddMessage("Waypoint already in use");
                }
            }

            if (isNew && GetTripWaypoint(tw) != null)
            {
                evr.AddMessage("Waypoint already in use");
            }



            return(evr);
        }
        private List <TripWaypoint> getTripWaypoints()
        {
            List <TripWaypoint> thisList = new List <TripWaypoint>();
            var dt = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $"Select * from trip_waypoints";

                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        thisList.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            DateTime     timestamp = (DateTime)dr["TimeStamp"];
                            TripWaypoint t         = new TripWaypoint
                            {
                                Trip                = Entities.TripViewModel.GetTrip(int.Parse(dr["TripID"].ToString())),
                                RowID               = int.Parse(dr["RowID"].ToString()),
                                WaypointName        = dr["WaypointName"].ToString(),
                                SetNumber           = int.Parse(dr["SetNumber"].ToString()),
                                TimeStamp           = timestamp.AddHours(-1 * Global.Settings.HoursOffsetGMT),
                                WaypointType        = dr["WaypointType"].ToString(),
                                WaypointGPXFileName = dr["WaypointGPXFileName"].ToString(),
                                Waypoint            = new Waypoint
                                {
                                    Latitude  = double.Parse(dr["Latitude"].ToString()),
                                    Longitude = double.Parse(dr["Longitude"].ToString()),
                                    Time      = timestamp
                                }
                            };
                            thisList.Add(t);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
                return(thisList);
            }
        }
Exemple #6
0
        public EntityValidationResult ValidateTrip(TripWaypoint tw, bool isNew, Waypoint oldWaypoint = null)
        {
            EntityValidationResult evr = new EntityValidationResult();

            if (tw.WaypointName == null || tw.WaypointName.Length < 1)
            {
                evr.AddMessage("Waypoint name must be at least 1 character long");
            }

            if (tw.TimeStamp <= tw.Trip.DateTimeDeparture || tw.TimeStamp >= tw.Trip.DateTimeArrival)
            {
                evr.AddMessage("Waypoint timestamp must be within departure and arrival time of trip");
            }

            if (tw.WaypointType == null || tw.WaypointType.Length < 3)
            {
                evr.AddMessage("Waypoint type is not valid");
            }

            if (tw.SetNumber == 0)
            {
                evr.AddMessage("Set number is not valid");
            }

            if (!isNew && tw.Waypoint.Name != oldWaypoint.Name)
            {
                if (GetTripWaypoint(tw) != null)
                {
                    evr.AddMessage("Waypoint already in use");
                }
            }

            if (isNew && GetTripWaypoint(tw) != null)
            {
                evr.AddMessage("Waypoint already in use");
            }



            return(evr);
        }
Exemple #7
0
        public bool UpdateRecordInRepo(TripWaypoint tw)
        {
            if (tw.RowID == 0)
            {
                throw new Exception("Error: ID cannot be null");
            }

            int index = 0;

            while (index < TripWaypointCollection.Count)
            {
                if (TripWaypointCollection[index].RowID == tw.RowID)
                {
                    TripWaypointCollection[index] = tw;
                    break;
                }
                index++;
            }

            return(_operationSucceeded);
        }
        public bool Update(TripWaypoint t)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Update trip_waypoints set
                                TripID = {t.Trip.TripID},
                                WaypointName = '{t.WaypointName}',
                                WaypointType = '{t.WaypointType}',
                                [TimeStamp] = '{t.TimeStampAdjusted}',
                                SetNumber = {t.SetNumber},
                                Longitude = {t.Waypoint.Longitude},
                                Latitude = {t.Waypoint.Latitude},
                                WaypointGPXFileName = '{t.WaypointGPXFileName}'
                            WHERE RowID = {t.RowID}";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Exemple #9
0
 public TripWaypoint GetTripWaypoint(TripWaypoint tpw)
 {
     return(TripWaypointCollection
            .Where(t => t.Trip.GPS.DeviceID == tpw.Trip.GPS.DeviceID)
            .Where(t => t.WaypointName == tpw.WaypointName).FirstOrDefault());
 }