private List <LineStation> TableToList(DataTable dt)
        {
            List <LineStation> result = new List <LineStation>();

            if (dt == null || dt.Rows.Count == 0)
            {
                return(result);
            }
            LineStation model;

            foreach (DataRow dr in dt.Rows)
            {
                model = new LineStation
                {
                    UDID         = Convert.ToInt32(dr["线路上下行id"]),
                    stationIndex = Convert.ToInt32(dr["顺序"]),
                    stationId    = Convert.ToInt32(dr["站点id"]),
                    stationName  = ConstInfo.filterStr(dr["名称"].ToString()),
                    gpsX         = dr["gpsx2"].ToString(),
                    gpsY         = dr["gpsy2"].ToString(),
                    isVirtual    = Convert.ToInt32(dr["realStation"])
                };
                result.Add(model);
            }
            return(result);
        }
        /// <summary>
        /// add new lineStation to database
        /// </summary>
        /// <param name="lineStation"></param>
        public void CreateLineStation(LineStation lineStation)
        {
            List <LineStation> LineStationList = XMLTools.LoadListFromXMLSerializer <LineStation>(lineStationsPath);

            LineStationList.Add(lineStation);
            XMLTools.SaveListToXMLSerializer(LineStationList, lineStationsPath);
        }
Beispiel #3
0
        void IDAL.AddLineStation(LineStation lineStation)
        {
            if (!DataSource.BusLines.Exists(BusLine => BusLine.BusLineID1 == lineStation.BusLineID2 && BusLine.IsAvailable1))
            {
                throw new ExceptionDl("The line not exist in the compny");
            }
            if (!DataSource.BusStations.Exists(station1 => station1.StationNumber == lineStation.StationNumberOnLine && station1.IsAvailable3))
            {
                throw new ExceptionDl("The Station not exist in the compny");
            }

            if (DataSource.LineStations.Exists(lineStation1 => lineStation1.BusLineID2 == lineStation.BusLineID2))
            {
                LineStation lineStation1 = DataSource.LineStations.FirstOrDefault(lineStation1 => lineStation1.BusLineID2 == lineStation.BusLineID2 && lineStation1.StationNumberOnLine == lineStation.StationNumberOnLine && lineStation1.ChackDelete2);
                if (lineStation1 != null)
                {
                    throw new ExceptionDl("the Station alrady exist in the this line!!!");
                }
                else
                {
                    DataSource.LineStations.Add(lineStation.Clone());
                }
            }
            else
            {
                DataSource.LineStations.Add(lineStation.Clone());
            }
        }
Beispiel #4
0
        public void DeleteLineStation(LineStation lineStation)
        {
            var lineStationToDelete = DataSource.ListLineStations.Where(t => t.LineId == lineStation.LineId &&
                                                                        t.StationKey == lineStation.StationKey).FirstOrDefault();

            DataSource.ListLineStations.Remove(lineStationToDelete);
        }
Beispiel #5
0
        public void UpdateLineStation(LineStation station, Action <LineStation> update)
        {
            LineStation tempStat = DataSource.ListLineStations.FirstOrDefault(s => s.LineId == station.LineId &&
                                                                              s.StationKey == station.StationKey);

            update(tempStat);
        }
        // POST: api/LineStations
        //[ResponseType(typeof(LineStation))]
        public IHttpActionResult PostLineStation(Line lineStations)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <LineStation> lineStation = new List <LineStation>();

            for (int i = 0; i < lineStations.ListOfStations.Count; i++)
            {
                LineStation l = new LineStation();
                l.OrdinalNumber = i;
                l.StationId     = lineStations.ListOfStations[i].Id;
                l.LineId        = lineStations.Id;
            }

            foreach (var item in lineStation)
            {
                _unitOfWork.LineStations.Add(item);
                _unitOfWork.Complete();
            }


            return(Ok());

            //return CreatedAtRoute("DefaultApi", new { id = lineStation.Id }, lineStation);
        }
Beispiel #7
0
        void IDAL.AddLineStation(LineStation lineStation)
        {
            if (DataSource.BusStations.Exists(station1 => station1.StationNumber == lineStation.StationNumberOnLine && !station1.IsAvailable3))
            {
                throw new ExceptionLineStation(lineStation.BusLineID2, lineStation.StationNumberOnLine, "The Station not exist in the compny");
            }

            if (DataSource.LineStations.Exists(lineStation1 => lineStation1.BusLineID2 == lineStation.BusLineID2 && lineStation1.StationNumberOnLine == lineStation.StationNumberOnLine && lineStation1.ChackDelete2))
            {
                throw new ExceptionLineStation(lineStation.BusLineID2, lineStation.StationNumberOnLine, "the Station line alrady exist in the this line!!!");
            }
            else
            {
                DataSource.LineStations.Add(lineStation.Clone());
            }

            //if (!DataSource.LineStations.Exists(item => item.BusLineID2 == lineStation.BusLineID2))
            //{
            //}

            //else
            //{
            //    int index1 = DataSource.LineStations.FindIndex(item => item.BusLineID2 == lineStation.BusLineID2 && lineStation.LocationNumberOnLine == item.LocationNumberOnLine);
            //    foreach (LineStation item1 in DataSource.LineStations.Where(item => item.BusLineID2 == lineStation.BusLineID2 && item.LocationNumberOnLine >= lineStation.LocationNumberOnLine))
            //    {
            //        ++item1.LocationNumberOnLine;
            //    }
            //    DataSource.LineStations.Add(lineStation.Clone());
            //}
        }
Beispiel #8
0
 public void AddLineStation(LineStation lineStation)
 {
     if (DataSource.ListLineStations.FirstOrDefault(s => (s.LineId == lineStation.LineId &&
                                                          s.StationKey == lineStation.StationKey)) != null)
     {
         throw new ArgumentException("Duplicate Stations");
     }
     DataSource.ListLineStations.Add(lineStation);
 }
Beispiel #9
0
        public LineStation GetLineStation(int lineId, int stationKey)
        {
            LineStation lsToReturn = DataSource.ListLineStations.FirstOrDefault(s => s.LineId == lineId && s.StationKey == stationKey);

            if (lsToReturn == null)
            {
                return(null);
            }
            return(lsToReturn.Clone());
        }
        public void DeleteLineStation(int lineId, int station)//IDL function
        {
            LineStation cur = DataSource.LineStations.FirstOrDefault(curLineStation => curLineStation.LineId == lineId && curLineStation.Station == station && !curLineStation.Deleted);

            if (cur == null)
            {
                throw new LineStationExceptions(lineId, station, false);
            }
            cur.Deleted = true;
        }
        public IHttpActionResult GetLineStation(int id)
        {
            LineStation lineStation = _unitOfWork.LineStations.Get(id);

            if (lineStation == null)
            {
                return(NotFound());
            }

            return(Ok(lineStation));
        }
Beispiel #12
0
 public void DeleteLineStation(LineStation lineStation)
 {
     if (lineStation.Code != null)
     {
         DataSource.Line_StationList.Remove(lineStation);
     }
     else
     {
         throw new Exception("lineStation doesn't exist!!");
     }
 }
        public async Task AddStationToLine(Station s, Line l)
        {
            var ls = new LineStation
            {
                Line    = l,
                Station = s
            };

            _context.LineStation.Add(ls);
            await _context.SaveChangesAsync();
        }
 public void AddLineStation(LineStation lineStation)//IDL function
 {
     if (DataSource.LineStations.FirstOrDefault(curLineStation => curLineStation.LineId == lineStation.LineId && curLineStation.Station == lineStation.Station && !curLineStation.Deleted) != null)
     {
         throw new LineStationExceptions(lineStation.LineId, lineStation.Station, true);
     }
     else
     {
         DataSource.LineStations.Add(lineStation.Clone());
     }
 }
        public void UpdateLineStation(LineStation newLineStation)//IDL function
        {
            LineStation cur = DataSource.LineStations.FirstOrDefault(curLineStation => curLineStation.LineId == newLineStation.LineId && curLineStation.Station == newLineStation.Station && !curLineStation.Deleted);

            if (cur == null)
            {
                throw new LineStationExceptions(newLineStation.LineId, newLineStation.Station, false);
            }
            DataSource.LineStations.Remove(cur);
            DataSource.LineStations.Add(newLineStation);
        }
        public ActionResult AddLineStation(int id)
        {
            if (!isAuthenticated())
            {
                return(RedirectToAction("Index", "Auth"));
            }

            ViewBag.LineId = id;
            LineStation lineStation = new LineStation();

            return(View(lineStation));
        }
        public static LineStation ReturnNewLineStationDoFromBo(StationLineBO func1)
        {
            LineStation lineStation = new LineStation
            {
                BusLineID2           = func1.BusLineID2,
                StationNumberOnLine  = func1.StationNumberOnLine,
                LocationNumberOnLine = func1.LocationNumberOnLine,
                ChackDelete2         = func1.ChackDelete2
            };

            return(lineStation);
        }
        public LineStation GetLineStation(int lineId, int station)//IDL function
        {
            LineStation retValue = DataSource.LineStations.FirstOrDefault(curLineStation => curLineStation.LineId == lineId && curLineStation.Station == station && !curLineStation.Deleted);

            if (retValue != null)
            {
                return(retValue.Clone());
            }
            else
            {
                throw new LineStationExceptions(lineId, station, false);
            }
        }
        /// <summary>
        /// helper function to get a linestation
        /// </summary>
        /// <param name="lineId"></param>
        /// <param name="code"></param>
        /// <param name="numberInLine"></param>
        /// <returns></returns>
        public LineStation GetLineStation(long lineId, long code, long numberInLine)
        {
            LineStation t = DataSource.LineStationList.Find(lineStation => lineStation.Code == code && lineStation.LineId == lineId);

            if (t == null)
            {
                throw new Exception("no such line!!");
            }
            if (!t.Valid)
            {
                throw new Exception("line is not valid!!");
            }
            return(t);
        }
Beispiel #20
0
        public void UpdateLineStation(LineStation lineStation)
        {
            int indLine;

            if (lineStation.Code != null)
            {
                indLine = DataSource.Line_StationList.FindIndex(l => l.Code == lineStation.Code);
                DataSource.Line_StationList[indLine] = lineStation;
            }
            else
            {
                throw new Exception("lineStation doesn't exist!!");
            }
        }
        /// <summary>
        /// request a LineStation according to a predicate
        /// </summary>
        /// <param name="pr"></param>
        /// <returns></returns>
        public LineStation RequestLineStation(Predicate <LineStation> pr = null)
        {
            LineStation ret = DataSource.LineStationList.Find(line => pr(line));

            if (ret == null)
            {
                throw new Exception("no line that meets these conditions!");
            }
            if (ret == null)
            {
                throw new Exception("line that meets these conditions is not valid");
            }
            return(ret.GetPropertiesFrom <LineStation, LineStation>());
        }
Beispiel #22
0
        public TimeSpan CalculateDistance(LineTrip trip)
        {
            double      totalDist = 0;
            int         ID = GetLine(trip.LineIdTrip).Id;
            BusLine     line = GetLine(trip.LineIdTrip);
            LineStation stop1, stop2 = GetLineStation(ID, line.FirstStationKey);

            for (int i = 2; i <= GetLineStation(ID, trip.StationKey).RankInLine; i++)
            {
                stop1      = stop2;
                stop2      = GetLineStation(ID, GetAllLineStationsBy(s => s.LineId == ID && s.RankInLine == i).First().StationKey);
                totalDist += GetFollowingStations(GetStation(stop1.StationKey), GetStation(stop2.StationKey)).AverageJourneyTime;
            }
            return(TimeSpan.FromMinutes(totalDist));
        }
Beispiel #23
0
        public void UpdateLineStation(LineStation station)
        {
            LineStation tempStat = DataSource.ListLineStations.FirstOrDefault(s => s.LineId == station.LineId &&
                                                                              s.StationKey == station.StationKey);

            if (tempStat != null)
            {
                DataSource.ListLineStations.Remove(tempStat);
                DataSource.ListLineStations.Add(station);
            }
            else
            {
                throw new ArgumentException("line station doesn't exist");
            }
        }
Beispiel #24
0
        /// <summary>
        /// 添加线路站点
        /// </summary>
        /// <param name="station">线路站点</param>
        /// <returns>是否成功</returns>
        public bool AddStation(LineStation station)
        {
            string sql = "insert into linestation(no,name,stationName,lng,lat,type,lineId) " +
                         "values(@no,@name,@stationName,@lng,@lat,@type,@lineId)";
            var result = SqlHelper.ExecSql(sql, new SqlParameter[] {
                new SqlParameter("@no", station.no),
                new SqlParameter("@name", station.name),
                new SqlParameter("@stationName", station.stationName),
                new SqlParameter("@lng", station.lng),
                new SqlParameter("@lat", station.lat),
                new SqlParameter("@type", station.type),
                new SqlParameter("@lineId", station.lineId)
            });

            return(result > 0 ? true : false);
        }
 public StationLineBO ReturnStationLine(int LineNumber, int numberStation)
 {
     try
     {
         StationLineBO stationLineBO = new StationLineBO();
         BusStation    busStation    = dl.ReturnStation(numberStation);
         LineStation   lineStation   = dl.ReturnLineStation(LineNumber, numberStation);
         lineStation.CopyPropertiesTo(stationLineBO);
         stationLineBO.NameOfStation = busStation.NameOfStation;
         return(stationLineBO);
     }
     catch (ExceptionLineStation ex)
     {
         throw new BOExceptionLineStation("Error!!!", ex);
     }
 }
        /// <summary>
        /// request a LineStation according to a predicate
        /// </summary>
        /// <param name="pr"></param>
        /// <returns></returns>
        public LineStation RequestLineStation(Predicate <LineStation> pr = null)
        {
            List <LineStation> LineStationList = XMLTools.LoadListFromXMLSerializer <LineStation>(lineStationsPath);

            LineStation ret = LineStationList.Find(line => pr(line));

            if (ret == null)
            {
                throw new Exception("no line that meets these conditions!");
            }
            if (ret == null)
            {
                throw new Exception("line that meets these conditions is not valid");
            }
            return(ret);
        }
Beispiel #27
0
        /// <summary>
        /// 修改线路
        /// </summary>
        /// <param name="station">线路</param>
        /// <returns>是否成功</returns>
        public bool UpdateStation(LineStation station)
        {
            string sql = "update linestation " +
                         "set no=@no,name=@name,stationName=@stationName,lng=@lng,lat=@lat,type=@type " +
                         "where id=@id";
            var result = SqlHelper.ExecSql(sql, new SqlParameter[] {
                new SqlParameter("@no", station.no),
                new SqlParameter("@name", station.name),
                new SqlParameter("@stationName", station.stationName),
                new SqlParameter("@lng", station.lng),
                new SqlParameter("@lat", station.lat),
                new SqlParameter("@type", station.type),
                new SqlParameter("@id", station.id),
            });

            return(result > 0 ? true : false);
        }
Beispiel #28
0
        /// <summary>
        /// Sets stations list
        /// </summary>
        /// <returns>List of stations</returns>
        private static List <LineStation> setStationsList()
        {
            List <LineStation> stationsList   = new List <LineStation>(); // Data
            double             _busStationKey = 100000;
            Random             randomLandmark = new Random();
            double             _latitude;
            double             _longitude;

            for (int i = 0; i < 40; i++)
            {
                _latitude  = randomLandmark.Next(31, 33) + randomLandmark.NextDouble();
                _longitude = randomLandmark.Next(34, 35) + randomLandmark.NextDouble();
                LineStation newStation = new LineStation(_busStationKey + i, _latitude, _longitude, "");
                stationsList.Add(newStation);
            }
            return(stationsList);
        }
Beispiel #29
0
        /// <summary>
        /// 根据id查找线路信息
        /// </summary>
        /// <param name="id">线路id</param>
        /// <returns>线路信息</returns>
        public LineInfo FindById(int id)
        {
            LineInfo info = new LineInfo();

            info.lineStations = new List <LineStation>();


            string    sql    = "select * from linestation where lineId=" + id + " order by no";
            DataTable result = SqlHelper.ExecuteDataTable(sql);

            if (result != null)
            {
                for (int i = 0; i < result.Rows.Count; i++)
                {
                    LineStation entity = new LineStation
                    {
                        id          = (int)result.Rows[i]["id"],
                        no          = (int)result.Rows[i]["no"],
                        lineId      = (int)result.Rows[i]["lineid"],
                        type        = (int)result.Rows[i]["type"],
                        lng         = (double)result.Rows[i]["lng"],
                        lat         = (double)result.Rows[i]["lat"],
                        name        = result.Rows[i]["name"].ToString(),
                        stationName = result.Rows[i]["stationname"].ToString()
                    };
                    if (entity.type == 2)
                    {
                        info.lineStations.Add(entity);
                    }
                    else if (entity.type == 0)
                    {
                        info.start = entity;
                    }
                    else if (entity.type == 1)
                    {
                        info.terminus = entity;
                    }
                }
                return(info);
            }
            else
            {
                return(null);
            }
        }
        public TimeSpan GetNextStopTime(TimeSpan check, TimeSpan time, long lineId)
        {
            LineStation ret         = new LineStation();
            Line        currentLine = GetLine(lineId);

            foreach (LineStation lineStation in GetAllLineStationsByLineNumber(currentLine.Number))
            {
                if (currentLine.FirstStop != lineStation.Code)
                {
                    check += TravelTimeCalculate(currentLine.Number, currentLine.FirstStop, lineStation.Code);
                    if (check > time)
                    {
                        return(check - time);
                    }
                }
            }
            return(new TimeSpan());
        }