コード例 #1
0
ファイル: JourneyRepository.cs プロジェクト: DwewOlden/Roots
        public List <Journey.Journey> GetAllTripJourneys(int Id)
        {
            List <Journey.Journey> journeysList = new List <Journey.Journey>();

            try
            {
                string SQLString = GetCompleteRecordsFromTrip(Id);

                connection = new SqliteConnection("Data Source=" + GetPathToDatabase());
                connection.Open();

                using (var c = connection.CreateCommand())
                {
                    c.CommandText = SQLString;
                    var reader = c.ExecuteReader();

                    while (reader.Read())
                    {
                        Journey.Journey j = new Journey.Journey()
                        {
                            JourneyId = reader.GetInt32(0),
                            DriverId  = reader.GetInt32(1),
                            TripId    = reader.GetInt32(2),
                            Starting  = DateTime.ParseExact(reader.GetString(3), "yyyy-M-d H:m:s.FFF", CultureInfo.InvariantCulture, DateTimeStyles.None),
                            Ending    = DateTime.ParseExact(reader.GetString(4), "yyyy-M-d H:m:s.FFF", CultureInfo.InvariantCulture, DateTimeStyles.None),

                            Distance   = reader.GetDouble(5),
                            EndPoint   = reader.GetString(6),
                            DriverName = reader.GetString(12)
                        };

                        journeysList.Add(j);
                    }

                    reader.Close();
                }

                connection.Close();
                connection.Dispose();
                connection = null;

                return(journeysList);
            }
            catch (Exception ex)
            {
                return(new List <Journey.Journey>());
            }
        }
コード例 #2
0
ファイル: JourneyRepository.cs プロジェクト: DwewOlden/Roots
        public bool GetAllDriverStats(int Id, out Dictionary <string, int> Time, out Dictionary <string, double> Distance)
        {
            Time     = new Dictionary <string, int>();
            Distance = new Dictionary <string, double>();

            try
            {
                string SQLString = GetCompleteRecordsFromTrip(Id);

                connection = new SqliteConnection("Data Source=" + GetPathToDatabase());
                connection.Open();

                using (var c = connection.CreateCommand())
                {
                    c.CommandText = SQLString;
                    var reader = c.ExecuteReader();

                    while (reader.Read())
                    {
                        Journey.Journey j = new Journey.Journey()
                        {
                            Starting   = DateTime.ParseExact(reader.GetString(3), "yyyy-M-d H:m:s.FFF", CultureInfo.InvariantCulture, DateTimeStyles.None),
                            Ending     = DateTime.ParseExact(reader.GetString(4), "yyyy-M-d H:m:s.FFF", CultureInfo.InvariantCulture, DateTimeStyles.None),
                            DriverName = reader.GetString(8)
                        };
                    }

                    reader.Close();
                }

                connection.Close();
                connection.Dispose();
                connection = null;

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }