修复固件版本换算方式和设备上传报错
This commit is contained in:
@@ -4569,7 +4569,7 @@ Public Class FrmMain
|
||||
If Not String.IsNullOrEmpty(FirmwareVer) Then
|
||||
Dim Firbuf As String() = FirmwareVer.Split("_")
|
||||
If Firbuf.Length > 3 Then
|
||||
FVer = Convert.ToInt32(Firbuf(3))
|
||||
FVer = Convert.ToInt32(Firbuf(3), 16)
|
||||
End If
|
||||
End If
|
||||
If _TableInteraction.TableCompiletoByte(FVer, savePath, True) = True Then
|
||||
@@ -4841,6 +4841,317 @@ Public Class FrmMain
|
||||
|
||||
|
||||
|
||||
Private Sub ToolStripButton19_Click(sender As Object, e As EventArgs) Handles ToolStripButton19.Click
|
||||
If Releaseflag And Not IsNothing(TvwMain.SelectedNode) Then
|
||||
Else
|
||||
MsgBox("Please select the publishing node.")
|
||||
Return
|
||||
End If
|
||||
Dim TrNode As TreeNode = TvwMain.SelectedNode
|
||||
|
||||
If TrNode.Level > 1 Then
|
||||
TrNode = TrNode.Parent
|
||||
End If
|
||||
Dim FirmwareVer As String = TrNode.FirstNode.NextNode.NextNode.Text ' TrNode.NextVisibleNode.NextNode.Text
|
||||
Dim FVer As Integer = 0
|
||||
If Not String.IsNullOrEmpty(FirmwareVer) Then
|
||||
Dim Firbuf As String() = FirmwareVer.Split("_")
|
||||
If Firbuf.Length > 3 Then
|
||||
'将Firbuf(3)十六进制字符串转换为十进制
|
||||
|
||||
|
||||
FVer = Convert.ToInt32(Firbuf(3), 16)
|
||||
End If
|
||||
End If
|
||||
UploadDeviceList(FVer)
|
||||
End Sub
|
||||
|
||||
Public Sub UploadDeviceList(pzVer As Integer)
|
||||
' 1. 参数验证
|
||||
If Not Releaseflag OrElse IsNothing(TvwMain.SelectedNode) Then
|
||||
MsgBox("Please select the publishing node.")
|
||||
Return
|
||||
End If
|
||||
|
||||
If IsNothing(_TableInteraction) Then
|
||||
MsgBox("Unselected model")
|
||||
Return
|
||||
End If
|
||||
|
||||
Try
|
||||
' 2. 获取数据
|
||||
Dim aaa = _TableInteraction.TestReportingScenario1()
|
||||
If IsNothing(aaa) Then
|
||||
MsgBox("Please configure the logical table first.")
|
||||
Return
|
||||
End If
|
||||
|
||||
' 3. 序列化 JSON
|
||||
Dim device_list_json As String = JsonConvert.SerializeObject(aaa.TDevicemodel)
|
||||
|
||||
|
||||
|
||||
Dim hotel_id As Integer = _project.HotelIndex
|
||||
Dim roomtype_id As Integer = _project.RoomType(g_CurrentTreeNodeRoomTypeItemIndex).structRoomType_ID
|
||||
Dim createTime As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
|
||||
|
||||
' 5. 使用参数化查询
|
||||
Dim insertStr As String = "INSERT INTO `blv_rcu_db`.`tbl_room_type_device` " &
|
||||
"(`hotel_id`, `roomtype_id`, `device_list_json`, `version`, `create_time`) " &
|
||||
"VALUES (@hotel_id, @roomtype_id, @device_list_json, @version, @create_time)"
|
||||
|
||||
Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString)
|
||||
db.Open()
|
||||
|
||||
' 清空可能存在的旧参数
|
||||
db.ClearDbParameter()
|
||||
|
||||
'' 使用新的AddParameter方法添加参数
|
||||
'db.AddParameter("@hotel_id", hotel_id)
|
||||
'db.AddParameter("@roomtype_id", roomtype_id)
|
||||
'db.AddParameter("@device_list_json", device_list_json)
|
||||
'db.AddParameter("@version", pzVer)
|
||||
'db.AddParameter("@create_time", createTime)
|
||||
|
||||
' 使用明确的类型
|
||||
db.AddParameter("@hotel_id", hotel_id, DbType.Int32)
|
||||
db.AddParameter("@roomtype_id", roomtype_id, DbType.Int32)
|
||||
db.AddParameter("@device_list_json", device_list_json, DbType.String)
|
||||
db.AddParameter("@version", pzVer, DbType.Int32)
|
||||
db.AddParameter("@create_time", createTime, DbType.DateTime)
|
||||
|
||||
' 执行插入操作
|
||||
Dim result As Integer = db.ExecuteNonQuery(insertStr)
|
||||
|
||||
db.Close()
|
||||
|
||||
If result > 0 Then
|
||||
MsgBox("Device list upload successful")
|
||||
Else
|
||||
MsgBox("Upload of equipment list failed")
|
||||
End If
|
||||
End Using
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox($"An error occurred while uploading the device list.: {ex.Message}")
|
||||
' 记录详细错误日志
|
||||
LogError($"UploadDeviceList error: {ex.Message}{Environment.NewLine}{ex.StackTrace}")
|
||||
End Try
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
' JSON验证函数
|
||||
|
||||
|
||||
' 日志记录函数
|
||||
Private Sub LogError(message As String)
|
||||
Dim logPath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrorLog.txt")
|
||||
|
||||
Try
|
||||
File.AppendAllText(logPath, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {message}{Environment.NewLine}{Environment.NewLine}")
|
||||
Catch
|
||||
' 日志写入失败时不抛出异常
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton23_Click(sender As Object, e As EventArgs) Handles ToolStripButton23.Click
|
||||
If Releaseflag And Not IsNothing(TvwMain.SelectedNode) Then
|
||||
Else
|
||||
MsgBox("Please select the publishing node.")
|
||||
Return
|
||||
End If
|
||||
Dim TrNode As TreeNode = TvwMain.SelectedNode
|
||||
|
||||
If TrNode.Level > 1 Then
|
||||
TrNode = TrNode.Parent
|
||||
End If
|
||||
Dim FirmwareVer As String = TrNode.FirstNode.NextNode.NextNode.Text ' TrNode.NextVisibleNode.NextNode.Text
|
||||
Dim FVer As Integer = 0
|
||||
If Not String.IsNullOrEmpty(FirmwareVer) Then
|
||||
Dim Firbuf As String() = FirmwareVer.Split("_")
|
||||
If Firbuf.Length > 3 Then
|
||||
FVer = Convert.ToInt32(Firbuf(3), 16)
|
||||
End If
|
||||
End If
|
||||
UploadDeviceList1(FVer)
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
Public Sub UploadDeviceList1(pzVer As Integer)
|
||||
Dim headnode As RowNode
|
||||
headnode = _grdModel._rootNode
|
||||
Dim childnode, D485node, Virtualnode As RowNode
|
||||
'初始化treeview控件
|
||||
|
||||
Console.WriteLine("初始化treeview控件")
|
||||
|
||||
' 1. 参数验证
|
||||
If IsNothing(TvwMain.SelectedNode) Then
|
||||
MsgBox("Please select the publishing node.")
|
||||
Return
|
||||
End If
|
||||
childnode = headnode.Nodes(0)
|
||||
childnode = childnode.Nodes(0)
|
||||
|
||||
D485node = childnode.Nodes(1)
|
||||
Virtualnode = childnode.Nodes(2)
|
||||
|
||||
If IsNothing(_grdModel) OrElse IsNothing(_grdModel._rootNode) Then
|
||||
MsgBox("No model selected")
|
||||
Return
|
||||
End If
|
||||
Dim li As List(Of UpdataDevnode) = New List(Of UpdataDevnode)
|
||||
Dim hnode As UpdataDevnode = Extractnode(childnode, True)
|
||||
li.Add(hnode)
|
||||
For Each node In D485node.Nodes
|
||||
|
||||
For Each node2 In node.Nodes
|
||||
li.Add(Extractnode(node2))
|
||||
Next
|
||||
|
||||
|
||||
Next
|
||||
For Each node In Virtualnode.Nodes
|
||||
For Each node2 In node.Nodes
|
||||
li.Add(Extractnode(node2))
|
||||
Next
|
||||
Next
|
||||
|
||||
Try
|
||||
|
||||
|
||||
|
||||
' 3. 序列化 JSON
|
||||
Dim device_list_json As String = JsonConvert.SerializeObject(li)
|
||||
|
||||
|
||||
|
||||
Dim hotel_id As Integer = _project.HotelIndex
|
||||
Dim roomtype_id As Integer = _project.RoomType(g_CurrentTreeNodeRoomTypeItemIndex).structRoomType_ID
|
||||
Dim createTime As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
|
||||
|
||||
' 5. 使用参数化查询
|
||||
Dim insertStr As String = "INSERT INTO `blv_rcu_db`.`tbl_room_type_device` " &
|
||||
"(`hotel_id`, `roomtype_id`, `device_list_json`, `version`, `create_time`,`format`) " &
|
||||
"VALUES (@hotel_id, @roomtype_id, @device_list_json, @version, @create_time,@format)"
|
||||
|
||||
Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString)
|
||||
db.Open()
|
||||
|
||||
' 清空可能存在的旧参数
|
||||
db.ClearDbParameter()
|
||||
|
||||
'' 使用新的AddParameter方法添加参数
|
||||
'db.AddParameter("@hotel_id", hotel_id)
|
||||
'db.AddParameter("@roomtype_id", roomtype_id)
|
||||
'db.AddParameter("@device_list_json", device_list_json)
|
||||
'db.AddParameter("@version", pzVer)
|
||||
'db.AddParameter("@create_time", createTime)
|
||||
|
||||
' 使用明确的类型
|
||||
db.AddParameter("@hotel_id", hotel_id, DbType.Int32)
|
||||
db.AddParameter("@roomtype_id", roomtype_id, DbType.Int32)
|
||||
db.AddParameter("@device_list_json", device_list_json, DbType.String)
|
||||
db.AddParameter("@version", pzVer, DbType.Int32)
|
||||
db.AddParameter("@create_time", createTime, DbType.DateTime)
|
||||
db.AddParameter("@format", 0, DbType.Int32)
|
||||
' 执行插入操作
|
||||
Dim result As Integer = db.ExecuteNonQuery(insertStr)
|
||||
|
||||
db.Close()
|
||||
|
||||
If result > 0 Then
|
||||
MsgBox("The equipment list has been uploaded successfully.")
|
||||
Else
|
||||
MsgBox("The equipment list upload failed.")
|
||||
End If
|
||||
End Using
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox($"An error occurred while uploading the device list: {ex.Message}")
|
||||
' 记录详细错误日志
|
||||
LogError($"UploadDeviceList error: {ex.Message}{Environment.NewLine}{ex.StackTrace}")
|
||||
End Try
|
||||
|
||||
|
||||
End Sub
|
||||
Public Function Extractnode(node As RowNode, Optional isRoot As Boolean = False) As UpdataDevnode
|
||||
|
||||
|
||||
Dim updataDevnode As UpdataDevnode = New UpdataDevnode
|
||||
updataDevnode.DevName = node.Text
|
||||
|
||||
updataDevnode.DevAttr = New Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, String)))
|
||||
updataDevnode.DevFunc = New Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, (String, String)))))
|
||||
|
||||
''遍历节点默认第一个节点为设备属性
|
||||
For i As Integer = 0 To node.Nodes.Count - 1
|
||||
If i = 0 Then
|
||||
Dim attr As Dictionary(Of String, Dictionary(Of String, String)) = New Dictionary(Of String, Dictionary(Of String, String))
|
||||
updataDevnode.DevAttr.Add(node.Nodes(i).Text, attr)
|
||||
For j As Integer = 0 To node.Nodes(i).Nodes.Count - 1
|
||||
Dim attr2 As Dictionary(Of String, String) = New Dictionary(Of String, String)
|
||||
attr.Add(node.Nodes(i).Nodes(j).name, attr2)
|
||||
'继续遍历子节点
|
||||
For k As Integer = 0 To node.Nodes(i).Nodes(j).Nodes.Count - 1
|
||||
attr2.Add(node.Nodes(i).Nodes(j).Nodes(k).name, node.Nodes(i).Nodes(j).Nodes(k).devicetype.ToString)
|
||||
Next
|
||||
Next
|
||||
Else
|
||||
'判断节点名称不能为"RS485"、"VirtualObject"
|
||||
If node.Nodes(i).name <> "RS485" AndAlso node.Nodes(i).name <> "VirtualObject" Then
|
||||
'遍历节点的子节点
|
||||
Dim devtype As String = "0"
|
||||
Dim addr As String = "0"
|
||||
Dim tnodename As String
|
||||
If isRoot Then
|
||||
'"设备存在组:DO设备组信息"
|
||||
tnodename = $"{node.Nodes(i).name} device group information"
|
||||
If updataDevnode.DevAttr.Values(0).ContainsKey(tnodename) Then
|
||||
|
||||
If updataDevnode.DevAttr.Values(0)(tnodename).ContainsKey("DeviceType") Then
|
||||
devtype = updataDevnode.DevAttr.Values(0).Item(tnodename).Item("DeviceType")
|
||||
End If
|
||||
If updataDevnode.DevAttr.Values(0)(tnodename).ContainsKey("DeviceAddr") Then
|
||||
addr = updataDevnode.DevAttr.Values(0).Item(tnodename).Item("DeviceAddr")
|
||||
End If
|
||||
|
||||
End If
|
||||
Else
|
||||
devtype = node.Nodes(i).DEV_TYPE_DATA
|
||||
tnodename = "Device present"
|
||||
If updataDevnode.DevAttr.Values(0)(tnodename).ContainsKey("Dialing address") Then
|
||||
addr = updataDevnode.DevAttr.Values(0).Item(tnodename).Item("Dialing address")
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Dim func1 As New Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, (String, String))))
|
||||
Dim func2 As New Dictionary(Of String, Dictionary(Of String, (String, String)))
|
||||
Dim func As New Dictionary(Of String, (String, String))
|
||||
' 功能块名 , 类型值 , 功能块地址 别名,序号
|
||||
' Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, String)))
|
||||
func2.Add(addr, func)
|
||||
func1.Add(devtype, func2)
|
||||
updataDevnode.DevFunc.Add(node.Nodes(i).Text, func1) ' (devtype, func))
|
||||
|
||||
'Dim tag As AttributeRowNodeTag = node.Tag
|
||||
|
||||
For j As Integer = 0 To node.Nodes(i).Nodes.Count - 1
|
||||
|
||||
func.Add(node.Nodes(i).Nodes(j).index + 1, (node.Nodes(i).Nodes(j).Text, node.Nodes(i).Nodes(j).deviceAlias))
|
||||
|
||||
Next
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
|
||||
Next
|
||||
Return updataDevnode
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
@@ -4931,3 +5242,15 @@ Public Class RoomType
|
||||
' Public Property RoomType_OldID As String
|
||||
|
||||
End Class
|
||||
|
||||
<Serializable>
|
||||
Public Class UpdataDevnode
|
||||
'设备名称
|
||||
Public Property DevName As String
|
||||
'设备属性列表
|
||||
Public Property DevAttr As Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, String)))
|
||||
' 功能块名 , 类型值 , 功能块地址 序号 回路名 别名
|
||||
Public Property DevFunc As Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, (String, String)))))
|
||||
|
||||
End Class
|
||||
|
||||
|
||||
Reference in New Issue
Block a user