Exemplo n.º 1
0
        public IEnumerable <CarClass> GetList()
        {
            string          query  = "SELECT * FROM cars";
            MySqlDataReader reader = GetReader(query);

            while (reader.Read())
            {
                int           carId       = int.Parse(reader[0].ToString());
                BodyworkClass bodywork    = SQLBodyworks.GetInstance().Search(reader[1].ToString());
                EngineClass   engine      = SQLEngines.GetInstance().Search(reader[2].ToString());
                ClientClass   client      = ClientService.SearchClientById(int.Parse(reader[3].ToString()));
                int           kilometrage = int.Parse(reader[4].ToString());
                int           cost        = int.Parse(reader[5].ToString());
                int           carStatus   = int.Parse(reader[6].ToString());
                yield return(new CarClass(carId, bodywork, engine, client, kilometrage, cost, carStatus));
            }
            reader.Close();
        }
Exemplo n.º 2
0
        public CarClass Search(string carId)
        {
            string          query  = "SELECT * FROM cars WHERE carId='" + carId + "'";
            CarClass        car    = null;
            MySqlDataReader reader = GetReader(query);

            try
            {
                reader.Read();
                BodyworkClass bodywork    = SQLBodyworks.GetInstance().Search(reader[1].ToString());
                EngineClass   engine      = SQLEngines.GetInstance().Search(reader[2].ToString());
                ClientClass   client      = ClientService.SearchClientById(int.Parse(reader[3].ToString()));
                int           kilometrage = int.Parse(reader[4].ToString());
                int           cost        = int.Parse(reader[5].ToString());
                int           carStatus   = int.Parse(reader[6].ToString());
                car = new CarClass(int.Parse(carId), bodywork, engine, client, kilometrage, cost, carStatus);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { reader.Close(); }
            return(car);
        }