From a0ee62668c254f8df709cd807b94ab82c87cc0ad Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 30 Jun 2026 11:59:11 +0200 Subject: [PATCH] =?UTF-8?q?'=20=20=2030/06/2027=20=20MANMOG=20=20Version?= =?UTF-8?q?=203.0.7=20=20=20=20=20Correcci=C3=B3n=20CharConverter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Baget/Aplicacion.nuspec | 2 +- My Project/AssemblyInfo.vb | 5 +- clFuncionesGenericas.vb | 125 +++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 71 deletions(-) diff --git a/Baget/Aplicacion.nuspec b/Baget/Aplicacion.nuspec index 5db80ff..17764a0 100644 --- a/Baget/Aplicacion.nuspec +++ b/Baget/Aplicacion.nuspec @@ -2,7 +2,7 @@ tsl5 - 3.0.6 + 3.0.7 Tecnosis Tecnosis false diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb index bcb3190..ea6afbc 100644 --- a/My Project/AssemblyInfo.vb +++ b/My Project/AssemblyInfo.vb @@ -31,12 +31,13 @@ Imports System.Runtime.InteropServices ' mediante el asterisco ('*'), como se muestra a continuación: ' - - + + ' Modificaciones: ' =============== +' 30/06/2027 MANMOG Version 3.0.7 Corrección CharConverter ' 26/06/2027 MANMOG Version 3.0.6 Se añade tsExcepcion ' 03/06/2027 MANMOG Version 3.0.5 Correccion en tsNotificacionesClient ' 14/05/2026 MANMOG Version 3.0.4 Actualización de .nuspec para que incluya dependencias externas \ No newline at end of file diff --git a/clFuncionesGenericas.vb b/clFuncionesGenericas.vb index a48a6c0..e3256bf 100644 --- a/clFuncionesGenericas.vb +++ b/clFuncionesGenericas.vb @@ -1,12 +1,13 @@ -Imports System.Windows.Forms -Imports System.Data -Imports System.Data.SqlClient -Imports MySql.Data.MySqlClient +Imports System.Data Imports System.Data.OleDb -Imports System.IO +Imports System.Data.SqlClient 'Imports ComponentAce.Compression.ZipForge 'Imports ComponentAce.Compression.Archiver Imports System.Environment +Imports System.IO +Imports System.Text +Imports System.Windows.Forms +Imports MySql.Data.MySqlClient 'Imports UtilidadesTSL4net.clCharConv @@ -3756,74 +3757,62 @@ Public Class clFuncionesGenericas End Function - Public Shared Sub CharConverter(ByVal jcOrigen As String, ByVal jcDestino As String, ByVal Fichero_Origen As String, Optional ByVal Fichero_Destino As String = "") + + + Public Shared Sub CharConverter(jcOrigen As String, jcDestino As String, Fichero_Origen As String, Optional Fichero_Destino As String = "") Try - Dim Temporal As String = Fichero_Origen & ".tmp" - Dim sBuffer As String - Dim i, pos, fr, fw As Integer - Dim Size As Long = FileLen(Fichero_Origen) - Dim cAux(), cOrigen(), cDestino() As Char - 'Inicializamos los juegos de caracteres origen y destino - Select Case jcOrigen.ToUpper - Case "WINDOWS" - cOrigen = WINDOWS - Case "ROMAN8" - cOrigen = ROMAN8 - Case "ROMAN8SA" - cOrigen = ROMAN8SA - Case Else - ' MsgBox("Juegos de caracteres origen erróneo o no soportado.") - ' Exit Sub - Throw New Exception("Juego de caracteres origen erróneo.") - End Select - Select Case jcDestino.ToUpper - Case "WINDOWS" - cDestino = WINDOWS - Case "ROMAN8" - cDestino = ROMAN8 - Case "ROMAN8SA" - cDestino = ROMAN8SA - Case Else - Throw New Exception("Juego de caracteres destino erróneo.") - 'MsgBox("Juegos de caracteres destino erróneo o no soportado.") - 'Exit Sub - End Select - 'Abrimos Origen y Destino - fr = FreeFile() - fw = fr + 1 - FileOpen(fr, Fichero_Origen, OpenMode.Input, OpenAccess.Read) - FileOpen(fw, Temporal, OpenMode.Output, OpenAccess.Write) - 'Guardamos el contenido del fichero en un Buffer - sBuffer = InputString(fr, Size) - 'Reemplazamos los caracteres especiales en Windows UTF8 por sus correspondientes en Roman8 - cAux = sBuffer - For i = 0 To NumChar - 1 - pos = 0 - Do - pos = InStr(pos + 1, sBuffer, cOrigen(i), CompareMethod.Binary) - If pos > 0 Then - cAux(pos - 1) = cDestino(i) - End If - Loop Until pos = 0 - Next - sBuffer = cAux - Print(fw, sBuffer) - 'Cerramos los ficheros - FileClose(fr, fw) - 'Si el destino no viene especificado es que tomaremos el origen como destino - 'y usaremos como destino para el proceso un fichero temporal - If Fichero_Destino = "" Then - File.Copy(Temporal, Fichero_Origen, True) - Else - File.Copy(Temporal, Fichero_Destino, True) + ' Seleccionamos las tablas de caracteres + Dim origen() As Char = GetCharTable(jcOrigen) + Dim destino() As Char = GetCharTable(jcDestino) + + If origen.Length <> destino.Length Then + Throw New Exception("Las tablas de conversión no tienen la misma longitud.") End If - 'Borramos el fichero temporal - File.Delete(Temporal) + + ' Creamos diccionario de sustitución + Dim mapa As New Dictionary(Of Char, Char) + For i = 0 To origen.Length - 1 + mapa(origen(i)) = destino(i) + Next + + ' Leemos el fichero como texto (UTF-8 por defecto) + Dim texto As String = File.ReadAllText(Fichero_Origen, Encoding.UTF8) + + ' Convertimos carácter por carácter + Dim sb As New StringBuilder(texto.Length) + + For Each ch As Char In texto + If mapa.ContainsKey(ch) Then + sb.Append(mapa(ch)) + Else + sb.Append(ch) + End If + Next + + ' Determinar destino + Dim rutaDestino As String = If(Fichero_Destino = "", Fichero_Origen, Fichero_Destino) + + ' Guardar resultado + File.WriteAllText(rutaDestino, sb.ToString(), Encoding.UTF8) + Catch ex As Exception - 'MsgBox(ex.Message, , "Error") - Throw New Exception(ex.Message) + Throw New Exception("Error en CharConverter: " & ex.Message) End Try End Sub + + Private Shared Function GetCharTable(nombre As String) As Char() + Select Case nombre.ToUpper() + Case "WINDOWS" + Return WINDOWS + Case "ROMAN8" + Return ROMAN8 + Case "ROMAN8SA" + Return ROMAN8SA + Case Else + Throw New Exception("Juego de caracteres no soportado: " & nombre) + End Select + End Function + Public Shared Function LeeRegistrosSQLSQLServer(ByVal Conexion As SqlConnection, ByVal Clausula_SQL As String, Optional ByVal Sin_Errores As Boolean = True, Optional ByVal NombreDataset As String = "DATASET", Optional ByVal NombreTabla As String = "TABLA") As DataTable LeeRegistrosSQLSQLServer = Nothing Try