123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- Option Explicit On
- Imports System.Data.SqlClient
- Imports System.Net
- Public Class Login
- ReadOnly screenWidth = Screen.PrimaryScreen.Bounds.Width
- ReadOnly screenHeight = Screen.PrimaryScreen.Bounds.Height
- ' TODO: 插入程式碼,利用提供的使用者名稱和密碼執行自訂驗證
- ' (請參閱 http://go.microsoft.com/fwlink/?LinkId=35339)。
- ' 如此便可將自訂主體附加到目前執行緒的主體,如下所示:
- ' My.User.CurrentPrincipal = CustomPrincipal
- ' 其中 CustomPrincipal 是用來執行驗證的 IPrincipal 實作。
- ' 接著,My.User 便會傳回封裝在 CustomPrincipal 物件中的識別資訊,
- ' 例如使用者名稱、顯示名稱等。
- ReadOnly ds2 As New DataSet
- Public Property Credentials As ICredentials
- Public Property Target1 As String
- Private Property MYSQL As String
- ReadOnly da As Object
- ReadOnly ds As Object
- ReadOnly conn As New SqlConnection
- ReadOnly cmd As New SqlCommand
- ReadOnly da1 As New SqlDataAdapter
- Dim dr As SqlDataReader
- Dim MACKK As String 'MAC碼
- Dim diskId As String '數字ID
- Dim diskSerialNumber As String '硬碟序列
- Dim diskModel As String '磁盘型態
- Dim FFGG As Integer : Dim GGHH As Integer
- Dim HostName As String
- Dim IPAdress As IPAddress
- Dim MYIP As String
- Private Sub Set_DGV1載入前設定()
- DataGridView1.DataSource = Nothing : ds2.Clear()
- DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- DataGridView1.ColumnHeadersHeight = 25
- DataGridView1.AllowUserToAddRows = False
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- End Sub
- Private Sub Set_DGV1載入後設定()
- cmd.Connection = conn : cmd.CommandText = SQL1 : da1.SelectCommand = cmd : da1.Fill(ds2) : DataGridView1.DataSource = ds2.Tables(0) : conn.Close()
- End Sub
- Private Sub Set_清單1()
- Set_DGV1載入前設定()
- SQL1 = "SELECT 資料夾名稱, 指定 FROM FTP資料夾管理"
- Set_DGV1載入後設定()
- End Sub
- <Obsolete>
- Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- '-----------------------控件基本設定-----------------------------------------------------------------------------------------------------------------------------------------------
- CheckBox1.Enabled = False : CheckBox3.Checked = True : CheckBox3.Enabled = False : CheckBox1.Enabled = False
- TextBox4.Text = "1"
- Label1.Text = "執行檔版本號 : " & 版本
- 網段.ShowDialog()
- If 登入判斷 = True And 內外網 = False Then
- ComboBox1.Text = "工巧明內網"
- OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
- ElseIf 登入判斷 = False And 內外網 = False Then
- ComboBox1.Text = "工巧明內網"
- OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
- ElseIf 登入判斷 = True And 內外網 = True Then
- ComboBox1.Text = "工巧明外網"
- OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
- End If
- '-----------------------取得本機IP-----------------------------------------------------------------------------------------------------------------------------------------------
- HostName = Dns.GetHostName '获得本机的机器名
- IPAdress = Dns.GetHostByName(HostName).AddressList.GetValue(0) '获得本机的IP
- MYIP = IPAdress.ToString
- '-----------------------IP比對----------------------------------------------------------------------------------------------------------------------------------------------------
- If Strings.Left(MYIP, 10) = "192.168.12" Or Strings.Left(MYIP, 7) = "10.0.0." Then
- ComboBox1.Text = "工巧明內網"
- OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
- Else
- ComboBox1.Text = "工巧明外網"
- OK.Enabled = True : Cancel.Enabled = True : CheckBox1.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
- End Sub
- <Obsolete>
- Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
- '-----------------------確認登入伺服器位置-----------------------------------------------------------------------------------------------------------------------------------------
- If ComboBox1.Text = "工巧明內網" Then
- HostName = Dns.GetHostName '获得本机的机器名
- IPAdress = Dns.GetHostByName(HostName).AddressList.GetValue(0) '获得本机的IP
- MYIP = IPAdress.ToString
- If Strings.Left(MYIP, 10) = "192.168.12" Or Strings.Left(MYIP, 7) = "10.0.0." Then
- 登入人IP = "192.168.12.127"
- 登入()
- OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
- End If
- ElseIf ComboBox1.Text = "工巧明外網" Then
- HostName = Dns.GetHostName '获得本机的机器名
- IPAdress = Dns.GetHostByName(HostName).AddressList.GetValue(0) '获得本机的IP
- MYIP = IPAdress.ToString
- If Strings.Left(MYIP, 10) <> "192.168.12" Or Strings.Left(MYIP, 7) <> "10.0.0." Then
- 登入人IP = "180.177.181.162,5264"
- 登入()
- OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
- End If
- End If
- UsernameTextBox.Focus()
- End Sub
- Private Sub 登入()
- '-----------------------寫入連線字串-----------------------------------------------------------------------------------------------------------------------------------------------
- ConString = "Data Source=" & 登入人IP & ";Initial Catalog=我的資料庫;Persist Security Info=True;User ID=b70340;Password=0911274990;Max pool size = 200;Connection Timeout=0"
- g_conn_type = ComboBox1.Text & "伺服器"
- '-----------------------系統版本號寫入-----------------------------------------------------------------------------------------------------------------------------------------------
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "SELECT 系統認證版本號 FROM 版本號管理 "
- cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
- If dr.Read() Then
- Label2.Text = "資料庫版本號 : " & dr("系統認證版本號") : 版本號 = dr("系統認證版本號")
- End If : conn.Close()
- '-----------------------FTP資料夾登入位置宣告--------------------------------------------------------------------------------------------------------------------------------------
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "SELECT FTP地址, FTP帳號, FTP密碼 FROM FTP資料庫管理 WHERE 地區 LIKE N'" & ComboBox1.Text & "'"
- cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
- If dr.Read() Then
- Target = dr("FTP地址") : FTP帳號 = dr("FTP帳號") : FTP密碼 = dr("FTP密碼")
- End If : conn.Close()
- Set_清單1()
- For i As Integer = 0 To DataGridView1.Rows.Count - 1
- If DataGridView1(1, i).Value.ToString = "AA00" Then : AA(0) = DataGridView1(0, i).Value.ToString : End If
- If DataGridView1(1, i).Value.ToString = "AA01" Then : AA(1) = DataGridView1(0, i).Value.ToString : End If
- If DataGridView1(1, i).Value.ToString = "AA02" Then : AA(2) = DataGridView1(0, i).Value.ToString : End If
- If DataGridView1(1, i).Value.ToString = "AA03" Then : AA(3) = DataGridView1(0, i).Value.ToString : End If
- If DataGridView1(1, i).Value.ToString = "AA04" Then : AA(4) = DataGridView1(0, i).Value.ToString : End If
- Next
- Target1 = Target & AA(1) & "/"
- WebBrowser3.Url = New Uri(Target1)
- If Strings.Right(Label1.Text, 10) <> Strings.Right(Label2.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 = "GCM-ERP-SYS - " & 版本號 & ".exe"
- SaveFileDialog1.ShowDialog()
- If Strings.Right(SaveFileDialog1.FileName, 28) = "GCM-ERP-SYS - " & 版本號 & ".exe" Then
- My.Computer.Network.DownloadFile(Target & AA(1) & "/" & "GCM-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 = "GCM-ERP-SYS - " & 版本號 & ".exe"
- SaveFileDialog1.ShowDialog()
- If Strings.Right(SaveFileDialog1.FileName, 28) = "GCM-ERP-SYS - " & 版本號 & ".exe" Then
- My.Computer.Network.DownloadFile(Target & AA(1) & "/" & "GCM-ERP-SYS - " & 版本號 & ".exe", SaveFileDialog1.FileName, "", "", True, 10000, True)
- MsgBox("下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。")
- Me.Close()
- Else
- MsgBox("操作不正確,請用手動方式下載更新。")
- End If
- End If
- End Sub
- Private Sub 登入第一層()
- If UsernameTextBox.Text = "" Then
- MsgBox("請輸入帳號! 如使用刷登入,請確定該卡片有合法註冊!")
- ElseIf UsernameTextBox.Text <> "" Then
- If UsernameTextBox.Text = "" Then
- MsgBox("請輸入帳號!")
- ElseIf UsernameTextBox.Text <> "" Then
- If TextBox4.Text = "1" Then
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- MYSQL = "SELECT " & 登入權限AQL & " FROM 使用者 WHERE (帳號 = '" & UsernameTextBox.Text & "')"
- cmd.Connection = conn : cmd.CommandText = MYSQL : dr = cmd.ExecuteReader
- If dr.Read() Then
- TextBox1.Text = dr("密碼").ToString : gUserName = dr("姓名").ToString : TextBox2.Text = dr("密碼日期").ToString
- For I As Integer = 0 To 26
- CC(I) = dr.Item(I + 4)
- Next
- FFGG = DateDiff("d", TextBox2.Text, Format(Today(), "yyyy/MM/dd"))
- If CC(24) = True Then
- GGHH = 密碼時限 - FFGG
- If GGHH <= 0 Then
- MsgBox("密碼過期!")
- 個人帳號管理.ShowDialog()
- Else
- If Strings.Right(Label1.Text, 10) <> Strings.Right(Label2.Text, 10) Then
- If CC(26) = True Then
- 自動更新1()
- Else
- 自動更新2()
- End If
- Else
- 登入第二層()
- End If
- End If
- Else
- If Strings.Right(Label1.Text, 10) <> Strings.Right(Label2.Text, 10) Then
- If CC(26) = True Then
- 自動更新1()
- Else
- 自動更新2()
- End If
- Else
- 登入第二層()
- End If
- End If
- End If
- dr.Close()
- End If
- End If
- End If
- conn.Close()
- End Sub
- Private Sub 登入第二層()
- If PasswordTextBox.Text = TextBox1.Text Then
- If TextBox1.Text = "" Then
- MsgBox("帳號或密碼錯誤,請重新輸入!")
- Else
- Me.Hide()
- GCM_ERP_SYS.Show() : PasswordTextBox.Text = "" : UsernameTextBox.Text = ""
- End If
- ElseIf PasswordTextBox.Text <> TextBox1.Text Then
- MsgBox("帳號或密碼錯誤,請重新輸入!")
- End If
- End Sub
- Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
- If ComboBox1.Text = "" Then
- MsgBox("請正確選擇正確資料庫!")
- Else
- '-----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("signature")
- diskSerialNumber = cmicWmiObj("serialnumber")
- diskModel = cmicWmiObj("Model")
- Next
-
- If UsernameTextBox.Text = "b70340" Or UsernameTextBox.Text = "B70340" Then
- 登入第一層() : 判斷重登 = False
- ElseIf CheckBox3.Checked = True Then
- conn.Close()
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "SELECT MAC碼 FROM 系統綁定電腦資訊
- WHERE MAC碼 LIKE N'" & MACKK & "' AND 硬碟ID LIKE N'" & diskId & "' AND 硬碟序列 LIKE N'" & diskSerialNumber & "' AND 磁盘型態 LIKE N'" & diskModel & "'"
- cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
- If dr.Read() Then
- conn.Close()
- 登入第一層()
- Else
- conn.Close()
- MsgBox("該電腦沒有註冊,無法使用系統。")
- End If
- ElseIf CheckBox3.Checked = False Then
- 登入第一層()
- End If
- End If
- End Sub
- Private Sub Cancel_Click(sender As Object, e As EventArgs) Handles Cancel.Click
- Me.Close()
- End Sub
- Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
- If CheckBox2.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_TextChanged(sender As Object, e As EventArgs) Handles UsernameTextBox.TextChanged
- If CheckBox1.Checked = False Then
- Else
- If IsNumeric(UsernameTextBox.Text) = True Then
- If UsernameTextBox.Text.Length = 10 Then
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- MYSQL = "SELECT 帳號, 密碼 FROM 使用者 WHERE (ID卡號 = '" & UsernameTextBox.Text & "')"
- cmd.Connection = conn : cmd.CommandText = MYSQL : dr = cmd.ExecuteReader
- If dr.Read() Then
- UsernameTextBox.Text = dr("帳號").ToString
- PasswordTextBox.Text = dr("密碼").ToString
- conn.Close()
- Else
- UsernameTextBox.Text = "" : PasswordTextBox.Text = "" : conn.Close()
- End If
- Exit Sub : Me.OK.PerformClick()
- End If
- End If
- End If
- End Sub
- Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
- UsernameTextBox.Focus()
- End Sub
- End Class
|