コード例 #1
0
        protected void LlenarFields(Ingrediente obj)
        {
            ViewState["IdIngrediente"] = obj.IdIngrediente;

            DetalleIngrediente detalle = iDAL.GetDetalleByDefault(obj.IdIngrediente);

            ViewState["IdDetalle"] = detalle.IdIngredienteDetalle;

            txtNombre.Text                = obj.Nombre;
            txtDescripcion.Text           = obj.Descripcion;
            txtStock.Text                 = obj.Stock.ToString();
            txtValorNeto.Text             = obj.ValorNeto.ToString();
            cboMarca.SelectedValue        = detalle.IdMarca.HasValue ? detalle.IdMarca.Value.ToString() : "1";
            cboTipoAlimento.SelectedValue = obj.IdTipoAlimento.HasValue ? obj.IdTipoAlimento.ToString() : "0";
            cboTipoMedicion.SelectedValue = obj.IdTipoMedicion.ToString();
            txtPorcion.Text               = obj.Porción.ToString();
            SetCboTipoMedicionPorcion(Convert.ToInt32(cboTipoMedicion.SelectedValue));
            string value = obj.IdTipoMedicionPorcion.HasValue ? obj.IdTipoMedicionPorcion.Value.ToString() : "0";

            cboTipoMedicionPorcion.SelectedValue = value;
            chkVigencia.Checked = obj.Estado == 1;

            btnAgregar.Visible   = false;
            btnModificar.Visible = true;
        }
コード例 #2
0
        protected void gridViewIngredientesAlimento_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridViewRow row         = e.Row;
                Label       lblCodigo   = row.FindControl("lblCodigo") as Label;
                Ingrediente ingrediente = iDAL.Find(Convert.ToInt32(lblCodigo.Text));

                Label label = (Label)row.FindControl("lblNombre");
                label.Text = ingrediente.Nombre;

                label      = (Label)row.FindControl("lblDescripcion");
                label.Text = ingrediente.Descripcion;

                label = (Label)row.FindControl("lblMarca");
                DetalleIngrediente detalle = iDAL.GetDetalleByDefault(ingrediente.IdIngrediente);
                label.Text = detalle.IdMarca.HasValue ? mDAL.Find(Convert.ToInt32(detalle.IdMarca.Value)).Nombre : "Sin Marca";

                label = (Label)row.FindControl("lblCantidad");
                int cantidad = int.Parse(label.Text);

                label      = (Label)row.FindControl("lblCantidadTotal");
                label.Text = $"{ingrediente.Porción * cantidad} {tMDAL.Find(ingrediente.IdTipoMedicionPorcion.Value).Descripcion}";
            }
        }
コード例 #3
0
 protected void GridViewDetalle_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         int   index     = Convert.ToInt32(e.CommandArgument);
         Label lblCodigo = (Label)GridViewDetalle.Rows[index].FindControl("lblCodigo");
         int   idDetalle = Convert.ToInt32(lblCodigo.Text);
         switch (e.CommandName)
         {
         case "Eliminar":
             if (dIDAL.GetAllByIngrediente((int)ViewState["IdIngrediente"]).Count == 1)
             {
                 throw new Exception("No se pueden eliminar todos los registros del ingrediente");
             }
             DetalleIngrediente obj = dIDAL.Find(idDetalle);
             obj.Estado = 0;
             dIDAL.Update(obj);
             LoadGridDetalle();
             break;
         }
     }
     catch (Exception ex)
     {
         UserMessage(ex.Message, "danger");
     }
 }
コード例 #4
0
        public void Remove(int id)
        {
            DetalleIngrediente p = Find(id);

            nowBDEntities.DetalleIngrediente.Remove(p);
            nowBDEntities.SaveChanges();
        }
コード例 #5
0
        public DetalleIngrediente Add(DetalleIngrediente p)
        {
            DetalleIngrediente obj = nowBDEntities.DetalleIngrediente.Add(p);

            nowBDEntities.SaveChanges();
            return(obj);
        }
コード例 #6
0
        public Ingrediente Add(Ingrediente i, DetalleIngrediente dI)
        {
            ValidateNombre(i.Nombre);
            i.Estado = 1;
            Ingrediente obj = nowBDEntities.Ingrediente.Add(i);

            nowBDEntities.SaveChanges();
            dI.IdIngrediente = obj.IdIngrediente;
            dIDAL.Add(dI);
            return(obj);
        }
コード例 #7
0
        public void Update(DetalleIngrediente p)
        {
            DetalleIngrediente detalleU = nowBDEntities.DetalleIngrediente.FirstOrDefault(obj => obj.IdIngredienteDetalle == p.IdIngredienteDetalle);

            detalleU.IdIngrediente     = p.IdIngrediente;
            detalleU.Foto              = p.Foto;
            detalleU.CantidadIngresada = p.CantidadIngresada;
            detalleU.IdMarca           = p.IdMarca;
            detalleU.Descripcion       = p.Descripcion;
            detalleU.Estado            = p.Estado;

            nowBDEntities.SaveChanges();
        }
コード例 #8
0
        protected void gridViewIngredientes_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridViewRow row         = e.Row;
                Label       lbl         = row.FindControl("lblCodigo") as Label;
                Ingrediente ingrediente = iDAL.Find(Convert.ToInt32(lbl.Text));

                lbl = (Label)row.FindControl("lblMarca");
                DetalleIngrediente detalle = iDAL.GetDetalleByDefault(ingrediente.IdIngrediente);
                lbl.Text = detalle.IdMarca.HasValue ? mDAL.Find(Convert.ToInt32(detalle.IdMarca.Value)).Nombre : "Sin Marca";

                lbl      = (Label)row.FindControl("lblTipoAlimento");
                lbl.Text = lbl.Text == "" ? "Sin Tipo de Alimento" : tADAL.Find(Convert.ToInt32(lbl.Text)).Descripcion;

                lbl      = (Label)row.FindControl("lblTipoMedicion");
                lbl.Text = lbl.Text == "" ? "Sin Medición" : tMDAL.Find(Convert.ToInt32(lbl.Text)).Descripcion;
            }
        }
コード例 #9
0
        protected void btnModificar_Click(object sender, EventArgs e)
        {
            try
            {
                ValidarCampos();
                int idIngrediente = Convert.ToInt32(ViewState["IdIngrediente"]);
                int idDetalle     = Convert.ToInt32(ViewState["IdDetalle"]);

                Ingrediente ingrediente = iDAL.Find(idIngrediente);
                ingrediente.IdIngrediente = idIngrediente;
                ingrediente.Nombre        = txtNombre.Text;
                ingrediente.Descripcion   = txtDescripcion.Text;

                ingrediente.Stock                 = txtStock.Text == "" ? (int?)null : Convert.ToInt32(txtStock.Text);
                ingrediente.ValorNeto             = txtValorNeto.Text == "" ? (double?)null : Convert.ToDouble(txtValorNeto.Text);
                ingrediente.IdTipoAlimento        = cboTipoAlimento.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboTipoAlimento.SelectedValue);
                ingrediente.IdTipoMedicion        = cboTipoMedicion.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboTipoMedicion.SelectedValue);
                ingrediente.Porción               = Convert.ToInt32(txtPorcion.Text);
                ingrediente.IdTipoMedicionPorcion = cboTipoMedicionPorcion.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboTipoMedicionPorcion.SelectedValue);
                ingrediente.Estado                = chkVigencia.Checked ? 1 : 0;

                DetalleIngrediente detalle = dIDAL.Find(idDetalle);

                /*detalle.CantidadIngresada;
                 * detalle.Descripcion
                 * detalle.Foto
                 * detalle.IdMarca*/
                iDAL.Update(ingrediente);
                dIDAL.Update(detalle);

                UserMessage("Ingrediente Modificado", "success");
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                UserMessage(ex.Message, "danger");
            }
        }
コード例 #10
0
 protected void btnAgregar_Click(object sender, EventArgs e)
 {
     try
     {
         ValidarCampos();
         Ingrediente iObj = new Ingrediente()
         {
             Nombre      = txtNombre.Text,
             Descripcion = txtDescripcion.Text,
             Stock       = txtStock.Text == "" ? (int?)null : Convert.ToInt32(txtStock.Text),
             ValorNeto   = txtValorNeto.Text == "" ? (double?)null : Convert.ToDouble(txtValorNeto.Text),
             //IdMarca = cboMarca.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboMarca.SelectedValue),
             IdTipoAlimento        = cboTipoAlimento.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboTipoAlimento.SelectedValue),
             IdTipoMedicion        = cboTipoMedicion.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboTipoMedicion.SelectedValue),
             Porción               = Convert.ToInt32(txtPorcion.Text),
             IdTipoMedicionPorcion = cboTipoMedicionPorcion.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboTipoMedicion.SelectedValue),
             Estado = 1
         };
         DetalleIngrediente diObj = new DetalleIngrediente()
         {
             IdIngrediente     = iObj.IdIngrediente,
             Descripcion       = txtDescripcion.Text,
             Foto              = "Foto1",
             IdMarca           = cboMarca.SelectedValue == "0" ? (int?)null : Convert.ToInt32(cboMarca.SelectedValue),
             CantidadIngresada = txtStock.Text == "" ? (int?)null : Convert.ToInt32(txtStock.Text),
             Estado            = 1
         };
         iObj = iDAL.Add(iObj, diObj);
         UserMessage("Ingrediente agregado", "success");
         GridView1.DataBind();
     }
     catch (Exception ex)
     {
         UserMessage(ex.Message, "danger");
     }
 }
コード例 #11
0
        public DetalleIngrediente Find(int id)
        {
            DetalleIngrediente m = nowBDEntities.DetalleIngrediente.FirstOrDefault(obj => obj.IdIngredienteDetalle == id);

            return(m);
        }
コード例 #12
0
        private void SaveIngredients(Factura obj)
        {
            DataTable dt = ViewState["Data"] as DataTable;

            foreach (DataRow row in dt.Rows)
            {
                #region Declaración de variables
                string rowNombre       = row["Nombre"] as string;
                string rowDescripción  = (row["Descripción"] as string);
                string rowCantidad     = row["Cantidad"] as string;
                string rowMarca        = row["Marca"] as string;
                string rowTipoAlimento = row["TipoAlimento"] as string;
                string rowTipoMedicion = row["TipoMedicion"] as string;
                string rowPrecio       = row["Precio"] as string;
                string rowTotal        = row["Total"] as string;
                string rowCantPorPack  = row["CantidadPack"] as string;
                #endregion

                Marca              marca        = mDAL.FindByName(rowMarca);
                TipoAlimento       tipoAlimento = tADAL.FindByName(rowTipoAlimento);
                TipoMedicion       tipoMedicion = tMDAL.FindByName(rowTipoMedicion);
                List <Ingrediente> ingredientesDeMismoNombre = iDAL.FindAllByName(rowNombre);
                DetalleIngrediente detalleIn       = new DetalleIngrediente();
                Ingrediente        ingrediente     = iDAL.FindByName(rowNombre);
                TipoMedicion       tipoMedicionIng = ingrediente != null?tMDAL.Find(ingrediente.IdTipoMedicion.Value) : null;

                int  cantidad   = string.IsNullOrEmpty(rowCantPorPack) ? Convert.ToInt32(rowCantidad) : Convert.ToInt32(rowCantidad) * Convert.ToInt32(rowCantPorPack);
                bool convertido = false;

                marca = marca == null?mDAL.Add(new Marca()
                {
                    Nombre = rowMarca,
                    Estado = 1
                }) : marca;

                tipoAlimento = tipoAlimento == null?tADAL.Add(new TipoAlimento()
                {
                    Descripcion = rowTipoAlimento,
                    Estado      = 1
                }) : tipoAlimento;

                tipoMedicion = tipoMedicion == null?tMDAL.Add(new TipoMedicion()
                {
                    Descripcion = rowTipoMedicion,
                    Estado      = 1
                }) : tipoMedicion;

                //SetEquivalence(cantidad, tipoMedicionIng, tipoMedicion, out cantidad, out convertido);

                //Verificar si ya existe

                //Ingreso del ingrediente y del detalle

                bool existe = ingrediente != null;

                if (ingredientesDeMismoNombre.Count > 1)
                {
                    Ingrediente ingredienteConMismaDescripcion = iDAL.GetAll().FirstOrDefault(x => x.Descripcion == rowDescripción);
                    if (ingredienteConMismaDescripcion != null)
                    {
                        ingrediente = ingredienteConMismaDescripcion;
                    }
                }

                if (!existe)
                {
                    ingrediente = new Ingrediente()
                    {
                        Nombre         = rowNombre,
                        Descripcion    = rowDescripción,
                        Stock          = 0,
                        IdTipoAlimento = tipoAlimento.IdTipoAlimento,
                        IdTipoMedicion = tipoMedicion.IdTipoMedicion
                    };
                    detalleIn = new DetalleIngrediente()
                    {
                        CantidadIngresada = cantidad,
                        Descripcion       = rowDescripción,
                        IdMarca           = marca.IdMarca,
                        Estado            = 1
                    };
                    ingrediente = iDAL.Add(ingrediente, detalleIn);
                }

                IngredienteFactura ingredienteFactura = new IngredienteFactura();
                ingredienteFactura.Factura     = obj.IdFactura;
                ingredienteFactura.Ingrediente = ingrediente.IdIngrediente;
                ingredienteFactura.Precio      = Convert.ToInt32(rowPrecio);
                ingredienteFactura.Cantidad    = cantidad;
                ingredienteFactura.Impuesto    = 0;

                iFDAL.Add(ingredienteFactura);
                iFDAL.UpdateIngrediente(ingredienteFactura, tipoMedicion.IdTipoMedicion);
            }
        }