277 lines
11 KiB
VB.net
277 lines
11 KiB
VB.net
Imports System.Data
|
|
Imports System.Linq
|
|
Imports Extensiones
|
|
Imports System.IO
|
|
Imports System.Text.RegularExpressions
|
|
|
|
Partial Class OI_CircularDetalle
|
|
Inherits ClsPaginas
|
|
|
|
Private Property DtUsuarios As DataTable
|
|
Get
|
|
Return If(IsNothing(ViewState("DtUsuarios")), Nothing, CType(ViewState("DtUsuarios"), DataTable))
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtUsuarios") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property CveCircular As Integer
|
|
Get
|
|
Return ViewState("CveCircular").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveCircular") = value
|
|
End Set
|
|
End Property
|
|
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
CargarCve()
|
|
ConfigurarBotones()
|
|
CargaDatos()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargarCve()
|
|
Dim PreCveCircular As String = Request.Params("CveCircular").ToString()
|
|
If IsNumeric(PreCveCircular) Then
|
|
CveCircular = PreCveCircular.ToEntero
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ConfigurarBotones()
|
|
If CveCircular > 0 Then
|
|
BtnGuardar.Text = "Actualizar"
|
|
BtnEliminar.Visible = True
|
|
Else
|
|
BtnGuardar.Text = "Guardar"
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaDatos()
|
|
If CveCircular > 0 Then
|
|
Dim ObjOI As New ClsOIEventos
|
|
If ObjOI.GetCircular(UsuarioActual.CveEmpresa, CveCircular) Then
|
|
Dim Circular As DataRow = ObjOI.DtResultados(0)
|
|
|
|
TxtAsunto.Text = Circular.Item("Asunto")
|
|
TxtCorreo.Value = Circular.Item("CorreosInternos")
|
|
TxtCorreoAdicional.Value = Circular.Item("CorreosExternos")
|
|
TxtCircular.Text = Circular.Item("Circular")
|
|
|
|
If Circular.Item("ArchivoAdjunto") <> "" Then
|
|
archivosDiv.Visible = True
|
|
HkArchivo.NavigateUrl = $"~/Empresas/{UsuarioActual.CveEmpresa}/Formatos/{Circular.Item("ArchivoAdjunto")}"
|
|
HkArchivo.Text = Circular.Item("ArchivoAdjunto")
|
|
End If
|
|
|
|
UpCliente.Update()
|
|
End If
|
|
ObjOI.Dispose()
|
|
End If
|
|
|
|
DdlRolesFiltro.DataSource = GlobalDTRoles(UsuarioActual.CveEmpresa)
|
|
DdlRolesFiltro.DataBind()
|
|
DdlRolesFiltro.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
DdlSucursales.DataSource = GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa)
|
|
DdlSucursales.DataBind()
|
|
DdlSucursales.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
End Sub
|
|
|
|
Private Sub BtnGuardar_Click() Handles BtnGuardar.Click
|
|
Dim ObjOI As New ClsOIEventos
|
|
If CveCircular > 0 Then
|
|
|
|
Dim AdjuntoValidate As String = NombreArchivo().Split("-")(1)
|
|
|
|
If ObjOI.UpdateCircular(CveCircular, TxtAsunto.Text, TxtCircular.Text, TxtCorreo.Value, TxtCorreoAdicional.Value, AdjuntoValidate) Then
|
|
GuardarArchivo(CveCircular)
|
|
Alert("Actualizado correctamente")
|
|
End If
|
|
Else
|
|
Dim CorreoExtra As String = If(TxtCorreoAdicional.Value = "", "-1", TxtCorreoAdicional.Value)
|
|
|
|
Dim AdjuntoValidate As String = NombreArchivo().Split("-")(1)
|
|
Dim CircularInsertado As Integer = ObjOI.AddCircular(TxtAsunto.Text, TxtCircular.Text, TxtCorreo.Value, Today.ToString, UsuarioActual.CveUsuario,
|
|
UsuarioActual.CveEmpresa, CorreoExtra, AdjuntoValidate)
|
|
If CircularInsertado > 0 Then
|
|
GuardarArchivo(CircularInsertado)
|
|
Alert("Ingresado correctamente")
|
|
End If
|
|
End If
|
|
CargaDatos()
|
|
End Sub
|
|
|
|
Private Sub BtnEliminar_Click() Handles BtnEliminar.Click
|
|
Dim ObjOI As New ClsOIEventos
|
|
If ObjOI.DeleteCircular(CveCircular) Then
|
|
Response.Redirect("~/OI/CircularDetalle.aspx?CveCircular=-1")
|
|
End If
|
|
ObjOI.Dispose()
|
|
End Sub
|
|
|
|
Protected Sub LbBuscar_Click(sender As Object, e As EventArgs) Handles LbBuscar.Click
|
|
LimpiarModal()
|
|
RegistraScript("$('#ModalDescuento').modal()")
|
|
End Sub
|
|
|
|
Private Sub LimpiarModal()
|
|
DdlRolesFiltro.SelectedValue = -1
|
|
DdlSucursales.SelectedValue = -1
|
|
GvUsuarios.DataSource = Nothing
|
|
GvUsuarios.DataBind()
|
|
UpUsuarios.Update()
|
|
End Sub
|
|
|
|
Protected Sub BtnBuscar_Click() Handles BtnBuscar.Click
|
|
Dim buscadorQuery As New StringBuilder
|
|
buscadorQuery.Append(If(DdlRolesFiltro.SelectedValue.ToEntero > 0, String.Format("CveRol = {0}", DdlRolesFiltro.SelectedValue), ""))
|
|
buscadorQuery.Append(If(DdlSucursales.SelectedValue.ToEntero > 0, String.Format("{0} CveSubProyecto = {1}", If(buscadorQuery.Length > 0, "AND", ""), DdlSucursales.SelectedValue), ""))
|
|
GvUsuarios.DataSource = GlobalDTUsuarios(CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros(buscadorQuery.ToString)
|
|
DtUsuarios = GlobalDTUsuarios(CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros(buscadorQuery.ToString)
|
|
GvUsuarios.DataBind()
|
|
UpUsuarios.Update()
|
|
RegistraScript("$('#ModalDescuento').modal()")
|
|
End Sub
|
|
|
|
Private Sub BtnAplicarDescG_Click() Handles BtnAplicarDescG.Click
|
|
Dim UsuariosCorreos As String = ""
|
|
For Each usuario As DataRow In DtUsuarios.Rows
|
|
If usuario.Item("Correo").ToString.Length > 0 Then
|
|
UsuariosCorreos = String.Format("{0}{1}" & Environment.NewLine, UsuariosCorreos, usuario.Item("Correo").ToString)
|
|
End If
|
|
Next
|
|
TxtCorreo.Value = UsuariosCorreos
|
|
RegistraScript("$('#ModalDescuento').modal('hide')")
|
|
UpCliente.Update()
|
|
End Sub
|
|
|
|
Private Function NombreArchivo() As String
|
|
Dim Filesgral As List(Of Archivo) = TxtFileDocumentacion.getfiles().Archivos
|
|
Dim Filename As String = "-1"
|
|
For Each fileItem As Archivo In Filesgral
|
|
Try
|
|
Filename = fileItem.filename
|
|
Catch ex As Exception
|
|
Filename = "-1"
|
|
End Try
|
|
Next
|
|
Return Filename
|
|
End Function
|
|
|
|
Private Function TituloAnterior() As String
|
|
Dim Directorio As New IO.DirectoryInfo(String.Format("{0}Empresas/{1}/Formatos/", ModExtensiones.DirectorioBaseEmpresas, UsuarioActual.CveEmpresa))
|
|
Dim ArchivosArreglo As IO.FileInfo() = Directorio.GetFiles()
|
|
Dim patronRegEx As String = String.Format("^{0}_.*", CveCircular)
|
|
Dim archivoEncontrado As String = ""
|
|
For Each file As IO.FileInfo In ArchivosArreglo
|
|
If Regex.IsMatch(file.Name, patronRegEx) Then
|
|
archivoEncontrado = file.Name
|
|
End If
|
|
Next
|
|
Return archivoEncontrado
|
|
End Function
|
|
|
|
Private Function GuardarArchivo(CircularInsertado As Integer) As String
|
|
|
|
Dim respuesta As String = ""
|
|
Dim FileExtension As String = "-1"
|
|
Dim Filesgral As List(Of Archivo) = TxtFileDocumentacion.getfiles().Archivos
|
|
Dim Filename As String = ""
|
|
|
|
For Each fileItem As Archivo In Filesgral
|
|
Try
|
|
respuesta = fileItem.filenameO
|
|
FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "")
|
|
Dim tempArray() As String
|
|
tempArray = fileItem.filename.ToString().Split("-".ToCharArray())
|
|
|
|
Dim rutaDestino As String = UsuarioActual.Empresa.Ruta & "Formatos\" & CircularInsertado & "_" & fileItem.filenameO
|
|
|
|
Dim ArchivoAnterior As String = TituloAnterior()
|
|
|
|
If ArchivoAnterior.Length > 0 Then
|
|
Dim docAnterior As String = String.Format("{0}Formatos\{1}", UsuarioActual.Empresa.Ruta, ArchivoAnterior)
|
|
If File.Exists(docAnterior) Then
|
|
File.Delete(docAnterior)
|
|
End If
|
|
End If
|
|
|
|
If Not Directory.Exists(UsuarioActual.Empresa.Ruta & "\Formatos") Then
|
|
Directory.CreateDirectory(UsuarioActual.Empresa.Ruta & "\Formatos")
|
|
|
|
End If
|
|
|
|
If System.IO.File.Exists(rutaDestino) Then
|
|
System.IO.File.Delete(rutaDestino)
|
|
End If
|
|
|
|
System.IO.File.Move(fileItem.FileUrl, rutaDestino)
|
|
|
|
Catch ex As Exception
|
|
OnError("Error al cargar archivo", ex)
|
|
End Try
|
|
TxtFileDocumentacion.Text = ""
|
|
Next
|
|
|
|
|
|
Return respuesta
|
|
End Function
|
|
|
|
Protected Sub LnkMandarCorreo_Click() Handles LnkMandarCorreo.Click
|
|
Dim correos() As String
|
|
correos = TxtCorreo.Value.Split(Environment.NewLine)
|
|
Dim ArchivoBytes As Byte() = ArchivoBytesArrya(HkArchivo.Text)
|
|
|
|
Dim Contador As Integer = 0
|
|
Try
|
|
For Each Correo As String In correos
|
|
MandaCorreo(TxtAsunto.Text, Correo, If(Contador > 0, "", TxtCorreoAdicional.Value), TxtCircular.Text, ArchivoBytes, HkArchivo.Text)
|
|
Contador += 1
|
|
Next
|
|
Alert("El correo se envió correctamente")
|
|
Catch ex As Exception
|
|
Alert("Error al enviar correo", TipoMensaje.MsgError)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub MandaCorreo(Asunto As String, Para As String, ArrayCC As String, body As String, ArchivoBinario As Byte(), NombreArchivo As String)
|
|
|
|
Dim a As String = String.Format("{0} -- {1} --- {2}", Asunto, Para, ArrayCC)
|
|
a.GuardaLog()
|
|
|
|
Dim Mail As New ClsSisMail()
|
|
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
|
|
Dim itemMail As New ClsSisMail.ArchivoMail
|
|
|
|
With itemMail
|
|
itemMail.ArchivoBinario = ArchivoBinario
|
|
itemMail.NombreArchivo = NombreArchivo
|
|
|
|
End With
|
|
|
|
LSRutasMail.Add(itemMail)
|
|
|
|
|
|
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, body, ArrayCC, LSRutasMail)
|
|
Mail = Nothing
|
|
End Sub
|
|
|
|
Private Function ArchivoBytesArrya(ArchivoNombre As String) As Byte()
|
|
Dim ArchivoEnviar As String = String.Format("{0}Formatos\{1}", UsuarioActual.Empresa.Ruta, ArchivoNombre)
|
|
If File.Exists(ArchivoEnviar) Then
|
|
Dim fs As System.IO.FileStream = System.IO.File.Open(ArchivoEnviar, IO.FileMode.Open, IO.FileAccess.Read)
|
|
Dim buff(fs.Length) As Byte
|
|
If fs.Length > 0 Then
|
|
fs.Read(buff, 0, fs.Length - 1)
|
|
fs.Close()
|
|
End If
|
|
Return buff
|
|
End If
|
|
|
|
Return New Byte() {}
|
|
End Function
|
|
End Class
|