Geen omschrijving
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 13KB

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