
APLICACION 3 CAPAS AYUDA URGENTE
Publicado por Edgar (26 intervenciones) el 17/01/2008 00:37:58
Amigos del Foro necesito su ayuda urgente,desde ya muchas gracias por su valiosa ayuda.
Hasta el momento estoy realizando un proyecto contable con ASP.NET , con lenguaje Visual.net 2005 y base de datos SQL 2000.
Para este proyecto me cree una clase en donde tengo declarado las propiedades, conexion, llamada a los enventos de insetar, borra, actualizar, etc. Yo creía que estaba realizando ya 3 capas pero me di cuenta que no es asi pues en cada web form en los respectivos botones realizaba los respectivos insert, update y delete como lo prodran ver en le codigo que pongo a continuacion.....
POR FAVOR NECESITO ME INDIQUEN COMO HAGO QUE MAS ME FALTA PARA QUE SEA 3 CAPAS .... ES URGENTE PUES DE ESTO DEPENDE MI PROYECTO
CODIGO CLASE dbopciones.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Namespace Contabilidad.data ' Nombre del Namespace como vamos a instancias nuestras paginas aspx
Public Class dbOpciones 'Creacion de la Clase dbOperaciones
Sub New()
End Sub
'Atributos de nuestra clase
Private _Database As String
Private _Delete_command As SqlCommand
Private _Insert_command As SqlCommand
Private _Password As String
Private _Select_Command As SqlCommand
Private _Server As String
Private _Update_command As SqlCommand
Private _UserId As String
Public [Error] As String
Public Property Database() As String ' Propiedades de la Clase para acceder desde las paginas aspx
Get
Return _Database
End Get
Set(ByVal value As String)
_Database = value
End Set
End Property
Public Property Delete_Command() As SqlCommand
Get
Return _Delete_command
End Get
Set(ByVal value As SqlCommand)
_Delete_command = value
End Set
End Property
Public Property Insert_Command() As SqlCommand
Get
Return _Insert_command
End Get
Set(ByVal value As SqlCommand)
_Insert_command = value
End Set
End Property
Public Property Password() As String
Get
Return _Password
End Get
Set(ByVal value As String)
_Password = value
End Set
End Property
Public Property Select_Command() As SqlCommand
Get
Return _Select_Command
End Get
Set(ByVal value As SqlCommand)
_Select_Command = value
End Set
End Property
Public Property Server() As String
Get
Return _Server
End Get
Set(ByVal value As String)
_Server = value
End Set
End Property
Public Property Update_command() As SqlCommand
Get
Return _Update_command
End Get
Set(ByVal value As SqlCommand)
_Update_command = value
End Set
End Property
Public Property UserId() As String
Get
Return _UserId
End Get
Set(ByVal value As String)
_UserId = value
End Set
End Property
'Metodos de nuestra calse
Public Function GetStringConection() As SqlConnection
Return New SqlConnection("Data Source =..SQLEXPRESS;AttachDbFilename=C:MODCONTABILIDADApp_DataBase.mdf;Integrated Security=True;User Instance=True")
End Function
'Métodos que interactúan directamente con la base de datos
'BUSQUEDA Y SELECCION (SELECT)
Public Function SelectFields() As DataTable
Dim strCon As String = Me.GetStringConection.ConnectionString
Dim ds As New DataSet
Dim oCon As New SqlConnection(strCon)
Dim da As New SqlDataAdapter(Me.Select_Command.CommandText, oCon)
Try
oCon.Open()
da.Fill(ds)
Catch ex As Exception
Me.Error = ex.ToString
Finally
oCon.Open()
End Try
Return ds.Tables.Item(0)
End Function
'INSERTAR (INSERT)
Public Function InsertFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Insert_Command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.close()
End Try
Return success
End Function
'ELIMINAR (DELETE)
Public Function DeleteFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Delete_Command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.Close()
End Try
Return success
End Function
'ACTUALIZAR (UPDATE)
Public Function UpdateFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Update_command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.close()
End Try
Return success
End Function
End Class
End Namespace
CODIGO DE UNO DEL BOTON INSERTAR EN UN WEB FORM
Partial Class Secuencial
Inherits System.Web.UI.Page
Dim oCon As New Contabilidad.data.dbOpciones
Private Sub Secuenciales()
oCon.Server = "DESARROLLO"
oCon.Database = "BASE"
oCon.UserId = "sa"
oCon.Password = "sa"
End Sub
Protected Sub cmdInsertar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdInsertar.Click
Me.Secuenciales()
Dim _insert As New System.Data.SqlClient.SqlCommand("INSERT INTO CONTB_SECUENCIAL(SECUENCIAL_INGRESO,SECUENCIAL_EGRESO, SECUENCIAL_DIARIO, SECUENCIAL_ASIENTO, SECUENCIAL_RETEN_FUENTE, SECUENCIAL_RETEN_IVA) VALUES('" + Me.txtIngreso.Text + "','" + Me.txtEgreso.Text + "','" + Me.txtDiario.Text + "','" + Me.txtAsiento.Text + "','" + Me.txtFuente.Text + "','" + Me.txtIva.Text + ")")
oCon.Insert_Command = _insert
Dim status As Boolean = oCon.InsertFields()
End Sub
Hasta el momento estoy realizando un proyecto contable con ASP.NET , con lenguaje Visual.net 2005 y base de datos SQL 2000.
Para este proyecto me cree una clase en donde tengo declarado las propiedades, conexion, llamada a los enventos de insetar, borra, actualizar, etc. Yo creía que estaba realizando ya 3 capas pero me di cuenta que no es asi pues en cada web form en los respectivos botones realizaba los respectivos insert, update y delete como lo prodran ver en le codigo que pongo a continuacion.....
POR FAVOR NECESITO ME INDIQUEN COMO HAGO QUE MAS ME FALTA PARA QUE SEA 3 CAPAS .... ES URGENTE PUES DE ESTO DEPENDE MI PROYECTO
CODIGO CLASE dbopciones.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Namespace Contabilidad.data ' Nombre del Namespace como vamos a instancias nuestras paginas aspx
Public Class dbOpciones 'Creacion de la Clase dbOperaciones
Sub New()
End Sub
'Atributos de nuestra clase
Private _Database As String
Private _Delete_command As SqlCommand
Private _Insert_command As SqlCommand
Private _Password As String
Private _Select_Command As SqlCommand
Private _Server As String
Private _Update_command As SqlCommand
Private _UserId As String
Public [Error] As String
Public Property Database() As String ' Propiedades de la Clase para acceder desde las paginas aspx
Get
Return _Database
End Get
Set(ByVal value As String)
_Database = value
End Set
End Property
Public Property Delete_Command() As SqlCommand
Get
Return _Delete_command
End Get
Set(ByVal value As SqlCommand)
_Delete_command = value
End Set
End Property
Public Property Insert_Command() As SqlCommand
Get
Return _Insert_command
End Get
Set(ByVal value As SqlCommand)
_Insert_command = value
End Set
End Property
Public Property Password() As String
Get
Return _Password
End Get
Set(ByVal value As String)
_Password = value
End Set
End Property
Public Property Select_Command() As SqlCommand
Get
Return _Select_Command
End Get
Set(ByVal value As SqlCommand)
_Select_Command = value
End Set
End Property
Public Property Server() As String
Get
Return _Server
End Get
Set(ByVal value As String)
_Server = value
End Set
End Property
Public Property Update_command() As SqlCommand
Get
Return _Update_command
End Get
Set(ByVal value As SqlCommand)
_Update_command = value
End Set
End Property
Public Property UserId() As String
Get
Return _UserId
End Get
Set(ByVal value As String)
_UserId = value
End Set
End Property
'Metodos de nuestra calse
Public Function GetStringConection() As SqlConnection
Return New SqlConnection("Data Source =..SQLEXPRESS;AttachDbFilename=C:MODCONTABILIDADApp_DataBase.mdf;Integrated Security=True;User Instance=True")
End Function
'Métodos que interactúan directamente con la base de datos
'BUSQUEDA Y SELECCION (SELECT)
Public Function SelectFields() As DataTable
Dim strCon As String = Me.GetStringConection.ConnectionString
Dim ds As New DataSet
Dim oCon As New SqlConnection(strCon)
Dim da As New SqlDataAdapter(Me.Select_Command.CommandText, oCon)
Try
oCon.Open()
da.Fill(ds)
Catch ex As Exception
Me.Error = ex.ToString
Finally
oCon.Open()
End Try
Return ds.Tables.Item(0)
End Function
'INSERTAR (INSERT)
Public Function InsertFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Insert_Command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.close()
End Try
Return success
End Function
'ELIMINAR (DELETE)
Public Function DeleteFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Delete_Command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.Close()
End Try
Return success
End Function
'ACTUALIZAR (UPDATE)
Public Function UpdateFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Update_command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.close()
End Try
Return success
End Function
End Class
End Namespace
CODIGO DE UNO DEL BOTON INSERTAR EN UN WEB FORM
Partial Class Secuencial
Inherits System.Web.UI.Page
Dim oCon As New Contabilidad.data.dbOpciones
Private Sub Secuenciales()
oCon.Server = "DESARROLLO"
oCon.Database = "BASE"
oCon.UserId = "sa"
oCon.Password = "sa"
End Sub
Protected Sub cmdInsertar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdInsertar.Click
Me.Secuenciales()
Dim _insert As New System.Data.SqlClient.SqlCommand("INSERT INTO CONTB_SECUENCIAL(SECUENCIAL_INGRESO,SECUENCIAL_EGRESO, SECUENCIAL_DIARIO, SECUENCIAL_ASIENTO, SECUENCIAL_RETEN_FUENTE, SECUENCIAL_RETEN_IVA) VALUES('" + Me.txtIngreso.Text + "','" + Me.txtEgreso.Text + "','" + Me.txtDiario.Text + "','" + Me.txtAsiento.Text + "','" + Me.txtFuente.Text + "','" + Me.txtIva.Text + ")")
oCon.Insert_Command = _insert
Dim status As Boolean = oCon.InsertFields()
End Sub
Valora esta pregunta


0