Ei kuvausta
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.

Login.vb 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. Option Explicit On
  2. Imports System.Data.SqlClient
  3. Imports System.Net
  4. Public Class Login
  5. ReadOnly screenWidth = Screen.PrimaryScreen.Bounds.Width
  6. ReadOnly screenHeight = Screen.PrimaryScreen.Bounds.Height
  7. ' TODO: 插入程式碼,利用提供的使用者名稱和密碼執行自訂驗證
  8. ' (請參閱 http://go.microsoft.com/fwlink/?LinkId=35339)。
  9. ' 如此便可將自訂主體附加到目前執行緒的主體,如下所示:
  10. ' My.User.CurrentPrincipal = CustomPrincipal
  11. ' 其中 CustomPrincipal 是用來執行驗證的 IPrincipal 實作。
  12. ' 接著,My.User 便會傳回封裝在 CustomPrincipal 物件中的識別資訊,
  13. ' 例如使用者名稱、顯示名稱等。
  14. ReadOnly ds2 As New DataSet
  15. Public Property Credentials As ICredentials
  16. Public Property Target1 As String
  17. Private Property MYSQL As String
  18. ReadOnly da As Object
  19. ReadOnly ds As Object
  20. ReadOnly conn As New SqlConnection
  21. ReadOnly cmd As New SqlCommand
  22. ReadOnly da1 As New SqlDataAdapter
  23. Dim dr As SqlDataReader
  24. Dim MACKK As String 'MAC碼
  25. Dim diskId As String '數字ID
  26. Dim diskSerialNumber As String '硬碟序列
  27. Dim diskModel As String '磁盘型態
  28. Dim FFGG As Integer : Dim GGHH As Integer
  29. Dim HostName As String
  30. Dim IPAdress As IPAddress
  31. Dim MYIP As String
  32. Private Sub Set_DGV1載入前設定()
  33. DataGridView1.DataSource = Nothing : ds2.Clear()
  34. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  35. DataGridView1.ColumnHeadersHeight = 25
  36. DataGridView1.AllowUserToAddRows = False
  37. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  38. End Sub
  39. Private Sub Set_DGV1載入後設定()
  40. cmd.Connection = conn : cmd.CommandText = SQL1 : da1.SelectCommand = cmd : da1.Fill(ds2) : DataGridView1.DataSource = ds2.Tables(0) : conn.Close()
  41. End Sub
  42. Private Sub Set_清單1()
  43. Set_DGV1載入前設定()
  44. SQL1 = "SELECT 資料夾名稱, 指定 FROM FTP資料夾管理"
  45. Set_DGV1載入後設定()
  46. End Sub
  47. <Obsolete>
  48. Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  49. '-----------------------控件基本設定-----------------------------------------------------------------------------------------------------------------------------------------------
  50. CheckBox1.Enabled = False : CheckBox3.Checked = True : CheckBox3.Enabled = False : CheckBox1.Enabled = False
  51. TextBox4.Text = "1"
  52. Label1.Text = "執行檔版本號 : " & 版本
  53. 網段.ShowDialog()
  54. If 登入判斷 = True And 內外網 = False Then
  55. ComboBox1.Text = "工巧明內網"
  56. OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
  57. ElseIf 登入判斷 = False And 內外網 = False Then
  58. ComboBox1.Text = "工巧明內網"
  59. OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
  60. ElseIf 登入判斷 = True And 內外網 = True Then
  61. ComboBox1.Text = "工巧明外網"
  62. OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
  63. End If
  64. '-----------------------取得本機IP-----------------------------------------------------------------------------------------------------------------------------------------------
  65. HostName = Dns.GetHostName '获得本机的机器名
  66. IPAdress = Dns.GetHostByName(HostName).AddressList.GetValue(0) '获得本机的IP
  67. MYIP = IPAdress.ToString
  68. '-----------------------IP比對----------------------------------------------------------------------------------------------------------------------------------------------------
  69. If Strings.Left(MYIP, 10) = "192.168.12" Or Strings.Left(MYIP, 7) = "10.0.0." Then
  70. ComboBox1.Text = "工巧明內網"
  71. OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
  72. Else
  73. ComboBox1.Text = "工巧明外網"
  74. OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
  75. End If
  76. '-----------------------調整視窗大小-----------------------------------------------------------------------------------------------------------------------------------------------
  77. Me.Size = New Size(466, 279)
  78. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
  79. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
  80. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
  81. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
  82. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
  83. End If
  84. End Sub
  85. <Obsolete>
  86. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  87. '-----------------------確認登入伺服器位置-----------------------------------------------------------------------------------------------------------------------------------------
  88. If ComboBox1.Text = "工巧明內網" Then
  89. HostName = Dns.GetHostName '获得本机的机器名
  90. IPAdress = Dns.GetHostByName(HostName).AddressList.GetValue(0) '获得本机的IP
  91. MYIP = IPAdress.ToString
  92. If Strings.Left(MYIP, 10) = "192.168.12" Or Strings.Left(MYIP, 7) = "10.0.0." Then
  93. 登入人IP = "192.168.12.127"
  94. 登入()
  95. OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
  96. End If
  97. ElseIf ComboBox1.Text = "工巧明外網" Then
  98. HostName = Dns.GetHostName '获得本机的机器名
  99. IPAdress = Dns.GetHostByName(HostName).AddressList.GetValue(0) '获得本机的IP
  100. MYIP = IPAdress.ToString
  101. If Strings.Left(MYIP, 10) <> "192.168.12" Or Strings.Left(MYIP, 7) <> "10.0.0." Then
  102. 登入人IP = "180.177.181.162,5264"
  103. 登入()
  104. OK.Enabled = True : Cancel.Enabled = True : CheckBox1.Checked = True
  105. End If
  106. End If
  107. UsernameTextBox.Focus()
  108. End Sub
  109. Private Sub 登入()
  110. '-----------------------寫入連線字串-----------------------------------------------------------------------------------------------------------------------------------------------
  111. ConString = "Data Source=" & 登入人IP & ";Initial Catalog=我的資料庫;Persist Security Info=True;User ID=b70340;Password=0911274990;Max pool size = 200;Connection Timeout=0"
  112. g_conn_type = ComboBox1.Text & "伺服器"
  113. '-----------------------系統版本號寫入-----------------------------------------------------------------------------------------------------------------------------------------------
  114. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  115. SQL1 = "SELECT 系統認證版本號 FROM 版本號管理 "
  116. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  117. If dr.Read() Then
  118. Label2.Text = "資料庫版本號 : " & dr("系統認證版本號") : 版本號 = dr("系統認證版本號")
  119. End If : conn.Close()
  120. '-----------------------FTP資料夾登入位置宣告--------------------------------------------------------------------------------------------------------------------------------------
  121. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  122. SQL1 = "SELECT FTP地址, FTP帳號, FTP密碼 FROM FTP資料庫管理 WHERE 地區 LIKE N'" & ComboBox1.Text & "'"
  123. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  124. If dr.Read() Then
  125. Target = dr("FTP地址") : FTP帳號 = dr("FTP帳號") : FTP密碼 = dr("FTP密碼")
  126. End If : conn.Close()
  127. Set_清單1()
  128. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  129. If DataGridView1(1, i).Value.ToString = "AA00" Then : AA(0) = DataGridView1(0, i).Value.ToString : End If
  130. If DataGridView1(1, i).Value.ToString = "AA01" Then : AA(1) = DataGridView1(0, i).Value.ToString : End If
  131. If DataGridView1(1, i).Value.ToString = "AA02" Then : AA(2) = DataGridView1(0, i).Value.ToString : End If
  132. If DataGridView1(1, i).Value.ToString = "AA03" Then : AA(3) = DataGridView1(0, i).Value.ToString : End If
  133. If DataGridView1(1, i).Value.ToString = "AA04" Then : AA(4) = DataGridView1(0, i).Value.ToString : End If
  134. Next
  135. Target1 = Target & AA(1) & "/"
  136. WebBrowser3.Url = New Uri(Target1)
  137. If Strings.Right(Label1.Text, 10) <> Strings.Right(Label2.Text, 10) Then
  138. 自動更新2()
  139. Else : End If
  140. End Sub
  141. Private Sub 自動更新1()
  142. Dim aa1 As MsgBoxResult
  143. aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請開發人員注意是否有其他人員修改。並決定是否下載最新的執行檔?", MsgBoxStyle.OkCancel)
  144. If aa1 = MsgBoxResult.Ok Then
  145. With SaveFileDialog1 : .Filter = "所有文件(*.exe)|*.exe" : End With
  146. SaveFileDialog1.FileName = "GCM-ERP-SYS - " & 版本號 & ".exe"
  147. SaveFileDialog1.ShowDialog()
  148. If Strings.Right(SaveFileDialog1.FileName, 28) = "GCM-ERP-SYS - " & 版本號 & ".exe" Then
  149. My.Computer.Network.DownloadFile(Target & AA(1) & "/" & "GCM-ERP-SYS - " & 版本號 & ".exe", SaveFileDialog1.FileName, "", "", True, 10000, True)
  150. MsgBox("下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。")
  151. Me.Close()
  152. Else
  153. MsgBox("操作不正確,請用手動方式下載更新。")
  154. End If
  155. Else
  156. 登入第二層()
  157. End If
  158. End Sub
  159. Private Sub 自動更新2()
  160. Dim aa1 As MsgBoxResult
  161. aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請下載最新的執行檔。", MsgBoxStyle.OkCancel)
  162. If aa1 = MsgBoxResult.Ok Then
  163. With SaveFileDialog1 : .Filter = "所有文件(*.exe)|*.exe" : End With
  164. SaveFileDialog1.FileName = "GCM-ERP-SYS - " & 版本號 & ".exe"
  165. SaveFileDialog1.ShowDialog()
  166. If Strings.Right(SaveFileDialog1.FileName, 28) = "GCM-ERP-SYS - " & 版本號 & ".exe" Then
  167. My.Computer.Network.DownloadFile(Target & AA(1) & "/" & "GCM-ERP-SYS - " & 版本號 & ".exe", SaveFileDialog1.FileName, "", "", True, 10000, True)
  168. MsgBox("下載完成,請手動刪除就的執行檔,並且用新的執行檔開啟。")
  169. Me.Close()
  170. Else
  171. MsgBox("操作不正確,請用手動方式下載更新。")
  172. End If
  173. End If
  174. End Sub
  175. Private Sub 登入第一層()
  176. If UsernameTextBox.Text = "" Then
  177. MsgBox("請輸入帳號! 如使用刷登入,請確定該卡片有合法註冊!")
  178. ElseIf UsernameTextBox.Text <> "" Then
  179. If UsernameTextBox.Text = "" Then
  180. MsgBox("請輸入帳號!")
  181. ElseIf UsernameTextBox.Text <> "" Then
  182. If TextBox4.Text = "1" Then
  183. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  184. MYSQL = "SELECT " & 登入權限AQL & " FROM 使用者 WHERE (帳號 = '" & UsernameTextBox.Text & "')"
  185. cmd.Connection = conn : cmd.CommandText = MYSQL : dr = cmd.ExecuteReader
  186. If dr.Read() Then
  187. TextBox1.Text = dr("密碼").ToString : gUserName = dr("姓名").ToString : TextBox2.Text = dr("密碼日期").ToString
  188. For I As Integer = 0 To 26
  189. CC(I) = dr.Item(I + 4)
  190. Next
  191. FFGG = DateDiff("d", TextBox2.Text, Format(Today(), "yyyy/MM/dd"))
  192. If CC(24) = True Then
  193. GGHH = 密碼時限 - FFGG
  194. If GGHH <= 0 Then
  195. MsgBox("密碼過期!")
  196. 個人帳號管理.ShowDialog()
  197. Else
  198. If Strings.Right(Label1.Text, 10) <> Strings.Right(Label2.Text, 10) Then
  199. If CC(26) = True Then
  200. 自動更新1()
  201. Else
  202. 自動更新2()
  203. End If
  204. Else
  205. 登入第二層()
  206. End If
  207. End If
  208. Else
  209. If Strings.Right(Label1.Text, 10) <> Strings.Right(Label2.Text, 10) Then
  210. If CC(26) = True Then
  211. 自動更新1()
  212. Else
  213. 自動更新2()
  214. End If
  215. Else
  216. 登入第二層()
  217. End If
  218. End If
  219. End If
  220. dr.Close()
  221. End If
  222. End If
  223. End If
  224. conn.Close()
  225. End Sub
  226. Private Sub 登入第二層()
  227. If PasswordTextBox.Text = TextBox1.Text Then
  228. If TextBox1.Text = "" Then
  229. MsgBox("帳號或密碼錯誤,請重新輸入!")
  230. Else
  231. Me.Hide()
  232. GCM_ERP_SYS.Show() : PasswordTextBox.Text = "" : UsernameTextBox.Text = ""
  233. End If
  234. ElseIf PasswordTextBox.Text <> TextBox1.Text Then
  235. MsgBox("帳號或密碼錯誤,請重新輸入!")
  236. End If
  237. End Sub
  238. Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
  239. If ComboBox1.Text = "" Then
  240. MsgBox("請正確選擇正確資料庫!")
  241. Else
  242. '-----MAC碼----------------------------------------------------------------------------------------------
  243. Dim Wmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
  244. For Each WmiObj As Management.ManagementObject In Wmi.Get
  245. If CBool(WmiObj("IPEnabled")) Then
  246. MACKK = WmiObj("MACAddress")
  247. End If
  248. Next
  249. '-----硬碟資料----------------------------------------------------------------------------------------------
  250. Dim cmicWmi As New Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")
  251. For Each cmicWmiObj As Management.ManagementObject In cmicWmi.Get
  252. diskId = cmicWmiObj("signature")
  253. diskSerialNumber = cmicWmiObj("serialnumber")
  254. diskModel = cmicWmiObj("Model")
  255. Next
  256. If UsernameTextBox.Text = "b70340" Or UsernameTextBox.Text = "B70340" Then
  257. 登入第一層() : 判斷重登 = False
  258. ElseIf CheckBox3.Checked = True Then
  259. conn.Close()
  260. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  261. SQL1 = "SELECT MAC碼 FROM 系統綁定電腦資訊
  262. WHERE MAC碼 LIKE N'" & MACKK & "' AND 硬碟ID LIKE N'" & diskId & "' AND 硬碟序列 LIKE N'" & diskSerialNumber & "' AND 磁盘型態 LIKE N'" & diskModel & "'"
  263. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  264. If dr.Read() Then
  265. conn.Close()
  266. 登入第一層()
  267. Else
  268. conn.Close()
  269. MsgBox("該電腦沒有註冊,無法使用系統。")
  270. End If
  271. ElseIf CheckBox3.Checked = False Then
  272. 登入第一層()
  273. End If
  274. End If
  275. End Sub
  276. Private Sub Cancel_Click(sender As Object, e As EventArgs) Handles Cancel.Click
  277. Me.Close()
  278. End Sub
  279. Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
  280. If CheckBox2.Checked = False Then
  281. Me.Size = New Size(466, 279)
  282. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
  283. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
  284. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
  285. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
  286. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
  287. End If
  288. Else
  289. Me.Size = New Size(705, 279)
  290. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(608, 401)
  291. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(331, 245)
  292. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(368, 311)
  293. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(288, 373)
  294. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(448, 311)
  295. End If
  296. End If
  297. End Sub
  298. Private Sub UsernameTextBox_TextChanged(sender As Object, e As EventArgs) Handles UsernameTextBox.TextChanged
  299. If CheckBox1.Checked = False Then
  300. Else
  301. If IsNumeric(UsernameTextBox.Text) = True Then
  302. If UsernameTextBox.Text.Length = 10 Then
  303. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  304. MYSQL = "SELECT 帳號, 密碼 FROM 使用者 WHERE (ID卡號 = '" & UsernameTextBox.Text & "')"
  305. cmd.Connection = conn : cmd.CommandText = MYSQL : dr = cmd.ExecuteReader
  306. If dr.Read() Then
  307. UsernameTextBox.Text = dr("帳號").ToString
  308. PasswordTextBox.Text = dr("密碼").ToString
  309. conn.Close()
  310. Else
  311. UsernameTextBox.Text = "" : PasswordTextBox.Text = "" : conn.Close()
  312. End If
  313. Exit Sub : Me.OK.PerformClick()
  314. End If
  315. End If
  316. End If
  317. End Sub
  318. Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
  319. UsernameTextBox.Focus()
  320. End Sub
  321. End Class