Пример #1
0
        private void btn_agregarIngrediente_Click(object sender, EventArgs e)
        {
            Detalle_receta det = null;
            int            id_ingrediente;
            float          cantidad1;
            int            id_unidad;
            string         mensaje = "Intente nuevamente agregar el ingrediente";

            try
            {
                id_ingrediente = Convert.ToInt32(comboProducto.SelectedValue);
                id_unidad      = Convert.ToInt32(comboUnidad.SelectedValue);
                cantidad1      = float.Parse(txtCantidad.Text);

                if (btn_agregarIngrediente.Text == "GUARDAR CAMBIOS")
                {
                    if (id_detalle_receta1 > 0)
                    {
                        Detalle_receta.actualizarDetalle(id_detalle_receta1, id_ingrediente, id_unidad, cantidad1);
                        btn_agregarIngrediente.Text = "AGREGAR INGREDIENTE";
                    }
                    mensaje = "Intente nuevamente modificar el ingrediente";
                }
                else
                {
                    if (id_receta1 > 0)
                    {
                        det = new Detalle_receta(id_receta1, id_ingrediente, id_unidad, cantidad1, 0);
                        det.guardarDetalle();
                    }
                }
            }
            catch (Exception ex)
            {
                Funciones.mError(this, mensaje);
            }
            cargarDetalles(id_receta1);
        }
Пример #2
0
        // PREGUNTA SI LA TABLA TIENE DETALLES SI = TRUE,CREA Y GUARDA LA RECETA CON SUS DETALLES
        private void btn_guardarReceta_Click(object sender, EventArgs e)
        {
            float     cantidad;
            bool      pivote  = true;
            string    mensaje = "La receta se guardo correctamente\n";
            DataTable dt      = (DataTable)tablaIngredientes.DataSource;

            if (dt != null)
            {
                string nombreIngrediente = "Error en la cantidad";
                try
                {
                    foreach (DataRow fila in dt.Rows)
                    {
                        nombreIngrediente = fila["nombre"].ToString();
                        cantidad          = float.Parse(fila["cantidad"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    Funciones.mError(this, nombreIngrediente + ", por favor ingrese un número entero para la cantidad\n" + ex.Message);
                    pivote = false;
                }



                if (pivote)
                {
                    receta1             = new Receta();
                    receta1.Id_producto = Convert.ToInt32(txtId.Text);
                    receta1.Fecha       = fecha.Value.Date;
                    receta1.Nombre      = txtNombreReceta.Text;

                    if (receta1.guardarReceta()) //GUARDA LA RECETA Y SUS DETALLES, PREGUNTAR SI QUIERE CREAR OTRA
                    {
                        Detalle_receta det;
                        int            id_ingrediente;
                        int            id_unidad;
                        foreach (DataRow fila in dt.Rows)
                        {
                            id_ingrediente = Int32.Parse(fila["id_producto"].ToString());
                            id_unidad      = Int32.Parse(fila["id_unidad"].ToString());
                            cantidad       = float.Parse(fila["cantidad"].ToString());

                            det = new Detalle_receta(receta1.Id_receta, id_ingrediente, id_unidad, cantidad, 0);

                            if (!det.guardarDetalle())
                            {
                                Funciones.mOk(this, "El detalle " + fila["nombre"].ToString() + ", NO se guardo correctamente");
                                mensaje = "La receta se guardo con errores, vaya a 'Modificar Producto' para corregir";
                            }
                        }

                        if (!Funciones.mConsulta(this, mensaje + "Desea generar otra version de receta para el mismo producto"))
                        {
                            pane_receta.Enabled    = false;
                            panel_producto.Enabled = true;
                            inicializarDatos();
                            ActualizarProductos();
                        }

                        dt.Clear();
                        txtNombreReceta.Text    = "Mi receta";
                        txtNombre_producto.Text = "";
                        receta1 = null;
                        det     = null;
                    }
                    else
                    {
                        Funciones.mError(this, "NO se pudo guardar la receta, intente nuevamente");
                    }
                }
            }
            else
            {
                Funciones.mError(this, "Debe agregar al menos un ingrediente para la receta");
            }
        }