Programa de Funciones Financieras

Public Class Form1
    'Explicación:
    'Normalmente la gente simplemente se clave en la tasa de
    'interés anual como entero y no como%, así que tengo que
    'dividir la tasa por 100 y luego por 12 para obtener el
    'interés mensual. ¿Por qué signo negativo para el valor
    'presente (VP)? Porque esa es la cantidad que recibimos
    'en préstamo, por lo que debe ser negativa. El valor
    'futuro se establece en 0 porque para entonces usted
    'tiene pagar todo el pago. Por último, debido toma el
    'valor 0 como el pago vence al final del mes.
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        Label5.Text = ""
        Label10.Text = ""
        RadioButton1.Checked = False
        RadioButton2.Checked = False
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
        TextBox7.Clear()
        TextBox8.Clear()
        TextBox9.Clear()
        TextBox10.Clear()
        TextBox11.Clear()
        TextBox12.Clear()
        Label15.Text = ""
        Label13.Text = ""
        Label11.Text = ""
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        ' en la siguiente línea de código se comprueba si el caracter es dígito...
        'If (Not e.KeyChar.IsDigit(e.KeyChar)) Then
        '    ' de igual forma se podría comprobar si es caracter: e.KeyChar.IsLetter
        '    ' si es un caracter minusculas: e.KeyChar.IsLower ...etc
        '    If Not (e.KeyChar = Convert.ToChar(Keys.Back)) Then
        '        e.Handled = True ' esto invalida la tecla pulsada
        '    End If
        'End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim x As New DataSet
        If datos.ejecutar_comandos("Insert into clientes values('" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox11.Text & "','" & TextBox10.Text & "','" & TextBox9.Text & "'," & TextBox12.Text & ")") = True Then
            MsgBox("Cliente Registrado", MsgBoxStyle.OkOnly, Title:="Financiera")
        Else
            MsgBox("Error, revise los datos", MsgBoxStyle.Critical, Title:="Financiera")
        End If
        x = datos.ejecutar_select("select * from clientes")
        Me.DataGridView1.DataSource = x.Tables(0)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim cuota, n, g, a As Double
        a = Val(Label13.Text)
        n = Val(TextBox5.Text)
        g = Val(TextBox4.Text)
        If RadioButton1.Checked Then
            cuota = a - ((n - 1) * g)
        End If
        If RadioButton2.Checked Then
            cuota = a + ((n - 1) * g)
        End If
        Label15.Text = cuota
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim vp, a, c, n, d, g, i, total, h As Double
        vp = Val(TextBox1.Text)
        n = Val(TextBox3.Text) * 12
        i = (Val(TextBox2.Text) / 100) / 12
        c = (((1 + i) ^ n) - 1) / (i * ((1 + i) ^ n))
        d = n / ((1 + i) ^ n)
        g = Val(TextBox4.Text) / i
        h = (((1 + i) ^ n) - 1) / (i)

        If RadioButton1.Checked Then
            a = (g * (c - d) + vp) / c
            total = (a * h) - (g * (h - n))
        End If
        If RadioButton2.Checked Then
            a = (vp - (g * (c - d))) / c
            total = (a * h) + (g * (h - n))
        End If
        Label13.Text = a
        Label11.Text = total
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim N As Integer
        Dim amt, payment, rate, total As Double
        amt = Val(TextBox1.Text)
        rate = (Val(TextBox2.Text) / 100) / 12
        N = Val(TextBox3.Text) * 12
        payment = Pmt(rate, N, -amt, 0, 0)
        total = FV(rate, N, -payment, 0, 0)
        'Label5.Text = Format(payment, "$#,##0.00")
        Label5.Text = payment
        Label10.Text = total
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Dim x As New DataSet
        If datos.ejecutar_comandos("Insert into creditos values(" & TextBox1.Text & "," & TextBox2.Text & "," & TextBox3.Text & ",'" & Label5.Text & "','" & Label10.Text & "'," & TextBox12.Text & ")") = True Then
            MsgBox("Crédito Registrado", MsgBoxStyle.OkOnly, Title:="Financiera")
        Else
            MsgBox("Error, revise los datos", MsgBoxStyle.Critical, Title:="Financiera")
        End If
        x = datos.ejecutar_select("select * from creditos")
        Me.DataGridView1.DataSource = x.Tables(0)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim x As New DataSet
        If datos.ejecutar_comandos("delete from clientes where cod_cre=" & TextBox12.Text & "") = True Then
            MsgBox("Cliente Eliminado", MsgBoxStyle.OkOnly, Title:="Financiera")
        Else
            MsgBox("Error, revise los datos", MsgBoxStyle.Critical, Title:="Financiera")
        End If
        x = datos.ejecutar_select("select * from clientes")
        Me.DataGridView1.DataSource = x.Tables(0)
    End Sub

End Class

---------------------------------------------------------------------------------------
Creamos una clase llamada datos
Public Class datos
    Shared con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\DELL INSPIRON\Escritorio\vb.net\funciones financieras\financiera.mdb")'Ruta
    Shared Function ejecutar_select(ByVal consulta As String) As DataSet
        If CON.State = ConnectionState.Closed Then CON.Open()
        Dim da As New OleDb.OleDbDataAdapter(consulta, CON)
        Dim ds As New DataSet
        da.Fill(ds)
        CON.Close()
        Return ds
    End Function
    Shared Function ejecutar_comandos(ByVal comando As String) As Boolean
        If CON.State = ConnectionState.Closed Then CON.Open()
        Dim cm As New OleDb.OleDbCommand(comando, CON)
        Try
            cm.ExecuteNonQuery()
            Return True
        Catch ex As Exception
            Return False
        End Try
        CON.Close()
    End Function
End Class

Comentarios

Entradas populares de este blog

Google Glass llegará al mercado en 2014

Suma y Multiplicacion de Matrices php

Para Hombres griego