123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- Imports System.Net
- Imports System.IO
- Imports System.Text
- Public Class LoginForm1
- ' TODO: 插入程式碼,利用提供的使用者名稱和密碼執行自訂驗證
- ' (請參閱 https://go.microsoft.com/fwlink/?LinkId=35339)。
- ' 如此便可將自訂主體附加到目前執行緒的主體,如下所示:
- ' My.User.CurrentPrincipal = CustomPrincipal
- ' 其中 CustomPrincipal 是用來執行驗證的 IPrincipal 實作。
- ' 接著,My.User 便會傳回封裝在 CustomPrincipal 物件中的識別資訊,
- ' 例如使用者名稱、顯示名稱等。
- Public Property Credentials As ICredentials
- Private ReadOnly ds As Object
- Private ReadOnly ds2 As New DataSet
- Private ReadOnly screenWidth = Screen.PrimaryScreen.Bounds.Width
- Private ReadOnly screenHeight = Screen.PrimaryScreen.Bounds.Height
- Dim HH As String
- Dim Str As String = Application.StartupPath
- Dim Strs As String = Application.StartupPath
- Private Sub Set_清單1()
- 表單1_dgv.DataSource = Nothing : ds2.Clear()
- 表單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 表單1_dgv.ColumnHeadersHeight = 25
- 表單1_dgv.AllowUserToAddRows = False
- SQL_資料夾名稱清單()
- da.Fill(ds2) : 表單1_dgv.DataSource = ds2.Tables(0) : conn.Close()
- End Sub
- Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
- '-----------------------刪除自動更新項目-------------------------------------------------------------------------------------------------------------------------------------------
- Dim 已開啟 As Boolean = False
-
- If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\SYS-UPDATE.exe") Then
- Dim pro() As Process = System.Diagnostics.Process.GetProcesses()
- ' 判斷是否有符合的Process
- For Each process As Process In pro
- If ("SYS-UPDATE").Equals(process.ProcessName) Then
- 已開啟 = True
- End If
- Next
- If 已開啟 = False Then
- Timer1.Enabled = False
- If File.Exists(Str + "\SYS-UPDATE.exe") Then : File.Delete(Str + "\SYS-UPDATE.exe") : End If
- If File.Exists(Str + "\LIVE.txt") Then : File.Delete(Str + "\LIVE.txt") : End If : Timer1.Enabled = False
- End If
- ElseIf File.Exists(Strs & "\SYS-UPDATE.exe") Then
- Dim pro() As Process = System.Diagnostics.Process.GetProcesses()
- ' 判斷是否有符合的Process
- For Each process As Process In pro
- If ("SYS-UPDATE").Equals(process.ProcessName) Then
- 已開啟 = True
- End If
- Next
- If 已開啟 = False Then
- Timer1.Enabled = False
- If File.Exists(Str + "\SYS-UPDATE.exe") Then : File.Delete(Str + "\SYS-UPDATE.exe") : End If
- If File.Exists(Str + "\LIVE.txt") Then : File.Delete(Str + "\LIVE.txt") : End If : Timer1.Enabled = False
- End If
- End If
- End Sub
- <Obsolete>
- Private Sub LoginForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- '-----------------------控件基本設定-----------------------------------------------------------------------------------------------------------------------------------------------
- 刷卡登入_ch.Checked = True : 刷卡登入_ch.Enabled = False
- 執行檔版本號_lb.Text = "執行檔版本號 : " & 版本 : TextBox4.Text = "1"
- 網段.ShowDialog()
- '-----------------------調整視窗大小-----------------------------------------------------------------------------------------------------------------------------------------------
- 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
- Timer1.Enabled = True
- End Sub
- Private Sub LoginForm1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
- If 登入判斷 = True Then
- 伺服器區域選擇_cb.Text = "巨益線路"
- OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
- ElseIf 登入判斷 = False Then
- 伺服器區域選擇_cb.Text = "開發線路"
- OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
- End If
- End Sub
- <Obsolete>
- Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 伺服器區域選擇_cb.SelectedIndexChanged
- '-----------------------確認登入伺服器位置-----------------------------------------------------------------------------------------------------------------------------------------
- If 伺服器區域選擇_cb.Text = "巨益線路" Then
- If SQL_連線狀態模組.ConnectTest("192.168.10.5") = True Then
- 登入人IP = "192.168.10.5" : 登入()
- OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
- Else
- MsgBox("巨益伺服器無法連線,自動轉跳測試線路,請聯繫系統管理員!!")
- 伺服器區域選擇_cb.Text = "開發線路"
- 登入人IP = "106.1.48.106,4567" : 登入()
- OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
- End If
- ElseIf 伺服器區域選擇_cb.Text = "開發線路" Then
- 登入人IP = "106.1.48.106,4567" : 登入()
- OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
- End If
- UsernameTextBox.Focus()
- End Sub
- Private Sub 登入()
- '-----------------------寫入連線字串-----------------------------------------------------------------------------------------------------------------------------------------------
- If 伺服器區域選擇_cb.Text = "開發線路" Then
- SQL_連線字串_測試() : SQL密碼 = "Lee0911274990"
- Else
- SQL_連線字串_正式() : SQL密碼 = "0911274990"
- End If
- g_conn_type = 伺服器區域選擇_cb.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()
- For i As Integer = 0 To 表單1_dgv.Rows.Count - 1
- If i < 10 Then : HH = "0" & i : ElseIf i >= 10 Then : HH = i : End If
- If 表單1_dgv(1, i).Value.ToString = "AA" & HH Then : AA(i) = 表單1_dgv(0, i).Value : End If
- Next
- Target1 = Target & AA(0) & "/"
- WebBrowser3.Url = New Uri(Target1)
- '-----------------------自動更新--------------------------------------------------------------------------------------------------------------------------------------
- Dim Str As String = Application.StartupPath
- If File.Exists(Str + "\WINPROFIT-ERP-SYS - 2021093001.exe") Then
- UPDATE_bt.PerformClick()
- End If
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
- 自動更新2()
- Else : End If
- End Sub
- Private Sub 登入程序()
- If UsernameTextBox.Text = "" Then
- MsgBox("請輸入帳號! 如使用刷登入,請確定該卡片有合法註冊!")
- ElseIf UsernameTextBox.Text <> "" Then
- If TextBox4.Text = "1" Then
- SQL_讀取使用者權限管理表()
- If dr.Read() Then
- TextBox1.Text = dr("密碼").ToString
- gUserName = dr("姓名").ToString
- 登入人部門 = dr("部門").ToString
- For I As Integer = 0 To 95
- CC(I) = dr.Item(I + 5)
- Next
- End If
- If PasswordTextBox.Text = TextBox1.Text Then
- If TextBox1.Text = "" Then
- MsgBox("帳號或密碼錯誤,請重新輸入!")
- Else
- Me.Hide()
- WINPROFIT_ERP_SYS.Show()
- OK.Enabled = False : Cancel.Enabled = False
- End If
- ElseIf PasswordTextBox.Text <> TextBox1.Text Then
- MsgBox("帳號或密碼錯誤,請重新輸入!")
- End If
- dr.Close()
- End If
- End If
- SQL_用員工編號分辨()
- If dr.Read() Then
- 員工編號 = dr("員工編號").ToString
- End If
- conn.Close()
- End Sub
- Private Sub 自動更新1()
- Dim Str As String = Application.StartupPath
- If File.Exists(Str + "\NOTAUTO.txt") Then : Else
- Dim aa1 As MsgBoxResult
- aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請開發人員注意是否有其他人員修改。並決定是否下載最新的執行檔?", MsgBoxStyle.OkCancel)
- If aa1 = MsgBoxResult.Ok Then
- UPDATE_bt.PerformClick()
- Else
- 登入程序()
- End If
- End If
- End Sub
- Private Sub 自動更新2()
- Dim Str As String = Application.StartupPath
- If File.Exists(Str + "\NOTAUTO.txt") Then : Else
- Dim aa1 As MsgBoxResult
- aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請下載最新的執行檔。", MsgBoxStyle.OkCancel)
- If aa1 = MsgBoxResult.Ok Then
- UPDATE_bt.PerformClick()
- End If
- End If
- End Sub
- Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
- If UsernameTextBox.Text = "b70340" Or UsernameTextBox.Text = "B70340" Then
- 登入程序()
- Else
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
- 自動更新2()
- Else
- 登入程序()
- End If
- End If
- 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 CheckBox2_Click(sender As Object, e As EventArgs) Handles 下載檔案_ch.Click
- 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
- 輸入密碼.ShowDialog()
- If PA = "753582" Then
- 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
- Else
- If PA = "" Then : 下載檔案_ch.Checked = False : Else
- MsgBox("密碼錯誤!!") : 下載檔案_ch.Checked = False
- End If
- End If
- End If
- End Sub
- Private Sub UsernameTextBox_TextChanged(sender As Object, e As EventArgs) Handles UsernameTextBox.TextChanged
- If 刷卡登入_ch.Checked = False Then
- Else
- If IsNumeric(UsernameTextBox.Text) = True Then
- If UsernameTextBox.Text.Length = 10 Then
- SQL_讀取ID卡號()
- 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 刷卡登入_ch.Click
- UsernameTextBox.Focus()
- End Sub
- Private Sub UPDATE_bt_Click(sender As Object, e As EventArgs) Handles UPDATE_bt.Click
- Dim Strs As String = Application.StartupPath
- If File.Exists(Strs + "\LIVE.txt") Then : File.Delete(Strs + "\LIVE.txt") : End If
- Dim filepath As String = Strs + "\LIVE.txt"
- Try
- Using fs As IO.FileStream = New IO.FileStream(filepath, FileMode.Append)
- Using sw As StreamWriter = New StreamWriter(fs, Encoding.Default)
- If 伺服器區域選擇_cb.Text = "巨益線路" Then
- Dim str As String = "A"
- sw.WriteLine(str)
- sw.Flush()
- Else
- Dim str As String = "B"
- sw.WriteLine(str)
- sw.Flush()
- End If
- End Using
- End Using
- Catch ex As Exception
- End Try
- My.Computer.Network.DownloadFile(Target & AA(0) & "/" & "SYS-UPDATE.exe", Strs + "\SYS-UPDATE.exe")
- Shell(Strs + "\SYS-UPDATE.exe", vbNormalFocus)
- Me.Close()
- End Sub
- End Class
|