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

352 lines
12 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Partial Class ZDG_MensajeManual
Inherits ClsPaginas
#Region " PROPIEDADES "
Private Property DtCoordinadores As DataTable
Get
Return CType(ViewState("DtCoordinadores"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtCoordinadores") = value
End Set
End Property
Private Property DtLideres As DataTable
Get
Return CType(ViewState("DtLideres"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtLideres") = value
End Set
End Property
Private Property DtMovilizadores As DataTable
Get
Return CType(ViewState("DtMovilizadores"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtMovilizadores") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
SetValues()
Else
LbRestantes.Text = (160 - TxtMensaje.Text.Length).ToString
End If
End Sub
#Region " SET VALUES "
Private Sub SetValues()
Dim ObjDG As New ClsDG
'CargaMunicipios
If ObjDG.GetMunicipios() Then
DdlMunicipio.DataSource = ObjDG.DtResultados
Else
DdlMunicipio.DataSource = Nothing
End If
'Carga # Mensajes
If ObjDG.MensajeGet() AndAlso ObjDG.DtResultados.Rows.Count = 1 Then
LbMensajesEnviados.Text = ObjDG.DtResultados.Rows(0)("NumeroMensajes").ToString
Else
Alert("Ocurrió un error al obtener el numero de mensajes Enviados.", TipoMensaje.MsgError)
End If
ObjDG.Dispose()
DdlMunicipio.DataBind()
End Sub
#End Region
#Region " CARGA DATOS "
Protected Sub DdlMunicipio_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim ObjDG As New ClsDG
DtCoordinadores = Nothing
If ChkCoordinadores.Checked Then
If ObjDG.GetCoordinadores("-1", DdlMunicipio.SelectedValue.ToEntero) Then
DtCoordinadores = ObjDG.DtResultados
Else
Alert("Ocurrió un error al cargar los Coordinadores. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
End If
DtLideres = Nothing
If ChkLideres.Checked Then
If ObjDG.GetLideres("-1", DdlMunicipio.SelectedValue.ToEntero) Then
DtLideres = ObjDG.DtResultados
Else
Alert("Ocurrió un error al cargar los Lideres. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
End If
DtMovilizadores = Nothing
If ChkMovilizadores.Checked Then
If ObjDG.GetMovilizadores("-1", DdlMunicipio.SelectedValue.ToEntero) Then
DtMovilizadores = ObjDG.DtResultados
Else
Alert("Ocurrió un error al cargar los Movilizadores. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
End If
ObjDG.Dispose()
CalculaTotales()
End Sub
Protected Sub ChkCoordinadores_CheckedChanged(sender As Object, e As EventArgs)
Dim ObjDG As New ClsDG
DtCoordinadores = Nothing
If ChkCoordinadores.Checked Then
If ObjDG.GetCoordinadores("-1", DdlMunicipio.SelectedValue.ToEntero) Then
DtCoordinadores = ObjDG.DtResultados
Else
Alert("Ocurrió un error al cargar los Coordinadores. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
End If
ObjDG.Dispose()
CalculaTotales()
End Sub
Protected Sub ChkLideres_CheckedChanged(sender As Object, e As EventArgs)
Dim ObjDG As New ClsDG
DtLideres = Nothing
If ChkLideres.Checked Then
If ObjDG.GetLideres("-1", DdlMunicipio.SelectedValue.ToEntero) Then
DtLideres = ObjDG.DtResultados
Else
Alert("Ocurrió un error al cargar los Lideres. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
End If
ObjDG.Dispose()
CalculaTotales()
End Sub
Protected Sub ChkMovilizadores_CheckedChanged(sender As Object, e As EventArgs)
Dim ObjDG As New ClsDG
DtMovilizadores = Nothing
If ChkMovilizadores.Checked Then
If ObjDG.GetMovilizadores("-1", DdlMunicipio.SelectedValue.ToEntero) Then
DtMovilizadores = ObjDG.DtResultados
Else
Alert("Ocurrió un error al cargar los Movilizadores. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
End If
ObjDG.Dispose()
CalculaTotales()
End Sub
Private Sub CalculaTotales()
LbCoordinadores.Text = If(DtCoordinadores IsNot Nothing, DtCoordinadores.COUNT("RNM").ToString, "0")
LbLideres.Text = If(DtLideres IsNot Nothing, DtLideres.COUNT("RNM").ToString, "0")
LbMovilizadores.Text = If(DtMovilizadores IsNot Nothing, DtMovilizadores.COUNT("RNM").ToString, "0")
LbTotal.Text = (LbCoordinadores.Text.ToEntero + LbLideres.Text.ToEntero + LbMovilizadores.Text.ToEntero).ToString
End Sub
#End Region
#Region " ENVIAR "
Protected Sub BtnEnviar_Click(sender As Object, e As EventArgs)
'Alert(LimpiarMensaje(TxtMensaje.Text))
'Exit Sub
'Dim X As New WSTecnoMovil.SendSmsWS
'Dim Response As WSTecnoMovil.sendSmsResponseTO
'Response = X.sendSms("AD", "SISTEMAS", "SALUDO GABRIELA, TE QUERIAMOS DECIR QUE TIENES EL MEJOR ESPOSO DEL MUNDO.", "6624297448", 99, False)
'Exit Sub
'Dim ObjDG As New ClsDG
'If ObjDG.EnviarMensajeWS(1234567890, "Hola") Then
'Else
' Alert("Ocurrió un Error al mandar el mensaje: ", TipoMensaje.MsgError)
'End If
'ObjDG.Dispose()
'Exit Sub
''CORREO
'Dim ObjMail As New ClsSisMail
'ObjMail.SendMail(UsuarioActual.Empresa, "ing.israelpina@hotmail.com", "MENSAJE SMS DG", "TEST", "israel.pina@adsistemas.mx")
'Alert("TODO FRENADO!!", TipoMensaje.MsgAdvertencia)
'Exit Sub
If TxtMensaje.Text = "" Then
Alert("No hay mensaje que enviar. Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If ChkCoordinadores.Checked = False And ChkLideres.Checked = False And ChkMovilizadores.Checked = False Then
Alert("No hay destinatarios a los que enviar el mensaje. Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjDG As New ClsDG
Dim Str As New StringBuilder
Dim Acum = 1
Dim MensajeLimpio = ""
'COORDINADORES
If DtCoordinadores IsNot Nothing Then
For Each Dr As DataRow In DtCoordinadores.Rows
MensajeLimpio = If(LimpiarMensaje(TxtMensaje.Text).Length > 150, LimpiarMensaje(TxtMensaje.Text).Substring(0, 150), LimpiarMensaje(TxtMensaje.Text))
'MensajeLimpio = $"C: {MensajeLimpio}"
If ObjDG.EnviarMensajeWS(Dr("Telefono").ToString, MensajeLimpio) Then
If ObjDG.MensajeAdd(1, Dr("Telefono").ToString, MensajeLimpio, UsuarioActual.CveUsuario) Then
Str.AppendFormat("#{0} - Coordinador: {1} {2} <br/>", Acum, Dr("Nombre"), Dr("Telefono"))
Acum += 1
End If
End If
Next
End If
'LIDERES
If DtLideres IsNot Nothing Then
For Each Dr As DataRow In DtLideres.Rows
MensajeLimpio = If(LimpiarMensaje(TxtMensaje.Text).Length > 150, LimpiarMensaje(TxtMensaje.Text).Substring(0, 150), LimpiarMensaje(TxtMensaje.Text))
'MensajeLimpio = $"L: {MensajeLimpio}"
If ObjDG.EnviarMensajeWS(Dr("Telefono").ToString, MensajeLimpio) Then
If ObjDG.MensajeAdd(1, Dr("Telefono").ToString, MensajeLimpio, UsuarioActual.CveUsuario) Then
Str.AppendFormat("#{0} - Lider: {1} {2} <br/>", Acum, Dr("Nombre"), Dr("Telefono"))
Acum += 1
End If
End If
Next
End If
'MOVILIZADORES
If DtMovilizadores IsNot Nothing Then
For Each Dr As DataRow In DtMovilizadores.Rows
MensajeLimpio = If(LimpiarMensaje(TxtMensaje.Text).Length > 150, LimpiarMensaje(TxtMensaje.Text).Substring(0, 150), LimpiarMensaje(TxtMensaje.Text))
'MensajeLimpio = $"M: {MensajeLimpio}"
If ObjDG.EnviarMensajeWS(Dr("Telefono").ToString, MensajeLimpio) Then
If ObjDG.MensajeAdd(1, Dr("Telefono").ToString, MensajeLimpio, UsuarioActual.CveUsuario) Then
Str.AppendFormat("#{0} - Movilizador: {1} {2} <br/>", Acum, Dr("Nombre"), Dr("Telefono"))
Acum += 1
End If
End If
Next
End If
'MENSAJES A ALGUIEN
MensajeLimpio = If(LimpiarMensaje(TxtMensaje.Text).Length > 150, LimpiarMensaje(TxtMensaje.Text).Substring(0, 150), LimpiarMensaje(TxtMensaje.Text))
If ObjDG.EnviarMensajeWS("5545112326", MensajeLimpio) Then
If ObjDG.MensajeAdd(1, "5545112326", MensajeLimpio, UsuarioActual.CveUsuario) Then
End If
End If
'MENSAJES A IPP
If ObjDG.EnviarMensajeWS("6313186706", String.Format("SE ENVIO SMS MANUAL - Hora:{0}", Now.ToString("HH:mm:ss"))) Then
If ObjDG.MensajeAdd(1, "6313186706", String.Format("SE ENVIO SMS MANUAL - Hora:{0}", Now.ToString("HH:mm:ss")), UsuarioActual.CveUsuario) Then
End If
End If
'MENSAJES A JA
If ObjDG.EnviarMensajeWS("6621317425", String.Format("SE ENVIO SMS MANUAL - Hora: {0}", Now.ToString("HH:mm:ss"))) Then
If ObjDG.MensajeAdd(1, "6621317425", String.Format("SE ENVIO SMS MANUAL - Hora:{0}", Now.ToString("HH:mm:ss")), UsuarioActual.CveUsuario) Then
End If
End If
'CORREO
Dim ObjMail As New ClsSisMail
ObjMail.SendMail(UsuarioActual.Empresa, "ing.israelpina@hotmail.com", "MENSAJE SMS MANUAL DG", Str.ToString, "israel.pina@adsistemas.mx,rene.molina@adsistemas.mx,julian@adsistemas.mx,jjaguialrv@hotmail.com")
'Alert(Str.ToString)
Alert("Mensaje enviado exitosamente.", TipoMensaje.MsgInformacion)
ObjDG.Dispose()
Limpiar()
End Sub
#End Region
#Region " CANCELAR "
Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs)
Limpiar()
End Sub
Private Sub Limpiar()
DtCoordinadores = Nothing
DtLideres = Nothing
DtMovilizadores = Nothing
TxtMensaje.Text = ""
ChkCoordinadores.Checked = False
ChkLideres.Checked = False
ChkMovilizadores.Checked = False
LbCoordinadores.Text = "0"
LbLideres.Text = "0"
LbMovilizadores.Text = "0"
LbRestantes.Text = "150"
LbTotal.Text = "0"
DdlMunicipio.SelectedValueExist("-1")
'Carga # Mensajes
Dim ObjDG As New ClsDG
If ObjDG.MensajeGet() AndAlso ObjDG.DtResultados.Rows.Count = 1 Then
LbMensajesEnviados.Text = ObjDG.DtResultados.Rows(0)("NumeroMensajes").ToString
Else
Alert("Ocurrió un error al obtener el numero de mensajes Enviados.", TipoMensaje.MsgError)
End If
ObjDG.Dispose()
End Sub
#End Region
Function LimpiarMensaje(texto As String) As String
Dim consignos As String = "áàäéèëíìïóòöúùuñÁÀÄÉÈËÍÌÏÓÒÖÚÙÜÑçÇ"
Dim sinsignos As String = "aaaeeeiiiooouuunAAAEEEIIIOOOUUUNcC"
Dim textoSinAcentos As System.Text.StringBuilder = New System.Text.StringBuilder(texto.Length)
Dim indexConAcento As Integer
For Each caracter As Char In texto
indexConAcento = consignos.IndexOf(caracter)
If (indexConAcento > -1) Then
textoSinAcentos.Append(sinsignos.Substring(indexConAcento, 1))
Else
textoSinAcentos.Append(caracter)
End If
Next
Dim regex As New Regex("[ ](?=[ ])|[^,.A-Za-z0-9 ]+")
Return regex.Replace(textoSinAcentos.ToString, "")
End Function
End Class