/// <summary> /// Meto que cargar el datagridview /// </summary> public void cargarGrid() { try { DeduccionesD oDeduccionesD = new DeduccionesD(this.cnx); this.grdDeducciones.DataSource = oDeduccionesD.obtenerDeducciones(); if (oDeduccionesD.Error) { MessageBox.Show("Error cargando los datos" + oDeduccionesD.ErrorDescription); } } catch (Exception e) { MessageBox.Show("Error cargando los datos" + e.Message); } }
/// <summary> /// Metodo que elimina la línea seleccionada /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnBorrar_Click(object sender, EventArgs e) { if (this.grdDeducciones.RowCount > 0) { //pide confirmación: DialogResult confirmacion = MessageBox.Show("¿Está seguro de borrar esta Deducción?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirmacion == DialogResult.No) return; DeduccionesL oDeduccionesL = (DeduccionesL)this.grdDeducciones.CurrentRow.DataBoundItem; DeduccionesD oDeduccionesD = new DeduccionesD(this.cnx); oDeduccionesD.borrarDeduccion(oDeduccionesL); if (oDeduccionesD.Error) { MessageBox.Show("Error borrando la Deducción:" + oDeduccionesD.ErrorDescription); } else { MessageBox.Show("Deducción borrada!!!"); this.cargarGrid(); } } }
/// <summary> /// Metodo que refresca la línea la seleccionada /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEditar_Click(object sender, EventArgs e) { if (this.grdDeducciones.RowCount > 0) { DeduccionesL oDeduccionesOriginal = (DeduccionesL)this.grdDeducciones.CurrentRow.DataBoundItem; frmEdicionDeducciones ofrmEdicion = new frmEdicionDeducciones(oDeduccionesOriginal, this.oUsuarioL, this.cnx); ofrmEdicion.ShowDialog(); if (ofrmEdicion.Aceptar) { DeduccionesD oDeduccionesD = new DeduccionesD(this.cnx); oDeduccionesD.editarDeducciones(oDeduccionesOriginal, ofrmEdicion.ODeduccionesL); if (oDeduccionesD.Error) { MessageBox.Show("Error actualizando los datos:" + oDeduccionesD.ErrorDescription); } else { MessageBox.Show("Deducción actualizada!!!"); this.cargarGrid(); } } } }
/// <summary> /// Metodo que realiza un nuevo registro /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNuevo_Click(object sender, EventArgs e) { frmEdicionDeducciones ofrmEdicion = new frmEdicionDeducciones(this.oUsuarioL, this.cnx); ofrmEdicion.ShowDialog(); if (ofrmEdicion.Aceptar) { DeduccionesD oDeduccionesD = new DeduccionesD(this.cnx); oDeduccionesD.agregarDeduccion(ofrmEdicion.ODeduccionesL); if (oDeduccionesD.Error) { MessageBox.Show("Error agregando los datos:" + oDeduccionesD.ErrorDescription); } else { MessageBox.Show("Deducción agregada!!!"); this.cargarGrid(); } } }
/// <summary> /// Método del botón aceptar,el cual verifica si el usuario preciono el botón aceptar o no,si lo hizo procede a revisar si no dejo /// algún espacio en blanco sino lo hizo creando una deducción con los datos suministrados /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAceptar_Click(object sender, EventArgs e) { String activo = "No"; if (this.chkActivo.Checked) { activo = "Sí"; } if ((this.txtIdDeducciones.Text == "") || (this.txtPorcentaje.Text == "") || (this.txtDescripcion.Text == "")) { MessageBox.Show("Faltan datos requeridos"); return; } else { try { //se verifica que lo que se alla puesto en este campo sea un valor númerico this.monto = double.Parse(this.txtPorcentaje.Value.ToString()); } catch { MessageBox.Show("El porcentaje es incorrecto"); this.txtPorcentaje.Text = ""; //se queda el scrol en el txt para modificar el dato mal ingresado this.txtPorcentaje.Focus(); return; } DeduccionesD oDeduccionesD = new DeduccionesD(this.conexion); List<DeduccionesL> listaDeducciones = oDeduccionesD.obtenerDeduccionId(this.txtIdDeducciones.Text); if (this.edicion == false) { if (listaDeducciones.Count > 0) { MessageBox.Show("El código de deducción ya existe"); this.txtIdDeducciones.Text = ""; this.txtIdDeducciones.Focus(); return; } else { this.oDeduccionesL = new DeduccionesL(this.txtIdDeducciones.Text, double.Parse(this.txtPorcentaje.Text), this.txtDescripcion.Text, DateTime.Now, DateTime.Now, oUsuarioL[0].IdUsuario, oUsuarioL[0].IdUsuario, activo); } } else { txtIdDeducciones.ReadOnly = false; this.oDeduccionesL = new DeduccionesL(this.txtIdDeducciones.Text, double.Parse(this.txtPorcentaje.Text), this.txtDescripcion.Text, DateTime.Now, DateTime.Now, oUsuarioL[0].IdUsuario, oUsuarioL[0].IdUsuario, activo); } } this.aceptar = true; this.Close(); }