182 lines
8.7 KiB
VB.net
182 lines
8.7 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
Imports System.Data.SqlClient
|
|
Imports Extensiones
|
|
Imports Extensiones.ModExtensiones
|
|
|
|
Partial Class ListadoContratos
|
|
Inherits ClsPaginas
|
|
|
|
Private Property CveContrato As Integer
|
|
Get
|
|
Return ViewState("CveContrato").ToString().ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveContrato") = value
|
|
End Set
|
|
End Property
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
ViewState("CveContrato") = 0
|
|
InicializaCombos()
|
|
CargaDatos()
|
|
End If
|
|
End Sub
|
|
Private Sub InicializaCombos()
|
|
DdlTipoAF.DataSource = GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa)
|
|
DdlTipoAF.DataBind()
|
|
DdlTipoAF.Items.Insert(0, New ListItem("Seleccione", ""))
|
|
|
|
'Lista Chofer'
|
|
DdlChofer.DataSource = GlobalDTRHPersonal(185)
|
|
DdlChofer.DataBind()
|
|
DdlChofer.Items.Insert(0, New ListItem("Seleccione", ""))
|
|
|
|
UpModal.Update()
|
|
End Sub
|
|
Private Sub CargaDatos()
|
|
Dim ObjContratos As New ClsContratos
|
|
If ObjContratos.GetContratos(-1, UsuarioActual.CveEmpresa, TipoContrato:=2) Then
|
|
GvContratos.DataSource = ObjContratos.DtResultados
|
|
End If
|
|
GvContratos.DataBind()
|
|
UpTitulos.Update()
|
|
|
|
End Sub
|
|
Protected Sub MostrarModal(Optional Descripcion As String = "", Optional FechaSalida As String = "", Optional FechaRegreso As String = "", Optional Observaciones As String = "", Optional Ubicacion As String = "", Optional Transporte As String = "", Optional CveCliente As Integer = 0, Optional Dolares As String = "", Optional Pesos As String = "", Optional Anticipo As String = "", Optional Boton As String = "Guardar", Optional Chofer As String = "")
|
|
|
|
'DdlClientes.SelectedText = Cliente
|
|
TxtDescripcion.Text = Descripcion
|
|
TxtUbicacion.Text = Ubicacion
|
|
TxtFechaSalida.Text = FechaSalida
|
|
TxtFechaRegreso.Text = FechaRegreso
|
|
TxtObservaciones.Text = Observaciones
|
|
TxtUbicacion.Text = Ubicacion
|
|
DdlTipoAF.SelectedValue = Transporte
|
|
DdlClientes.SelectedText = GlobalDTCliente(UsuarioActual.CveEmpresa, -1, CveCliente:=CveCliente).FiltroPrimeroValor("NombreComercial")
|
|
DdlClientes.SelectedValue = CveCliente.ToString
|
|
DdlChofer.SelectedValue = Chofer
|
|
TxtObservaciones.Text = Observaciones
|
|
TxtDolares.Text = Dolares
|
|
TxtPesos.Text = Pesos
|
|
TxtAnticipo.Text = Anticipo
|
|
BtnGuardar.Text = Boton
|
|
Dim EstatusContrato As String
|
|
If EstatusContrato <> "" Then
|
|
LbEstatus.Visible = True
|
|
DdlEstatusContrato.Visible = True
|
|
DdlEstatusContrato.SelectedValue = EstatusContrato
|
|
End If
|
|
'DdlEstatusContrato.Text = EstatusContrato
|
|
myModalLabel.InnerHtml = $"{Boton} Contrato"
|
|
UpModal.Update()
|
|
RegistraScript(String.Format("$('#{0}').modal('show');", "ModalAgregar"))
|
|
End Sub
|
|
Private Sub LBAgregarContrato_Click(sender As Object, e As EventArgs) Handles LBAgregarContrato.Click
|
|
MostrarModal()
|
|
End Sub
|
|
Protected Sub AddContrato(sender As Object, e As EventArgs)
|
|
|
|
If DdlClientes.SelectedValue = "" Then
|
|
Alert("Debe seleccionar al cliente", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim ObjContratos As New ClsContratos
|
|
ObjContratos.IniciaTransacSQL()
|
|
|
|
Dim CveEstatusInicial As Integer = 10
|
|
Dim CveContratoHijo As Integer = -1
|
|
Dim CveContratoTipo As Integer = 2
|
|
Dim retorno As Boolean = False
|
|
|
|
If ObjContratos.GetContratosEstatus(UsuarioActual.CveEmpresa) Then
|
|
CveEstatusInicial = ObjContratos.DtResultados.FiltroPrimeroValor("CveContratoEstatus", "TipoEstatus=1").ToEntero
|
|
End If
|
|
'Agregar contrato
|
|
If BtnGuardar.Text = "Guardar" Then
|
|
CveContratoHijo = ObjContratos.AddContratos("", TxtDescripcion.Text, "", UsuarioActual.CveProveedor, DdlClientes.SelectedValue.ToEntero, -1, TxtFechaSalida.Text.ToDate, TxtFechaRegreso.Text.ToDate, TxtUbicacion.Text, "", 10, -1, -1, -1, -1, "", "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False, TxtAnticipo.Text.ToDecimal, TxtPesos.Text.ToDecimal, TxtDolares.Text.ToDecimal, -1, 0, CveContratoTipo:=2, CveContratosEstatus:=1, CveTipoAF:=DdlTipoAF.SelectedValue.ToEntero, CveChofer:=DdlChofer.SelectedValue.ToEntero)
|
|
If CveContratoHijo > 0 Then
|
|
ObjContratos.Commit()
|
|
Alert("Agregado Correctamente.")
|
|
End If
|
|
End If
|
|
|
|
'Actualizar contrato
|
|
If BtnGuardar.Text = "Editar" Then
|
|
retorno = ObjContratos.UpdateContratos(CveContrato, "", TxtDescripcion.Text, "", -1, DdlClientes.SelectedValue.ToEntero, -1, TxtFechaSalida.Text.ToDate, TxtFechaRegreso.Text.ToDate, TxtUbicacion.Text, "", 10, -1, -1, -1, -1, "", "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False, TxtAnticipo.Text.ToDecimal, TxtPesos.Text.ToDecimal, TxtDolares.Text.ToDecimal, -1, 0, CveContratoTipo:=2, CveContratosEstatus:=1, CveChofer:=DdlChofer.SelectedValue.ToEntero, CveTipoAF:=DdlTipoAF.SelectedValue.ToEntero)
|
|
|
|
ObjContratos.Commit()
|
|
Alert("Actualizado Correctamente.")
|
|
End If
|
|
|
|
TxtDescripcion.Text = ""
|
|
TxtFechaSalida.Text = ""
|
|
TxtFechaRegreso.Text = ""
|
|
TxtObservaciones.Text = ""
|
|
TxtUbicacion.Text = ""
|
|
DdlClientes.SelectedText = ""
|
|
DdlTipoAF.SelectedValue = ""
|
|
DdlChofer.SelectedValue = ""
|
|
TxtDolares.Text = ""
|
|
TxtPesos.Text = ""
|
|
TxtAnticipo.Text = ""
|
|
BtnGuardar.Text = "Guardar"
|
|
|
|
ObjContratos.Dispose()
|
|
CargaDatos()
|
|
|
|
End Sub
|
|
Protected Sub UpdateContrato(sender As Object, e As EventArgs)
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
ViewState("CveContrato") = GvRow.DataKey("CveContrato")
|
|
MostrarModal(
|
|
Descripcion:=GvRow.DataKey("DescripcionContrato"), FechaSalida:=GvRow.DataKey("FechaInicial").ToDateTime.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "T"), FechaRegreso:=GvRow.DataKey("FechaFinal").ToDateTime.ToString("yyyy-MM-dd HH:mm:ss").Replace(" ", "T"), Observaciones:=GvRow.DataKey("DescripcionContrato"), Ubicacion:=GvRow.DataKey("Ubicacion"), Transporte:=GvRow.DataKey("CveTipoAF"), CveCliente:=GvRow.DataKey("CveCliente").ToEntero, Dolares:=GvRow.DataKey("Importe"), Pesos:=GvRow.DataKey("ImporteMax"), Anticipo:=GvRow.DataKey("ImporteMin"), Boton:="Editar", Chofer:=GvRow.DataKey("CveChofer"))
|
|
End Sub
|
|
Protected Sub RemoveContrato(sender As Object, e As EventArgs)
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
Dim ObjContratos As New ClsContratos
|
|
|
|
If ObjContratos.RemoveContrato(GvRow.DataKey("CveContrato").ToEntero, UsuarioActual.CveEmpresa) Then
|
|
Alert("Contrato eliminado correctamente")
|
|
CargaDatos()
|
|
End If
|
|
ObjContratos.Dispose()
|
|
End Sub
|
|
|
|
Protected Sub LBExcel_Click(sender As Object, e As EventArgs) Handles LBExcel.Click
|
|
GvContratos.ExportToExcel("ReporteCompras" & NowADS().ToShortDateString)
|
|
End Sub
|
|
|
|
Protected Sub Consultar(sender As Object, e As EventArgs)
|
|
|
|
If DdlClientesConsulta.SelectedValue = "" Then
|
|
Alert("Debe seleccionar al cliente", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim cliente As Integer = DdlClientesConsulta.SelectedValue.ToEntero
|
|
Dim estatus As Integer = DdlEstatusConsulta.SelectedValue.ToEntero
|
|
Dim fechaInicial As DateTime = txtFechaI.Text.ToDate
|
|
Dim fechaFinal As DateTime = txtFechaF.Text.ToDate
|
|
|
|
Dim query As String = "SELECT *, ISNULL(Cli.NombreComercial,'') AS NombreComercial FROM Con_Contratos C LEFT JOIN Clientes Cli with(nolock) ON Cli.CveCliente = C.CveCliente WHERE C.CveCliente = @Cliente AND EstatusContrato = @Estatus AND FechaInicial BETWEEN @FechaInicial AND @FechaFinal"
|
|
|
|
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("Conexion").ConnectionString)
|
|
Using command As New SqlCommand(query, connection)
|
|
command.Parameters.AddWithValue("@Cliente", cliente)
|
|
command.Parameters.AddWithValue("@Estatus", estatus)
|
|
command.Parameters.AddWithValue("@FechaInicial", fechaInicial)
|
|
command.Parameters.AddWithValue("@FechaFinal", fechaFinal)
|
|
|
|
connection.Open()
|
|
Dim reader As SqlDataReader = command.ExecuteReader()
|
|
GvContratos.DataSource = reader
|
|
GvContratos.DataBind()
|
|
End Using
|
|
End Using
|
|
|
|
UpTitulos.Update()
|
|
End Sub
|
|
End Class
|