You are on page 1of 4

Detalle Orden: CapaLogica De Negocios

Imports CapaAccesoDatos
Imports Entidad
Public Class Detalle_OrdenLN
Public Shared Function ListarOrdenPago(ObjO As Orden_Pago) As String
Dim objAD As New Orden_PagoAD
Return Convert.ToString(objAD.ListarOrdenPago(ObjO))
End Function
Public Shared Function ListarOrdenPago02(objO As Orden_Pago) As String
Dim objAD As New Orden_PagoAD
Return objAD.ListarOrdenPago02(objO)
End Function
End Class
Orden Pago : Entidades
Public Class Orden_Pago

Private m_Estado As String


Public Property Estado() As String
Get
Return m_Estado
End Get
Set(ByVal value As String)
m_Estado = value
End Set
End Property
Private m_Descripcion As String
Public Property Descripcion() As String
Get
Return m_Descripcion
End Get
Set(ByVal value As String)
m_Descripcion = value
End Set
End Property
Private m_Fecha As Date
Public Property Fecha() As Date
Get
Return m_Fecha
End Get
Set(ByVal value As Date)
m_Fecha = value
End Set
End Property
Private m_Monto As Double
Public Property Monto() As Double
Get
Return m_Monto
End Get
Set(ByVal value As Double)
m_Monto = value
End Set
End Property
Private m_IDOrden As Integer
Public Property IDOrden() As Integer
Get
Return m_IDOrden
End Get
Set(ByVal value As Integer)
m_IDOrden = value
End Set
End Property
End Class
Orden Pago : CapaAccesoADatos
Imports Entidad
Imports System.Data.SqlClient
Public Class Orden_PagoAD
Public Function ListarOrdenPago(objO As Orden_Pago) As Integer
Dim cn As New SqlConnection("server=(local); Integrated Security=true; database=AreadeLogistica")
Dim cmd As New SqlCommand
Try
cn.Open()
cmd.Connection = cn
cmd.CommandText = "sp_BuscarOrden"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@IDOrden", SqlDbType.Int).Value = Trim(objO.IDOrden)

Dim Lector As SqlDataReader


Lector = cmd.ExecuteReader
If Lector.HasRows = True Then
While Lector.Read
objO.Monto = Lector.Item(0)
objO.Estado = Lector.Item(1)
End While
End If
Return objO.Monto
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
cn.Close()
End Try
End Function

Public Function ListarOrdenPago02(objO As Orden_Pago) As String


Dim cn As New SqlConnection("server=(local); Integrated Security=true; database=AreadeLogistica")
Dim cmd As New SqlCommand
Try
cn.Open()
cmd.Connection = cn
cmd.CommandText = "sp_BuscarOrden"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@IDOrden", SqlDbType.Int).Value = Trim(objO.IDOrden)

Dim Lector As SqlDataReader


Lector = cmd.ExecuteReader
If Lector.HasRows = True Then
While Lector.Read
objO.Estado = Lector.Item(1)
End While
End If
Return Convert.ToString(objO.Estado)
Catch ex As Exception
Finally
cn.Close()
End Try
End Function
End Class

Public Class frmDETALLE_DE_ORDEN


Private Sub BorrarDatos()
TxtDNI.Clear()
TxtIDSecretaria.Clear()
TxtIDOrden.Clear()
TxtFecha.Clear()
TxtUbicacion.Clear()
End Sub

Private Sub MostrarDetalle()


With DataSet.Tables("Detalles").Rows(xPosicion)
TxtDNI.Text = .Item(0)
TxtIDSecretaria = .Item(1)
TxtIDOrden = .Item(2)
TxtFecha = .Item(3)
TxtUbicacion = .Item(4)
End With
End Sub
Private Sub frmDETALLE_DE_ORDEN_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If NumOperacion = Operacion.Nuevo Then
Me.Text = "Adicionar un Detalle"
BorrarDatos()
ElseIf NumOperacion = Operacion.Editar Then
Me.Text = "Actualizar Detalle"
MostrarDetalle()
ElseIf NumOperacion = Operacion.Eliminar Then
Me.Text = "Eliminar un Producto"
MostrarDetalle()
End If
End Sub

Private Sub BtnAceptar_Click(sender As Object, e As EventArgs) Handles BtnAceptar.Click


With DataSet.Tables("Detalles")
Dim Fila As DataRow
If NumOperacion = Operacion.Nuevo Then
Fila = .NewRow
Fila(0) = CInt(TxtIDOrden.Text)
Fila(1) = CDate(TxtFecha.Text)
Fila(2) = TxtUbicacion.Text

.Rows.Add(Fila)
ElseIf NumOperacion = Operacion.Editar Then
.BeginInit()
Fila = .Rows(xPosicion)
Fila(0) = CInt(TxtIDOrden.Text)
Fila(1) = CDate(TxtFecha.Text)
Fila(2) = TxtUbicacion.Text

.EndInit()
ElseIf NumOperacion = Operacion.Eliminar Then
Fila = .Rows(xPosicion)
Fila.Delete()
End If
End With
Close()
End Sub

Private Sub BtnCancelar_Click(sender As Object, e As EventArgs) Handles BtnCancelar.Click


Close()
End Sub
End Class

.
Imports Entidad
Imports CapaLogicaNegocios
Imports System.Data.SqlClient
Imports System.Int32
Public Class frmOrdenesyDetalle
Dim con As New SqlConnection("Server=(local); Integrated Security=true; Database=AreadeLogistica")
Dim DataAdapter As New SqlDataAdapter("", con)
Dim DataSet As New DataSet()
Private Sub frmOrdenesyDetalle_Load(sender As Object, e As EventArgs) Handles MyBase.Load

DataAdapter.SelectCommand.CommandText = "select OP.IDOrden, OP.Descripcion, E.ApPaterno+' '+E.Nombre as


Empleado from ORDEN_PAGO OP join EMPLEADO E on OP.DNI=E.DNI"
DataAdapter.Fill(DataSet, "Ordenes")

DataAdapter.SelectCommand.CommandText = "select IDOrden,


Fecha,
Ubicacin
from Detalle_Orden"
DataAdapter.Fill(DataSet, "Detalles")

Dim DataRelation As New DataRelation("DetallesOrden", DataSet.Tables(0).Columns(0), DataSet.Tables(1).Columns(0))


DataSet.Relations.Add(DataRelation)
DGOrdenes.DataSource = DataSet.Tables("Ordenes")

End Sub

Private Sub MostrarDetalle(ByVal sender As Object, e As EventArgs) Handles BtnNuevo.Click, BtnEditar.Click, BtnEliminar.Click
xPosicion = DGOrdenes.CurrentRowIndex
NumOperacion = sender.tag
Dim frmNewDetalle As New frmDETALLE_DE_ORDEN
frmNewDetalle.ShowDialog()
End Sub

Private Sub BtnGenerar_Click(sen As Object, e As EventArgs) Handles BtnGenerar.Click


Dim objO As New Orden_Pago
objO.IDOrden = txtOrden.Text
objO.Estado = txtEstado.Text
txtMonto.Text = Detalle_OrdenLN.ListarOrdenPago(objO)
If txtMonto.Text = "" Then
MessageBox.Show("Error Orden de Pago, No existe", "Orden de Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtOrden.Text = ""
txtOrden.Focus()
End If
txtEstado.Text = Detalle_OrdenLN.ListarOrdenPago02(objO)
If txtEstado.Text = "" Then
MessageBox.Show("Error Orden de Pago No existe", "Error de Orden", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtOrden.Text = ""
txtOrden.Focus()
End If
End Sub

Private Sub BtnEnviar_Click(sender As Object, e As EventArgs) Handles BtnEnviar.Click


Try
Dim CommandBuilder As New SqlCommandBuilder(DataAdapter)
DataAdapter.Update(DataSet, "Detalles")
MessageBox.Show("Operacion realizada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally

DataAdapter.Fill(DataSet, "Detalles")
DGOrdenes.DataSource = DataSet.Tables(0)
End Try
End Sub

End Class

You might also like