protected void dgvFabricaciones_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { FabricacionNegocio FabricacionesNeg = new FabricacionNegocio(); Fabricacion fab = new Fabricacion(); fab.producto = new Producto(); fab.empleado = new Empleado(); fab.id = Convert.ToInt64(dgvFabricaciones.DataKeys[e.RowIndex].Value.ToString()); fab.producto.id = Convert.ToInt64((dgvFabricaciones.Rows[e.RowIndex].FindControl("ddlProductos") as DropDownList).Text); fab.empleado.id = Convert.ToInt64((dgvFabricaciones.Rows[e.RowIndex].FindControl("ddlEmpleados") as DropDownList).Text); fab.cantidad = Convert.ToDouble((dgvFabricaciones.Rows[e.RowIndex].FindControl("txbCantidad") as TextBox).Text); fab.estadoFab = (dgvFabricaciones.Rows[e.RowIndex].FindControl("ddlEstadoEdit") as DropDownList).Text; fab.fechaInicio = Convert.ToDateTime((dgvFabricaciones.Rows[e.RowIndex].FindControl("txbFechaI") as TextBox).Text); fab.fechaFin = Convert.ToDateTime((dgvFabricaciones.Rows[e.RowIndex].FindControl("txbFechaFin") as TextBox).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); FabricacionesNeg.Modificar(fab); foreach (Formula item in listaFormula) { FabricacionesNeg.DisminuirStock(item.insumo.id, item.cantidad, fab.cantidad); } lblCorrecto.Text = "Modificado correctamente."; lblIncorrecto.Text = ""; Response.Redirect("Fabricaciones.aspx"); } else { Cargardgv(); lblCorrecto.Text = ""; lblIncorrecto.Text = "No se modifico"; Response.Redirect("Fabricaciones.aspx"); } } else { FabricacionesNeg.Modificar(fab); Response.Redirect("Fabricaciones.aspx"); } } 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(); } }