暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoginForm1.vb 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. Imports System.Drawing
  2. Imports System.Net
  3. Imports System.Windows.Forms
  4. Public Class LoginForm1
  5. ' TODO: 插入程式碼,利用提供的使用者名稱和密碼執行自訂驗證
  6. ' (請參閱 https://go.microsoft.com/fwlink/?LinkId=35339)。
  7. ' 如此便可將自訂主體附加到目前執行緒的主體,如下所示:
  8. ' My.User.CurrentPrincipal = CustomPrincipal
  9. ' 其中 CustomPrincipal 是用來執行驗證的 IPrincipal 實作。
  10. ' 接著,My.User 便會傳回封裝在 CustomPrincipal 物件中的識別資訊,
  11. ' 例如使用者名稱、顯示名稱等。
  12. ReadOnly ds2 As New DataSet
  13. Dim MACKK As String 'MAC碼
  14. Dim diskId As String '數字ID
  15. Dim diskSerialNumber As String '硬碟序列
  16. Dim diskModel As String '磁盘型態
  17. Public Property Credentials As ICredentials
  18. ReadOnly screenWidth = Screen.PrimaryScreen.Bounds.Width
  19. ReadOnly screenHeight = Screen.PrimaryScreen.Bounds.Height
  20. Dim 鎖定 As Boolean
  21. Private Sub Set_清單1()
  22. FTP清單_dgv.DataSource = Nothing : ds2.Clear()
  23. FTP清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  24. FTP清單_dgv.ColumnHeadersHeight = 25 : FTP清單_dgv.AllowUserToAddRows = False
  25. SQL_FTP資料夾路徑分配()
  26. da.Fill(ds2) : FTP清單_dgv.DataSource = ds2.Tables(0) : conn.Close()
  27. End Sub
  28. Private Sub LoginForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  29. '-----------------------控件基本設定-----------------------------------------------------------------------------------------------------------------------------------------------
  30. 刷卡登入_ch.Checked = True : 刷卡登入_ch.Enabled = False : 登入綁定_ch.Checked = False : 登入綁定_ch.Enabled = False : 帳號_tb.Visible = False
  31. 執行檔版本號_lb.Text = "執行檔版本號 : " & 版本
  32. 網段.ShowDialog()
  33. If 登入判斷 = True And 內外網 = False Then
  34. 伺服器區域_ch.Text = "懋桔內網" : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
  35. ElseIf 登入判斷 = True And 內外網 = True Then
  36. 伺服器區域_ch.Text = "懋桔外網" : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
  37. ElseIf 登入判斷 = False And 內外網 = False Then
  38. 伺服器區域_ch.Text = "設計線路" : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
  39. End If
  40. '-----------------------調整視窗大小-----------------------------------------------------------------------------------------------------------------------------------------------
  41. Me.Size = New Size(466, 279)
  42. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
  43. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
  44. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
  45. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
  46. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
  47. End If
  48. Me.ActiveControl = 使用者帳號_cb
  49. '-----------------------系統鎖定判斷-----------------------------------------------------------------------------------------------------------------------------------------------
  50. SQL_系統版本號驗證()
  51. If dr.Read() Then : 鎖定 = dr("系統鎖定") : End If : conn.Close()
  52. If 鎖定 = True Then
  53. MsgBox("非系統功能因素造成目前系統已鎖定,無法開啟,請聯繫系統開發商。")
  54. Me.Close()
  55. End If
  56. '-----MAC碼與硬碟資料-------------------------------------------------------------------------------------------------------------------------------------------------------------
  57. Dim Wmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
  58. For Each WmiObj As Management.ManagementObject In Wmi.Get
  59. If CBool(WmiObj("IPEnabled")) Then
  60. MACKK = WmiObj("MACAddress")
  61. End If
  62. Next
  63. Dim cmicWmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")
  64. For Each cmicWmiObj As Management.ManagementObject In cmicWmi.Get
  65. diskId = cmicWmiObj("size") 'diskId = cmicWmiObj("signature")
  66. diskSerialNumber = cmicWmiObj("serialnumber")
  67. diskModel = cmicWmiObj("Model")
  68. Exit For
  69. Next
  70. '-----電腦綁定判斷-------------------------------------------------------------------------------------------------------------------------------------------------------------
  71. PA1 = MACKK : PA2 = diskId : PA3 = diskSerialNumber : PA4 = diskModel
  72. SQL_電腦綁定()
  73. If dr.Read() Then
  74. conn.Close()
  75. Else
  76. conn.Close() : MsgBox("該電腦沒有註冊,無法使用系統。") : Me.Close()
  77. End If
  78. End Sub
  79. Private Sub 伺服器區域_ch_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 伺服器區域_ch.SelectedIndexChanged
  80. '-----------------------確認登入伺服器位置-----------------------------------------------------------------------------------------------------------------------------------------
  81. If 登入判斷 = True And 內外網 = False Then
  82. 登入人IP = "192.168.0.199,2433" : 登入() : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
  83. ElseIf 登入判斷 = True And 內外網 = True Then
  84. 登入人IP = "59.127.190.74,2433" : 登入() : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
  85. ElseIf 登入判斷 = False And 內外網 = False Then
  86. 登入人IP = "106.1.50.79" : 登入() : 確認_bt.Enabled = True : 取消_bt.Enabled = True : 刷卡登入_ch.Checked = True
  87. End If
  88. End Sub
  89. Private Sub 登入()
  90. '-----------------------寫入連線字串-----------------------------------------------------------------------------------------------------------------------------------------------
  91. SQL_連線字串_正式()
  92. 驗證_tb.Text = "1" : g_conn_type = 伺服器區域_ch.Text & "伺服器"
  93. '-----------------------系統版本號驗證-----------------------------------------------------------------------------------------------------------------------------------------------
  94. SQL_系統版本號驗證()
  95. If dr.Read() Then : 資料庫版本號_lb.Text = "資料庫版本號 : " & dr("系統認證版本號") : 版本號 = dr("系統認證版本號") : End If : conn.Close()
  96. '-----------------------FTP伺服器登入位置--------------------------------------------------------------------------------------------------------------------------------------
  97. SQL_FTP伺服器登入位置()
  98. If dr.Read() Then : Target = dr("FTP地址") : FTP帳號 = dr("FTP帳號") : FTP密碼 = dr("FTP密碼") : FTP物理位置 = dr("FTP物理位置") : End If : conn.Close()
  99. Set_清單1()
  100. Dim HH As String = 0
  101. For i As Integer = 0 To FTP清單_dgv.Rows.Count - 1
  102. If i < 10 Then : HH = "0" & i : ElseIf i >= 10 Then : HH = i : End If
  103. If FTP清單_dgv("指定", i).Value.ToString = "AA" & HH Then : AA(i) = FTP清單_dgv("資料夾名稱", i).Value.ToString : End If
  104. Next
  105. Target1 = Target & AA(0) & "/"
  106. FTP執行檔_wb.Url = New Uri(Target1)
  107. SQL_帳號讀取()
  108. 使用者帳號_cb.Items.Clear() : While (dr.Read()) : 使用者帳號_cb.Items.Add(dr("帳號")) : End While : conn.Close()
  109. If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
  110. 自動更新2()
  111. Else : End If
  112. End Sub
  113. Private Sub 自動更新1()
  114. Dim aa1 As MsgBoxResult
  115. aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請開發人員注意是否有其他人員修改。並決定是否下載最新的執行檔?", MsgBoxStyle.OkCancel)
  116. If aa1 = MsgBoxResult.Ok Then
  117. With SaveFileDialog1 : .Filter = "所有文件(*.exe)|*.exe" : End With
  118. SaveFileDialog1.FileName = "MAOJI-ERP-SYS - " & 版本號 & ".exe"
  119. SaveFileDialog1.ShowDialog()
  120. If Strings.Right(SaveFileDialog1.FileName, 30) = "MAOJI-ERP-SYS - " & 版本號 & ".exe" Then
  121. My.Computer.Network.DownloadFile(Target & AA(0) & "/" & "MAOJI-ERP-SYS - " & 版本號 & ".exe", SaveFileDialog1.FileName, "", "", True, 10000, True)
  122. MsgBox("下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。")
  123. Me.Close()
  124. Else
  125. MsgBox("操作不正確,請用手動方式下載更新。")
  126. End If
  127. Else
  128. 登入程序()
  129. End If
  130. End Sub
  131. Private Sub 自動更新2()
  132. Dim aa1 As MsgBoxResult
  133. aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請下載最新的執行檔。", MsgBoxStyle.OkCancel)
  134. If aa1 = MsgBoxResult.Ok Then
  135. With SaveFileDialog1 : .Filter = "所有文件(*.exe)|*.exe" : End With
  136. SaveFileDialog1.FileName = "MAOJI-ERP-SYS - " & 版本號 & ".exe"
  137. SaveFileDialog1.ShowDialog()
  138. If Strings.Right(SaveFileDialog1.FileName, 30) = "MAOJI-ERP-SYS - " & 版本號 & ".exe" Then
  139. My.Computer.Network.DownloadFile(Target & AA(0) & "/" & "MAOJI-ERP-SYS - " & 版本號 & ".exe", SaveFileDialog1.FileName, "", "", True, 10000, True)
  140. MsgBox("下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。")
  141. Me.Close()
  142. Else
  143. MsgBox("操作不正確,請用手動方式下載更新。")
  144. End If
  145. End If
  146. End Sub
  147. Private Sub 登入第一層()
  148. If 帳號_tb.Text = "b70340" Or 帳號_tb.Text = "B70340" Then
  149. If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then : 自動更新1() : Else : 登入程序() : End If
  150. Else
  151. If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then : 自動更新2() : Else : 登入程序() : End If
  152. End If
  153. End Sub
  154. Private Sub 登入程序()
  155. If 帳號_tb.Text = "" Then
  156. MsgBox("請輸入帳號! 如使用刷登入,請確定該卡片有合法註冊!")
  157. ElseIf 帳號_tb.Text <> "" Then
  158. If 帳號_tb.Text = "" Then
  159. MsgBox("請輸入帳號!")
  160. ElseIf 帳號_tb.Text <> "" Then
  161. If 驗證_tb.Text = "1" Then
  162. SQL_使用者權限宣告()
  163. If dr.Read() Then
  164. 密碼驗證_tb.Text = dr("密碼").ToString : gUserName = dr("姓名").ToString
  165. For I As Integer = 0 To 權限數量 : CC(I) = dr.Item(I + 3) : Next : 登入第二層()
  166. End If : dr.Close()
  167. End If
  168. End If
  169. End If : conn.Close()
  170. End Sub
  171. Private Sub 登入第二層()
  172. If 密碼_tb.Text = 密碼驗證_tb.Text Then
  173. If 密碼驗證_tb.Text = "" Then
  174. MsgBox("帳號或密碼錯誤,請重新輸入!")
  175. Else
  176. Me.Hide() : MAOJI_ERP_SYS.Show() : 密碼_tb.Text = "" : 帳號_tb.Text = ""
  177. End If
  178. ElseIf 密碼_tb.Text <> 密碼驗證_tb.Text Then
  179. MsgBox("帳號或密碼錯誤,請重新輸入!")
  180. End If
  181. End Sub
  182. Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 確認_bt.Click
  183. 登入第一層()
  184. End Sub
  185. Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 取消_bt.Click
  186. Me.Close()
  187. End Sub
  188. Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles 更新下載_ch.CheckedChanged
  189. If 更新下載_ch.Checked = False Then
  190. Me.Size = New Size(466, 279)
  191. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
  192. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
  193. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
  194. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
  195. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
  196. End If
  197. Else
  198. Me.Size = New Size(705, 279)
  199. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(608, 401)
  200. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(331, 245)
  201. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(368, 311)
  202. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(288, 373)
  203. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(448, 311)
  204. End If
  205. End If
  206. End Sub
  207. Private Sub UsernameTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 帳號_tb.KeyPress
  208. If e.KeyChar = ChrW(13) Then : Me.確認_bt.PerformClick() : End If
  209. End Sub
  210. Private Sub PasswordTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 密碼_tb.KeyPress
  211. If e.KeyChar = ChrW(13) Then : Me.確認_bt.PerformClick() : End If
  212. End Sub
  213. Private Sub UsernameTextBox_TextChanged(sender As Object, e As EventArgs) Handles 帳號_tb.TextChanged
  214. If 刷卡登入_ch.Checked = False Then
  215. Else
  216. If IsNumeric(帳號_tb.Text) = True Then
  217. If 帳號_tb.Text.Length = 10 Then
  218. SQL_刷卡登入()
  219. If dr.Read() Then
  220. 帳號_tb.Text = dr("帳號").ToString : 密碼_tb.Text = dr("密碼").ToString
  221. Else
  222. 帳號_tb.Text = "" : 密碼_tb.Text = ""
  223. End If : conn.Close()
  224. Exit Sub : Me.確認_bt.PerformClick()
  225. End If
  226. End If
  227. End If
  228. End Sub
  229. Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles 刷卡登入_ch.Click
  230. Me.ActiveControl = 使用者帳號_cb
  231. End Sub
  232. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 使用者帳號_cb.TextChanged
  233. 帳號_tb.Text = 使用者帳號_cb.Text
  234. End Sub
  235. End Class