Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Frm_BG_IO.vb 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. Imports System.Data.SqlClient
  2. Imports System.Reflection
  3. Public Class Frm_BG_IO
  4. Dim cmd As New SqlCommand
  5. Dim da As New SqlDataAdapter
  6. Dim dt As New DataTable
  7. Dim sql As String
  8. Dim conn As New SqlConnection
  9. Dim DR As SqlDataReader
  10. Private Sub Frm_BG_IO_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  11. Me.MdiParent = FrmMDI
  12. Dim type As Type = DGV1.GetType()
  13. Dim pi As PropertyInfo = type.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
  14. pi.SetValue(DGV1, True, Nothing)
  15. conn.ConnectionString = connstring
  16. conn.Open()
  17. cmd.Connection = conn
  18. sql = "SELECT NO,case when checked='true' then N'已核销' else N'执行中' end as checked FROM RT_BG_MAIN ORDER BY SERIAL"
  19. cmd.CommandText = sql
  20. DR = cmd.ExecuteReader
  21. While DR.Read
  22. ListBox1.Items.Add(DR("NO") & vbTab & DR("checked"))
  23. End While
  24. DR.Close()
  25. 'DGV1.DataSource = dt
  26. DGV1.RowHeadersVisible = False
  27. End Sub
  28. Private Sub ListBox1_Click(sender As Object, e As EventArgs) Handles ListBox1.Click
  29. ListBox2.Items.Clear()
  30. ListBox2.Items.Clear()
  31. ListBox4.Items.Clear()
  32. Dim p() As String
  33. p = Split(ListBox1.Items(ListBox1.SelectedIndex), vbTab)
  34. sql = "SELECT item_new from rt_bg_io where xno like '%" & p(0) & "%' and item not like N'%牛二层%' group by item_new"
  35. cmd.CommandText = sql
  36. DR = cmd.ExecuteReader
  37. While DR.Read
  38. ListBox2.Items.Add(DR("item_new"))
  39. 'ListBox2.Items.Add(S1)
  40. 'ListBox2.Items.Add(S2)
  41. End While
  42. DR.Close()
  43. sql = "SELECT ITEM_new from rt_bg_io where xno like '%" & p(0) & "%' and item like N'%牛二层%' group by item_new "
  44. cmd.CommandText = sql
  45. DR = cmd.ExecuteReader
  46. While DR.Read
  47. ListBox4.Items.Add(DR("item_new"))
  48. 'ListBox2.Items.Add(S1)
  49. 'ListBox2.Items.Add(S2)
  50. End While
  51. DR.Close()
  52. ' ListBox2.SelectedIndex = 1
  53. End Sub
  54. Private Sub ListBox2_Click(sender As Object, e As EventArgs) Handles ListBox2.Click
  55. Dim dt As New DataTable
  56. Dim p() As String
  57. p = Split(ListBox1.Items(ListBox1.SelectedIndex), vbTab)
  58. sql = "SELECT date AS 日期, CASE WHEN m_in = '0' THEN NULL ELSE cast(m_in as numeric(10,1)) END AS 入库, CASE WHEN m_out = '0' THEN NULL ELSE cast(m_out as numeric(10,1)) END AS 出库, cast(bal as numeric(10,1)) AS 结存 FROM RT_BG_IO where xno like '%" & p(0) & "%' and item_new =N'" & ListBox2.Items(ListBox2.SelectedIndex) & "' order by date"
  59. cmd.CommandText = sql
  60. da.SelectCommand = cmd
  61. da.Fill(dt)
  62. Dim myDataRow As DataRow
  63. myDataRow = dt.NewRow
  64. 'myDataRow(0) = "合计"
  65. myDataRow(1) = dt.Compute("sum(入库)", "")
  66. myDataRow(2) = dt.Compute("sum(出库)", "")
  67. If IsDBNull(myDataRow(1)) Then myDataRow(1) = 0
  68. If IsDBNull(myDataRow(2)) Then myDataRow(2) = 0
  69. myDataRow(3) = myDataRow(1) - (myDataRow(2))
  70. l_in.Text = myDataRow(1)
  71. l_out.Text = myDataRow(2)
  72. l_bal.Text = myDataRow(3)
  73. dt.Rows.InsertAt(myDataRow, dt.Rows.Count)
  74. DGV1.DataSource = dt
  75. DGV1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
  76. 'DGV3.AllowUserToAddRows = False
  77. DGV1.Rows(DGV1.Rows.Count - 2).Cells(0).Style.ForeColor = Color.Red
  78. DGV1.Rows(DGV1.Rows.Count - 2).Cells(1).Style.ForeColor = Color.Red
  79. DGV1.Rows(DGV1.Rows.Count - 2).Cells(2).Style.ForeColor = Color.Red
  80. DGV1.Rows(DGV1.Rows.Count - 2).Cells(3).Style.ForeColor = Color.Red
  81. dt = New DataTable
  82. sql = "SELECT year(date) AS 年,month(date) as 月, CASE WHEN sum(m_in) = 0 THEN NULL ELSE cast(sum(m_in) as numeric(10,1)) END AS 入库, CASE WHEN sum(m_out) = '0' THEN NULL ELSE cast(sum(m_out) as numeric(10,1)) END AS 出库 FROM RT_BG_IO where xno like '%" & p(0) & "%' and item_new =N'" & ListBox2.Items(ListBox2.SelectedIndex) & "' group by year(date),month(date) order by year(date),month(date)"
  83. cmd.CommandText = sql
  84. da.SelectCommand = cmd
  85. da.Fill(dt)
  86. myDataRow = dt.NewRow
  87. 'myDataRow(0) = "合计"
  88. myDataRow(1) = dt.Compute("sum(入库)", "")
  89. myDataRow(2) = dt.Compute("sum(出库)", "")
  90. If IsDBNull(myDataRow(1)) Then myDataRow(1) = 0
  91. If IsDBNull(myDataRow(2)) Then myDataRow(2) = 0
  92. myDataRow(3) = myDataRow(1) - (myDataRow(2))
  93. Label12.Text = myDataRow(1)
  94. Label11.Text = myDataRow(2)
  95. Label10.Text = myDataRow(3)
  96. dt.Rows.InsertAt(myDataRow, dt.Rows.Count)
  97. dgv2.DataSource = dt
  98. dgv2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
  99. 'DGV3.AllowUserToAddRows = False
  100. dgv2.Rows(dgv2.Rows.Count - 2).Cells(0).Style.ForeColor = Color.Red
  101. dgv2.Rows(dgv2.Rows.Count - 2).Cells(1).Style.ForeColor = Color.Red
  102. dgv2.Rows(dgv2.Rows.Count - 2).Cells(2).Style.ForeColor = Color.Red
  103. dgv2.Rows(dgv2.Rows.Count - 2).Cells(3).Style.ForeColor = Color.Red
  104. End Sub
  105. Private Sub ListBox1_DoubleClick(sender As Object, e As EventArgs) Handles ListBox1.DoubleClick
  106. Dim p() As String
  107. p = Split(ListBox1.Items(ListBox1.SelectedIndex), vbTab)
  108. xno = p(0)
  109. Dim my_form As New Frm_BG_sum
  110. my_form.Show(Me)
  111. End Sub
  112. Private Sub ListBox2_LostFocus(sender As Object, e As EventArgs) Handles ListBox2.LostFocus
  113. l_in.Text = ""
  114. l_out.Text = ""
  115. l_bal.Text = ""
  116. End Sub
  117. Private Sub ListBox4_Click(sender As Object, e As EventArgs) Handles ListBox4.Click
  118. Dim dt As New DataTable
  119. Dim p() As String
  120. p = Split(ListBox1.Items(ListBox1.SelectedIndex), vbTab)
  121. sql = "SELECT cast(year + '/' + month + '/' + date1 as date) AS 日期, CASE WHEN m_in = '0' THEN NULL ELSE cast(m_in as numeric(10,1)) END AS 入库, CASE WHEN m_out = '0' THEN NULL ELSE cast(m_out as numeric(10,1)) END AS 出库, cast(bal as numeric(10,1)) AS 结存 FROM RT_BG_IO where xno like '%" & p(0) & "%' and item =N'" & ListBox4.Items(ListBox4.SelectedIndex) & "' order by 日期"
  122. sql = "SELECT (year + '/' + month + '/' + date1 ) AS 日期, CASE WHEN m_in = '0' THEN NULL ELSE cast(m_in as numeric(10,2)) END AS 入库, CASE WHEN m_out = '0' THEN NULL ELSE cast(m_out as numeric(10,2)) END AS 出库, cast(bal as numeric(10,2)) AS 结存 FROM RT_BG_IO where xno like '%" & p(0) & "%' and item_new =N'" & ListBox4.Items(ListBox4.SelectedIndex) & "'"
  123. cmd.CommandText = sql
  124. da.SelectCommand = cmd
  125. da.Fill(dt)
  126. Dim myDataRow As DataRow
  127. myDataRow = dt.NewRow
  128. 'myDataRow(0) = "合计"
  129. myDataRow(1) = dt.Compute("sum(入库)", "")
  130. myDataRow(2) = dt.Compute("sum(出库)", "")
  131. If IsDBNull(myDataRow(1)) Then myDataRow(1) = 0
  132. If IsDBNull(myDataRow(2)) Then myDataRow(2) = 0
  133. myDataRow(3) = myDataRow(1) - (myDataRow(2))
  134. l_in.Text = myDataRow(1)
  135. l_out.Text = myDataRow(2)
  136. l_bal.Text = myDataRow(3)
  137. dt.Rows.InsertAt(myDataRow, dt.Rows.Count)
  138. DGV1.DataSource = dt
  139. DGV1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
  140. 'DGV3.AllowUserToAddRows = False
  141. DGV1.Rows(DGV1.Rows.Count - 2).Cells(0).Style.ForeColor = Color.Red
  142. DGV1.Rows(DGV1.Rows.Count - 2).Cells(1).Style.ForeColor = Color.Red
  143. DGV1.Rows(DGV1.Rows.Count - 2).Cells(2).Style.ForeColor = Color.Red
  144. DGV1.Rows(DGV1.Rows.Count - 2).Cells(3).Style.ForeColor = Color.Red
  145. dt = New DataTable
  146. sql = "SELECT year(date) AS 年,month(date) as 月, CASE WHEN sum(m_in) = 0 THEN NULL ELSE cast(sum(m_in) as numeric(10,1)) END AS 入库, CASE WHEN sum(m_out) = '0' THEN NULL ELSE cast(sum(m_out) as numeric(10,1)) END AS 出库 FROM RT_BG_IO where xno like '%" & p(0) & "%' and item_new =N'" & ListBox4.Items(ListBox4.SelectedIndex) & "' group by year(date),month(date) order by year(date),month(date)"
  147. cmd.CommandText = sql
  148. da.SelectCommand = cmd
  149. da.Fill(dt)
  150. myDataRow = dt.NewRow
  151. 'myDataRow(0) = "合计"
  152. myDataRow(1) = dt.Compute("sum(入库)", "")
  153. myDataRow(2) = dt.Compute("sum(出库)", "")
  154. If IsDBNull(myDataRow(1)) Then myDataRow(1) = 0
  155. If IsDBNull(myDataRow(2)) Then myDataRow(2) = 0
  156. myDataRow(3) = myDataRow(1) - (myDataRow(2))
  157. Label12.Text = myDataRow(1)
  158. Label11.Text = myDataRow(2)
  159. Label10.Text = myDataRow(3)
  160. dt.Rows.InsertAt(myDataRow, dt.Rows.Count)
  161. dgv2.DataSource = dt
  162. dgv2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
  163. 'DGV3.AllowUserToAddRows = False
  164. dgv2.Rows(dgv2.Rows.Count - 2).Cells(0).Style.ForeColor = Color.Red
  165. dgv2.Rows(dgv2.Rows.Count - 2).Cells(1).Style.ForeColor = Color.Red
  166. dgv2.Rows(dgv2.Rows.Count - 2).Cells(2).Style.ForeColor = Color.Red
  167. dgv2.Rows(dgv2.Rows.Count - 2).Cells(3).Style.ForeColor = Color.Red
  168. End Sub
  169. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click '----查询
  170. Dim dt As New DataTable
  171. Dim p() As String
  172. p = Split(ListBox1.Items(ListBox1.SelectedIndex), vbTab)
  173. sql = "SELECT date AS 日期, CASE WHEN m_in = '0' THEN NULL ELSE cast(m_in as numeric(10,1)) END AS 入库, CASE WHEN m_out = '0' THEN NULL ELSE cast(m_out as numeric(10,1)) END AS 出库, cast(bal as numeric(10,1)) AS 结存 FROM RT_BG_IO where date between '" & dtp1.Value & "' and '" & dtp2.Value & "' and xno like '%" & p(0) & "%' and item_new =N'" & ListBox2.Items(ListBox2.SelectedIndex) & "' order by date"
  174. cmd.CommandText = sql
  175. da.SelectCommand = cmd
  176. da.Fill(dt)
  177. Dim myDataRow As DataRow
  178. myDataRow = dt.NewRow
  179. 'myDataRow(0) = "合计"
  180. myDataRow(1) = dt.Compute("sum(入库)", "")
  181. myDataRow(2) = dt.Compute("sum(出库)", "")
  182. If IsDBNull(myDataRow(1)) Then myDataRow(1) = 0
  183. If IsDBNull(myDataRow(2)) Then myDataRow(2) = 0
  184. myDataRow(3) = myDataRow(1) - (myDataRow(2))
  185. Label7.Text = myDataRow(1)
  186. Label6.Text = myDataRow(2)
  187. Label5.Text = myDataRow(3)
  188. dt.Rows.InsertAt(myDataRow, dt.Rows.Count)
  189. dgv_query.DataSource = dt
  190. dgv_query.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
  191. 'DGV3.AllowUserToAddRows = False
  192. dgv_query.Rows(dgv_query.Rows.Count - 2).Cells(0).Style.ForeColor = Color.Red
  193. dgv_query.Rows(dgv_query.Rows.Count - 2).Cells(1).Style.ForeColor = Color.Red
  194. dgv_query.Rows(dgv_query.Rows.Count - 2).Cells(2).Style.ForeColor = Color.Red
  195. dgv_query.Rows(dgv_query.Rows.Count - 2).Cells(3).Style.ForeColor = Color.Red
  196. End Sub
  197. End Class