Files
SIG/Transportes/RepContratosCalendario.aspx.vb
2025-02-04 13:06:19 -07:00

966 lines
45 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports ADSNetLibrary.SIGAPI.Helpers
Imports Extensiones.ModExtensiones
Imports GemBox.Spreadsheet
Imports Microsoft.Reporting.WebForms
Imports Newtonsoft.Json.Linq
Partial Class RepContratosCalendario
Inherits ClsPaginas
#Region "PROPIEDADES"
Public Property DtAvance() As DataTable
Get
Return CType(ViewState("DtAvance"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtAvance") = value
End Set
End Property
Public Property Contrato As String
Get
Return IfNull(ViewState("Contrato"), "").ToString()
End Get
Set(value As String)
ViewState("Contrato") = value
End Set
End Property
Public Property CveContrato As Integer
Get
Return HdnCveContrato.Value.ToEntero
End Get
Set(value As Integer)
HdnCveContrato.Value = value.ToString
End Set
End Property
#End Region
Public Property RCveEvento As Integer
Get
Return If(ViewState("RCveEvento") IsNot Nothing, ViewState("RCveEvento").ToString().ToEntero(), 0)
End Get
Set(value As Integer)
ViewState("RCveEvento") = value
End Set
End Property
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
RCveEvento = 0
txtFechaI.Text = NowADS().FirstDayOfMonth.ToShortDateString()
txtFechaF.Text = GetLastDayOfMonth(NowADS()).ToShortDateString()
InicializaCombos()
CargaDatos()
End If
'InicializaCalendar()
End Sub
Private Sub CargaDatos()
Dim ObjContratos As New ClsContratos
'EL fondo de las líneas es blanco, por eso cambio el color a negro de la cabecera
GvContratos.HeaderStyle.ForeColor = Drawing.Color.Black
Dim CveCliente As Integer = DdlCliente.SelectedValue.ToEntero
If CveCliente = 0 Then CveCliente = -1
If ObjContratos.GetContratosReporte(UsuarioActual.CveEmpresa, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate.AddDays(6),
DdlCliente.SelectedValue.ToEntero,
CveSubProyecto:=DdlSubProyectos.SelectedValue.ToEntero,
CveEstatus:=DdlEstatusConsulta.SelectedValue.ToEntero,
CveTipoContrato:=34,
CveTipoAF:=DdlTipoUnidad.SelectedValue.ToEntero,
CveChofer:=DdlChoferFiltro.SelectedValue.ToEntero) Then
DtAvance = ObjContratos.DtResultados.Copy()
CargaCronograma(DdlTipoVistaCalendario.SelectedValue.ToEntero)
'CargaDiagramadeGant(DdlTipoVista.SelectedValue.ToEntero)
'CargaScheduler(DdlTipoVista.SelectedValue.ToEntero)
End If
GvContratos.DataSource = DtAvance
DdlEstatusContrato.Enabled = UsuarioActual.TienePermisoProceso(173)
ObjContratos.Dispose()
GvContratos.DataBind()
UpTitulos.Update()
InicializaCalendar()
End Sub
Public Shared Function GetLastDayOfMonth(ByVal dateTime As DateTime) As DateTime
Return New DateTime(dateTime.Year, dateTime.Month, DateTime.DaysInMonth(dateTime.Year, dateTime.Month))
End Function
Private Sub CargaScheduler(Optional TipoVista As Integer = -1)
' var data = [
'{
'Id: 1,
'Subject: 'Board Meeting',
'Description: 'Meeting to discuss business goal of 2021.',
'StartTime: New Date(2021, 7, 1, 9, 0),
'EndTime: New Date(2021, 7, 2, 11, 0),
'RoomId: 1
'}]
'[ { text 'Room A', id: 1, color: '#98AFC7' },]
Dim StrFiltro As String = ""
If DdlTipoUnidad.SelectedValue.ToEntero > 0 Then StrFiltro = " AND CveTipoActivoFijo = " & DdlTipoUnidad.SelectedValue
Dim DtUnidades As DataTable = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltraParametros("Codigo <> '' AND MedidaVehicular IN (2,3) " & StrFiltro, Orderby:=" TipoActivoFijo ASC, CodigoNumeroOrden ASC", DistinctColumns:={"Codigo", "CveActivoFijo"})
Dim jsonData As New JArray()
Dim jsonCategorias As New JArray()
Dim strAF As New StringBuilder
Dim strData As New StringBuilder
Dim strAFData As New StringBuilder
strData.AppendLine("[")
For Each Row As DataRow In DtAvance.FiltraParametros("CodigoAF <> '' AND TipoEstatus <> 3").Rows
Dim FI As Date = Row("FechaInicial").ToString.ToDate
Dim FF As Date = Row("FechaFinal").ToString.ToDate
Dim obj As New JObject(
New JProperty("Id", Row("CveContrato").ToString),
New JProperty("Subject", $"{Row("CodigoAF").ToString}"),
New JProperty("Description", $"{Row("NombreAF")}"),
New JProperty("StartTime", $"new Date({FI.Year},{FI.Month - 1},{FI.Day},{FI.Hour},{FI.Minute})"),
New JProperty("EndTime", $"new Date({FF.Year},{FF.Month - 1},{FF.Day},{FF.Hour},{FF.Minute})"),
New JProperty("IsBlock", "true"),
New JProperty("RoomId", Row("CveAF").ToString)
)
jsonData.Add(obj)
strData.AppendLine("{")
strData.AppendLine($"Id: {Row("CveContrato").ToString},")
strData.AppendLine($"Subject: {$"'{Row("NumeroContrato").ToString}"}',")
strData.AppendLine($"StartTime: new Date({FI.Year},{FI.Month - 1},{FI.Day},{FI.Hour},{FI.Minute}),")
strData.AppendLine($"EndTime: new Date({FF.Year},{FF.Month - 1},{FF.Day},{FI.Hour},{FF.Minute}),")
strData.AppendLine($"RoomId: {Row("CveAF").ToString}")
strData.AppendLine("},")
strAF.AppendFormat("{0},", Row("CveAF"))
Next
strData.AppendLine("{}]")
If TipoVista = 1 Then 'solo con viajes
DtUnidades = DtUnidades.FiltraParametros($"CveActivoFijo IN ({strAF.ToString})")
End If
Dim random = New Random()
strAFData.AppendLine("[")
For Each Row As DataRow In DtUnidades.Rows
Dim obj As New JObject(
New JProperty("text", Row("Codigo").ToString),
New JProperty("id", Row("CveActivoFijo").ToString),
New JProperty("color", String.Format("#{0:X6}", random.Next(16777216)))
)
jsonCategorias.Add(obj)
strAFData.AppendLine("{")
strAFData.AppendLine($"text: '{Row("Codigo").ToString}',")
strAFData.AppendLine($"id: {Row("CveActivoFijo").ToString},")
strAFData.AppendLine($"color: '{String.Format("#{0:X6}", random.Next(16777216))}'")
strAFData.AppendLine("},")
Next
strAFData.AppendLine("{}]")
'RegistraScript($"cargaScheduler({jsonData.ToString()},{jsonCategorias.ToString()},{TipoVista});", "A1")
'RegistraScript($"cargaScheduler({strData.ToString().TrimEnd(","c) },{strAFData.ToString().TrimEnd(","c) },{TipoVista}, {$"new Date({txtFechaI.ToDate.ToString("yyyy, MM, dd, hh, MM")})"}, {$"new Date({txtFechaF.ToDate.ToString("yyyy, MM, dd, hh, MM")})"});", "A1")
Dim FechaInicio As Date = txtFechaI.Text.ToDate
Dim FechaFin As Date = txtFechaF.Text.ToDate
'strData.Append($",new Date({FechaInicio.Year},{FechaInicio.Month - 1},{FechaInicio.Day})")
'strData.Append($",new Date({FechaFin.Year},{FechaFin.Month - 1},{FechaFin.Day})")
'RegistraScript($"cargaScheduler({strData.ToString().TrimEnd(","c) },{strAFData.ToString().TrimEnd(","c) },{TipoVista}, {$" new Date({FechaInicio.Year},{FechaInicio.Month - 1},{FechaInicio.Day})"}, {$"new Date({FechaFin.Year},{FechaFin.Month - 1},{FechaFin.Day})"});", "A1")
' RegistraScript($"cargaScheduler({strData.ToString().TrimEnd(","c) },{strAFData.ToString().TrimEnd(","c) },{TipoVista}, {$" new Date({FechaInicio.Year},{FechaInicio.Month - 1},{FechaInicio.Day})"}, {$"new Date(2024,09,5)"});", "A1")
UPScheduler.Update()
End Sub
Private Sub CargaCronograma(Optional TipoVista As Integer = -1)
If DtAvance IsNot Nothing Then
Dim strData As New StringBuilder
Dim strAFData As New StringBuilder
Dim StrFiltro As String = "" 'solo unidades activas
If DdlTipoUnidad.SelectedValue.ToEntero > 0 Then StrFiltro = " AND CveTipoActivoFijo = " & DdlTipoUnidad.SelectedValue
Dim DtUnidades As DataTable = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltraParametros("Codigo <> '' AND CveEstadoActivoFijo = 1 AND MedidaVehicular IN (2,3) " & StrFiltro, Orderby:=" TipoActivoFijo ASC, CodigoNumeroOrden ASC", DistinctColumns:={"Codigo", "CveActivoFijo"})
Dim jsonData As New JArray()
Dim jsonCategorias As New JArray()
Dim random = New Random()
'DATOS
Dim strAF As New StringBuilder
'se quitan los estatus cancelados
Dim randomNumber As New Random
strData.AppendLine("[")
For Each Row As DataRow In DtAvance.FiltraParametros("CodigoAF <> '' AND TipoEstatus <> 3").Rows
Dim obj As New JObject(
New JProperty("category", Row("CodigoAF")),
New JProperty("fromDate", Row("FechaInicial").ToString().ToDateTime().ToString("yyyy-MM-dd HH:mm:ss")),
New JProperty("toDate", Row("FechaFinal").ToString().ToDateTime.ToString("yyyy-MM-dd HH:mm:ss")),
New JProperty("columnSettings", New JObject(
New JProperty("fill", String.Format("#{0:X6}", random.Next(16777216)))
)),
New JProperty("unidad", Row("NombreAF")),
New JProperty("cveContrato", Row("CveContrato")),
New JProperty("contrato", Row("NumeroContrato")),
New JProperty("fechaFinalViaje", Row("FechaFinal").ToString().ToDateTime().ToString("yyyy-MM-dd HH:mm:ss"))
)
jsonData.Add(obj)
Dim FI As Date = Row("FechaInicial").ToString.ToDate
Dim FF As Date = Row("FechaFinal").ToString.ToDate
strData.AppendLine("{")
strData.AppendLine($"category: '{Row("CodigoAF").ToString.Replace("'", "")}',")
strData.AppendLine($"fromDate: '{FI.ToString("yyyy-MM-dd HH:mm:ss")}',")
strData.AppendLine($"toDate: '{FF.ToString("yyyy-MM-dd HH:mm:ss")}',")
'strData.AppendLine($"columnSettings: {{fill: '{String.Format("#{0:X6}", random.Next(16777216))}'}},")
strData.AppendLine($"unidad: '{Row("NombreAF").ToString.Replace("'", "")}',")
strData.AppendLine($"color: am4core.color('" & String.Format("#{0:X6}", random.Next(16777216)) & "'),")
strData.AppendLine($"cveContrato: {Row("CveContrato").ToString.ToEntero},")
strData.AppendLine($"contrato: '{Row("NumeroContrato").ToString}',")
strData.AppendLine($"fechaFinalViaje: '{FF.ToString("yyyy-MM-dd HH:mm:ss")}',")
strData.AppendLine($"cliente: '{Row("NombreComercial").ToString.Replace("'", "")}'")
strData.AppendLine("},")
strAF.AppendFormat("{0},", Row("CveAF"))
'uniad contrato y duracion
'Dim unidad As String = $"{Row("CodigoAF")}-{Row("NombreAF")}"
'Dim duracion As String = $"{Row("FechaInicial").ToString.ToDate.ToString("dd/MM/yyyy HH:mm")} - {Row("FechaFinal").ToString.ToDate.ToString("dd/MM/yyyy HH:mm")}"
'str.AppendLine(String.Format("{0}{{id: {1}, text: ""{2}"", start_date: ""{3:yyyy/MM/dd HH:mm}"", end_date: ""{4:yyyy/MM/dd HH:mm}"", parent: {5}, progress:{6}, open: true, unidad: ""{7}"",duracion: ""{8}"", color: ""{9}"",codigoaf: ""{10}""}}",
' separator, Row("CveContrato"), Row("NumeroContrato").ToString().Replace("\\", "\\\\").Replace("""", "\"""), Row("FechaInicial"), Row("FechaFinal"), 0, 100, unidad, duracion, ColorAleatorio(randomNumber), Row("CodigoAF").ToString))
'separator = ","
Next
strData.AppendLine("{}]")
If TipoVista = 1 Then 'solo con viajes
DtUnidades = DtUnidades.FiltraParametros($"CveActivoFijo IN ({strAF.ToString})")
End If
'CATEGORIAS 'AGREGAR TODAS LAS UNIDADES
strAFData.AppendLine("[")
For Each Row As DataRow In DtUnidades.Rows
Dim obj As New JObject(
New JProperty("category", Row("Codigo"))
)
jsonCategorias.Add(obj)
strAFData.AppendLine("{")
strAFData.AppendFormat("category: '{0}'", Row("Codigo"))
strAFData.AppendLine("},")
Next
strAFData.AppendLine("{}]")
'RegistraScript($"cargaDiagramaGrant({jsonData.ToString()},{jsonCategorias.ToString()},{TipoVista});", $"{random.Next(16777216)}")
RegistraScript($" cargaDiagramaGrantAMC4({strData.ToString().Replace(",{}", "")},{strAFData.ToString().Replace(",{}", "")},{TipoVista}); ", random.Next(16777216).ToString)
UPPGantt.Update()
UPGat.Update()
End If
End Sub
Private Sub CargaDiagramadeGant(Optional TipoVista As Integer = -1)
Dim randomNumber As New Random
If DtAvance IsNot Nothing Then
Dim str As New StringBuilder()
str.AppendLine("datosGant=[")
If TipoVista = 1 Then 'solo con viajes
Else
Dim StrFiltro As String = ""
If DdlTipoUnidad.SelectedValue.ToEntero > 0 Then StrFiltro = " AND CveTipoActivoFijo = " & DdlTipoUnidad.SelectedValue
Dim DtUnidades As DataTable = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltraParametros("Codigo <> '' AND MedidaVehicular IN (2,3) " & StrFiltro, Orderby:=" TipoActivoFijo ASC, CodigoNumeroOrden ASC", DistinctColumns:={"Codigo", "CveActivoFijo"})
Dim separator As String = ""
Dim encontrados As Integer = 0
Dim CvePadre As Integer = -1
For Each dRowUnidad As DataRow In DtUnidades.Rows
Dim CveActivoFijo As Integer = dRowUnidad("CveActivoFijo").ToString.ToEntero
Dim CodigoAF As String = dRowUnidad("Codigo").ToString
'Dim unidad As String = $"{dRowUnidad("Codigo").ToString}-{dRowUnidad("Descripcion").tostring}"
Dim SeEncontro As Boolean = False
Dim EsHijo As Boolean = False
For Each Row As DataRow In DtAvance.FiltraParametros("CodigoAF <> '' AND TipoEstatus <> 3").Rows
Dim CveActivoFijoContrato As Integer = Row("CveAF").ToString.ToEntero
'If CveActivoFijo = CveActivoFijoContrato Then
' str.AppendLine(String.Format("{0}", separator))
' SeEncontro = True
' Dim unidad As String = $"{Row("CodigoAF")}-{Row("NombreAF")}"
' Dim duracion As String = $"{Row("FechaInicial").ToString.ToDate.ToString("dd/MM/yyyy HH:mm")} - {Row("FechaFinal").ToString.ToDate.ToString("dd/MM/yyyy HH:mm")}"
' str.AppendLine(String.Format("{{id: {1}, text: ""{2}"", start_date: ""{3:yyyy/MM/dd HH:mm}"", end_date: ""{4:yyyy/MM/dd HH:mm}"", parent: {5}, progress:{6}, open: true, unidad: ""{7}"",duracion: ""{8}"", color: ""{9}"",codigoaf: ""{10}""}} ",
' separator, Row("CveContrato"), Row("NumeroContrato").ToString().Replace("\\", "\\\\").Replace("""", "\"""), Row("FechaInicial"), Row("FechaFinal"), 0, 100, unidad, duracion, ColorAleatorio(randomNumber), Row("CodigoAF").ToString))
' separator = ","
' encontrados = encontrados + 1
'End If
If CveActivoFijo = CveActivoFijoContrato Then
str.AppendLine(String.Format("{0}", separator))
SeEncontro = True
Dim unidad As String = $"{Row("CodigoAF")}-{Row("NombreAF")}"
Dim duracion As String = $"{Row("FechaInicial").ToString.ToDate.ToString("dd/MM/yyyy HH:mm")} - {Row("FechaFinal").ToString.ToDate.ToString("dd/MM/yyyy HH:mm")}"
If EsHijo Then
str.AppendLine(String.Format("{{id: {1}, text: ""{2}"", start_date: ""{3:yyyy/MM/dd HH:mm}"", end_date: ""{4:yyyy/MM/dd HH:mm}"", progress:{6}, open: true, unidad: ""{7}"",duracion: ""{8}"", color: ""{9}"",codigoaf: ""{10}"", cvecontrato: ""{11}"", parent: {12} }} ",
separator, Row("CveContrato").ToString, Row("NumeroContrato").ToString().Replace("\\", "\\\\").Replace("""", "\"""), Row("FechaInicial"), Row("FechaFinal"), 0, 100, unidad, duracion, ColorAleatorio(randomNumber), Row("CodigoAF").ToString, Row("CveContrato").ToString, CvePadre)
)
Else
str.AppendLine(String.Format("{{id: {1}, text: ""{2}"", start_date: ""{3:yyyy/MM/dd HH:mm}"", end_date: ""{4:yyyy/MM/dd HH:mm}"", progress:{6}, open: true, unidad: ""{7}"",duracion: ""{8}"", color: ""{9}"",codigoaf: ""{10}"", cvecontrato: ""{11}"",parent: 0 }} ",
separator, Row("CveContrato").ToString, Row("NumeroContrato").ToString().Replace("\\", "\\\\").Replace("""", "\"""), Row("FechaInicial"), Row("FechaFinal"), 0, 100, unidad, duracion, ColorAleatorio(randomNumber), Row("CodigoAF").ToString, Row("CveContrato").ToString)
)
End If
If Not EsHijo Then
CvePadre = Row("CveContrato").ToString.ToEntero
EsHijo = True
End If
separator = ","
encontrados = encontrados + 1
Else
EsHijo = False
End If
Next
If Not SeEncontro Then
If encontrados > 0 Then
separator = ","
End If
str.AppendLine(String.Format("{0}", separator))
str.AppendLine(String.Format("{{id: {1}, text: ""{2}"", start_date: ""{3}"", end_date: ""{4}"", parent: {5}, progress:{6}, open: true, unidad: ""{7}"",duracion: ""{8}"", color: ""{9}"",codigoaf: ""{10}"", hidden: true}} ",
"", CveActivoFijo, -1, txtFechaF.Text.ToDate.ToString("yyyy/MM/dd HH:mm"), txtFechaF.Text.ToDate.ToString("yyyy/MM/dd HH:mm"), 0, 100, "", "", ColorAleatorio(randomNumber), CodigoAF))
separator = ","
End If
'str.AppendLine(String.Format("}"))
Next
End If
str.AppendLine("];loadGant();")
RegistraScript(str.ToString())
UPPGantt.Update()
UPGat.Update()
End If
End Sub
Private Function ColorAleatorio(randomNumber As Random) As String
Dim listaColores As New List(Of String)
listaColores.Add("#94f35a")
listaColores.Add("#1989a9")
listaColores.Add("#5a3c98")
listaColores.Add("#556855")
listaColores.Add("#e199cf")
listaColores.Add("#50cc77")
listaColores.Add("#559f9d")
listaColores.Add("#ede805")
listaColores.Add("#f1e489")
listaColores.Add("#c381f6")
listaColores.Add("#f2496b")
listaColores.Add("#c4d7dc")
listaColores.Add("#f3f9f9")
listaColores.Add("#fd8ffe")
listaColores.Add("#f2496b")
listaColores.Add("#5a8f9c")
listaColores.Add("#87bfbd")
listaColores.Add("#fb01fd")
listaColores.Add("#6836dc")
listaColores.Add("#67627e")
listaColores.Add("#1b9f44")
listaColores.Add("#3a54dc")
listaColores.Add("#fb66f1")
listaColores.Add("#24f6b4")
listaColores.Add("#60feee")
listaColores.Add("#82a199")
listaColores.Add("#93a9e1")
listaColores.Add("#ff8809")
listaColores.Add("#8379ba")
listaColores.Add("#f62ea2")
listaColores.Add("#41cf69")
listaColores.Add("#8624b2")
listaColores.Add("#f4948a")
listaColores.Add("#205da6")
listaColores.Add("#9f38b6")
listaColores.Add("#540466")
listaColores.Add("#7a4e49")
listaColores.Add("#bd22ce")
listaColores.Add("#6d89a0")
listaColores.Add("#7e6d8c")
listaColores.Add("#124a70")
listaColores.Add("#c3d2c2")
listaColores.Add("#506702")
listaColores.Add("#058106")
listaColores.Add("#0485f2")
listaColores.Add("#401685")
Dim ranNumber As Integer = randomNumber.Next(0, listaColores.Count - 1)
Return listaColores(ranNumber)
End Function
'Public Sub loadEvento()
' Dim separator As String = ""
' Dim str As New StringBuilder()
' str.AppendLine("datosGant=[")
' Using oieve As New ClsOIEventos()
' If oieve.GetEventos2(RCveEvento, UsuarioActual.CveEmpresa) AndAlso oieve.DtResultados.Rows.Count > 0 Then
' Dim drow As System.Data.DataRow = oieve.DtResultados.Rows(0)
' LblAsunto.Text = drow("Asunto").ToString()
' End If
' If oieve.GetTareaConHijos(RCveEvento, UsuarioActual.CveEmpresa) Then
' For Each dr As System.Data.DataRow In oieve.DtResultados.Select("Nivel > 0")
' str.AppendLine(String.Format("{0}{{id: {1}, text: ""{2}"", start_date: ""{3:yyyy/MM/dd}"", end_date: ""{4:yyyy/MM/dd}"", parent: {5}, progress:{6}, open: true }}",
' separator, dr("CveEvento"), dr("Asunto").ToString().Replace("\\", "\\\\").Replace("""", "\"""), dr("FechaInicio"), dr("FechaFin"), If(dr("Nivel").ToString().ToEntero() <= 1, 0, dr("CveEventoPadre").ToString().ToEntero()), dr("Avance").ToString().ToDecimal() / 100))
' separator = ","
' Next
' End If
' End Using
' str.AppendLine("];loadGant();")
' RegistraScript(str.ToString())
' UpContenido.Update()
' ' { id: 2, text: "Direccion: evaluación de mercado", start_date: "2020/04/29 00:00", end_date: "2020/05/02 00:00",/*duration: 3,*/ parent: 1, progress: 0.25 }
'End Sub
Private Sub InicializaCalendar()
RegistraScript("InitCalendar();")
DirectCast(Master.FindControl("TSM"), ScriptManager).EnablePageMethods = True
End Sub
Private Sub InicializaCombos()
'Lista de Tipos de activo fijos
Dim dttipoaf As DataTable = GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa).FiltraParametros("MedidaVehicularClave IN (2,3)")
DdlTipoAF.DataSource = dttipoaf
DdlTipoAF.Items.Insert(0, New ListItem("-", "-1"))
DdlTipoAF.DataBind()
DdlTipoUnidad.DataSource = dttipoaf
DdlTipoUnidad.Items.Insert(0, New ListItem("Todos", "-1"))
DdlTipoUnidad.DataBind()
'Lista de Activos fijos
DdlAF.DataSource = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltraParametros(" EstadoActivoFijo= 'Activo' ")
DdlAF.DataBind()
DdlAF.Items.Insert(0, New ListItem("-", "-1"))
'Lista Chofer'
Dim dtchofer As DataTable = GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltraParametros("CvePuesto = 702 and CveEstatusPersonal = 1", "NombreCompleto")
DdlChofer.DataSource = dtchofer
DdlChofer.DataBind()
DdlChofer.Items.Insert(0, New ListItem("-", "-1"))
DdlChofer.SelectedValueExist(-1)
DdlChofer2.DataSource = dtchofer
DdlChofer2.DataBind()
DdlChofer2.Items.Insert(0, New ListItem("-", "-1"))
DdlChofer2.SelectedValueExist(-1)
DdlChoferFiltro.DataSource = dtchofer
DdlChoferFiltro.DataBind()
DdlChoferFiltro.Items.Insert(0, New ListItem("Todos", "-1"))
DdlEstatusConsulta.DataSource = GlobalDTContratosEstatus(UsuarioActual.CveEmpresa)
DdlEstatusConsulta.DataBind()
DdlEstatusConsulta.Items.Insert(0, New ListItem("Todos", "-1"))
DdlEstatusContrato.DataSource = GlobalDTContratosEstatus(UsuarioActual.CveEmpresa)
DdlEstatusContrato.DataBind()
DdlEstatusContrato.Items.Insert(0, New ListItem("Todos", "-1"))
DdlSubProyectos.DataSource = GlobalDTSubProyectos(UsuarioActual.CveEmpresa)
DdlSubProyectos.DataBind()
DdlSubProyectos.Items.Insert(0, New ListItem("Todos", "-1"))
CargarCentrosDeCosto(Nothing, Nothing, Nothing, LblSubProyectoModal)
DdlSubProyectoModal.DataSource = GlobalDTSubProyectos(UsuarioActual.CveEmpresa)
DdlSubProyectoModal.DataBind()
DdlSubProyectoModal.Items.Insert(0, New ListItem("Seleccione uno", "-1"))
'CargarCentrosDeCosto(Nothing, DdlSubProyectos, Nothing, LblSubProyecto)
UpModal.Update()
End Sub
Private Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvContratos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim BackgroundColor As String = DataBinder.Eval(e.Row.DataItem, "BackgroundColor").ToString()
e.Row.BackColor = Drawing.ColorTranslator.FromHtml(BackgroundColor)
e.Row.Cells(1).Attributes.Add("data-order", e.Row.DBCampo("FechaInicial").ToDate.Ticks.ToString)
Dim BGC_Atencion As String = "#bc9b1b"
Dim TipoEstatus As Integer = e.Row.DataKey("TipoEstatus").ToEntero
If TipoEstatus <> 4 AndAlso TipoEstatus <> 3 Then
If e.Row.DataKey("CveChofer").ToEntero <= 0 Or (e.Row.DataKey("CveChofer2").ToEntero <= 0 And e.Row.DataKey("NumChoferes").ToEntero = 2) Or e.Row.DataKey("CveAF").ToEntero <= 0 Then
e.Row.BackColor = Drawing.ColorTranslator.FromHtml(BGC_Atencion)
End If
End If
End If
End Sub
Protected Sub BtnCargaContratoCalendario_Click(sender As Object, e As EventArgs)
Dim CveContratoConsulta As Integer = HdnCveContrato.Value.ToEntero
If CveContratoConsulta > 0 Then
Dim Objcontrato As New ClsContratos
If Objcontrato.GetContratos(CveContratoConsulta, UsuarioActual.CveEmpresa) AndAlso Objcontrato.DtResultados.Rows.Count > 0 Then
Dim DRow As DataRow
DRow = Objcontrato.DtResultados.Rows(0)
'Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim NumChoferes As Integer = DRow("NumChoferes").ToString.ToEntero
TxtFolio.Text = DRow("NumeroContrato").ToString
TxtCantidadPasajeros.Text = DRow("CantidadPasajeros").ToString
DdlClientes.SelectedValue = DRow("CveCliente").ToString
DdlClientes.SelectedText = DRow("NombreComercial").ToString
TxtDescripcion.Text = DRow("DescripcionContrato").ToString
TxtObservaciones.Text = DRow("Observaciones").ToString
TxtUbicacion.Text = DRow("Ubicacion").ToString
TxtFechaSalida.Text = Convert.ToDateTime(DRow("FechaInicial")).ToString("dd/MM/yyyy HH:mm:ss")
TxtFechaRegreso.Text = Convert.ToDateTime(DRow("FechaFinal")).ToString("dd/MM/yyyy HH:mm:ss ")
TxtMoneda.Text = DRow("Moneda").ToString
TxtAnticipo.Text = DRow("ImporteMin").ToString
TxtDolares.Text = DRow("Importe").ToString
'Requeridos
DdlChofer.SelectedValueExist(-1)
DdlChofer2.SelectedValueExist(-1)
DdlChofer.SelectedValueExist(DRow("CveChofer").ToString)
DdlChofer2.SelectedValueExist(DRow("CveChofer2").ToString)
chkSegundoChofer.Checked = If(NumChoferes = 2, True, False)
DdlEstatusContrato.SelectedValueExist(DRow("CveContratosEstatus").ToString)
DdlSubProyectoModal.SelectedValueExist(DRow("CveSubProyecto").ToString)
DdlTipoAF.SelectedValueExist(DRow("CveTipoAF").ToString)
DdlTipoAF_SelectedIndexChanged(Nothing, Nothing)
If DRow("CveAF").ToString.ToEntero > 0 Then
Dim ExisteItem As Boolean = False
For Each item As ListItem In DdlAF.Items
If item.Value = DRow("CveAF").ToString Then
ExisteItem = True
Exit For
End If
Next
If Not ExisteItem Then
Dim TmpItemText As String = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CodDesc", $" EstadoActivoFijo= 'Activo' AND CveActivoFijo = {DRow("CveAF").ToString}")
DdlAF.Items.Add(New ListItem(TmpItemText, $"{DRow("CveAF").ToString}"))
End If
End If
DdlAF.SelectedValueExist(DRow("CveAF").ToString)
HidCveAF.Value = "-1"
HidCveAFDes.Value = ""
If DRow("CveAF").ToString.ToEntero > 0 Then
HidCveAF.Value = DRow("CveAF").ToString.ToString
HidCveAFDes.Value = DdlAF.SelectedItem.Text
End If
TxtMotivoCambioUnidad.Text = ""
DVMotivoCambioAF.Visible = False
HypRemision.Text = DRow("RemisionSerieFolio").ToString
HypRemision.NavigateUrl = $"/Ventas/Ventas.aspx?CveVenta={DRow("CveVentaRemision").ToString}"
If DRow("RemisionSaldo").ToString.ToDecimal > 0 Then
LblSaldo.Text = $"Saldo {DRow("RemisionSaldo").ToString.ToDecimal.ToString("###,###,###.00")}"
Else
LblSaldo.Text = ""
End If
CveContrato = CveContratoConsulta
OcultarMostrarSegundoChofer()
UpCommando.Update()
UpModal.Update()
RegistraScript("$('#ModalActualizar').modal('show');")
End If
Objcontrato.Dispose()
Else
Alert("Contrato no especificado", TipoMensaje.MsgAdvertencia)
End If
End Sub
Protected Sub UpdateContrato(sender As Object, e As EventArgs)
Dim TieneError As Boolean = False
Dim NumChoferes As Integer = If(chkSegundoChofer.Checked, 2, 1)
If NumChoferes = 2 AndAlso DdlChofer2.SelectedValue.ToEntero <= 0 Then
Alert("Debe de seleccionar un segundo chofer.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjContratos As New ClsContratos
Dim objGenerales As New ClsGenerales(ObjContratos.IniciaTransacSQL())
Dim DTAgendadados As New DataTable
If ObjContratos.GetContratosValUnidadesAgendadas(DdlAF.SelectedValue.ToEntero, TxtFechaSalida.Text.ToDate, TxtFechaRegreso.Text.ToDate, UsuarioActual.CveEmpresa, CveContrato) Then
DTAgendadados = ObjContratos.DtResultados.Copy
If DTAgendadados.Rows.Count > 0 Then
Dim sb As New StringBuilder
sb.Append($"Se detectaron Contratos con la unidad {DdlAF.SelectedItem.Text} asignada en las fechas especificadas.</br></br>")
For Each dr As DataRow In DTAgendadados.Rows
sb.AppendLine($"Contrato: <b>{dr("NumeroContrato").ToString }</b>, Salida: {dr("FechaInicial").ToString.ToDate.ToString("dd/MM/yyyy HH:mm:ss")}, Regreso: {dr("FechaFinal").ToString.ToDate.ToString("dd/MM/yyyy HH:mm:ss")} </br>")
Next
Alert(sb.ToString, TipoMensaje.MsgAdvertencia)
DTAgendadados.Dispose()
ObjContratos.Dispose()
Exit Sub
End If
End If
'If HidCveAF.Value.ToEntero <> DdlAF.SelectedValue.ToEntero Then
' If Not objGenerales.AddHistorialBitacora(465, -1, -1, -1, -1, -1, -1, -1, DdlAF.SelectedItem.Text, HidCveAFDes.Value, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0, TxtMotivoCambioUnidad.Text, "", "", CveContrato:=CveContrato) Then
' TieneError = True
' End If
'End If
If ObjContratos.UpdateContratos(CveContrato, TxtFolio.Text, TxtDescripcion.Text, "", -1, DdlClientes.SelectedValue.ToEntero, -1, TxtFechaSalida.Text.ToDate, TxtFechaRegreso.Text.ToDate, TxtUbicacion.Text, "", DdlSubProyectoModal.SelectedValue.ToEntero,
-1, -1, -1, -1, "", "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False, TxtAnticipo.Text.ToDecimal, TxtPesos.Text.ToDecimal, TxtDolares.Text.ToDecimal, -1, 0, CveContratoTipo:=34,
CveContratosEstatus:=DdlEstatusContrato.SelectedValue.ToEntero, CveChofer:=DdlChofer.SelectedValue.ToEntero, CveChofer2:=DdlChofer2.SelectedValue.ToEntero, CveTipoAF:=DdlTipoAF.SelectedValue.ToEntero,
CveAF:=DdlAF.SelectedValue.ToEntero, CantidadPasajeros:=TxtCantidadPasajeros.Text.ToEntero, Observaciones:=TxtObservaciones.Text.Trim, NumChoferes:=NumChoferes) Then
RegistraScript("$('#ModalActualizar').modal('hide');")
Alert("Actualizado Correctamente.")
Else
TieneError = True
End If
If TieneError Then
ObjContratos.RollBack()
Else
ObjContratos.Commit()
End If
ObjContratos.Dispose()
objGenerales.Dispose()
UpTitulos.Update()
CargaDatos()
InicializaCalendar()
End Sub
Protected Sub UpdateModal(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim NumChoferes As Integer = GvRow.DataKey("NumChoferes").ToEntero
TxtFolio.Text = GvRow.DataKey("NumeroContrato")
TxtCantidadPasajeros.Text = GvRow.DataKey("CantidadPasajeros")
DdlClientes.SelectedValue = GvRow.DataKey("CveCliente")
DdlClientes.SelectedText = GvRow.DataKey("NombreComercial")
TxtDescripcion.Text = GvRow.DataKey("DescripcionContrato")
TxtObservaciones.Text = GvRow.DataKey("Observaciones")
TxtUbicacion.Text = GvRow.DataKey("Ubicacion")
TxtFechaSalida.Text = Convert.ToDateTime(GvRow.DataKey("FechaInicial")).ToString("dd/MM/yyyy HH:mm:ss")
TxtFechaRegreso.Text = Convert.ToDateTime(GvRow.DataKey("FechaFinal")).ToString("dd/MM/yyyy HH:mm:ss ")
TxtMoneda.Text = GvRow.DataKey("Moneda")
TxtAnticipo.Text = GvRow.DataKey("ImporteMin")
TxtDolares.Text = GvRow.DataKey("Importe")
'Requeridos
DdlChofer.SelectedValueExist(GvRow.DataKey("CveChofer"))
DdlChofer2.SelectedValueExist(GvRow.DataKey("CveChofer2"))
chkSegundoChofer.Checked = If(NumChoferes = 2, True, False)
DdlEstatusContrato.SelectedValueExist(GvRow.DataKey("CveContratosEstatus"))
DdlSubProyectoModal.SelectedValueExist(GvRow.DataKey("CveSubProyecto"))
DdlTipoAF.SelectedValueExist(GvRow.DataKey("CveTipoAF"))
DdlTipoAF_SelectedIndexChanged(Nothing, Nothing)
If GvRow.DataKey("CveAF").ToEntero > 0 Then
Dim ExisteItem As Boolean = False
For Each item As ListItem In DdlAF.Items
If item.Value = GvRow.DataKey("CveAF") Then
ExisteItem = True
Exit For
End If
Next
If Not ExisteItem Then
Dim TmpItemText As String = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CodDesc", $" EstadoActivoFijo= 'Activo' AND CveActivoFijo = {GvRow.DataKey("CveAF")}")
DdlAF.Items.Add(New ListItem(TmpItemText, $"{GvRow.DataKey("CveAF")}"))
End If
End If
DdlAF.SelectedValueExist(GvRow.DataKey("CveAF"))
HidCveAF.Value = "-1"
HidCveAFDes.Value = ""
If GvRow.DataKey("CveAF").ToEntero > 0 Then
HidCveAF.Value = GvRow.DataKey("CveAF").ToString
HidCveAFDes.Value = DdlAF.SelectedItem.Text
End If
TxtMotivoCambioUnidad.Text = ""
DVMotivoCambioAF.Visible = False
HypRemision.Text = GvRow.DataKey("RemisionSerieFolio")
HypRemision.NavigateUrl = $"/Ventas/Ventas.aspx?CveVenta={GvRow.DataKey("CveVentaRemision")}"
If GvRow.DataKey("RemisionSaldo").ToDecimal > 0 Then
LblSaldo.Text = $"Saldo {GvRow.DataKey("RemisionSaldo").ToDecimal.ToString("###,###,###.00")}"
Else
LblSaldo.Text = ""
End If
CveContrato = GvRow.DataKey("CveContrato").ToEntero
OcultarMostrarSegundoChofer()
UpCommando.Update()
UpModal.Update()
RegistraScript("$('#ModalActualizar').modal('show');")
End Sub
Protected Sub MostrarModal(sender As Object, e As System.EventArgs)
If HidModClienteNombre.Value = "" Then
HidModClienteNombre.Value = GlobalDTCliente(UsuarioActual.CveEmpresa, -1, HidModCveCliente.Value.ToEntero).FiltroPrimeroValor("NombreComercial")
End If
TxtMotivoCambioUnidad.Text = ""
DVMotivoCambioAF.Visible = False
DdlClientes.SelectedText = HidModClienteNombre.Value
DdlClientes.SelectedValue = HidModCveCliente.Value
DdlClientes.txtText.Value = HidModClienteNombre.Value
DdlClientes.txtValue.Value = HidModCveCliente.Value
chkSegundoChofer.Checked = If(HidNumChoferes.Value.ToEntero = 2, True, False)
OcultarMostrarSegundoChofer()
HypRemision.Text = HidRemisionSerieFolio.Value
HypRemision.NavigateUrl = $"/Ventas/Ventas.aspx?CveVenta={HidCveVentaRemision.Value}"
If HidRemisionSaldo.Value.ToDecimal > 0 Then
LblSaldo.Text = $"Saldo {HidRemisionSaldo.Value.ToDecimal.ToString("###,###,###.00")}"
Else
LblSaldo.Text = ""
End If
CargaAFDdl(HidCveTipoAF.Value.ToEntero)
DdlAF.SelectedValueExist(HidCveAF.Value)
If HidCveAF.Value.ToEntero > 0 AndAlso DdlAF.SelectedValue <> HidCveAF.Value Then
DdlAF.Items.Insert(0, New ListItem(GlobalDTActivoFijos(UsuarioActual.CveEmpresa, CveActivoFijo:=HidCveAF.Value.ToEntero).FiltroPrimeroValor("CodigoDescripcion"), HidCveAF.Value))
DdlAF.SelectedValueExist(HidCveAF.Value)
End If
HidCveAFDes.Value = DdlAF.SelectedItem.Text
UpModal.Update()
myModalLabel.InnerText = "Contrato: " & HdnNumContrato.Value
RegistraScript("$('#ModalActualizar').modal('show');")
End Sub
Protected Sub chkSegundoChofer_CheckedChanged(sender As Object, e As EventArgs)
OcultarMostrarSegundoChofer()
End Sub
Private Sub OcultarMostrarSegundoChofer()
If chkSegundoChofer.Checked Then
DdlChofer2.Visible = True
'DVChofer2.Attributes.Add("style", "display:block")
Else
DdlChofer2.Visible = False
'DVChofer2.Attributes.Add("style", "display:none")
End If
UpCommando.Update()
UpModal.Update()
End Sub
Protected Sub DdlTipoAF_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaAFDdl(DdlTipoAF.SelectedValue.ToEntero)
End Sub
'Protected Sub BtnDdlTipoAF_Click(sender As Object, e As EventArgs)
' CargaAFDdl(HidCveTipoAF.Value.ToEntero)
'End Sub
Private Sub CargaAFDdl(CveTipoAF As Integer)
'Lista de Activos fijos
DdlAF.ClearSelection()
DdlAF.SelectedValue = Nothing
DdlAF.Items.Clear()
Dim ObjContratos As New ClsContratos
If ObjContratos.GetContratosValUnidadesAgendadas(DdlAF.SelectedValue.ToEntero, TxtFechaSalida.Text.ToDate, TxtFechaRegreso.Text.ToDate, UsuarioActual.CveEmpresa, CveContrato, 2) Then
If CveTipoAF > 0 Then
DdlAF.DataSource = ObjContratos.DtResultados.FiltraParametros($" CveTipoActivoFijo = {CveTipoAF} ")
Else
DdlAF.DataSource = ObjContratos.DtResultados
End If
End If
ObjContratos.Dispose()
'If CveTipoAF > 0 Then
' DdlAF.DataSource = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltraParametros($" EstadoActivoFijo= 'Activo' AND CveTipoActivoFijo = {CveTipoAF} ")
'Else
' DdlAF.DataSource = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltraParametros($" EstadoActivoFijo= 'Activo' ")
'End If
DdlAF.DataBind()
DdlAF.Items.Insert(0, New ListItem("-", "0")) 'DEBE DE SER CERO, SI SE QUIERE QUITAR LA UNIDAD
UpModal.Update()
End Sub
Protected Sub LnkExcel_Click(sender As Object, e As EventArgs) Handles LnkExcel.Click
Dim SubProyecto As String = DdlSubProyectos.SelectedItem.Text
Dim SbFiltros As New StringBuilder()
SbFiltros.AppendFormat($"Fecha Inicio: {txtFechaI.Text} Fecha Fin: {txtFechaF.Text}|")
SbFiltros.AppendFormat("SubProyecto: {0}|", SubProyecto)
GvContratos.ExportToExcelGembox($"Reporte_Contratos_{NowADS.ToString("yyyyMMddHHmmss")}", UsuarioActual, "Reporte Contratos", DatoTituloExtra:=$"", DatosFiltros:=SbFiltros.ToString())
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Esto es necesario para permitir la renderización del control fuera de un formulario servidor
' No se requiere implementación específica, solo la anulación.
End Sub
Protected Sub LnkPDF_Click(sender As Object, e As EventArgs) Handles LnkPdf.Click
ImprimirReporte()
End Sub
Private Sub ImprimirReporte(Optional Formato As String = "PDF")
Dim ObjContratos As New ClsContratos
Dim DTDatos As New DataTable
If ObjContratos.GetContratos(-1, UsuarioActual.CveEmpresa, TipoContrato:=2) Then
DTDatos = ObjContratos.DtResultados
Else
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia)
End If
ObjContratos.Dispose()
If DTDatos IsNot Nothing Then
Dim Imagen As New IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
Dim logouri As String = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa)
Dim Cliente As String = If(DdlClientes.SelectedValue = "-1", "", $"&emsp;<b>Cliente:</b>&nbsp;{DdlClientes.SelectedText}")
Dim params As New List(Of ReportParameter) From {
New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa),
New ReportParameter("FechaInicio", "-1"),
New ReportParameter("FechaFin", "-1"),
New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa),
New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre),
New ReportParameter("FechaImpresion", NowADS().ToDateTime.ToShortDateString),
New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", ""))
}
ImprimirPDF("Empresas/Grales/Formatos/RepContratos.rdlc", DTDatos, params, NombreArchivo:="Reporte Contratos", Formato:=Formato)
End If
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
CargaDatos()
End Sub
Protected Sub RBTipoVista_SelectedIndexChanged(sender As Object, e As EventArgs)
InicializaCalendar()
'CargaCronograma()
'CargaDiagramadeGant()
CargaScheduler(DdlTipoVista.SelectedValue.ToEntero)
End Sub
Protected Sub DdlTipoVista_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaDiagramadeGant(DdlTipoVista.SelectedValue.ToEntero)
End Sub
Protected Sub DdlAF_SelectedIndexChanged(sender As Object, e As EventArgs)
DVMotivoCambioAF.Visible = False
If HidCveAF.Value.ToEntero > 0 AndAlso DdlAF.SelectedValue.ToEntero <> HidCveAF.Value.ToEntero Then
DVMotivoCambioAF.Visible = True
End If
UpModal.Update()
End Sub
Protected Sub DdlTipoVistaCalendario_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaCronograma(DdlTipoVistaCalendario.SelectedValue.ToEntero)
End Sub
End Class