Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LoginForm1.vb 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. Imports System.Net
  2. Imports System.IO
  3. Imports System.Text
  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. Public Property Credentials As ICredentials
  13. Private ReadOnly ds As Object
  14. Private ReadOnly ds2 As New DataSet
  15. Private ReadOnly screenWidth = Screen.PrimaryScreen.Bounds.Width
  16. Private ReadOnly screenHeight = Screen.PrimaryScreen.Bounds.Height
  17. Dim HH As String
  18. Dim Str As String = Application.StartupPath
  19. Dim Strs As String = Application.StartupPath
  20. Private Sub Set_清單1()
  21. 表單1_dgv.DataSource = Nothing : ds2.Clear()
  22. 表單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  23. 表單1_dgv.ColumnHeadersHeight = 25
  24. 表單1_dgv.AllowUserToAddRows = False
  25. SQL_資料夾名稱清單()
  26. da.Fill(ds2) : 表單1_dgv.DataSource = ds2.Tables(0) : conn.Close()
  27. End Sub
  28. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  29. '-----------------------刪除自動更新項目-------------------------------------------------------------------------------------------------------------------------------------------
  30. Dim 已開啟 As Boolean = False
  31. If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\SYS-UPDATE.exe") Then
  32. Dim pro() As Process = System.Diagnostics.Process.GetProcesses()
  33. ' 判斷是否有符合的Process
  34. For Each process As Process In pro
  35. If ("SYS-UPDATE").Equals(process.ProcessName) Then
  36. 已開啟 = True
  37. End If
  38. Next
  39. If 已開啟 = False Then
  40. Timer1.Enabled = False
  41. If File.Exists(Str + "\SYS-UPDATE.exe") Then : File.Delete(Str + "\SYS-UPDATE.exe") : End If
  42. If File.Exists(Str + "\LIVE.txt") Then : File.Delete(Str + "\LIVE.txt") : End If : Timer1.Enabled = False
  43. End If
  44. ElseIf File.Exists(Strs & "\SYS-UPDATE.exe") Then
  45. Dim pro() As Process = System.Diagnostics.Process.GetProcesses()
  46. ' 判斷是否有符合的Process
  47. For Each process As Process In pro
  48. If ("SYS-UPDATE").Equals(process.ProcessName) Then
  49. 已開啟 = True
  50. End If
  51. Next
  52. If 已開啟 = False Then
  53. Timer1.Enabled = False
  54. If File.Exists(Str + "\SYS-UPDATE.exe") Then : File.Delete(Str + "\SYS-UPDATE.exe") : End If
  55. If File.Exists(Str + "\LIVE.txt") Then : File.Delete(Str + "\LIVE.txt") : End If : Timer1.Enabled = False
  56. End If
  57. End If
  58. End Sub
  59. <Obsolete>
  60. Private Sub LoginForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  61. '-----------------------控件基本設定-----------------------------------------------------------------------------------------------------------------------------------------------
  62. 刷卡登入_ch.Checked = True : 刷卡登入_ch.Enabled = False
  63. 執行檔版本號_lb.Text = "執行檔版本號 : " & 版本 : TextBox4.Text = "1"
  64. 網段.ShowDialog()
  65. '-----------------------調整視窗大小-----------------------------------------------------------------------------------------------------------------------------------------------
  66. Me.Size = New Size(466, 279)
  67. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
  68. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
  69. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
  70. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
  71. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
  72. End If
  73. Timer1.Enabled = True
  74. End Sub
  75. Private Sub LoginForm1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
  76. If 登入判斷 = True Then
  77. 伺服器區域選擇_cb.Text = "巨益線路"
  78. OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
  79. ElseIf 登入判斷 = False Then
  80. 伺服器區域選擇_cb.Text = "開發線路"
  81. OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
  82. End If
  83. End Sub
  84. <Obsolete>
  85. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 伺服器區域選擇_cb.SelectedIndexChanged
  86. '-----------------------確認登入伺服器位置-----------------------------------------------------------------------------------------------------------------------------------------
  87. If 伺服器區域選擇_cb.Text = "巨益線路" Then
  88. If SQL_連線狀態模組.ConnectTest("192.168.10.5") = True Then
  89. 登入人IP = "192.168.10.5" : 登入()
  90. OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
  91. Else
  92. MsgBox("巨益伺服器無法連線,自動轉跳測試線路,請聯繫系統管理員!!")
  93. 伺服器區域選擇_cb.Text = "開發線路"
  94. 登入人IP = "106.1.48.106,4567" : 登入()
  95. OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
  96. End If
  97. ElseIf 伺服器區域選擇_cb.Text = "開發線路" Then
  98. 登入人IP = "106.1.48.106,4567" : 登入()
  99. OK.Enabled = True : Cancel.Enabled = True : 刷卡登入_ch.Checked = True
  100. End If
  101. UsernameTextBox.Focus()
  102. End Sub
  103. Private Sub 登入()
  104. '-----------------------寫入連線字串-----------------------------------------------------------------------------------------------------------------------------------------------
  105. If 伺服器區域選擇_cb.Text = "開發線路" Then
  106. SQL_連線字串_測試() : SQL密碼 = "Lee0911274990"
  107. Else
  108. SQL_連線字串_正式() : SQL密碼 = "0911274990"
  109. End If
  110. g_conn_type = 伺服器區域選擇_cb.Text
  111. '-----------------------系統版本號寫入-----------------------------------------------------------------------------------------------------------------------------------------------
  112. SQL_系統認證版本號()
  113. If dr.Read() Then
  114. 資料庫版本號_lb.Text = "資料庫版本號 : " & dr("系統認證版本號") : 版本號 = dr("系統認證版本號")
  115. End If : conn.Close()
  116. '-----------------------FTP資料夾登入位置宣告--------------------------------------------------------------------------------------------------------------------------------------
  117. SQL_FTP資料庫管理()
  118. If dr.Read() Then
  119. Target = dr("FTP地址") : FTP帳號 = dr("FTP帳號") : FTP密碼 = dr("FTP密碼") : FTP實體位置 = dr("FTP實體位置")
  120. End If : conn.Close()
  121. Set_清單1()
  122. For i As Integer = 0 To 表單1_dgv.Rows.Count - 1
  123. If i < 10 Then : HH = "0" & i : ElseIf i >= 10 Then : HH = i : End If
  124. If 表單1_dgv(1, i).Value.ToString = "AA" & HH Then : AA(i) = 表單1_dgv(0, i).Value : End If
  125. Next
  126. Target1 = Target & AA(0) & "/"
  127. WebBrowser3.Url = New Uri(Target1)
  128. '-----------------------自動更新--------------------------------------------------------------------------------------------------------------------------------------
  129. Dim Str As String = Application.StartupPath
  130. If File.Exists(Str + "\WINPROFIT-ERP-SYS - 2021093001.exe") Then
  131. UPDATE_bt.PerformClick()
  132. End If
  133. If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
  134. 自動更新2()
  135. Else : End If
  136. End Sub
  137. Private Sub 登入程序()
  138. If UsernameTextBox.Text = "" Then
  139. MsgBox("請輸入帳號! 如使用刷登入,請確定該卡片有合法註冊!")
  140. ElseIf UsernameTextBox.Text <> "" Then
  141. If TextBox4.Text = "1" Then
  142. SQL_讀取使用者權限管理表()
  143. If dr.Read() Then
  144. TextBox1.Text = dr("密碼").ToString
  145. gUserName = dr("姓名").ToString
  146. 登入人部門 = dr("部門").ToString
  147. For I As Integer = 0 To 95
  148. CC(I) = dr.Item(I + 5)
  149. Next
  150. End If
  151. If PasswordTextBox.Text = TextBox1.Text Then
  152. If TextBox1.Text = "" Then
  153. MsgBox("帳號或密碼錯誤,請重新輸入!")
  154. Else
  155. Me.Hide()
  156. WINPROFIT_ERP_SYS.Show()
  157. OK.Enabled = False : Cancel.Enabled = False
  158. End If
  159. ElseIf PasswordTextBox.Text <> TextBox1.Text Then
  160. MsgBox("帳號或密碼錯誤,請重新輸入!")
  161. End If
  162. dr.Close()
  163. End If
  164. End If
  165. SQL_用員工編號分辨()
  166. If dr.Read() Then
  167. 員工編號 = dr("員工編號").ToString
  168. End If
  169. conn.Close()
  170. End Sub
  171. Private Sub 自動更新1()
  172. Dim Str As String = Application.StartupPath
  173. If File.Exists(Str + "\NOTAUTO.txt") Then : Else
  174. Dim aa1 As MsgBoxResult
  175. aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請開發人員注意是否有其他人員修改。並決定是否下載最新的執行檔?", MsgBoxStyle.OkCancel)
  176. If aa1 = MsgBoxResult.Ok Then
  177. UPDATE_bt.PerformClick()
  178. Else
  179. 登入程序()
  180. End If
  181. End If
  182. End Sub
  183. Private Sub 自動更新2()
  184. Dim Str As String = Application.StartupPath
  185. If File.Exists(Str + "\NOTAUTO.txt") Then : Else
  186. Dim aa1 As MsgBoxResult
  187. aa1 = MsgBox("系統版本號 與 資料庫版本號 對應不上,請下載最新的執行檔。", MsgBoxStyle.OkCancel)
  188. If aa1 = MsgBoxResult.Ok Then
  189. UPDATE_bt.PerformClick()
  190. End If
  191. End If
  192. End Sub
  193. Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
  194. If UsernameTextBox.Text = "b70340" Or UsernameTextBox.Text = "B70340" Then
  195. 登入程序()
  196. Else
  197. If Strings.Right(執行檔版本號_lb.Text, 10) <> Strings.Right(資料庫版本號_lb.Text, 10) Then
  198. 自動更新2()
  199. Else
  200. 登入程序()
  201. End If
  202. End If
  203. End Sub
  204. Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
  205. Me.Close()
  206. End Sub
  207. Private Sub CheckBox2_Click(sender As Object, e As EventArgs) Handles 下載檔案_ch.Click
  208. If 下載檔案_ch.Checked = False Then
  209. Me.Size = New Size(466, 279)
  210. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(727, 401)
  211. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(450, 245)
  212. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(487, 311)
  213. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(407, 373)
  214. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(567, 311)
  215. End If
  216. Else
  217. 輸入密碼.ShowDialog()
  218. If PA = "753582" Then
  219. Me.Size = New Size(705, 279)
  220. If screenWidth = 1920 And screenHeight = 1080 Then : Me.Location = New Point(608, 401)
  221. ElseIf screenWidth = 1366 And screenHeight = 768 Then : Me.Location = New Point(331, 245)
  222. ElseIf screenWidth = 1440 And screenHeight = 900 Then : Me.Location = New Point(368, 311)
  223. ElseIf screenWidth = 1280 And screenHeight = 1024 Then : Me.Location = New Point(288, 373)
  224. ElseIf screenWidth = 1600 And screenHeight = 900 Then : Me.Location = New Point(448, 311)
  225. End If
  226. Else
  227. If PA = "" Then : 下載檔案_ch.Checked = False : Else
  228. MsgBox("密碼錯誤!!") : 下載檔案_ch.Checked = False
  229. End If
  230. End If
  231. End If
  232. End Sub
  233. Private Sub UsernameTextBox_TextChanged(sender As Object, e As EventArgs) Handles UsernameTextBox.TextChanged
  234. If 刷卡登入_ch.Checked = False Then
  235. Else
  236. If IsNumeric(UsernameTextBox.Text) = True Then
  237. If UsernameTextBox.Text.Length = 10 Then
  238. SQL_讀取ID卡號()
  239. If dr.Read() Then
  240. UsernameTextBox.Text = dr("帳號").ToString
  241. PasswordTextBox.Text = dr("密碼").ToString
  242. conn.Close()
  243. Else
  244. UsernameTextBox.Text = "" : PasswordTextBox.Text = "" : conn.Close()
  245. End If
  246. Exit Sub : Me.OK.PerformClick()
  247. End If
  248. End If
  249. End If
  250. End Sub
  251. Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles 刷卡登入_ch.Click
  252. UsernameTextBox.Focus()
  253. End Sub
  254. Private Sub UPDATE_bt_Click(sender As Object, e As EventArgs) Handles UPDATE_bt.Click
  255. Dim Strs As String = Application.StartupPath
  256. If File.Exists(Strs + "\LIVE.txt") Then : File.Delete(Strs + "\LIVE.txt") : End If
  257. Dim filepath As String = Strs + "\LIVE.txt"
  258. Try
  259. Using fs As IO.FileStream = New IO.FileStream(filepath, FileMode.Append)
  260. Using sw As StreamWriter = New StreamWriter(fs, Encoding.Default)
  261. If 伺服器區域選擇_cb.Text = "巨益線路" Then
  262. Dim str As String = "A"
  263. sw.WriteLine(str)
  264. sw.Flush()
  265. Else
  266. Dim str As String = "B"
  267. sw.WriteLine(str)
  268. sw.Flush()
  269. End If
  270. End Using
  271. End Using
  272. Catch ex As Exception
  273. End Try
  274. My.Computer.Network.DownloadFile(Target & AA(0) & "/" & "SYS-UPDATE.exe", Strs + "\SYS-UPDATE.exe")
  275. Shell(Strs + "\SYS-UPDATE.exe", vbNormalFocus)
  276. Me.Close()
  277. End Sub
  278. End Class