Option Explicit On
Imports System.IO
Public Class LoginForm1
    Dim MACKK As String 'MAC碼
    Dim diskId As String '數字ID
    Dim diskSerialNumber As String '硬碟序列
    Dim diskModel As String '磁盘型態
    Private Property MYSQL As String
    ReadOnly ds As Object
    ReadOnly ds2 As New DataSet
    ReadOnly screenWidth = Screen.PrimaryScreen.Bounds.Width
    ReadOnly screenHeight = Screen.PrimaryScreen.Bounds.Height
    Private Sub SQL_使用者下拉清單載入()
        SQL_使用者下拉清單() : 使用者_cb.Items.Clear()
        While (dr.Read()) : 使用者_cb.Items.Add(dr("UserName")) : End While : conn.Close()
    End Sub
    Private Sub LoginForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SQL_連線字串_考勤() : SQL_連線字串_ERP()
        '-----------------------登入準備-----------------------------------------------------------------------------------------------------------------------------------------------
        SQL_使用者下拉清單載入()
        '-----------------------調整視窗大小-----------------------------------------------------------------------------------------------------------------------------------------------
        Me.Size = New Size(470, 288)
        If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(725, 396)
        ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(448, 240)
        ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(485, 306)
        ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(405, 368)
        ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(565, 306)
        End If
        '-----------------------系統版本號寫入-----------------------------------------------------------------------------------------------------------------------------------------------
        SQL_系統版本號讀取()
        If dr.Read() Then
            Label2.Text = "資料庫版本號 : " & dr("系統認證版本號") : 版本號 = dr("系統認證版本號")
        End If : conn.Close()
        Label1.Text = "執行檔版本號 : " & 版本
        '-----------------------FTP伺服器登入位置--------------------------------------------------------------------------------------------------------------------------------------------
        Target = "https://gcm-smart.com/ERP/HSKIN/"
        '-----------------------系統版本號驗證-----------------------------------------------------------------------------------------------------------------------------------------------
        If Strings.Right(Label1.Text, 10) <> Strings.Right(Label2.Text, 10) Then
            自動更新2()
        Else : End If
        '-----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
        '-----電腦綁定判斷-------------------------------------------------------------------------------------------------------------------------------------------------------------
        PA1 = MACKK : PA2 = diskId : PA3 = diskSerialNumber : PA4 = diskModel
        SQL_電腦綁定()
        If dr.Read() Then
            conn.Close() : 適應症_bt.Visible = True
        Else
            conn.Close() : 適應症_bt.Visible = False
        End If
    End Sub
    Private Sub 自動更新2()
        Dim Str As String = Application.StartupPath
        If File.Exists(Str + "\NOTAUTO.txt") Then : Else
            My.Computer.Network.DownloadFile(Target & "SYS-UPDATE.exe", Str + "\SYS-UPDATE.exe")
            Shell(Str + "\SYS-UPDATE.exe", vbNormalFocus)
            Me.Close()
        End If
    End Sub
    Private Sub 手動更新_cb_CheckedChanged(sender As Object, e As EventArgs) Handles 手動更新_cb.CheckedChanged
        If 手動更新_cb.Checked = False Then
            Me.Size = New Size(470, 288)
            If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(725, 396)
            ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(448, 240)
            ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(485, 306)
            ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(405, 368)
            ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(565, 306)
            End If
        Else
            Me.Size = New Size(729, 288)
            If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(596, 396)
            ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(319, 240)
            ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(356, 306)
            ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(276, 368)
            ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(436, 306)
            End If
        End If
    End Sub
    Private Sub 使用者_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 使用者_cb.SelectedIndexChanged
        PA = 使用者_cb.Text : SQL_使用者密碼讀取()
        If dr.Read() Then : 密碼_tb.Text = dr("Password") : End If : conn.Close()
        PasswordTextBox.Focus()
    End Sub
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If 密碼_tb.Text = "" Then
            MsgBox("請選擇使用者!")
        ElseIf 密碼_tb.Text <> "" Then
            SQL_使用者權限讀取()
            If dr.Read() Then
                gUserName = 使用者_cb.Text
                For I As Integer = 1 To 權限數量
                    CC(I) = dr.Item(I)
                Next
            End If
            If PasswordTextBox.Text = 密碼_tb.Text Then
                If PasswordTextBox.Text = "" Then
                    MsgBox("帳號或密碼錯誤，請重新輸入!")
                Else
                    Me.Hide()
                    GRAMS_SYS.Show() : OK.Enabled = False : Cancel.Enabled = False
                End If
            ElseIf PasswordTextBox.Text <> 密碼_tb.Text Then
                MsgBox("帳號或密碼錯誤，請重新輸入!")
            End If
            dr.Close()
        End If
        conn.Close()
    End Sub
    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub
    Private Sub 適應症_bt_Click(sender As Object, e As EventArgs) Handles 適應症_bt.Click
        非第一次 = False : Me.Hide() : 醫師.Show()
    End Sub
End Class
