Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Partial Class Bancos_NotificacionCheques
Inherits ClsPaginas
#Region "Propiedades"
Private Property DtPorNotificar As DataTable
Get
DtPorNotificar = DirectCast(ViewState("DtPorNotificar"), DataTable)
End Get
Set(ByVal value As DataTable)
ViewState("DtPorNotificar") = value
End Set
End Property
Private Property DtPorEntregar As DataTable
Get
DtPorEntregar = DirectCast(ViewState("DtPorEntregar"), DataTable)
End Get
Set(ByVal value As DataTable)
ViewState("DtPorEntregar") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
txtFechaI.Text = NowADS().AddMonths(-1).FirstDayOfMonth.ToShortDateString
txtFechaF.Text = NowADS().ToShortDateString
CargaTipoTransaccion("Egs")
CargaPorNotificar()
CargaPorEntregar()
End If
End Sub
Private Sub CargaTipoTransaccion(Tipo As String)
DdlTipoTransaccion.Items.Clear()
If Tipo <> "" And Tipo <> "-1" Then
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros(String.Format("CveTipoTransaccion IN (1,2) AND Tipo = '{0}' ", Tipo))
DdlTipoTransaccion.DataBind()
Else
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones
DdlTipoTransaccion.DataBind()
End If
DdlTipoTransaccion.Items.Insert(0, New ListItem("Todos", "-1"))
End Sub
'Private Sub CreaDTPorNotificar()
' DtPorNotificar = New DataTable
' DtPorNotificar.Columns.Add("Folio", GetType(String))
' DtPorNotificar.Columns.Add("FechaDocumento", GetType(DateTime))
' DtPorNotificar.Columns.Add("Banco", GetType(String))
' DtPorNotificar.Columns.Add("PagueseA", GetType(String))
' DtPorNotificar.Columns.Add("ProvCorreo", GetType(String))
' DtPorNotificar.Columns.Add("ProvTelefono", GetType(String))
' DtPorNotificar.Columns.Add("RHCorreo", GetType(String))
' DtPorNotificar.Columns.Add("RHTelefono", GetType(String))
' DtPorNotificar.Columns.Add("Importe", GetType(Decimal))
' DtPorNotificar.Columns.Add("CveIE", GetType(Integer))
' DtPorNotificar.Columns.Add("CveProveedor", GetType(Integer))
' DtPorNotificar.Columns.Add("CvePersonal", GetType(Integer))
'End Sub
Protected Sub CargaPorNotificar()
Dim objIE As New ClsBancos
If objIE.GetBancosIENotificaciones(txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, -1, If(TxtPagueseA.Text.Trim <> "", TxtPagueseA.Text.Trim & "%", "-1"), DdlCorreo.SelectedValue.ToEntero, 0, UsuarioActual.CveEmpresa) Then
DtPorNotificar = objIE.DtResultados
End If
objIE.Dispose()
CargaGridPorNotificar()
End Sub
Protected Sub CargaGridPorNotificar()
GvPorNotificar.DataSource = DtPorNotificar
GvPorNotificar.DataBind()
uppPorNotificar.Update()
End Sub
Protected Sub CargaPorEntregar()
Dim objIE As New ClsBancos
If objIE.GetBancosIENotificaciones(txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, 1, If(TxtPagueseA.Text.Trim <> "", TxtPagueseA.Text.Trim & "%", "-1"), DdlCorreo.SelectedValue.ToEntero, 1, UsuarioActual.CveEmpresa) Then
DtPorEntregar = objIE.DtResultados
End If
objIE.Dispose()
CargaGridPorEntregar()
End Sub
Protected Sub CargaGridPorEntregar()
gvPorEntregar.DataSource = DtPorEntregar
gvPorEntregar.DataBind()
uppPorEntregar.Update()
End Sub
Protected Sub GvPorEntregar_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles gvPorEntregar.RowCancelingEdit
gvPorEntregar.EditIndex = -1
CargaGridPorEntregar()
End Sub
Protected Sub GvPorNotificar_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvPorNotificar.RowEditing
GvPorNotificar.EditIndex = e.NewEditIndex
CargaGridPorNotificar()
End Sub
Protected Sub GvPorEntregar_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles gvPorEntregar.RowEditing
gvPorEntregar.EditIndex = e.NewEditIndex
CargaGridPorEntregar()
End Sub
Protected Sub GvPorNotificar_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvPorNotificar.RowUpdating
'ACTUALIZAR EL CORREO DEL PROVEEDOR o RH
Dim ActualizoA As String = ""
Dim Correo As String = GvPorNotificar.Rows(e.RowIndex).FCTextBox("txtCorreo").Text
If Not IsDBNull(GvPorNotificar.Rows(e.RowIndex).DataKey("CveProveedor")) AndAlso GvPorNotificar.Rows(e.RowIndex).DataKey("CveProveedor").ToEntero > 0 Then
'Actualizar a el Proveedor
ActualizoA = "PROV"
'Dim objProv As New ClsCompProveedores
'If objProv.UpdateProveedor(
'objProv.Dispose()
ElseIf Not IsDBNull(GvPorNotificar.Rows(e.RowIndex).DataKey("CvePersonal")) AndAlso GvPorNotificar.Rows(e.RowIndex).DataKey("CvePersonal").ToEntero > 0 Then
ActualizoA = "RH"
' e.Row.FCLiteral("ltlCorreo").Text = e.Row.DBCampo("RHCorreo").ToString
' e.Row.FCLiteral("ltlTelefono").Text = e.Row.DBCampo("RHTelefono").ToString
End If
Dim dr As DataRow() = DtPorNotificar.Select("CveIE = " & GvPorNotificar.Rows(e.RowIndex).DataKey("CveIE").ToString.ToEntero)
'Dim totalanterior As Double = dr(0)("Total").ToString.ToDouble
If ActualizoA = "PROV" Then
dr(0)("ProvCorreo") = Correo
Else
dr(0)("RHCorreo") = Correo
End If
DtPorNotificar.AcceptChanges()
GvPorNotificar.EditIndex = -1
CargaGridPorNotificar()
End Sub
Protected Sub GvPorNotificar_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvPorNotificar.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ProvRH As String = ""
If Not IsDBNull(e.Row.DBCampo("CveProveedor")) AndAlso e.Row.DBCampo("CveProveedor").ToEntero > 0 Then
ProvRH = "PROV"
ElseIf Not IsDBNull(e.Row.DBCampo("CvePersonal")) AndAlso e.Row.DBCampo("CvePersonal").ToEntero > 0 Then
ProvRH = "RH"
Else
ProvRH = ""
End If
If ProvRH = "PROV" Then
e.Row.FCTextBox("txtCorreo").Text = e.Row.DBCampo("ProvCorreo").ToString
e.Row.FCLiteral("ltlTelefono").Text = e.Row.DBCampo("ProvTelefono").ToString
e.Row.FCHyperLink("HLPagueseA").NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", e.Row.DBCampo("CveProveedor"))
ElseIf ProvRH = "RH" Then
e.Row.FCTextBox("txtCorreo").Text = e.Row.DBCampo("RHCorreo").ToString
e.Row.FCLiteral("ltlTelefono").Text = e.Row.DBCampo("RHTelefono").ToString
e.Row.FCHyperLink("HLPagueseA").NavigateUrl = String.Format("/RH/Personal.aspx?CvePersonal={0}", e.Row.DBCampo("CvePersonal"))
Else
e.Row.FCCheckBox("chkNotificar").Enabled = False
e.Row.FCHyperLink("HLPagueseA").Enabled = False
End If
If e.Row.DBCampo("Comprobante") <> "" Then
e.Row.FCHyperLink("HLComprobante").Visible = True
e.Row.FCHyperLink("HLComprobante").NavigateUrl = String.Format("\Empresas\{0}\IE\{1}", UsuarioActual.CveEmpresa, e.Row.DBCampo("Comprobante"))
End If
End If
End Sub
Protected Sub GvPorEntregar_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvPorEntregar.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Not IsDBNull(e.Row.DBCampo("CveProveedor")) AndAlso e.Row.DBCampo("CveProveedor").ToEntero > 0 Then
e.Row.FCLiteral("ltlCorreo").Text = e.Row.DBCampo("ProvCorreo").ToString
e.Row.FCLiteral("ltlTelefono").Text = e.Row.DBCampo("ProvTelefono").ToString
ElseIf Not IsDBNull(e.Row.DBCampo("CvePersonal")) AndAlso e.Row.DBCampo("CvePersonal").ToEntero > 0 Then
e.Row.FCLiteral("ltlCorreo").Text = e.Row.DBCampo("RHCorreo").ToString
e.Row.FCLiteral("ltlTelefono").Text = e.Row.DBCampo("RHTelefono").ToString
Else
e.Row.FCImageButton("ibNotificarDeNuevo").Enabled = False
End If
End If
End Sub
Protected Sub btnPorNotificar_Click(sender As Object, e As EventArgs) Handles btnPorNotificar.Click
For Each Row As GridViewRow In GvPorNotificar.Rows
If Row.FCCheckBox("chkNotificar").Checked = True Then
Dim Param As New List(Of String)
Param.Add(Row.FCTextBox("txtCorreo").Text) 'Para
'Param.Add("jonaslopez@gmail.com") 'Para
Param.Add("Notificación de Pago") 'Asunto
Param.Add(GeneraCorreo(Row.DataKey("CveIE").ToEntero)) 'Body
Param.Add(Row.DataKey("CveIE").ToString) 'CveIE
Param.Add(Row.DataKey("CveTipoTransaccion").ToString) 'CveIE
Param.Add(If(Row.DataKey("Comprobante").ToString <> "", String.Format("{0}IE\{1}", UsuarioActual.Empresa.Ruta, Row.DataKey("Comprobante").ToString), "")) 'Archivo Adjunto
Dim Hilo As New Threading.Thread(AddressOf MandaCorreo)
Hilo.Start(Param)
End If
Next
Threading.Thread.Sleep(4000)
Alert("Se notificará a los beneficiarios seleccionados", TipoMensaje.MsgInformacion)
CargaPorNotificar()
CargaPorEntregar()
End Sub
Private Sub MandaCorreo(data As Object)
Dim Parametros As List(Of String) = DirectCast(data, List(Of String))
Dim Mail As New ClsSisMail()
Dim Para As String = Parametros(0)
Dim Asunto As String = Parametros(1)
Dim Body As String = Parametros(2)
Dim CveIE As Integer = Parametros(3).ToEntero
Dim CveTipoTransaccion As Integer = If(Parametros(4) IsNot Nothing, Parametros(4).ToEntero, 0)
'Dim Estatus As Integer = 1 If(CveTipoTransaccion = 2, 2, 1) ' cuando es transferencia, no lo pasa por entregar
'Dim ArrayAttachment As New List(Of String)
Dim ListaArchivos As New List(Of ClsSisMail.ArchivoMail)
If Parametros(5) IsNot Nothing AndAlso Parametros(5) <> "" Then
' ArrayAttachment.Add(Parametros(5).ToString)
ListaArchivos.Add(New ClsSisMail.ArchivoMail With {.Ruta = Parametros(5).ToString})
End If
If Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, Archivos:=ListaArchivos) Then
Dim objIE As New ClsBancos
objIE.UpdateBancos_IENotificaciones(1, "-1", "-1", CveIE)
objIE.Dispose()
End If
'If Mail.Mandacorreo(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayAttachment:=ArrayAttachment) Then
' Dim objIE As New ClsBancos
' objIE.UpdateBancos_IENotificaciones(1, "-1", "-1", CveIE)
' objIE.Dispose()
'End If
End Sub
Private Function GeneraCorreo(CveIE As Integer) As String
Dim strBody As New StringBuilder
Dim objIE As New ClsBancos
If objIE.GetBancosIE(CveIE, UsuarioActual.CveEmpresa) Then
strBody.Append(" ")
strBody.Append("
")
strBody.Append("")
End If
objIE.Dispose()
Return strBody.ToString
End Function
Protected Sub ibNotificarDeNuevo_Click(sender As Object, e As ImageClickEventArgs)
Dim ibtn As ImageButton = DirectCast(sender, ImageButton)
Dim gvr As GridViewRow = DirectCast(ibtn.NamingContainer, GridViewRow)
Dim Param As New List(Of String)
Param.Add(gvr.FCLiteral("LtlCorreo").Text) 'Para
'Param.Add("jonaslopez@gmail.com") 'Para
Param.Add("Notificaciones de pago") 'Asunto
Param.Add(GeneraCorreo(gvr.DataKey("CveIE").ToEntero)) 'Body
Param.Add(gvr.DataKey("CveIE").ToString) 'CveIE
Dim Hilo As New Threading.Thread(AddressOf MandaCorreo)
Hilo.Start(Param)
' Alert(String.Format("Se Notificara a el correo {0}", Param(0)))
End Sub
Protected Sub ibEntregar_Click(sender As Object, e As ImageClickEventArgs)
Dim ibtn As ImageButton = DirectCast(sender, ImageButton)
Dim gvr As GridViewRow = DirectCast(ibtn.NamingContainer, GridViewRow)
Dim objIE As New ClsBancos
If objIE.UpdateBancos_IENotificaciones(2, NowADS().ToString("dd/MM/yyyy"), gvr.FCTextBox("txtObservacionEntrega").Text, gvr.DataKey("CveIE").ToEntero) Then
Alert("Cheque marcado como Entregado")
End If
objIE.Dispose()
gvPorEntregar.EditIndex = -1
CargaPorEntregar()
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
CargaPorNotificar()
CargaPorEntregar()
End Sub
End Class