Sin descripción
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.

Frm_Measure_PU.vb 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. Imports System.Data.SqlClient
  2. Imports System.Windows.Forms.VisualStyles.VisualStyleElement
  3. Public Class Frm_Measure_PU
  4. Dim cmd As New SqlCommand
  5. Dim da As New SqlDataAdapter
  6. Dim dt As New DataTable
  7. Dim sql As String
  8. Private Sub Frm_Measure_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  9. Dim conn As New SqlConnection
  10. 'connstring = "Data Source=127.0.0.1;Persist Security Info=True;User ID=sa;Password=Lafayette11;Initial Catalog=maindb_hy2014"
  11. conn.ConnectionString = connstring
  12. conn.Open()
  13. dgv2.RowHeadersWidth = 15
  14. dgv2.ColumnHeadersHeight = 20
  15. dgv2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  16. DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  17. DataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  18. DataGridView3.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  19. DataGridView4.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  20. DataGridView5.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  21. DataGridView6.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  22. DataGridView7.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  23. DataGridView8.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  24. cmd.Connection = conn
  25. sql = "select top(1) date1 from rt_pu_measure2_temp order by date1 desc"
  26. cmd.CommandText = sql
  27. Label22.Text = cmd.ExecuteScalar
  28. End Sub
  29. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  30. sql = "SELECT count(*) as 笔数,comment1 as 分类,cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') group by comment1" '--全部
  31. dt = New DataTable
  32. cmd.CommandText = sql
  33. da.SelectCommand = cmd
  34. da.Fill(dt)
  35. ' dt.Columns(0).ColumnName = "贴膜打尺"
  36. dgv2.DataSource = dt
  37. dgv2.Columns(0).Width = 65
  38. dgv2.Columns(1).Width = 110
  39. dgv2.Columns(2).Width = 80
  40. sql = "SELECT cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') "
  41. dt = New DataTable
  42. cmd.CommandText = sql
  43. Label3.Text = cmd.ExecuteScalar.ToString
  44. sql = "SELECT count(*) as 笔数,comment1 as 分类,cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and not( comment1 like N'%仓存%' or comment1 like N'%仓库%' or comment1 like N'%库存%' or comment1 like N'%取%' or comment1 like N'%退返%' or comment1 like N'%冲孔%' or comment1 like N'%返车间%') group by comment1" '-----------------------------------------------正常
  45. dt = New DataTable
  46. cmd.CommandText = sql
  47. da.SelectCommand = cmd
  48. da.Fill(dt)
  49. DataGridView1.DataSource = dt
  50. DataGridView1.Columns(0).Width = 65
  51. DataGridView1.Columns(1).Width = 110
  52. DataGridView1.Columns(2).Width = 80
  53. sql = "SELECT cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and not( comment1 like N'%仓存%' or comment1 like N'%仓库%' or comment1 like N'%库存%' or comment1 like N'%取%' or comment1 like N'%退返%' or comment1 like N'%冲孔%' or comment1 like N'%返车间%')"
  54. dt = New DataTable
  55. cmd.CommandText = sql
  56. Label15.Text = cmd.ExecuteScalar.ToString
  57. sql = "SELECT count(*) as 笔数,comment1 as 分类,cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%仓存%' group by comment1" '----仓存
  58. dt = New DataTable
  59. cmd.CommandText = sql
  60. da.SelectCommand = cmd
  61. da.Fill(dt)
  62. DataGridView2.DataSource = dt
  63. DataGridView2.Columns(0).Width = 65
  64. DataGridView2.Columns(1).Width = 110
  65. DataGridView2.Columns(2).Width = 80
  66. sql = "SELECT cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%仓存%'"
  67. dt = New DataTable
  68. cmd.CommandText = sql
  69. Label5.Text = cmd.ExecuteScalar.ToString
  70. sql = "SELECT count(*) as 笔数,comment1 as 分类,cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%仓库%' group by comment1" '-----仓库
  71. dt = New DataTable
  72. cmd.CommandText = sql
  73. da.SelectCommand = cmd
  74. da.Fill(dt)
  75. DataGridView3.DataSource = dt
  76. DataGridView3.Columns(0).Width = 65
  77. DataGridView3.Columns(1).Width = 110
  78. DataGridView3.Columns(2).Width = 80
  79. sql = "SELECT cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%仓库%' "
  80. dt = New DataTable
  81. cmd.CommandText = sql
  82. Label7.Text = cmd.ExecuteScalar.ToString
  83. sql = "SELECT count(*) as 笔数,comment1 as 分类,cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%库存%' group by comment1" '------库存
  84. dt = New DataTable
  85. cmd.CommandText = sql
  86. da.SelectCommand = cmd
  87. da.Fill(dt)
  88. DataGridView4.DataSource = dt
  89. DataGridView4.Columns(0).Width = 65
  90. DataGridView4.Columns(1).Width = 110
  91. DataGridView4.Columns(2).Width = 80
  92. sql = "SELECT cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%库存%'"
  93. dt = New DataTable
  94. cmd.CommandText = sql
  95. Label9.Text = cmd.ExecuteScalar.ToString
  96. sql = "SELECT count(*) as 笔数,comment1,cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%取%' group by comment1" '----待打包
  97. dt = New DataTable
  98. cmd.CommandText = sql
  99. da.SelectCommand = cmd
  100. da.Fill(dt)
  101. DataGridView5.DataSource = dt
  102. DataGridView5.Columns(0).Width = 65
  103. DataGridView5.Columns(1).Width = 110
  104. DataGridView5.Columns(2).Width = 80
  105. sql = "SELECT cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%取%'"
  106. dt = New DataTable
  107. cmd.CommandText = sql
  108. Label11.Text = cmd.ExecuteScalar.ToString
  109. sql = "SELECT count(*) as 笔数,comment1,cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%退返%' group by comment1" '-----退返
  110. dt = New DataTable
  111. cmd.CommandText = sql
  112. da.SelectCommand = cmd
  113. da.Fill(dt)
  114. DataGridView6.DataSource = dt
  115. DataGridView6.Columns(0).Width = 65
  116. DataGridView6.Columns(1).Width = 110
  117. DataGridView6.Columns(2).Width = 80
  118. sql = "SELECT cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%退返%'"
  119. dt = New DataTable
  120. cmd.CommandText = sql
  121. Label13.Text = cmd.ExecuteScalar.ToString
  122. sql = "SELECT count(*) as 笔数, comment1 as 分类, cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%冲孔%' group by comment1" '-----冲孔
  123. dt = New DataTable
  124. cmd.CommandText = sql
  125. da.SelectCommand = cmd
  126. da.Fill(dt)
  127. DataGridView7.DataSource = dt
  128. DataGridView7.Columns(0).Width = 65
  129. DataGridView7.Columns(1).Width = 110
  130. DataGridView7.Columns(2).Width = 80
  131. sql = "SELECT cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%冲孔%'"
  132. dt = New DataTable
  133. cmd.CommandText = sql
  134. Label17.Text = cmd.ExecuteScalar.ToString
  135. sql = "SELECT count(*) as 笔数, comment1 as 分类, cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%返车间%' group by comment1" '-----返车间
  136. dt = New DataTable
  137. cmd.CommandText = sql
  138. da.SelectCommand = cmd
  139. da.Fill(dt)
  140. DataGridView8.DataSource = dt
  141. DataGridView8.Columns(0).Width = 65
  142. DataGridView8.Columns(1).Width = 110
  143. DataGridView8.Columns(2).Width = 80
  144. sql = "SELECT cast(sum(sf) as numeric(10,1)) as sf FROM Rt_pu_measure2_TEMP WHERE (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and comment1 like N'%返车间%'"
  145. dt = New DataTable
  146. cmd.CommandText = sql
  147. Label19.Text = cmd.ExecuteScalar.ToString
  148. With dgv2.Columns(0).DefaultCellStyle
  149. .Alignment = DataGridViewContentAlignment.MiddleCenter
  150. End With
  151. With dgv2.Columns(2).DefaultCellStyle
  152. .Format = "n1"
  153. .Alignment = DataGridViewContentAlignment.MiddleRight
  154. End With
  155. Label23.Text = Val(Label15.Text) + Val(Label5.Text) + Val(Label17.Text) + Val(Label7.Text) + Val(Label9.Text) + Val(Label19.Text) + Val(Label11.Text) + Val(Label13.Text)
  156. End Sub
  157. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '--516打尺入库
  158. Dim aa As String
  159. Dim bb As String
  160. Dim my_card As String = ""
  161. Dim my_date As Date
  162. aa = TextBox8.Text
  163. bb = TextBox8.Text
  164. If aa = "" Then
  165. MsgBox("请输入起始单号")
  166. Exit Sub
  167. End If
  168. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  169. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  170. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  171. Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
  172. Dim file_name As String = ""
  173. Dim file_name1 As String = ""
  174. Dim my_weight As Double = 0
  175. Dim a As Integer = 0
  176. Dim my_count As Integer = 0
  177. Dim my_x As Integer = 0
  178. xlApp = CreateObject("Excel.Application")
  179. xlApp.Visible = True
  180. xlApp.DisplayAlerts = False
  181. xlBook = xlApp.Workbooks.Open("D:\K3\k3表格模板\PU打尺入库.xls",, True)
  182. xlBook.Activate()
  183. Dim dt2 As New DataTable
  184. For i = 1 To xlApp.Worksheets.Count
  185. If xlApp.Workbooks(1).Worksheets(i).name = "Page1" Then
  186. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  187. xlSheet.Activate()
  188. Exit For
  189. End If
  190. Next
  191. Dim my_no As String = "CPRK0"
  192. Dim yy As Integer = 1
  193. Dim x As Integer = 0
  194. Dim dt_inprocess As New DataTable
  195. Dim dt_out As New DataTable
  196. sql = "select date1 from rt_pu_measure2_temp where (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') group by date1 order by date1"
  197. cmd.CommandText = sql
  198. da.SelectCommand = cmd
  199. da.Fill(dt_out)
  200. For x = 0 To dt_out.Rows.Count - 1 '-----------loop
  201. xlSheet.Cells(x + 2, 1) = dt_out.Rows(x).Item("date1")
  202. xlSheet.Cells(x + 2, 2) = dt_out.Rows(x).Item("date1")
  203. xlSheet.Cells(x + 2, 3) = "'曾添梅"
  204. xlSheet.Cells(x + 2, 4) = "'" & my_no & bb
  205. xlSheet.Cells(x + 2, 5) = "'zhang"
  206. xlSheet.Cells(x + 2, 6) = "'1"
  207. xlSheet.Cells(x + 2, 7) = "'2"
  208. xlSheet.Cells(x + 2, 8) = "'165701"
  209. xlSheet.Cells(x + 2, 9) = "'655P-R"
  210. xlSheet.Cells(x + 2, 10) = "'修剪、成检、量尺、包装-R"
  211. xlSheet.Cells(x + 2, 11) = "'120"
  212. xlSheet.Cells(x + 2, 12) = "'吴小男"
  213. xlSheet.Cells(x + 2, 13) = "'120"
  214. xlSheet.Cells(x + 2, 14) = "'吴小男"
  215. xlSheet.Cells(x + 2, 15) = "'85"
  216. For i = 1 To xlApp.Worksheets.Count
  217. If xlApp.Workbooks(1).Worksheets(i).name = "Page2" Then
  218. xlSheet2 = xlApp.Workbooks(1).Worksheets(i)
  219. xlSheet2.Activate()
  220. Exit For
  221. End If
  222. Next
  223. Dim serial As Integer = 1
  224. For xx As Integer = 1 To 5
  225. Dim sql1 As String
  226. Dim my_type As String
  227. Select Case xx
  228. Case 1
  229. sql = "SELECT date1 ,cust,color,thick,pattern,comment1,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec, cast(sf as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 = '" & dt_out.Rows(x).Item("date1") & "') and not( comment1 like N'%仓存%' or comment1 like N'%仓库%' or comment1 like N'%库存%' or comment1 like N'%取%' or comment1 like N'%退返%' or comment1 like N'%冲孔%' or comment1 like N'%返车间%') order by date1 "
  230. my_type = "--正常--"
  231. Case 2
  232. sql = "SELECT date1 ,cust,color,thick,pattern,comment1,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec,cast(sf as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 = '" & dt_out.Rows(x).Item("date1") & "') and (comment1 not like N'%冲孔%') and (comment1 like N'%仓存%' or comment1 like N'%仓库%') order by date1" '----仓存仓库
  233. my_type = "--仓库--"
  234. Case 3
  235. sql = "SELECT date1, cust,color,thick,case when (comment1 like N'%4-8%' or comment1 like N'%7%') then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when (comment1 like N'%12%') then N'516 贴膜 12+' end as spec, CAST((sf) AS numeric(10, 1)) AS 尺数,comment1
  236. FROM Rt_pu_measure2_TEMP where (date1 = '" & dt_out.Rows(x).Item("date1") & "') and (comment1 not like N'%冲孔%') and ((comment1 like N'%取%') or (comment1 like N'%库存%')) ORDER BY date1"
  237. my_type = "--待打包、库存--"
  238. Case 4
  239. sql = "SELECT date1 ,cust,color,thick,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec, CAST((sf) AS numeric(10, 1)) AS 尺数,comment1
  240. FROM Rt_pu_measure2_TEMP where (date1 = '" & dt_out.Rows(x).Item("date1") & "') and (comment1 like N'%退返%') order by date1 " '---退返
  241. my_type = "--退返--"
  242. Case 5
  243. sql = "SELECT date1 , cust,color,thick,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec, CAST((sf) AS numeric(10, 1)) AS 尺数,comment1
  244. FROM Rt_pu_measure2_TEMP where (date1 = '" & dt_out.Rows(x).Item("date1") & "') and ((comment1 like N'%冲孔%') or (comment1 like N'%返车间%')) ORDER BY date1 "
  245. my_type = "--冲孔、返车间--"
  246. End Select
  247. dt2 = New DataTable
  248. cmd.CommandText = sql
  249. da.SelectCommand = cmd
  250. da.Fill(dt2)
  251. For y = 0 To dt2.Rows.Count - 1
  252. xlSheet2.Cells(yy + 1 + y, 2) = "'" & serial '行号
  253. xlSheet2.Cells(yy + 1 + y, 3) = "'" & my_no & bb
  254. 'If dt2.Rows(y).Item("name") Like "*贴膜*" Then
  255. xlSheet2.Cells(yy + 1 + y, 5) = "516.P.PU"
  256. xlSheet2.Cells(yy + 1 + y, 6) = "贴膜皮"
  257. 'Else
  258. ' xlSheet2.Cells(yy + 1 + y, 5) = "516.F.FM"
  259. ' xlSheet2.Cells(yy + 1 + y, 6) = "二层皮"
  260. 'End If
  261. xlSheet2.Cells(yy + 1 + y, 14) = dt2.Rows(y).Item("尺数")
  262. ' xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price")
  263. 'xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("sf") * dt2.Rows(y).Item("price")
  264. xlSheet2.Cells(yy + 1 + y, 17) = dt2.Rows(y).Item("spec") '批号
  265. xlSheet2.Cells(yy + 1 + y, 18) = "打尺入库" & my_type
  266. xlSheet2.Cells(yy + 1 + y, 25) = "'516-R"
  267. xlSheet2.Cells(yy + 1 + y, 26) = "待售成品仓/赤湖"
  268. xlSheet2.Cells(yy + 1 + y, 38) = "'" & dt2.Rows(y).Item("cust")
  269. xlSheet2.Cells(yy + 1 + y, 39) = "'" & dt2.Rows(y).Item("color")
  270. xlSheet2.Cells(yy + 1 + y, 40) = "'" & dt2.Rows(y).Item("date1")
  271. xlSheet2.Cells(yy + 1 + y, 43) = dt2.Rows(y).Item("thick")
  272. xlSheet2.Cells(yy + 1 + y, 47) = dt2.Rows(y).Item("comment1")
  273. serial = serial + 1
  274. Next
  275. yy = yy + dt2.Rows.Count
  276. aa = aa + 1
  277. my_x = my_x + 1
  278. ' my_card = dt_inprocess.Rows(x).Item("card")
  279. ' my_date = dt_inprocess.Rows(x).Item("date")
  280. Next
  281. xlSheet2.Range("A2:A" & xlSheet2.UsedRange.Rows.Count).FillDown()
  282. 'xlSheet2.Range("B2:B" & x + 1).FillDown()
  283. xlSheet2.Range("D2:D" & xlSheet2.UsedRange.Rows.Count).FillDown()
  284. xlSheet2.Range("J2:J" & xlSheet2.UsedRange.Rows.Count).FillDown()
  285. xlSheet2.Range("L2:L" & xlSheet2.UsedRange.Rows.Count).FillDown()
  286. xlSheet2.Range("M2:M" & xlSheet2.UsedRange.Rows.Count).FillDown()
  287. 'xlSheet2.Range("O2:O" & x + 1).FillDown()
  288. 'xlSheet2.Range("P2:P" & x + 1).FillDown()
  289. bb = bb + 1
  290. Next
  291. MsgBox("")
  292. End Sub
  293. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click '-----313出库
  294. Dim aa As String
  295. Dim bb As String
  296. Dim my_card As String = ""
  297. Dim my_date As Date
  298. aa = TextBox1.Text
  299. bb = TextBox1.Text
  300. If aa = "" Then
  301. MsgBox("请输入起始单号")
  302. Exit Sub
  303. End If
  304. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  305. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  306. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  307. Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
  308. Dim file_name As String = ""
  309. Dim file_name1 As String = ""
  310. Dim my_weight As Double = 0
  311. Dim a As Integer = 0
  312. Dim my_count As Integer = 0
  313. Dim my_x As Integer = 0
  314. xlApp = CreateObject("Excel.Application")
  315. xlApp.Visible = True
  316. xlApp.DisplayAlerts = False
  317. xlBook = xlApp.Workbooks.Open("D:\K3\k3表格模板\PU打尺出库.xls",, True)
  318. xlBook.Activate()
  319. Dim dt2 As New DataTable
  320. For i = 1 To xlApp.Worksheets.Count
  321. If xlApp.Workbooks(1).Worksheets(i).name = "Page1" Then
  322. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  323. xlSheet.Activate()
  324. Exit For
  325. End If
  326. Next
  327. Dim my_no As String = "SCLL0"
  328. Dim yy As Integer = 1
  329. Dim x As Integer = 0
  330. Dim dt_inprocess As New DataTable
  331. Dim dt_out As New DataTable
  332. sql = "select date1 from rt_pu_measure2_temp where (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') group by date1 order by date1"
  333. sql = "SELECT date FROM Rt_pu_measure1
  334. WHERE (date BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') and card not like '%返工皮%' group by date"
  335. cmd.CommandText = sql
  336. da.SelectCommand = cmd
  337. da.Fill(dt_out)
  338. For x = 0 To dt_out.Rows.Count - 1 '-----------loop
  339. xlSheet.Cells(x + 2, 1) = dt_out.Rows(x).Item("date")
  340. xlSheet.Cells(x + 2, 2) = dt_out.Rows(x).Item("date")
  341. xlSheet.Cells(x + 2, 3) = "'曾添梅"
  342. xlSheet.Cells(x + 2, 4) = "'" & my_no & bb
  343. xlSheet.Cells(x + 2, 5) = "'zhang"
  344. xlSheet.Cells(x + 2, 6) = "'1"
  345. xlSheet.Cells(x + 2, 7) = "'24"
  346. xlSheet.Cells(x + 2, 8) = "'165701"
  347. xlSheet.Cells(x + 2, 9) = "'651P-R"
  348. xlSheet.Cells(x + 2, 10) = "'中检、量尺-R"
  349. xlSheet.Cells(x + 2, 12) = "'103"
  350. xlSheet.Cells(x + 2, 13) = "'曾添梅"
  351. xlSheet.Cells(x + 2, 14) = "'103"
  352. xlSheet.Cells(x + 2, 15) = "'曾添梅"
  353. For i = 1 To xlApp.Worksheets.Count
  354. If xlApp.Workbooks(1).Worksheets(i).name = "Page2" Then
  355. xlSheet2 = xlApp.Workbooks(1).Worksheets(i)
  356. xlSheet2.Activate()
  357. Exit For
  358. End If
  359. Next
  360. Dim serial As Integer = 1
  361. sql = "SELECT date, card, card1, source, cust, spec, color, weight1/2 as weight, sf, cast(sf1 as numeric(10,2)) as rate, tech
  362. FROM Rt_pu_measure1 WHERE (date = '" & String.Format("{0:d}", dtp_begin.Value) & "') and card not like '%返工皮%' order by card1"
  363. sql = "SELECT date, card, card1, source, cust, spec, color, weight1 / 2 AS weight, sf, CAST(sf1 AS numeric(10, 2)) AS rate, tech,
  364. CASE WHEN source LIKE N'%无铬鞣%' THEN N'无铬鞣 二层' WHEN source LIKE N'%阿根廷%' THEN N'阿根廷 二层' WHEN source LIKE N'%澳%' THEN N'澳大利亚 二层'
  365. WHEN (source LIKE N'%巴西%' OR
  366. source LIKE N'%bx%' OR
  367. source LIKE N'%南美%')
  368. THEN N'巴西 二层' WHEN source LIKE N'%智利%' THEN N'智利 二层' WHEN source LIKE N'%德国%' THEN N'德国 二层' WHEN source LIKE N'%西班牙%' THEN N'西班牙 二层'
  369. WHEN source LIKE N'%欧洲%' THEN N'欧洲 二层' WHEN source LIKE N'%法国%' THEN N'法国 二层' WHEN source LIKE N'%爱尔兰%' THEN N'爱尔兰 二层' WHEN
  370. source LIKE N'%APP%' THEN N'美国 二层' WHEN source LIKE N'%日本%' THEN N'日本 二层' WHEN source LIKE N'%美国%' THEN N'美国 二层' WHEN source LIKE
  371. N'%新西兰%' THEN N'新西兰 二层' WHEN source LIKE N'%小皮%' THEN N'小皮 二层' WHEN source LIKE N'%英国%' THEN N'英国 二层' WHEN source LIKE N'%墨西哥%'
  372. THEN N'墨西哥 二层' WHEN source LIKE N'%乌拉圭%' THEN N'乌拉圭 二层' WHEN source LIKE N'%南非%' THEN N'南非 二层' WHEN source LIKE N'%孟加拉%' THEN
  373. N'孟加拉 二层' WHEN source LIKE N'%泰国%' THEN N'泰国 二层' ELSE N'杂皮 二层' END AS 皮源
  374. FROM Rt_pu_measure1
  375. WHERE (date = '" & dt_out.Rows(x).Item("date") & "') AND (card NOT LIKE '%返工皮%')"
  376. dt2 = New DataTable
  377. cmd.CommandText = sql
  378. da.SelectCommand = cmd
  379. da.Fill(dt2)
  380. For y = 0 To dt2.Rows.Count - 1
  381. xlSheet2.Cells(yy + 1 + y, 2) = "'" & serial '行号
  382. xlSheet2.Cells(yy + 1 + y, 3) = "'" & my_no & bb
  383. xlSheet2.Cells(yy + 1 + y, 4) = "'24"
  384. 'If dt2.Rows(y).Item("name") Like "*贴膜*" Then
  385. xlSheet2.Cells(yy + 1 + y, 6) = "516.P.PU"
  386. xlSheet2.Cells(yy + 1 + y, 7) = "贴膜皮"
  387. xlSheet2.Cells(yy + 1 + y, 24) = dt2.Rows(y).Item("weight")
  388. ' xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price")
  389. 'xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("sf") * dt2.Rows(y).Item("price")
  390. xlSheet2.Cells(yy + 1 + y, 23) = "313 " & dt2.Rows(y).Item("皮源") '批号
  391. xlSheet2.Cells(yy + 1 + y, 28) = "中检仓" & "/" & dt2.Rows(y).Item("cust") & "/" & dt2.Rows(y).Item("color") '备注
  392. xlSheet2.Cells(yy + 1 + y, 35) = "'313"
  393. xlSheet2.Cells(yy + 1 + y, 36) = "涂饰在制品"
  394. xlSheet2.Cells(yy + 1 + y, 52) = "'" & dt2.Rows(y).Item("cust")
  395. xlSheet2.Cells(yy + 1 + y, 54) = "'" & dt2.Rows(y).Item("rate")
  396. xlSheet2.Cells(yy + 1 + y, 55) = "'" & dt2.Rows(y).Item("tech")
  397. xlSheet2.Cells(yy + 1 + y, 56) = "'" & dt2.Rows(y).Item("color")
  398. xlSheet2.Cells(yy + 1 + y, 57) = "'" & dt2.Rows(y).Item("spec")
  399. xlSheet2.Cells(yy + 1 + y, 58) = dt2.Rows(y).Item("card")
  400. ' xlSheet2.Cells(yy + 1 + y, 47) = dt2.Rows(y).Item("comment1")
  401. serial = serial + 1
  402. Next
  403. yy = yy + dt2.Rows.Count
  404. aa = aa + 1
  405. my_x = my_x + 1
  406. ' my_card = dt_inprocess.Rows(x).Item("card")
  407. ' my_date = dt_inprocess.Rows(x).Item("date")
  408. bb = bb + 1
  409. Next
  410. xlSheet2.Range("A2:A" & xlSheet2.UsedRange.Rows.Count).FillDown()
  411. 'xlSheet2.Range("B2:B" & x + 1).FillDown()
  412. xlSheet2.Range("D2:D" & xlSheet2.UsedRange.Rows.Count).FillDown()
  413. xlSheet2.Range("J2:J" & xlSheet2.UsedRange.Rows.Count).FillDown()
  414. xlSheet2.Range("L2:L" & xlSheet2.UsedRange.Rows.Count).FillDown()
  415. xlSheet2.Range("M2:M" & xlSheet2.UsedRange.Rows.Count).FillDown()
  416. 'xlSheet2.Range("O2:O" & x + 1).FillDown()
  417. 'xlSheet2.Range("P2:P" & x + 1).FillDown()
  418. MsgBox("")
  419. End Sub
  420. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click '------517B出库
  421. Dim aa As String
  422. Dim bb As String
  423. Dim my_card As String = ""
  424. Dim my_date As Date
  425. aa = TextBox2.Text
  426. bb = aa
  427. If aa = "" Then
  428. MsgBox("请输入起始单号")
  429. Exit Sub
  430. End If
  431. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  432. Dim xlApp1 As Microsoft.Office.Interop.Excel.Application
  433. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  434. Dim xlBook1 As Microsoft.Office.Interop.Excel.Workbook
  435. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  436. Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
  437. Dim xlSheet_1 As Microsoft.Office.Interop.Excel.Worksheet
  438. Dim xlSheet2_2 As Microsoft.Office.Interop.Excel.Worksheet
  439. Dim file_name As String = ""
  440. Dim file_name1 As String = ""
  441. Dim my_weight As Double = 0
  442. Dim a As Integer = 0
  443. Dim my_count As Integer = 0
  444. Dim my_x As Integer = 0
  445. xlApp = CreateObject("Excel.Application")
  446. xlApp.Visible = True
  447. xlApp.DisplayAlerts = False
  448. xlBook = xlApp.Workbooks.Open("D:\K3\k3表格模板\313打尺出库.xls",, True)
  449. xlBook.Activate()
  450. Dim dt2 As New DataTable
  451. For i = 1 To xlApp.Worksheets.Count
  452. If xlApp.Workbooks(1).Worksheets(i).name = "Page1" Then
  453. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  454. xlSheet.Activate()
  455. Exit For
  456. End If
  457. Next
  458. Dim my_no As String = "SCLL0"
  459. Dim yy As Integer = 1
  460. Dim x As Integer = 0
  461. Dim my_total_no As Integer = 0
  462. Dim dt As New DataTable
  463. sql = "select date1 from rt_pu_measure2_temp where (date1 BETWEEN '" & String.Format("{0:d}", dtp_begin.Value) & "' and '" & String.Format("{0:d}", dtp_end.Value) & "') group by date1 order by date1"
  464. cmd.CommandText = sql
  465. da.SelectCommand = cmd
  466. Dim dt_out As New DataTable
  467. da.Fill(dt_out)
  468. Dim final_no As Integer
  469. For x = 0 To dt_out.Rows.Count - 1 '-----------loop
  470. xlSheet.Cells(x + 2, 1) = String.Format("{0:d}", dt_out.Rows(x).Item("date1"))
  471. xlSheet.Cells(x + 2, 2) = String.Format("{0:d}", dt_out.Rows(x).Item("date1"))
  472. xlSheet.Cells(x + 2, 3) = "'曾添梅"
  473. xlSheet.Cells(x + 2, 4) = "'" & my_no & bb
  474. xlSheet.Cells(x + 2, 5) = "'zhang"
  475. xlSheet.Cells(x + 2, 6) = "'1"
  476. xlSheet.Cells(x + 2, 7) = "'24"
  477. xlSheet.Cells(x + 2, 8) = "'165701"
  478. xlSheet.Cells(x + 2, 9) = "'655P-R"
  479. xlSheet.Cells(x + 2, 10) = "'修剪、成检、量尺、包装-R"
  480. xlSheet.Cells(x + 2, 12) = "'103"
  481. xlSheet.Cells(x + 2, 13) = "'曾添梅"
  482. xlSheet.Cells(x + 2, 14) = "'103"
  483. xlSheet.Cells(x + 2, 15) = "'曾添梅"
  484. ' xlSheet.Cells(x + 2, 15) = "'85"
  485. For i = 1 To xlApp.Worksheets.Count
  486. If xlApp.Workbooks(1).Worksheets(i).name = "Page2" Then
  487. xlSheet2 = xlApp.Workbooks(1).Worksheets(i)
  488. xlSheet2.Activate()
  489. Exit For
  490. End If
  491. Next
  492. Dim serial As Integer = 1
  493. For xx As Integer = 1 To 5
  494. Dim sql1 As String
  495. Dim my_type As String
  496. Select Case xx
  497. Case 1
  498. sql = "SELECT date1 ,cust,color,thick,pattern,comment1,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec, cast(sf as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 = '" & dt_out.Rows(x).Item("date1") & "') and not( comment1 like N'%仓存%' or comment1 like N'%仓库%' or comment1 like N'%库存%' or comment1 like N'%取%' or comment1 like N'%退返%' or comment1 like N'%冲孔%' or comment1 like N'%返车间%') order by date1 "
  499. my_type = "--正常--"
  500. Case 2
  501. sql = "SELECT date1 ,cust,color,thick,pattern,comment1,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec,cast(sf as numeric(10,1)) as 尺数 FROM Rt_pu_measure2_TEMP WHERE (date1 = '" & dt_out.Rows(x).Item("date1") & "') and (comment1 not like N'%冲孔%') and (comment1 like N'%仓存%' or comment1 like N'%仓库%') order by date1" '----仓存仓库
  502. my_type = "--仓库--"
  503. Case 3
  504. sql = "SELECT date1, cust,color,thick,case when (comment1 like N'%4-8%' or comment1 like N'%7%') then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when (comment1 like N'%12%') then N'516 贴膜 12+' end as spec, CAST((sf) AS numeric(10, 1)) AS 尺数,comment1
  505. FROM Rt_pu_measure2_TEMP where (date1 = '" & dt_out.Rows(x).Item("date1") & "') and (comment1 not like N'%冲孔%') and ((comment1 like N'%取%') or (comment1 like N'%库存%')) ORDER BY date1"
  506. my_type = "--待打包、库存--"
  507. Case 4
  508. sql = "SELECT date1 ,cust,color,thick,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec, CAST((sf) AS numeric(10, 1)) AS 尺数,comment1
  509. FROM Rt_pu_measure2_TEMP where (date1 = '" & dt_out.Rows(x).Item("date1") & "') and (comment1 like N'%退返%') order by date1 " '---退返
  510. my_type = "--退返--"
  511. Case 5
  512. sql = "SELECT date1 , cust,color,thick,case when comment1 like N'%4-8%' or comment1 like N'%7%' then N'516 贴膜 4-8' when (comment1 like N'%8以上%' or comment1 like N'%8%') and (comment1 not like N'%4%') then N'516 贴膜 8-12' when comment1 like N'%12%' then N'516 贴膜 12+' end as spec, CAST((sf) AS numeric(10, 1)) AS 尺数,comment1
  513. FROM Rt_pu_measure2_TEMP where (date1 = '" & dt_out.Rows(x).Item("date1") & "') and ((comment1 like N'%冲孔%') or (comment1 like N'%返车间%')) ORDER BY date1 "
  514. my_type = "--冲孔、返车间--"
  515. End Select
  516. dt2 = New DataTable
  517. cmd.CommandText = sql
  518. da.SelectCommand = cmd
  519. da.Fill(dt2)
  520. For y = 0 To dt2.Rows.Count - 1
  521. xlSheet2.Cells(yy + 1 + y, 2) = "'" & serial '行号
  522. xlSheet2.Cells(yy + 1 + y, 3) = "'" & my_no & bb
  523. xlSheet2.Cells(yy + 1 + y, 6) = "313.P.PU"
  524. xlSheet2.Cells(yy + 1 + y, 7) = "二层皮"
  525. xlSheet2.Cells(yy + 1 + y, 24) = String.Format(dt2.Rows(y).Item("尺数"), "###0.0")
  526. ' xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price")
  527. 'xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("sf") * dt2.Rows(y).Item("price")
  528. xlSheet2.Cells(yy + 1 + y, 23) = dt2.Rows(y).Item("spec") '批号
  529. xlSheet2.Cells(yy + 1 + y, 28) = "打尺入库" & my_type
  530. xlSheet2.Cells(yy + 1 + y, 35) = "'517B"
  531. xlSheet2.Cells(yy + 1 + y, 36) = "PU成品仓"
  532. xlSheet2.Cells(yy + 1 + y, 52) = "'" & dt2.Rows(y).Item("cust")
  533. xlSheet2.Cells(yy + 1 + y, 54) = dt2.Rows(y).Item("尺数")
  534. xlSheet2.Cells(yy + 1 + y, 56) = "'" & dt2.Rows(y).Item("color")
  535. ' xlSheet2.Cells(yy + 1 + y, 40) = "'" & dt2.Rows(y).Item("date")
  536. xlSheet2.Cells(yy + 1 + y, 57) = dt2.Rows(y).Item("thick")
  537. xlSheet2.Cells(yy + 1 + y, 58) = dt2.Rows(y).Item("comment1")
  538. ' xlSheet2.Cells(yy + 1 + y, 61) = dt2.Rows(y).Item("commentB")
  539. ' xlSheet2.Cells(yy + 1 + y, 64) = dt2.Rows(y).Item("retan_weight")
  540. serial = serial + 1
  541. Next
  542. yy = yy + dt2.Rows.Count
  543. aa = aa + 1
  544. my_x = my_x + 1
  545. ' my_card = dt_inprocess.Rows(x).Item("card")
  546. ' my_date = dt_inprocess.Rows(x).Item("date")
  547. Next
  548. bb = bb + 1
  549. final_no = x
  550. Next
  551. 'my_total_no = my_total_no + dt.Rows.Count
  552. ''For dd As Integer = 0 To dt.Rows.Count - 1
  553. xlSheet2.Range("A2:A" & final_no).FillDown()
  554. 'xlSheet2.Range("B2:B" & x + 1).FillDown()
  555. xlSheet2.Range("D2:D" & final_no).FillDown()
  556. xlSheet2.Range("I2:I" & final_no).FillDown()
  557. xlSheet2.Range("J2:J" & final_no).FillDown()
  558. xlSheet2.Range("K2:V" & final_no).FillDown()
  559. xlSheet.Range("A2:A" & final_no).FillDown()
  560. xlSheet.Range("R2:V" & final_no).FillDown()
  561. MsgBox("")
  562. End Sub
  563. End Class