Sistema Ferreteria

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Create Database Ferreteria

Use Ferreteria
Create table Productos
(
idprod int primary key,
nomprod varchar(50),
precio int,
idcat int
)
Create table Categorias
(
idcate int primary key,
nomcate varchar(50)
)
Create table Empleados
(
idemp int identity primary key,
nomemp varchar(50),
clave varchar(12)
)
insert into Empleados (nomemp,clave) values ('oscar','12345')
insert into Empleados (nomemp,clave) values ('maria','54321')
Select * From Empleados
Public Class Form9
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value = ProgressBar1.Value + 1
If ProgressBar1.Value >= 100 Then
Timer1.Enabled = False
Form1.Show()
Me.Hide()
End If
End Sub
End Class
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1


Dim cn As New SqlConnection("Server=(local);Integrated
Security=yes;DataBase=Ferreteria")
Dim x As Integer

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


System.EventArgs) Handles Button1.Click
Dim sql As String
sql = "Select * From Empleados Where nomemp='" + TextBox1.Text + "'
and clave='" + TextBox2.Text + "'"
Dim cmd As New SqlCommand(sql, cn) 'Para capturar un registro de la
tabla
cn.Open()
Dim lector As SqlDataReader 'Se usa para leer el registro del Command
lector = cmd.ExecuteReader 'Lee la informacion del command y se lo da
al lector
If lector.Read Then
MsgBox("Bienvenido al Sistema", 32, "Gracias")
Form2.Show() 'Mostrar el Formulario2
Me.Hide() 'Ocultar al Formulario1
Else
x=x+1 'otra forma x += 1
MsgBox("Usuario o Clave Incorrecta", 16, "Cuidado")
limpiar()
If x > 2 Then
MsgBox("Cumplio sus 3 intentos", 16, "Gracias")
Close()
End If
End If
cn.Close()
End Sub
'Crear un procedimiento
Sub limpiar()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
End Class

Menu Principal

Public Class Form2

Private Sub NuevoToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
NuevoToolStripMenuItem.Click
Form3.MdiParent = Me
Form3.Show()
End Sub

Private Sub ProductosToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
ProductosToolStripMenuItem.Click
Form7.MdiParent = Me
Form7.Show()
End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles ToolStripButton1.Click
Form3.Show()
End Sub

Private Sub BuscarToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
BuscarToolStripMenuItem.Click
Form4.MdiParent = Me
Form4.Show()
End Sub

Private Sub EditarToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
EditarToolStripMenuItem.Click
Form5.MdiParent = Me
Form5.Show()
End Sub

Private Sub EliminarToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
EliminarToolStripMenuItem.Click
Form6.MdiParent = Me
Form6.Show()
End Sub

Private Sub EmpleadosToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
EmpleadosToolStripMenuItem.Click
Form8.MdiParent = Me
Form8.Show()
End Sub

Private Sub ArchivoToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
ArchivoToolStripMenuItem.Click

End Sub
End Class
Imports System.Data
Imports System.Data.SqlClient

Public Class Form3


Dim cn As New SqlConnection("Server=(local);Integrated
Security=yes;DataBase=Ferreteria")

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


System.EventArgs) Handles Button2.Click
Dim sql As String
sql = "Insert into Categorias (idcate,nomcate) values
(@idcate,@nomcate)"
Dim cmd As New SqlCommand(sql, cn) 'capturo el Insert
cn.Open()
cmd.Parameters.AddWithValue("@idcate", TextBox1.Text) 'Alimento el
parametro
cmd.Parameters.AddWithValue("@nomcate", TextBox2.Text)
cmd.ExecuteNonQuery() 'Executo la sentencia del Insert
cn.Close()
MsgBox("Registro Guardado Correctamente", 32, "Gracias")
limpiar()
activar(False)
End Sub
Sub limpiar() 'Este es un procedimiento General
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub

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


System.EventArgs) Handles Button1.Click
activar(True)
limpiar()
End Sub
Sub activar(ByVal x As Boolean) 'Boolean significa Verdadero o Falso
TextBox1.Enabled = x
TextBox2.Enabled = x
Button2.Enabled = x
Button1.Enabled = Not x
End Sub
End Class

Imports System.Data
Imports System.Data.SqlClient
Public Class Form4
Dim cn As New SqlConnection("Server=(local);Integrated
Security=yes;DataBase=Ferreteria")
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim sql As String
sql = "Select * From Categorias Where idcate=" & TextBox1.Text
Dim cmd As New SqlCommand(sql, cn)
cn.Open()
Dim lector As SqlDataReader 'Sirve para leer la Data del command
lector = cmd.ExecuteReader 'Lee el Select del command
If lector.Read Then
TextBox2.Text = lector(1).ToString
Else
MsgBox("Codigo no Existe", 16, "Aviso")
End If
TextBox1.Clear()
TextBox1.Focus()
cn.Close()
End Sub
End Class

Imports System.Data
Imports System.Data.SqlClient
Public Class Form5
Dim cn As New SqlConnection("Server=(local);Integrated
Security=yes;DataBase=Ferreteria")
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim sql As String
sql = "Select * From Categorias Where idcate=" & TextBox1.Text
Dim cmd As New SqlCommand(sql, cn)
cn.Open()
Dim lector As SqlDataReader
lector = cmd.ExecuteReader
If lector.Read Then
TextBox2.Text = lector(1).ToString
Else
MsgBox("Codigo no Existe", 16, "Aviso")
End If
cn.Close()
activar(True)
End Sub
Sub activar(ByVal x As Boolean)
TextBox1.Enabled = Not x
TextBox2.Enabled = x
Button2.Enabled = Not x
Button1.Enabled = x
Button3.Enabled = Not x
End Sub

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


System.EventArgs) Handles Button1.Click
Dim sql As String
sql = "Update Categorias SET nomcate='" & TextBox2.Text & "' Where
idcate=" & TextBox1.Text
Dim cmd As New SqlCommand(sql, cn)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
MsgBox("Dato Modificado Correctamente", 32, "Gracias")
activar(False)
limpiar()
End Sub
Sub limpiar()
TextBox1.Clear()
TextBox2.Clear()
TextBox1.Focus()
End Sub

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


System.EventArgs) Handles Button3.Click
activar(False)
limpiar()
End Sub
End Class

Imports System.Data
Imports System.Data.SqlClient

Public Class Form6


Dim cn As New SqlConnection("Server=(local);Integrated
Security=yes;DataBase=Ferreteria")
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim sql As String
sql = "Select * From Categorias Where idcate=" & TextBox1.Text
Dim cmd As New SqlCommand(sql, cn)
cn.Open()
Dim lector As SqlDataReader
lector = cmd.ExecuteReader
If lector.Read Then
TextBox2.Text = lector(1).ToString
Else
MsgBox("Codigo no Existe", 16, "Aviso")
End If
cn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sql As String
sql = "Delete From Categorias where idcate=" & TextBox1.Text
Dim cmd As New SqlCommand(sql, cn)
cn.Open()
cmd.ExecuteNonQuery() 'Se usa ExecuteNonQuery para
Insert,Update,Delete
cn.Close()
MsgBox("Registro Eliminado Correctamente", 32, "Aviso")
limpiar()
End Sub
Sub limpiar()
TextBox1.Clear()
TextBox2.Clear()
TextBox1.Focus()
End Sub
End Class
Imports System.Data
Imports System.Data.SqlClient

Public Class Form10


Dim cn As New SqlConnection("Server=(local);Integrated
Security=yes;DataBase=Ferreteria")
Dim ds As DataSet
Dim da As SqlDataAdapter
Dim dr As DataRow 'Para detectar las FILAS(Row) de datos
Dim estado As String
Dim pos, tot, fil, col As Integer 'Para la posicion
Dim sql As String 'Para las sentencias

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


System.EventArgs) Handles MyBase.Load
Verdatos2()
botones(True)
verdatos()
textos(False)
End Sub
Sub Verdatos2()
da = New SqlDataAdapter("Select * From Empleados", cn)
ds = New DataSet
cn.Open()
da.Fill(ds, "empleados")
cn.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = "empleados"
End Sub
Sub botones(ByVal ver As Boolean)
Button1.Enabled = ver
Button2.Enabled = ver
Button3.Enabled = ver
Button4.Enabled = Not ver
Button5.Enabled = ver
End Sub
Sub limpiar()
Label1.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Sub textos(ByVal ver As Boolean)
TextBox1.Enabled = ver
TextBox2.Enabled = ver
End Sub
Sub verdatos()
tot = DataGridView1.GetCellCount(DataGridViewElementStates.Selected)
'Capturo total de registros
If tot > 0 Then 'Si hay registros
fil = DataGridView1.SelectedCells(pos).RowIndex.ToString
col = DataGridView1.SelectedCells(pos).ColumnIndex.ToString
Label2.Text = DataGridView1.Item(col, fil).Value
TextBox1.Text = DataGridView1.Item(col + 1, fil).Value
TextBox2.Text = DataGridView1.Item(col + 2, fil).Value
End If
End Sub

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


System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellClick
verdatos()
End Sub

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


System.EventArgs) Handles Button1.Click
textos(True)
limpiar()
botones(False)
estado = "Nuevo"
End Sub

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


System.EventArgs) Handles Button2.Click
textos(True)
estado = "Modificar"
botones(False)
End Sub

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


System.EventArgs) Handles Button4.Click
If estado = "Nuevo" Then
If MsgBox("Desea Grabar el Nuevo Registro?", MsgBoxStyle.YesNo,
"Aviso") = vbYes Then
cn.Open()
dr = ds.Tables("empleados").NewRow
dr(1) = TextBox1.Text
dr(2) = TextBox2.Text
ds.Tables("empleados").Rows.Add(dr)
Dim cb As New SqlCommandBuilder(da)
da.Update(ds, "empleados")
ds.Tables(0).AcceptChanges()
botones(True)
limpiar()
textos(True)
cn.Close()

End If
Else
If estado = "Modificar" Then
If MsgBox("Desear Actualizar los cambios del Registro",
MsgBoxStyle.YesNo, "Aviso") = vbYes Then
cn.Open()
dr = ds.Tables("empleados").Rows(fil)
dr(1) = TextBox1.Text
dr(2) = TextBox2.Text
Dim cb As New SqlCommandBuilder(da)
da.Update(ds, "empleados")
ds.Tables(0).AcceptChanges()
botones(True)
textos(True)
limpiar()
cn.Close()
End If
End If
End If
estado = ""
Verdatos2()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If MsgBox("Desea eliminar el Registro?", MsgBoxStyle.YesNo, "Aviso") =
vbYes Then
dr = ds.Tables("empleados").Rows(fil)
dr.Delete()
Dim del As New DataTable
Dim cb As New SqlCommandBuilder(da)
del = ds.Tables("empleados").GetChanges(DataRowState.Deleted)
da.Update(del)
ds.Tables("empleados").AcceptChanges()
textos(False)
verdatos()
End If
End Sub

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


System.EventArgs) Handles Button5.Click
If MsgBox("Esta seguro que desea Salir?", MsgBoxStyle.YesNo, "Adios")
= vbYes Then
Me.Close()
End If
End Sub
End Class

You might also like