Imports System.IO Imports System.Text Public Class 計算機 Dim MACKK As String 'MAC碼 Dim diskId As String '數字ID Dim diskSerialNumber As String '硬碟序列 Dim diskModel As String '磁盘型態 Dim IP公, IP測1, IP測2, 內網線路, 可登入 As Boolean Private ReadOnly 對話框(15) As String Private Sub 初始化系統語言() If File.Exists(Application.StartupPath + "\LANGUAGE_FILE.csv") Then Dim filereader = My.Computer.FileSystem.OpenTextFileReader(Application.StartupPath + "\LANGUAGE_FILE.csv", System.Text.Encoding.Default) Dim line As String = filereader.ReadLine() While Not (line Is Nothing) line = filereader.ReadLine() If line <> Nothing Then line = line.Replace("""", "") : Dim separator As String = "-" : Dim result() As String = line.Split(separator) If result.Count > 4 Then Dim key As String = result(0).ToString() & "-" & result(1).ToString() & "-" & result(2).ToString() Dim value As String = result(3).ToString() For i As Integer = 4 To result.Count - 1 : value += "-" & result(i) : Next If value.EndsWith(",") Then : value = value.Substring(0, value.Length - 1) : End If : 系統語言字典.Add(key, value) Else Dim key As String = result(0).ToString() & "-" & result(1).ToString() & "-" & result(2).ToString() Dim value As String = result(3).ToString() If value.EndsWith(",") Then : value = value.Substring(0, value.Length - 1) : End If : 系統語言字典.Add(key, value) End If End If End While End If End Sub Private Sub 語言轉換讀取() End Sub Private Sub IP比對() If SQL_連線狀態模組3.ConnectTest3("192.168.1.6,2433") = True Then '---主伺服器導通------------------------------------------- IP公 = True : IP測1 = True : IP測2 = True : 伺服器區域_cb.Text = "公司內網" : 公司線路_rb.Checked = True : 測試線路_rb.Checked = False : 內網線路 = True 刷卡登入_ch.Checked = True Else Dim Str As String = Application.StartupPath If File.Exists(Str + "\HXLINE.txt") Then Dim filereader = My.Computer.FileSystem.OpenTextFileReader(Str + "\HXLINE.txt", System.Text.Encoding.Default) Dim Text As String = "" : Dim line As String = filereader.ReadLine() While Not (line Is Nothing) : Text = Text & line & vbCrLf : line = filereader.ReadLine() : End While : filereader.Close() If Strings.Left(Text, 10) = "3MBPS-LINE" Then : PA49 = "36.64.59.26,2433" ElseIf Strings.Left(Text, 11) = "20MBPS-LINE" Then : PA49 = "36.64.59.26,2433" : End If Else : 線路選擇.ShowDialog() : End If If SQL_連線狀態模組1.ConnectTest1(PA49) = True Then '---主伺服器導通------------------------------------------- IP公 = True : IP測1 = True : IP測2 = True : 伺服器區域_cb.Text = "公司雲端" : 公司線路_rb.Checked = True : 測試線路_rb.Checked = False : 內網線路 = False 刷卡登入_ch.Checked = True Else 線路選擇.ShowDialog() If PA49 = "106.1.48.106,4567" Then IP公 = True : IP測1 = True : IP測2 = True : 伺服器區域_cb.Text = "測試雲端" : 公司線路_rb.Checked = True : 測試線路_rb.Checked = False : 內網線路 = False 刷卡登入_ch.Checked = True Else IP公 = True : IP測1 = True : IP測2 = True : 伺服器區域_cb.Text = "公司雲端" : 公司線路_rb.Checked = True : 測試線路_rb.Checked = False : 內網線路 = False 刷卡登入_ch.Checked = True End If End If End If End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 初始化系統語言() : 後數_tb.Enabled = False : 前數_tb.Enabled = False : 算式_tb.Enabled = False Me.KeyPreview = True : Panel1.SendToBack() '-----電腦預設值------------------------------------------------------------------------------------------------------------------------------------------------------------------ Dim Str As String = Application.StartupPath If File.Exists(Str + "\LANGUAGE.txt") Then Dim filereader = My.Computer.FileSystem.OpenTextFileReader(Str + "\LANGUAGE.txt", System.Text.Encoding.Default) Dim Text As String = "" : Dim line As String = filereader.ReadLine() While Not (line Is Nothing) : Text &= line : line = filereader.ReadLine() : End While : filereader.Close() If Strings.Left(Text, 4) = "CHER" Then 系統語言_cb.Text = "繁體中文" : 系統語言 = "繁體中文" ElseIf Strings.Left(Text, 4) = "Engl" Then 系統語言_cb.Text = "English" : 系統語言 = "English" ElseIf Strings.Left(Text, 4) = "Indo" Then 系統語言_cb.Text = "Indonesian" : 系統語言 = "Indonesian" End If Else Dim strDirName As String : Dim Strs As String = Application.StartupPath If File.Exists(Strs & "\LANGUAGE.txt") Then : File.Delete(Strs & "\LANGUAGE.txt") : End If strDirName = Strs & "\LANGUAGE.txt" Try Using fs As New IO.FileStream(strDirName, FileMode.Append) Using sw As New StreamWriter(fs, Encoding.Default) Dim stra As String = "CHER" sw.WriteLine(stra) '插入一整行 sw.Flush() End Using End Using Catch ex As Exception : End Try 系統語言_cb.Text = "繁體中文" : 系統語言 = "繁體中文" End If IP比對() '-----電腦綁定判斷------------------------------------------------------------------------------------------------------------------------------------------------------------- PA1 = MACKK : PA2 = diskId : PA3 = diskSerialNumber : PA4 = diskModel SQL_電腦綁定() If dr.Read() Then 可登入 = True : PA50 = dr("使用者").ToString : conn.Close() Else 可登入 = False : conn.Close() End If End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 伺服器區域_cb.SelectedIndexChanged '-----------------------確認登入伺服器位置----------------------------------------------------------------------------------------------------------------------------------------- If 伺服器區域_cb.Text = "公司內網" Then If IP公 = True Then : 登入人IP = "192.168.1.6,2433" : Line通訊IP = "192.168.1.6,2433" : Line伺服器名稱 = "HX-LINE-AUTO" 登入() : 刷卡登入_ch.Checked = True : Else : MGB(對話框(11), 1) : Me.Close() : End If ElseIf 伺服器區域_cb.Text = "公司雲端" Then If IP公 = True Then : 登入人IP = PA49 : Line通訊IP = PA49 : Line伺服器名稱 = "HX-LINE-AUTO" 登入() : 刷卡登入_ch.Checked = True : Else : MGB(對話框(11), 1) : Me.Close() : End If ElseIf 伺服器區域_cb.Text = "測試雲端" Then If IP測1 = True Then : 登入人IP = "106.1.48.106,4567" : Line通訊IP = "36.64.59.26,2433" : Line伺服器名稱 = "HX-LINE-AUTO" 登入() : 刷卡登入_ch.Checked = True : Else : MGB(對話框(11), 1) : Me.Close() : End If ElseIf 伺服器區域_cb.Text = "印尼測試" Then If IP測2 = True Then : 登入人IP = "172.1.1.189,2433" : Line通訊IP = "192.168.1.6,2433" : Line伺服器名稱 = "HX-LINE-AUTO" If SQL_連線狀態模組2.ConnectTest2("172.1.1.189,2433") = True Then : 登入() : 刷卡登入_ch.Checked = True : Else : MGB(對話框(11), 1) : Me.Close() : End If Else : MGB(對話框(11), 1) : Me.Close() : End If End If End Sub Private Sub 登入() '-----------------------寫入連線字串----------------------------------------------------------------------------------------------------------------------------------------------- If Strings.Left(伺服器區域_cb.Text, 2) = "印尼" Or Strings.Left(伺服器區域_cb.Text, 2) = "公司" Then SQL_連線字串_正式() : SQL_連線字串_正式_工程SQL() : SQL_連線字串_正式_管理SQL() Else SQL_連線字串_測試() : SQL_連線字串_測試_工程SQL() : SQL_連線字串_測試_管理SQL() End If g_conn_type = 伺服器區域_cb.Text & "伺服器" '-----------------------系統版本號寫入----------------------------------------------------------------------------------------------------------------------------------------------- SQL_系統版本號驗證() If dr.Read() Then : 資料庫版本 = dr("內帳系統") : 版本號 = dr("內帳系統") : End If : conn.Close() 語言轉換讀取() 系統語言_cb.Items.Clear() : 系統語言_cb.Items.Add("繁體中文") : 系統語言_cb.Items.Add("Indonesian") : 系統語言_cb.Items.Add("English") '-----MAC碼與硬碟資料------------------------------------------------------------------------------------------------------------------------------------------------------------- Dim Wmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration") For Each WmiObj As Management.ManagementObject In Wmi.Get If CBool(WmiObj("IPEnabled")) Then MACKK = WmiObj("MACAddress") End If Next Dim cmicWmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive") For Each cmicWmiObj As Management.ManagementObject In cmicWmi.Get diskId = cmicWmiObj("size") 'diskId = cmicWmiObj("signature") diskSerialNumber = cmicWmiObj("serialnumber") diskModel = cmicWmiObj("Model") Exit For Next End Sub Private verificationCode As String Private verificationStartTime As DateTime Dim currentTime As DateTime Dim elapsedTime As TimeSpan Private Sub GenerateVerificationCode() Dim random As New Random() : verificationCode = random.Next(10000000, 99999999).ToString() : verificationStartTime = DateTime.Now : LIN訊息通知("CC260", PA50, verificationCode) End Sub Private Sub Form_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown Select Case e.KeyCode Case Keys.NumPad1 : Me.ActiveControl = Button1 : Button1.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad2 : Me.ActiveControl = Button2 : Button2.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad3 : Me.ActiveControl = Button3 : Button3.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad4 : Me.ActiveControl = Button4 : Button4.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad5 : Me.ActiveControl = Button5 : Button5.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad6 : Me.ActiveControl = Button6 : Button6.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad7 : Me.ActiveControl = Button7 : Button7.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad8 : Me.ActiveControl = Button8 : Button8.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad9 : Me.ActiveControl = Button9 : Button9.PerformClick() : Me.ActiveControl = Button18 Case Keys.NumPad0 : Me.ActiveControl = Button10 : Button10.PerformClick() : Me.ActiveControl = Button18 Case Keys.Decimal : Me.ActiveControl = Button12 : Button12.PerformClick() : Me.ActiveControl = Button18 Case Keys.D1 : Me.ActiveControl = Button1 : Button1.PerformClick() : Me.ActiveControl = Button18 Case Keys.D2 : Me.ActiveControl = Button2 : Button2.PerformClick() : Me.ActiveControl = Button18 Case Keys.D3 : Me.ActiveControl = Button3 : Button3.PerformClick() : Me.ActiveControl = Button18 Case Keys.D4 : Me.ActiveControl = Button4 : Button4.PerformClick() : Me.ActiveControl = Button18 Case Keys.D5 : Me.ActiveControl = Button5 : Button5.PerformClick() : Me.ActiveControl = Button18 Case Keys.D6 : Me.ActiveControl = Button6 : Button6.PerformClick() : Me.ActiveControl = Button18 Case Keys.D7 : Me.ActiveControl = Button7 : Button7.PerformClick() : Me.ActiveControl = Button18 Case Keys.D8 : Me.ActiveControl = Button8 : Button8.PerformClick() : Me.ActiveControl = Button18 Case Keys.D9 : Me.ActiveControl = Button9 : Button9.PerformClick() : Me.ActiveControl = Button18 Case Keys.D0 : Me.ActiveControl = Button10 : Button10.PerformClick() : Me.ActiveControl = Button18 Case Keys.OemPeriod : Me.ActiveControl = Button12 : Button12.PerformClick() : Me.ActiveControl = Button18 Case Keys.Delete : Me.ActiveControl = Button11 : Button11.PerformClick() : Me.ActiveControl = Button18 Case Keys.Multiply : Me.ActiveControl = Button15 : Button15.PerformClick() : Me.ActiveControl = Button18 Case Keys.Subtract : Me.ActiveControl = Button14 : Button14.PerformClick() : Me.ActiveControl = Button18 Case Keys.OemMinus : Me.ActiveControl = Button14 : Button14.PerformClick() : Me.ActiveControl = Button18 Case Keys.Add : Me.ActiveControl = Button13 : Button13.PerformClick() : Me.ActiveControl = Button18 Case Keys.Oemplus : Me.ActiveControl = Button13 : Button13.PerformClick() : Me.ActiveControl = Button18 Case Keys.Oem2 : Me.ActiveControl = Button16 : Button16.PerformClick() : Me.ActiveControl = Button18 Case Keys.Divide : Me.ActiveControl = Button16 : Button16.PerformClick() : Me.ActiveControl = Button18 Case Keys.Back : Me.ActiveControl = Button11 : Button11.PerformClick() : Me.ActiveControl = Button18 Case Keys.Return : Me.ActiveControl = Button11 : Button11.PerformClick() : Me.ActiveControl = Button18 End Select End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 1 : Else : 後數_tb.Text = 1 : End If : 計算呈現() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 2 : Else : 後數_tb.Text = 2 : End If : 計算呈現() End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 3 : Else : 後數_tb.Text = 3 : End If : 計算呈現() End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 4 : Else : 後數_tb.Text = 4 : End If : 計算呈現() End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 5 : Else : 後數_tb.Text = 5 : End If : 計算呈現() End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 6 : Else : 後數_tb.Text = 6 : End If : 計算呈現() End Sub Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 7 : Else : 後數_tb.Text = 7 : End If : 計算呈現() End Sub Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 8 : Else : 後數_tb.Text = 8 : End If : 計算呈現() End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 9 : Else : 後數_tb.Text = 9 : End If : 計算呈現() End Sub Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & 0 : Else : 後數_tb.Text = 0 : End If : 計算呈現() End Sub Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click If 後數_tb.Text <> "" Then : 後數_tb.Text = 後數_tb.Text & "." : Else : 後數_tb.Text = "0." : End If : 計算呈現() End Sub '----------------------------數字鍵盤--------------------------------------------------------------------------------------------------------------- Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click Dim SS As Integer If 後數_tb.Text <> "" Then : 後數_tb.Text = Int(Val(後數_tb.Text) / 10) ElseIf 後數_tb.Text = "" And 前數_tb.Text <> "" Then : SS = Len(前數_tb.Text) : 前數_tb.Text = Strings.Left(前數_tb.Text, SS - 1) Else : 後數_tb.Text = "" : End If : 計算呈現() End Sub Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click Button18.PerformClick() If 後數_tb.Text <> "" And 前數_tb.Text = "" Then : 前數_tb.Text = 後數_tb.Text : 後數_tb.Text = "" : End If If 後數_tb.Text <> "" And 前數_tb.Text <> "" Then : 前數_tb.Text = Val(前數_tb.Text) / Val(後數_tb.Text) : 後數_tb.Text = "" : End If 算式_tb.Text = "/" : 計算呈現() End Sub Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click Button18.PerformClick() If 後數_tb.Text <> "" And 前數_tb.Text = "" Then : 前數_tb.Text = 後數_tb.Text : 後數_tb.Text = "" : End If If 後數_tb.Text <> "" And 前數_tb.Text <> "" Then : 前數_tb.Text = Val(後數_tb.Text) * Val(前數_tb.Text) : 後數_tb.Text = "" : End If 算式_tb.Text = "X" : 計算呈現() End Sub Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click Button18.PerformClick() If 後數_tb.Text <> "" And 前數_tb.Text = "" Then : 前數_tb.Text = 後數_tb.Text : 後數_tb.Text = "" : End If If 後數_tb.Text <> "" And 前數_tb.Text <> "" Then : 前數_tb.Text = Val(後數_tb.Text) + Val(前數_tb.Text) : 後數_tb.Text = "" : End If 算式_tb.Text = "+" : 計算呈現() End Sub Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click Button18.PerformClick() If 後數_tb.Text <> "" And 前數_tb.Text = "" Then : 前數_tb.Text = 後數_tb.Text : 後數_tb.Text = "" : End If If 後數_tb.Text <> "" And 前數_tb.Text <> "" Then : 前數_tb.Text = Val(前數_tb.Text) - Val(後數_tb.Text) : 後數_tb.Text = "" : End If 算式_tb.Text = "-" : 計算呈現() End Sub Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click 後數_tb.Text = "" : 前數_tb.Text = "" : 算式_tb.Text = "" : 合計_tb.Text = "" : 計算呈現() End Sub Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles 前數_tb.TextChanged 合計_tb.Text = 前數_tb.Text If 前數_tb.Text = "" Then : Else If 前數_tb.Text - Int(前數_tb.Text) <> 0 Then : 合計_tb.Text = Format(Val(合計_tb.Text), "#,##0.0000") : Else : 合計_tb.Text = Format(Val(合計_tb.Text), "#,##0") : End If End If If Val(前數_tb.Text) > 9.99973000350998E+85 Then : MsgBox("EFFORT错误!结果过大请点击AC重新启动!!!") : End If End Sub Private Sub 計算() If 後數_tb.Text <> "" And 前數_tb.Text <> "" Then If 算式_tb.Text = "X" Then : 前數_tb.Text = Val(後數_tb.Text) * Val(前數_tb.Text) : 後數_tb.Text = "" : End If If 算式_tb.Text = "/" Then : 前數_tb.Text = Val(前數_tb.Text) / Val(後數_tb.Text) : 後數_tb.Text = "" : End If If 算式_tb.Text = "+" Then : 前數_tb.Text = Val(後數_tb.Text) + Val(前數_tb.Text) : 後數_tb.Text = "" : End If If 算式_tb.Text = "-" Then : 前數_tb.Text = Val(前數_tb.Text) - Val(後數_tb.Text) : 後數_tb.Text = "" : End If Else : End If : 計算呈現() End Sub Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click If 可登入 = False Then : 計算() : Else If verificationCode = "" Then : 計算() : Else currentTime = DateTime.Now elapsedTime = currentTime - verificationStartTime If elapsedTime.TotalMinutes <= 0.5 Then If 呈現_tb.Text = verificationCode Then : Me.Hide() : LoginForm1.Show() : verificationCode = "" : Else : 計算() : End If Else : 計算() : End If End If End If End Sub Private Sub 計算呈現() If 後數_tb.Text <> "" And 算式_tb.Text = "" And 前數_tb.Text = "" And 合計_tb.Text = "" Then : 呈現_tb.Text = 後數_tb.Text ElseIf 後數_tb.Text = "" And 算式_tb.Text <> "" And 前數_tb.Text <> "" And 合計_tb.Text = "" Then : 呈現_tb.Text = 前數_tb.Text ElseIf 後數_tb.Text = "" And 算式_tb.Text <> "" And 前數_tb.Text <> "" And 合計_tb.Text <> "" Then : 呈現_tb.Text = 合計_tb.Text ElseIf 後數_tb.Text = "" And 算式_tb.Text <> "" And 前數_tb.Text = "" And 合計_tb.Text = "" Then : 呈現_tb.Text = "0" ElseIf 後數_tb.Text = "" And 算式_tb.Text = "" And 前數_tb.Text = "" And 合計_tb.Text = "" Then : 呈現_tb.Text = "0" ElseIf 後數_tb.Text <> "" And 算式_tb.Text <> "" And 前數_tb.Text <> "" And 合計_tb.Text <> "" And CLng(前數_tb.Text) = CLng(合計_tb.Text) Then 呈現_tb.Text = Strings.Format(CDbl(前數_tb.Text), "#,##0.00") & " " & 算式_tb.Text & " " & Strings.Format(CDbl(後數_tb.Text), "#,##0.00") ElseIf 後數_tb.Text <> "" And 算式_tb.Text <> "" And 前數_tb.Text <> "" And 合計_tb.Text <> "" And CLng(前數_tb.Text) <> CLng(合計_tb.Text) Then 呈現_tb.Text = 合計_tb.Text End If End Sub Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click If 可登入 = False Then Dim result As Double = Math.Sqrt(CDbl(呈現_tb.Text)) 呈現_tb.Text = Strings.Format(result, "#,##0.0000") Else : GenerateVerificationCode() : 呈現_tb.Text = "0" : End If End Sub End Class