116 lines
3.8 KiB
VB.net
116 lines
3.8 KiB
VB.net
Imports System.Data.SqlClient
|
|
|
|
Public Class frmPatrones
|
|
Private ds As New DataSet
|
|
Private adapter As SqlDataAdapter
|
|
Private cls As clsComplejo
|
|
|
|
Private Sub frmPatrones_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
Iniciar()
|
|
DesHeader.Text = Me.Text
|
|
End Sub
|
|
|
|
Private Function llenarCombos() As Boolean
|
|
llenarCombos = False
|
|
Try
|
|
cls = New clsComplejo()
|
|
cls.sbLlenaCombo("spLlenaComboProducto", Me.cboProducto)
|
|
|
|
cls = New clsComplejo()
|
|
cls.sbLlenaCombo("spLlenaComboPatronProducto", Me.cboPatron)
|
|
|
|
Limpiar()
|
|
Catch ex As Exception
|
|
MessageBox.Show(ex.Message)
|
|
End Try
|
|
llenarCombos = True
|
|
End Function
|
|
|
|
Private Function Limpiar() As Boolean
|
|
Limpiar = False
|
|
Try
|
|
cboProducto.SelectedIndex = -1
|
|
cboPatron.SelectedIndex = -1
|
|
Catch ex As Exception
|
|
MessageBox.Show(ex.Message)
|
|
End Try
|
|
Limpiar = True
|
|
End Function
|
|
|
|
Private Function Iniciar() As Boolean
|
|
Try
|
|
GrdPatrones.DataSource = Nothing
|
|
GrdPatrones.ClearFields()
|
|
GrdPatrones.Refresh()
|
|
llenarCombos()
|
|
LlenarGrid()
|
|
Catch ex As Exception
|
|
MessageBox.Show(ex.Message)
|
|
End Try
|
|
End Function
|
|
|
|
Private Function LlenarGrid() As Boolean
|
|
Dim Ssql As String
|
|
ds.Clear()
|
|
|
|
Try
|
|
cls = New clsComplejo()
|
|
cls.sbConectaBD()
|
|
Ssql = "SELECT idPP,NombrePP,Activo FROM CAT_PATRONPRODUCTO WHERE 1=1 and Status=1"
|
|
If cboPatron.SelectedIndex <> -1 Or cboProducto.SelectedIndex <> -1 And (cboPatron.Items.Count > 0 And cboProducto.Items.Count > 0) Then
|
|
Ssql += " AND idPatron = " & IIf(cboPatron.SelectedIndex = -1, "idPatron", cboPatron.SelectedValue)
|
|
Ssql += " AND idProducto = " & IIf(cboProducto.SelectedIndex = -1, "idProducto", cboProducto.SelectedValue)
|
|
End If
|
|
adapter = New SqlDataAdapter(Ssql, cls.cn)
|
|
adapter.Fill(ds, "CAT_PATRONPRODUCTO")
|
|
GrdPatrones.SetDataBinding(ds, "CAT_PATRONPRODUCTO")
|
|
GrdPatrones.Splits(0).DisplayColumns(1).Locked = True
|
|
GrdPatrones.Splits(0).DisplayColumns(0).Visible = False
|
|
GrdPatrones.Splits(0).DisplayColumns(1).AutoSize()
|
|
Catch ex As Exception
|
|
'MessageBox.Show(ex.Message)
|
|
End Try
|
|
End Function
|
|
|
|
Private Function Guardar() As Boolean
|
|
Try
|
|
Dim build As New SqlCommandBuilder(adapter)
|
|
adapter.Update(ds, "CAT_PATRONPRODUCTO")
|
|
MessageBox.Show("Registros guardados con éxito")
|
|
Salir()
|
|
Catch ex As Exception
|
|
MessageBox.Show(ex.Message)
|
|
End Try
|
|
End Function
|
|
|
|
Private Function Salir() As Boolean
|
|
Try
|
|
If cls.cn.State = ConnectionState.Open Then
|
|
cls.sbCierraCn()
|
|
End If
|
|
Close()
|
|
Catch ex As Exception
|
|
MessageBox.Show(ex.Message)
|
|
End Try
|
|
End Function
|
|
|
|
Private Sub cboPatron_SelectedValueChanged(sender As System.Object, e As System.EventArgs) Handles cboPatron.SelectedValueChanged
|
|
LlenarGrid()
|
|
End Sub
|
|
|
|
Private Sub cboProducto_SelectedValueChanged(sender As System.Object, e As System.EventArgs) Handles cboProducto.SelectedValueChanged
|
|
LlenarGrid()
|
|
End Sub
|
|
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnCerrar.Click
|
|
Salir()
|
|
End Sub
|
|
|
|
Private Sub btnLimpiar_Click(sender As Object, e As EventArgs) Handles btnLimpiar.Click
|
|
Limpiar()
|
|
End Sub
|
|
|
|
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnGuardar.Click
|
|
Guardar()
|
|
End Sub
|
|
End Class |