diff --git a/.vs/BLV_Studio/v16/.suo b/.vs/BLV_Studio/v16/.suo index 882f666..d000650 100644 Binary files a/.vs/BLV_Studio/v16/.suo and b/.vs/BLV_Studio/v16/.suo differ diff --git a/BLV_Studio/Database/DbExecutor.vb b/BLV_Studio/Database/DbExecutor.vb index 6e8877a..2bee45c 100644 --- a/BLV_Studio/Database/DbExecutor.vb +++ b/BLV_Studio/Database/DbExecutor.vb @@ -374,4 +374,81 @@ Public Class DbExecutor GC.Collect() '对所有缓存垃圾进行回收 End Sub + + + ''' + ''' 添加参数到命令(简化版本,自动推断参数类型) + ''' + ''' 参数名称(需包含@或:前缀) + ''' 参数值 + ''' 创建的DbParameter对象 + Public Function AddParameter(parameterName As String, value As Object) As DbParameter + ' 自动根据值类型推断DbType + Dim dbType As DbType + Dim convertedValue As Object = value + + If value Is Nothing OrElse DBNull.Value.Equals(value) Then + dbType = DbType.Object + convertedValue = DBNull.Value + Else + Select Case value.GetType() + Case GetType(Integer) + dbType = DbType.Int32 + Case GetType(String) + dbType = DbType.String + Case GetType(Boolean) + dbType = DbType.Boolean + Case GetType(DateTime) + dbType = DbType.DateTime + Case GetType(Decimal) + dbType = DbType.Decimal + Case GetType(Double) + dbType = DbType.Double + Case GetType(Single) + dbType = DbType.Single + Case GetType(Byte()) + dbType = DbType.Binary + Case GetType(Guid) + dbType = DbType.Guid + Case Else + dbType = DbType.Object + End Select + End If + + ' 调用现有的AddDbParameter方法 + Return AddDbParameter(dbType, parameterName, convertedValue) + End Function + + ''' + ''' 添加参数到命令(指定明确的类型) + ''' + ''' 参数名称 + ''' 参数值 + ''' 参数的数据类型 + ''' 创建的DbParameter对象 + Public Function AddParameter(parameterName As String, value As Object, dbType As DbType) As DbParameter + Dim convertedValue As Object = value + + ' 处理空值 + If value Is Nothing OrElse DBNull.Value.Equals(value) Then + convertedValue = DBNull.Value + End If + + Return AddDbParameter(dbType, parameterName, convertedValue) + End Function + + ''' + ''' 添加参数到命令(包含方向) + ''' + ''' 参数名称 + ''' 参数值 + ''' 参数的数据类型 + ''' 参数方向(输入/输出) + ''' 创建的DbParameter对象 + Public Function AddParameter(parameterName As String, value As Object, dbType As DbType, direction As ParameterDirection) As DbParameter + Dim param = AddParameter(parameterName, value, dbType) + param.Direction = direction + Return param + End Function + End Class \ No newline at end of file diff --git a/BLV_Studio/FrmMain.Designer.vb b/BLV_Studio/FrmMain.Designer.vb index 7574d77..e0a7d90 100644 --- a/BLV_Studio/FrmMain.Designer.vb +++ b/BLV_Studio/FrmMain.Designer.vb @@ -265,6 +265,7 @@ Partial Class FrmMain Me.tsb_SyncConfigFiles = New System.Windows.Forms.ToolStripButton() Me.ToolStripButton4 = New System.Windows.Forms.ToolStripButton() Me.ToolStripButton17 = New System.Windows.Forms.ToolStripButton() + Me.ToolStripButton23 = New System.Windows.Forms.ToolStripButton() Me.MsMain.SuspendLayout() Me.StatusStrip1.SuspendLayout() Me.CmsEvent.SuspendLayout() @@ -1140,17 +1141,15 @@ Partial Class FrmMain ' 'ToolStripButton19 ' - Me.ToolStripButton19.Enabled = False Me.ToolStripButton19.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte)) Me.ToolStripButton19.ForeColor = System.Drawing.Color.Black Me.ToolStripButton19.Image = CType(resources.GetObject("ToolStripButton19.Image"), System.Drawing.Image) Me.ToolStripButton19.ImageTransparentColor = System.Drawing.Color.Magenta Me.ToolStripButton19.Name = "ToolStripButton19" - Me.ToolStripButton19.Size = New System.Drawing.Size(33, 37) - Me.ToolStripButton19.Text = "导出" + Me.ToolStripButton19.Size = New System.Drawing.Size(81, 37) + Me.ToolStripButton19.Text = "上传设备信息" Me.ToolStripButton19.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText Me.ToolStripButton19.ToolTipText = "将文件导出到Excel表格" - Me.ToolStripButton19.Visible = False ' 'ToolStripSeparator22 ' @@ -1580,7 +1579,7 @@ Partial Class FrmMain ' 'ToolStrip2 ' - Me.ToolStrip2.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsb_ReleaseToProjcet, Me.ToolStripSeparator7, Me.tsb_RuleCheck, Me.tsb_Compile, Me.tsb_DownLoad, Me.ToolStripSeparator4, Me.TsBtnNewFile, Me.TsBtnLoad, Me.tsb_SaveFile, Me.TsBtnSaveAs, Me.tsb_OpenFileFolder, Me.ToolStripSeparator6, Me.TsBtnAddModel, Me.TsBtnAddActions, Me.TsBtnAddDev, Me.TsBtnAddCondition, Me.TsBtnAddAction, Me.tsb_ExportToExcel, Me.ToolStripSeparator13, Me.UploadFirmware_btn, Me.ToolStripSeparator17}) + Me.ToolStrip2.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsb_ReleaseToProjcet, Me.ToolStripSeparator7, Me.tsb_RuleCheck, Me.tsb_Compile, Me.tsb_DownLoad, Me.ToolStripSeparator4, Me.TsBtnNewFile, Me.TsBtnLoad, Me.tsb_SaveFile, Me.TsBtnSaveAs, Me.tsb_OpenFileFolder, Me.ToolStripSeparator6, Me.TsBtnAddModel, Me.TsBtnAddActions, Me.TsBtnAddDev, Me.TsBtnAddCondition, Me.TsBtnAddAction, Me.tsb_ExportToExcel, Me.ToolStripSeparator13, Me.UploadFirmware_btn, Me.ToolStripSeparator17, Me.ToolStripButton23}) Me.ToolStrip2.Location = New System.Drawing.Point(3, 3) Me.ToolStrip2.Name = "ToolStrip2" Me.ToolStrip2.Size = New System.Drawing.Size(987, 40) @@ -2706,6 +2705,17 @@ Partial Class FrmMain Me.ToolStripButton17.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText Me.ToolStripButton17.Visible = False ' + 'ToolStripButton23 + ' + Me.ToolStripButton23.ForeColor = System.Drawing.Color.Blue + Me.ToolStripButton23.Image = CType(resources.GetObject("ToolStripButton23.Image"), System.Drawing.Image) + Me.ToolStripButton23.ImageTransparentColor = System.Drawing.Color.Magenta + Me.ToolStripButton23.Name = "ToolStripButton23" + Me.ToolStripButton23.Size = New System.Drawing.Size(60, 37) + Me.ToolStripButton23.Text = "上传设备" + Me.ToolStripButton23.TextAlign = System.Drawing.ContentAlignment.MiddleRight + Me.ToolStripButton23.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText + ' 'FrmMain ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!) @@ -3031,4 +3041,5 @@ Partial Class FrmMain Friend WithEvents lab_RoomType As Label Friend WithEvents ToolStripButton17 As ToolStripButton Friend WithEvents TvwMain As TreeViewEx + Friend WithEvents ToolStripButton23 As ToolStripButton End Class diff --git a/BLV_Studio/FrmMain.vb b/BLV_Studio/FrmMain.vb index 886bbd1..18e8fdc 100644 --- a/BLV_Studio/FrmMain.vb +++ b/BLV_Studio/FrmMain.vb @@ -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 + + +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 + diff --git a/BLV_Studio/Test/GridTest/ReportingScenario.vb b/BLV_Studio/Test/GridTest/ReportingScenario.vb index cf05aac..4cce31e 100644 --- a/BLV_Studio/Test/GridTest/ReportingScenario.vb +++ b/BLV_Studio/Test/GridTest/ReportingScenario.vb @@ -16,6 +16,10 @@ Public Class ReportingScenario 'Runing(grd, Devicemodel, ActionConfiguration) End Sub + Sub New(grd As FlexCell.Grid, Devicemodel As Dictionary(Of String, DeviceModel)) + Tgrd = grd + TDevicemodel = Devicemodel + End Sub '配置名称 Public ConfigurationName As String '配置版本 diff --git a/BLV_Studio/Test/GridTest/TableInteraction.vb b/BLV_Studio/Test/GridTest/TableInteraction.vb index 2d00569..d40f267 100644 --- a/BLV_Studio/Test/GridTest/TableInteraction.vb +++ b/BLV_Studio/Test/GridTest/TableInteraction.vb @@ -7141,6 +7141,10 @@ ON DUPLICATE KEY UPDATE {updatastr};" GetAccountAuth(nsurl, str) Return aaa End Function + Public Function TestReportingScenario1() As ReportingScenario + Dim aaa As New ReportingScenario( _grd, Dic_Devicemodel) + Return aaa + End Function Private Function GetAccountAuth(url As String, data As String) As Boolean Dim jsonString As String = HttpMothod.PostData2(url, data) If String.IsNullOrWhiteSpace(jsonString) OrElse jsonString.ToUpper.Contains("False".ToUpper) Then diff --git a/BLV_Studio/bin/Debug/BLV_Studio.xml b/BLV_Studio/bin/Debug/BLV_Studio.xml index f9c3f8f..86674d9 100644 --- a/BLV_Studio/bin/Debug/BLV_Studio.xml +++ b/BLV_Studio/bin/Debug/BLV_Studio.xml @@ -7452,6 +7452,33 @@ BLV_Studio 回收资源 + + + 添加参数到命令(简化版本,自动推断参数类型) + + 参数名称(需包含@或:前缀) + 参数值 + 创建的DbParameter对象 + + + + 添加参数到命令(指定明确的类型) + + 参数名称 + 参数值 + 参数的数据类型 + 创建的DbParameter对象 + + + + 添加参数到命令(包含方向) + + 参数名称 + 参数值 + 参数的数据类型 + 参数方向(输入/输出) + 创建的DbParameter对象 + 查询指定数据表的信息 diff --git a/BLV_Studio/obj/Debug/BLV_Studio.xml b/BLV_Studio/obj/Debug/BLV_Studio.xml index f9c3f8f..86674d9 100644 --- a/BLV_Studio/obj/Debug/BLV_Studio.xml +++ b/BLV_Studio/obj/Debug/BLV_Studio.xml @@ -7452,6 +7452,33 @@ BLV_Studio 回收资源 + + + 添加参数到命令(简化版本,自动推断参数类型) + + 参数名称(需包含@或:前缀) + 参数值 + 创建的DbParameter对象 + + + + 添加参数到命令(指定明确的类型) + + 参数名称 + 参数值 + 参数的数据类型 + 创建的DbParameter对象 + + + + 添加参数到命令(包含方向) + + 参数名称 + 参数值 + 参数的数据类型 + 参数方向(输入/输出) + 创建的DbParameter对象 + 查询指定数据表的信息