247 lines
14 KiB
Plaintext
247 lines
14 KiB
Plaintext
<%@ WebHandler Language="VB" Class="CargaEventos" %>
|
|
Option Explicit On
|
|
Option Strict On
|
|
|
|
Imports System
|
|
Imports System.Web
|
|
Imports System.Collections
|
|
Imports System.Collections.Generic
|
|
Imports System.Web.SessionState
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
|
|
Public Class CargaEventos : Implements IHttpHandler, IRequiresSessionState
|
|
|
|
Public Property events As List(Of CalendarEvent)
|
|
|
|
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
|
context.Response.ContentType = "text/plain"
|
|
|
|
Dim CveUsuario = -1
|
|
Dim CveEmpresa = -1
|
|
Dim FI As Date
|
|
Dim FF As Date
|
|
|
|
If context.Request("U").ToEntero > 0 Then
|
|
CveUsuario = context.Request("U").ToEntero
|
|
CveEmpresa = context.Request("E").ToEntero
|
|
FI = context.Request("start").ToDate
|
|
|
|
FF = context.Request("end").ToDate
|
|
End If
|
|
|
|
|
|
If Not GetEventos(CveUsuario, CveEmpresa, FI, FF) Then
|
|
'Convierte el objeto de Eventos en JSON
|
|
'Dim oSerializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer
|
|
Dim sJSON As String = Newtonsoft.Json.JsonConvert.SerializeObject(events)
|
|
|
|
context.Response.Write(sJSON)
|
|
End If
|
|
End Sub
|
|
|
|
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
|
Get
|
|
Return False
|
|
End Get
|
|
End Property
|
|
|
|
|
|
Private Function GetEventos(CveUsuario As Integer, CveEmpresa As Integer, pFI As Date, pFF As Date) As Boolean
|
|
Dim ObjEventos As New ClsOIEventos
|
|
Dim ErrorEventos = False
|
|
If ObjEventos.GetEventos(-1, -1, -1, "-1", "-1", -1, CveUsuario, CveUsuario, -1, -1, -1, "-1", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, CveUsuario, CveUsuario, CveUsuario, CveEmpresa, pFI, pFF) Then
|
|
|
|
If ObjEventos.DtResultados.Rows.Count > 0 Then
|
|
events = New List(Of CalendarEvent)
|
|
Try
|
|
For Each dr As DataRow In ObjEventos.DtResultados.Rows
|
|
Dim cevent As CalendarEvent = New CalendarEvent()
|
|
cevent.id = dr("CveEvento").ToString.ToEntero
|
|
cevent.title = dr("Asunto").ToString
|
|
cevent.description = dr("Descripcion").ToString
|
|
cevent.start = String.Format("{0:s}", dr("FechaInicio").ToString.ToDateTime)
|
|
cevent.end = String.Format("{0:s}", dr("FechaFin").ToString.ToDateTime)
|
|
cevent.allDay = False
|
|
cevent.CveEventoEstatus = dr("CveEventoEstatus").ToString.ToEntero
|
|
cevent.cveagendatipo = dr("CveAgendaTipo").ToString
|
|
cevent.prioridad = dr("CvePrioridad").ToString.ToEntero
|
|
cevent.backgroundColor = dr("BackGroundColor").ToString
|
|
cevent.recurrenciatipo = dr("RecurrenciaTipo").ToString.ToEntero
|
|
cevent.frecuencia = dr("Frecuencia").ToString.ToEntero
|
|
cevent.diassemana = dr("DiasSemana").ToString
|
|
cevent.dia = dr("Dia").ToString.ToEntero
|
|
cevent.mes = dr("Mes").ToString.ToEntero
|
|
cevent.recurrenciafin = dr("RecurrenciaFin").ToString
|
|
cevent.CveProspecto = dr("CveProspecto").ToString.ToEntero
|
|
cevent.Prospecto = dr("Prospecto").ToString
|
|
cevent.CveTipoEvento = dr("Prospecto").ToString.ToEntero
|
|
|
|
'11/05/2018 - Evento Gasto Recurrente
|
|
cevent.CveTipoEvento = dr("CveTipoEvento").ToString.ToEntero
|
|
If cevent.CveTipoEvento = 10 Then
|
|
cevent.Importe = dr("Importe").ToString.ToDouble
|
|
End If
|
|
|
|
If cevent.CveEventoEstatus.ToString.ToEntero = 3 Then
|
|
cevent.backgroundColor = "#1BBC9B"
|
|
End If
|
|
|
|
'VERIFICAMOS SI TIENE O NO RECURRENCIA
|
|
If Not cevent.recurrenciatipo > 0 Then
|
|
|
|
'AGREGAMOS CUANDO NO ES RECURRENTE
|
|
Dim tFecha As DateTime = DateAdd(DateInterval.Month, -6, Date.Now)
|
|
'SI LA FECHA DEL EVENTO ES MENOR DE 6 MESES DE LA FECHA ACTUAL NO LO AGREGA
|
|
If dr("FechaFin").ToString.ToDateTime > tFecha Or dr("FechaInicio").ToString.ToDateTime > tFecha Then
|
|
events.Add(cevent)
|
|
End If
|
|
Else
|
|
|
|
'EMPIEZA METODO PARA AGREGAR CUANDO SI ES RECURRENTE
|
|
|
|
Dim FinRecurrencia = cevent.recurrenciafin.ToEntero
|
|
Dim FI As DateTime, FF As DateTime, FT As DateTime
|
|
Dim DiasSemana = cevent.diassemana.Split(","c)
|
|
FI = cevent.start.ToDateTime
|
|
FF = cevent.end.ToDateTime
|
|
|
|
'OBTENEMOS LA FECHA TERMINO (FT) DE LA RECURRENCIA
|
|
Select Case FinRecurrencia
|
|
Case -1
|
|
FT = DateAdd(DateInterval.Year, 2, dr("FechaInicio").ToString.ToDateTime)
|
|
Case 0
|
|
FT = dr("RecurrenciaFin").ToString.ToDate
|
|
Case Is > 0
|
|
FinRecurrencia -= 1
|
|
Select Case cevent.recurrenciatipo
|
|
Case 1
|
|
FT = DateAdd(DateInterval.Hour, FinRecurrencia * cevent.frecuencia, dr("FechaInicio").ToString.ToDateTime)
|
|
Case 2
|
|
FT = DateAdd(DateInterval.Day, FinRecurrencia * cevent.frecuencia, dr("FechaInicio").ToString.ToDateTime)
|
|
Case 3
|
|
FT = DateAdd(DateInterval.WeekOfYear, FinRecurrencia * cevent.frecuencia, dr("FechaInicio").ToString.ToDateTime)
|
|
FT = DateAdd(DateInterval.Day, (7 - Weekday(FT)).ToString.ToDouble, FT)
|
|
Case 4
|
|
FT = DateAdd(DateInterval.Month, FinRecurrencia * cevent.frecuencia, dr("FechaInicio").ToString.ToDateTime)
|
|
Case 5
|
|
FT = DateAdd(DateInterval.Year, FinRecurrencia * cevent.frecuencia, dr("FechaInicio").ToString.ToDateTime)
|
|
End Select
|
|
End Select
|
|
|
|
'SI ES TIPO SEMANAL Y DIASSEMANA TIENE VALORES CHECKEA ESTOS VALORES
|
|
Do
|
|
If DiasSemana.Length > 0 AndAlso DiasSemana(0) <> "" Then
|
|
For Each drDias As String In DiasSemana
|
|
Dim FIT = FI, FFT = FF
|
|
|
|
FIT = DateAdd(DateInterval.Day, (drDias.ToEntero - Weekday(FI)).ToString.ToDouble, FI)
|
|
FFT = DateAdd(DateInterval.Day, (drDias.ToEntero - Weekday(FF)).ToString.ToDouble, FF)
|
|
|
|
cevent = New CalendarEvent()
|
|
cevent.id = dr("CveEvento").ToString.ToEntero
|
|
cevent.title = dr("Asunto").ToString
|
|
cevent.description = dr("Descripcion").ToString
|
|
cevent.start = String.Format("{0:s}", FIT)
|
|
cevent.end = String.Format("{0:s}", FFT)
|
|
cevent.allDay = False
|
|
cevent.CveEventoEstatus = dr("CveEventoEstatus").ToString.ToEntero
|
|
cevent.cveagendatipo = dr("CveAgendaTipo").ToString
|
|
cevent.prioridad = dr("CvePrioridad").ToString.ToEntero
|
|
cevent.backgroundColor = dr("BackGroundColor").ToString
|
|
|
|
cevent.recurrenciatipo = dr("RecurrenciaTipo").ToString.ToEntero
|
|
cevent.frecuencia = dr("Frecuencia").ToString.ToEntero
|
|
cevent.diassemana = dr("DiasSemana").ToString
|
|
cevent.dia = dr("Dia").ToString.ToEntero
|
|
cevent.mes = dr("Mes").ToString.ToEntero
|
|
cevent.recurrenciafin = dr("RecurrenciaFin").ToString
|
|
cevent.CveProspecto = dr("CveProspecto").ToString.ToEntero
|
|
cevent.Prospecto = dr("Prospecto").ToString
|
|
|
|
'11/05/2018 - Evento Gasto Recurrente
|
|
cevent.CveTipoEvento = dr("CveTipoEvento").ToString.ToEntero
|
|
If cevent.CveTipoEvento = 10 Then
|
|
cevent.Importe = dr("Importe").ToString.ToDouble
|
|
End If
|
|
|
|
If cevent.CveEventoEstatus.ToString.ToEntero = 3 Then
|
|
cevent.backgroundColor = "#1BBC9B"
|
|
End If
|
|
|
|
'SI LA FECHA DEL EVENTO ES MENOR DE 6 MESES DE LA FECHA ACTUAL Y/0 SI LA FECHA INICIAL DE LA RECURRENCIA ES MENOR A LA FECHA QUE SE CREO EL EVENTO NO LO AGREGA
|
|
If FIT > DateAdd(DateInterval.Month, -6, Date.Now) And FIT >= dr("FechaInicio").ToString.ToDateTime Then
|
|
events.Add(cevent)
|
|
End If
|
|
Next
|
|
Else
|
|
cevent = New CalendarEvent()
|
|
cevent.id = dr("CveEvento").ToString.ToEntero
|
|
cevent.title = dr("Asunto").ToString
|
|
cevent.description = dr("Descripcion").ToString
|
|
cevent.start = String.Format("{0:s}", FI)
|
|
cevent.end = String.Format("{0:s}", FF)
|
|
cevent.allDay = False
|
|
cevent.CveEventoEstatus = dr("CveEventoEstatus").ToString.ToEntero
|
|
cevent.cveagendatipo = dr("CveAgendaTipo").ToString
|
|
cevent.prioridad = dr("CvePrioridad").ToString.ToEntero
|
|
cevent.backgroundColor = dr("BackGroundColor").ToString
|
|
|
|
cevent.recurrenciatipo = dr("RecurrenciaTipo").ToString.ToEntero
|
|
cevent.frecuencia = dr("Frecuencia").ToString.ToEntero
|
|
cevent.diassemana = dr("DiasSemana").ToString
|
|
cevent.dia = dr("Dia").ToString.ToEntero
|
|
cevent.mes = dr("Mes").ToString.ToEntero
|
|
cevent.recurrenciafin = dr("RecurrenciaFin").ToString
|
|
cevent.CveProspecto = dr("CveProspecto").ToString.ToEntero
|
|
cevent.Prospecto = dr("Prospecto").ToString
|
|
|
|
'11/05/2018 - Evento Gasto Recurrente
|
|
cevent.CveTipoEvento = dr("CveTipoEvento").ToString.ToEntero
|
|
If cevent.CveTipoEvento = 10 Then
|
|
cevent.Importe = dr("Importe").ToString.ToDouble
|
|
End If
|
|
|
|
If cevent.CveEventoEstatus.ToString.ToEntero = 3 Then
|
|
cevent.backgroundColor = "#1BBC9B"
|
|
End If
|
|
|
|
'SI LA FECHA DEL EVENTO ES MENOR DE 6 MESES DE LA FECHA ACTUAL NO LO AGREGA
|
|
If FI > DateAdd(DateInterval.Month, -6, Date.Now) Then
|
|
events.Add(cevent)
|
|
End If
|
|
End If
|
|
|
|
Select Case cevent.recurrenciatipo
|
|
Case 1
|
|
FI = DateAdd(DateInterval.Hour, cevent.frecuencia, FI)
|
|
FF = DateAdd(DateInterval.Hour, cevent.frecuencia, FF)
|
|
Case 2
|
|
FI = DateAdd(DateInterval.Day, cevent.frecuencia, FI)
|
|
FF = DateAdd(DateInterval.Day, cevent.frecuencia, FF)
|
|
Case 3
|
|
FI = DateAdd(DateInterval.WeekOfYear, cevent.frecuencia, FI)
|
|
FF = DateAdd(DateInterval.WeekOfYear, cevent.frecuencia, FF)
|
|
Case 4
|
|
FI = DateAdd(DateInterval.Month, cevent.frecuencia, FI)
|
|
FF = DateAdd(DateInterval.Month, cevent.frecuencia, FF)
|
|
Case 5
|
|
FI = DateAdd(DateInterval.Year, cevent.frecuencia, FI)
|
|
FF = DateAdd(DateInterval.Year, cevent.frecuencia, FF)
|
|
End Select
|
|
|
|
Loop Until FI > FT
|
|
End If
|
|
Next
|
|
Catch ex As Exception
|
|
GuardaLog(ex.ToString())
|
|
End Try
|
|
End If
|
|
|
|
End If
|
|
ObjEventos.Dispose()
|
|
Return ErrorEventos
|
|
End Function
|
|
|
|
|
|
End Class |