Example #1
0
        private void btnAmortizacion_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtTasa.Text) || String.IsNullOrWhiteSpace(txtPlazo.Text) || String.IsNullOrWhiteSpace(txtCredito.Text) || String.IsNullOrWhiteSpace(txtCorreo.Text))
            {
                MessageBox.Show("Porfavor rellene todos los campos del formulario");
                return;
            }
            else
            {
                if (!validate_emailaddress.IsMatch(txtCorreo.Text))
                {
                    MessageBox.Show("Direccion de correco no valida!", "Invalido", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtCorreo.Focus();
                    return;
                }
                else
                {
                    if (txtPlazo.Text == "0" || txtCredito.Text == "0" || txtTasa.Text == "0")
                    {
                        MessageBox.Show("No puede haber campos que valgan 0");
                        return;
                    }
                }
            }

            try
            {
                using (var db = new NorthwindEntities())
                {
                    db.TablaAmortizacion(decimal.Parse(txtCredito.Text), int.Parse(txtPlazo.Text), decimal.Parse(txtTasa.Text), decimal.Parse(txtIncremento.Text));
                    dgvAmortizacion.DataSource = db.Prestamo.ToList();
                    db.EnviarCorreo(txtCorreo.Text);
                    db.Database.ExecuteSqlCommand("TRUNCATE TABLE Prestamo");
                    db.SaveChangesAsync();
                }
            }
            catch (ArithmeticException ex)
            {
                MessageBox.Show(ex.Message);
            }

            txtCorreo.Clear();
            txtCredito.Clear();
            txtIncremento.Clear();
            txtPlazo.Clear();
            txtTasa.Clear();
            btnRefresh.Enabled = true;
        }