126 lines
4.1 KiB
VB.net
126 lines
4.1 KiB
VB.net
![]() |
Imports System.IO
|
|||
|
Imports System.Text
|
|||
|
|
|||
|
Public Class frmMqtt
|
|||
|
Private programForm As String = "DUALSONIC T/D MEASURING INSTRUMENT"
|
|||
|
|
|||
|
' TODO: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD> <20><>ȣ<EFBFBD><C8A3> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>ڵ带 <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>
|
|||
|
' (https://go.microsoft.com/fwlink/?LinkId=35339 <20><><EFBFBD><EFBFBD>).
|
|||
|
' <20><EFBFBD><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ü<EFBFBD><C3BC> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ü<EFBFBD><C3BC> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ÷<>ε<EFBFBD> <20><> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
|
|||
|
' My.User.CurrentPrincipal = CustomPrincipal
|
|||
|
' <20><><EFBFBD>⼭ CustomPrincipal<61><6C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD> IPrincipal<61><6C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Դϴ<D4B4>.
|
|||
|
' <20><><EFBFBD>߿<EFBFBD> My.User<65><72> CustomPrincipal <20><>ü<EFBFBD><C3BC> ĸ<><C4B8>ȭ<EFBFBD><C8AD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD>, ǥ<><C7A5> <20≯<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
' ID <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȯ<EFBFBD>մϴ<D5B4>.
|
|||
|
|
|||
|
Private Sub frmMqtt_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|||
|
Dim versionNum As String = "2.3.0"
|
|||
|
Me.Text = "DUALSONIC T/D MEASURING INSTRUMENT_" & versionNum & "- MQTT Setting"
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
|
|||
|
If txbMqttAd.Text = String.Empty Or txbMqttTp.Text = String.Empty Then
|
|||
|
MsgBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Է<EFBFBD><D4B7>Ͽ<EFBFBD> <20>ֽʽÿ<CABD>.", vbExclamation)
|
|||
|
GoTo failResult
|
|||
|
End If
|
|||
|
|
|||
|
If saveMqtt() = False Then
|
|||
|
GoTo failResult
|
|||
|
End If
|
|||
|
|
|||
|
If loadMqtt() = False Then
|
|||
|
GoTo failResult
|
|||
|
End If
|
|||
|
|
|||
|
Me.Close()
|
|||
|
Exit Sub
|
|||
|
|
|||
|
failResult:
|
|||
|
txbMqttAd.Text = String.Empty
|
|||
|
txbMqttTp.Text = String.Empty
|
|||
|
frmTD_JIG.mqttBroker = String.Empty
|
|||
|
frmTD_JIG.mqttTopic = String.Empty
|
|||
|
txbMqttAd.Focus()
|
|||
|
Exit Sub
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
|
|||
|
If loadMqtt() = False Then
|
|||
|
txbMqttAd.Text = String.Empty
|
|||
|
txbMqttTp.Text = String.Empty
|
|||
|
frmTD_JIG.mqttBroker = String.Empty
|
|||
|
frmTD_JIG.mqttTopic = String.Empty
|
|||
|
End If
|
|||
|
|
|||
|
Me.Close()
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Function saveMqtt() As Boolean
|
|||
|
Try
|
|||
|
Dim filePath, filename, saveStr As String
|
|||
|
|
|||
|
filePath = System.AppDomain.CurrentDomain.BaseDirectory() & "\Config"
|
|||
|
dirUse(filePath)
|
|||
|
filename = filePath & "\TD_Select_MQTT_Config.ini"
|
|||
|
|
|||
|
saveStr = txbMqttAd.Text & "^" & txbMqttTp.Text
|
|||
|
|
|||
|
If File.Exists(filename) Then
|
|||
|
File.Delete(filename)
|
|||
|
End If
|
|||
|
|
|||
|
File.WriteAllText(filename, saveStr, Encoding.UTF8)
|
|||
|
|
|||
|
Return True
|
|||
|
Catch ex As Exception
|
|||
|
MsgBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ::" & ex.Message, vbCritical)
|
|||
|
Return False
|
|||
|
End Try
|
|||
|
|
|||
|
End Function
|
|||
|
|
|||
|
Public Function loadMqtt() As Boolean
|
|||
|
Try
|
|||
|
Dim filePath, fileName, readData As String
|
|||
|
|
|||
|
filePath = System.AppDomain.CurrentDomain.BaseDirectory & "\Config"
|
|||
|
dirUse(filePath)
|
|||
|
fileName = filePath & "\TD_Select_MQTT_Config.ini"
|
|||
|
|
|||
|
If File.Exists(fileName) Then
|
|||
|
readData = File.ReadAllText(fileName, System.Text.Encoding.UTF8)
|
|||
|
If readData <> Nothing Or readData <> "" Then
|
|||
|
If UBound(Split(readData, "^")) = 1 Then
|
|||
|
txbMqttAd.Text = Mid(readData, 1, InStr(readData, "^") - 1)
|
|||
|
txbMqttTp.Text = Mid(readData, InStr(readData, "^") + 1, readData.Length)
|
|||
|
|
|||
|
frmTD_JIG.mqttBroker = txbMqttAd.Text
|
|||
|
frmTD_JIG.mqttTopic = txbMqttTp.Text
|
|||
|
|
|||
|
Return True
|
|||
|
ElseIf UBound(Split(readData, "^")) > 1 Then
|
|||
|
MsgBox("<EFBFBD>߸<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.", vbCritical)
|
|||
|
Return False
|
|||
|
Else
|
|||
|
Return False
|
|||
|
End If
|
|||
|
Else
|
|||
|
Return False
|
|||
|
End If
|
|||
|
Else
|
|||
|
Return False
|
|||
|
End If
|
|||
|
Catch ex As Exception
|
|||
|
MsgBox("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD> :: " + ex.Message & vbCritical)
|
|||
|
Return False
|
|||
|
End Try
|
|||
|
|
|||
|
End Function
|
|||
|
|
|||
|
Private Sub dirUse(filePath As String)
|
|||
|
If Dir(filePath, vbDirectory) = "" Then
|
|||
|
MkDir(filePath)
|
|||
|
End If
|
|||
|
End Sub
|
|||
|
|
|||
|
End Class
|