Exemple #1
0
 public void Inactivate(Plato p)
 {
     using (MySqlConnection conn = new MySqlConnection(Constants.QueryConn))
     {
         MySqlTransaction trans = null;
         try
         {
             conn.Open();
             trans = conn.BeginTransaction();
             if (conn.Execute(Constants.DeletePlato, p, null, null, CommandType.Text) == -1)
             {
                 throw new DataException("Error al actualizar como NO DISPONIBLE un plato");
             }
             PromocionesDao promoDao = new PromocionesDao();
             var promos = promoDao.GetPromosByPlato(p);
             foreach (var pr in promos)
             {
                 if (promoDao.Inactivate(pr.Promocion_Id, conn, trans) == -1)
                 {
                     throw new DataException("Error al actualizar como NO DISPONIBLE la promocion con id =" + pr.Promocion_Id +  " asociada al plato");
                 }
             }
             trans.Commit();
         }
         catch (Exception ex)
         {
             trans.Rollback();
             throw ex;
         }
         finally
         {
             conn.Close();
         }
     }
 }
 public void Activate(Plato p)
 {
     PlatoDao dao = new PlatoDao();
     if (dao.Activate(p) != 1)
     {
         throw new Exception("No se actualizó como DISPONIBLE el plato");
     }
 }
 public void Insert(Plato p)
 {
     PlatoDao dao = new PlatoDao();
     if (dao.Insert(p) != 1)
     {
         throw new Exception("No se insertó el plato");
     }
 }
Exemple #4
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);
        }
Exemple #5
0
 public int Activate(Plato p)
 {
     using (MySqlConnection conn = new MySqlConnection(Constants.QueryConn))
     {
         try
         {
             conn.Open();
             return conn.Execute(Constants.ActivatePlato, p, null, null, CommandType.Text);
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
         }
     }
 }
Exemple #6
0
        public static List <Plato> platos()
        {
            List <Plato> platos = new List <Plato>();

            platos.Add(new Plato(0, "Seleccione un plato"));

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

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

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


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

                        plato.Id     = reader.GetInt32(0);
                        plato.Nombre = reader[1].ToString();

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

            return(platos);
        }
 public DetalleProduccion()
 {
     plato = new Plato();
 }
Exemple #8
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;
        }
Exemple #9
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);
        }
Exemple #10
0
        public static void actualizarIngredientes(Plato modificar)
        {
            // Proporciona la cadena de conexion a base de datos desde el archivo de configuracion
            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;


            // 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))
            {
                SqlCommand commandI = new SqlCommand("ActualizarPlato", connection);
                commandI.CommandType = CommandType.StoredProcedure;
                commandI.Parameters.AddWithValue("id", modificar.Id);
                commandI.Parameters.AddWithValue("nom", modificar.Nombre);
                commandI.Parameters.AddWithValue("precio", modificar.Costo);
                commandI.Parameters.AddWithValue("clasificacion", modificar.Clasificacion);


                // Crear el objeto Command.


                try
                {
                    connection.Open();
                    SqlTransaction trato = connection.BeginTransaction();
                    commandI.Transaction = trato;

                    int fila = commandI.ExecuteNonQuery();


                    foreach (Ingrediente item in modificar.getIngredientes())
                    {
                        SqlCommand command = new SqlCommand("ActualizarIngrediente", connection);
                        command.CommandType = CommandType.StoredProcedure;

                        command.Parameters.AddWithValue("idIngrediente", item.Id);
                        command.Parameters.AddWithValue("cantidad", item.Cantidad);
                        command.Parameters.AddWithValue("idPlato", item.IdPlato);
                        command.Parameters.AddWithValue("idProducto", item.IdProducto);
                        command.Parameters.AddWithValue("idUnidad", item.IdUnidad);

                        command.ExecuteNonQuery();
                    }



                    if (fila != 0)
                    {
                        trato.Commit();
                    }
                    else
                    {
                        trato.Rollback();
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #11
0
        public static void registraPlato(Plato plato)
        {
            // Proporciona la cadena de conexion a base de datos desde el archivo de configuracion
            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            // 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("Registro_Plato", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("nombre", plato.Nombre);
                command.Parameters.AddWithValue("costo", plato.Costo);
                command.Parameters.AddWithValue("idClasificacion", plato.Clasificacion.Codigo);
                command.Parameters.AddWithValue("idPlato", 0);

                command.Parameters["idPlato"].Direction = ParameterDirection.Output;

                try
                {
                    connection.Open();
                    //transacciones
                    SqlTransaction trato = connection.BeginTransaction();
                    command.Transaction = trato;

                    int fila = command.ExecuteNonQuery();


                    if (fila != 0)
                    {
                        int id = Convert.ToInt32(command.Parameters["idPlato"].Value);

                        foreach (Ingrediente ing in plato.getIngredientes())
                        {
                            SqlCommand comanding = new SqlCommand("Registro_Ingredientes", connection);

                            comanding.CommandType = CommandType.StoredProcedure;


                            comanding.Parameters.AddWithValue("cantidad", ing.Cantidad);
                            comanding.Parameters.AddWithValue("idPlato", id);
                            comanding.Parameters.AddWithValue("idProducto", ing.IdProducto);
                            comanding.Parameters.AddWithValue("idUnidad", ing.Unidad.Id);

                            comanding.Transaction = trato;

                            fila = comanding.ExecuteNonQuery();
                        }
                    }
                    if (fila != 0)
                    {
                        trato.Commit();
                    }
                    else
                    {
                        trato.Rollback();
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
 /// <summary>
 /// Devuelve todas las promociones en las que participa el plato
 /// </summary>
 public IEnumerable<Plato_Promocion> GetPromosByPlato(Plato p)
 {
     using (MySqlConnection conn = new MySqlConnection(Constants.QueryConn))
     {
         try
         {
             conn.Open();
             var lista = conn.Query<Plato_Promocion>(Constants.SelectPromosByPlato, p, null, true, null, CommandType.Text);
             return lista;
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             conn.Close();
         }
     }
 }
Exemple #13
0
        public static void borraProduccion(int idProduccion)
        {
            List <Plato> platos   = Plato.datosPlatosProd(idProduccion);
            int          fila     = 0;
            bool         correcto = false;
            string       con      = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

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

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


                try
                {
                    SqlTransaction trato = connection.BeginTransaction();
                    command.Transaction = trato;

                    connection.Open();

                    command.Transaction = trato;
                    fila = command.ExecuteNonQuery();

                    if (fila != 0)
                    {
                        foreach (var item in platos)
                        {
                            foreach (var itemI in item.getIngredientesUsados())
                            {
                                SqlCommand commandI = new SqlCommand("ActualizarCantProd", connection);
                                commandI.CommandType = CommandType.StoredProcedure;

                                commandI.Parameters.AddWithValue("idProducto", itemI.IdProducto);
                                commandI.Parameters.AddWithValue("cantidad", itemI.Cantidad);

                                commandI.Transaction = trato;
                                fila = commandI.ExecuteNonQuery();

                                if (fila != 0)
                                {
                                    correcto = true;
                                }
                                else
                                {
                                    correcto = false;
                                    break;
                                }
                            }
                        }
                    }

                    if (correcto)
                    {
                        trato.Commit();
                    }
                    else
                    {
                        trato.Rollback();
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #14
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;
        }
Exemple #15
0
 public DetalleProduccion()
 {
     plato = new Plato();
 }
 public void Delete(Plato p)
 {
     PlatoDao dao = new PlatoDao();
        dao.Inactivate(p);
 }
Exemple #17
0
        public static List<Plato> platos()
        {
            List<Plato> platos = new List<Plato>();
            platos.Add(new Plato(0, "Seleccione un plato"));

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

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

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

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

                        plato.Id = reader.GetInt32(0);
                        plato.Nombre = reader[1].ToString();

                        platos.Add(plato);
                    }

                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return platos;
        }
 public void Update(Plato p)
 {
     PlatoDao dao = new PlatoDao();
     if (dao.Update(p) != 1)
     {
         throw new Exception("No se actualizó el plato");
     }
 }
Exemple #19
0
        public static void actualizarIngredientes(Plato modificar)
        {
            // Proporciona la cadena de conexion a base de datos desde el archivo de configuracion
            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            // 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))
            {
                SqlCommand commandI = new SqlCommand("ActualizarPlato", connection);
                commandI.CommandType = CommandType.StoredProcedure;
                commandI.Parameters.AddWithValue("id", modificar.Id);
                commandI.Parameters.AddWithValue("nom", modificar.Nombre);
                commandI.Parameters.AddWithValue("precio", modificar.Costo);
                commandI.Parameters.AddWithValue("clasificacion", modificar.Clasificacion);

                // Crear el objeto Command.

                try
                {
                    connection.Open();
                    SqlTransaction trato = connection.BeginTransaction();
                    commandI.Transaction = trato;

                    int fila = commandI.ExecuteNonQuery();

                    foreach (Ingrediente item in modificar.getIngredientes())
                    {
                        SqlCommand command = new SqlCommand("ActualizarIngrediente", connection);
                        command.CommandType = CommandType.StoredProcedure;

                        command.Parameters.AddWithValue("idIngrediente", item.Id);
                        command.Parameters.AddWithValue("cantidad", item.Cantidad);
                        command.Parameters.AddWithValue("idPlato", item.IdPlato);
                        command.Parameters.AddWithValue("idProducto", item.IdProducto);
                        command.Parameters.AddWithValue("idUnidad", item.IdUnidad);

                        command.ExecuteNonQuery();

                    }

                    if (fila != 0)
                    {
                        trato.Commit();
                    }
                    else
                    {
                        trato.Rollback();
                    }

                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #20
0
        public static void registraPlato(Plato plato)
        {
            // Proporciona la cadena de conexion a base de datos desde el archivo de configuracion
            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            // 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("Registro_Plato", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("nombre", plato.Nombre);
                command.Parameters.AddWithValue("costo", plato.Costo);
                command.Parameters.AddWithValue("idClasificacion", plato.Clasificacion.Codigo);
                command.Parameters.AddWithValue("idPlato", 0);

                command.Parameters["idPlato"].Direction = ParameterDirection.Output;

                try
                {
                    connection.Open();
                    //transacciones
                    SqlTransaction trato = connection.BeginTransaction();
                    command.Transaction = trato;

                    int fila = command.ExecuteNonQuery();

                    if (fila != 0)
                    {

                        int id = Convert.ToInt32(command.Parameters["idPlato"].Value);

                        foreach (Ingrediente ing in plato.getIngredientes())
                        {
                            SqlCommand comanding = new SqlCommand("Registro_Ingredientes", connection);

                            comanding.CommandType = CommandType.StoredProcedure;

                            comanding.Parameters.AddWithValue("cantidad", ing.Cantidad);
                            comanding.Parameters.AddWithValue("idPlato", id);
                            comanding.Parameters.AddWithValue("idProducto", ing.IdProducto);
                            comanding.Parameters.AddWithValue("idUnidad", ing.Unidad.Id);

                            comanding.Transaction = trato;

                            fila = comanding.ExecuteNonQuery();

                        }
                    }
                    if (fila != 0)
                    {
                        trato.Commit();
                    }
                    else
                    {
                        trato.Rollback();
                    }

                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception)
                {

                    throw;
                }
            }
        }