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

MANUAL DE PROGRAMADOR

Sistema Taller de Autos ver 1.0

Índice

Indice

3

I.

Base de Datos SQL Server 2005

4

Diagrama de la Base de Datos

4

Transact SQL

5

Procedimiento Almacenado

11

 

o

ActualizaPassUsu

11

o

ActualizarStockProducto

11

o

ListarBitacoraXfecha

12

o

RegistroBitacora

12

II.

Programación VISUAL.NET

13

Tipo de Programación

13

CAPA APLICACIÓN

13

 

o

Formulario Login

13

o

MDI Panel Principal

14

o

Reporte Producto

18

CAPA DATOS

19

 

o

ConexioBD

19

CAPA LOGICA DE NEGOCIO

21

 

o

ClaseCliente

21

o

ClaseProducto

22

I.

Base de Datos SQL Server 2005

Diagrama de la Base de Datos

I. Base de Datos SQL Server 2005  Diagrama de la Base de Datos 4

Transact-SQL

CREATE DATABASE BD_TALLER GO USE BD_TALLER GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Tipo_trabajo]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Tipo_trabajo]( [id_tipo_trabajo] [int] IDENTITY(1,1) NOT NULL, [nomb_tipo_trabajo] [varchar](150) NULL, [descripc_tipo_trabajo] [varchar](250) NULL, [precio_tipo_trabajo] [money] NULL, CONSTRAINT [PK_tipo_trabajo] PRIMARY KEY CLUSTERED

(

[id_tipo_trabajo] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Clientes]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Clientes]( [id_cliente] [int] IDENTITY(1,1) NOT NULL, [nomb_cliente] [varchar](150) NULL, [ape_cliente] [varchar](150) NULL, [dni_cliente] [varchar](8) NULL, [direc_cliente] [varchar](50) NULL, [tele1_cliente] [varchar](50) NULL, [tele2_cliente] [varchar](50) NULL, CONSTRAINT [PK_Clientes] PRIMARY KEY CLUSTERED

(

[id_cliente] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Proveedor]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Proveedor]( [id_proveedor] [int] IDENTITY(1,1) NOT NULL, [ruc_proveedor] [varchar](20) NULL, [nombre_proveedor] [varchar](150) NULL, [direc_proveedor] [varchar](150) NULL, [fono_proveedor] [varchar](50) NULL,

[mail_proveedor] [varchar](50) NULL, CONSTRAINT [PK_Proveedor] PRIMARY KEY CLUSTERED

(

[id_proveedor] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Trabajador]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Trabajador]( [id_trab] [int] IDENTITY(1,1) NOT NULL, [nomb_trab] [varchar](150) NULL,

[ape_trab] [varchar](150) NULL, [sex_trab] [char](1) NULL, [direc_trab] [varchar](100) NULL, [tel_trab] [varchar](50) NULL, [fechaN_trab] [smalldatetime] NULL, [dni_trab] [varchar](50) NULL, CONSTRAINT [PK_Trabajador] PRIMARY KEY CLUSTERED

(

[id_trab] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Registro_taller]') AND type in (N'U')) BEGIN

CREATE TABLE [dbo].[Registro_taller]( [id_registro_taller] [int] NOT NULL, [fecha_registro_taller] [smalldatetime] NULL, [id_usuario] [int] NULL, [id_vehiculoC] [int] NULL, [precio_venta] [decimal](18, 2) NULL, CONSTRAINT [PK_registro_taller] PRIMARY KEY CLUSTERED

(

[id_registro_taller] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Detalle_pagos]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Detalle_pagos]( [id_detalle_pago] [int] IDENTITY(1,1) NOT NULL, [id_pago] [int] NULL,

[id_usuario] [int] NULL, [pago] [money] NULL, [observacion] [varchar](50) NULL, CONSTRAINT [PK_Detalle_pagos] PRIMARY KEY CLUSTERED

(

[id_detalle_pago] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Regsitro_historico_producto]') AND type in (N'U')) BEGIN

CREATE TABLE [dbo].[Regsitro_historico_producto]( [id_registro_producto] [int] IDENTITY(1,1) NOT NULL, [id_producto] [int] NULL, [cantidad] [int] NULL, [proceso] [char](1) NULL, [id_usuario] [int] NULL,

[fecha_registro] [smalldatetime] NULL, [doc_reg] [varchar](150) NULL, CONSTRAINT [PK_Regsitro_historico_producto] PRIMARY KEY CLUSTERED

(

[id_registro_producto] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Bitacora_usuarios]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Bitacora_usuarios]( [id_bitac] [int] IDENTITY(1,1) NOT NULL, [id_usuario] [int] NOT NULL, [fechaProceso] [datetime] NULL, [detalleProceso] [varchar](250) NULL, CONSTRAINT [PK_bitacora_usuarios] PRIMARY KEY CLUSTERED

(

[id_bitac] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[VehiculoC]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[VehiculoC](

[id_vehiculoC] [int] IDENTITY(1,1) NOT NULL, [tipo_vehiculoC] [varchar](150) NULL, [marca_vehiculoC] [varchar](50) NULL, [modelo_vehiculoC] [varchar](50) NULL, [placa_vehiculoC] [varchar](50) NULL, [descripcion_vehiculoC] [varchar](250) NULL, [id_cliente] [int] NULL, CONSTRAINT [PK_VehiculoC] PRIMARY KEY CLUSTERED

(

[id_vehiculoC] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Registro_Materiales]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Registro_Materiales]( [id_materiales] [int] IDENTITY(1,1) NOT NULL, [id_producto] [int] NULL, [id_registro_taller] [int] NULL, [cantidad] [int] NULL, CONSTRAINT [PK_Registro_Materiales] PRIMARY KEY CLUSTERED

(

[id_materiales] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pagos]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Pagos]( [id_pago] [int] IDENTITY(1,1) NOT NULL, [id_registro_taller] [int] NULL, [tipo_pago] [varchar](150) NULL, [cantidad_pago] [money] NULL, [observacion] [varchar](250) NULL, CONSTRAINT [PK_Pagos] PRIMARY KEY CLUSTERED

(

[id_pago] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Producto]') AND type in (N'U')) BEGIN

CREATE TABLE [dbo].[Producto]( [id_producto] [int] IDENTITY(1,1) NOT NULL, [nombre_producto] [varchar](150) NULL, [stock_actual] [int] NULL, [stock_minimo] [int] NULL, [precio_unidad] [decimal](6, 2) NULL, [id_proveedor] [int] NULL, CONSTRAINT [PK_Producto] PRIMARY KEY CLUSTERED

(

[id_producto] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Usuarios]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Usuarios]( [id_usuario] [int] IDENTITY(1,1) NOT NULL, [nick_usuario] [varchar](50) NULL, [pass_usuario] [varchar](255) NOT NULL, [nive_priv] [int] NULL, [area_trabajo] [varchar](50) NULL, [id_trab] [int] NULL, [estado_usuario] [int] NULL, CONSTRAINT [PK_Usuarios] PRIMARY KEY CLUSTERED

(

[id_usuario] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Registro_taller_Registro_taller]') AND parent_object_id = OBJECT_ID(N'[dbo].[Registro_taller]')) ALTER TABLE [dbo].[Registro_taller] WITH CHECK ADD CONSTRAINT [FK_Registro_taller_Registro_taller] FOREIGN KEY([id_vehiculoC]) REFERENCES [dbo].[VehiculoC] ([id_vehiculoC]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_registro_taller_Usuarios]') AND parent_object_id = OBJECT_ID(N'[dbo].[Registro_taller]')) ALTER TABLE [dbo].[Registro_taller] WITH CHECK ADD CONSTRAINT [FK_registro_taller_Usuarios] FOREIGN KEY([id_usuario]) REFERENCES [dbo].[Usuarios] ([id_usuario]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Detalle_pagos_Pagos]') AND parent_object_id = OBJECT_ID(N'[dbo].[Detalle_pagos]')) ALTER TABLE [dbo].[Detalle_pagos] WITH CHECK ADD CONSTRAINT [FK_Detalle_pagos_Pagos] FOREIGN KEY([id_pago]) REFERENCES [dbo].[Pagos] ([id_pago])

GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Detalle_pagos_Usuarios]') AND parent_object_id = OBJECT_ID(N'[dbo].[Detalle_pagos]')) ALTER TABLE [dbo].[Detalle_pagos] WITH CHECK ADD CONSTRAINT [FK_Detalle_pagos_Usuarios] FOREIGN KEY([id_usuario]) REFERENCES [dbo].[Usuarios] ([id_usuario]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Regsitro_historico_producto_Producto] ') AND parent_object_id = OBJECT_ID(N'[dbo].[Regsitro_historico_producto]')) ALTER TABLE [dbo].[Regsitro_historico_producto] WITH CHECK ADD CONSTRAINT [FK_Regsitro_historico_producto_Producto] FOREIGN KEY([id_producto]) REFERENCES [dbo].[Producto] ([id_producto]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Regsitro_historico_producto_Usuarios] ') AND parent_object_id = OBJECT_ID(N'[dbo].[Regsitro_historico_producto]')) ALTER TABLE [dbo].[Regsitro_historico_producto] WITH CHECK ADD CONSTRAINT [FK_Regsitro_historico_producto_Usuarios] FOREIGN KEY([id_usuario]) REFERENCES [dbo].[Usuarios] ([id_usuario]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Bitacora_usuarios_Usuarios]') AND parent_object_id = OBJECT_ID(N'[dbo].[Bitacora_usuarios]')) ALTER TABLE [dbo].[Bitacora_usuarios] WITH CHECK ADD CONSTRAINT [FK_Bitacora_usuarios_Usuarios] FOREIGN KEY([id_usuario]) REFERENCES [dbo].[Usuarios] ([id_usuario]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_VehiculoC_Clientes]') AND parent_object_id = OBJECT_ID(N'[dbo].[VehiculoC]')) ALTER TABLE [dbo].[VehiculoC] WITH CHECK ADD CONSTRAINT [FK_VehiculoC_Clientes] FOREIGN KEY([id_cliente]) REFERENCES [dbo].[Clientes] ([id_cliente]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Registro_Materiales_Producto]') AND parent_object_id = OBJECT_ID(N'[dbo].[Registro_Materiales]')) ALTER TABLE [dbo].[Registro_Materiales] WITH CHECK ADD CONSTRAINT [FK_Registro_Materiales_Producto] FOREIGN KEY([id_producto]) REFERENCES [dbo].[Producto] ([id_producto]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id =

OBJECT_ID(N'[dbo].[FK_Registro_Materiales_Registro_taller1]

') AND parent_object_id = OBJECT_ID(N'[dbo].[Registro_Materiales]'))

ALTER TABLE [dbo].[Registro_Materiales] WITH CHECK ADD CONSTRAINT [FK_Registro_Materiales_Registro_taller1] FOREIGN KEY([id_registro_taller]) REFERENCES [dbo].[Registro_taller] ([id_registro_taller]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Pagos_Registro_taller]') AND parent_object_id = OBJECT_ID(N'[dbo].[Pagos]')) ALTER TABLE [dbo].[Pagos] WITH CHECK ADD CONSTRAINT [FK_Pagos_Registro_taller] FOREIGN KEY([id_registro_taller]) REFERENCES [dbo].[Registro_taller] ([id_registro_taller]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Producto_Proveedor]') AND parent_object_id = OBJECT_ID(N'[dbo].[Producto]')) ALTER TABLE [dbo].[Producto] WITH CHECK ADD CONSTRAINT [FK_Producto_Proveedor] FOREIGN KEY([id_proveedor]) REFERENCES [dbo].[Proveedor] ([id_proveedor]) GO IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Usuarios_Usuarios1]') AND parent_object_id = OBJECT_ID(N'[dbo].[Usuarios]')) ALTER TABLE [dbo].[Usuarios] WITH CHECK ADD CONSTRAINT [FK_Usuarios_Usuarios1] FOREIGN KEY([id_trab]) REFERENCES [dbo].[Trabajador] ([id_trab])

Procedimiento Almacenados

ActualizaPassUsu

set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go

ALTER PROCEDURE [dbo].[ActualizaPassUsu] @pas as varchar(255), @id as int

AS

BEGIN

update Usuarios set pass_usuario=@pas where id_usuario=@id

END

ActualizarSotckProducto

set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go

ALTER PROCEDURE [dbo].[ActualizarSotckProducto] @cod as int

AS

BEGIN Declare @I int,

@S int, @Act int

set @I= (select sum(cantidad) from Regsitro_historico_producto where proceso='I' and id_producto=@cod); set @S= (select sum(cantidad) from Regsitro_historico_producto where proceso='S'and id_producto=@cod); if (@S is NULL) begin

set @S=0;

end if (@I is NULL) begin

set @I=0;

end set @Act =@I-@S

update Producto set stock_actual=@Act where id_producto=@cod; END

ListarBitacoraXfecha

set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go

ALTER PROCEDURE [dbo].[ListarBitacoraXfecha] @date as char(10)

AS BEGIN select t.nomb_trab +' '+ t.ape_trab as "USUARIO", b.fechaProceso as "FECHA DE PROCESO", b.detalleProceso as "DETALLE" from Bitacora_usuarios b inner join Usuarios u on b.id_usuario=u.id_usuario inner join Trabajador t on u.id_trab=t.id_trab Where Convert(Char(10), b.fechaProceso , 101)=@date order by b.fechaProceso desc END

RegistroBitacora

set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go

ALTER PROCEDURE [dbo].[RegistroBitacora] @user as int, @fecha as smalldatetime, @proceso as varchar(150) AS BEGIN insert into Bitacora_usuarios values(@user,@fecha,@proceso) END

II.

Programación VISUAL .NET

Tipo de Programación.- programación por capas es una arquitectura cliente-servidor en el que el objetivo primordial es la separación de la lógica de negocios de la lógica de diseño; un ejemplo básico de esto consiste en separar la capa de datos de la capa de presentación al usuario.

CAPA APLICACIÓN

o Formulario Login

Public Class Login Dim claseUsuario As New CAPA_LOGICA_NEGOCIO.ClasesUsuarios Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

Button2.Click

Me.Dispose() End Sub

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

Button1.Click

Dim obj As DataTable obj = claseUsuario.ListarUsua(Me.txtUsu.Text, Me.TxtPass.Text)

If (obj.Rows.Count = 0) Then MsgBox("Revise su cuenta", MsgBoxStyle.Exclamation, "SISTEMA TALLER_AUTOS") Else

If (obj.Rows(0).Item(4) <> 1) Then MsgBox("Comuniquese con el Administrador. Cuenta Deshabilitada", MsgBoxStyle.Exclamation, "SISTEMA TALLER_AUTOS") Else

Variables_Globales.IdAccesoUser =

obj.Rows(0).Item(0)

Variables_Globales.NivelAcceso =

obj.Rows(0).Item(1)

Variables_Globales.AreaTrab =

obj.Rows(0).Item(2)

Variables_Globales.IdTrabaAcceso =

obj.Rows(0).Item(3)

Variables_Globales.Pass =

TxtPass.Text

Me.Visible = False MsgBox("Bienvenido al sistema", MsgBoxStyle.Information, "SISTEMA TALLER_AUTOS")

claseUsuario.RegistroBitacora(Variables_Globales.IdA ccesoUser, Date.Now, "Ingreso al Sistema") FromularioPrincipal.Show() End If End If

End Sub

Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TxtPass.Text = "" Me.txtUsu.Text = "" End Sub

Private Sub Login_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged Me.TxtPass.Text = "" Me.txtUsu.Text = "" End Sub End Class

o MDI Panel Principal

Public Class FromularioPrincipal Dim claseUsuario As New CAPA_LOGICA_NEGOCIO.ClasesUsuarios

Private mMenu As New System.Windows.Forms.MainMenu()

Private Sub FromularioPrincipal_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

claseUsuario.RegistroBitacora(Variables_Globales.IdAc cesoUser, Date.Now, "Salida del Sistema") Login.Close() End Sub Private Sub mnuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Select Case CType(sender, MenuItem).Text Case "Cambio de Clave" CambioClave.MdiParent = Me CambioClave.Show() Case "Registro de Cliente" Clientes.MdiParent = Me Clientes.Show() Case "Busqueda de Cliente" BusquedaCliente.MdiParent = Me BusquedaCliente.Show() Case "Registro Vehiculo" Vehiculo.MdiParent = Me Vehiculo.Show() Case "Producto Nuevo" Productos.MdiParent = Me Productos.Show() Case "Ingreso de Productos" Ingreso_Stock_Producto.MdiParent = Me Ingreso_Stock_Producto.Show() Case "Registrar Proveedor" Proveedor.MdiParent = Me Proveedor.Show()

Case "Registro Salida" RegistroSalida.MdiParent = Me RegistroSalida.Show() Case "Registro de Trabajador" Trabajador.MdiParent = Me Trabajador.Show() Case "Registro de Usuario" Usuarios.MdiParent = Me Usuarios.Show() Case "Bitacora de Ingresos al Sistema" Bitacora.MdiParent = Me Bitacora.Show() Case "Reporte de Ingreso de Producto" Variables_Globales.Reporte = "Reporte

Ingreso"

 

ReporteProducto.MdiParent = Me ReporteProducto.Show() Case "Reporte de Salida de Producto" Variables_Globales.Reporte = "Reporte

Salida"

 

ReporteProducto.MdiParent = Me ReporteProducto.Show() Case "Kardex de Producto" Kardex.MdiParent = Me Kardex.Show() Case "Grafico de Top de Productos

Vendidos"

VisorGraficos.MdiParent = Me VisorGraficos.Show() Case "Reporte de Salida de Almacen" VisorSalidaAlmacen.MdiParent = Me VisorSalidaAlmacen.Show() Case "Grafico Productos Vendidos por Mes" VisorGraficos2.MdiParent = Me

VisorGraficos2.Show()

Case "Grafico Ventas Realizada por Intervalo de Mes" VisorGrafico3.MdiParent = Me

VisorGrafico3.Show()

Case "Grafico Ventas Realizada por Trabajador por Mes" VisorGrafico4.MdiParent = Me

VisorGrafico4.Show()

Case "Salir"

claseUsuario.RegistroBitacora(Variables_Globales.IdAc cesoUser, Date.Now, "Salida del Sistema") Login.Show() Me.Visible = False

End Select End Sub Private Sub FromularioPrincipal_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Menu = Nothing CreaMenu() End Sub

Public Sub CreaMenu() ' Creamos los menús a usar

Me.Menu = mMenu 'Usuario With mMenu.MenuItems.Add("mnuUsuario") .Text = "&Usuario" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Cambio de Clave" End With End With

With mMenu.MenuItems.Add("mnuCliente") .Text = "&Cliente" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Registro de Cliente" End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Busqueda de Cliente" End With End With 'Menu Vehiculo If (Variables_Globales.NivelAcceso = 2 Or Variables_Globales.NivelAcceso = 3) Then With mMenu.MenuItems.Add("mnuVehiculo") .Text = "&Vehiculo" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Registro Vehiculo" End With End With End If 'Menu Proveedor With mMenu.MenuItems.Add("mnuProveedor") .Text = "&Proveedor" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Registrar Proveedor" End With End With 'Menu Producto With mMenu.MenuItems.Add("mnuProducto") .Text = "&Productos" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Producto Nuevo" End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Ingreso de Productos" End With End With 'Menu Almacen With mMenu.MenuItems.Add("mnuAlmacen") .Text = "&Almacen" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Registro Salida" End With End With 'Menu Administrador

With mMenu.MenuItems.Add("mnuAdmin") .Text = "&Administrador" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Registro de Trabajador" End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Registro de Usuario" End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Bitacora de Ingresos al

Sistema"

End With

End With 'Menu Reportes With mMenu.MenuItems.Add("mnuReportes") .Text = "&Reportes"

With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Reporte de Ingreso de

Producto"

End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Kardex de Producto" End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Reporte de Salida de

Almacen"

End With End With 'Menu Graficos With mMenu.MenuItems.Add("mnuReportes") .Text = "&Graficos" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Grafico de Top de Productos

Vendidos"

End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Grafico Productos Vendidos

por Mes"

End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Grafico Ventas Realizada por Intervalo de Mes" End With With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Grafico Ventas Realizada por Trabajador por Mes" End With End With 'Menu Salir

With mMenu.MenuItems.Add("mnuSalir") .Text = "&Salir" With .MenuItems.Add("mnuItem", New EventHandler(AddressOf mnuItem_Click)) .Text = "Salir" End With End With End Sub

End Class

o Reporte Producto

Imports CrystalDecisions.CrystalReports.Engine Public Class ReporteProducto Dim claseProducto As New CAPA_LOGICA_NEGOCIO.ClaseProducto Private Sub ReporteProducto_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.CbProd.DataSource = claseProducto.ListarProductoXnombCod(" ") Me.CbProd.DisplayMember = "NOMBRE PRODUCTO" End Sub Private Sub VisualizaReporteIngreso() Dim rpt As New ReportDocument() 'Cargamos el reporte mediante su ruta rpt.Load(Application.StartupPath + "\ReportStockProd.rpt") 'Origen de datos para el reporte

rpt.SetDataSource(Me.IngresosProducto(Me.CbProd.Selec tedValue("CODIGO"))) 'Título del reporte rpt.SummaryInfo.ReportTitle = "Ingresos de Producto: " + Me.CbProd.Text 'Enlazamos el reporte al visor Me.CrystalReportViewer1.ReportSource = rpt End Sub Private Sub VisualizaReporteSalida() Dim rpt As New ReportDocument() 'Cargamos el reporte mediante su ruta rpt.Load(Application.StartupPath + "\ReportStockProdS.rpt") 'Origen de datos para el reporte

rpt.SetDataSource(Me.IngresosProducto(Me.CbProd.Selec tedValue("CODIGO"))) 'Título del reporte rpt.SummaryInfo.ReportTitle = "Salida de Producto: " + Me.CbProd.Text 'Enlazamos el reporte al visor Me.CrystalReportViewer1.ReportSource = rpt End Sub Private Function IngresosProducto(ByVal cod As Integer) As DataTable Dim dt As New DataTable("Reporte") If Variables_Globales.Reporte = "Reporte Salida" Then

dt = claseProducto.ListarProdSalida(cod)

Else

dt = claseProducto.ListarIngresoProdxCod(cod)

End If

Return dt

End Function

Private Sub CbProd_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CbProd.SelectedIndexChanged If Variables_Globales.Reporte = "Reporte Salida" Then

VisualizaReporteSalida()

Else

VisualizaReporteIngreso() End If

End Sub

End Class

CAPA DATOS o ConexionBD

Imports System.Data.SqlClient Public Class ClaseConexion Public Conexion As New SqlConnection("Data Source=.;Initial Catalog=BD_Taller;User

ID=sa;Password=123")

Public Function Procedimiento(ByVal NombreProc As String, ByVal ParamArray xParam() As Object) As Integer

Dim i, r As Integer Dim sc As New SqlCommand Conexion.Open() Try

sc = New SqlCommand(NombreProc, Conexion) sc.CommandType = CommandType.StoredProcedure SqlCommandBuilder.DeriveParameters(sc) If Not xParam Is Nothing Then With sc For i = 0 To xParam.Length - 1 Try

CType(.Parameters(i + 1), System.Data.SqlClient.SqlParameter).Value = xParam(i) Catch ex As Exception Throw (ex) End Try

Next End With End If

r = sc.ExecuteNonQuery()

r = 1 Conexion.Close() Return r Catch ex As Exception MsgBox(ex.Message) Conexion.Close() Return -1

End Try End Function Public Function Listado(ByVal NombreProc As String, ByVal ParamArray xParam() As Object) As DataTable Dim i As Integer Dim da As New SqlDataAdapter Dim dt As New DataTable Dim sc As New SqlCommand Conexion.Open() dt.Clear() sc = New System.Data.SqlClient.SqlCommand(NombreProc, Conexion) sc.CommandType = CommandType.StoredProcedure SqlCommandBuilder.DeriveParameters(sc) Try

If Not xParam Is Nothing Then With sc For i = 0 To xParam.Length - 1 Try

CType(.Parameters(i + 1), System.Data.SqlClient.SqlParameter).Value = xParam(i) Catch ex As Exception Throw (ex) End Try

Next End With End If da = New SqlDataAdapter(sc) da.Fill(dt) Conexion.Close() Return dt Catch ex As Exception MsgBox(ex.Message) Conexion.Close() Listado = Nothing End Try End Function Public Function Buscar(ByVal NombreProc As String, ByVal ParamArray xParam() As Object) As Integer

Dim i, r As Integer Dim sc As New SqlCommand Dim dr As SqlDataReader Conexion.Open() Try

sc = New SqlCommand(NombreProc, Conexion) sc.CommandType = CommandType.StoredProcedure SqlCommandBuilder.DeriveParameters(sc) If Not xParam Is Nothing Then With sc For i = 0 To xParam.Length - 1 Try

CType(.Parameters(i + 1), System.Data.SqlClient.SqlParameter).Value = xParam(i) Catch ex As Exception Throw (ex) End Try

Next

End With

End If

dr = sc.ExecuteReader dr.Read() r = Val(dr(0)) If r > 0 Then

= 1

r End If Conexion.Close() Return r Catch ex As Exception Conexion.Close() Return 0 End Try End Function End Class

CAPA LOGICA DE NEGOCIO o ClaseCliente

Public Class ClaseCliente Dim BD As New CAPA_DATOS.ClaseConexion Public Sub InsertaCliente(ByVal d1, ByVal d2, ByVal d3, ByVal d4, ByVal d5, ByVal d6) Try

BD.Procedimiento("InsertarClientes", d1, d2, d3, d4, d5, d6) Catch ex As Exception Throw End Try End Sub Public Function ContarClienteXdni(ByVal dni) Return BD.Buscar("ContarClienteXDni", dni) End Function Public Function ListarClienteXdni(ByVal dni) Return BD.Listado("BusquedaClienteXdni", dni) End Function

Public Function ListarClientesXnomb(ByVal nomb) Return BD.Listado("ListarClientesXnomb",

nomb) End Function Public Function ListarVehiculoCxCodClie(ByVal

cod)

Return BD.Listado("ListarVehiculoCxCodClie",

cod)

End Function Public Sub InsertaVehiculoC(ByVal tipo, ByVal marca, ByVal modelo, ByVal placa, ByVal descrip, ByVal cod) Try

BD.Procedimiento("InsertarVehiculoC", tipo, marca, modelo, placa, descrip, cod) Catch ex As Exception Throw End Try End Sub Public Sub InsertarRegistroTaller(ByVal cod, ByVal fecha, ByVal usu, ByVal veh, ByVal val)

Try

BD.Procedimiento("InsertarRegistroTaller", cod, fecha, usu, veh, val) Catch ex As Exception Throw End Try End Sub Public Function CargaComboPlacaVehiculo(ByVal

cod)

Return BD.Listado("CargaComboPlacaVehiculo",

cod)

End Function Public Function ContarRegistroTaller() Return BD.Listado("ContarRegistroTaller") End Function Public Function ListaRegistroXCliente(ByVal nomb) Return BD.Listado("ListaRegistroXCliente",

nomb) End Function

End Class

o ClaseProducto

Public Class ClaseProducto Dim BD As New CAPA_DATOS.ClaseConexion Public Sub InsertaProductoPrimera(ByVal Nombre, ByVal Stock, ByVal Precio, ByVal prov) Try

BD.Procedimiento("InsertaProductoInicial", Nombre, Stock, Precio, prov) Catch ex As Exception Throw End Try End Sub Public Function ContarProdXNomb(ByVal nomb) Return BD.Buscar("BusquedaProductoXnomb",

nomb) End Function Public Function ListarProductoXnombre(ByVal Nombre)

Return BD.Listado("ListarProductoXnomb",

Nombre) End Function Public Function ListarProductoXnombCod(ByVal Nombre)

Return BD.Listado("ListarProductoXnombCod",

Nombre) End Function

Public Function ListarProducto(ByVal Nombre) Return BD.Listado("ListarProducto", Nombre) End Function Public Function DatosProducto(ByVal cod) Return BD.Listado("DatosProductoXCod", cod) End Function Public Function ListarIngresoProdxCod(ByVal cod)

Return BD.Listado("ListarIngresoProdxCod ",

cod)

End Function Public Function ListarProdSalida(ByVal cod) Return BD.Listado("ListarProdSalida", cod) End Function Public Function KardexProd(ByVal cod) Return BD.Listado("KardexProd", cod) End Function Public Sub InsertaRegistroP(ByVal CodigoP, ByVal

Cantidad, ByVal proc, ByVal usu, ByVal fecha, ByVal

doc)

Try

BD.Procedimiento("InsertarRegistroProducto", CodigoP, Cantidad, proc, usu, fecha, doc) Catch ex As Exception Throw End Try End Sub

Public Sub InsertarRegistroMateriales(ByVal CodigoP, ByVal CodReg, ByVal cant) Try

BD.Procedimiento("InsertarRegistroMateriales", CodigoP, CodReg, cant) Catch ex As Exception Throw End Try End Sub

Public Sub ActualizaStockActual(ByVal Codigo) Try

BD.Procedimiento("ActualizarSotckProducto", Codigo) Catch ex As Exception Throw End Try End Sub Public Function ListarTopProd(ByVal n) Return BD.Listado("ReporteTopProducto", n) End Function Public Function ListarTopProdM(ByVal n) Return BD.Listado("ReporteTopProductoMenos",

n)

End Function Public Function ReportSalidaAlmacen(ByVal n) Return BD.Listado("ReportSalidaAlmacen", n) End Function Public Function ListarReporte(ByVal c, ByVal fi, ByVal ff, ByVal a)

Return BD.Listado("ReporteVentaProductoMesAhno", c, fi, ff,

a)

End Function Public Function ListarReporteVentas(ByVal fi, ByVal ff, ByVal a) Return BD.Listado("ReporteVentasPorMesAhno", fi, ff, a) End Function

Public Function ListarReporteVentasxTrabajador(ByVal m) Return BD.Listado("ReporteTrabajaVentaXmes",

m)

End Function

End Class