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.

人員入職資料表.vb 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Imports System.IO
  4. Imports System.Net
  5. Public Class 人員入職資料表
  6. Public Property Credentials As ICredentials
  7. ReadOnly conn As New SqlConnection
  8. ReadOnly da As New SqlDataAdapter
  9. ReadOnly cmd As New SqlCommand
  10. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet
  11. Dim dr As SqlDataReader
  12. Dim DTP As String : Dim DTP1 As String
  13. Private Sub Set_使用者清單()
  14. DataGridView1.DataSource = Nothing : ds.Clear()
  15. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  16. DataGridView1.ColumnHeadersHeight = 25
  17. DataGridView1.AllowUserToAddRows = False
  18. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  19. SQL1 = "SELECT 人事資料表.員工編號, 使用者權限管理表.姓名 AS 系統登入姓名, 人事資料表.姓名, 人事資料表.入職日期
  20. FROM 使用者權限管理表 LEFT OUTER JOIN
  21. 人事資料表 ON 使用者權限管理表.員工編號 = 人事資料表.員工編號 AND
  22. 使用者權限管理表.姓名 = 人事資料表.系統登入姓名
  23. WHERE (使用者權限管理表.CC49 = 0) AND (人事資料表.員工編號 IS NULL)
  24. ORDER BY 使用者權限管理表.職稱"
  25. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
  26. End Sub
  27. Private Sub Set_grid()
  28. DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).Width = 150 : DataGridView1.Columns(2).Visible = False : DataGridView1.Columns(3).Visible = False
  29. End Sub
  30. Private Sub Set_人員清單()
  31. DataGridView2.DataSource = Nothing : ds1.Clear()
  32. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  33. DataGridView2.ColumnHeadersHeight = 25
  34. DataGridView2.AllowUserToAddRows = False
  35. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  36. SQL1 = "SELECT 人事資料表.員工編號, 使用者權限管理表.姓名 AS 系統登入姓名, 人事資料表.姓名, 人事資料表.入職日期, 人事資料表.離職日期
  37. FROM 使用者權限管理表 LEFT OUTER JOIN
  38. 人事資料表 ON 使用者權限管理表.員工編號 = 人事資料表.員工編號 AND
  39. 使用者權限管理表.姓名 = 人事資料表.系統登入姓名
  40. WHERE (使用者權限管理表.CC49 = 0) AND (人事資料表.員工編號 IS NOT NULL) AND (人事資料表.離職日期 LIKE '在職')
  41. ORDER BY 使用者權限管理表.職稱"
  42. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1()
  43. End Sub
  44. Private Sub Set_grid1()
  45. DataGridView2.Columns(0).Visible = False : DataGridView2.Columns(1).Width = 150 : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).Visible = False
  46. DataGridView2.Columns(4).Visible = False
  47. End Sub
  48. Private Sub 讀取圖片()
  49. conn.Close()
  50. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  51. SQL1 = "SELECT 人事表圖片 FROM 人事資料表 WHERE 員工編號 LIKE N'" & TextBox1.Text & "'"
  52. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  53. While dr.Read() = True
  54. Dim unused As Byte() = New Byte(-1) {}
  55. Dim bytes As Byte() = DirectCast(dr.Item("人事表圖片"), Byte())
  56. Dim oStream As New MemoryStream(bytes)
  57. PictureBox1.Image = Bitmap.FromStream(oStream)
  58. End While
  59. conn.Close()
  60. PictureBox1.SizeMode = 4
  61. End Sub
  62. Private Sub 人員入職資料表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  63. Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  64. Set_使用者清單() : Set_人員清單()
  65. TextBox1.Enabled = False : TextBox2.Enabled = False : TextBox7.Visible = False : GroupBox1.Visible = False
  66. Target1 = Target & AA(14) & "/"
  67. WebBrowser1.Url = New Uri(Target1)
  68. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  69. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  70. End If
  71. End Sub
  72. Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  73. If e.RowIndex = -1 Then : Else
  74. TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
  75. TextBox1.Text = "" : TextBox3.Text = ""
  76. PictureBox1.Image = Nothing
  77. End If
  78. End Sub
  79. Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  80. If e.RowIndex = -1 Then : Else
  81. TextBox1.Text = DataGridView2(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView2(1, e.RowIndex).Value.ToString : TextBox3.Text = DataGridView2(2, e.RowIndex).Value.ToString
  82. DateTimePicker1.Value = DataGridView2(3, e.RowIndex).Value.ToString : TextBox5.Text = DataGridView2(4, e.RowIndex).Value.ToString
  83. Dim TSFM As Integer = DateDiff("d", DateTimePicker1.Value, Today())
  84. TextBox6.Text = TSFM
  85. 讀取圖片()
  86. End If
  87. End Sub
  88. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  89. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  90. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  91. End If
  92. End Sub
  93. Private Sub TextBox4_DragEnter(sender As Object, e As DragEventArgs) Handles TextBox4.DragEnter
  94. If e.Data.GetDataPresent(DataFormats.FileDrop) Then
  95. Dim files As String()
  96. Try
  97. files = CType(e.Data.GetData(DataFormats.FileDrop), String())
  98. TextBox4.Text = files(files.Length - 1)
  99. Catch ex As Exception
  100. MessageBox.Show(ex.Message)
  101. Return
  102. End Try
  103. End If
  104. Dim STR2 As Integer = 0
  105. TextBox7.Text = TextBox4.Text
  106. If TextBox4.Text = "" Then
  107. Else
  108. For i As Integer = 0 To 9999
  109. Dim STR1 As Integer = Strings.Len(TextBox7.Text)
  110. If Strings.Right((TextBox7.Text), 1) <> "\" Then
  111. STR1 -= 1 : STR2 += 1
  112. If STR1 = 0 Then
  113. TextBox7.Text = ""
  114. TextBox4.Text = ""
  115. i = 9999
  116. Else
  117. TextBox7.Text = Strings.Left((TextBox7.Text), STR1)
  118. End If
  119. Else
  120. TextBox7.Text = Strings.Right((TextBox4.Text), STR2)
  121. TextBox4.Text = TextBox7.Text
  122. i = 9999
  123. End If
  124. Next
  125. End If
  126. End Sub
  127. Private Sub TextBox4_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBox4.DragDrop
  128. Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
  129. For Each file As String In files
  130. TextBox4.AppendText(file + Environment.NewLine)
  131. Next
  132. End Sub
  133. Private Sub Set_日期格式轉換()
  134. DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd")
  135. DTP1 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  136. End Sub
  137. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  138. If TextBox4.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
  139. MsgBox("請確定人事資料表的圖片檔已準備完成,並且有選擇未建檔的人事清單資料、人員中文姓名有填寫等")
  140. Else
  141. If TextBox1.Text <> "" Then
  142. MsgBox("該員工編號已經建檔完畢,請確認資料是否正確")
  143. Else
  144. conn.Close()
  145. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  146. SQL1 = "SELECT TOP (1) 員工編號 FROM 人事資料表 ORDER BY 員工編號 DESC"
  147. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  148. If dr.Read() Then : TextBox1.Text = dr("員工編號").ToString : Else : TextBox1.Text = "EN00000000" : End If
  149. conn.Close()
  150. Dim NUM1 As Integer
  151. NUM1 = Double.Parse(Strings.Right(TextBox1.Text, 8)) + 1
  152. If NUM1 < 10 Then : TextBox1.Text = "EN" & "0000000" & NUM1
  153. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox1.Text = "EN" & "000000" & NUM1
  154. ElseIf NUM1 > 99 And NUM1 < 1000 Then : TextBox1.Text = "EN" & "00000" & NUM1
  155. ElseIf NUM1 > 999 And NUM1 < 10000 Then : TextBox1.Text = "EN" & "0000" & NUM1
  156. ElseIf NUM1 > 9999 And NUM1 < 100000 Then : TextBox1.Text = "EN" & "000" & NUM1
  157. ElseIf NUM1 > 99999 And NUM1 < 100000 Then : TextBox1.Text = "EN" & "00" & NUM1
  158. ElseIf NUM1 > 999999 And NUM1 < 1000000 Then : TextBox1.Text = "EN" & "0" & NUM1
  159. ElseIf NUM1 > 9999999 Then : TextBox1.Text = "EN" & NUM1
  160. End If
  161. Set_日期格式轉換()
  162. conn.Close()
  163. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  164. SQL1 = "INSERT INTO 人事資料表 (員工編號, 系統登入姓名, 姓名, 入職日期, 離職日期, 人事表圖片) SELECT N'" & TextBox1.Text & "',N'" & TextBox2.Text & "',N'" & TextBox3.Text &
  165. "','" & DTP & "','在職', " &
  166. "BULKCOLUMN FROM OPENROWSET ( BULK '" & FTP實體位置 & AA(14) & "\" & TextBox4.Text & "', SINGLE_BLOB) AS EMPLOYEEPICTURE"
  167. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  168. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  169. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  170. frq = CType(WebRequest.Create(New Uri(Target1 & TextBox4.Text)), FtpWebRequest)
  171. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  172. frq.Credentials = fcr
  173. frq.Method = WebRequestMethods.Ftp.DeleteFile
  174. frq.UseBinary = True
  175. frp = CType(frq.GetResponse, FtpWebResponse)
  176. frp.Close()
  177. WebBrowser1.Refresh()
  178. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  179. TextBox4.Text = ""
  180. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  181. SQL1 = "UPDATE 使用者權限管理表 SET 員工編號 = '" & TextBox1.Text & "' WHERE (姓名 = '" & TextBox2.Text & "')"
  182. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  183. MsgBox("新增完成")
  184. Set_使用者清單() : Set_人員清單()
  185. 讀取圖片()
  186. End If
  187. End If
  188. End Sub
  189. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click
  190. If TextBox1.Text = "" Or TextBox4.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
  191. MsgBox("請確定人事資料表的圖片檔已準備完成,並且所有人事清單資料、人員中文姓名等資料正確")
  192. Else
  193. conn.Close()
  194. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  195. SQL1 = "UPDATE 人事資料表 SET 人事表圖片 = BULKCOLUMN FROM OPENROWSET ( BULK '" & FTP實體位置 & AA(14) & "\" & TextBox4.Text & "', SINGLE_BLOB) AS EMPLOYEEPICTURE " &
  196. "WHERE (員工編號 = '" & TextBox1.Text & "')"
  197. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  198. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  199. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  200. frq = CType(WebRequest.Create(New Uri(Target1 & TextBox4.Text)), FtpWebRequest)
  201. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  202. frq.Credentials = fcr
  203. frq.Method = WebRequestMethods.Ftp.DeleteFile
  204. frq.UseBinary = True
  205. frp = CType(frq.GetResponse, FtpWebResponse)
  206. frp.Close()
  207. WebBrowser1.Refresh()
  208. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  209. TextBox4.Text = ""
  210. MsgBox("修改完成")
  211. 讀取圖片()
  212. End If
  213. End Sub
  214. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  215. If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
  216. MsgBox("請確定選中離職人員的人事資料表")
  217. Else
  218. GroupBox1.Visible = True
  219. End If
  220. End Sub
  221. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  222. Set_日期格式轉換()
  223. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  224. SQL1 = "UPDATE 人事資料表 SET 離職日期 = '" & DTP1 & "' WHERE (員工編號 = '" & TextBox1.Text & "')"
  225. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  226. GroupBox1.Visible = False
  227. Set_使用者清單() : Set_人員清單()
  228. End Sub
  229. End Class