214 lines
8.6 KiB
VB.net
214 lines
8.6 KiB
VB.net
Imports System.Data.SqlClient
|
|
Imports System.Drawing
|
|
Imports System.Net.NetworkInformation
|
|
Imports System.Reflection
|
|
Imports System.Windows.Forms
|
|
|
|
Public Class cTranslateAuto_LIST
|
|
|
|
Public list As New List(Of cTranslateAuto)
|
|
Dim trs_progId
|
|
|
|
Sub New()
|
|
LOAD()
|
|
End Sub
|
|
|
|
Public Sub LOAD()
|
|
Try
|
|
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("SELECT * FROM tblTranslateAuto WHERE [trs_active]=1 ", conn)
|
|
'cmd.Parameters.AddWithValue("@trs_progId", trs_progId)
|
|
Dim dr = cmd.ExecuteReader()
|
|
While dr.Read
|
|
Dim T As New cTranslateAuto
|
|
T.trs_id = dr("trs_id")
|
|
T.trs_textDE = dr("trs_textDE")
|
|
T.trs_sprache = dr("trs_sprache")
|
|
T.trs_text = dr("trs_text")
|
|
T.trs_active = dr("trs_active")
|
|
list.Add(T)
|
|
End While
|
|
dr.Close()
|
|
End Using
|
|
End Using
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
Shared Sub DoToAllControls(ByVal m_Control As Control, LAN As String, Optional LAN_SRC As String = "DE")
|
|
For Each ctrl As Control In m_Control.Controls
|
|
If ctrl.Controls.Count > 0 Then
|
|
DoToAllControls(ctrl, LAN, LAN_SRC)
|
|
End If
|
|
'If ctrl.GetType().Equals(GetType(ToolStrip)) Then
|
|
' For Each item As ToolStripItem In DirectCast(ctrl, ToolStrip).Items
|
|
' MsgBox(item.Name)
|
|
' Next
|
|
'End If
|
|
'MsgBox(ctrl.Name)
|
|
|
|
If (TypeOf ctrl Is System.Windows.Forms.Label) Then
|
|
DirectCast(ctrl, System.Windows.Forms.Label).Text = VERAG_PROG_ALLGEMEIN.cTranslateAuto._Transle(ctrl.Text, LAN, LAN_SRC)
|
|
End If
|
|
If (TypeOf ctrl Is System.Windows.Forms.Button) Or (TypeOf ctrl Is VERAG_PROG_ALLGEMEIN.FlatButton) Then
|
|
DirectCast(ctrl, System.Windows.Forms.Button).Text = VERAG_PROG_ALLGEMEIN.cTranslateAuto._Transle(ctrl.Text, LAN, LAN_SRC)
|
|
End If
|
|
If (TypeOf ctrl Is System.Windows.Forms.TabPage) Then
|
|
DirectCast(ctrl, System.Windows.Forms.TabPage).Text = VERAG_PROG_ALLGEMEIN.cTranslateAuto._Transle(ctrl.Text, LAN, LAN_SRC)
|
|
End If
|
|
If (TypeOf ctrl Is System.Windows.Forms.RadioButton) Or (TypeOf ctrl Is VERAG_PROG_ALLGEMEIN.MyRadioButton) Then
|
|
DirectCast(ctrl, System.Windows.Forms.RadioButton).Text = VERAG_PROG_ALLGEMEIN.cTranslateAuto._Transle(ctrl.Text, LAN, LAN_SRC)
|
|
End If
|
|
If (TypeOf ctrl Is System.Windows.Forms.GroupBox) Then
|
|
DirectCast(ctrl, System.Windows.Forms.GroupBox).Text = VERAG_PROG_ALLGEMEIN.cTranslateAuto._Transle(ctrl.Text, LAN, LAN_SRC)
|
|
End If
|
|
If (TypeOf ctrl Is System.Windows.Forms.ComboBox) Or (TypeOf ctrl Is VERAG_PROG_ALLGEMEIN.MyComboBox) Then
|
|
'DirectCast(obj, System.Windows.Forms.Label).Text = TXT.trs_text
|
|
End If
|
|
|
|
Next
|
|
End Sub
|
|
End Class
|
|
Public Class cTranslateAuto
|
|
Property trs_id As Integer
|
|
Property trs_sprache As String
|
|
Property trs_textDE As String
|
|
Property trs_text As String
|
|
Property trs_active As Boolean = True
|
|
|
|
|
|
Public hasEntry = False
|
|
|
|
Dim SQL As New SQL
|
|
Sub New()
|
|
|
|
End Sub
|
|
Sub New(trs_id)
|
|
Me.trs_id = trs_id
|
|
LOAD()
|
|
End Sub
|
|
Function getParameterList() As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
|
|
Dim list As New List(Of VERAG_PROG_ALLGEMEIN.SQLVariable)
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("trs_id", trs_id,, True))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("trs_textDE", trs_textDE))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("trs_sprache", trs_sprache))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("trs_text", trs_text))
|
|
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("trs_active", trs_active))
|
|
|
|
Return list
|
|
End Function
|
|
|
|
|
|
|
|
Public Function SAVE() As Boolean
|
|
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
|
|
|
|
Dim sqlstr = " BEGIN TRAN IF EXISTS(SELECT * FROM tblTranslateAuto WHERE trs_id=@trs_id) " &
|
|
" BEGIN " & getUpdateCmd() & " END " &
|
|
" Else " &
|
|
" BEGIN " & getInsertCmd() & " END " &
|
|
" commit tran "
|
|
|
|
Return SQL.doSQLVarList(sqlstr, "FMZOLL", , list)
|
|
End Function
|
|
|
|
Public Sub LOAD()
|
|
Try
|
|
hasEntry = False
|
|
Using conn As SqlConnection = SQL.GetNewOpenConnectionFMZOLL()
|
|
Using cmd As New SqlCommand("SELECT * FROM tblTranslateAuto WHERE trs_id=@trs_id AND [trs_active]=1 ", conn)
|
|
cmd.Parameters.AddWithValue("@trs_id", trs_id)
|
|
Dim dr = cmd.ExecuteReader()
|
|
If dr.Read Then
|
|
For Each li In getParameterList()
|
|
Dim propInfo As PropertyInfo = Me.GetType.GetProperty(li.Scalarvariable)
|
|
|
|
If dr.Item(li.Text) Is DBNull.Value Then
|
|
propInfo.SetValue(Me, Nothing)
|
|
Else
|
|
propInfo.SetValue(Me, dr.Item(li.Text))
|
|
End If
|
|
|
|
Next
|
|
hasEntry = True
|
|
End If
|
|
dr.Close()
|
|
End Using
|
|
End Using
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
|
|
Public Function getUpdateCmd() As String
|
|
Try
|
|
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
|
|
|
|
Dim str As String = ""
|
|
For Each i In list
|
|
If Not i.isPrimaryParam Then
|
|
str &= "[" & i.Text & "] = @" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
|
|
End If
|
|
Next
|
|
str = str.Substring(0, str.Length - 1) 'wg. ','
|
|
Return (" UPDATE [tblTranslateAuto] SET " & str & " WHERE trs_id=@trs_id ")
|
|
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
Return ""
|
|
End Function
|
|
|
|
|
|
Public Function getInsertCmd() As String
|
|
Try
|
|
Dim list As List(Of VERAG_PROG_ALLGEMEIN.SQLVariable) = getParameterList()
|
|
Dim str As String = ""
|
|
Dim values As String = ""
|
|
For Each i In list
|
|
If Not i.isPrimaryParam Then
|
|
str &= "[" & i.Text & "],"
|
|
values &= "@" & i.Scalarvariable & "," '.Replace("-", "").Replace(" ", "") & ","
|
|
End If
|
|
Next
|
|
str = str.Substring(0, str.Length - 1) 'wg. ','
|
|
values = values.Substring(0, values.Length - 1) 'wg. ','
|
|
Return (" INSERT INTO tblTranslateAuto (" & str & ") VALUES(" & values & ") ")
|
|
Catch ex As Exception
|
|
MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
|
|
End Try
|
|
Return ""
|
|
|
|
End Function
|
|
|
|
|
|
|
|
Shared Function _Transle(Text, LAN, Optional SRC_LAN = "") As String
|
|
Dim TRS_RSLT = VERAG_PROG_ALLGEMEIN.cAllgemein.TRANSLATE_AUTO.list.Find(Function(x) (x.trs_textDE = Text Or x.trs_text = Text) And x.trs_sprache = LAN)
|
|
If TRS_RSLT IsNot Nothing Then
|
|
Return TRS_RSLT.trs_text
|
|
Else
|
|
Dim TextResult = ""
|
|
If cDeeplAPI.deepl_Translate(Text, TextResult, LAN, SRC_LAN) Then
|
|
Dim TRS As New cTranslateAuto
|
|
TRS.trs_text = TextResult
|
|
TRS.trs_sprache = LAN
|
|
TRS.trs_textDE = Text
|
|
TRS.SAVE()
|
|
'MsgBox(Text & " --- " & TextResult)
|
|
VERAG_PROG_ALLGEMEIN.cAllgemein.TRANSLATE_AUTO.list.Add(TRS)
|
|
Return TextResult
|
|
End If
|
|
End If
|
|
Return Text
|
|
|
|
End Function
|
|
|
|
|
|
|
|
End Class
|