新增温控提示音版本控制分支和设备链表上传

This commit is contained in:
2026-03-10 10:08:36 +08:00
parent 20e71513ef
commit c26c2bf49c
13 changed files with 483 additions and 22833 deletions

View File

@@ -2,6 +2,7 @@
Imports System.Net
Imports System.Security.Cryptography
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Threading
Imports BLV_Studio.GridModel
Imports BLV_Studio.GridModel.DeviceEventModel
@@ -120,21 +121,21 @@ Public Class FrmMain
Else
If ImgLstMain.Images.Count = 0 Then Return
Dim imgindex As Integer = -1
Select Case ftpFlag
Case 0
imgindex = ImgLstMain.Images.IndexOfKey(Syncing.png)
If imgindex = -1 Then Return
FtpIcon_lab.Image = ImgLstMain.Images.Item(imgindex)
Case 1
imgindex = ImgLstMain.Images.IndexOfKey(Syncerror.png)
If imgindex = -1 Then Return
FtpIcon_lab.Image = ImgLstMain.Images.Item(imgindex)
Case 2
imgindex = ImgLstMain.Images.IndexOfKey(SyncTrue.png)
If imgindex = -1 Then Return
FtpIcon_lab.Image = ImgLstMain.Images.Item(imgindex)
End Select
End If
Select Case ftpFlag
Case 0
imgindex = ImgLstMain.Images.IndexOfKey(Syncing.png)
If imgindex = -1 Then Return
FtpIcon_lab.Image = ImgLstMain.Images.Item(imgindex)
Case 1
imgindex = ImgLstMain.Images.IndexOfKey(Syncerror.png)
If imgindex = -1 Then Return
FtpIcon_lab.Image = ImgLstMain.Images.Item(imgindex)
Case 2
imgindex = ImgLstMain.Images.IndexOfKey(SyncTrue.png)
If imgindex = -1 Then Return
FtpIcon_lab.Image = ImgLstMain.Images.Item(imgindex)
End Select
End If
End Sub
Public ricLabelGrb_li As New List(Of Control)
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
@@ -2423,33 +2424,33 @@ Public Class FrmMain
' Try
'生成文件夹
If CreateXmlPath() Then
'先运行规则检查
ruleCheckReslut = _grdModel.StartGobleRuleCheck(ruleCheck_ErrCnt, ruleCheck_WarningCnt)
'先运行规则检查
ruleCheckReslut = _grdModel.StartGobleRuleCheck(ruleCheck_ErrCnt, ruleCheck_WarningCnt)
'如果规则检查有错误则不允许编译
If ruleCheck_ErrCnt > 0 Then
MsgBox("规则检测不通过,请逐项处理后重新编译!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "编译失败..")
Return False
'如果规则检查有错误则不允许编译
If ruleCheck_ErrCnt > 0 Then
MsgBox("规则检测不通过,请逐项处理后重新编译!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "编译失败..")
Return False
Else
'填充配置信息
'_grdModel._ConfigInf
If _grdModel.Compile(compileErrMsg, savePath dic) = True Then
_grdModel.Save(savePath) '保存配置文件
If IsShowCompileResult Then MsgBox($"编译完成, 配置版本号:" & _grdModel._ConfigInfo.CfgFileVersion)
Return True
Else
'填充配置信息
'_grdModel._ConfigInf
If _grdModel.Compile(compileErrMsg, savePath dic) = True Then
_grdModel.Save(savePath) '保存配置文件
If IsShowCompileResult Then MsgBox($"编译完成, 配置版本号:" & _grdModel._ConfigInfo.CfgFileVersion)
Return True
Else
MsgBox(compileErrMsg, MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "编译失败.")
Return False
End If
MsgBox(compileErrMsg, MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "编译失败.")
Return False
End If
End If
End If
'Catch ex As Exception
' MsgBox($"编译失败,{ex.Message}")
' Return False
'End Try
'Catch ex As Exception
' MsgBox($"编译失败,{ex.Message}")
' Return False
'End Try
Return True
Return True
End Function
@@ -4649,8 +4650,8 @@ Public Class FrmMain
MsgBox("编译失败!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "创建项目文件失败..")
Return False
End If
Catch ex As exception
msgbox($"编译失败,{ex.message}")
Catch ex As Exception
MsgBox($"编译失败,{ex.Message}")
Return False
End Try
@@ -5156,18 +5157,301 @@ Public Class FrmMain
End Function
Private Sub ToolStripButton19_Click(sender As Object, e As EventArgs) Handles ToolStripButton19.Click
If Releaseflag And Not IsNothing(TvwMain.SelectedNode) Then
Else
MsgBox("请选择发布节点")
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))
End If
End If
UploadDeviceList(FVer)
End Sub
Public Sub UploadDeviceList(pzVer As Integer)
' 1. 参数验证
If Not Releaseflag OrElse IsNothing(TvwMain.SelectedNode) Then
MsgBox("请选择发布节点")
Return
End If
If IsNothing(_TableInteraction) Then
MsgBox("未选择模型")
Return
End If
Try
' 2. 获取数据
Dim aaa = _TableInteraction.TestReportingScenario1()
If IsNothing(aaa) Then
MsgBox("请先配置逻辑表")
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("设备列表上传成功")
Else
MsgBox("设备列表上传失败")
End If
End Using
Catch ex As Exception
MsgBox($"上传设备列表时发生错误: {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("请选择发布节点")
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))
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("请选择发布节点")
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("未选择模型")
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("设备列表上传成功")
Else
MsgBox("设备列表上传失败")
End If
End Using
Catch ex As Exception
MsgBox($"上传设备列表时发生错误: {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, (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).Text, attr2)
'继续遍历子节点
For k As Integer = 0 To node.Nodes(i).Nodes(j).Nodes.Count - 1
attr2.Add(node.Nodes(i).Nodes(j).Nodes(k).Text, 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 tnodename As String
If isRoot Then
'"设备存在组:DO设备组信息"
tnodename = $"设备存在组:{node.Nodes(i).name}设备组信息"
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
End If
Else
devtype = node.Nodes(i).DEV_TYPE_DATA
End If
Dim func As Dictionary(Of String, (String, String)) = New Dictionary(Of String, (String, String))
' 功能块名 ,类型值 ,别名,序号
' Dictionary(Of String, (String, Dictionary(Of String, String)))
updataDevnode.DevFunc.Add(node.Nodes(i).Text, (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).Text, (node.Nodes(i).Nodes(j).index + 1, node.Nodes(i).Nodes(j).deviceAlias))
Next
End If
End If
Next
Return updataDevnode
End Function
@@ -5258,3 +5542,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, (String, Dictionary(Of String, (String, String))))
End Class