Ejemplo n.º 1
0
        public static List <Moto> getTodasMotoDB()
        {
            string queryTemplate = "SELECT moto_id, nombre, descripcion, marca, year, modelo,color, tipo, precio, strock FROM Motos;";

            DataTable   tableMotos = DataBasePort.getTableQuery(queryTemplate);
            List <Moto> result     = new List <Moto>();

            foreach (DataRow row in tableMotos.Rows)
            {
                int    motoId      = Int32.Parse(row["moto_id"].ToString());
                string nombre      = row["nombre"].ToString();
                string descripcion = row["descripcion"].ToString();
                string marca       = row["marca"].ToString();
                int    year        = Int32.Parse(row["year"].ToString());
                string modelo      = row["modelo"].ToString();
                string tipo        = row["tipo"].ToString();
                string color       = row["color"].ToString();
                float  price       = float.Parse(row["precio"].ToString());
                int    stock       = Int32.Parse(row["strock"].ToString());


                Moto moto = new Moto(motoId, nombre, descripcion, marca, year, modelo, tipo, color, price, stock);

                result.Add(moto);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static Vendedor getVendedorPorId(string vendedor_id)
        {
            string query_text = $"SELECT vendedor_id, nombre, CAST(fecha_nacimiento AS text) AS fecha_nacimiento, telefono, correo, direccion, contraseña FROM Vendedores WHERE vendedor_id = '{vendedor_id}';";


            DataTable result = DataBasePort.getTableQuery(query_text);

            if (result.Rows.Count <= 0)
            {
                return(null);
            }
            int      id              = Int32.Parse(result.Rows[0]["vendedor_id"].ToString());
            string   nombre          = result.Rows[0]["nombre"].ToString();
            DateTime fechaNacimiento = DateTime.Now;
            string   telefono        = result.Rows[0]["telefono"].ToString();
            string   correo          = result.Rows[0]["correo"].ToString();
            string   direccion       = result.Rows[0]["direccion"].ToString();
            string   contraseña      = result.Rows[0]["contraseña"].ToString();

            Vendedor encontrado = new Vendedor(id, nombre, fechaNacimiento, correo, telefono, direccion, contraseña);


            return(encontrado);
        }