示例#1
0
        public static List <Ingrediente> Ler()
        {
            List <Ingrediente> result        = new List <Ingrediente>();
            SqlConnection      sqlConnection = new SqlConnection(Properties.Settings.Default.connectionString);
            SqlCommand         sqlCommand    = new SqlCommand();

            sqlCommand.Connection  = sqlConnection;
            sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
            sqlCommand.CommandText = "dbo.LerIngredientes";

            try
            {
                sqlConnection.Open();

                SqlDataReader reader = sqlCommand.ExecuteReader();

                while (reader.Read())
                {
                    Ingrediente ingrediente = new Ingrediente();
                    ingrediente.IngredienteID   = reader.GetInt32(0);
                    ingrediente.NomeIngrediente = reader.GetString(1);
                    result.Add(ingrediente);
                }

                sqlConnection.Close();
            }
            catch (Exception e)
            {
            }

            return(result);
        }
示例#2
0
        public static Plato infPalto(int idPlato, float cantPlatos)
        {
            Plato plato = new Plato();

            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand("INF_PLATO", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("cantPlato", cantPlatos);
                command.Parameters.AddWithValue("idplato", idPlato);

                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();


                    while (reader.Read())
                    {
                        plato.Id     = reader.GetInt32(0);
                        plato.Nombre = reader[1].ToString();
                        plato.Costo  = reader.GetDecimal(2);

                        reader.NextResult();

                        while (reader.Read())
                        {
                            Ingrediente ingrediente = new Ingrediente();

                            ingrediente.IdProducto    = reader.GetInt32(0);
                            ingrediente.Cantidad      = (float)reader.GetDouble(1);
                            ingrediente.Unidad.Nombre = reader[2].ToString();

                            plato.setIngredientes(ingrediente);
                        }
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(plato);
        }
示例#3
0
 public void setIngredientesUsados(Ingrediente ing)
 {
     ingredientes.Add(ing);
 }
示例#4
0
        public static List <Ingrediente> BuuscarIngrediente(int idIngrediente)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            // Proporcionar la cadena de consulta
            // string queryString = "Select IdPersona, Nombre,  ApPaterno from Persona where Nombre like '%{0}%' or ApPaterno like '%{1}%'";


            //Lista de Clientes recuperados
            List <Ingrediente> listaIngrediente = new List <Ingrediente>();

            // Crear y abrir la conexión en un bloque using.
            // Esto asegura que todos los recursos serán cerrados
            // y dispuestos cuando el código sale

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                // Crear el objeto Command.
                SqlCommand command = new SqlCommand("infoIngrediente", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("idIngrediente", idIngrediente);

                // Abre la conexión en un bloque try / catch
                // Crear y ejecutar el DataReader, escribiendo
                // el conjunto de resultados a la ventana de la consola.
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            Ingrediente ing = new Ingrediente();

                            ing.Id         = reader.GetInt32(0);
                            ing.IdPlato    = reader.GetInt32(1);
                            ing.Cantidad   = (float)reader.GetDouble(2);
                            ing.IdUnidad   = reader.GetInt32(3);
                            ing.IdProducto = reader.GetInt32(4);



                            listaIngrediente.Add(ing);
                        }

                        reader.NextResult();
                    }
                    reader.Close();
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(listaIngrediente);
        }
示例#5
0
        public static List <Plato> datosPlatosProd(int id)
        {
            List <Plato> platos = new List <Plato>();

            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand("platosProduccion", connection);
                command.CommandType = CommandType.StoredProcedure;


                command.Parameters.AddWithValue("dProduccion", id);
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();


                    while (reader.Read())
                    {
                        Plato plato = new Plato();

                        plato.Id    = reader.GetInt32(0);
                        plato.Costo = reader.GetDecimal(2);

                        //recuperar los ingredientes de los platos en una lista de lista

                        SqlCommand commandI = new SqlCommand("ingredienteDetalle", connection);
                        commandI.CommandType = CommandType.StoredProcedure;


                        commandI.Parameters.AddWithValue("idPlato", plato.Id);
                        commandI.Parameters.AddWithValue("cantidad", plato.Costo);

                        SqlDataReader readerI = commandI.ExecuteReader();

                        while (readerI.Read())
                        {
                            Ingrediente ing = new Ingrediente();

                            ing.Unidad.Nombre = readerI[3].ToString();
                            ing.Cantidad      = Validar.ConvertirAKilo(ing.Unidad.Nombre, (float)readerI.GetDouble(2));

                            plato.setIngredientes(ing);
                        }

                        platos.Add(plato);
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(platos);
        }