Files
SIG/Prospectos/CatEventosEstructuras.aspx.vb
2023-02-11 08:33:59 -07:00

218 lines
10 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports System.Linq
Imports Extensiones
Partial Class Prospectos_CatEventosEstructuras
Inherits ClsPaginas
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
ViewState("Orden") = ""
CargaEventoTipo()
CargaDatos()
CargaAnfitrion(DdlAnfitrion)
DdlMunicipio.DataSource = GlobalDTGralMunicipios("26")
DdlMunicipio.DataBind()
End If
End Sub
Private Sub CargaEventoTipo()
DdlEventoTIpo.DataSource = GlobalDTProspectosEventosTipo(UsuarioActual.CveEmpresa)
DdlEventoTipo.DataBind()
End Sub
Private Sub CargaAnfitrion(ddl As DropDownList)
Dim Anf As New ClsProspectos
If Anf.GetProspectosAnfitriones(-1, UsuarioActual.CveEmpresa) Then
ddl.DataSource = Anf.DtResultados
End If
Anf.Dispose()
ddl.DataBind()
End Sub
Public Sub CargaDatos()
Dim ObjEvento As New ClsProspectos
If ObjEvento.GetProspectosEventos(-1, UsuarioActual.CveEmpresa) Then
ViewState("DTEvento") = ObjEvento.DtResultados '.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTProspectosEvento(-1, UsuarioActual.CveEmpresa) = ObjEvento.DtResultados
Else
Me.GvDatos.DataSource = Nothing
End If
'ObjEvento.Dispose()
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End Sub
Protected Sub LbAgregar_Click(sender As Object, e As System.EventArgs) Handles LbAgregar.Click
Dim ObjAnfitrion As New ClsProspectos
If ObjAnfitrion.AddProspectosEventos(TxtEvento.Text.Trim, DdlEventoTIpo.SelectedValue.ToEntero, TxtFechaEvento.Text.ToDateTime, -1, DdlAnfitrion.SelectedValue.ToEntero, "", DdlMunicipio.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
DdlEventoTIpo.SelectedIndex = 0
TxtEvento.Text = ""
DdlAnfitrion.SelectedValue = "-1"
Alert("El nuevo Evento se guardó correctamente.", TipoMensaje.MsgInformacion)
UpTitulos.Update()
ViewState("DTEvento") = ObjAnfitrion.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End If
ObjAnfitrion.Dispose()
End Sub
#Region "G V D A T O S"
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = 0 Then
e.Row.Cells(0).Width = Unit.Pixel(100)
e.Row.Cells(1).Width = Unit.Pixel(150)
e.Row.Cells(2).Width = Unit.Pixel(130)
e.Row.Cells(3).Width = Unit.Pixel(160)
e.Row.Cells(4).Width = Unit.Pixel(150)
e.Row.Cells(5).Width = Unit.Pixel(80)
e.Row.Cells(6).Width = Unit.Pixel(80)
e.Row.Cells(7).Width = Unit.Pixel(80)
e.Row.Cells(8).Width = Unit.Pixel(100)
e.Row.Cells(9).Width = Unit.Pixel(61)
End If
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(9).HorizontalAlign = HorizontalAlign.Center
If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then
e.Row.FCDropDownList("DdlEventoTipo").DataSource = GlobalDTProspectosEventosTipo(UsuarioActual.CveEmpresa)
e.Row.FCDropDownList("DdlEventoTipo").DataBind()
e.Row.FCDropDownList("DdlEventoTipo").SelectedValue = e.Row.DBCampo("CveEventoTipo")
e.Row.FCDropDownList("DdlMunicipio").DataSource = GlobalDTGralMunicipios("26")
e.Row.FCDropDownList("DdlMunicipio").DataBind()
e.Row.FCDropDownList("DdlMunicipio").SelectedValue = e.Row.DBCampo("CveMunicipio")
CargaAnfitrion(e.Row.FCDropDownList("DdlAnfitrion"))
e.Row.FCDropDownList("DdlAnfitrion").SelectedValue = e.Row.DBCampo("CveAnfitrion")
End If
End If
End Sub
Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
Dim ObjAnfitrion As New ClsProspectos
If ObjAnfitrion.RemoveProspectosEventos(GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then
GvDatos.EditIndex = -1
ViewState("DTEvento") = ObjAnfitrion.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
Alert("El Anfitrión se eliminó correctamente.", TipoMensaje.MsgInformacion)
End If
ObjAnfitrion.Dispose()
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End Sub
Protected Sub GvDatos_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvDatos.RowCancelingEdit
GvDatos.EditIndex = -1
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End Sub
Protected Sub GvDatos_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatos.RowUpdating
Dim ObjAnfitrion As New ClsProspectos
Dim Evento As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtEvento"), TextBox).Text.Trim
Dim CveEventoTipo As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlEventoTipo"), DropDownList).SelectedValue.ToEntero
'Dim Anfitrion As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtAnfitrion"), TextBox).Text.Trim
Dim FechaEvento As DateTime = CDate(DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtFechaEvento"), TextBox).Text.Trim)
Dim CveSupervisor As Integer = -1 ' DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlSupervisor"), DropDownList).SelectedValue.ToEntero
Dim CveAnfitrion As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlAnfitrion"), DropDownList).SelectedValue.ToEntero
Dim CveMunicipio As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlMunicipio"), DropDownList).SelectedValue.ToEntero
Dim Estatus As Boolean = GvDatos.Rows(e.RowIndex).FCCheckBox("ChkEstatus").Checked
Dim CveEvento As Integer = GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero
If ObjAnfitrion.UpdateProspectosEventos(Evento, CveEventoTipo, FechaEvento, CveSupervisor, CveAnfitrion, "", CveMunicipio, Estatus, CveEvento) Then
GvDatos.EditIndex = -1
ViewState("DTEvento") = ObjAnfitrion.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTProspectosEvento(-1, -1) = ObjAnfitrion.DtResultados
Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion)
End If
ObjAnfitrion.Dispose()
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End Sub
Protected Sub GvDatos_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvDatos.RowEditing
GvDatos.EditIndex = e.NewEditIndex
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End Sub
#End Region
#Region "O R D E N A M I E N T O"
Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Orden As String = ""
Dim Campo As String = ""
Dim Literal As Literal = Nothing
Const OrdenInicial As String = ""
Dim Arg(2) As String
Arg = CType(sender, LinkButton).CommandArgument().ToString.Split(";"c)
Campo = Arg(0)
Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal)
If ViewState(String.Format("O{0}", Campo)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo)).ToString = String.Format("{0} DESC", Campo) Then
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} ASC", Campo)
Literal.Text = String.Format("<i class='fa fa-sort-asc' style='color:#999' ></i>")
Else
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} DESC", Campo)
Literal.Text = String.Format("<i class='fa fa-sort-desc' style='color:#999' ></i>")
End If
Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo)).ToString
ViewState("Orden") = Orden
CargaGrid(Orden)
End Sub
Private Sub CargaGrid(Orden As String)
If Orden <> String.Empty Then
Dim DV As New DataView(CType(ViewState("DTEvento"), DataTable), "", Orden, DataViewRowState.CurrentRows)
GvDatos.DataSource = DV.ToTable()
DV.Dispose()
Else
GvDatos.DataSource = CType(ViewState("DTEvento"), DataTable)
End If
GvDatos.DataBind()
UpDatos.Update()
End Sub
#End Region
End Class