Agregar archivos de proyecto.
This commit is contained in:
410
GestionGrupoSanchoToro/Comun.vb
Normal file
410
GestionGrupoSanchoToro/Comun.vb
Normal file
@@ -0,0 +1,410 @@
|
||||
Imports bdGrupoSanchoToro
|
||||
Imports bdGrupoSanchoToro.db
|
||||
Imports bdGrupoSanchoToro.db.Utilidades
|
||||
Imports DevExpress.Xpf.Docking
|
||||
Imports DevExpress.XtraReports.UI
|
||||
Imports System.IO
|
||||
Imports DevExpress.Xpf.Printing
|
||||
Imports DevExpress.Xpf.Core
|
||||
Imports tsWPFCore
|
||||
Imports tsUtilidades
|
||||
Imports System.Data.Entity
|
||||
|
||||
Imports DevExpress.Xpf.Editors
|
||||
|
||||
'TODO No permitir 2 facturas rápidas al mismo tiempo
|
||||
'TODO Traspaso a otra caja
|
||||
'TODO Seleccion cajas en conciliación bancaria
|
||||
|
||||
Public Class Comun
|
||||
|
||||
Friend Shared OtrosParametros As String = ""
|
||||
Public Shared Property dwi As DXWindow
|
||||
Public Shared Property dg As DocumentGroup
|
||||
Public Shared Sub EscalaVentana(ByRef Ventana As Window, ByRef tr As Transform)
|
||||
If UsuarioActual.Escala.HasValue AndAlso UsuarioActual.Escala Then
|
||||
Ventana.Height = Math.Min(Comun.dwi.Height, Ventana.Height * UsuarioActual.Escala.Value)
|
||||
Ventana.Width = Math.Min(Comun.dwi.Width, Ventana.Width * UsuarioActual.Escala.Value)
|
||||
Dim scaler = TryCast(tr, ScaleTransform)
|
||||
If scaler Is Nothing Then
|
||||
scaler = New ScaleTransform(1.0, 1.0)
|
||||
tr = scaler
|
||||
End If
|
||||
scaler.ScaleX = UsuarioActual.Escala.Value
|
||||
scaler.ScaleY = UsuarioActual.Escala.Value
|
||||
scaler.BeginAnimation(ScaleTransform.ScaleXProperty, Nothing)
|
||||
scaler.BeginAnimation(ScaleTransform.ScaleYProperty, Nothing)
|
||||
End If
|
||||
End Sub
|
||||
Public Shared Function ObtienePermisos(bd As tscGrupoSanchoToro, Codigo As String, idUsuario As Integer) As tsUtilidades.Permisos
|
||||
Dim per As New tsUtilidades.Permisos
|
||||
If bd.usuarios.First(Function(x) x.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario).idGrupoNavigation.Descripcion = "SUPERADMINISTRADORES" Then
|
||||
per.Consultar = True
|
||||
per.Eliminar = True
|
||||
per.Nuevos = True
|
||||
per.Otros = True
|
||||
per.Modificar = True
|
||||
per.Impresion = True
|
||||
per.Exportar = True
|
||||
Else
|
||||
Dim au = (From a In bd.autorizacionesusuarios Select a Where a.idPermisoNavigation.CodigoPermiso = Codigo AndAlso a.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario)
|
||||
If au.Count = 0 Then
|
||||
Dim idGrupo As Integer = (From u In bd.usuarios Select u Where u.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario).First.idGrupo.Value
|
||||
Dim ag = (From g In bd.autorizacionesgrupos Select g Where g.idPermisoNavigation.CodigoPermiso = Codigo AndAlso g.idGrupo = idGrupo)
|
||||
If ag.Count = 0 Then
|
||||
per.Consultar = False
|
||||
per.Eliminar = False
|
||||
per.Nuevos = False
|
||||
per.Otros = False
|
||||
per.Modificar = False
|
||||
per.Impresion = False
|
||||
per.Exportar = False
|
||||
Else
|
||||
per.Consultar = ag.First.PermitirConsultas
|
||||
per.Eliminar = ag.First.PermitirEliminaciones
|
||||
per.Nuevos = ag.First.PermitirNuevos
|
||||
per.Otros = ag.First.OtrosPermisos
|
||||
per.Modificar = ag.First.PermitirModificaciones
|
||||
per.Impresion = ag.First.PermitirImpresiones
|
||||
per.Exportar = ag.First.PermitirImpresiones
|
||||
End If
|
||||
Else
|
||||
per.Consultar = au.First.PermitirConsultas
|
||||
per.Eliminar = au.First.PermitirEliminaciones
|
||||
per.Nuevos = au.First.PermitirNuevos
|
||||
per.Otros = au.First.OtrosPermisos
|
||||
per.Modificar = au.First.PermitirModificaciones
|
||||
per.Impresion = au.First.PermitirImpresiones
|
||||
per.Exportar = au.First.PermitirExportar
|
||||
End If
|
||||
End If
|
||||
'If Not bdga.DataBase.ToLower.Contains("GrupoSanchoToro") AndAlso Not bdga.DataBase.ToLower.Contains("desarrollo") AndAlso Not bdga.DataBase.ToLower.Contains("viernes") Then
|
||||
' per.Modificar = False
|
||||
' per.Nuevos = False
|
||||
'End If
|
||||
|
||||
Return per
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Public Shared Function ObtienePermisos(bd As tscGrupoSanchoToro, idPermiso As Nullable(Of Integer), idUsuario As Integer) As tsUtilidades.Permisos
|
||||
Dim per As New tsUtilidades.Permisos
|
||||
If bd.usuarios.First(Function(x) x.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario).Usuario = "MANMOG" Then
|
||||
per.Consultar = True
|
||||
per.Eliminar = True
|
||||
per.Nuevos = True
|
||||
per.Otros = True
|
||||
per.Modificar = True
|
||||
per.Impresion = True
|
||||
per.Exportar = True
|
||||
Else
|
||||
If idPermiso Is Nothing Then
|
||||
per.Consultar = False
|
||||
per.Eliminar = False
|
||||
per.Nuevos = False
|
||||
per.Otros = False
|
||||
per.Modificar = False
|
||||
per.Impresion = False
|
||||
per.Exportar = False
|
||||
Else
|
||||
Dim au = (From a In bd.autorizacionesusuarios Select a Where a.idPermisoNavigation.idPermiso = idPermiso AndAlso a.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario)
|
||||
If au.Count = 0 Then
|
||||
Dim idGrupo As Integer = (From u In bd.usuarios Select u Where u.idUsuario = bdGrupoSanchoToro.db.Utilidades.idUsuario).First.idGrupo.Value
|
||||
Dim ag = (From g In bd.autorizacionesgrupos Select g Where g.idPermisoNavigation.idPermiso = idPermiso AndAlso g.idGrupo = idGrupo)
|
||||
If ag.Count = 0 Then
|
||||
per.Consultar = False
|
||||
per.Eliminar = False
|
||||
per.Nuevos = False
|
||||
per.Otros = False
|
||||
per.Modificar = False
|
||||
per.Impresion = False
|
||||
per.Exportar = False
|
||||
Else
|
||||
per.Consultar = ag.First.PermitirConsultas
|
||||
per.Eliminar = ag.First.PermitirEliminaciones
|
||||
per.Nuevos = ag.First.PermitirNuevos
|
||||
per.Otros = ag.First.OtrosPermisos
|
||||
per.Modificar = ag.First.PermitirModificaciones
|
||||
per.Impresion = ag.First.PermitirImpresiones
|
||||
per.Exportar = ag.First.PermitirImpresiones 'ag.First.PermitirExportar
|
||||
End If
|
||||
Else
|
||||
per.Consultar = au.First.PermitirConsultas
|
||||
per.Eliminar = au.First.PermitirEliminaciones
|
||||
per.Nuevos = au.First.PermitirNuevos
|
||||
per.Otros = au.First.OtrosPermisos
|
||||
per.Modificar = au.First.PermitirModificaciones
|
||||
per.Impresion = au.First.PermitirImpresiones
|
||||
per.Exportar = au.First.PermitirImpresiones
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Return per
|
||||
End Function
|
||||
Friend Shared Function ObtienePlantillas(bd As tscGrupoSanchoToro, Grupo As String, Optional IncluirTipoListado As Boolean = True) As List(Of tsWPFCore.Plantilla)
|
||||
Dim plas As IQueryable(Of plantillas)
|
||||
If Not IncluirTipoListado Then
|
||||
plas = (From p In bd.plantillas Where p.idEmpresa = EmpresaActual.idEmpresa AndAlso p.idGrupoNavigation.Codigo = Grupo AndAlso p.TipoListado = False Select p)
|
||||
Else
|
||||
plas = (From p In bd.plantillas Where p.idEmpresa = EmpresaActual.idEmpresa AndAlso p.idGrupoNavigation.Codigo = Grupo Select p)
|
||||
End If
|
||||
Dim plantillas As New List(Of tsWPFCore.Plantilla)
|
||||
For Each p In plas
|
||||
Dim pl As New tsWPFCore.Plantilla
|
||||
pl.idPlantilla = p.idPlantilla
|
||||
pl.Descripcion = p.Descripcion
|
||||
plantillas.Add(pl)
|
||||
Next
|
||||
Return plantillas
|
||||
End Function
|
||||
Friend Shared Function ObtienePlantillas(bd As tscGrupoSanchoToro, Grupos() As String, Optional IncluirTipoListado As Boolean = True) As List(Of tsWPFCore.Plantilla)
|
||||
Dim plas As List(Of plantillas)
|
||||
If Not IncluirTipoListado Then
|
||||
plas = (From p In bd.plantillas Where p.TipoListado = False AndAlso p.Oculta = False Order By p.Orden Select p).ToList
|
||||
Else
|
||||
plas = (From p In bd.plantillas Where p.Oculta = False Order By p.Orden Select p).ToList
|
||||
End If
|
||||
Dim plantillas As New List(Of tsWPFCore.Plantilla)
|
||||
For Each p In plas
|
||||
If Grupos.Contains(p.idGrupoNavigation.Codigo) Then
|
||||
If Not p.idPermiso.HasValue OrElse ObtienePermisos(bd, p.idPermisoNavigation.CodigoPermiso, idUsuario).Impresion Then
|
||||
Dim pl As New tsWPFCore.Plantilla
|
||||
pl.idPlantilla = p.idPlantilla
|
||||
pl.Descripcion = p.Descripcion
|
||||
plantillas.Add(pl)
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
Return plantillas
|
||||
End Function
|
||||
Friend Shared Function ObtienePlantillasPorCodigos(bd As tscGrupoSanchoToro, Codigos() As String, Optional IncluirTipoListado As Boolean = True) As List(Of tsWPFCore.Plantilla)
|
||||
Dim plas As List(Of plantillas)
|
||||
If Not IncluirTipoListado Then
|
||||
plas = (From p In bd.plantillas Where p.idEmpresa = EmpresaActual.idEmpresa AndAlso p.TipoListado = False AndAlso p.Oculta = False Order By p.Orden Select p).ToList
|
||||
Else
|
||||
plas = (From p In bd.plantillas Where p.idEmpresa = EmpresaActual.idEmpresa AndAlso p.Oculta = False Order By p.Orden Select p).ToList
|
||||
End If
|
||||
Dim plantillas As New List(Of tsWPFCore.Plantilla)
|
||||
plas = plas.Where(Function(x) Codigos.Contains(x.Codigo) AndAlso (x.idPermisoNavigation Is Nothing OrElse ObtienePermisos(bd, x.idPermisoNavigation.CodigoPermiso, idUsuario).Impresion)).ToList
|
||||
For Each p In plas
|
||||
Dim pl As New tsWPFCore.Plantilla
|
||||
pl.idPlantilla = p.idPlantilla
|
||||
pl.Descripcion = p.Descripcion
|
||||
plantillas.Add(pl)
|
||||
Next
|
||||
Return plantillas
|
||||
End Function
|
||||
'Friend Shared Sub MuestraImpresos(bd As tscGrupoSanchoToro, idPlantilla As Integer, Datasource As Object, GrupoDocumentos As DocumentGroup, dc As DockController)
|
||||
' Try
|
||||
|
||||
' If idPlantilla = 0 Then Throw New Exception("Seleccione primero la plantilla a imprimir")
|
||||
' Dim xr As New XtraReport
|
||||
|
||||
' Dim qr As ObjectSet(Of plantillas) = bd.plantillas
|
||||
' ' qr.MergeOption = MergeOption.OverwriteChanges
|
||||
|
||||
' Dim pl = qr.Where(Function(x) x.idPlantilla = idPlantilla).First
|
||||
|
||||
' 'Dim pl As plantillas = (From p In bd.plantillas Where p.idPlantilla = idPlantilla).First
|
||||
' Dim s As String = System.Text.Encoding.UTF8.GetString(pl.idFicheroNavigation.Fichero)
|
||||
' Using sw As New StreamWriter(New MemoryStream())
|
||||
' sw.Write(s)
|
||||
' sw.Flush()
|
||||
' xr = XtraReport.FromStream(sw.BaseStream, True)
|
||||
' End Using
|
||||
' Try
|
||||
' Dim pr As DevExpress.XtraReports.Parameters.Parameter = (From p As DevExpress.XtraReports.Parameters.Parameter In xr.Parameters Where p.Name = "Fecha").First
|
||||
' pr.Value = Now
|
||||
' pr.Visible = False
|
||||
' Catch ex As Exception
|
||||
|
||||
' End Try
|
||||
|
||||
' Select Case Datasource.GetType
|
||||
' 'Case GetType(personas), GetType(List(Of personas))
|
||||
' ' If Datasource.GetType = GetType(personas) Then
|
||||
' ' Dim lp As New List(Of personas)
|
||||
' ' Dim per As personas = Datasource
|
||||
' ' lp.Add(per)
|
||||
' ' Datasource = lp
|
||||
' ' End If
|
||||
' ' If pl.enumeraciones.Codigo = "GRUPLA.TARJETAVERTICAL" Then
|
||||
' ' Dim ltvd As New List(Of TarjetaVerticalDiputado)
|
||||
' ' Dim iNumPer As Integer
|
||||
' ' Dim tvd As TarjetaVerticalDiputado = Nothing
|
||||
|
||||
' ' For Each p In DirectCast(Datasource, List(Of personas))
|
||||
' ' iNumPer += 1
|
||||
' ' If iNumPer Mod 2 = 1 Then
|
||||
' ' tvd = New TarjetaVerticalDiputado
|
||||
' ' With tvd
|
||||
' ' .Dni1 = p.NIF
|
||||
' ' If p.idFicheroFoto IsNot Nothing AndAlso p.idFicheroNavigation.Fichero IsNot Nothing AndAlso p.idFicheroNavigation.Fichero.Length > 0 Then
|
||||
' ' Dim original = System.Drawing.Image.FromStream(New IO.MemoryStream(p.idFicheroNavigation.Fichero))
|
||||
' ' original.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone)
|
||||
' ' Dim memStream As IO.MemoryStream = New IO.MemoryStream()
|
||||
' ' original.Save(memStream, ImageFormat.Png)
|
||||
' ' .Foto1 = memStream.ToArray
|
||||
' ' End If
|
||||
' ' .Nombre1 = p.Nombre & " " & p.Apellidos
|
||||
' ' .PuestoEnTarjeta1 = p.PuestoTrabajoEnTarjeta
|
||||
' ' .Tratamiento1 = p.Tratamiento
|
||||
' ' End With
|
||||
' ' ltvd.Add(tvd)
|
||||
' ' Else
|
||||
' ' With tvd
|
||||
' ' .Dni2 = p.NIF
|
||||
' ' If p.idFicheroFoto IsNot Nothing AndAlso p.idFicheroNavigation.Fichero.Length > 0 Then
|
||||
' ' Dim original = System.Drawing.Image.FromStream(New IO.MemoryStream(p.idFicheroNavigation.Fichero))
|
||||
' ' original.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone)
|
||||
' ' Dim memStream As IO.MemoryStream = New IO.MemoryStream()
|
||||
' ' original.Save(memStream, ImageFormat.Png)
|
||||
' ' .Foto2 = memStream.ToArray
|
||||
' ' End If
|
||||
' ' .Nombre2 = p.Nombre & " " & p.Apellidos
|
||||
' ' .PuestoEnTarjeta2 = p.PuestoTrabajoEnTarjeta
|
||||
' ' .Tratamiento2 = p.Tratamiento
|
||||
' ' End With
|
||||
' ' End If
|
||||
' ' Next
|
||||
' ' Datasource = ltvd
|
||||
' ' End If
|
||||
' End Select
|
||||
|
||||
|
||||
' xr.DataSource = Datasource
|
||||
' Dim modelo As New XtraReportPreviewModel(xr)
|
||||
|
||||
' Dim vi As New tsWPFCore.ucVisualizadorInformes
|
||||
' vi.Visualizador.Model = modelo
|
||||
' xr.CreateDocument(True)
|
||||
|
||||
' 'If pl.Codigo = "TARDIPVER" Then
|
||||
|
||||
' ' Dim original = System.Drawing.Image.FromStream(New IO.MemoryStream(Per.idFicheroNavigation.Fichero))
|
||||
' ' original.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone)
|
||||
' ' Dim memStream As IO.MemoryStream = New IO.MemoryStream()
|
||||
' ' original.Save(memStream, ImageFormat.Png)
|
||||
' ' Per.idFicheroNavigation.Fichero = memStream.ToArray
|
||||
' 'End If
|
||||
' Dim docpanel As New DevExpress.Xpf.Docking.DocumentPanel
|
||||
' docpanel.Caption = pl.Descripcion
|
||||
' docpanel.Content = vi
|
||||
' docpanel.ClosingBehavior = DevExpress.Xpf.Docking.ClosingBehavior.ImmediatelyRemove
|
||||
' GrupoDocumentos.Items.Add(docpanel)
|
||||
' dc.Activate(docpanel)
|
||||
|
||||
' Catch ex As Exception
|
||||
' DXMessageBox.Show(ex.Message, "Atención", MessageBoxButton.OK, MessageBoxImage.Error)
|
||||
' End Try
|
||||
'End Sub
|
||||
Shared Sub GeneraRegistroCorreoExcepcion(bd As tscGrupoSanchoToro, ex As Exception, Rutina As String, Optional FicheroImagen As Byte() = Nothing)
|
||||
Try
|
||||
If bd Is Nothing Then bd = tscGrupoSanchoToro.NuevoContexto
|
||||
Dim sMensaje As String = "Usuario: " & bdGrupoSanchoToro.db.Utilidades.Usuario & vbCrLf
|
||||
Dim sStackTrace As String = "Tipo excepción: " & ex.ToString & vbCrLf
|
||||
Dim exError As Exception = ex
|
||||
Do
|
||||
sStackTrace &= exError.StackTrace & vbCrLf
|
||||
exError = exError.InnerException
|
||||
Loop Until IsNothing(exError)
|
||||
If sStackTrace <> "" Then sMensaje &= vbCrLf & "StackTrace: " & sStackTrace
|
||||
Dim cuentaorigen As cuentascorreo = (From c In bd.cuentascorreo Select c Where c.Codigo = "M3SOFT").First
|
||||
If FicheroImagen Is Nothing Then
|
||||
correos.GeneraRegistroCorreon(bd, "Mensaje Automático. Error en " & Rutina, sMensaje, cuentaorigen, "manmog@gmail.com", "", "", , ,, "ERRORES")
|
||||
Else
|
||||
correos.GeneraRegistroCorreon(bd, "Mensaje Automático. Error en " & Rutina, sMensaje, cuentaorigen, "manmog@gmail.com", "", "", FicheroImagen, "captura.jpg",, "ERRORES")
|
||||
End If
|
||||
Catch ex2 As Exception
|
||||
DXMessageBox.Show(ex2.Message & vbCrLf & ex2.StackTrace, "Error Generando Correo Excepcion")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Friend Shared Function ObtieneListaAlmacenes(bd As tscGrupoSanchoToro) As List(Of almacenes)
|
||||
Dim alms = bd.almacenes.Where(Function(x) x.FechaBaja.HasValue = False).ToList
|
||||
Return alms
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Namespace Convertidores
|
||||
|
||||
Public Class DoubleToDecimalConverter
|
||||
Implements IValueConverter
|
||||
|
||||
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
|
||||
If value Is Nothing Then
|
||||
Return 0
|
||||
Else
|
||||
Return Decimal.Parse(value)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
|
||||
If value Is Nothing Then
|
||||
Return 0
|
||||
Else
|
||||
Return Double.Parse(value)
|
||||
End If
|
||||
End Function
|
||||
End Class
|
||||
|
||||
|
||||
Public Class ExistenLineasConverter
|
||||
Implements IValueConverter
|
||||
|
||||
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
|
||||
Dim lineas As IEnumerable(Of Object) = value
|
||||
Return (lineas.Count > 0)
|
||||
End Function
|
||||
|
||||
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
|
||||
Return value
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Public Class ImagenConverter
|
||||
Implements IValueConverter
|
||||
|
||||
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
|
||||
Try
|
||||
If value Is Nothing Then
|
||||
Return Nothing
|
||||
Else
|
||||
Dim ms As New IO.MemoryStream(DirectCast(value, Byte()))
|
||||
Dim img As New BitmapImage
|
||||
img.BeginInit()
|
||||
img.StreamSource = ms
|
||||
img.CacheOption = BitmapCacheOption.OnLoad
|
||||
img.EndInit()
|
||||
img.Freeze()
|
||||
ms.Close()
|
||||
ms.Dispose()
|
||||
Return img
|
||||
GC.Collect()
|
||||
GC.WaitForPendingFinalizers()
|
||||
GC.Collect()
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
' Throw New Exception(ex.Message, ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
|
||||
Try
|
||||
If value Is Nothing Then
|
||||
Return Nothing
|
||||
Else
|
||||
Dim bm As BitmapImage = value
|
||||
Dim ms As IO.MemoryStream = bm.StreamSource
|
||||
Return ms.ToArray
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Throw New Exception(ex.Message, ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user