Sie sind auf Seite 1von 4

Imports System.

IO
Public Class Form1
Dim Ruta As String = "c:\"
Dim Archivo As String = "Factura.txt"
Dim cantidad, precio, subtotal, totalp, itbis, sumaTotal, SumaItbis,
sumatotalPago As Double
Sub limpiar()
Me.txtcantidad.Clear()
Me.txtcedula.Clear()
Me.txtciudad.Clear()
Me.txtcliente.Clear()
Me.txtcodart.Clear()
Me.txtdesc.Clear()
Me.txtdir.Clear()
Me.txtitbis.Clear()
Me.txtNofa.Clear()
Me.DataGridView1.Columns.Clear()
End Sub
Sub activar()
Me.GroupBox1.Enabled = True
Me.GroupBox2.Enabled = True
Me.Button2.Enabled = True
End Sub
Sub letras(ByVal e) 'solo letras
If (Not e.keychar.isletter(e.keychar)) Then
If Not (e.keychar = Convert.ToChar(Keys.Back)) Then
e.handled = True
End If
End If
End Sub
Sub numeros(ByVal e)
If (Not e.keychar.isnumber(e.keychar)) Then
If Not (e.keychar = Convert.ToChar(Keys.Back)) Then
e.handled = True
End If
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
limpiar()
activar()
'Me.txtNofa.Text = CInt(Me.txtNofa.Text) + 1
Me.txtfecha.Text = Today

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
limpiar()
End Sub

Private Sub txtcantidad_KeyDown(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyEventArgs) Handles txtcantidad.KeyDown
' Me.txtcodart.Focus()
End Sub

Private Sub txtcantidad_LostFocus(ByVal sender As Object, ByVal e As


System.EventArgs) Handles txtcantidad.LostFocus
cantidad = Val(Me.txtcantidad.Text)
precio = Val(Me.txtprecio.Text)
subtotal = cantidad * precio
sumaTotal = sumaTotal + subtotal
itbis = subtotal * 0.18
SumaItbis = SumaItbis + itbis
sumatotalPago = sumatotalPago + subtotal + itbis

Me.txtsub.Text = sumaTotal.ToString
Me.txtitbis.Text = SumaItbis.ToString
Me.txtTotalp.Text = sumatotalPago.ToString
Me.DataGridView1.Rows.Add(Me.txtcodart.Text, Me.txtdesc.Text,
Me.txtprecio.Text, Me.txtcantidad.Text, subtotal.ToString("##.00"),
itbis.ToString("##.00"))
Me.DataGridView1.ForeColor = Color.Blue
Me.DataGridView1.ColumnHeadersBorderStyle =
DataGridViewHeaderBorderStyle.Raised

guardar()
End Sub

Public Sub guardar()


Dim Escribir As New StreamWriter(Ruta & Archivo, True)
Try
Escribir.WriteLine("Codigo:" & Me.txtcodart.Text + "," + " "
& "Descripcion: " & Me.txtdesc.Text + "," + " " & "Cantidad: " &
Me.txtcantidad.Text + "," + " " & "Precio: " & Me.txtprecio.Text + "," +
" " & "Subtotal: " + Me.txtsub.Text + "," + " " & "Itbis: " &
Me.txtitbis.Text + "," + "Total Itbis:" & SumaItbis.ToString + "," +
"Total Factura:" & sumatotalPago.ToString)
Escribir.Close()
MessageBox.Show("Registro Guardado")
Catch ex As Exception
MessageBox.Show("Error al guardar registros")
End Try
End Sub

Private Sub txtcliente_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtcliente.KeyPress
letras(e)
End Sub

Private Sub txtcodart_LostFocus(ByVal sender As Object, ByVal e As


System.EventArgs) Handles txtcodart.LostFocus
If Me.txtcodart.Text = "01" Then
Me.txtdesc.Text = "Arroz La Garza Saco 25 libras"
Me.txtprecio.Text = 425
ElseIf Me.txtcodart.Text = "02" Then
Me.txtdesc.Text = "Aceite el Gallo galon grande"
Me.txtprecio.Text = 520
ElseIf Me.txtcodart.Text = "03" Then
Me.txtdesc.Text = "Bacalao Noruego libra"
Me.txtprecio.Text = 85.25
ElseIf Me.txtcodart.Text = "04" Then
Me.txtdesc.Text = "Harina de Maiz funda "
Me.txtprecio.Text = 12.3
ElseIf Me.txtcodart.Text = "05" Then
Me.txtdesc.Text = "Margarina Manicera 1/2 libra"
Me.txtprecio.Text = 42.1
ElseIf Me.txtcodart.Text = "06" Then
Me.txtdesc.Text = "Arroz AA Saco 110 libras"
Me.txtprecio.Text = 2100.0
Else
MsgBox("Codigo no existe")
Me.txtcodart.Clear()
Me.txtcodart.Focus()
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
Try
Dim ruta As String = "c:\factura.txt"
Using sr As New StreamReader(ruta, False)
Dim linea As String
While (linea = sr.ReadLine()) <> Nothing
Me.txtcodart.Text = linea
End While
End Using
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
facturar.Show()
End Sub
End Class