private void AgregarImplementosDevueltos(cSGPRDEVOLUCIONNegocios pDevolucion) { Panel implementos = (Panel)_prestamoElegido.FindControl("implementos_" + pDevolucion.FK_IDPRESTAMO); Char[] delimiter = { '_' }; foreach (Control implemento in implementos.Controls) { string idPanel = implemento.ID; string sIdImplemento = idPanel.Split(delimiter)[1]; int idImplemento = int.Parse(sIdImplemento); DropDownList drpCantDevolver = (DropDownList)implemento.FindControl("drpCantDevolver_" + idImplemento); if (drpCantDevolver.SelectedIndex > 0) { cSGPRIMPLEMENTOSPORDEVOLUCIONNegocios implementoDevuelto = new cSGPRIMPLEMENTOSPORDEVOLUCIONNegocios(Global.gCOD_APLICACION, "CA", 0, "0"); implementoDevuelto.FK_IMPLEMENTO = idImplemento; implementoDevuelto.FK_DEVOLUCION = pDevolucion.ID_DEVOLUCION; implementoDevuelto.CANT_DEVUELTOS = drpCantDevolver.SelectedIndex; implementoDevuelto.Insertar(); cSGGIIMPLEMENTONegocios implementoInventario = new cSGGIIMPLEMENTONegocios(Global.gCOD_APLICACION, "CA", 0, "0"); implementoInventario.ID_IMPLEMENTO = idImplemento; DataTable tablaBusqueda = implementoInventario.Buscar(); implementoInventario.CAN_DISPONIBLE = int.Parse(tablaBusqueda.Rows[0]["CAN_DISPONIBLE"].ToString()) + drpCantDevolver.SelectedIndex; implementoInventario.Actualizar(); DropDownList drpCantDanada = (DropDownList)implemento.FindControl("drpCantDanada_" + idImplemento); if (drpCantDanada.SelectedIndex > 0) { cSGGIDANOPORIMPLEMENTONegocios dano = new cSGGIDANOPORIMPLEMENTONegocios(Global.gCOD_APLICACION, "CA", 0, "0"); dano.FK_IDIMPLEMENTO = idImplemento; dano.FEC_REPORTE = DateTime.Now; dano.CAN_IMPLEMENTOS = drpCantDanada.SelectedIndex; TextBox txtObservaciones = (TextBox)implemento.FindControl("txtObservaciones_" + idImplemento); dano.DSC_DANO = txtObservaciones.Text; dano.Insertar(); cSGPRDANOPORDEVOLUCIONNegocios danoDevolucion = new cSGPRDANOPORDEVOLUCIONNegocios(Global.gCOD_APLICACION, "CA", 0, "0"); danoDevolucion.FK_IDDEVOLUCION = pDevolucion.ID_DEVOLUCION; danoDevolucion.FK_IDDANO = dano.ID_DANO; danoDevolucion.Insertar(); } } } }
private Boolean ComprobarDevolucionValida(cSGPRDEVOLUCIONNegocios pDevolucion) { Panel implementos = (Panel)_prestamoElegido.FindControl("implementos_" + pDevolucion.FK_IDPRESTAMO); Char[] delimiter = { '_' }; foreach (Control implemento in implementos.Controls) { string idPanel = implemento.ID; string sIdImplemento = idPanel.Split(delimiter)[1]; int idImplemento = int.Parse(sIdImplemento); DropDownList drpCantDevolver = (DropDownList)implemento.FindControl("drpCantDevolver_" + idImplemento); if (drpCantDevolver.SelectedIndex > 0) { return true; } } return false; }
protected void btnRealizarDevolucion_Click(object sender, EventArgs e) { cSGPRDEVOLUCIONNegocios devolucion = new cSGPRDEVOLUCIONNegocios(Global.gCOD_APLICACION, "CA", 0, "0"); devolucion.FEC_DEVOLUCION = DateTime.Now; Label lblIdentifiacion = (Label)_prestamoElegido.FindControl("lblIdentificacion"); devolucion.CAR_USUARIOGIMNASIO = lblIdentifiacion.Text; Char[] delimiter = { '_' }; string idPanel = _prestamoElegido.ID; string idPrestamo = idPanel.Split(delimiter)[1]; devolucion.FK_IDPRESTAMO = int.Parse(idPrestamo); if (!ComprobarDevolucionValida(devolucion)) { if (!Page.ClientScript.IsStartupScriptRegistered("DevolucionInvalida")) { Page.ClientScript.RegisterStartupScript(this.GetType(), "DevolucionInvalida", "<script type=\"text/javascript\"> alert('Debe ingresar alguna cantidad a devolver para al menos uno de los implementos.'); </script>"); } return; } devolucion.Insertar(); AgregarImplementosDevueltos(devolucion); WrapperDetalle.Controls.Clear(); _prestamoElegido = null; cSGPRIMPLEMENTOPORPRESTAMONegocios implementosTemp = new cSGPRIMPLEMENTOPORPRESTAMONegocios(Global.gCOD_APLICACION, "CA", 0, "0"); implementosTemp.FK_IDPRESTAMO = int.Parse(idPrestamo); DataTable tablaImplementos = implementosTemp.SeleccionarTodos_Con_FK_IDPRESTAMO_FK(); if (tablaImplementos.Rows.Count == 0) { cSGPRPRESTAMONegocios prestamos = new cSGPRPRESTAMONegocios(Global.gCOD_APLICACION, "CA", 0, "0"); prestamos.ID_PRESTAMO = int.Parse(idPrestamo); prestamos.ESTADO = true; prestamos.Actualizar(); } if (!Page.ClientScript.IsStartupScriptRegistered("DevolucionSatisfactoria")) { Page.ClientScript.RegisterStartupScript(this.GetType(), "DevolucionSatisfactoria", "<script type=\"text/javascript\"> __doPostBack(); alert('La devolución se realizó satisfactoriamente.'); </script>"); } }