설명 없음
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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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
  8. Dim dr As SqlDataReader
  9. Private Sub Set_清單1()
  10. DataGridView1.DataSource = Nothing : ds.Clear()
  11. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  12. DataGridView1.ColumnHeadersHeight = 25
  13. DataGridView1.AllowUserToAddRows = False
  14. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  15. SQL1 = "SELECT 項一, 項二, 項三,項一 AS [項1], 項二 AS [項2], 項三 AS [項3], 內容, 狀態
  16. FROM 系統開發點檢表基本資料
  17. ORDER BY 項一, 項二, 項三"
  18. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
  19. End Sub
  20. Private Sub Set_grid()
  21. DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).Visible = False
  22. DataGridView1.Columns(3).Width = 60 : DataGridView1.Columns(4).Width = 60 : DataGridView1.Columns(5).Width = 60 : DataGridView1.Columns(6).Width = 700
  23. DataGridView1.Columns(7).Width = 60
  24. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  25. If Strings.Right(DataGridView1.Rows(i).Cells("項2").Value, 2) = "00" Then
  26. DataGridView1.Rows(i).Cells("項2").Value = ""
  27. End If
  28. If Strings.Right(DataGridView1.Rows(i).Cells("項3").Value, 2) = "00" Then
  29. DataGridView1.Rows(i).Cells("項3").Value = ""
  30. End If
  31. Next
  32. End Sub
  33. Private Sub Set_清單2()
  34. DataGridView2.DataSource = Nothing : ds1.Clear()
  35. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  36. DataGridView2.ColumnHeadersHeight = 25
  37. DataGridView2.AllowUserToAddRows = False
  38. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  39. SQL1 = "SELECT 項一, 項二, 項三, 內容, 狀態 FROM 系統開發點檢表基本資料 WHERE 項一 LIKE '" & TextBox1.Text & "'
  40. ORDER BY 項一, 項二, 項三"
  41. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1()
  42. End Sub
  43. Private Sub Set_grid1()
  44. DataGridView2.Columns(0).Width = 60 : DataGridView2.Columns(1).Width = 60 : DataGridView2.Columns(2).Width = 60 : DataGridView2.Columns(3).Width = 650
  45. DataGridView2.Columns(4).Width = 60
  46. End Sub
  47. Private Sub ComboBox1下拉表單資料載入()
  48. conn.Close()
  49. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  50. SQL1 = "SELECT 內容 FROM 系統開發點檢表基本資料 WHERE (RIGHT(項二, 2) LIKE '00')"
  51. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  52. ComboBox1.Items.Clear()
  53. While (dr.Read()) : ComboBox1.Items.Add(dr("內容")) : End While
  54. conn.Close()
  55. End Sub
  56. Private Sub 系統開發點檢控制表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  57. Me.MdiParent = GCM_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  58. Set_清單1() : ComboBox1下拉表單資料載入()
  59. End Sub
  60. Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
  61. timeNow = 0
  62. GCM_ERP_SYS.Timer1.Enabled = False
  63. GCM_ERP_SYS.Timer1.Enabled = True
  64. End Sub
  65. Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
  66. timeNow = 0
  67. GCM_ERP_SYS.Timer1.Enabled = False
  68. GCM_ERP_SYS.Timer1.Enabled = True
  69. End Sub
  70. Private Sub DataGridView2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  71. If e.RowIndex = -1 Then : Else
  72. TextBox2.Text = DataGridView2.Rows(e.RowIndex).Cells("項二").Value : TextBox3.Text = DataGridView2.Rows(e.RowIndex).Cells("項三").Value
  73. TextBox4.Text = DataGridView2.Rows(e.RowIndex).Cells("內容").Value : ComboBox2.Text = DataGridView2.Rows(e.RowIndex).Cells("狀態").Value
  74. End If
  75. End Sub
  76. Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
  77. Dim linePen As New Pen(Color.Blue, 2)
  78. If e.RowIndex = DataGridView1.Rows.Count - 1 Then
  79. Exit Sub
  80. Else
  81. If DataGridView1(0, e.RowIndex).Value.ToString <> DataGridView1(0, e.RowIndex + 1).Value.ToString Then
  82. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  83. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  84. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  85. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  86. Exit Sub
  87. End If
  88. End If
  89. End Sub
  90. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  91. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  92. SQL1 = "SELECT 項一 FROM 系統開發點檢表基本資料 WHERE 內容 LIKE N'" & ComboBox1.Text & "'"
  93. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  94. If dr.Read() Then : TextBox1.Text = dr("項一") : End If
  95. conn.Close()
  96. Set_清單2()
  97. End Sub
  98. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  99. If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or ComboBox2.Text = "" Then
  100. MsgBox("資料不齊全,請重新確認。")
  101. Else
  102. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  103. SQL1 = "SELECT 項一 FROM 系統開發點檢表基本資料 WHERE 項二 LIKE N'" & TextBox2.Text & "' AND 項三 LIKE N'" & TextBox3.Text & "'"
  104. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  105. If dr.Read() Then : conn.Close()
  106. MsgBox("項二資料重複,請重新確認。")
  107. Else
  108. conn.Close()
  109. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  110. SQL1 = "SELECT 項一 FROM 系統開發點檢表基本資料 WHERE 項三 LIKE N'" & TextBox3.Text & "'"
  111. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  112. If dr.Read() Then : conn.Close()
  113. MsgBox("項三資料重複,請重新確認。")
  114. Else
  115. conn.Close()
  116. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  117. SQL1 = "SELECT 項一 FROM 系統開發點檢表基本資料 WHERE 內容 LIKE N'" & TextBox4.Text & "'"
  118. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  119. If dr.Read() Then : conn.Close()
  120. MsgBox("內容資料重複,請重新確認。")
  121. Else
  122. conn.Close()
  123. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  124. SQL1 = "INSERT INTO 系統開發點檢表基本資料 (項一, 項二, 項三, 內容, 狀態) VALUES (N'" & TextBox1.Text & "',N'" & TextBox2.Text & "',N'" & TextBox3.Text &
  125. "', N'" & TextBox4.Text & "', '" & ComboBox2.Text & "')"
  126. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  127. MsgBox("新增完成") : Set_清單1() : Set_清單2()
  128. End If
  129. End If
  130. End If
  131. End If
  132. End Sub
  133. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  134. If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or ComboBox2.Text = "" Then
  135. MsgBox("資料不齊全,請重新確認。")
  136. Else
  137. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  138. SQL1 = "SELECT 項一 FROM 系統開發點檢表基本資料 WHERE 內容 LIKE N'" & TextBox4.Text & "'"
  139. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  140. If dr.Read() Then : conn.Close()
  141. MsgBox("內容資料重複,請重新確認。")
  142. Else
  143. conn.Close()
  144. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  145. SQL1 = "UPDATE 系統開發點檢表基本資料 SET 內容 = '" & TextBox4.Text & "', 狀態 = '" & ComboBox2.Text & "'
  146. WHERE (項一 LIKE '" & TextBox1.Text & "' AND 項二 LIKE '" & TextBox2.Text & "' AND 項三 LIKE '" & TextBox3.Text & "')"
  147. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() : conn.Close()
  148. MsgBox("新增完成") : Set_清單1() : Set_清單2()
  149. End If
  150. End If
  151. End Sub
  152. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  153. SQL1 = "DELETE FROM 系統開發點檢表基本資料 WHERE (項一 LIKE '" & TextBox1.Text & "' AND 項二 LIKE '" & TextBox2.Text & "' AND 項三 LIKE '" & TextBox3.Text & "')"
  154. cmd.CommandText = SQL1 : cmd.Connection = conn
  155. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  156. Dim aa As MsgBoxResult
  157. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  158. If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If
  159. conn.Close() : conn.Close() : Set_清單1() : Set_清單2()
  160. End Sub
  161. End Class