Uploaded on

vb 2010

vb 2010

More in: Sports
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
220
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
9
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Imports System.Data.OleDb Para poder trabajar con base de datos enaccessImports System.Windows.FormsPublic Class Form1 Declaración de variables u objetos globales Dim Comando As OleDbCommand Dim Adaptador As OleDbDataAdapter Dim Conexion As OleDbConnection Dim Ds As New DataSet Dim idRecepciondeArticulopantalla As String Dim idempleadospantalla As String Dim numerocuentapantalla As String Dim idarticulospantalla As String Dim comandoactualizar As String Dim Leer As OleDbDataReader Dim total As Single Private Sub Acceso() Dim A As String A = "Select IdEmpleado,NombreEmpleado from [ENTRADA AL SISTEMA]" Comando = New OleDbCommand(A, Conexion) Conexion.Open() leer = Comando.ExecuteReader If leer.Read = True Then Me.lblidempleado.Text = leer("IdEmpleado") Me.lblnombreEmpleado.Text = leer("NombreEmpleado") End If leer.Close() Conexion.Close() End Sub Private Sub Acceso1() Dim A As String Dim leer As OleDbDataReader A = "Select IdEmpleado,NombreEmpleado from [ENTRADA AL SISTEMA]" Comando = New OleDbCommand(A, Conexion) Conexion.Open() leer = Comando.ExecuteReader If leer.Read = True Then Me.lblidempleado.Text = leer("IdEmpleado") lblnombreEmpleado.Text = leer("NombreEmpleado") End If leer.Close() Conexion.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load Me.lblFecha.Text = Format(DateTime.Now, "dd/MM/yyyy") Conexion = NewOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
  • 2. Source=C:Usershr.tavarezDesktopWindowsApplication1(TAREA2)DataCXP.mdb") Acceso() Acceso1() total = 0 End Sub Private Sub txtidsuplidor_Click(ByVal sender As System.Object, ByVale As System.EventArgs) End Sub Private Sub PresentarDatosProveedor(ByVal X As String) Ds.Clear() Try Conexion.Open() Comando = New OleDbCommand(X, Conexion) Adaptador = New OleDbDataAdapter(Comando) Adaptador.Fill(Ds, "Suplidores") Me.dgvsup.DataSource = Ds Me.dgvsup.DataMember = "Suplidores" Catch ex As Exception MessageBox.Show(ex.Message) Finally Conexion.Close() End Try End Sub Private Sub PresentarDatosProveedor1(ByVal X As String) Ds.Clear() Try Conexion.Open() Comando = New OleDbCommand(X, Conexion) Adaptador = New OleDbDataAdapter(Comando) Adaptador.Fill(Ds, "Suplidores") Me.dgvsup.DataSource = Ds Me.dgvsup.DataMember = "Suplidores" Catch ex As Exception MessageBox.Show(ex.Message) Finally Conexion.Close() End Try End Sub Private Sub refrescar(ByVal A As String) Conexion.Open() Comando = New OleDbCommand(A, Conexion) Comando.ExecuteNonQuery() Ejecuta un update o insert que nodevuelve nada
  • 3. Conexion.Close() End Sub Private Sub txtnomsup_TextChanged_1(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles txtnomsup.TextChanged Filtro los datos del proveedor por el nombre PresentarDatosProveedor("Select IdSuplidor, Nombre fromSuplidores where Nombre like %" + txtnomsup.Text + "%") End Sub Private Sub txtcantidad_Click_1(ByVal sender As System.Object, ByVale As System.EventArgs) Handles txtcantidad.Click Dim A As String Dim leer As OleDbDataReader A = "Select IdArtículo,Descripción,Precio,ITBIS from[ARTICULOSOSERVICIOS] where IdArtículo like %" + Me.txtidarticulo.Text +"%" Comando = New OleDbCommand(A, Conexion) Conexion.Open() leer = Comando.ExecuteReader If leer.Read = True Then Me.lblidarticulo.Text = leer("Descripción") Me.lblprecio.Text = leer("Precio") Me.lblitbis.Text = leer("ITBIS") End If leer.Close() Conexion.Close() End Sub Private Sub btnbajar_Click_1(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles btnbajar.Click validamos que no esten los objetos en blanco antes de bajar If Me.txtidarticulo.Text = String.Empty Or Me.lblidarticulo.Text= String.Empty Or Me.lblprecio.Text = String.Empty Or Me.lblitbis.Text =String.Empty Or Me.txtcantidad.Text = String.Empty Then MessageBox.Show("Debes llenar los datos antes de bajar","Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If Aumentar la existencia de los articulos comandoactualizar = "Update ARTICULOSOSERVICIOS setCantidad=Cantidad+ " & Me.txtcantidad.Text & " where IdArtículo =val("& Me.txtidarticulo.Text & ")" refrescar(comandoactualizar) Agregando Filas en el DataGridView If Me.lblitbis.Text = "True" Then Me.lblitbis.Text = Val(Me.lblprecio.Text) * 0.16 Else Me.lblitbis.Text = 0 End If Me.dgvrecepcion.Rows.Add(Me.txtidarticulo.Text,Me.lblidarticulo.Text, Me.lblprecio.Text, Me.lblitbis.Text,Me.txtcantidad.Text, Me.lblprecio.Text * Me.txtcantidad.Text)
  • 4. total = total + (Me.lblprecio.Text * Me.txtcantidad.Text) Me.lblmontototal.Text = Format(total, "currency") Me.txtidarticulo.Text = "" Me.lblidarticulo.Text = "" Me.lblprecio.Text = "" Me.lblitbis.Text = "" Me.txtcantidad.Text = "" Me.txtidarticulo.Focus() End Sub Private Sub btnguardar_Click_1(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles btnguardar.Click Dim I As Integer Para validar las entradas del usuario If txtidsuplidor.Text = "" Or lblidsuplidor.Text = "" Ortxtfactura.Text = "" Then MsgBox("Debes llenar todos los datos antes de guardar",MsgBoxStyle.Information, "Aviso") Exit Sub End If Determino el tipo de recepcion If Me.rdbcredito.Checked = True Then Me.lbltipofactura.Text = "Cr" Me.lblsaldada.Text = "0" Me.lblmontoadeudado.Text = Me.lblmontototal.Text Modifico la deuda en la tabla de proveedor comandoactualizar = "Update suplidores set Balance=Balance +" & Me.lblmontototal.Text & " where IdSuplidor =val(" &txtidsuplidor.Text & ")" refrescar(comandoactualizar) Else Me.lbltipofactura.Text = "Co" Me.lblsaldada.Text = "1" Me.lblmontoadeudado.Text = "0" End If Guardo en detalle de recepcion comandoactualizar = "Insert into RECEPCIONARTICULOS (IdEmpleado,IdSuplidor,FechaRecepción,MontoRecepción,NúmeroFacturaSuplidor,FechaVencimiento,MontoAdeudado,Saldada,TipoFacturaSuplidor) values (" & Me.lblidempleado.Text& "," & Me.txtidsuplidor.Text & "," & Me.lblFecha.Text & "," &Me.lblmontototal.Text & "," & Me.txtfactura.Text & "," &dtpfactura.Text & "," & Me.lblmontoadeudado.Text & "," &Me.lblsaldada.Text & "," & Me.lbltipofactura.Text & " )" refrescar(comandoactualizar) invoco procedimiento NumeroRecepcionGerado() invoco procedimiento Guardo en la tabla detalle de recepción For I = 0 To Me.dgvrecepcion.RowCount - 2 comandoactualizar = "Insert intoDETALLERECEPCION(NúmeroRecepción,IdArtículo, Cantidad, ITBIS, Precio )values (val(" & Me.LBlNumRec.Text & "), " &Me.dgvrecepcion.Rows(I).Cells(0).Value & ", " &
  • 5. Me.dgvrecepcion.Rows(I).Cells(4).Value & ", val(" &Me.dgvrecepcion.Rows(I).Cells(3).Value & ")," &Me.dgvrecepcion.Rows(I).Cells(2).Value & ")" refrescar(comandoactualizar) invoco procedimiento Next limpiar() End Sub Private Sub txtidsuplidor_Click_1(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles txtidsuplidor.Click Me.txtnomsup.Visible = True Me.dgvsup.Visible = True Me.txtnomsup.Focus() invoco procedimiento para visualizar supliddores PresentarDatosProveedor("Select IdSuplidor, Nombre fromSuplidores ") End Sub Private Sub dgvsup_Click_1(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles dgvsup.Click Me.txtidsuplidor.Text = Me.dgvsup.CurrentRow.Cells(0).Value Me.lblidsuplidor.Text = Me.dgvsup.CurrentRow.Cells(1).Value Ocultamos el dgvsup y textnomsup Me.dgvsup.Visible = False Me.txtnomsup.Visible = False Me.txtfactura.Focus() End Sub Private Sub NumeroRecepcionGerado() Try Busco el máximo número de recepción que se generó en latabla RECEPCIONARTICULOS Me.comandoactualizar = "SELECT MAX(NúmeroRecepción) AS NUMEROFROM RECEPCIONARTICULOS" Conexion.Open() Comando = New OleDbCommand(comandoactualizar, Conexion) Leer = Comando.ExecuteReader() Leyendo el resultado delselect If Leer.Read Then Me.LBlNumRec.Text = Leer("NUMERO") End If Conexion.Close() Leer.Close() Cerrando el objeto de lectura Catch ex As Exception MsgBox("Ha ocurrido un error buscando el numero demantenimiento: " & ex.Message) End Try End Sub Private Sub limpiar() Me.lblidsuplidor.Text = "" Me.txtidsuplidor.Text = "" txtfactura.Text = ""
  • 6. Me.dgvrecepcion.Rows.Clear() Me.lblmontototal.Text = "" End SubEnd Class