Imports System.IO Imports BLV_Studio.UTSModule Public Class UpdataDevMode Public DbConnString As String = "Server=blv-cloud-db.mysql.rds.aliyuncs.com;Port=3307;Database=blv_rcu_db;Uid=blv_rcu;Pwd=fnadiaJDIJ7546;charset=utf8;" Public Author As String Private Sub UpdataDevMode_Load(sender As Object, e As EventArgs) Handles MyBase.Load UploadFileList = New Dictionary(Of String, String) InitGrid() InitGrid2() End Sub Public Sub InitGrid() Grid1.Rows = 1 Grid1.Cols = 5 Grid1.DisplayRowNumber = True Grid1.ExtendLastCol = True For i = 0 To 4 Select Case i Case 0 Grid1.Cell(0, i).Text = "ID" Case 1 Grid1.Cell(0, i).Text = "Name" Case 2 Grid1.Cell(0, i).Text = "MD5" Case 3 Grid1.Cell(0, i).Text = "Size" Case 4 Grid1.Cell(0, i).Text = "PATH" End Select Grid1.Column(i).Locked = True Next End Sub Public rmodedevtablenode As Dictionary(Of String, modedevtablenode) Public Sub InitGrid2() Grid2.Rows = 1 Grid2.Cols = 5 Grid2.DisplayRowNumber = True Grid2.ExtendLastCol = True For i = 0 To 4 Select Case i Case 0 Grid2.Cell(0, i).Text = "ID" Case 1 Grid2.Cell(0, i).Text = "UPdataTime" Case 2 Grid2.Cell(0, i).Text = "Name" Case 3 Grid2.Cell(0, i).Text = "MD5" Case 4 Grid2.Cell(0, i).Text = "PATH" ' Grid2.Cell(0, i).Text = "Size" Case 5 End Select Grid2.Column(i).Locked = True Next rmodedevtablenode = GetServerFile() For Each item In rmodedevtablenode Grid2.AddItem("") Grid2.Cell(Grid2.Rows - 1, 1).Text = item.Value.UploadDateTime Grid2.Cell(Grid2.Rows - 1, 4).Text = item.Value.Directory Grid2.Cell(Grid2.Rows - 1, 3).Text = item.Value.XLM_MD5 Grid2.Cell(Grid2.Rows - 1, 2).Text = item.Value.XML_FileName Next End Sub Public Function GetServerFile() Dim result As New Dictionary(Of String, modedevtablenode) Dim selectstr As String = $"SELECT * FROM `blv_rcu_db`.`tbl_model_file_data` ORDER BY `MFD_ID` DESC" 'Dim delete As String = $"DELETE FROM {tablename} WHERE HotelID ='{HotelID}' and RoomID='{RoomID}'" Dim dt As DataTable Dim mdtn As modedevtablenode Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString) db.Open() Try dt = db.ExecuteDataTable(selectstr) If IsNothing(dt) Then Return result For i As Integer = 0 To dt.Rows.Count - 1 mdtn = New modedevtablenode mdtn.MFD_ID = dt(i)("MFD_ID") mdtn.Available = dt(i)("Available") 'mdtn.Brand = dt(i)("Brand") 'mdtn.ModelNo = dt(i)("ModelNo") 'mdtn.ModelName = dt(i)("ModelName") 'mdtn.Description = dt(i)("Description") 'mdtn.Image = dt(i)("Image") mdtn.Directory = dt(i)("Directory") mdtn.XML_FileName = dt(i)("XML_FileName") 'mdtn.DAT_FileName = dt(i)("DAT_FileName") 'mdtn.Version = dt(i)("Version") mdtn.UploadDateTime = dt(i)("UploadDateTime") '判读Author 是否为dbnull If IsDBNull(dt(i)("Author")) Then mdtn.Author = "" Else mdtn.Author = dt(i)("Author") End If mdtn.XLM_MD5 = dt(i)("XLM_MD5") 'mdtn.DAT_MD5 = dt(i)("DAT_MD5") 'mdtn.PartNumber = dt(i)("PartNumber") 'mdtn.Remark = dt(i)("Remark") result.Add($"{dt(i)("XML_FileName")}", mdtn) Next db.Close() Catch ex As Exception db.Close() End Try End Using Return result End Function Public Function deleteServerFile(XML_FileName As String) As Boolean Dim result As Boolean = False Dim selectstr As String = $"DELETE FROM `blv_rcu_db`.`tbl_model_file_data` where XML_FileName='{XML_FileName}' " 'Dim delete As String = $"DELETE FROM {tablename} WHERE HotelID ='{HotelID}' and RoomID='{RoomID}'" Dim dt As Integer = 0 Dim mdtn As modedevtablenode Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString) db.Open() Try dt = db.ExecuteNonQuery(selectstr) If IsNothing(dt) OrElse dt = 0 Then Return result result = True db.Close() Catch ex As Exception db.Close() End Try End Using Return result End Function Private Sub ToolStripButton6_Click(sender As Object, e As EventArgs) Handles ToolStripButton6.Click '获取Grid1选中的行 Dim selectedRow As Integer = Grid1.ActiveCell.Row '获取选中的文件名称 Dim selectedFileName As String = Grid1.Cell(selectedRow, 1).Text '判断是否选中了有效行 If selectedRow > 0 Then '删除Grid1选中行(selectedRow) Grid1.RemoveItem(selectedRow) '判断文件在不在键值对 If UploadFileList.ContainsKey(selectedFileName) Then '删除键值对 UploadFileList.Remove(selectedFileName) End If End If End Sub '待上传文件列表变量 Public UploadFileList As Dictionary(Of String, String) Private Sub ToolStripButton4_Click(sender As Object, e As EventArgs) Handles ToolStripButton4.Click '打开文件选择器 设置打开的路径为根目录下BLV_Studio\Data\Model Dim OpenFileDialog1 As New OpenFileDialog() OpenFileDialog1.Filter = "XML Files (*.xml)|*.xml" OpenFileDialog1.InitialDirectory = Application.StartupPath & "\Data\Model" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then '将选中的文件名和文件路径填充键值对 If rmodedevtablenode.ContainsKey(OpenFileDialog1.SafeFileName) Then MsgBox("服务器已存在该文件!") Return End If If UploadFileList.ContainsKey(OpenFileDialog1.SafeFileName) Then MsgBox("文件已存在") Else '将选中的文件名和文件路径填充键值对 UploadFileList.Add(OpenFileDialog1.SafeFileName, OpenFileDialog1.FileName) End If End If 'Case 0 'Grid1.Cell(0, i).Text = "ID" 'Case 1 'Grid1.Cell(0, i).Text = "Name" 'Case 2 'Grid1.Cell(0, i).Text = "MD5" 'Case 3 'Grid1.Cell(0, i).Text = "Size" 'Case 4 'Grid1.Cell(0, i).Text = "PATH" Dim xmlmd5 As String Dim fileInfo As FileInfo Dim fileSize As Long Grid1.Rows = 1 For Each item In UploadFileList Grid1.AddItem("") Grid1.Cell(Grid1.Rows - 1, 1).Text = item.Key xmlmd5 = GetStringMd5(item.Value) Grid1.Cell(Grid1.Rows - 1, 2).Text = xmlmd5 '获取文件大小 fileInfo = New FileInfo(item.Value) fileSize = fileInfo.Length Grid1.Cell(Grid1.Rows - 1, 3).Text = fileSize Grid1.Cell(Grid1.Rows - 1, 4).Text = item.Value Next End Sub Private Sub UpdataDevMode_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed Me.DialogResult = System.Windows.Forms.DialogResult.OK Me.Close() Return End Sub Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click If String.IsNullOrEmpty(ToolStripComboBox1.Text) Then MsgBox("请选择上传的文件类型!") Return End If If UploadFileList.Count = 0 Then MsgBox("请选择上传的文件!") Return End If Dim strInputMsg As String = InputBox("请输入上传设备模型密码", "密码确认") If strInputMsg <> "Cc2022OK" Then Return '遍历UploadFileList Dim serverpath = $"\Data\Model\{ToolStripComboBox1.Text}" Dim tmp_FTP_Xml_FullName As String = "" Dim sqlstr As String = "" Dim insertstr As String = "" Dim dt As Integer = 0 For Each item In UploadFileList tmp_FTP_Xml_FullName = serverpath & "\" & item.Key If UtsFtp.CreateObject.FtpUploadBlv(tmp_FTP_Xml_FullName, item.Value) = 1 Then '插入一条数据库记录 insertstr = getInsertStr(serverpath, item.Key, item.Value) Using db As New DbExecutor(DbExecutor.DbTypeEnum.Mysql, DbConnString) db.Open() Try dt = db.ExecuteNonQuery(insertstr) db.Close() Catch ex As Exception db.Close() End Try End Using Else MsgBox("上传文件错误!") Return End If Next MsgBox("上传完成!") UpdataDevMode_Load(Nothing, Nothing) End Sub '生成插入一条数据库记录函数 Public Function getInsertStr(serverpath As String, filename As String, filepath As String) Dim md5 As String = GetStringMd5(filepath) Dim result As String = $"INSERT INTO `blv_rcu_db`.`tbl_model_file_data` (`Available` ,`Directory` ,`XML_FileName` ,`UploadDateTime` ,`Author` ,`XLM_MD5` ,`Remark`) VALUES (1,'{serverpath.Replace("\", "\\")}','{filename}','{Now}','{Author}','{md5}','配置上传~')" Return result End Function Private Sub ToolStripButton5_Click(sender As Object, e As EventArgs) Handles ToolStripButton5.Click Dim strInputMsg As String = InputBox("请输入删除设备模型密码", "密码确认") If strInputMsg <> "Cc2022OK" Then Return '获取Gri2的选择文件名 Dim selectedRow As Integer = Grid2.ActiveCell.Row Dim selectedFileName As String = Grid2.Cell(selectedRow, 2).Text '判断是否选中了有效行 If selectedRow > 0 Then If deleteServerFile(selectedFileName) Then '删除Grid2选中行(selectedRow) Grid2.RemoveItem(selectedRow) '判断文件在不在键值对 If rmodedevtablenode.ContainsKey(selectedFileName) Then '删除键值对 rmodedevtablenode.Remove(selectedFileName) End If Else MsgBox("删除失败!") End If End If End Sub End Class Public Class modedevtablenode Public MFD_ID As Integer Public Available As String Public Brand As String Public ModelNo As String Public ModelName As String Public Description As String Public Image As String Public Directory As String Public XML_FileName As String Public DAT_FileName As String Public Version As String Public UploadDateTime As String Public Author As String Public XLM_MD5 As String Public DAT_MD5 As String Public PartNumber As String Public Remark As String End Class