Пример #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
        private void btn_eliminarIngrediente_Click(object sender, EventArgs e)
        {
            int   indice;
            Int32 selectedRowCount = dg_ingrediente.Rows.GetRowCount(DataGridViewElementStates.Selected);

            if (selectedRowCount == 1)
            {
                if (Funciones.mConsulta(this, "¿Está seguro que desea eliminar el ingrediente seleccionado"))
                {
                    for (int i = 0; i < selectedRowCount; i++)
                    {
                        int id_detalle_receta = 0;
                        try
                        {
                            Int32 firstSelectd = this.dg_ingrediente.Rows.GetFirstRow(
                                DataGridViewElementStates.Selected);

                            indice            = firstSelectd;
                            id_detalle_receta = Convert.ToInt32(dg_ingrediente.Rows[indice].Cells["id_detalle_receta"].Value);
                            this.dg_ingrediente.Rows.RemoveAt(firstSelectd);

                            if (!Detalle_receta.eliminarDetalle(id_detalle_receta))
                            {
                                Funciones.mError(this, "Error al eliminar el ingrediente seleccionado");
                            }
                        }
                        catch (Exception ex)
                        {
                            Funciones.mError(this, "Error al eliminar el ingrediente seleccionado");
                        }
                    }
                }
            }
            else
            {
                Funciones.mError(this, "Seleccione una fila");
            }
        }
Пример #3
0
        private void btn_modificarIngrediente_Click(object sender, EventArgs e)
        {
            int   indice;
            Int32 selectedRowCount = dg_ingrediente.Rows.GetRowCount(DataGridViewElementStates.Selected);

            if (selectedRowCount == 1)
            {
                for (int i = 0; i < selectedRowCount; i++)
                {
                    int id_detalle_receta = 0;
                    try
                    {
                        Int32 firstSelectd = this.dg_ingrediente.Rows.GetFirstRow(
                            DataGridViewElementStates.Selected);

                        indice            = firstSelectd;
                        id_detalle_receta = Convert.ToInt32(dg_ingrediente.Rows[indice].Cells["id_detalle_receta"].Value);

                        DataRow fila = Detalle_receta.recuperarDetalle(id_detalle_receta).Tables[0].Rows[0];
                        comboProducto.SelectedValue = fila["id_producto"];
                        comboUnidad.SelectedValue   = fila["unidad"];
                        txtCantidad.Text            = fila["cantidad"].ToString();
                        btn_agregarIngrediente.Text = "GUARDAR CAMBIOS";
                        id_detalle_receta1          = id_detalle_receta;
                    }
                    catch (Exception ex)
                    {
                        Funciones.mError(this, "Error al modificar el ingrediente seleccionado");
                        id_detalle_receta1 = 0;
                    }
                }
            }
            else
            {
                Funciones.mError(this, "Seleccione una fila");
            }
        }
Пример #4
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");
            }
        }