protected void dgvFabricaciones_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("AddNew")) { FabricacionNegocio FabricacionesNeg = new FabricacionNegocio(); Fabricacion fab = new Fabricacion(); fab.producto = new Producto(); fab.empleado = new Empleado(); fab.producto.id = Convert.ToInt64((dgvFabricaciones.FooterRow.FindControl("ddlProductosFooter") as DropDownList).Text); fab.empleado.id = Convert.ToInt64((dgvFabricaciones.FooterRow.FindControl("ddlEmpleadosFooter") as DropDownList).Text); fab.cantidad = Convert.ToDouble((dgvFabricaciones.FooterRow.FindControl("txbCantidadFooter") as TextBox).Text); fab.estadoFab = ((dgvFabricaciones.FooterRow.FindControl("ddlEstadosFooter") as DropDownList).Text); fab.fechaInicio = Convert.ToDateTime(txbInicio.Text); fab.fechaFin = Convert.ToDateTime(txbFin.Text); FabricacionesNeg.Agregar(fab); FabricacionesNeg.AgregarStock(fab.producto.id, fab.cantidad); lblCorrecto.Text = "Agregado correctamente."; lblIncorrecto.Text = ""; Cargardgv(); } } catch (Exception ex) { lblCorrecto.Text = ""; lblIncorrecto.Text = ex.Message; } }
protected void btnAgregar_Click(object sender, EventArgs e) { FabricacionNegocio FabricacionesNeg = new FabricacionNegocio(); Fabricacion fab = new Fabricacion(); fab.producto = new Producto(); fab.empleado = new Empleado(); fab.producto.id = Convert.ToInt64(ddlProductos.SelectedValue); fab.empleado.id = Convert.ToInt64(ddlEmpleados.SelectedValue); fab.cantidad = Convert.ToDouble(txbCantidad.Text); fab.estadoFab = ddlEstados.SelectedValue; fab.fechaInicio = Convert.ToDateTime(txbInicio.Text); fab.fechaFin = Convert.ToDateTime(txbFin.Text); List <Formula> listaFormula; FormulaNegocio formuNeg = new FormulaNegocio(); listaFormula = formuNeg.Listar(Convert.ToInt32(fab.producto.id)); if (fab.estadoFab.Equals("Completado")) { int cant = FabricacionesNeg.ContarInsumosXProd(fab.producto.id); if (FabricacionesNeg.VerificarStock(fab.producto.id, cant, fab.cantidad)) { FabricacionesNeg.AgregarStock(fab.producto.id, fab.cantidad); lblCorrecto.Text = "Tenemos los insumos!"; lblIncorrecto.Text = " "; FabricacionesNeg.Agregar(fab); foreach (Formula item in listaFormula) { FabricacionesNeg.DisminuirStock(item.insumo.id, item.cantidad, fab.cantidad); } Cargardgv(); } else { lblIncorrecto.Text = "No hay insumos suficientes. Se asignara estado Pendiente"; lblCorrecto.Text = " "; fab.estadoFab = "Pendiente"; FabricacionesNeg.Agregar(fab); Cargardgv(); } } else if (fab.estadoFab.Equals("Pendiente")) { int cant = FabricacionesNeg.ContarInsumosXProd(fab.producto.id); if (FabricacionesNeg.VerificarStock(fab.producto.id, cant, fab.cantidad)) { lblCorrecto.Text = "Tenemos los insumos!"; lblIncorrecto.Text = " "; FabricacionesNeg.Agregar(fab); Cargardgv(); } else { lblIncorrecto.Text = "No hay insumos suficientes."; lblCorrecto.Text = " "; FabricacionesNeg.Agregar(fab); Cargardgv(); } } else { lblCorrecto.Text = "Agregado correctamente."; lblIncorrecto.Text = ""; FabricacionesNeg.Agregar(fab); Cargardgv(); } }