Няма описание
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 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 人員行政物料領用記錄表
  4. Dim conn As New SqlConnection
  5. Dim da As New SqlDataAdapter
  6. Dim cmd As New SqlCommand
  7. Dim ds As New DataSet : Dim ds1 As New DataSet : Dim ds2 As New DataSet
  8. Dim dr As SqlDataReader
  9. Dim 編號 As String
  10. Dim KKKJJ As String : Dim KKKJJ2 As String : Dim KKKJJ3 As String : Dim KKK3 As String : Dim KKK4 As String
  11. Dim XXCC As String : Dim DTP As String
  12. Private Sub Set_人員清單()
  13. DataGridView2.DataSource = Nothing : ds1.Clear()
  14. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  15. DataGridView2.ColumnHeadersHeight = 25
  16. DataGridView2.AllowUserToAddRows = False
  17. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  18. SQL1 = "SELECT 人事資料表.員工編號, 使用者權限管理表.姓名 AS 系統登入姓名, 人事資料表.姓名, 人事資料表.入職日期, 人事資料表.離職日期
  19. FROM 使用者權限管理表 LEFT OUTER JOIN
  20. 人事資料表 ON 使用者權限管理表.員工編號 = 人事資料表.員工編號 AND
  21. 使用者權限管理表.姓名 = 人事資料表.系統登入姓名
  22. WHERE (使用者權限管理表.CC49 = 0) AND (人事資料表.員工編號 IS NOT NULL) AND (人事資料表.離職日期 LIKE '在職')
  23. ORDER BY 使用者權限管理表.職稱"
  24. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1()
  25. End Sub
  26. Private Sub Set_grid1()
  27. DataGridView2.Columns(0).Visible = False : DataGridView2.Columns(1).Width = 150 : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).Visible = False
  28. DataGridView2.Columns(4).Visible = False
  29. End Sub
  30. Private Sub Set_清單()
  31. DataGridView1.DataSource = Nothing : ds.Clear()
  32. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  33. DataGridView1.ColumnHeadersHeight = 25
  34. DataGridView1.AllowUserToAddRows = False
  35. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  36. SQL1 = "SELECT 流水號, 人員, 日期, 物料, 數量, 單位 FROM 人員行政物料領用紀錄表 WHERE (人員 LIKE N'" & XXCC & "') " & KKKJJ3 & "
  37. ORDER BY 日期"
  38. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
  39. End Sub
  40. Private Sub Set_grid()
  41. DataGridView1.Columns(0).Width = 150 : DataGridView1.Columns(1).Width = 150 : DataGridView1.Columns(2).Width = 150 : DataGridView1.Columns(3).Width = 934
  42. DataGridView1.Columns(4).Width = 150 : DataGridView1.Columns(5).Width = 150
  43. DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter
  44. End Sub
  45. Private Sub ComboBox1下拉表單資料載入()
  46. conn.Close()
  47. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  48. SQL1 = "SELECT 年份 FROM 年份清單 ORDER BY 年份 DESC"
  49. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  50. ComboBox1.Items.Clear()
  51. While (dr.Read()) : ComboBox1.Items.Add(dr("年份")) : End While
  52. conn.Close()
  53. End Sub
  54. Private Sub ComboBox3下拉表單資料載入()
  55. conn.Close()
  56. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  57. SQL1 = "SELECT 行政物料 FROM 人員行政物料表 ORDER BY 行政物料"
  58. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  59. ComboBox3.Items.Clear()
  60. While (dr.Read()) : ComboBox3.Items.Add(dr("行政物料")) : End While
  61. conn.Close()
  62. End Sub
  63. Private Sub Set_日期格式轉換()
  64. DTP = Format(Today(), "yyyy/MM/dd")
  65. End Sub
  66. Private Sub 人員行政物料領用記錄表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  67. Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  68. ComboBox1下拉表單資料載入() : ComboBox3下拉表單資料載入()
  69. Set_人員清單()
  70. ComboBox1.Text = Year(Today) : ComboBox2.SelectedIndex = Month(Today) - 1
  71. KKKJJ3 = "AND (日期 LIKE N'" & KKK3 & "/" & KKK4 & "%') "
  72. End Sub
  73. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  74. If e.RowIndex = -1 Then : Else
  75. XXCC = DataGridView2.Rows(e.RowIndex).Cells("姓名").Value
  76. KKKJJ3 = "AND (日期 LIKE N'" & KKK3 & "/" & KKK4 & "%') "
  77. Set_清單()
  78. End If
  79. End Sub
  80. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  81. If e.RowIndex = -1 Then : Else
  82. TextBox4.Text = DataGridView1.Rows(e.RowIndex).Cells("流水號").Value
  83. End If
  84. End Sub
  85. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  86. If ComboBox3.Text = "" Or XXCC = "" Then
  87. MsgBox("沒有選擇物料或人員")
  88. Else
  89. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  90. SQL1 = "SELECT TOP (1) 流水號 FROM 人員行政物料領用紀錄表 ORDER BY 流水號 DESC"
  91. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  92. If dr.Read() Then : 編號 = dr("流水號").ToString : Else : 編號 = "MR00000000" : End If
  93. conn.Close()
  94. Dim NUM1 As Integer
  95. NUM1 = Double.Parse(Strings.Right(編號, 8)) + 1
  96. If NUM1 < 10 Then : 編號 = "MR" & "0000000" & NUM1
  97. ElseIf NUM1 > 9 And NUM1 < 100 Then : 編號 = "MR" & "000000" & NUM1
  98. ElseIf NUM1 > 99 And NUM1 < 1000 Then : 編號 = "MR" & "00000" & NUM1
  99. ElseIf NUM1 > 999 And NUM1 < 10000 Then : 編號 = "MR" & "0000" & NUM1
  100. ElseIf NUM1 > 9999 And NUM1 < 100000 Then : 編號 = "MR" & "000" & NUM1
  101. ElseIf NUM1 > 99999 And NUM1 < 100000 Then : 編號 = "MR" & "00" & NUM1
  102. ElseIf NUM1 > 999999 And NUM1 < 1000000 Then : 編號 = "MR" & "0" & NUM1
  103. ElseIf NUM1 > 9999999 Then : 編號 = "MR" & NUM1
  104. End If
  105. Set_日期格式轉換()
  106. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  107. SQL1 = "INSERT INTO 人員行政物料領用紀錄表 (流水號, 人員, 日期, 物料, 數量, 單位) " &
  108. "VALUES (N'" & 編號 & "',N'" & XXCC & "',N'" & DTP & "',N'" & ComboBox3.Text & "','0','')"
  109. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  110. Set_清單()
  111. End If
  112. End Sub
  113. Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
  114. Dim aa As MsgBoxResult
  115. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  116. If AA = MsgBoxResult.Ok Then
  117. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  118. SQL1 = "DELETE FROM 人員行政物料領用紀錄表 WHERE (流水號 = '" & TextBox4.Text & "')"
  119. cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
  120. MsgBox("刪除完成") : Set_清單()
  121. End If
  122. End Sub
  123. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  124. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  125. 資料數 = DataGridView1.Rows.Count : MyModule1.進度條()
  126. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  127. SQL1 = "UPDATE 人員行政物料領用紀錄表 SET 數量 = '" & DataGridView1.Rows(i).Cells("數量").Value & "', 單位 = '" & DataGridView1.Rows(i).Cells("單位").Value & "' " &
  128. "WHERE (流水號 LIKE N'" & DataGridView1.Rows(i).Cells("流水號").Value & "')"
  129. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  130. Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  131. End Sub
  132. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  133. 清單修改.Close() : 行政物料 = True : 清單修改.ShowDialog() : ComboBox3下拉表單資料載入() : 行政物料 = False
  134. End Sub
  135. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  136. KKK3 = ComboBox1.Text
  137. KKKJJ3 = "AND (日期 LIKE N'" & KKK3 & "/" & KKK4 & "%') "
  138. End Sub
  139. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
  140. KKK4 = ComboBox2.Text
  141. KKKJJ3 = "AND (日期 LIKE N'" & KKK3 & "/" & KKK4 & "%') "
  142. End Sub
  143. End Class