Imports Imports Public Class Dim As New Dim As New Dim As New Private Sub Byval As Byval As Handles Mybase
Imports Imports Public Class Dim As New Dim As New Dim As New Private Sub Byval As Byval As Handles Mybase
Imports Imports Public Class Dim As New Dim As New Dim As New Private Sub Byval As Byval As Handles Mybase
Data Imports Npgsql Public Class Form1 Dim oConexio As New NpgsqlConnection("server=localhost; port=5432; user id=postgres; password=123456;database=majes_catastro") Dim oDataAda As New NpgsqlDataAdapter("Select * from catastro.tf_personas", oConexio) Dim oDataSet As New DataSet Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load oDataAda.Fill(oDataSet) DataGridView1.DataSource = oDataSet.Tables(0) TextBox6.Text = DataGridView1.RowCount.ToString
End Sub
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click Dim row As DataGridViewRow = DataGridView1.CurrentRow Dim fila As DataRow 'If row IsNot Nothing Then 'MessageBox.Show(row.Index) ' End If DataGridView1.Refresh() fila = oDataSet.Tables(0).Rows(row.Index) TextBox1.Text = fila("Nombres") TextBox2.Text = fila("ape_paterno") TextBox3.Text = fila("ape_materno") TextBox4.Text = fila("nume_doc") End Sub Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress If e.KeyChar = ChrW(Keys.Enter) Then MsgBox("Not hay Registros") End If
End Sub Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
Dim oConexio As New NpgsqlConnection("server=localhost; port=5432; user id=postgres; password=123456;database=majes_catastro") Dim oDataAda As New NpgsqlDataAdapter("Select * from catastro.tf_personas where nombres LIKE '" & Trim(TextBox5.Text) & "%'", oConexio) Dim oDataSet As New DataSet oConexio.Open() oDataAda.Fill(oDataSet, "tf_personas") DataGridView1.DataSource = oDataSet.Tables(0) DataGridView1.Refresh()
CREAMOS EL MODULO DE CONEXIN Y UNA FUNCIN DE CONSULTA POR MEDIO DE TABLA DE DATOS
Module Module1 Public CN As New SqlConnection("Integrated Security=True;Initial Catalog=BDFactura;data source=a3_16") Function CargarDatos(ByVal CadSQL As String) As DataTable Dim Da As New SqlDataAdapter(CadSQL, CN)
Dim Tabla As New DataTable Da.Fill(Tabla) Return Tabla End Function End Module
AS MISMO AHORA CODIFICA LOS EVENTOS DEL FORMULARIO Public Class Form1
Dim DvCliente As New DataView Dim DvArticulos As New DataView Dim Tabla As New DataTable Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DvCliente = CargarDatos("Select * from Clientes").DefaultView DvCliente.Sort = "Cli_Codigo" DvArticulos = CargarDatos("Select * from articulos").DefaultView DvArticulos.Sort = "Art_Codigo" 'Creando tabla Temporal Tabla.Columns.Add("CodArti", GetType(String)) Tabla.Columns.Add("NomArti", GetType(String)) Tabla.Columns.Add("Precio", GetType(Double)) Tabla.Columns.Add("Canti", GetType(Integer)) Tabla.Columns.Add("Monto", GetType(Double)) Me.DataGridView1.DataSource = Tabla End Sub Private Sub cmdagregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdagregar.Click Dim F As DataRow F = Tabla.NewRow F("CodArti") = Me.TxtCodArti.Text F("NomArti") = Me.TxtNomArti.Text F("Precio") = Me.txtprecio.Text F("Canti") = Me.txtcanti.Text F("Monto") = F("precio") * F("Canti") Tabla.Rows.Add(F) End Sub
Private Sub txtcodcli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcodcli.KeyPress If Asc(e.KeyChar) = 13 Then Dim P As Integer P = DvCliente.Find(Me.txtcodcli.Text) If P < 0 Then MessageBox.Show("Cliente no existe...") Else Me.txtnomcli.Text = DvCliente.Item(P).Row("Cli_nombre") Me.txtruccli.Text = DvCliente.Item(P).Row("Cli_ruc") Me.txtdircli.Text = DvCliente.Item(P).Row("Cli_direccion") End If End If End Sub
If P < 0 Then MessageBox.Show("Articulo no existe") Else Me.TxtNomArti.Text = DvArticulos.Item(P).Row("Art_nombre") Me.txtprecio.Text = DvArticulos.Item(P).Row("Art_Precio") Me.txtstock.Text = DvArticulos.Item(P).Row("Art_Stock") End If End If End Sub
Private Sub cmdgrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdgrabar.Click Dim I As Integer
Dim Cmd As New SqlCommand If CN.State = ConnectionState.Closed Then CN.Open() End If Cmd.Connection = CN 'Grabando Cabecera Cmd.CommandText = "Insert into fac_cabe values(@num,@fec,@clicod,@igv)" Cmd.Parameters.Add("@num", SqlDbType.VarChar, 5).Value = Me.txtnum.Text Cmd.Parameters.Add("@fec", SqlDbType.DateTime).Value = Date.Today Cmd.Parameters.Add("@clicod", SqlDbType.VarChar, 5).Value = Me.txtcodcli.Text Cmd.Parameters.Add("@igv", SqlDbType.VarChar, 1).Value = "S" Cmd.ExecuteNonQuery() 'Grabando Detalle
For I = 0 To Tabla.Rows.Count - 1
Cmd.Parameters.Clear() Cmd.CommandText = "Insert into fac_deta values(@numDETA,@codarti,@canti)" Cmd.Parameters.Add("@numDETA", SqlDbType.VarChar, 5).Value = Me.txtnum.Text Cmd.Parameters.Add("@codarti", SqlDbType.VarChar, 5).Value = Tabla.Rows(I).Item("CodArti") Cmd.Parameters.Add("@canti", SqlDbType.Int).Value = Tabla.Rows(I).Item("Canti") Cmd.ExecuteNonQuery() Next If CN.State = ConnectionState.Open Then CN.Close() End If Cmd.Dispose() End Sub
End Class