Ejemplo n.º 1
0
        public List <Cars> GetAllCars()
        {
            List <Cars> result = new List <Cars>();

            try
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    using (cmd.Connection = new SQLiteConnection(m_conn_string))
                    {
                        cmd.Connection.Open();

                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.CommandText = "SELECT * FROM Cars";

                        SQLiteDataReader reader = cmd.ExecuteReader();


                        while (reader.Read())
                        {
                            Cars c = new Cars
                            {
                                ID           = (long)reader["ID"],
                                Manufacturer = reader["Manufacturer"].ToString(),
                                Year         = (long)reader["YEAR"],
                                Model        = reader["Model"].ToString(),
                            };
                            result.Add(c);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                my_logger.Error("Failed Function GetAllCars by query (select * from cars)");
                my_logger.Error($"Failed to read from data base. Error : {ex}");
            }
            return(result);
        }
Ejemplo n.º 2
0
 public void UpdateCars(Cars c, int id)
 {
     ExecuteNonQuery(
         $"UPDATE Cars SET Manufacturer='{c.Manufacturer}', Year={c.Year},Model='{c.Model}'" +
         $"WHERE ID={id}");
 }
Ejemplo n.º 3
0
 public void AddCars(Cars c)
 {
     ExecuteNonQuery("INSERT INTO Cars(Manufacturer,Model,Year)" +
                     $"VALUES('{c.Manufacturer}', '{c.Model}', {c.Year});");
 }
Ejemplo n.º 4
0
        public override bool Equals(object obj)
        {
            Cars c = (Cars)obj;

            return(this.ID == c.ID);
        }