Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Control de celulares (taller de aplicación – henrry

/clase 281009)
use master
go
if(db_id('ControlCelulares')is not null)
drop database ControlCelulares
create database ControlCelulares
go
use ControlCelulares
go
create table Celular
(IdCel int identity(1,1)primary key,
Modelo varchar(50) not null unique,
Tipo char(1) not null check(Tipo in('M','C')),-- M: movistar C:claro
Precio smallmoney not null,
Stock tinyint not null,
RutaImg varchar(255)
)
go
Create Proc InsertaCelular(@Modelo varchar(50),@Tipo char(1),@Precio
smallmoney,@Stock tinyint,@Ruta varchar(255))
As Begin
Insert Into Celular
values(@Modelo,@Tipo,@Precio,@Stock,@Ruta)
End
go

Create Proc ListadoXTipo(@Tipo char(1))


As Begin
Select* From Celular Where Tipo=@Tipo
End
go

Select * from Celular


Visual ( conexión)

Celular.Vb (clase.Vb)
Imports System.Data.SqlClient
Public Class Celular
'Atributos
'Metodos
'Listado de celulares x tipo
'Guardar celulares

Public Function guardar(ByVal Modelo As String, ByVal Tipo As String,


ByVal Precio As Decimal, ByVal Stock As Integer, ByVal Ruta As String) As
Integer

Dim i As Integer
Dim Cmd As SqlCommand
Try
Abrir()
Cmd = New SqlCommand("InsertaCelular", con)
Cmd.CommandType = CommandType.StoredProcedure
With Cmd.Parameters
.AddWithValue("@Modelo", Modelo)
.AddWithValue("@Tipo", Tipo)
.AddWithValue("@Precio", Precio)
.AddWithValue("@Stock", Stock)
.AddWithValue("@Ruta", Ruta)
End With
i = Cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally : Cerrar()
End Try
Return i
End Function
End Class

Form1

Module1.Vb
Imports System.Data.SqlClient
Module Module1
Public con As New SqlConnection("data
source=.;database=controlcelulares;integrated security=true")
Public Sub Abrir()
If con.State = 0 Then con.Open()
End Sub
Public Sub Cerrar()
If con.State = 1 Then con.Close()
End Sub
End Module

General
Imports Biblioteca
Public Class Form1
Private Ruta As String
Private c As New Biblioteca.Celular

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


As System.EventArgs) Handles PictureBox1.Click
Dim f As New OpenFileDialog
If f.ShowDialog() = Windows.Forms.DialogResult.OK Then
Ruta = f.FileName
PictureBox1.ImageLocation = Ruta

End If
End Sub

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


System.EventArgs) Handles Button1.Click
Dim Tipo As String
Dim x As Integer
If RadioButton1.Checked = True Then
Tipo = "M"
Else : Tipo = "C"
End If
Try
x = c.guardar(txtModelo.Text, Tipo, CDec(txtPrecio.Text),
CInt(NumericUpDown1.Value), Ruta)
If x = 1 Then
MessageBox.Show("Celular Registrado ok...")
Else
MessageBox.Show("Error...")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

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


System.EventArgs) Handles MyBase.Load
End Sub
End Class

You might also like