private void txtInteres_TextChanged(object sender, EventArgs e) { if (ValidacionesCL.ValidarSoloNumeros(txtInteres.Text)) { // QUITA LOS ESPACIOS EN BLANCO txtMonto.Text = txtMonto.Text.Replace(" ", ""); txtInteres.Text = txtInteres.Text.Replace(" ", ""); if (txtInteres.Text == "" || txtMonto.Text == "") { lblValorInteres.Text = "₡ 0000"; lblValorTotal.Text = "₡ 0000"; } else { monto = Convert.ToDouble(txtMonto.Text.Replace(" ", "")); // TOMA EL INTERES Y SE LO AGREGA A LA VARIABLE interes = Convert.ToDouble(txtInteres.Text); totalInteres = (interes / 100) * monto; total = monto + totalInteres; lblValorTotal.Text = Convert.ToString("₡ " + total); lblValorInteres.Text = Convert.ToString("₡ " + totalInteres); } } else { // ELIMINA LOS VALOREES ( LETRAS, SIMBOLOS) txtInteres.Text = txtInteres.Text.Remove(txtInteres.Text.Length - 1); txtInteres.SelectionStart = txtInteres.Text.Length; } }
private void dtFechaInicial_CloseUp(object sender, EventArgs e) { int dia = dtFechaInicial.Value.Day; int mes = dtFechaInicial.Value.Month; int ano = dtFechaInicial.Value.Year; int tipo = ValidacionesCL.ValidarDiaPagoIndex(cmbDiaPago.SelectedItem.ToString()); bool ValidacionQuincena = ValidacionesCL.validarQuincena(dia, mes, ano, tipo); }
private void btnGuardar_Click(object sender, EventArgs e) { int dia = dtFechaInicial.Value.Day; int mes = dtFechaInicial.Value.Month; int ano = dtFechaInicial.Value.Year; int tipo = ValidacionesCL.ValidarDiaPagoIndex(cmbDiaPago.SelectedItem.ToString()); bool ValidacionQuincena = ValidacionesCL.validarQuincena(dia, mes, ano, tipo); // COMPRUEBA SI EL DIA DE PAGO NO ES QUINCENA if (ValidacionQuincena == false) { if (dtgCuotas.RowCount > 0) { if (txtMonto.Text == "" || txtInteres.Text == "" || txtCuotas.Text == "") { MessageBox.Show("Rellene todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { PrestamosCL oPrestamos = new PrestamosCL(); Prestamos_CuotasCL oPrestamos_Cuotas = new Prestamos_CuotasCL(); double saldo = total; oPrestamos.InsertarPrestamo(numeroPrestamo, dtFecha.Value, cliente, monto, interes, Convert.ToInt32(txtCuotas.Text), saldo, total, false, tipo); foreach (DataRow item in cuotasGeneradas) { oPrestamos_Cuotas.InsertarPrestamo_Cuotas( numeroPrestamo, Convert.ToInt32(item.ItemArray[0]), Convert.ToDateTime(item.ItemArray[1]), Convert.ToInt32(item.ItemArray[2]), Convert.ToInt32(item.ItemArray[3]) ); } if (oPrestamos.IsError) { MessageBox.Show(oPrestamos.ErrorDescripcion, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Prestamo creado con exito", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); prestamos.CargarPrestamos(); this.Dispose(); } } } else { MessageBox.Show("Genere primero las cuotas antes de crear un prestamo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// GENERA LA PREVISUALIZACION DE LAS NUEVAS CUOTAS public void generarCuotasPrevias() { if (!revisarAbonos()) { if (!string.IsNullOrEmpty(txtMonto.Text)) { #region VARIABLES double oSaldoCuota = saldoPrestamo + Convert.ToDouble(txtMonto.Text); double valorxcuotas = montoCuota; // saldoPrestamo += Convert.ToDouble(txtMonto.Text); totalPrestamo += Convert.ToDouble(txtMonto.Text); Boolean terminarGenerarCuotas = true; fecha = Convert.ToDateTime(dCuotas.Rows[dCuotas.Rows.Count - 1]["fecha_pactada"]); int contador = 0; int numeroCuota = Convert.ToInt32(dCuotas.Rows[dCuotas.Rows.Count - 1]["num_cuota"]); int dia = fecha.Day; int mes = fecha.Month; int ano = fecha.Year; int tipo = dia_pago; #endregion // COPIA LA ESTRUCTURA Y DATOS DEL TABLE dCuotasPre = dCuotas.Copy(); // CICLO QUE GENERA LAS CUOTAS DE RECARGO while (terminarGenerarCuotas) { /* SI EL SALDO ES MENOR AL VALOR DE LA CUOTA, ENTONCES EL VALOR DE * LA CUOTA SE CONVIERTE EN EL SALDO RESTANTE */ if (oSaldoCuota < valorxcuotas) { valorxcuotas = oSaldoCuota; } // VA DISMINUYENDO EL SALDO EN CADA VUELTA, PARA DARLE UN SALDO A CADA CUOTA oSaldoCuota -= valorxcuotas; if (oSaldoCuota > 0) { valorxcuotas = montoCuota; } else { // TERMINA EL CICLO terminarGenerarCuotas = false; } // MODIFICA LAS CUOTAS EXISTENTES POR LOS NUEVOS VALORES if (contador <= dCuotas.Rows.Count - 1) { dCuotasPre.Rows[contador]["monto"] = valorxcuotas; dCuotasPre.Rows[contador]["saldo"] = oSaldoCuota; } // CREA UNA NUEVA FILA PARA AGREGAR CUOTAS else { numeroCuota = numeroCuota + 1; DataRow row = dCuotasPre.Rows.Add(numeroCuota); // LLEVA EL CONTROL DE LOS MESES PARA UNA FECHA ESPECIFICA contadorMeses++; ValidacionesCL.contadorMeses = contadorMeses; fecha = ValidacionesCL.validarFechaPago(fecha.Day, fecha.Month, fecha.Year, fecha, tipo); // AGREGA VALORES A LAS NUEVAS FILAS CREADAS row["num_cuota"] = numeroCuota; row["fecha_pactada"] = fecha; row["monto"] = valorxcuotas; row["saldo"] = oSaldoCuota; } contador++; } dtgCuotasPrevias.DataSource = dCuotasPre; contadorMeses = 0; } else { MessageBox.Show("Escriba el monto a recargar", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Las siguientes cuotas en rojo presentan abonos y no han sido pagadas en su totalidad, " + "cancele las cuotas pendientes antes de continuar ", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnGuardar_Click(object sender, EventArgs e) { var dia = dtFechaInicial.Value.Day; var mes = dtFechaInicial.Value.Month; var ano = dtFechaInicial.Value.Year; var tipo = ValidacionesCL.ValidarDiaPagoIndex(cmbDiaPago.SelectedItem.ToString()); var validacionQuincena = ValidacionesCL.validarQuincena(dia, mes, ano, tipo); if (_dCuotasGeneradas == null || _dCuotasGeneradas.Rows.Count == 0) { MessageBox.Show("Debe hacer clic en Generar previsualización para poder procesar la edición", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (validacionQuincena == false) { var countErrors = 0; var oCuotas = new Prestamos_CuotasCL(); var oPlanilla = new PlanillaCL(); var oAbonosCuotas = new Abonos_CuotasCL(); foreach (DataRow item in _dCuotas.Rows) { var id = item["id"].ToString(); // ELIMINAR ABONOS DE UNA CUOTA oAbonosCuotas.EliminarAbono_Cuotas_Id_Cuota(id); // ELIMINA DETALLE DE PLANILLA REFERENTE A UNA CUOTA oPlanilla.EliminarPlanillaDetalle(id); // ELIMINAR LA CUOTA oCuotas.EliminarCuota(id); if (oCuotas.IsError) { countErrors++; } } foreach (DataRow item in _dCuotasGeneradas.Rows) { // INSERTA NUEVAS CUOTAS oCuotas.InsertarPrestamo_Cuotas( _prestamoId, Convert.ToInt32(item["Numero couta"].ToString()), Convert.ToDateTime(item["Fecha de pago"].ToString()), Convert.ToDouble(item["Monto"].ToString()), Convert.ToDouble(item["Saldo"].ToString())); if (oCuotas.IsError) { countErrors++; } } if (countErrors > 0) { MessageBox.Show("Se presentaron errores al editar las cuotas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Préstamo modificado con éxito", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Dispose(); } } }
public void GenerarCuotasPrevias() { try { // COMPRUEBA EL VALOR DE LOS CAMPOS if (txtCuotas.Text == "") { MessageBox.Show(@"LLene los campos faltantes", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var dia = dtFechaInicial.Value.Day; var mes = dtFechaInicial.Value.Month; var ano = dtFechaInicial.Value.Year; var tipo = ValidacionesCL.ValidarDiaPagoIndex(cmbDiaPago.SelectedItem.ToString()); var validacionQuincena = ValidacionesCL.validarQuincena(dia, mes, ano, tipo); // COMPRUEBA SI EL DIA DE PAGO NO ES QUINCENA if (validacionQuincena == false) { #region COLUMNAS DE LA TABLA _dCuotasGeneradas = new DataTable(); _dCuotasGeneradas.Columns.Add("Numero couta"); _dCuotasGeneradas.Columns.Add("Fecha de pago"); _dCuotasGeneradas.Columns.Add("Monto"); _dCuotasGeneradas.Columns.Add("Saldo"); #endregion #region GENERA LAS CUOTAS // TOMA LA FECHA INICIAL _fecha = dtFechaInicial.Value; // EL SALDO ES IGUAL AL TOTAL AL PRINCIPIO var saldoCuotas = _prestamoSaldo; // VARIABLE QUE SE ESTABLECE PARA DECIDIR CUANDO TERMINAR DE CALCULAR var terminarGenerarCuotas = true; // EMPIEZA A CONTAR DESDE EL PRIMER NUMERO DE CUOTA var contNumeroCuota = _primerNumeroCuota; var contMeses = 1; if (saldoCuotas > 0) { // ESTABLECE LA FECHA INICIAL ValidacionesCL.fechaInicial = _fecha; while (terminarGenerarCuotas) { if (saldoCuotas >= Convert.ToDouble(txtCuotas.Text.Trim())) { _valorxcuotas = Convert.ToDouble(txtCuotas.Text.Trim()); } else { _valorxcuotas = saldoCuotas; terminarGenerarCuotas = false; } saldoCuotas -= _valorxcuotas; var row = _dCuotasGeneradas.Rows.Add(); row["Numero couta"] = contNumeroCuota; row["Fecha de pago"] = _fecha.ToShortDateString(); row["Monto"] = _valorxcuotas; row["Saldo"] = saldoCuotas; // LLEVA EL CONTROL DE LOS MESES PARA UNA FECHA ESPECIFICA ValidacionesCL.contadorMeses = contMeses; // CONSULTA LA FECHA SIGUIENTE BASADO EN EL DIA PAGO ESCODIGO _fecha = ValidacionesCL.validarFechaPago(_fecha.Day, _fecha.Month, _fecha.Year, _fecha, tipo); contNumeroCuota++; contMeses++; if (saldoCuotas == 0) { break; } } } #endregion dtgCuotasPrevias.DataSource = _dCuotasGeneradas; } } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void GenerarCuotas() { // COMPRUEBA EL VALOR DE LOS CAMPOS if (txtInteres.Text == "" || txtMonto.Text == "" || txtCuotas.Text == "") { MessageBox.Show("LLene los campos faltantes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int dia = dtFechaInicial.Value.Day; int mes = dtFechaInicial.Value.Month; int ano = dtFechaInicial.Value.Year; int tipo = ValidacionesCL.ValidarDiaPagoIndex(cmbDiaPago.SelectedItem.ToString()); bool ValidacionQuincena = ValidacionesCL.validarQuincena(dia, mes, ano, tipo); // COMPRUEBA SI EL DIA DE PAGO NO ES QUINCENA if (ValidacionQuincena == false) { cuotasGeneradas = new ArrayList(); #region COLUMNAS DE LA TABLA DataSet oDatos = new DataSet(); DataTable oTable = oDatos.Tables.Add(); DataColumn oColumn = new DataColumn(); oColumn = oTable.Columns.Add("Numero couta"); oColumn = oTable.Columns.Add("Fecha de pago"); oColumn = oTable.Columns.Add("Monto"); oColumn = oTable.Columns.Add("Saldo"); #endregion #region GENERA LAS CUOTAS // TOMA LA FECHA INICIAL fecha = dtFechaInicial.Value; double cuotas = monto + totalInteres; // EL SALDO ES IGUAL AL TOTAL AL PRINCIPIO double SaldoCuotas = total; // VARIABLE QUE SE ESTABLECE PARA DECIDIR CUANDO TERMINAR DE CALCULAR Boolean terminarGenerarCuotas = true; int cont = 1; // CICLO QUE GENERA LAS CUOTAS if (ckActivarCuoutaInicial.CheckState == CheckState.Checked) { if (string.IsNullOrEmpty(txtMontoCuotaInicial.Text)) { MessageBox.Show("Falta el monto de la cuota inicial", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { SaldoCuotas -= Convert.ToDouble(txtMontoCuotaInicial.Text); DataRow row = oTable.Rows.Add(0); row["Numero couta"] = 0; row["Fecha de pago"] = dtFechaCuotaInicial.Value.ToShortDateString(); row["Monto"] = txtMontoCuotaInicial.Text; row["Saldo"] = SaldoCuotas; cuotasGeneradas.Add(row); } } if (SaldoCuotas > 0) { while (terminarGenerarCuotas) { if (SaldoCuotas >= Convert.ToDouble(txtCuotas.Text)) { valorxcuotas = Convert.ToDouble(txtCuotas.Text); } else { valorxcuotas = SaldoCuotas; terminarGenerarCuotas = false; } SaldoCuotas -= valorxcuotas; DataRow row = oTable.Rows.Add(cont); row["Numero couta"] = cont; row["Fecha de pago"] = fecha.ToShortDateString(); row["Monto"] = valorxcuotas; row["Saldo"] = SaldoCuotas; // LLEVA EL CONTROL DE LOS MESES PARA UNA FECHA ESPECIFICA ValidacionesCL.contadorMeses = cont; // CONSULTA LA FECHA SIGUIENTE BASADO EN EL DIA PAGO ESCODIGO fecha = ValidacionesCL.validarFechaPago(fecha.Day, fecha.Month, fecha.Year, fecha, tipo); cuotasGeneradas.Add(row); cont++; if (SaldoCuotas == 0) { break; } } } #endregion dtgCuotas.DataSource = oDatos.Tables[0]; } } }