Вы находитесь на странице: 1из 18

PRACTICA DE MANTENIMIENTO ADO.

net
Imports System.Data
Imports System.Data.SqlClient
Public Class Categoria
Public cnx2 As New SqlConnection("user i! sa" ser#er! . "atabase! minieu"$
Public ap2 As New SqlDataAapter("select % &rom categoria"' cnx2$
Public st2 As New DataSet
Public cm2 As New SqlComman
Public cont
Pri#ate Sub Categoria()oa(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles 0y*ase.)oa
ap2.1ill(st2' "cat"$
cont ! 2
I& st2.3ables("cat"$.4ows.Count 56 2 37en
Call mostrar(categoria(cont$
.n I&
.n Sub
Pri#ate Sub mostrar(categoria(*y+al a As Integer$
txtCoCat.3ext ! st2.3ables("cat"$.4ows(a$.Item(2$
txtNomCat.3ext ! st2.3ables("cat"$.4ows(a$.Item(8$
.n Sub
Pri#ate Sub 7ab(Categoria(*y+al a As *oolean' *y+al b As *oolean' *y+al c As *oolean$
btnNue#oCat..nable ! a
btn0oi&icarCat..nable ! b
btn.liminarCat..nable ! c
.n Sub
Pri#ate Sub btnNue#oCat(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnNue#oCat.Clic9
I& btnNue#oCat.3ext ! "Nue#o" 37en
txtCoCat.3ext ! "" : txtNomCat.3ext ! ""
Call 7ab(Categoria(3rue' 1alse' 1alse$
btnNue#oCat.3ext ! ";rabar"
txtNomCat.1ocus($
.lseI& btnNue#oCat.3ext ! ";rabar" 37en
Dim co(c<' tmpc<' iuec=
I& st2.3ables("cat"$.4ows.Count ! 2 37en
co(c ! "222"
.lse
iuec ! st2.3ables("cat"$.4ows.Count > 8
co(c ! st2.3ables("cat"$.4ows(iuec$.Item(2$
.n I&
tmpc ! Str(+al(0i(co(c' 2$$ ? 8$
co(c ! 0i(co(c' 8' @ > )en(3rim(tmpc$$$ A 3rim(tmpc$
txtCoCat.3ext ! co(c
cnx2.,pen($
cm2 ! New SqlComman("insert into categoria #alues(B" A txtCoCat.3ext A "B'B" A txtNomCat.3ext A "B$"' cnx2$
cm2..xecuteScalar($
cm2.Dispose($
cnx2.Close($
0sg*ox("Datos almacenaos correctamente"' ' "Atencion"$
st2.3ables("cat"$.Clear($
ap2.SelectComman.Comman3ext ! "select % &rom categoria"
ap2.1ill(st2' "cat"$
cont ! st2.3ables("cat"$.4ows.Count > 8
Call 7ab(Categoria(3rue' 3rue' 3rue$
btnNue#oCat.3ext ! "Nue#o"
.n I&
.n Sub
Pri#ate Sub btn0oi&icarCat(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btn0oi&icarCat.Clic9
I& btn0oi&icarCat.3ext ! "0oi&icar" 37en
Call 7ab(Categoria(1alse' 3rue' 1alse$
btn0oi&icarCat.3ext ! "Con&irmar"
txtNomCat.1ocus($
.lseI& btn0oi&icarCat.3ext ! "Con&irmar" 37en
cnx2.,pen($
cm2 ! New SqlComman("upate categoria set nomCat!B" A txtNomCat.3ext A "Bw7ere iCat!B" A txtCoCat.3ext A "B"' cnx2$
cm2..xecuteScalar($
cm2.Dispose($
cnx2.Close($
0sg*ox("Se actualiCaron los atos correctamente"' ' "Atencion"$
st2.3ables("cat"$.Clear($
ap2.SelectComman.Comman3ext ! "select % &rom categoria"
ap2.1ill(st2' "cat"$
Call 7ab(Categoria(3rue' 3rue' 3rue$
btn0oi&icarCat.3ext ! "0oi&icar"
.n I&
.n Sub
Pri#ate Sub btn.liminarCat(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btn.liminarCat.Clic9
Dim 0 As ,b-ect ! 0sg*ox("DEste #a 7a eliminar un registroF"' 0sg*oxStyle.GesNo' "CuiaoH"$
I& 0 ! I 37en
cnx2.,pen($
cm2 ! New SqlComman("elete categoria w7ere iCat!B" A txtCoCat.3ext A "B"' cnx2$
cm2..xecuteScalar($
cm2.Dispose($
cnx2.Close($
0sg*ox(")os atos se eliminaron correctamente"' ' "Atencion"$
st2.3ables("cat"$.Clear($
ap2.SelectComman.Comman3ext ! "select % &rom categoria"
ap2.1ill(st2' "cat"$
cont >! 8
I& cont 5 2 37en
0sg*ox("Acaba e eliminar el ultimo registro"' 0sg*oxStyle..xclamation' "CuiaoH"$
txtCoCat.3ext ! "" : txtNomCat.3ext ! ""
.n I&
I& st2.3ables("cat"$.4ows.Count 56 2 37en
Call mostrar(categoria(cont$
.n I&
.n I&
.n Sub
Pri#ate Sub btnPrimeroCat(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnPrimeroCat.Clic9
cont ! 2
Call mostrar(categoria(cont$
.n Sub
Pri#ate Sub btnAnteriorCat(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnAnteriorCat.Clic9
cont >! 8
I& cont 5 2 37en
cont ! 2
0sg*ox(")lego al primer registro"' '"Atencion"$
Call mostrar(categoria(cont$
.n I&
Call mostrar(categoria(cont$
.n Sub
Pri#ate Sub btnsiguienteCat(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnsiguienteCat.Clic9
cont ?! 8
I& cont 6 (st2.3ables("cat"$.4ows.Count > 8$ 37en
cont ! st2.3ables("cat"$.4ows.Count > 8
0sg*ox(")lego al ultimo registro"' ' "Atencion"$
Call mostrar(categoria(cont$
.n I&
Call mostrar(categoria(cont$
.n Sub
Pri#ate Sub btnEltimoCat(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnEltimoCat.Clic9
cont ! st2.3ables("cat"$.4ows.Count > 8
Call mostrar(categoria(cont$
.n Sub
.n Class
Imports System.Data
Imports System.Data.Sqlclient
Public Class 1rmmantenimtosinproce
Pri#ate Cnx As New SqlConnection("Eser i!sa"passwor!82@JKI"ser#er!."atabase!neptuno"$
Pri#ate Dap As New SqlDataAapter("S.).C3 IProucto' NombreProucto' IPro#eeor' ICategorLa' PrecioEnia' Eniaes.n.xistencia 14,0
Prouctos"' Cnx$
Pri#ate cm As New SqlComman
Pri#ate Dst As New DataSet
Public & As Integer
Pri#ate Sub 1rmmantenimtosinproce()oa(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles 0y*ase.)oa
Dap.1ill(Dst' "prouctos"$
grproucto.DataSource ! Dst.3ables("prouctos"$
Dap.SelectComman.Comman3ext ! "Select % 1rom categorLas"
Dap.1ill(Dst' "categorias"$
Mit7 cboCategoria
.DataSource ! Dst.3ables("Categorias"$
.Display0ember ! "NombreCategorLa"
.+alue0ember ! "ICategorLa"
.n Mit7
Dap.SelectComman.Comman3ext ! "Select % 1rom pro#eeores"
Dap.1ill(Dst' "pro#eeor"$
Mit7 cboPro#eeor
.DataSource ! Dst.3ables("pro#eeor"$
.Display0ember ! "NombreCompaNLa"
.+alue0ember ! "Ipro#eeor"
.n Mit7
.n Sub

Pri#ate Sub grproucto(Clic9(*y+al sener As ,b-ect' *y+al e As System..#entArgs$ /anles grproucto.Clic9
0ostrarDatos($
.n Sub
Pri#ate Sub btnAicionar(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnAicionar.Clic9
I& btnAicionar.3ext ! "Nue#o" 37en
txtCoigo.3ext ! "" : txtNombre.3ext ! "" : txtPrecio.3ext ! "" : txtStoc9.3ext ! ""
BCall 7ab(Categoria(3rue' 1alse' 1alse$
btnAicionar.3ext ! ";rabar"
txtNombre.1ocus($
.lseI& btnAicionar.3ext ! ";rabar" 37en
Cnx.,pen($
cm ! New SqlComman("insert into Prouctos(NombreProucto'Ipro#eeor'IcategorLa'PrecioEnia'Eniaes.n.xistencia$ #alues(B" A
txtNombre.3ext A "B'B" A cboPro#eeor.Selecte+alue A "B'B" A cboCategoria.Selecte+alue A "B'B" A Single.Parse(txtPrecio.3ext$ A "B'B" A
Integer.Parse(txtStoc9.3ext$ A "B$"' Cnx$
cm..xecuteNonOuery($
cm.Dispose($
Cnx.Close($
0sg*ox("Datos almacenaos correctamente"' ' "Atencion"$
Dst.3ables("prouctos"$.Clear($
Dap.SelectComman.Comman3ext ! "S.).C3 IProucto' NombreProucto' IPro#eeor' ICategorLa' PrecioEnia' Eniaes.n.xistencia 14,0
Prouctos"
Dap.1ill(Dst' "prouctos"$
btnAicionar.3ext ! "Nue#o"
.n I&
.n Sub
Pri#ate Sub btn0oi&icar(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btn0oi&icar.Clic9

3ry
I& btn0oi&icar.3ext ! "0oi&icar" 37en
btn0oi&icar.3ext ! "Con&irmar"
.lseI& btn0oi&icar.3ext ! "Con&irmar" 37en
Cnx.,pen($
cm ! New SqlComman(" EPDA3. Prouctos S.3 NombreProucto !B" A txtNombre.3ext A "B ' IPro#eeor !B" A cboPro#eeor.Selecte+alue A
"B ' ICategorLa !B" A cboCategoria.Selecte+alue A "B' PrecioEnia !B" A Single.Parse(txtPrecio.3ext$ A "B' Eniaes.n.xistencia ! B" A
Integer.Parse(txtStoc9.3ext$ A "B M7ere Iproucto!B" A Integer.Parse(txtCoigo.3ext$ A "B"' Cnx$
cm..xecuteNonOuery($
cm.Dispose($
Cnx.Close($
0sg*ox(")os Datos se moi&icaron correctamente"' ' "Atencion"$
Dst.3ables("prouctos"$.Clear($
Dap.SelectComman.Comman3ext ! "S.).C3 IProucto' NombreProucto' IPro#eeor' ICategorLa' PrecioEnia' Eniaes.n.xistencia
14,0 Prouctos"
Dap.1ill(Dst' "prouctos"$
btnAicionar.3ext ! "Nue#o"
.n I&
Catc7 ex As Sql.xception
0sg*ox(ex$
.n 3ry
.n Sub
Pri#ate Sub btn.liminar(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btn.liminar.Clic9
3ry
Dim 0 As ,b-ect ! 0sg*ox("D.sta seguro e .liminar el reguistro ActualF"' 0sg*oxStyle.GesNo$
I& 0 ! I 37en
Cnx.,pen($
cm ! New SqlComman(" D.).3. 14,0 Prouctos M/.4. (IProucto !B" A Integer.Parse(txtCoigo.3ext$ A "B$"' Cnx$
cm..xecuteNonOuery($
cm.Dispose($
Cnx.Close($
0sg*ox("Datos se eliminaron correctamente"' ' "Atencion"$
Dst.3ables("prouctos"$.Clear($
Dap.SelectComman.Comman3ext ! "S.).C3 IProucto' NombreProucto' IPro#eeor' ICategorLa' PrecioEnia' Eniaes.n.xistencia
14,0 Prouctos"
Dap.1ill(Dst' "prouctos"$
btnAicionar.3ext ! "Nue#o"
txtCoigo.3ext ! "" : txtNombre.3ext ! "" : txtPrecio.3ext ! "" : txtStoc9.3ext ! ""
.n I&
Catc7 ex As Sql.xception
37row ex
.n 3ry
.n Sub
Pri#ate Sub btnprimero(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnprimero.Clic9
& ! 2
Call mostrar(atos(&$
.n Sub
Pri#ate Sub btnanterior(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnanterior.Clic9
& >! 8
I& & 5 2 37en
& ! 2
0sg*ox(")lego al primer registro"' ' "Atencion"$
Call mostrar(atos(&$
.n I&
Call mostrar(atos(&$
.n Sub
Pri#ate Sub btnsiguiente(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btnsiguiente.Clic9
& ?! 8
I& & 6 (Dst.3ables("prouctos"$.4ows.Count > 8$ 37en
& ! Dst.3ables("prouctos"$.4ows.Count > 8
0sg*ox(")lego al ultimo registro"' ' "Atencion"$
Call mostrar(atos(&$
.n I&
Call mostrar(atos(&$
.n Sub
Pri#ate Sub btn&inal(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles btn&inal.Clic9
& ! Dst.3ables("prouctos"$.4ows.Count > 8
Call mostrar(atos(&$
.n Sub
P4egion "proceimientos"
Pri#ate Sub )impia3extos($
txtCoigo.Clear($
txtNombre.Clear($
txtPrecio.Clear($
txtStoc9.Clear($
cboPro#eeor.SelecteInex ! 2
cboCategoria.SelecteInex ! 2
txtNombre.1ocus($
.n Sub

Pri#ate Sub 0ostrarDatos($
& ! grproucto.CurrentCell.4owInex
txtCoigo.3ext ! grproucto.Item(2' 1$.+alue
txtNombre.3ext ! grproucto.Item(8' 1$.+alue
cboPro#eeor.Selecte+alue ! grproucto.Item(2' 1$.+alue
cboCategoria.Selecte+alue ! grproucto.Item(@' 1$.+alue
txtPrecio.3ext ! grproucto.Item(J' 1$.+alue
txtStoc9.3ext ! grproucto.Item(K' 1$.+alue
.n Sub
Pri#ate Sub mostrar(atos(*y+al & As Integer$
txtCoigo.3ext ! Dst.3ables("prouctos"$.4ows(&$.Item(2$
txtNombre.3ext ! Dst.3ables("prouctos"$.4ows(&$.Item(8$
cboPro#eeor.Selecte+alue ! Dst.3ables("prouctos"$.4ows(&$.Item(2$
cboCategoria.Selecte+alue ! Dst.3ables("prouctos"$.4ows(&$.Item(@$
txtPrecio.3ext ! Dst.3ables("prouctos"$.4ows(&$.Item(J$
txtStoc9.3ext ! Dst.3ables("prouctos"$.4ows(&$.Item(K$
.n Sub
Pri#ate Sub re&rescarlista($
grproucto.DataSource ! Dst.3ables("prouctos"$
.n Sub
P.n 4egion
.n Class
Imports system.ata
Imports System.Data.SqlClient
Public Class 1orm@
Public cnx As New SqlConnection("user i!sa"ser#er!."atabase!minieu"$
Public ap As New SqlDataAapter("select % &rom personal"' cnx$
Public st As New DataSet
Public cm As New SqlComman
Public c=' rtmp<
Pri#ate Sub 1orm@()oa(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles 0y*ase.)oa
ap.1ill(st' "per"$
c ! 2
I& st.3ables("per"$.4ows.Count 6 2 37en
Call mostrar(registro(c$
.lseI& st.3ables("per"$.4ows.Count ! 2 37en
0sg*ox("No existen registros en la base e atos' pulse Nue#o"' 0sg*oxStyle.Critical' "A#ertenciaH"$
.n I&
ap.SelectComman.Comman3ext ! "select % &rom categoria"
ap.1ill(st' "cat"$
CboCategoria.DataSource ! st.3ables("cat"$
CboCategoria.Display0ember ! "nomCat"
0e.CboCategoria.+alue0ember ! "iCat"
ap.SelectComman.Comman3ext ! "select % &rom epartamento"
ap.1ill(st' "ep"$
CboDepartamento.DataSource ! st.3ables("ep"$
CboDepartamento.Display0ember ! "nomDepa"
0e.CboDepartamento.+alue0ember ! "iDepa"
.n Sub
Pri#ate Sub mostrar(registro(*y+al & As Integer$
Mit7 st.3ables("per"$
3xtCo.3ext ! .4ows(&$.Item(2$
3xtNombre.3ext ! .4ows(&$.Item(8$
3xtApellios.3ext ! .4ows(&$.Item(2$
3xtDni.3ext ! .4ows(&$.Item(@$
3xtDireccion.3ext ! .4ows(&$.Item(J$
D31ec7aIng.3ext ! .4ows(&$.Item(K$
CboSexo.3ext ! .4ows(&$.Item(I$
BCboDepartamento.3ext ! .4ows(&$.Item(Q$
BCboCategoria.3ext ! .4ows(&$.Item(R$
.n Mit7
Bruta&oto ! ruta(arc7i# A 3xtCo.3ext A ".-pg"
BP*1oto.Image)ocation ! ruta&oto
.n Sub
Pri#ate Sub 7ab(*y+al n As *oolean' *y+al m As *oolean' *y+al e As *oolean$
*8..nable ! n
*2..nable ! m
*@..nable ! e
.n Sub
Pri#ate Sub *tnSiguiente(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles *tnSiguiente.Clic9
c ?! 8
I& c 6 (st.3ables("per"$.4ows.Count > 8$ 37en
c ! st.3ables("per"$.4ows.Count > 8
0sg*ox("uste esta en el ultimo reg"$
Call mostrar(registro(c$
)abel82.3ext ! 0i(3xtCo.3ext' @$
.n I&
Call mostrar(registro(c$
)abel82.3ext ! 0i(3xtCo.3ext' @$
.n Sub
Pri#ate Sub *tnPrimero(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles *tnPrimero.Clic9
c ! 2
Call mostrar(registro(c$
.n Sub
Pri#ate Sub *tnAnterior(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles *tnAnterior.Clic9
c >! 8
I& c 5 2 37en
c ! 2
0sg*ox("uste esta en el primer registro"$
Call mostrar(registro(c$
.lse
Call mostrar(registro(c$
.n I&
.n Sub
Pri#ate Sub *tnEltimo(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles *tnEltimo.Clic9
c ! st.3ables("per"$.4ows.Count > 8
Call mostrar(registro(c$
.n Sub
Pri#ate Sub *8(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles *8.Clic9
I& *8.3ext ! "Nue#o" 37en
3xtCo.3ext ! "" : 3xtApellios.3ext ! ""
3xtNombre.3ext ! "" : 3xtDireccion.3ext ! ""
3xtDni.3ext ! "" : CboCategoria.3ext ! ""
D31ec7aIng.3ext ! "" : CboSexo.3ext ! ""
CboDepartamento.3ext ! ""
7ab(3rue' 1alse' 1alse$
*8.3ext ! ";uarar"
3xtNombre.1ocus($
.lseI& *8.3ext ! ";uarar" 37en
Dim co(x<' tmp<
I& st.3ables("per"$.4ows.Count ! 2 37en
co(x ! "pr2222"
.lse
Dim iue= ! st.3ables("per"$.4ows.Count > 8
co(x ! st.3ables("per"$.4ows(iue$.Item(2$
.n I&
tmp ! Str(+al(0i(co(x' @$$ ? 8$
co(x ! 0i(co(x' 8' I > )en(3rim(tmp$$$ A 3rim(tmp$
3xtCo.3ext ! co(x
cnx.,pen($
cm ! New SqlComman("insert into personal #alues(B" A 3xtCo.3ext A "B'B" A 3xtNombre.3ext A "B'B" A 3xtApellios.3ext A "B' B" A 3xtDni.3ext A
"B'B" A 3xtDireccion.3ext A "B'B" A D31ec7aIng.3ext A "B'B" A CboSexo.3ext A "B 'B" A CboCategoria.Selecte+alue A "B'B" A CboDepartamento.Selecte+alue A
"B$"' cnx$
cm..xecuteScalar($
cm.Dispose($
cnx.Close($
0sg*ox("atos el personal ingresaos en la base e atos"$
st.3ables("per"$.Clear($
ap.SelectComman.Comman3ext ! "select % &rom personal"
ap.1ill(st' "per"$
c ! st.3ables("per"$.4ows.Count > 8
7ab(3rue' 3rue' 1alse$
*8.3ext ! "Nue#o"
.n I&
.n Sub
Pri#ate Sub *2(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles *2.Clic9
I& *2.3ext ! "0oi&icar" 37en
7ab(1alse' 3rue' 1alse$
*2.3ext ! "Con&irmar"
.lseI& *2.3ext ! "Con&irmar" 37en
cnx.,pen($
cm ! New SqlComman("upate personal set nombre!B" A 3xtNombre.3ext A "B'apellios!B" A 3xtApellios.3ext A "B'DNI!B" A 3xtDni.3ext A
"B'ireccion!B" A 3xtDireccion.3ext A "B'&ec7aing!B" A D31ec7aIng.3ext A "B'sexo!B" A CboSexo.Selecte+alue A "B'iCat!B" A CboCategoria.Selecte+alue A
"B'iDepa!B" A CboDepartamento.Selecte+alue A "B w7ere coigo!B" A 3xtCo.3ext A "B"' cnx$
cm..xecuteScalar($
cm.Dispose($
cnx.Close($
0sg*ox(")os atos se actualiCaron correctamente"$
st.3ables("per"$.Clear($
ap.SelectComman.Comman3ext ! "select % &rom personal"
ap.1ill(st' "per"$
7ab(3rue' 3rue' 3rue$
*2.3ext ! "0oi&icar"
.n I&
.n Sub
Pri#ate Sub *@(Clic9(*y+al sener As System.,b-ect' *y+al e As System..#entArgs$ /anles *@.Clic9
Dim 0 As ,b-ect ! 0sg*ox("D.sta seguro e .liminar el reguistro ActualF"' 0sg*oxStyle.GesNo$
I& 0 ! I 37en
cnx.,pen($
cm ! New SqlComman("elete personal w7ere coigo!B" A 3xtCo.3ext A "B"' cnx$
cm..xecuteScalar($
cm.Dispose($
cnx.Close($
0sg*ox(")os atos el personal se eliminaron e la *D"$
st.3ables("per"$.Clear($
ap.SelectComman.Comman3ext ! "select % &rom personal"
ap.1ill(st' "per"$
c >! 8
I& c 5 2 37en c ! 2
I& st.3ables("Per"$.4ows.Count 56 2 37en Call mostrar(registro(c$
.n I&
.n Sub
.n Class

Вам также может понравиться