新增如下命令:
SetRecord GetReocrd CombindRecord
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
Imports UTS_Core.Database
|
||||
Imports UTS_Core.UTSModule
|
||||
Imports UTS_Core.UTSModule.DbConnect
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class CombindRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _filedNames As New List(Of String)
|
||||
Private _dutSn As String
|
||||
Private _dutSn2 As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_dutSn = command.Parameter(0)
|
||||
_dutSn2 = command.Parameter(1)
|
||||
|
||||
_filedNames.Add(command.Parameter(0))
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
|
||||
Dim filedName As String = _filedNames(0)
|
||||
Dim updateString As String = $"t1.`{filedName}` = t2.`{filedName}`"
|
||||
For i As Integer = 1 To _filedNames.Count - 1
|
||||
updateString += $",t1.`{filedName}` = t2.`{filedName}` "
|
||||
Next
|
||||
|
||||
|
||||
Dim saveDbCmdText As String = String.Empty
|
||||
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Dim cmdText As String = $"UPDATE `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 ON t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
|
||||
|
||||
Try
|
||||
db.Open()
|
||||
db.ExecuteNonQuery(cmdText)
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
saveDbCmdText = cmdText '云端执行,使用本地执行
|
||||
End Try
|
||||
End Using
|
||||
|
||||
'本地存储
|
||||
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
Try
|
||||
db.Open()
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
Try
|
||||
Dim cmdText As String = $"UPDATE `{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 ON t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
|
||||
db.ExecuteNonQuery(cmdText)
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库保存失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
|
||||
'本地缓存
|
||||
Try
|
||||
If String.IsNullOrEmpty(saveDbCmdText) Then
|
||||
DbConnector.SaveCmdStringToCacheTable(db, saveDbCmdText)
|
||||
CommandReturn.ExecuteResultTipString = "本地缓存成功"
|
||||
End If
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库缓存失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
|
||||
db.Close()
|
||||
End Using
|
||||
|
||||
End Function
|
||||
End Class
|
||||
@@ -1,18 +0,0 @@
|
||||
Namespace UTSModule.Test.Command.DatabaseCommand
|
||||
Public Class DatabaseCommandManager
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "GetRecord"
|
||||
Return New GetRecordCommand(command)
|
||||
Case "SetRecord"
|
||||
Return New SetRecordCommand(command)
|
||||
Case "CombindRecord"
|
||||
Return New CombindRecordCommand(command)
|
||||
Case Else
|
||||
Throw New Exception($"Database集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
Return executor
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -1,70 +0,0 @@
|
||||
Imports UTS_Core.Database
|
||||
Imports UTS_Core.UTSModule
|
||||
Imports UTS_Core.UTSModule.DbConnect
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class GetRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _filedName As String
|
||||
Private _dutSn As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_dutSn = command.Parameter(0)
|
||||
_filedName = command.Parameter(1)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'优先查询云端
|
||||
Dim useLocalSearch As Boolean = False
|
||||
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.DbSearch(UtsDb.RemotePrivateDb, _filedName, SnListTable.TableName, condition)
|
||||
|
||||
Try
|
||||
db.Open()
|
||||
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
CommandReturn.ExecuteResult = True
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
useLocalSearch = True '云端查询失败,使用本地查询
|
||||
End Try
|
||||
End Using
|
||||
|
||||
|
||||
'本地存储
|
||||
If useLocalSearch Then
|
||||
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
Try
|
||||
db.Open()
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
Try
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.Search(_filedName, SnListTable.TableName, condition)
|
||||
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库查询成功"
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库查询失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
db.Close()
|
||||
End Using
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
|
||||
|
||||
End Function
|
||||
End Class
|
||||
@@ -0,0 +1,97 @@
|
||||
Imports UTS_Core.Database
|
||||
Imports UTS_Core.UTSModule
|
||||
Imports UTS_Core.UTSModule.DbConnect
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
Imports System.Linq
|
||||
|
||||
Public Class CombindRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _filedNames As New List(Of String)
|
||||
Private _dutSn As String
|
||||
Private _dutSn2 As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
'合并逻辑:将源SN指定字段的值复制到目标SN,如果目标SN已经有值,则进行覆盖操作
|
||||
'如果合并字段名为 S1~S12,则对应的Result1~Result12 也进行合并,即Sx与Resultx配对进行操作
|
||||
'覆盖方向:源SN -》 目标SN’
|
||||
_dutSn = command.Parameter(0) '目标SN’
|
||||
_dutSn2 = command.Parameter(1) '源SN’
|
||||
|
||||
'_filedNames.Add(command.Parameter(2)) '字段名,多个字段名之间用“:”分割,大小写不敏感,去掉前后空格
|
||||
|
||||
'Dim upperArr = arr.Select(Function(x) x.ToUpper()).ToArray()
|
||||
' upperArr = {"A", "B", "C"}
|
||||
|
||||
_filedNames.AddRange(command.Parameter(2).Split(":"c).Select(Function(x) x.Trim()))
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
|
||||
Dim filedName As String = _filedNames(0)
|
||||
Dim updateString As String = $"t1.`{filedName}` = t2.`{filedName}`"
|
||||
For i As Integer = 1 To _filedNames.Count - 1
|
||||
filedName = _filedNames(i)
|
||||
updateString += $",t1.`{filedName}` = t2.`{filedName}` "
|
||||
Next
|
||||
|
||||
|
||||
Dim saveDbCmdText As String = String.Empty
|
||||
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Dim cmdText As String = $"UPDATE `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 On t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
|
||||
|
||||
Try
|
||||
db.Open()
|
||||
db.ExecuteNonQuery(cmdText)
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"数据库更新失败,{ex.Message}"
|
||||
End Try
|
||||
End Using
|
||||
|
||||
''本地存储
|
||||
'Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
' Try
|
||||
' db.Open()
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = "False"
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
' Try
|
||||
' Dim cmdText As String = $"UPDATE `{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 ON t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
|
||||
' db.ExecuteNonQuery(cmdText)
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = "False"
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库保存失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
|
||||
' '本地缓存
|
||||
' Try
|
||||
' If Not String.IsNullOrEmpty(saveDbCmdText) Then
|
||||
' DbConnector.SaveCmdStringToCacheTable(db, saveDbCmdText)
|
||||
' CommandReturn.ExecuteResultTipString = "本地缓存成功"
|
||||
' End If
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = "False"
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库缓存失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
|
||||
' db.Close()
|
||||
'End Using
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
@@ -0,0 +1,145 @@
|
||||
Imports UTS_Core.Database
|
||||
Imports UTS_Core.UTSModule
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class GetRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _filedName As String
|
||||
Private _dutSn As String
|
||||
Private _mode As String
|
||||
|
||||
Private _LowerLimit As String = ""
|
||||
Private _UpperLimit As String = ""
|
||||
Private _stringLen_LowwerLimit As String = ""
|
||||
Private _stringLen_UpperLimit As String = ""
|
||||
Private _Char_VerfiyMode As String = ""
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_dutSn = command.Parameter(0)
|
||||
_filedName = command.Parameter(1)
|
||||
_mode = command.Parameter(2) 'Local:只查询本地 Remote:只查询云端 Both:查询本地和云端(云端优先)
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub GetByLocal()
|
||||
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
Try
|
||||
db.Open()
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
Try
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.Search(_filedName, SnListTable.TableName, condition)
|
||||
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库查询成功"
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库查询失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
db.Close()
|
||||
End Using
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function GetByRemote() As Boolean
|
||||
Dim useLocalSearch As Boolean = False
|
||||
|
||||
|
||||
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.DbSearch(UtsDb.RemotePrivateDb, _filedName, SnListTable.TableName, condition)
|
||||
|
||||
Try
|
||||
db.Open()
|
||||
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
CommandReturn.ExecuteResult = True
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
useLocalSearch = True '云端查询失败,使用本地查询
|
||||
End Try
|
||||
End Using
|
||||
|
||||
Return useLocalSearch
|
||||
End Function
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Select Case _mode
|
||||
Case "Local", "0"
|
||||
GetByLocal()
|
||||
Case "Both", "2"
|
||||
If GetByRemote() = False Then GetByLocal()
|
||||
|
||||
Case "Remote", "1"
|
||||
GetByRemote()
|
||||
Case Else
|
||||
GetByRemote()
|
||||
End Select
|
||||
|
||||
'todo:数据验证
|
||||
|
||||
|
||||
|
||||
|
||||
''优先查询云端
|
||||
'Dim useLocalSearch As Boolean = False
|
||||
'Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
' Dim cmdText As String = db.CmdHelper.DbSearch(UtsDb.RemotePrivateDb, _filedName, SnListTable.TableName, condition)
|
||||
|
||||
' Try
|
||||
' db.Open()
|
||||
' CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
' CommandReturn.ExecuteResult = True
|
||||
' db.Close()
|
||||
' Catch ex As Exception
|
||||
' useLocalSearch = True '云端查询失败,使用本地查询
|
||||
' End Try
|
||||
'End Using
|
||||
|
||||
|
||||
''本地存储
|
||||
'If useLocalSearch Then
|
||||
' Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
' Try
|
||||
' db.Open()
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = ""
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
' Try
|
||||
' ' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
' Dim cmdText As String = db.CmdHelper.Search(_filedName, SnListTable.TableName, condition)
|
||||
' CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
' CommandReturn.ExecuteResult = True
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库查询成功"
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = ""
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库查询失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
' db.Close()
|
||||
' End Using
|
||||
'End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
@@ -19,7 +19,7 @@ Public Class SetRecordCommand
|
||||
_filedName = command.Parameter(1)
|
||||
_filedValue = command.Parameter(2)
|
||||
|
||||
|
||||
'todo:SetRecord 只能对自定义字段进行写入,保护字段不执行’
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
@@ -67,7 +67,7 @@ Public Class SetRecordCommand
|
||||
|
||||
'本地缓存
|
||||
Try
|
||||
If String.IsNullOrEmpty(saveDbCmdText) Then
|
||||
If Not String.IsNullOrEmpty(saveDbCmdText) Then
|
||||
DbConnector.SaveCmdStringToCacheTable(db, saveDbCmdText)
|
||||
CommandReturn.ExecuteResultTipString = "本地缓存成功"
|
||||
End If
|
||||
@@ -21,6 +21,12 @@
|
||||
executor = New GetDBDataExecutor(command)
|
||||
Case "Call"
|
||||
executor = New CallExecutor(command)
|
||||
Case "GetRecord"
|
||||
Return New GetRecordCommand(command)
|
||||
Case "SetRecord"
|
||||
Return New SetRecordCommand(command)
|
||||
Case "CombindRecord"
|
||||
Return New CombindRecordCommand(command)
|
||||
Case Else
|
||||
Throw New Exception($"System集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
Imports UTS_Core.UTSModule.Test.Command.ComPortCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.ConverterCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.ProcessCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.SystemCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.UtsComPortCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.ConverterCommand
|
||||
|
||||
Namespace UTSModule.Test.Command
|
||||
Public Class TestCommandManger
|
||||
|
||||
Reference in New Issue
Block a user