Files
SIG/Sistemas/CatNotificaciones.aspx.vb.exclude
JORGE LUIS CAUDILLO ESPARZA c35cf91883 Commit inicial Ventas Productivo
2019-08-14 16:40:54 -07:00

447 lines
17 KiB
Plaintext

Imports Extensiones
Imports System.Data
Partial Class CatNotificaciones
Inherits ClsPaginas
#Region "P R O P I E D A D E S"
Private Property CveNotificacion As Integer
Get
Return ViewState("CveNotificacion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveNotificacion") = value
End Set
End Property
#End Region
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
If ViewState("CveNotificacion") = Nothing Then
ViewState("CveNotificacion") = -1
End If
DdlEmpresa.SelectedValue = UsuarioActual.CveEmpresa.ToString
CargaEmpresasNotificaciones(UsuarioActual.CveEmpresa)
CargaNotificaciones()
CargaNoficacionesEmpresa()
CargaCombos()
End If
End Sub
Private Sub LimpiaChk()
ChkCampana.Checked = False
ChkCorreo.Checked = False
ChkDomingo.Checked = False
ChkJueves.Checked = False
ChkLunes.Checked = False
ChkMartes.Checked = False
ChkMiercoles.Checked = False
ChkMSN.Checked = False
ChkRecurrencia.Checked = False
ChkRecurrenciaFecha.Checked = False
ChkRecurrenciaVeces.Checked = False
ChkSabado.Checked = False
ChkSMS.Checked = False
ChkViernes.Checked = False
End Sub
#Region "N O T I F I C A C I O N E S "
Private Sub CargaCombos()
DdlModulo.DataSource = GlobalDTModulos()
DdlModulo.DataBind()
DdlEmpresa.DataSource = GlobalDTEmpresas()
DdlEmpresa.DataBind()
End Sub
Private Sub CargaNotificaciones()
Dim ObjNotificaciones As New ClsSisNotificaciones
If ObjNotificaciones.GetNotificacionesPlantilla() Then
GvNotificaciones.DataSource = ObjNotificaciones.DtResultados
Else
GvNotificaciones.DataSource = Nothing
End If
ObjNotificaciones.Dispose()
GvNotificaciones.DataBind()
UpDatos.Update()
End Sub
Private Sub DdlRecurrencia_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlRecurrencia.SelectedIndexChanged
If DdlRecurrencia.SelectedValue = 3 Then
divDiasSemana.Visible = True
Else
divDiasSemana.Visible = False
ChkLunes.Checked = False
ChkMartes.Checked = False
ChkMiercoles.Checked = False
ChkJueves.Checked = False
ChkViernes.Checked = False
ChkSabado.Checked = False
ChkDomingo.Checked = False
End If
End Sub
Private Sub BtnAddNotificacion_Click(sender As Object, e As EventArgs) Handles BtnAddNotificacion.Click
Dim ObjSis As New ClsSisNotificaciones
Dim TieneError = False
Dim DiasSemana As New StringBuilder()
If ChkLunes.Checked Then DiasSemana.AppendFormat("{0}", "L")
If ChkMartes.Checked Then DiasSemana.AppendFormat(If(DiasSemana.Length > 0, ",{0}", "{0}"), "Ma")
If ChkMiercoles.Checked Then DiasSemana.AppendFormat(If(DiasSemana.Length > 0, ",{0}", "{0}"), "Mi")
If ChkJueves.Checked Then DiasSemana.AppendFormat(If(DiasSemana.Length > 0, ",{0}", "{0}"), "J")
If ChkViernes.Checked Then DiasSemana.AppendFormat(If(DiasSemana.Length > 0, ",{0}", "{0}"), "V")
If ChkSabado.Checked Then DiasSemana.AppendFormat(If(DiasSemana.Length > 0, ",{0}", "{0}"), "S")
If ChkDomingo.Checked Then DiasSemana.AppendFormat(If(DiasSemana.Length > 0, ",{0}", "{0}"), "D")
Dim RecurrenciaFin As String
If ChkRecurrenciaVeces.Checked Then
RecurrenciaFin = TxtRecurrenciaFin.Text.Trim()
ElseIf ChkRecurrenciaFecha.Checked Then
RecurrenciaFin = TxtFecha.Text.Trim()
Else
RecurrenciaFin = "-1"
End If
If CveNotificacion < 0 Then
CveNotificacion = ObjSis.AddNotificacionesPlantilla(TxtNotificacion.Text.Trim, DdlModulo.SelectedValue.ToEntero, TxtPlantilla.Text.Trim, ChkCorreo.Checked, ChkSMS.Checked, ChkMSN.Checked,
ChkCampana.Checked, If(ChkRecurrencia.Checked, DdlRecurrencia.SelectedValue.ToEntero, -1), DiasSemana.ToString, If(ChkRecurrencia.Checked, TxtFrecuencia.Text.Trim.ToEntero, 0), RecurrenciaFin, UsuarioActual.CveUsuario)
If CveNotificacion > 0 Then
RegistraScript("LimpiaModal(); $('#divAddNotificacion').modal('hide')")
Alert("Se Agregó la Notificacón con éxito.")
CargaNotificaciones()
CargaNoficacionesEmpresa()
CargaEmpresasNotificaciones(UsuarioActual.CveEmpresa)
Else
Alert("Ocurrió un error al registar Notificación")
End If
Else
If Not ObjSis.UpdateNotificacionesPlantilla(CveNotificacion, TxtNotificacion.Text.Trim, DdlModulo.SelectedValue.ToEntero, TxtPlantilla.Text.Trim, ChkCorreo.Checked, ChkSMS.Checked, ChkMSN.Checked,
ChkCampana.Checked, If(ChkRecurrencia.Checked, DdlRecurrencia.SelectedValue.ToEntero, 0), DiasSemana.ToString, If(ChkRecurrencia.Checked, TxtFrecuencia.Text.Trim.ToEntero, 0), RecurrenciaFin, UsuarioActual.CveUsuario) Then
TieneError = True
End If
If Not TieneError Then
Alert("Se Modificó la Notificacón con éxito.")
RegistraScript("$('#divAddNotificacion').modal('hide')")
CargaNotificaciones()
CargaNoficacionesEmpresa()
CargaEmpresasNotificaciones(UsuarioActual.CveEmpresa)
Else
Alert("Ocurrió un error al registar Notificación")
End If
End If
End Sub
Private Sub ChkRecurrencia_CheckedChanged(sender As Object, e As EventArgs) Handles ChkRecurrencia.CheckedChanged
If ChkRecurrencia.Checked Then
DivRecurrencia.Visible = True
DivFrecuencia.Visible = True
DivRecurrenciaFin.Visible = True
If DdlRecurrencia.SelectedValue.ToEntero = 3 Then divDiasSemana.Visible = True
Else
DivRecurrencia.Visible = False
DivFrecuencia.Visible = False
divDiasSemana.Visible = False
DivRecurrenciaFin.Visible = False
End If
UpNotificionIS.Update()
End Sub
#Region "GV NOTIFICACIONES"
Private Sub GvNotificaciones_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvNotificaciones.RowEditing
GvNotificaciones.EditIndex = e.NewEditIndex
CargaNotificaciones()
End Sub
Private Sub GvNotificaciones_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvNotificaciones.RowCancelingEdit
GvNotificaciones.EditIndex = -1
CargaNotificaciones()
End Sub
Private Sub GvNotificaciones_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvNotificaciones.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim URL As String = String.Format("javascript:CargaModal({0})", e.Row.DataKey("CveNotificacionPlantilla").ToEntero)
Dim Liga As String = String.Format("<a class=""LinkBlanco"" href=""{0}"">", URL)
e.Row.FCLinkButton("LtlNotificacion").CommandArgument = e.Row.DataKey("CveNotificacionPlantilla")
End If
End Sub
Private Sub GvNotificaciones_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvNotificaciones.RowDeleting
Dim ObjNotificaciones As New ClsSisNotificaciones
Dim TieneError = False
Dim CveNotificacion = GvNotificaciones.Rows(e.RowIndex).DataKey("CveNotificacionPlantilla").ToEntero
If Not ObjNotificaciones.RemoveNotificacionesPlantilla(CveNotificacion) Then
TieneError = True
End If
If Not TieneError Then
GvNotificaciones.EditIndex = -1
Alert("La notificación ha sido eliminada.", TipoMensaje.MsgInformacion)
CargaNoficacionesEmpresa()
CargaNotificaciones()
CargaEmpresasNotificaciones(UsuarioActual.CveEmpresa)
Else
Alert("Error al eliminar los cambios.", TipoMensaje.MsgError)
End If
UpDatos.Dispose()
UpTitulos.Update()
End Sub
#End Region
Protected Sub BtnCargaModal_Click(sender As Object, e As EventArgs)
Dim ObjNotificaciones As New ClsSisNotificaciones
Dim DTnotificaciones As New DataTable
Dim Clave = CType(sender, LinkButton).CommandArgument.ToEntero
If ObjNotificaciones.GetNotificacionesPlantilla() Then
DTnotificaciones = ObjNotificaciones.DtResultados.FiltraParametros(String.Format("CveNotificacionPlantilla = {0}", Clave))
Else
DTnotificaciones = Nothing
End If
Dim Dias = DTnotificaciones(0)("DiasSemana").ToString.Split(","c)
For Each Dia As String In Dias
Select Case Dia
Case "L"
ChkLunes.Checked = True
Case "Ma"
ChkMartes.Checked = True
Case "Mi"
ChkMiercoles.Checked = True
Case "J"
ChkJueves.Checked = True
Case "V"
ChkViernes.Checked = True
Case "S"
ChkSabado.Checked = True
Case "D"
ChkDomingo.Checked = True
End Select
Next
TxtNotificacion.Text = DTnotificaciones(0)("Notificacion").ToString
DdlModulo.SelectedValueExist(DTnotificaciones(0)("CveModulo").ToString)
TxtPlantilla.Text = DTnotificaciones(0)("Plantilla").ToString
ChkCorreo.Checked = If(DTnotificaciones(0)("Correo").ToString = "Activo", True, False)
ChkSMS.Checked = If(DTnotificaciones(0)("SMS").ToString = "Activo", True, False)
ChkMSN.Checked = If(DTnotificaciones(0)("MSN").ToString = "Activo", True, False)
ChkCampana.Checked = If(DTnotificaciones(0)("Campana").ToString = "Activo", True, False)
DdlRecurrencia.SelectedValueExist(DTnotificaciones(0)("RecurrenciaTipo").ToString)
TxtFrecuencia.Text = DTnotificaciones(0)("Frecuencia").ToString
If DTnotificaciones(0)("RecurrenciaFin").ToString.ToEntero > 0 Then
ChkRecurrenciaVeces.Checked = True
TxtRecurrenciaFin.Text = DTnotificaciones(0)("RecurrenciaFin").ToString
Else
ChkRecurrenciaFecha.Checked = True
TxtFecha.Text = DTnotificaciones(0)("RecurrenciaFin").ToString
End If
If DdlRecurrencia.SelectedValue.ToEntero > 0 Then
ChkRecurrencia.Checked = True
ChkRecurrencia_CheckedChanged(ChkRecurrencia, EventArgs.Empty)
Else
ChkRecurrencia.Checked = False
End If
If Clave > 0 Then
BtnAddNotificacion.Text = "Actualizar"
Else
BtnAddNotificacion.Text = "Agregar"
End If
CveNotificacion = Clave
RegistraScript("$('#divAddNotificacion').modal()")
UpNotificionIS.Update()
UpNotificacion.Update()
End Sub
Private Sub LbAddNotificacion_Click(sender As Object, e As EventArgs) Handles LbAddNotificacion.Click
CveNotificacion = -1
If CveNotificacion > 0 Then
BtnAddNotificacion.Text = "Actualizar"
Else
BtnAddNotificacion.Text = "Agregar"
End If
divDiasSemana.Visible = False
DivFrecuencia.Visible = False
DivRecurrencia.Visible = False
DivRecurrenciaFin.Visible = False
UpFooter.Update()
UpNotificionIS.Update()
RegistraScript("$('#divAddNotificacion').modal();LimpiaModal()")
End Sub
#End Region
#Region "E M P R E S A S - N O T I F I C A C I O N E S"
Private Sub CargaNoficacionesEmpresa()
Dim ObjSis As New ClsSisNotificaciones
DdlNotificaciones.Items.Clear()
If ObjSis.GetNotificacionesEmpresa() Then
DdlNotificaciones.DataSource = ObjSis.DtResultados
Else
DdlNotificaciones.DataSource = Nothing
End If
DdlNotificaciones.DataBind()
ObjSis.Dispose()
UpTitulos.Update()
End Sub
Private Sub CargaEmpresasNotificaciones(CveEmpresa As Integer)
Dim ObjSis As New ClsSisNotificaciones
If ObjSis.GetNotificacionesEmpresas2(CveEmpresa) Then
GvEmpresas.DataSource = ObjSis.DtResultados
Else
GvEmpresas.DataSource = Nothing
End If
ObjSis.Dispose()
GvEmpresas.DataBind()
UpEmpresa.Update()
End Sub
Private Sub LbAgregarFuncionalidadEmpresa_Click(sender As Object, e As EventArgs) Handles LbAgregarFuncionalidadEmpresa.Click
Dim ObjSis As New ClsSisNotificaciones
Dim TieneError = False
If Not ObjSis.AddNotificacionesEmpresas(DdlEmpresa.SelectedValue.ToEntero, DdlNotificaciones.SelectedValue.ToEntero, UsuarioActual.CveUsuario) Then
TieneError = True
End If
ObjSis.Dispose()
If Not TieneError Then
Alert("Se ha agregado con éxito")
CargaEmpresasNotificaciones(DdlEmpresa.SelectedValue.ToEntero)
Else
Alert("Ha ocurrido un error al registrar los datos")
End If
End Sub
Private Sub DdlEmpresa_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlEmpresa.SelectedIndexChanged
CargaEmpresasNotificaciones(DdlEmpresa.SelectedValue.ToEntero)
End Sub
#Region "GV EMPRESA"
Private Sub GvEmpresas_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvEmpresas.RowEditing
GvEmpresas.EditIndex = e.NewEditIndex
CargaEmpresasNotificaciones(DdlEmpresa.SelectedValue.ToEntero)
End Sub
Private Sub GvEmpresas_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvEmpresas.RowCancelingEdit
GvEmpresas.EditIndex = -1
CargaEmpresasNotificaciones(DdlEmpresa.SelectedValue.ToEntero)
End Sub
Private Sub GvEmpresas_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvEmpresas.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
Dim ObjSis As New ClsSisNotificaciones
If ObjSis.GetNotificacionesEmpresa() Then
e.Row.FCDropDownList("DdlNotificacionesEdit").DataSource = ObjSis.DtResultados
e.Row.FCDropDownList("DdlNotificacionesEdit").DataBind()
End If
e.Row.FCDropDownList("DdlNotificacionesEdit").SelectedValueExist(e.Row.DataKey("CveNotificacion"))
ObjSis.Dispose()
End If
End If
End Sub
Private Sub GvEmpresas_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvEmpresas.RowDeleting
Dim ObjNotificaciones As New ClsSisNotificaciones
Dim TieneError = False
Dim CveNotificacion = GvEmpresas.Rows(e.RowIndex).DataKey("CveNotificacion").ToEntero
Dim CveEmpresa = GvEmpresas.Rows(e.RowIndex).DataKey("CveEmpresa").ToEntero
Dim CveEmpresaNotificacion = GvEmpresas.Rows(e.RowIndex).DataKey("CveNotificacionEmpresa").ToEntero
If Not ObjNotificaciones.RemoveNotificacionesEmpresa(CveNotificacion, CveEmpresa, CveEmpresaNotificacion) Then
TieneError = True
End If
If Not TieneError Then
GvEmpresas.EditIndex = -1
Alert("La notificación ha sido eliminada.", TipoMensaje.MsgInformacion)
CargaEmpresasNotificaciones(DdlEmpresa.SelectedValue.ToEntero)
Else
Alert("Error al eliminar los cambios.", TipoMensaje.MsgError)
End If
End Sub
Private Sub GvEmpresas_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvEmpresas.RowUpdating
Dim ObjNotificaciones As New ClsSisNotificaciones
Dim TieneError = False
Dim CveNotificacion = GvEmpresas.Rows(e.RowIndex).FCDropDownList("DdlNotificacionesEdit").SelectedValue.ToEntero
Dim CveEmpresa = GvEmpresas.Rows(e.RowIndex).DataKey("CveEmpresa").ToEntero
Dim CveEmpresaNotificacion = GvEmpresas.Rows(e.RowIndex).DataKey("CveNotificacionEmpresa").ToEntero
If Not ObjNotificaciones.UpdateNotificacionesEmpresa(CveNotificacion, CveEmpresa, UsuarioActual.CveUsuario, CveEmpresaNotificacion) Then
TieneError = True
End If
ObjNotificaciones.Dispose()
If Not TieneError Then
GvEmpresas.EditIndex = -1
Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion)
CargaEmpresasNotificaciones(DdlEmpresa.SelectedValue.ToEntero)
Else
Alert("Error al actualizar los cambios.", TipoMensaje.MsgError)
End If
End Sub
#End Region
#End Region
Protected Sub ServerValidate(source As Object, args As ServerValidateEventArgs)
args.IsValid = ChkRecurrenciaFecha.Checked Or ChkRecurrenciaVeces.Checked
End Sub
End Class