Beispiel #1
0
        public List <Cars> Reader(string query, string function)
        {
            List <Cars> allCars = new List <Cars>();

            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(_30122020_EXAMEN_SQLAppConfig.ConnectionString))
                {
                    using (SQLiteCommand command = new SQLiteCommand(query, connection))
                    {
                        using (SQLiteDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Cars c = new Cars
                                {
                                    Id           = (long)reader["id"],
                                    Manufacturer = reader["manufacturer"].ToString(),
                                    Model        = reader["model"].ToString(),
                                    Year         = (int)reader["year"]
                                };
                                allCars.Add(c);
                            }
                        }
                        return(allCars);
                    }
                }
            }
            catch (Exception ex)
            {
                _30122020_EXAMEN_SQLAppConfig._log.Error($"Process '{ function}' failed.Exception : {ex}");

                Console.WriteLine($"Process '{ function}' failed.Exception : {ex}");
                Console.ReadKey();
                Environment.Exit(-1);
            }
            return(null);
        }
Beispiel #2
0
 public void AddCar(Cars c)
 {
     _query = $"INSERT INTO tests" +
              $"VALUES ({c.Manufacturer},{c.Model},{c.Year})";
     int row = NonReader(_query, "Add Car");
 }
Beispiel #3
0
 public void UpdateCar(int id, Cars c)
 {
     _query = $"UPDATE tests SET id = {c.Id},manufacturer = {c.Manufacturer}, model = {c.Model},year = {c.Year} ";
     NonReader(_query, "Update Car");
 }
Beispiel #4
0
        public override bool Equals(object obj)
        {
            Cars test = obj as Cars;

            return(this.Id.Equals(test.Id));
        }