Option Strict On Imports System.Data Imports Extensiones Imports System.IO Imports System.Globalization Partial Class GPS_CatReportesProgramados Inherits ClsPaginas #Region "Propiedades" Public Property EsEditar As Integer Get Return ViewState("EsEditar").ToString.ToEntero End Get Set(value As Integer) ViewState("EsEditar") = value End Set End Property Public Property CveReporteProgramado As Integer Get Return ViewState("CveReporteProgramado").ToString.ToEntero End Get Set(value As Integer) ViewState("CveReporteProgramado") = value End Set End Property Public Property Dias As String Get Return ViewState("Dias").ToString End Get Set(value As String) ViewState("Dias") = value End Set End Property Public Property Dispositivos As String Get Return ViewState("Dispositivos").ToString End Get Set(value As String) ViewState("Dispositivos") = value End Set End Property Public Property Extras As String Get Return ViewState("Extras").ToString End Get Set(value As String) ViewState("Extras") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then EsEditar = 0 Dias = "" Dispositivos = "" Extras = "" CargaDdls() CargaDias() CargaDatos() CargaDispositivos() End If End Sub Private Sub CargaDdls() Dim ObjGPS As New ClsGPS If ObjGPS.GetReportes() Then DdlReporte.DataSource = ObjGPS.DtResultados End If ObjGPS.Dispose() DdlReporte.DataBind() UpAgregar.Update() End Sub Private Sub CargaDias() Select Case Now.DayOfWeek.ToString Case "Monday" ChkDiasSemana.Items(0).Selected = True Case "Tuesday" ChkDiasSemana.Items(1).Selected = True Case "Wednesday" ChkDiasSemana.Items(2).Selected = True Case "Thursday" ChkDiasSemana.Items(3).Selected = True Case "Friday" ChkDiasSemana.Items(4).Selected = True Case "Saturday" ChkDiasSemana.Items(5).Selected = True Case "Sunday" ChkDiasSemana.Items(6).Selected = True End Select End Sub Private Sub CargaDispositivos() Dim Gps As New ClsGPS If Gps.DispositivosGet(-1, 1, UsuarioActual.CveCliente) Then GvDispositivos.DataSource = Gps.DtResultados GvDispositivos.DataBind() End If Gps.Dispose() End Sub Private Sub CargaExtras(Extra As Integer) Dim Gps As New ClsGPS If Gps.ReportesProgramadosExtrasGet(UsuarioActual.CveCliente, Extra) Then GvExtras.DataSource = Gps.DtResultados GvExtras.DataBind() End If Gps.Dispose() UpExtras.Update() End Sub Private Sub CargaDispositivosReporte(CveReporteProgramado As Integer) Dim Gps As New ClsGPS If Gps.ReportesProgramadosDispositivosGet(CveReporteProgramado) Then For Each row As DataRow In Gps.DtResultados.Rows For Each row2 As GridViewRow In GvDispositivos.Rows If row2.DataKey("CveDispositivo").ToEntero = row("CveDispositivo").ToString.ToEntero Then row2.FCCheckBox("Chk").Checked = True Exit For End If Next Next End If Gps.Dispose() End Sub Private Sub CargaExtrasReporte(CveReporteProgramado As Integer, Extra As Integer) Select Case Extra Case 4 'Evento CargaEventosReporte(CveReporteProgramado) Case 6 'Geocerca CargaGeocercasReporte(CveReporteProgramado) Case 7 'PI CargaPIReporte(CveReporteProgramado) End Select End Sub Private Sub CargaGeocercasReporte(CveReporteProgramado As Integer) Dim Gps As New ClsGPS If Gps.ReportesProgramadosGeocercasGet(CveReporteProgramado) Then For Each row As DataRow In Gps.DtResultados.Rows For Each row2 As GridViewRow In GvExtras.Rows If row2.DataKey("Cve").ToEntero = row("Cve").ToString.ToEntero Then row2.FCCheckBox("Chk").Checked = True Exit For End If Next Next End If Gps.Dispose() End Sub Private Sub CargaPIReporte(CveReporteProgramado As Integer) Dim Gps As New ClsGPS If Gps.ReportesProgramadosPIGet(CveReporteProgramado) Then For Each row As DataRow In Gps.DtResultados.Rows For Each row2 As GridViewRow In GvExtras.Rows If row2.DataKey("Cve").ToEntero = row("Cve").ToString.ToEntero Then row2.FCCheckBox("Chk").Checked = True Exit For End If Next Next End If Gps.Dispose() End Sub Private Sub CargaEventosReporte(CveReporteProgramado As Integer) Dim Gps As New ClsGPS If Gps.ReportesProgramadosEventosGet(CveReporteProgramado) Then For Each row As DataRow In Gps.DtResultados.Rows For Each row2 As GridViewRow In GvExtras.Rows If row2.DataKey("Cve").ToEntero = row("Cve").ToString.ToEntero Then row2.FCCheckBox("Chk").Checked = True Exit For End If Next Next End If Gps.Dispose() End Sub Private Sub CargaDatos() Dim ObjGPS As New ClsGPS If ObjGPS.ReportesProgramadosGet(UsuarioActual.CveUsuario) Then GvDatos.DataSource = ObjGPS.DtResultados GvDatos.DataBind() End If UpDatos.Update() ObjGPS.Dispose() End Sub Protected Sub ImgE_Click(sender As Object, e As EventArgs) Dim Boton = CType(sender, LinkButton) Dim GvRow As GridViewRow = DirectCast(Boton.NamingContainer, GridViewRow) CveReporteProgramado = Boton.CommandArgument.ToEntero DdlReporte.SelectedValue = GvRow.DataKey("CveReporte").ToString DdlReporte_SelectedIndexChanged(Nothing, Nothing) DdlFrecuencia.SelectedValue = GvRow.DataKey("TinyFrecuencia").ToString DdlFrecuencia_SelectedIndexChanged(Nothing, Nothing) TxtIntervalo.Text = GvRow.DataKey("Intervalo").ToString 'TxtHoraInicio.SetTime(GvRow.DataKey("HorarioInicial").ToDateTime.Hour, GvRow.DataKey("HorarioInicial").ToDateTime.Minute, GvRow.DataKey("HorarioInicial").ToDateTime.Second, If(GvRow.DataKey("HorarioInicial").ToDateTime.ToString("tt", CultureInfo.InvariantCulture) = "PM", MKB.TimePicker.TimeSelector.AmPmSpec.PM, MKB.TimePicker.TimeSelector.AmPmSpec.AM)) 'TxtHoraFin.SetTime(GvRow.DataKey("HorarioFinal").ToDateTime.Hour, GvRow.DataKey("HorarioFinal").ToDateTime.Minute, GvRow.DataKey("HorarioFinal").ToDateTime.Second, If(GvRow.DataKey("HorarioFinal").ToDateTime.ToString("tt", CultureInfo.InvariantCulture) = "PM", MKB.TimePicker.TimeSelector.AmPmSpec.PM, MKB.TimePicker.TimeSelector.AmPmSpec.AM)) TxtHorarioEnvio.SetTime(GvRow.DataKey("HoraEnvio").ToDateTime.Hour, GvRow.DataKey("HoraEnvio").ToDateTime.Minute, GvRow.DataKey("HoraEnvio").ToDateTime.Second, If(GvRow.DataKey("HoraEnvio").ToDateTime.ToString("tt", CultureInfo.InvariantCulture) = "PM", MKB.TimePicker.TimeSelector.AmPmSpec.PM, MKB.TimePicker.TimeSelector.AmPmSpec.AM)) txtFechaI.Text = GvRow.DataKey("FechaI").ToString txtFechaF.Text = GvRow.DataKey("FechaF").ToString TxtCorreo.Text = GvRow.DataKey("Correos").ToString DdlFormato.SelectedValue = GvRow.DataKey("Formato").ToString EsEditar = 1 'Cargamos los Dias If GvRow.DataKey("NombreDia").ToString.Contains("Lunes") Then ChkDiasSemana.Items(0).Selected = True Else ChkDiasSemana.Items(0).Selected = False If GvRow.DataKey("NombreDia").ToString.Contains("Martes") Then ChkDiasSemana.Items(1).Selected = True Else ChkDiasSemana.Items(1).Selected = False If GvRow.DataKey("NombreDia").ToString.Contains("Miercoles") Then ChkDiasSemana.Items(2).Selected = True Else ChkDiasSemana.Items(2).Selected = False If GvRow.DataKey("NombreDia").ToString.Contains("Jueves") Then ChkDiasSemana.Items(3).Selected = True Else ChkDiasSemana.Items(3).Selected = False If GvRow.DataKey("NombreDia").ToString.Contains("Viernes") Then ChkDiasSemana.Items(4).Selected = True Else ChkDiasSemana.Items(4).Selected = False If GvRow.DataKey("NombreDia").ToString.Contains("Sabado") Then ChkDiasSemana.Items(5).Selected = True Else ChkDiasSemana.Items(5).Selected = False If GvRow.DataKey("NombreDia").ToString.Contains("Domingo") Then ChkDiasSemana.Items(6).Selected = True Else ChkDiasSemana.Items(6).Selected = False CargaDispositivosReporte(CveReporteProgramado) CargaExtrasReporte(CveReporteProgramado, DdlReporte.SelectedValue.ToEntero) UpBodyEstatus.Update() UpFooter.Update() RegistraScript("$('#C_GvDispositivos_checkAll').click(function () { $(""input[name^='ctl00$C$GvDispositivos']"").not(this).prop('checked', this.checked); });", "4") RegistraScript("$('#divAgregar').modal()", "5") End Sub Protected Sub BtnAgregarCatalogo_Click(sender As Object, e As EventArgs) Handles BtnAgregarCatalogo.Click Dim GPS As New ClsGPS AgregarDias() AgregarDispositivos() AgregarExtras() If Dispositivos = "" AndAlso DdlReporte.SelectedValue <> "9" Then Dias = "" Dispositivos = "" Extras = "" Alert("Debe Seleccionar al menos un Dispostivo", TipoMensaje.MsgAdvertencia) Exit Sub End If If DdlReporte.SelectedValue.ToEntero.Contiene(4) AndAlso Extras = "" Then '6, 7, 9 Dias = "" Dispositivos = "" Extras = "" If DdlReporte.SelectedValue.ToEntero = 4 Then Alert("Debe Seleccionar al menos un Evento", TipoMensaje.MsgAdvertencia) Exit Sub 'ElseIf DdlReporte.SelectedValue.ToEntero = 6 Then ' Alert("Debe Seleccionar al menos una Geocerca", TipoMensaje.MsgAdvertencia) ' Exit Sub 'ElseIf DdlReporte.SelectedValue.ToEntero = 7 Then ' Alert("Debe Seleccionar al menos un Punto de Interés", TipoMensaje.MsgAdvertencia) ' Exit Sub 'ElseIf DdlReporte.SelectedValue.ToEntero = 9 Then ' Alert("Debe Seleccionar al menos un Grupo", TipoMensaje.MsgAdvertencia) ' Exit Sub End If End If Dim Formato As String = DdlFormato.SelectedValue If EsEditar = 0 Then If GPS.ReportesProgramadosAdd(DdlReporte.SelectedValue.ToEntero, TxtCorreo.Text, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, $"{TxtHorarioEnvio.Hour}:{TxtHorarioEnvio.Minute}:{TxtHorarioEnvio.Second} {TxtHorarioEnvio.AmPm}".ToDateTime, DdlFrecuencia.SelectedValue, If(DivIntervalo.Visible, TxtIntervalo.Text.ToEntero, -1), Dias, Dispositivos, Extras, $"{TxtHoraInicio.Hour}: {TxtHoraInicio.Minute}:{TxtHoraInicio.Second} {TxtHoraInicio.AmPm}".ToDateTime, $"{TxtHoraFin.Hour}:{TxtHoraFin.Minute}:{TxtHoraFin.Second} {TxtHoraFin.AmPm}".ToDateTime, Formato, UsuarioActual.CveUsuario, UsuarioActual.CveCliente) Then Alert("La programacion se agregó correctamente.") LimpiarAgregado() RegistraScript("$('#divAgregar').modal('hide')", "11") End If Else 'If GPS.ReportesProgramadosUpdate(CveReporteProgramado, DdlReporte.SelectedValue.ToEntero, TxtCorreo.Text, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, $"{TxtHorarioEnvio.Hour}:{TxtHorarioEnvio.Minute}:{TxtHorarioEnvio.Second} {TxtHorarioEnvio.AmPm}".ToDateTime, DdlFrecuencia.SelectedValue, $"00:00:00 AM".ToDateTime, 0.0, $"00:00:00 AM".ToDateTime, 0, $"{TxtHoraInicio.Hour}:{TxtHoraInicio.Minute}:{TxtHoraInicio.Second} {TxtHoraInicio.AmPm}".ToDateTime, $"{TxtHoraFin.Hour}:{TxtHoraFin.Minute}:{TxtHoraFin.Second} {TxtHoraFin.AmPm}".ToDateTime) Then If GPS.ReportesProgramadosUpdate(CveReporteProgramado, DdlReporte.SelectedValue.ToEntero, TxtCorreo.Text, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, $"{TxtHorarioEnvio.Hour}:{TxtHorarioEnvio.Minute}:{TxtHorarioEnvio.Second} {TxtHorarioEnvio.AmPm}".ToDateTime, DdlFrecuencia.SelectedValue, If(DivIntervalo.Visible, TxtIntervalo.Text.ToEntero, -1), Dias, Dispositivos, Extras, $"{TxtHoraInicio.Hour}: {TxtHoraInicio.Minute}:{TxtHoraInicio.Second} {TxtHoraInicio.AmPm}".ToDateTime, $"{TxtHoraFin.Hour}:{TxtHoraFin.Minute}:{TxtHoraFin.Second} {TxtHoraFin.AmPm}".ToDateTime, Formato, UsuarioActual.CveCliente) Then Alert("La programacion se actualizó correctamente.") LimpiarAgregado() RegistraScript("$('#divAgregar').modal('hide')", "11") End If End If Dias = "" Dispositivos = "" Extras = "" GPS.Dispose() CargaDatos() UpBodyEstatus.Update() End Sub Private Sub LimpiarAgregado() DdlReporte.SelectedIndex = 0 DdlReporte_SelectedIndexChanged(Nothing, Nothing) DdlFrecuencia.SelectedIndex = 0 DdlFrecuencia_SelectedIndexChanged(Nothing, Nothing) TxtIntervalo.Text = "" TxtHoraInicio.SetTime(0, 0, 0, MKB.TimePicker.TimeSelector.AmPmSpec.AM) TxtHoraFin.SetTime(0, 0, 0, MKB.TimePicker.TimeSelector.AmPmSpec.AM) TxtHorarioEnvio.SetTime(0, 0, 0, MKB.TimePicker.TimeSelector.AmPmSpec.AM) txtFechaI.Text = "" txtFechaF.Text = "" TxtCorreo.Text = "" Dispositivos = "" Extras = "" EsEditar = 0 LimpiarDias() CargaDispositivos() UpAgregar.Update() End Sub Private Sub LimpiarDias() For Each Item As ListItem In ChkDiasSemana.Items Item.Selected = False Next CargaDias() End Sub Private Sub AgregarDias() For Each Item As ListItem In ChkDiasSemana.Items If Item.Selected Then Dias = Dias + Item.Text + "," End If Next End Sub Private Sub AgregarDispositivos() 'EN EL CASO DE SALIDA DE PARADAS LOS DISPOSITIVOS VIENEN EN EL GRUPO If DdlReporte.SelectedValue <> "9" Then For Each row As GridViewRow In GvDispositivos.Rows If row.FCCheckBox("Chk").Checked Then Dispositivos = Dispositivos + row.DataKey("CveDispositivo") + "," End If Next Else 'Dim ObjGPS As New ClsGPS 'For Each row As GridViewRow In GvExtras.Rows ' If row.FCCheckBox("Chk").Checked Then ' Dim CveGrupo As Integer = row.DataKey("Cve").ToEntero ' If ObjGPS.GruposDetallesGet(CveGrupo) Then ' For Each Grupos ' Dispositivos = Dispositivos + row.DataKey("Cve") + "," ' End If ' End If 'Next 'ObjGPS.Dispose() End If End Sub Private Sub AgregarExtras() For Each row As GridViewRow In GvExtras.Rows If row.FCCheckBox("Chk").Checked Then Extras = Extras + row.DataKey("Cve") + "," End If Next End Sub Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting Dim GPS As New ClsGPS Dim CveReporteProgramado As Integer = GvDatos.Rows(e.RowIndex).DataKey("CveReporteProgramado").ToEntero If GPS.ReportesProgramadosDelete(CveReporteProgramado) Then Alert("La programacion se eliminó correctamente.") End If GPS.Dispose() CargaDatos() UpDatos.Update() End Sub Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then e.Row.VerticalAlign = VerticalAlign.Middle e.Row.FCLinkButton("ImgE").CommandArgument = e.Row.DataKey("CveReporteProgramado").ToString e.Row.ToolTip = e.Row.DataKey("NombreDia").ToString End If End Sub Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click LimpiarAgregado() RegistraScript("$('#divAgregar').modal('hide')", "11") UpBodyEstatus.Update() UpFooter.Update() End Sub Private Sub DdlFrecuencia_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlFrecuencia.SelectedIndexChanged If DdlFrecuencia.SelectedValue = "S" Then DivDia.Visible = True Else DivDia.Visible = False End If If DdlFrecuencia.SelectedValue.Contiene("M", "S") Then DivIntervalo.Visible = True Else DivIntervalo.Visible = False End If UpAgregar.Update() RegistraScript("$('#C_GvDispositivos_checkAll').click(function () { $(""input[name^='ctl00$C$GvDispositivos']"").not(this).prop('checked', this.checked); });", "1") If DdlReporte.SelectedValue.ToEntero.Contiene(4, 6, 7) Then RegistraScript("$('#C_GvExtras_checkAll').click(function () { $(""input[name^='ctl00$C$GvExtras']"").not(this).prop('checked', this.checked); });", "2") End If End Sub Private Sub linkAgregar_Click(sender As Object, e As EventArgs) Handles linkAgregar.Click LimpiarAgregado() RegistraScript("$('#C_GvDispositivos_checkAll').click(function () { $(""input[name^='ctl00$C$GvDispositivos']"").not(this).prop('checked', this.checked); });", "1") RegistraScript("$('#divAgregar').modal()", "2") End Sub Private Sub DdlReporte_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlReporte.SelectedIndexChanged DivDispositivos.Visible = True DivDispositivos.Attributes.Remove("class") DivCuerpo.Attributes.Remove("class") UpAgregar.Attributes.Remove("style") If DdlReporte.SelectedValue.ToEntero = 4 Then CargaExtras(3) 'ElseIf DdlReporte.SelectedValue.ToEntero = 6 Then ' CargaExtras(1) 'ElseIf DdlReporte.SelectedValue.ToEntero = 7 Then ' CargaExtras(2) 'ElseIf DdlReporte.SelectedValue.ToEntero = 9 Then ' DivDispositivos.Visible = False ' CargaExtras(4) End If If DdlReporte.SelectedValue.ToEntero.Contiene(4) Then '6,7,9 DivExtras.Visible = True If DdlReporte.SelectedValue.ToEntero <> 9 Then DivDispositivos.Attributes.Add("class", "col-md-4") DivCuerpo.Attributes.Add("class", "col-md-4") DivExtras.Attributes.Add("class", "col-md-4") Else DivExtras.Attributes.Add("class", "col-md-6") DivCuerpo.Attributes.Add("class", "col-md-6") End If RegistraScript("$('#C_UpAgregar').width( 900 )", "1") RegistraScript("$('#C_GvExtras_checkAll').click(function () { $(""input[name^='ctl00$C$GvExtras']"").not(this).prop('checked', this.checked); });", "2") Else DivExtras.Visible = False DivDispositivos.Attributes.Add("class", "col-md-6") DivCuerpo.Attributes.Add("class", "col-md-6") RegistraScript("$('#C_UpAgregar').width( 605 )") End If RegistraScript("$('#C_GvDispositivos_checkAll').click(function () { $(""input[name^='ctl00$C$GvDispositivos']"").not(this).prop('checked', this.checked); });", "3") UpAgregar.Update() End Sub End Class