protected void dgvFormulas_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName.Equals("AddNew")) { FormulaNegocio FormulaNeg = new FormulaNegocio(); Formula formu = new Formula(); formu.insumo = new Insumo(); formu.insumo.id = Convert.ToInt64((dgvFormulas.FooterRow.FindControl("ddlInsumosFooter") as DropDownList).Text); formu.insumo.nombre = (dgvFormulas.FooterRow.FindControl("ddlInsumosFooter") as DropDownList).SelectedItem.ToString(); formu.producto = new Producto(); formu.producto.id = Convert.ToInt64(Session["idProducto"]); formu.producto.nombre = ((TextBox)dgvFormulas.FooterRow.FindControl("txbProductosFooter")).Text; formu.cantidad = Convert.ToInt32((dgvFormulas.FooterRow.FindControl("txbCantidadFooter") as TextBox).Text); FormulaNeg.Agregar(formu); lblCorrecto.Text = "Agregado correctamente."; lblIncorrecto.Text = ""; cargardgv(); // Response.Redirect("formulas.aspx"); } } catch (Exception ex) { lblCorrecto.Text = ""; lblIncorrecto.Text = ex.Message; } }
protected void dgvFormulas_RowEditing(object sender, GridViewEditEventArgs e) { try { dgvFormulas.EditIndex = e.NewEditIndex; cargardgv(); //((TextBox)dgvFormulas.Rows[e.NewEditIndex].FindControl("txbInsumos")).Text = dgvFormulas.Rows[e.NewEditIndex].Cells[1].Text.ToString(); FormulaNegocio formulaNeg = new FormulaNegocio(); InsumoNegocio insNeg = new InsumoNegocio(); ((DropDownList)dgvFormulas.Rows[e.NewEditIndex].FindControl("ddlInsumos")).DataSource = insNeg.listar(); ((DropDownList)dgvFormulas.Rows[e.NewEditIndex].FindControl("ddlInsumos")).DataValueField = "id"; ((DropDownList)dgvFormulas.Rows[e.NewEditIndex].FindControl("ddlInsumos")).DataTextField = "nombre"; ((DropDownList)dgvFormulas.Rows[e.NewEditIndex].FindControl("ddlInsumos")).DataBind(); //Insumo insumo = new Insumo(); //insumo.nombre = ((Label)dgvFormulas.Rows[e.NewEditIndex].FindControl("lblInsumo")).Text; int idFormu = Convert.ToInt32((dgvFormulas.Rows[e.NewEditIndex].FindControl("lblId") as Label).Text); Formula formu = (formulaNeg.ListarXidFormula(idFormu)); ((DropDownList)dgvFormulas.Rows[e.NewEditIndex].FindControl("ddlInsumos")).Items.FindByValue(formu.insumo.id.ToString()).Selected = true; } catch (Exception ex) { lblIncorrecto.Text = ex.ToString(); } }
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 btnBuscar_Click(object sender, EventArgs e) { FormulaNegocio forNegocio = new FormulaNegocio(); Formula formula = new Formula(); var algo = cboBuscar.SelectedValue.ToString(); Session["idProducto"] = algo; dgvFormulas.DataSource = forNegocio.Listar(Convert.ToInt32(cboBuscar.SelectedValue.ToString())); dgvFormulas.DataBind(); cargardgv(); btnCancelar.Visible = true; }
protected void btnGuardarFormula_Click(object sender, EventArgs e) { Formula formu = new Formula(); FormulaNegocio formNeg = new FormulaNegocio(); List <Formula> list = new List <Formula>(); list = Session["ListaFormula"] as List <Formula>; foreach (Formula item in list) { formNeg.Agregar(item); } Session["ListaFormula"] = null; Response.Redirect("AltaFormula.aspx"); }
protected void dgvFormulas_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { FormulaNegocio FormulaNeg = new FormulaNegocio(); long id = Convert.ToInt64(dgvFormulas.DataKeys[e.RowIndex].Value.ToString()); FormulaNeg.ModificarEstado(id); lblCorrecto.Text = "Elminado correctamente."; lblIncorrecto.Text = ""; cargardgv(); } catch (Exception ex) { lblCorrecto.Text = ""; lblIncorrecto.Text = ex.Message; } }
protected void dgvFormulas_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { FormulaNegocio FormulasNeg = new FormulaNegocio(); long id = Convert.ToInt64(dgvFormulas.DataKeys[e.RowIndex].Value.ToString()); int index = Convert.ToInt32(dgvFormulas.DataKeys[e.RowIndex].Value); List <Formula> lista = new List <Formula>(); lista = (Session["ListaFormula"] as List <Formula>); lista.RemoveAt(index); Session["ListaFormula"] = lista; dgvFormulas.DataSource = lista; dgvFormulas.DataBind(); } catch (Exception ex) { throw ex; } }
protected void dgvFormulas_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { FormulaNegocio FormulaNeg = new FormulaNegocio(); Formula formu = new Formula(); formu.id = Convert.ToInt64(dgvFormulas.DataKeys[e.RowIndex].Value.ToString()); formu.insumo = new Insumo(); formu.insumo.id = Convert.ToInt64((dgvFormulas.Rows[e.RowIndex].FindControl("ddlInsumos") as DropDownList).Text); formu.insumo.nombre = (dgvFormulas.Rows[e.RowIndex].FindControl("ddlInsumos") as DropDownList).SelectedItem.ToString(); formu.cantidad = Convert.ToInt32((dgvFormulas.Rows[e.RowIndex].FindControl("txbCantidad") as TextBox).Text); FormulaNeg.Modificar(formu); lblCorrecto.Text = "Modificado 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(); } }