Files
SIG/GPS/CatEventos.aspx.vb

301 lines
12 KiB
VB.net

Option Strict On
Imports Extensiones
Imports System.Data
Imports System.IO
Partial Class GPS_CatEventos
Inherits ClsPaginas
#Region "Propiedades"
Public Property CveEvento As Integer
Get
Return ViewState("CveEvento").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveEvento") = value
End Set
End Property
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 Sonido As String
Get
Return ViewState("Sonido").ToString
End Get
Set(value As String)
ViewState("Sonido") = value
End Set
End Property
Public Property Imagen As String
Get
Return ViewState("Imagen").ToString
End Get
Set(value As String)
ViewState("Imagen") = 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
Imagen = ""
Sonido = ""
CveEvento = -1
EsEditar = 0
'dvEstatusEv.Visible = False
CargaDatos()
End If
End Sub
Private Sub CargaDatos()
Dim GPS As New ClsGPS
If GPS.EventoGet(-1, -1, -1) Then
GvDatos.DataSource = GPS.DtResultados
Else
GvDatos.DataSource = Nothing
End If
GPS.Dispose()
GvDatos.DataBind()
CargaDdl()
End Sub
Private Sub CargaDdl()
'Dim GPS As New ClsGPS
'If GPS.ControladorGraficoGet(-1) Then
' DdlControladorGrafico.DataSource = GPS.DtResultados.FiltraParametros("Estatus = 1")
'Else
' DdlControladorGrafico.DataSource = Nothing
'End If
'GPS.Dispose()
'DdlControladorGrafico.DataBind()
End Sub
Protected Sub imgE_Click(sender As Object, e As EventArgs)
Dim Boton = CType(sender, LinkButton)
CveEvento = Boton.CommandArgument.ToEntero
myModalLabel3.InnerHtml = "Actualizar Evento"
Dim GvRow As GridViewRow = DirectCast(Boton.NamingContainer, GridViewRow)
TxtEvento.Text = GvRow.DataKey("Evento").ToString
TxtCSS.Text = GvRow.DataKey("CSS").ToString
Imagen = GvRow.DataKey("Imagen").ToString
Sonido = GvRow.DataKey("Sonido").ToString
If Not Sonido.Equals("") Then
PlaySonidoTmp.Visible = True
PlaySonidoTmp.OnClientClick = $"javascript:PlaySonidito('{Sonido}');return false;"
End If
EsEditar = 1
BtnAddEvento.Text = "Actualizar"
'dvEstatusEv.Visible = True
'chkEstatus.Checked = CBool(GvRow.DataKey("Estatus"))
UpBodyEvento.Update()
UpdatePanel2.Update()
UpFooterEvento.Update()
RegistraScript("$('#divEventos').modal()")
End Sub
Protected Sub BtnAgregarCatalogo_Click(sender As Object, e As EventArgs) Handles BtnAddEvento.Click
Dim GPS As New ClsGPS
Dim huboerror = False
If EsEditar = 0 Then
Try
If TxtUpImagen.getfiles().Archivos.Count > 0 Then
Dim ArchivoImagen As Archivo = TxtUpImagen.getfiles().Archivos(0)
Dim Path As String = $"{ModExtensiones.DirectorioBaseEmpresas}Imagenes"
If Not Directory.Exists(Path) Then
Directory.CreateDirectory(Path)
End If
Dim directorioNew As String = String.Format("{0}\{1}.{2}", Path, Imagen, ArchivoImagen.Extencion)
If File.Exists(directorioNew) Then
My.Computer.FileSystem.DeleteFile(directorioNew)
End If
My.Computer.FileSystem.MoveFile(ArchivoImagen.FileUrl, directorioNew)
End If
If TxtUpSonido.getfiles().Archivos.Count > 0 Then
Dim ArchivoSonido As Archivo = TxtUpSonido.getfiles().Archivos(0)
Dim PathSonido As String = $"{ModExtensiones.DirectorioBaseEmpresas}Sonidos"
Dim dirSonido As String = String.Format("{0}\{1}.{2}", PathSonido, Sonido, ArchivoSonido.Extencion)
If File.Exists(dirSonido) Then
My.Computer.FileSystem.DeleteFile(dirSonido)
End If
My.Computer.FileSystem.MoveFile(ArchivoSonido.FileUrl, dirSonido)
End If
Catch ex As Exception
huboerror = True
OnError("Ocurrió un error al agregar los archivos", ex)
End Try
If Not huboerror Then
Dim CveControladorGrafico As Integer = -1 'DdlControladorGrafico.SelectedValue.ToEntero
If GPS.EventoAdd(TxtEvento.Text, 1, True, TxtCSS.Text.Trim, Imagen, Sonido, UsuarioActual.CveUsuario, CveControladorGrafico, 1) Then
Alert("El Evento se agregó correctamente", TipoMensaje.MsgInformacion)
Else
Alert("Ocurrió un error al agregar el Evento", TipoMensaje.MsgError)
End If
End If
ElseIf EsEditar = 1 Then
Try
If TxtUpImagen.getfiles().Archivos.Count > 0 Then
Dim ArchivoImagen As Archivo = TxtUpImagen.getfiles().Archivos(0)
Dim Path As String = $"{ModExtensiones.DirectorioBaseEmpresas}Imagenes"
If Not Directory.Exists(Path) Then
Directory.CreateDirectory(Path)
End If
Dim directorioNew As String = String.Format("{0}\{1}", Path, Imagen)
If File.Exists(directorioNew) Then
My.Computer.FileSystem.DeleteFile(directorioNew)
End If
My.Computer.FileSystem.MoveFile(ArchivoImagen.FileUrl, directorioNew)
End If
If TxtUpSonido.getfiles().Archivos.Count > 0 Then
Dim ArchivoSonido As Archivo = TxtUpSonido.getfiles().Archivos(0)
Dim PathSonido As String = $"{ModExtensiones.DirectorioBaseEmpresas}Sonidos"
Dim dirSonido As String = String.Format("{0}\{1}", PathSonido)
If File.Exists(dirSonido) Then
My.Computer.FileSystem.DeleteFile(dirSonido)
End If
My.Computer.FileSystem.MoveFile(ArchivoSonido.FileUrl, dirSonido)
End If
Catch ex As Exception
huboerror = True
OnError("Ocurrió un error al agregar los archivos", ex)
End Try
If Not huboerror Then
Dim Estatus As Boolean = True 'chkEstatus.Checked
Dim CveControladorGrafico = -1 'DdlControladorGrafico.SelectedValue.ToEntero
If GPS.EventoUpdate(CveEvento, TxtEvento.Text, 1, Estatus, TxtCSS.Text.Trim, Imagen, Sonido,CveControladorGrafico , 1) Then
Alert("El Evento se editó correctamente", TipoMensaje.MsgInformacion)
Else
Alert("Ocurrió un error al editar al Evento", TipoMensaje.MsgError)
End If
EsEditar = 0
'dvEstatusEv.Visible = False
BtnAddEvento.Text = "Agregar"
End If
End If
RegistraScript("$('#divEventos').modal('hide')")
GPS.Dispose()
TxtEvento.Text = ""
TxtCSS.Text = ""
Imagen = ""
Sonido = ""
TxtUpImagen.Text = "[]"
TxtUpSonido.Text = "[]"
PlaySonidoTmp.Visible = False
CargaDatos()
UpDatos.Update()
UpBodyEvento.Update()
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 CveEvento As Integer = GvDatos.Rows(e.RowIndex).DataKey("CveEvento").ToEntero
If GPS.EventoDelete(CveEvento) Then
Alert("El conductor se eliminó correctamente", TipoMensaje.MsgInformacion)
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("CveEvento").ToString
If File.Exists($"{ModExtensiones.DirectorioBaseEmpresas}Sonidos/{e.Row.DataKey("Sonido").ToString}") Then
e.Row.FCLinkButton("PlaySonido").OnClientClick = $"javascript:PlaySonidito('{e.Row.DataKey("Sonido").ToString}');return false;"
Else
e.Row.FCLinkButton("PlaySonido").Visible = False
End If
End If
End Sub
#Region "UPLOADS"
Protected Sub btnAddImagen_Click(sender As Object, e As EventArgs) Handles btnAddImagen.Click
Dim Filesgral As List(Of Archivo) = TxtUpImagen.getfiles().Archivos
For Each fileItem As Archivo In Filesgral
Dim ImagenT = FormatearNombreArchivo(fileItem.filenameO)
If Imagen.Length > 199 Then
Alert("El nombre del archivo excede los 200 Caracteres permitidos favor de modificarlo.", TipoMensaje.MsgAdvertencia)
Exit Sub
Else
Imagen = ImagenT
End If
Next
RegistraScript("$('#DivImagen').modal('hide');")
UpBodyEvento.Update()
End Sub
Protected Sub btnAddSonido_Click(sender As Object, e As EventArgs) Handles btnAddSonido.Click
Dim Filesgral As List(Of Archivo) = TxtUpSonido.getfiles().Archivos
For Each fileItem As Archivo In Filesgral
Dim SonidoT = FormatearNombreArchivo(fileItem.filenameO)
If Sonido.Length > 199 Then
Alert("El nombre del archivo excede los 200 Caracteres permitidos favor de modificarlo.", TipoMensaje.MsgAdvertencia)
Exit Sub
Else
Sonido = SonidoT
PlaySonidoTmp.Visible = True
PlaySonidoTmp.OnClientClick = $"javascript:PlaySoniditoTmp('{fileItem.filename}');return false;"
End If
Next
RegistraScript("$('#DivSonido').modal('hide');")
UpBodyEvento.Update()
End Sub
Public Function FormatearNombreArchivo(nombreArchivoOriginal As String) As String
Dim nombreArchivoFormateado As String
nombreArchivoFormateado = nombreArchivoOriginal.Replace(" ", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("'", "")
nombreArchivoFormateado = nombreArchivoFormateado.Replace(Chr(34), "")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("$", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("#", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("%", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("!", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("&", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("?", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("¿", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("¡", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("*", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("~", "_")
nombreArchivoFormateado = nombreArchivoFormateado.Replace("^", "_")
Return nombreArchivoFormateado
End Function
#End Region
Protected Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles BtnOpenDiv.Click
EsEditar = 0
RegistraScript("$('#divEventos').modal()")
BtnAddEvento.Text = "Agregar"
myModalLabel3.InnerHtml = "Agregar Evento"
TxtEvento.Text = ""
TxtCSS.Text = ""
Imagen = ""
Sonido = ""
TxtUpImagen.Text = "[]"
TxtUpSonido.Text = "[]"
PlaySonidoTmp.Visible = False
'dvEstatusEv.Visible = False
UpBodyEvento.Update()
UpdatePanel2.Update()
UpFooterEvento.Update()
End Sub
End Class