123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- Imports System.IO
- Imports System.Text
- Public Class 登入畫面
- Dim MACKK, diskId, diskSerialNumber, diskModel As String 'MAC碼
- Dim Str As String = Application.StartupPath
- Dim IP公, IP測1, IP測2, 印尼測試內網網段 As Boolean
- Dim FFGG, GGHH As Integer
- ReadOnly 對話框(15) As String
- ReadOnly ds2, ds3 As New DataSet
- Private Sub 登入畫面_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim strDirNam As String = Path.Combine(Application.StartupPath, "GF00-ERP-UPDATE.EXE")
- If File.Exists(strDirNam) Then : File.Delete(strDirNam) : End If
- 執行檔版本號_lb.Text = "執行檔版本號 : " & 版本
-
- IP公 = False : IP測1 = False : IP測2 = False
- 系統登入_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
- '-----------------------控件基本設定-----------------------------------------------------------------------------------------------------------------------------------------------
- 深色風格_ch.Visible = 風格啟用 : 系統語言_cb.Visible = 多國語言啟用 : 系統語言_lb.Visible = 多國語言啟用
- If 多國語言啟用 = False Then : 系統語言 = "繁體中文" : End If : 廟 = False
- 公司線路_rb.Visible = 測試線路啟用 : 測試線路_rb.Visible = 測試線路啟用
- 刷卡登入_ch.Checked = True : 登入綁定_ch.Checked = False : 公司線路_rb.Checked = True
- 刷卡登入_ch.Visible = False : 登入綁定_ch.Visible = False : Panel1.SendToBack()
-
- Dim filePath1 As String = Path.Combine(Application.StartupPath, "TEST.txt")
- If File.Exists(filePath1) Then
- Dim fileContent As String = File.ReadAllText(Str + "\TEST.txt")
- txt = fileContent
- If fileContent.Length >= 10 AndAlso fileContent(2) = "G" AndAlso fileContent(9) = "F" Then
- Dim databaseID As String = fileContent(4) & fileContent(7) : 資料庫編號 = databaseID
- Else : MGB("錯誤,請通知系管理員", 1) : Me.Close() : End If
- Else
- 輸入密碼.ShowDialog()
- If PA = "0003065795" Then
- PA = InputBox("請輸入啟動碼!!", "啟用系統")
- Dim strDirName As String : Dim filePath2 As String = Path.Combine(Application.StartupPath, "TEST.txt")
- If File.Exists(filePath2) Then : File.Delete(filePath2) : End If
- strDirName = filePath2
- Try
- Using fs As IO.FileStream = New IO.FileStream(strDirName, FileMode.Append)
- Using sw As StreamWriter = New StreamWriter(fs, Encoding.Default)
- Dim str As String = PA
- sw.WriteLine(str) '插入一整行
- sw.Flush()
- End Using
- End Using
- Catch ex As Exception
- End Try
- Application.Restart()
- Else : MGB("驗證碼錯誤", 1) : Me.Close() : End If
- End If
- '-----------------------調整視窗大小-----------------------------------------------------------------------------------------------------------------------------------------------
- Me.Size = New Size(460, 280)
- Dim screenBounds As Rectangle = Screen.PrimaryScreen.Bounds
- Me.Left = (screenBounds.Width - Me.Width) / 2
- Me.Top = (screenBounds.Height - Me.Height) / 2
- '-----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")
- diskSerialNumber = cmicWmiObj("serialnumber")
- diskModel = cmicWmiObj("Model")
- Exit For
- Next
- '-----電腦預設值------------------------------------------------------------------------------------------------------------------------------------------------------------------
- SQL_連線字串_本機()
- 電腦識別碼 = diskId & "_" & diskSerialNumber & "_" & diskModel : 電腦識別碼 = Replace(電腦識別碼, "'", "_")
- SQL_電腦預設值查詢() : 帳號_rtb.ImeMode = 2
- '-----不啟用WEB------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Dim filePath3 As String = Path.Combine(Application.StartupPath, "NOPWEB.txt")
- If File.Exists(filePath3) Then
- Dim filereader = My.Computer.FileSystem.OpenTextFileReader(Str + "\NOPWEB.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, 2) = "NO" Then : 不啟用WEB_cb.Checked = False
- ElseIf Strings.Left(Text, 3) = "YES" Then : 不啟用WEB_cb.Checked = True : End If
- Else : 不啟用WEB_cb.Checked = False : End If
- If 不啟用WEB_cb.Checked = False Then : 不用WEB = False : Else : 不用WEB = True : End If
-
- PA49 = "mssql-147629-0.cloudclusters.net,12711"
- IP公 = True : IP測1 = True : IP測2 = True : 伺服器區域_cb.Text = "正式" : 公司線路_rb.Checked = True : 測試線路_rb.Checked = False : 內網線路 = True
- 確定_rbt.Enabled = True : 取消_rbt.Enabled = True : 刷卡登入_ch.Checked = True
- 'IP比對()
- SQL_系統版本號驗證()
- If dr.Read() Then : 資料庫版本 = dr("系統認證版本號") : 版本號 = dr("系統認證版本號") : End If : conn.Close()
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
- 自動更新2()
- Else : End If
- End Sub
- Private Function ScaleImage(ByVal img As Image, ByVal size As Size) As Image
- Dim newImage As New Bitmap(size.Width, size.Height)
- Using graphics As Graphics = Graphics.FromImage(newImage)
- graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
- graphics.DrawImage(img, New Rectangle(0, 0, size.Width, size.Height))
- End Using
- Return newImage
- End Function
- Private Sub IP比對()
- If SQL_連線狀態模組1.ConnectTest1("mssql-147629-0.cloudclusters.net,12711") = True Then
- '---主伺服器導通-------------------------------------------
- PA49 = "mssql-147629-0.cloudclusters.net,12711"
- IP公 = True : IP測1 = True : IP測2 = True : 伺服器區域_cb.Text = "正式" : 公司線路_rb.Checked = True : 測試線路_rb.Checked = False : 內網線路 = True
- 確定_rbt.Enabled = True : 取消_rbt.Enabled = True : 刷卡登入_ch.Checked = True
- Else
- If SQL_連線狀態模組2.ConnectTest2("106.1.48.106,4567") = True Then
- '---主伺服器導通-------------------------------------------
- 對話框(1) = "正式資料庫無法連線,請通知系統管理員!!"
- MGB(對話框(1), 1)
- PA49 = "106.1.48.106,4567"
- IP公 = True : IP測1 = True : IP測2 = True : 伺服器區域_cb.Text = "測試" : 公司線路_rb.Checked = True : 測試線路_rb.Checked = False : 內網線路 = True
- 確定_rbt.Enabled = True : 取消_rbt.Enabled = True : 刷卡登入_ch.Checked = True
- Else
- 對話框(1) = "正式及測試資料庫皆無法連線,請通知系統管理員!!"
- MGB(對話框(1), 1) : Me.Close()
- End If
- 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 = "mssql-147629-0.cloudclusters.net,12711"
- 登入() : 確定_rbt.Enabled = True : 取消_rbt.Enabled = True : 刷卡登入_ch.Checked = True
- Dim filePath As String = Path.Combine(Application.StartupPath, "NOTAUTO.txt")
- If File.Exists(filePath) Then : Me.Text = "GF" & 資料庫編號 & "-ERP-SYS Line : M " : Else : Me.Text = "GF" & 資料庫編號 & "-ERP-SYS Line : M" : End If
- Else : MGB(對話框(11), 1) : Me.Close() : End If
- ElseIf 伺服器區域_cb.Text = "測試" Then
- If IP公 = True Then : 登入人IP = "mssql-147629-0.cloudclusters.net,12711" : 資料庫編號 = "99"
- 登入() : 確定_rbt.Enabled = True : 取消_rbt.Enabled = True : 刷卡登入_ch.Checked = True
- Dim filePath As String = Path.Combine(Application.StartupPath, "NOTAUTO.txt")
- If File.Exists(filePath) Then : Me.Text = "GF" & 資料庫編號 & "-ERP-SYS Line : T " : Else : Me.Text = "GF" & 資料庫編號 & "-ERP-SYS Line : T" : End If
- Else : MGB(對話框(11), 1) : Me.Close() : End If
- End If : 帳號_rtb.Focus()
- End Sub
- Private Sub 登入()
- '-----------------------寫入連線字串-----------------------------------------------------------------------------------------------------------------------------------------------
- If Strings.Left(伺服器區域_cb.Text, 2) = "正式" Or Strings.Left(伺服器區域_cb.Text, 2) = "正式" Then : SQL_連線字串_正式() : Else : SQL_連線字串_正式() : End If
- 驗證_tb.Text = "1" : g_conn_type = 伺服器區域_cb.Text & "伺服器"
- '-----------------------系統是否鎖定-----------------------------------------------------------------------------------------------------------------------------------------------
- SQL_讀取鎖定()
- If dr.Read() Then
- Dim ch As Boolean = dr("系統鎖定") : If ch = True Then : 退出.ShowDialog() : 退出.BringToFront() : Return : End If
- End If : conn.Close()
- '-----------------------讀取圖片------------
- SQL_取得登入圖檔()
- While dr.Read() = True
- Dim unused As Byte() = New Byte(-1) {}
- Dim bytes As Byte() = DirectCast(dr.Item("簽名檔圖片"), Byte())
- Dim oStream As New MemoryStream(bytes)
- PictureBox1.Image = Bitmap.FromStream(oStream)
- End While
- '-----------------------系統版本號寫入-----------------------------------------------------------------------------------------------------------------------------------------------
- SQL_系統版本號驗證()
- If dr.Read() Then : 資料庫版本 = dr("系統認證版本號") : 版本號 = dr("系統認證版本號") : End If : conn.Close()
- '-----------------------FTP資料夾登入位置宣告--------------------------------------------------------------------------------------------------------------------------------------
- Target = "https://gcm-smart.com/ERP/GF-ERP/"
- If 多國語言啟用 = True Then : Else : 語言轉換讀取() : 資料庫版本號_lb.Text = "資料庫版本號 : " & 資料庫版本 : 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")
- diskSerialNumber = cmicWmiObj("serialnumber")
- diskModel = cmicWmiObj("Model")
- Exit For
- Next
- End Sub
- Private Sub ConnectToDatabase()
- SQL_系統版本號驗證() : If dr.Read() Then : 資料庫版本 = dr("系統認證版本號") : 版本號 = dr("系統認證版本號") : End If : conn.Close()
- End Sub
- 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 自動更新2()
- Dim filePath As String = Path.Combine(Application.StartupPath, "NOTAUTO.txt")
- If File.Exists(filePath) Then
- If 帳號_rtb.Text = "b70340" Or 帳號_rtb.Text = "B70340" Then : Else : End If
- Else
- SQL_系統認證版本號查詢()
- If dr.Read() Then
- If Strings.Right(執行檔版本號_lb.Text, 10) = dr("小更新1").ToString Or Strings.Right(執行檔版本號_lb.Text, 10) = dr("小更新2").ToString Or
- Strings.Right(執行檔版本號_lb.Text, 10) = dr("小更新3").ToString Or Strings.Right(執行檔版本號_lb.Text, 10) = dr("小更新4").ToString Or
- Strings.Right(執行檔版本號_lb.Text, 10) = dr("小更新5").ToString Then : PA = "1"
- ElseIf Strings.Right(執行檔版本號_lb.Text, 10) = dr("中更新1").ToString Or Strings.Right(執行檔版本號_lb.Text, 10) = dr("中更新2").ToString Or
- Strings.Right(執行檔版本號_lb.Text, 10) = dr("中更新3").ToString Or Strings.Right(執行檔版本號_lb.Text, 10) = dr("中更新4").ToString Or
- Strings.Right(執行檔版本號_lb.Text, 10) = dr("中更新5").ToString Then : PA = "2"
- Else : PA = "3" : End If
- End If : conn.Close() : PA = "1"
- Dim strDirName As String : filePath = Path.Combine(Application.StartupPath, "GF00UPDATE.txt")
- If File.Exists(filePath) Then : File.Delete(filePath) : End If
- strDirName = filePath
- Try
- Using fs As IO.FileStream = New IO.FileStream(strDirName, FileMode.Append)
- Using sw As StreamWriter = New StreamWriter(fs, Encoding.Default)
- Dim strd As String = PA
- sw.WriteLine(strd) '插入一整行
- sw.Flush()
- End Using
- End Using
- Catch ex As Exception
- End Try
- My.Computer.Network.DownloadFile(Target & "GF00-ERP-UPDATE.exe", Str & "\GF00-ERP-UPDATE.exe")
- Shell(Str & "\GF00-ERP-UPDATE.exe", vbNormalFocus) : Me.Close()
- End If
- End Sub
- Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 確定_rbt.Click
- 系統語言_cb.Text = "繁體中文"
- If 系統語言_cb.Text = " " Or 系統語言_cb.Text = "" Then : MGB(對話框(9), 1) : Else
- '-----電腦綁定判斷-------------------------------------------------------------------------------------------------------------------------------------------------------------
- If 登入綁定_ch.Checked = True Then
- PA1 = MACKK : PA2 = diskId : PA3 = diskSerialNumber : PA4 = diskModel
- SQL_電腦綁定()
- If dr.Read() Then : conn.Close() : 登入第一層() : Else
- If 帳號_rtb.Text = "b70340" Or 帳號_rtb.Text = "B70340" Then : conn.Close() : 登入第一層() : Else : conn.Close() : MGB(對話框(6), 1) : Me.Close() : End If
- End If
- Else : conn.Close() : 登入第一層() : End If
- End If
- End Sub
- Private Sub 登入第一層()
- If 帳號_rtb.Text = "b70340" Or 帳號_rtb.Text = "B70340" Then
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
- If 伺服器區域_cb.Text = "測試雲端" Then
- 自動更新2()
- 登入程序() : 判斷重登 = False
- Else
- 登入程序() : 判斷重登 = False
- End If
- Else
- 登入程序() : 判斷重登 = False
- End If
- Else
- If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
- If 伺服器區域_cb.Text = "測試雲端" Then
- 自動更新2()
- Else
- MGB(對話框(1), 1)
- End If
- Else
- 登入程序() : 判斷重登 = False
- End If
- End If
- End Sub
- Private Sub 登入程序()
- If 帳號_rtb.Text = "" Then : MGB(對話框(2), 1) : ElseIf 帳號_rtb.Text <> "" Then
- If 帳號_rtb.Text = "" Then : MGB(對話框(3), 1) : ElseIf 帳號_rtb.Text <> "" Then
- If 驗證_tb.Text = "1" Then
- SQL_使用者級別宣告() : If dr.Read() Then : 登入人級別 = dr("級別").ToString : End If
- SQL_使用者權限宣告()
- If dr.Read() Then
- 密碼驗證_tb.Text = dr("密碼").ToString : 密碼日期_tb.Text = dr("密碼日期").ToString
- gUserName = dr("姓名").ToString : 登入人部門 = dr("部門").ToString : 登入人課別 = dr("課別").ToString
- 登入人組別 = dr("組別").ToString
- For I As Integer = 1 To 權限數量 : CC(I) = dr.Item(I + 8 - 1) : Next
- FFGG = DateDiff("d", 密碼日期_tb.Text, Format(Today(), "yyyy/MM/dd"))
- If CC(45) = True Then : GGHH = 密碼時限 - FFGG
- If GGHH <= 0 Then
- MGB(對話框(4), 1) : 個人帳號管理.ShowDialog()
- Else : 登入第二層() : End If
- Else : 登入第二層() : End If
- Else : MGB(對話框(15), 1) : End If : dr.Close()
- End If
- End If
- End If
- conn.Close()
- End Sub
- Private Sub 進行下載_lb_Click(sender As Object, e As EventArgs) Handles 進行下載_lb.Click
- 自動更新2()
- End Sub
- Private Sub 隱藏開關_lb_Click(sender As Object, e As EventArgs) Handles 隱藏開關_lb.Click
- 輸入密碼.ShowDialog()
- If PA = "0003065795" Then
- PA = InputBox("請輸入啟動碼!!", "啟用系統", txt)
- Dim strDirName As String : Dim filePath As String = Path.Combine(Application.StartupPath, "TEST.txt")
- If File.Exists(filePath) Then : File.Delete(filePath) : End If : strDirName = filePath
- Try
- Using fs As IO.FileStream = New IO.FileStream(strDirName, FileMode.Append)
- Using sw As StreamWriter = New StreamWriter(fs, Encoding.Default)
- Dim str As String = PA
- sw.WriteLine(str) '插入一整行
- sw.Flush()
- End Using
- End Using
- Catch ex As Exception : End Try
- Application.Restart()
- Else : End If
- End Sub
- Private Sub 登入第二層()
- If 密碼_rtb.Text = 密碼驗證_tb.Text Then
- If 密碼驗證_tb.Text = "" Then : MGB(對話框(5), 1)
- Else
- Me.Hide() : Timer1.Enabled = False
- ICS_ASMS_ERP_SYS.Show() : 密碼_rtb.Text = "" : 帳號_rtb.Text = ""
- End If
- ElseIf 密碼_rtb.Text <> 密碼驗證_tb.Text Then : MGB(對話框(5), 1)
- End If
- End Sub
- Private Sub UsernameTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 帳號_rtb.KeyPress
- If e.KeyChar = ChrW(13) Then : Me.確定_rbt.PerformClick() : End If
- End Sub
- Private Sub PasswordTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 密碼_rtb.KeyPress
- If e.KeyChar = ChrW(13) Then : Me.確定_rbt.PerformClick() : End If
- End Sub
- Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 取消_rbt.Click
- Me.Close()
- End Sub
- Private Sub 風格()
- End Sub
- Private Sub UsernameTextBox_TextChanged(sender As Object, e As EventArgs) Handles 帳號_rtb.TextChanged
- If IsNumeric(帳號_rtb.Text) = True Then
- If 帳號_rtb.Text.Length = 10 Then
- SQL_刷卡登入()
- If dr.Read() Then
- 帳號_rtb.Text = dr("帳號").ToString : 密碼_rtb.Text = dr("密碼").ToString : conn.Close()
- Else
- 帳號_rtb.Text = "" : 密碼_rtb.Text = "" : conn.Close()
- End If
- Me.確定_rbt.PerformClick() : Exit Sub
- End If
- End If
- End Sub
- Private Sub 語言轉換讀取()
- 對話框(0) = "所選擇服務器不是台灣服務器,請連線該服務器所在網域的VPN,確保連線正常後重新選擇伺服器!"
- 對話框(1) = "系統版本號 與 資料庫版本號 對應不上,請下載最新的執行檔。"
- 對話框(2) = "請輸入帳號! 如使用刷登入,請確定該卡片有合法註冊!"
- 對話框(3) = "請輸入帳號!"
- 對話框(4) = "密碼過期!"
- 對話框(5) = "帳號或密碼錯誤,請重新輸入!"
- 對話框(6) = "該電腦沒有註冊,無法使用系統。"
- 對話框(7) = "下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。"
- 對話框(8) = "操作不正確,請用手動方式下載更新。"
- 對話框(9) = "未選擇語言"
- 對話框(10) = "請輸入 小更新 [1]、中更新 [2]、大更新 [3] !!"
- 對話框(11) = "網路錯誤,無法連線!!"
- 對話框(12) = "正式資料庫無法連線,請通知系統管理員!!"
- 對話框(13) = "線路轉換完成!!"
- 對話框(14) = "正式,測試資料庫無法使用!!"
- 對話框(15) = "帳號錯誤,請重新輸入!!"
- End Sub
- End Class
|