123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- Imports System.Drawing
- Imports System.Net
- Imports System.Windows.Forms
- Public Class LoginForm1
- ' TODO: 插入程式碼,利用提供的使用者名稱和密碼執行自訂驗證
- ' (請參閱 https://go.microsoft.com/fwlink/?LinkId=35339)。
- ' 如此便可將自訂主體附加到目前執行緒的主體,如下所示:
- ' My.User.CurrentPrincipal = CustomPrincipal
- ' 其中 CustomPrincipal 是用來執行驗證的 IPrincipal 實作。
- ' 接著,My.User 便會傳回封裝在 CustomPrincipal 物件中的識別資訊,
- ' 例如使用者名稱、顯示名稱等。
- ReadOnly ds2 As New DataSet
- Dim MACKK As String 'MAC碼
- Dim diskId As String '數字ID
- Dim diskSerialNumber As String '硬碟序列
- Dim diskModel As String '磁盘型態
- Public Property Credentials As ICredentials
- ReadOnly screenWidth = Screen.PrimaryScreen.Bounds.Width
- ReadOnly screenHeight = Screen.PrimaryScreen.Bounds.Height
- Dim 鎖定 As Boolean
- Private Sub Set_清單1()
- FTP清單_dgv.DataSource = Nothing : ds2.Clear()
- FTP清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- FTP清單_dgv.ColumnHeadersHeight = 25 : FTP清單_dgv.AllowUserToAddRows = False
- SQL_FTP資料夾路徑分配()
- da.Fill(ds2) : FTP清單_dgv.DataSource = ds2.Tables(0) : conn.Close()
- End Sub
- Private Sub LoginForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- '-----------------------控件基本設定-----------------------------------------------------------------------------------------------------------------------------------------------
- 刷卡登入_ch.Checked = True : 刷卡登入_ch.Enabled = False : 登入綁定_ch.Checked = False : 登入綁定_ch.Enabled = False : 帳號_tb.Visible = False
- 執行檔版本號_lb.Text = "執行檔版本號 : " & 版本
- 網段.ShowDialog()
- If 登入判斷 = True And 內外網 = False Then
- 伺服器區域_ch.Text = "懋桔內網" : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
- ElseIf 登入判斷 = True And 內外網 = True Then
- 伺服器區域_ch.Text = "懋桔外網" : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
- ElseIf 登入判斷 = False And 內外網 = False Then
- 伺服器區域_ch.Text = "設計線路" : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
- End If
- '-----------------------調整視窗大小-----------------------------------------------------------------------------------------------------------------------------------------------
- Me.Size = New Size(466, 279)
- If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
- ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
- ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
- ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
- ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
- End If
-
- Me.ActiveControl = 使用者帳號_cb
- '-----------------------系統鎖定判斷-----------------------------------------------------------------------------------------------------------------------------------------------
- SQL_系統版本號驗證()
- If dr.Read() Then : 鎖定 = dr("系統鎖定") : End If : conn.Close()
- If 鎖定 = True Then
- MsgBox("非系統功能因素造成目前系統已鎖定,無法開啟,請聯繫系統開發商。")
- Me.Close()
- 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()
- Else
- conn.Close() : MsgBox("該電腦沒有註冊,無法使用系統。") : Me.Close()
- End If
- End Sub
- Private Sub 伺服器區域_ch_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 伺服器區域_ch.SelectedIndexChanged
- '-----------------------確認登入伺服器位置-----------------------------------------------------------------------------------------------------------------------------------------
- If 登入判斷 = True And 內外網 = False Then
- 登入人IP = "192.168.0.199,2433" : 登入() : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
- ElseIf 登入判斷 = True And 內外網 = True Then
- 登入人IP = "59.127.190.74,2433" : 登入() : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
- ElseIf 登入判斷 = False And 內外網 = False Then
- 登入人IP = "106.1.50.79" : 登入() : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
- End If
- End Sub
- Private Sub 登入()
- '-----------------------寫入連線字串-----------------------------------------------------------------------------------------------------------------------------------------------
- If 伺服器區域_ch.Text = "設計線路" Then
- SQL_連線字串_測試()
- Else
- SQL_連線字串_正式()
- End If
-
- 驗證_tb.Text = "1" : g_conn_type = 伺服器區域_ch.Text & "伺服器"
- '-----------------------系統版本號驗證-----------------------------------------------------------------------------------------------------------------------------------------------
- SQL_系統版本號驗證()
- If dr.Read() Then : 資料庫版本號_lb.Text = "資料庫版本號 : " & dr("系統認證版本號") : 版本號 = dr("系統認證版本號") : End If : conn.Close()
- '-----------------------FTP伺服器登入位置--------------------------------------------------------------------------------------------------------------------------------------
- SQL_FTP伺服器登入位置()
- If dr.Read() Then : Target = dr("FTP地址") : FTP帳號 = dr("FTP帳號") : FTP密碼 = dr("FTP密碼") : FTP物理位置 = dr("FTP物理位置") : End If : conn.Close()
- Set_清單1()
- Dim HH As String = 0
- For i As Integer = 0 To FTP清單_dgv.Rows.Count - 1
- If i < 10 Then : HH = "0" & i : ElseIf i >= 10 Then : HH = i : End If
- If FTP清單_dgv("指定", i).Value.ToString = "AA" & HH Then : AA(i) = FTP清單_dgv("資料夾名稱", i).Value.ToString : End If
- Next
- Target1 = Target & AA(0) & "/"
- FTP執行檔_wb.Url = New Uri(Target1)
-
- SQL_帳號讀取()
- 使用者帳號_cb.Items.Clear() : While (dr.Read()) : 使用者帳號_cb.Items.Add(dr("帳號")) : End While : conn.Close()
-
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
- 自動更新2()
- Else : End If
-
- End Sub
- Private Sub 自動更新1()
- Dim aa1 As MsgBoxResult
- aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請開發人員注意是否有其他人員修改。並決定是否下載最新的執行檔?", MsgBoxStyle.OkCancel)
- If aa1 = MsgBoxResult.Ok Then
- With SaveFileDialog1 : .Filter = "所有文件(*.exe)|*.exe" : End With
- SaveFileDialog1.FileName = "MAOJI-ERP-SYS - " & 版本號 & ".exe"
- SaveFileDialog1.ShowDialog()
- If Strings.Right(SaveFileDialog1.FileName, 30) = "MAOJI-ERP-SYS - " & 版本號 & ".exe" Then
- My.Computer.Network.DownloadFile(Target & AA(0) & "/" & "MAOJI-ERP-SYS - " & 版本號 & ".exe", SaveFileDialog1.FileName, "", "", True, 10000, True)
- MsgBox("下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。")
- Me.Close()
- Else
- MsgBox("操作不正確,請用手動方式下載更新。")
- End If
- Else
- 登入程序()
- End If
- End Sub
- Private Sub 自動更新2()
- Dim aa1 As MsgBoxResult
- aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請下載最新的執行檔。", MsgBoxStyle.OkCancel)
- If aa1 = MsgBoxResult.Ok Then
- With SaveFileDialog1 : .Filter = "所有文件(*.exe)|*.exe" : End With
- SaveFileDialog1.FileName = "MAOJI-ERP-SYS - " & 版本號 & ".exe"
- SaveFileDialog1.ShowDialog()
- If Strings.Right(SaveFileDialog1.FileName, 30) = "MAOJI-ERP-SYS - " & 版本號 & ".exe" Then
- My.Computer.Network.DownloadFile(Target & AA(0) & "/" & "MAOJI-ERP-SYS - " & 版本號 & ".exe", SaveFileDialog1.FileName, "", "", True, 10000, True)
- MsgBox("下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。")
- Me.Close()
- Else
- MsgBox("操作不正確,請用手動方式下載更新。")
- End If
- End If
- End Sub
- Private Sub 登入第一層()
- If 帳號_tb.Text = "b70340" Or 帳號_tb.Text = "B70340" Then
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then : 自動更新1() : Else : 登入程序() : End If
- Else
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then : 自動更新2() : Else : 登入程序() : End If
- End If
- End Sub
- Private Sub 登入程序()
- If 帳號_tb.Text = "" Then
- MsgBox("請輸入帳號! 如使用刷登入,請確定該卡片有合法註冊!")
- ElseIf 帳號_tb.Text <> "" Then
- If 帳號_tb.Text = "" Then
- MsgBox("請輸入帳號!")
- ElseIf 帳號_tb.Text <> "" Then
- If 驗證_tb.Text = "1" Then
- SQL_使用者權限宣告()
- If dr.Read() Then
- 密碼驗證_tb.Text = dr("密碼").ToString : gUserName = dr("姓名").ToString
- For I As Integer = 0 To 權限數量 : CC(I) = dr.Item(I + 3) : Next : 登入第二層()
- End If : dr.Close()
- End If
- End If
- End If : conn.Close()
- End Sub
- Private Sub 登入第二層()
- If 密碼_tb.Text = 密碼驗證_tb.Text Then
- If 密碼驗證_tb.Text = "" Then
- MsgBox("帳號或密碼錯誤,請重新輸入!")
- Else
- Me.Hide() : MAOJI_ERP_SYS.Show() : 密碼_tb.Text = "" : 帳號_tb.Text = ""
- End If
- ElseIf 密碼_tb.Text <> 密碼驗證_tb.Text Then
- MsgBox("帳號或密碼錯誤,請重新輸入!")
- End If
- End Sub
- Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 確認_bt.Click
- 登入第一層()
- End Sub
- Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 取消_bt.Click
- Me.Close()
- End Sub
- Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles 更新下載_ch.CheckedChanged
- If 更新下載_ch.Checked = False Then
- Me.Size = New Size(466, 279)
- If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
- ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
- ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
- ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
- ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
- End If
- Else
- Me.Size = New Size(705, 279)
- If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(608, 401)
- ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(331, 245)
- ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(368, 311)
- ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(288, 373)
- ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(448, 311)
- End If
- End If
- End Sub
- Private Sub UsernameTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 帳號_tb.KeyPress
- If e.KeyChar = ChrW(13) Then : Me.確認_bt.PerformClick() : End If
- End Sub
- Private Sub PasswordTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 密碼_tb.KeyPress
- If e.KeyChar = ChrW(13) Then : Me.確認_bt.PerformClick() : End If
- End Sub
- Private Sub UsernameTextBox_TextChanged(sender As Object, e As EventArgs) Handles 帳號_tb.TextChanged
- If 刷卡登入_ch.Checked = False Then
- Else
- If IsNumeric(帳號_tb.Text) = True Then
- If 帳號_tb.Text.Length = 10 Then
- SQL_刷卡登入()
- If dr.Read() Then
- 帳號_tb.Text = dr("帳號").ToString : 密碼_tb.Text = dr("密碼").ToString
- Else
- 帳號_tb.Text = "" : 密碼_tb.Text = ""
- End If : conn.Close()
- Exit Sub : Me.確認_bt.PerformClick()
- End If
- End If
- End If
- End Sub
- Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles 刷卡登入_ch.Click
- Me.ActiveControl = 使用者帳號_cb
- End Sub
- Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 使用者帳號_cb.TextChanged
- 帳號_tb.Text = 使用者帳號_cb.Text
- End Sub
- End Class
|