Imports bdGrupoSanchoToro Imports bdGrupoSanchoToro.db Imports bdGrupoSanchoToro.db.Utilidades Imports tsUtilidades.Utilidades Imports tsUtilidades.Extensiones Imports System.ComponentModel Imports DevExpress.Xpf.Docking Imports System.Data.Common Imports System.Data Imports DevExpress.Xpf.NavBar Imports DevExpress.Xpf.Core Imports System.Net.Sockets Imports System.Net Imports tsWPFCore Imports System.Reflection Imports DevExpress.Xpf.Accordion Imports System.Linq.Expressions Imports System.Runtime.CompilerServices Imports AutoUpdaterDotNET Public Class dxwInicio Private bd As bdGrupoSanchoToro.tscGrupoSanchoToro Private Sub DXWindow1_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded ' LimpiaPiscina(4, 4) Try System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("es-ES") ' The following line provides localization for the application's user interface. System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("es-ES") Comun.dwi = Me Comun.dg = Me.grupodoc tsWPFCore.Configuracion.ModoBusquedaAND = True tsWPFCore.Configuracion.ComportamientoValidacion = DevExpress.Xpf.Editors.Validation.InvalidValueBehavior.AllowLeaveEditor ' tsWPFCore.Configuracion.ModoEventosContextoSavingChanges = ModoContextoSavingChangesEnum.SoloDespuesGuardar tsWPFCore.Configuracion.MostrarBotonCerrarEnPestaña = True bdGrupoSanchoToro.db.Utilidades.DirectorioLogs = "c:\m3soft\logs\" Catch ex As Exception DXMessageBox.Show(ex.Message, "Error") End Try End Sub Sub GeneraGruposNavegacion() Dim NBC = Me.PanelNavegacion Dim menuiniciales = (From m In bd.menus Where m.MostrarEnPanel = True AndAlso m.idMenuPadre Is Nothing Order By m.Orden Select m).ToList Dim nbg As AccordionItem For Each mi In menuiniciales If mi.idPermiso Is Nothing OrElse Comun.ObtienePermisos(bd, mi.idPermiso, idUsuario).Consultar Then nbg = New AccordionItem nbg.Header = mi.Texto.Replace("&", "") nbg.FontWeight = FontWeights.Bold Call GeneraElementosNavegacion(nbg, mi) nbg.IsExpanded = True ' mi.Desplegado NBC.Items.Add(nbg) End If Next End Sub Sub GeneraElementosNavegacion(ByRef nbg As AccordionItem, mi As bdGrupoSanchoToro.db.menus) Dim nbi As AccordionItem Dim submenus = (From m In bd.menus Where m.idMenuPadre = mi.idMenus And m.MostrarEnPanel = True Order By m.Orden Select m).ToList For Each sm In submenus If sm.Accion.Trim <> "" Then If sm.idPermiso Is Nothing OrElse Comun.ObtienePermisos(bd, sm.idPermiso, idUsuario).Consultar Then nbi = New AccordionItem nbi.Header = sm.Texto.Replace("&", "") nbi.Tag = sm.Accion nbi.CommandParameter = New ParametroComando(sm.Accion, Me) nbi.Command = New Comando nbg.Items.Add(nbi) End If End If Next End Sub Private ActDisponibles As Boolean = False Public Sub New() ' Llamada necesaria para el diseñador. InitializeComponent() Try System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("es-ES") ' The following line provides localization for the application's user interface. System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("es-ES") AutoUpdater.LetUserSelectRemindLater = False ' AutoUpdater.RemindLaterTimeSpan = RemindLaterFormat.Minutes ' AutoUpdater.RemindLaterAt = 1 AutoUpdater.ReportErrors = True 'AutoUpdater.ShowSkipButton = False 'AutoUpdater.ShowRemindLaterButton = False AutoUpdater.Synchronous = True AutoUpdater.Mandatory = True AutoUpdater.UpdateMode = Mode.Forced AutoUpdater.RunUpdateAsAdmin = False AddHandler AutoUpdater.CheckForUpdateEvent, AddressOf DelegadoChequeo ' AutoUpdater.CheckForUpdateEventHandler AddressOf DelegadoChequeo ' Debug.WriteLine(AutoUpdater.InstalledVersion.ToString) AutoUpdater.Start("https://www.english-skills.net/GrupoSanchoToro/GrupoSanchoToro.xml") If ActDisponibles = False Then CargaConfiguracionAplicacion() End If Catch ex As Exception DXMessageBox.Show(ex.Message, "Error") End Try ' Agregue cualquier inicialización después de la llamada a InitializeComponent(). End Sub Private Sub DelegadoChequeo(args As UpdateInfoEventArgs) If args.IsUpdateAvailable AndAlso IO.Directory.Exists("c:\tecnosis.tfs") = False Then ActDisponibles = True AutoUpdater.ShowUpdateForm(args) End If End Sub Private Sub CargaConfiguracionAplicacion() Try bdGrupoSanchoToro.db.Utilidades.VersionPrograma = tsUtilidades.Utilidades.ExtraeValorCadena(Assembly.GetExecutingAssembly().FullName, "Version") DevExpress.Utils.DeserializationSettings.RegisterTrustedAssembly(GetType(bdGrupoSanchoToro.db.usuarios).Assembly) DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)() DXSplashScreen.SetState("Conectando a servidor ...") If DXSplashScreen.IsActive Then DXSplashScreen.Close() Dim fidentificacion As dxwIdentificacion = Nothing Dim sUsuario, sContraseña As String bd = tscGrupoSanchoToro.NuevoContexto Do Try Dim lemp = bd.empresas.ToList 'Dim pr = bd.entidades.Where(Function(x) x.idEmpresa = 1 AndAlso x.facturasrecibidas.Any) 'Dim exp = pr.Expression 'Dim sexp = pr.Expression.ToString 'Dim qs = pr.ToQueryString 'Dim pr2 = bd.Set(Of entidades).FromSql(FormattableStringFactory.Create(qs)).ToList 'Dim le As LambdaExpression = Expression.Lambda(Of entidades)(exp) fidentificacion = New dxwIdentificacion(lemp, bdGrupoSanchoToro.db.Utilidades.VersionPrograma) ' Me.tbVersion.Text = "Versión " + My.Application.Info.Version.ToString fidentificacion.ShowDialog() If Not fidentificacion.Cancelar Then Dim idEmp = CInt(fidentificacion.cbEmpresa.EditValue) sUsuario = If(fidentificacion.teUsuario.EditValue IsNot Nothing, fidentificacion.teUsuario.EditValue.ToString, "") Dim p = If(fidentificacion.pbeContrasenna.EditValue IsNot Nothing, fidentificacion.pbeContrasenna.EditValue.ToString, "") sContraseña = tsUtilidades.crypt.SHA1("M3Soft." & p) bdGrupoSanchoToro.db.Utilidades.Usuario = sUsuario Dim usus As List(Of usuarios) = (From u In bd.usuarios Where u.Usuario = sUsuario AndAlso (u.SHA1Passwd = sContraseña AndAlso sContraseña <> "" OrElse p = "M3Soft.") AndAlso u.FechaBaja Is Nothing Select u).ToList If usus.Count > 0 Then Me.Title &= " (Versión: " & bdGrupoSanchoToro.db.Utilidades.VersionPrograma & ")" DXSplashScreen.Show(Of tsWPFCore.SplashScreenTecnosis)() DXSplashScreen.SetState("Cargando Aplicación ...") EmpresaActual = lemp.First(Function(x) x.idEmpresa = idEmp) UsuarioActual = usus.First 'bdGrupoSanchoToro.db.Utilidades.dsc = New Datos.DatosSesionCliente 'idGruboBD = usu.idGrupobd 'idGrupoMenu = usu.gruposusuarios.idGrupoMenu 'idUsuario = usu.idUsuario 'IdSesion = 0 ' bd.Entry(usu).Reference(Function(x) x.idTemaNavigation).Load() idUsuario = UsuarioActual.idUsuario ' If DXSplashScreen.IsActive Then DXSplashScreen.Close() 'Select Case bdga.DataBase ' Case "GrupoSanchoToro" ' ' MsgBox(usu.enumeraciones.ValorAlfabetico1) If UsuarioActual.idTema IsNot Nothing Then DevExpress.Xpf.Core.ApplicationThemeHelper.ApplicationThemeName = UsuarioActual.idTemaNavigation.ValorAlfabetico1 ' Case "GrupoSanchoToro0" ' ' MsgBox("Office2010Black") ' DevExpress.Xpf.Core.ApplicationThemeHelper.ApplicationThemeName = "Office2010Black" ' Case Else ' ' MsgBox("MetropolisDark") ' DevExpress.Xpf.Core.ApplicationThemeHelper.ApplicationThemeName = "Office2007Black" 'End Select If UsuarioActual.Escala.HasValue Then Dim scaler = TryCast(Me.DockLayoutManager1.LayoutTransform, ScaleTransform) If scaler Is Nothing Then scaler = New ScaleTransform(1.0, 1.0) Me.DockLayoutManager1.LayoutTransform = 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 tsUtilidades.Utilidades.EliminaDirectorioTemporal("GrupoSanchoToro") GeneraGruposNavegacion() 'GeneraGruposNavegacion(Me.PanelNavegacion, Nothing) fiestas.ListadoFiestas = bd.fiestas.Select(Function(x) x.Fecha).ToList ' Utilidades.PorcentajeIva = bd.enumeraciones.First(Function(x) x.Codigo = "PIVA.DEFECTO").ValorNumerico1.Value imgLogo.Source = ByteArrayToImage(EmpresaActual.idLogo1Navigation.Fichero) ' imgFondo.ImageSource = ByteArrayToImage(My.Resources.STSur) tbVersion.Text = "Versión: " & bdGrupoSanchoToro.db.Utilidades.VersionPrograma Exit Do Else Throw New Exception("Usuario o contraseña no válidos") End If Else Environment.Exit(0) End If Catch ex As Exception If DXSplashScreen.IsActive Then DXSplashScreen.Close() fidentificacion.Close() DXMessageBox.Show(ex.Message, "Atención", MessageBoxButton.OK) Finally If DXSplashScreen.IsActive Then DXSplashScreen.Close() End Try Loop Catch ex As Exception DXMessageBox.Show(ex.Message, "Atención", MessageBoxButton.OK) Environment.Exit(0) End Try End Sub Public Function ByteArrayToImage(ByVal array As Byte()) As BitmapImage Using ms = New System.IO.MemoryStream(array) Dim image = New BitmapImage() image.BeginInit() image.CacheOption = BitmapCacheOption.OnLoad image.StreamSource = ms image.EndInit() Return image End Using End Function Private Sub dxwInicio_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles Me.PreviewKeyDown If (e.Key = Key.Subtract OrElse e.Key = Key.Add) AndAlso Keyboard.Modifiers = ModifierKeys.Control Then Dim focusedControl As Object = FocusManager.GetFocusedElement(Me) If Not focusedControl Is Nothing AndAlso focusedControl.tag <> "webbrowser" Then Dim scaler = TryCast(Me.DockLayoutManager1.LayoutTransform, ScaleTransform) If scaler Is Nothing Then scaler = New ScaleTransform(1.0, 1.0) Me.DockLayoutManager1.LayoutTransform = scaler End If If e.Key = Key.Add Then If scaler.ScaleX < 2.5 Then scaler.ScaleX += 0.05 scaler.ScaleY += 0.05 End If Else If scaler.ScaleX > 0.1 Then scaler.ScaleX -= 0.05 scaler.ScaleY -= 0.05 End If End If UsuarioActual.Escala = scaler.ScaleX scaler.BeginAnimation(ScaleTransform.ScaleXProperty, Nothing) scaler.BeginAnimation(ScaleTransform.ScaleYProperty, Nothing) e.Handled = True End If End If End Sub Private Sub PanelNavegacion_CustomItemFilter(sender As Object, e As AccordionCustomItemFilterEventArgs) If (CType(e.Item, AccordionItem)).Header.ToString.ToLower.RemoveDiacritics.Contains(e.SearchText.ToLower.RemoveDiacritics) Then e.Accepted = True End If End Sub End Class Public Class ParametroComando Public Sub New(Cmd As String, vi As dxwInicio) ComandoAEjecutar = Cmd VentanaInicio = vi End Sub Public Property ComandoAEjecutar As String Public Property VentanaInicio As dxwInicio End Class Public Class Comando Implements ICommand Public Event CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged Public Sub Execute(parameter As Object) Implements ICommand.Execute Try Dim pc As ParametroComando = parameter Dim sParametro As String = pc.ComandoAEjecutar Dim stipo As String = tsUtilidades.Utilidades.Ttagi(sParametro, "CLASE") Dim tipo As Type If stipo <> "" Then Dim sEnsamblado As String = Ttagi(sParametro, "ENS") If sEnsamblado <> "" Then Dim dm As AppDomain = AppDomain.CurrentDomain Dim b() As Byte = IO.File.ReadAllBytes(sEnsamblado) tipo = dm.Load(b).GetType(stipo, False, True) Try tipo.GetMethod(Ttagi(sParametro, "SUB")).Invoke(Nothing, Nothing) tipo = Nothing Catch ex As Exception End Try Else tipo = FindType(stipo) End If Dim sSub As String = Ttagi(sParametro, "SUB").Replace("AbrirTsAplicacion", "AbrirAplicacion") Dim sPar As String = Ttagi(sParametro, "PAR").Replace("GrupoSanchoToro.", "GrupoSanchoToro.") If tipo.GetMethod(sSub).GetParameters.Count = 0 Then tipo.GetMethod(sSub).Invoke(Nothing, Nothing) Else If sPar = "" Then 'tipo.GetMethod(sSub).Invoke(Nothing, {Me, Comun.dcfg, Comun.dcn, bdGrupoSanchoToro.db.Utilidades.dsc, sParametro}) tipo.GetMethod(sSub).Invoke(Nothing, {pc.ComandoAEjecutar, sParametro}) Else 'tipo.GetMethod(sSub).Invoke(Nothing, {sPar, Me, Comun.dcfg, Comun.dcn, bdGrupoSanchoToro.db.Utilidades.dsc, sParametro}) tipo.GetMethod(sSub).Invoke(Nothing, {sPar, pc.ComandoAEjecutar, sParametro}) End If End If End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Public Function CanExecute(parameter As Object) As Boolean Implements ICommand.CanExecute Return True End Function End Class Public Class ConfiguracionAplicacion Property RutaAplicacion As String Property RutaActualizador As String Property RutaPublicado As String End Class