Ingen beskrivning
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_BG_main.vb~RF401dd27.TMP 41KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. Imports System.Data.SqlClient
  2. Imports System.Net
  3. Imports Microsoft.Office.Interop
  4. Public Class Frm_BG_main
  5. Dim cmd As New SqlCommand
  6. Dim da As New SqlDataAdapter
  7. Dim my_year111 As Integer
  8. Dim my_month111 As Integer
  9. 'Dim my_year As Integer
  10. Dim sql As String
  11. Dim conn As New SqlConnection
  12. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  13. Frm_wb_out.Show()
  14. End Sub
  15. Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
  16. Frm_Stock_Month.Show()
  17. End Sub
  18. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  19. Frm_BG_PROCESS.Show()
  20. End Sub
  21. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  22. Frm_BG_Record.Show()
  23. End Sub
  24. Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
  25. Frm_Ship_detail.Show()
  26. End Sub
  27. Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
  28. Frm_BG_IN_SUM.Show()
  29. End Sub
  30. Private Sub Button21_Click(sender As Object, e As EventArgs) Handles Button21.Click
  31. Frm_BG_OUT_SUM.Show()
  32. End Sub
  33. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  34. Frm_bg_chem_out_daily.Show()
  35. End Sub
  36. Private Sub Button22_Click(sender As Object, e As EventArgs) Handles Button22.Click '---每日发货
  37. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  38. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  39. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  40. Dim name(1000) As String
  41. Dim no(1000) As String
  42. Dim SERIAL(1000) As String
  43. Dim YEAR1(1000) As String
  44. Dim MONTH1(1000) As String
  45. Dim DATE1(1000) As String
  46. Dim COMMENT(1000) As String
  47. Dim qty(1000) As Double
  48. Dim QTY1(1000) As Double
  49. Dim po_no(1000) As String
  50. Dim sku_no(1000) As String
  51. Dim nw(1000) As Double
  52. Dim gw(1000) As Double
  53. Dim price(1000) As Double
  54. Dim dt As New DataTable
  55. Dim file_name As String = ""
  56. Dim file_name1 As String = ""
  57. ListBox1.Items.Clear()
  58. Dim a As Integer = 0
  59. Dim my_count As Integer = 0
  60. 'OpenFileDialog1.Multiselect = True
  61. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  62. file_name = OpenFileDialog1.FileName
  63. file_name1 = OpenFileDialog1.SafeFileName
  64. End If
  65. xlApp = CreateObject("Excel.Application")
  66. xlApp.Visible = True
  67. xlApp.DisplayAlerts = False
  68. 'sql = "delete from rt_bg_io"
  69. 'cmd.CommandText = sql
  70. 'cmd.ExecuteNonQuery()
  71. xlBook = xlApp.Workbooks.Open(file_name,, True)
  72. xlBook.Activate()
  73. Dim yy As Integer = 0
  74. ListBox1.Items.Add(file_name)
  75. Dim my_customer As String = ""
  76. If OpenFileDialog1.SafeFileName Like "越南上杰发货*" Then
  77. ElseIf OpenFileDialog1.SafeFileName Like "上杰*" Then '-----------上杰
  78. sql = "delete from rt_ship_daily_sj"
  79. cmd.CommandText = sql
  80. cmd.ExecuteNonQuery()
  81. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  82. Dim y As Integer = 0
  83. For y = 14 To xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  84. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  85. Exit For
  86. End If
  87. Next y
  88. xlApp.Range("A14:N" & y - 1).Select()
  89. ' If xlApp.Selection.mergecells = True Then
  90. xlApp.Selection.UnMerge
  91. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  92. xlApp.CutCopyMode = False
  93. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  94. ' End If
  95. For y = 14 To y - 1
  96. sql = "insert into rt_ship_daily_sj (no,name,qty_sf,nw,gw,po_no,qty_sf1,unit_price) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",'" & xlSheet.Cells(y, 7).value & "'," & xlSheet.Cells(y, 9).value & "," & xlSheet.Cells(y, 10).value & ")"
  97. cmd.CommandText = sql
  98. cmd.ExecuteScalar()
  99. Next
  100. sql = "select 品名,cast(sum(淨重) as numeric(10,1)) as 淨重 from (select case when 品名 like '%PU%' or 品名 like '%action%' or 品名 like N'%榔%' then 'pu' else '反毛' end as 品名,淨重 from (select name as 品名,sum(weight) as 淨重 from (SELECT no, name, qty_sf1, nw,qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) AS Ratio, cast(qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) *nw as numeric(10,3)) as weight FROM rt_ship_daily_sj) as p group by name) as q ) as qq group by 品名"
  101. cmd.CommandText = sql
  102. dt = New DataTable
  103. da.SelectCommand = cmd
  104. da.Fill(dt)
  105. dt.Columns.Add("尺数")
  106. dt.Columns.Add("货值")
  107. For rr As Integer = 0 To dt.Rows.Count - 1
  108. sql = "SELECT CAST(SUM(qty_sf1) AS numeric(10, 1)) AS 呎數 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM rt_ship_daily_sj) AS p
  109. GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  110. cmd.CommandText = sql
  111. dt.Rows(rr).Item("尺数") = cmd.ExecuteScalar
  112. Next
  113. For rr As Integer = 0 To dt.Rows.Count - 1
  114. sql = "SELECT CAST(SUM(qty_sf1 * unit_price) AS numeric(10, 3)) AS 金額 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM rt_ship_daily_sj) AS p
  115. GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  116. cmd.CommandText = sql
  117. dt.Rows(rr).Item("货值") = cmd.ExecuteScalar
  118. Next
  119. dgv1.DataSource = dt
  120. ElseIf OpenFileDialog1.SafeFileName Like "永正货柜*" Then '-----------永正
  121. sql = "delete from rt_ship_uz_HG"
  122. cmd.CommandText = sql
  123. cmd.ExecuteNonQuery()
  124. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  125. Dim y As Integer = 0
  126. For y = 14 To xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  127. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  128. Exit For
  129. End If
  130. Next y
  131. xlApp.Range("A14:N" & y - 1).Select()
  132. If xlApp.Selection.mergecells = True Then
  133. xlApp.Selection.UnMerge
  134. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  135. xlApp.CutCopyMode = False
  136. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  137. End If
  138. For y = 14 To y - 1
  139. sql = "insert into rt_ship_uz_HG (no,name,qty_sf,nw,gw,po_no,qty_sf1,unit_price) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 3).value * 0.1 & ",0,'" & xlSheet.Cells(y, 6).value & "'," & xlSheet.Cells(y, 8).value & ",0)"
  140. cmd.CommandText = sql
  141. cmd.ExecuteScalar()
  142. Next
  143. sql = "select 品名,cast(sum(淨重) as numeric(10,1)) as 淨重 from (select case when 品名 like '%PU%' or 品名 like '%action%' or 品名 like N'%榔%' then 'pu' else '反毛' end as 品名,淨重 from (select name as 品名,sum(weight) as 淨重 from (SELECT no, name, qty_sf1, nw,qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) AS Ratio, cast(qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) *nw as numeric(10,3)) as weight FROM RT_Ship_UZ_HG) as p group by name) as q ) as qq group by 品名"
  144. cmd.CommandText = sql
  145. dt = New DataTable
  146. da.SelectCommand = cmd
  147. da.Fill(dt)
  148. dt.Columns.Add("尺数")
  149. dt.Columns.Add("货值")
  150. For rr As Integer = 0 To dt.Rows.Count - 1
  151. sql = "SELECT CAST(SUM(qty_sf1) AS numeric(10, 1)) AS 呎數 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM RT_Ship_UZ_HG) AS p
  152. GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  153. cmd.CommandText = sql
  154. dt.Rows(rr).Item("尺数") = cmd.ExecuteScalar
  155. Next
  156. For rr As Integer = 0 To dt.Rows.Count - 1
  157. sql = "SELECT CAST(SUM(qty_sf1 * unit_price) AS numeric(10, 3)) AS 金額 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM RT_Ship_UZ_HG) AS p
  158. GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  159. cmd.CommandText = sql
  160. dt.Rows(rr).Item("货值") = cmd.ExecuteScalar
  161. Next
  162. dgv1.DataSource = dt
  163. ElseIf OpenFileDialog1.SafeFileName Like "永正发货*" Then '-----------永正1
  164. sql = "delete from rt_ship_uz_1"
  165. cmd.CommandText = sql
  166. cmd.ExecuteNonQuery()
  167. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  168. Dim y As Integer = 0
  169. For y = 14 To xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  170. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  171. Exit For
  172. End If
  173. Next y
  174. yy = y - 1
  175. xlApp.Range("A14:O" & yy).Select()
  176. If xlApp.Selection.mergecells = True Then
  177. xlApp.Selection.UnMerge
  178. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  179. xlApp.CutCopyMode = False
  180. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  181. End If
  182. For y = 14 To y - 1
  183. sql = "insert into rt_ship_uz_1 (no,name,qty_sf,nw,gw,po_no,qty_sf1,unit_price) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",'" & xlSheet.Cells(y, 7).value & "'," & xlSheet.Cells(y, 9).value & "," & xlSheet.Cells(y, 14).value & ")"
  184. cmd.CommandText = sql
  185. cmd.ExecuteScalar()
  186. Next
  187. sql = "select 品名,cast(sum(淨重) as numeric(10,1)) as 淨重 from (select case when 品名 like '%PU%' or 品名 like '%action%' or 品名 like N'%榔%' then 'pu' else '反毛' end as 品名,淨重 from (select name as 品名,sum(weight) as 淨重 from (SELECT no, name, qty_sf1, nw,qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) AS Ratio, cast(qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) *nw as numeric(10,3)) as weight FROM RT_Ship_UZ_1) as p group by name) as q ) as qq group by 品名"
  188. cmd.CommandText = sql
  189. dt = New DataTable
  190. da.SelectCommand = cmd
  191. da.Fill(dt)
  192. dt.Columns.Add("尺数")
  193. dt.Columns.Add("货值")
  194. For rr As Integer = 0 To dt.Rows.Count - 1
  195. sql = "SELECT CAST(SUM(qty_sf1) AS numeric(10, 1)) AS 呎數 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM RT_Ship_UZ_1) AS p
  196. GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  197. cmd.CommandText = sql
  198. dt.Rows(rr).Item("尺数") = cmd.ExecuteScalar
  199. Next
  200. For rr As Integer = 0 To dt.Rows.Count - 1
  201. sql = "SELECT CAST(SUM(qty_sf1 * unit_price) AS numeric(10, 3)) AS 金額 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM RT_Ship_UZ_1) AS p
  202. GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  203. cmd.CommandText = sql
  204. dt.Rows(rr).Item("货值") = cmd.ExecuteScalar
  205. Next
  206. dgv1.DataSource = dt
  207. ElseIf OpenFileDialog1.SafeFileName Like "永川*" Then
  208. ElseIf OpenFileDialog1.SafeFileName Like "亿博*" Then
  209. sql = "delete from rt_ship_daily_yb"
  210. cmd.CommandText = sql
  211. cmd.ExecuteNonQuery()
  212. For i = 1 To xlApp.Worksheets.Count
  213. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  214. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  215. xlSheet.Activate()
  216. Exit For
  217. End If
  218. Next
  219. Dim y As Integer = 0
  220. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  221. If Len(xlSheet.Cells(y, 9).value) < 1 Then
  222. Exit For
  223. End If
  224. Next y
  225. xlApp.Range("A2:i" & y - 1).Select()
  226. If xlApp.Selection.mergecells = True Then
  227. xlApp.Selection.UnMerge
  228. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  229. xlApp.CutCopyMode = False
  230. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  231. End If
  232. For y = 2 To y - 1
  233. sql = "insert into rt_ship_daily_yb (no,name,qty,nw,gw,po_no) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",N'" & xlSheet.Cells(y, 7).value & "')"
  234. cmd.CommandText = sql
  235. cmd.ExecuteScalar()
  236. Next
  237. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  238. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度"
  239. cmd.CommandText = sql
  240. dt = New DataTable
  241. da.SelectCommand = cmd
  242. da.Fill(dt)
  243. dgv1.DataSource = dt
  244. sql = "select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  245. FROM RT_SHIP_DAILY_YB) as p group by 订单号,类别,厚度"
  246. cmd.CommandText = sql
  247. dt = New DataTable
  248. da.SelectCommand = cmd
  249. da.Fill(dt)
  250. dgv2.DataSource = dt
  251. sql = "select 类别,sum(尺数),sum(净重) from (select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  252. FROM RT_SHIP_DAILY_YB) as p group by 订单号,类别,厚度) as q group by 类别"
  253. cmd.CommandText = sql
  254. dt = New DataTable
  255. da.SelectCommand = cmd
  256. da.Fill(dt)
  257. dgv3.DataSource = dt
  258. ' sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,1)) as 总价,sum(weight) as 淨重 from (SELECT no, name, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  259. 'FROM RT_SHIP_DAILY_PUMA) as p group by name"
  260. ' cmd.CommandText = sql
  261. ' dt = New DataTable
  262. ' da.SelectCommand = cmd
  263. ' da.Fill(dt)
  264. 'sql = ""
  265. 'cmd.CommandText = sql
  266. 'dt = New DataTable
  267. 'da.SelectCommand = cmd
  268. 'da.Fill(dt)
  269. 'dgv2.DataSource = dt
  270. ElseIf OpenFileDialog1.SafeFileName Like "加和*" Then
  271. sql = "delete from rt_ship_daily_jh"
  272. cmd.CommandText = sql
  273. cmd.ExecuteNonQuery()
  274. For i = 1 To xlApp.Worksheets.Count
  275. If xlApp.Workbooks(1).Worksheets(i).name = "加和" Then
  276. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  277. xlSheet.Activate()
  278. Exit For
  279. End If
  280. Next
  281. Dim y As Integer = 0
  282. For y = 4 To xlApp.ActiveSheet.UsedRange.Rows.Count
  283. If Len(xlSheet.Cells(y, 5).value) < 1 Then
  284. Exit For
  285. End If
  286. Next y
  287. xlApp.Range("A4:L" & y - 1).Select()
  288. If xlApp.Selection.mergecells = True Then
  289. xlApp.Selection.UnMerge
  290. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  291. xlApp.CutCopyMode = False
  292. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  293. End If
  294. For y = 4 To y - 1
  295. sql = "insert into rt_ship_daily_jh (no,po_no,m_no,name,thick,color,qty_sf,nw,gw) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "','" & xlSheet.Cells(y, 4).value & "',N'" & xlSheet.Cells(y, 5).value & "','" & xlSheet.Cells(y, 6).value & "',N'" & xlSheet.Cells(y, 7).value & "'," & xlSheet.Cells(y, 8).value & "," & xlSheet.Cells(y, 11).value & "," & xlSheet.Cells(y, 12).value& & ")"
  296. cmd.CommandText = sql
  297. cmd.ExecuteScalar()
  298. Next
  299. sql = "select po_no as 订单号,m_no as 料号,name as 品名, color as 颜色,thick as 厚度,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(weight) as numeric(10,1)) as 净重 from (SELECT no, po_no, no1, m_no, name, ltrim(thick) as thick, color, qty_sf, no2, p, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *nw as numeric(10,1)) as weight
  300. FROM RT_SHIP_DAILY_JH) as p group by po_no,m_no,name,color,thick"
  301. cmd.CommandText = sql
  302. dt = New DataTable
  303. da.SelectCommand = cmd
  304. da.Fill(dt)
  305. dgv1.DataSource = dt
  306. sql = "select po_no as 订单号,thick as 厚度,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(weight) as numeric(10,1)) as 净重 from (SELECT no, po_no, no1, m_no, name, ltrim(thick) as thick, color, qty_sf, no2, p, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *nw as numeric(10,1)) as weight
  307. FROM RT_SHIP_DAILY_JH) as p group by po_no,thick"
  308. cmd.CommandText = sql
  309. dt = New DataTable
  310. da.SelectCommand = cmd
  311. da.Fill(dt)
  312. dgv2.DataSource = dt
  313. sql = "select 品名,thick as 厚度, cast(sum(qty_sf) as numeric(10,1)) as 尺数,sum(weight) as 净重 from (SELECT no, po_no, no1, m_no, name, ltrim(thick) as thick, color, qty_sf, no2, p, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *nw as numeric(10,1)) as weight,case when name like '%PU%' or name like N'%纹%' or name like '%action%' or name like N'%榔%' then 'pu' else '反毛' end as 品名
  314. FROM RT_SHIP_DAILY_JH) as p group by 品名,thick"
  315. cmd.CommandText = sql
  316. dt = New DataTable
  317. da.SelectCommand = cmd
  318. da.Fill(dt)
  319. dgv3.DataSource = dt
  320. ElseIf OpenFileDialog1.SafeFileName Like "吉兴*" Then
  321. ElseIf OpenFileDialog1.SafeFileName Like "宏美*" Then
  322. ElseIf OpenFileDialog1.SafeFileName Like "宏福*" Then
  323. ElseIf OpenFileDialog1.SafeFileName Like "东治*" Then
  324. ElseIf OpenFileDialog1.SafeFileName Like "东家*" Then
  325. sql = "delete from rt_ship_daily_dj"
  326. cmd.CommandText = sql
  327. cmd.ExecuteNonQuery()
  328. For i = 1 To xlApp.Worksheets.Count
  329. If xlApp.Workbooks(1).Worksheets(i).name = "0" Then
  330. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  331. xlSheet.Activate()
  332. Exit For
  333. End If
  334. Next
  335. Dim y As Integer = 0
  336. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  337. If Len(xlSheet.Cells(y, 7).value) < 1 Then
  338. Exit For
  339. End If
  340. Next y
  341. xlApp.Range("A2:K" & y - 1).Select()
  342. xlApp.Selection.UnMerge
  343. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  344. xlApp.CutCopyMode = False
  345. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  346. For y = 2 To y - 1
  347. sql = "insert into rt_ship_daily_dj (no,name,qty,nw,gw,po_no,unit_price) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",N'" & xlSheet.Cells(y, 7).value & "'," & xlSheet.Cells(y, 10).value & ")"
  348. cmd.CommandText = sql
  349. cmd.ExecuteScalar()
  350. Next
  351. sql = "select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from
  352. (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,
  353. cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价
  354. FROM RT_SHIP_DAILY_dj) as p group by 订单号,类别,厚度"
  355. cmd.CommandText = sql
  356. dt = New DataTable
  357. da.SelectCommand = cmd
  358. da.Fill(dt)
  359. dgv1.DataSource = dt
  360. sql = "select 类别,sum(尺数),sum(净重),sum(货值) from(select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价 FROM RT_SHIP_DAILY_dj) as p group by 订单号,类别,厚度) as q group by 类别"
  361. cmd.CommandText = sql
  362. dt = New DataTable
  363. da.SelectCommand = cmd
  364. da.Fill(dt)
  365. dgv2.DataSource = dt
  366. ' sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,1)) as 总价,sum(weight) as 淨重 from (SELECT no, name, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  367. 'FROM RT_SHIP_DAILY_PUMA) as p group by name"
  368. ' cmd.CommandText = sql
  369. ' dt = New DataTable
  370. ' da.SelectCommand = cmd
  371. ' da.Fill(dt)
  372. 'sql = ""
  373. 'cmd.CommandText = sql
  374. 'dt = New DataTable
  375. 'da.SelectCommand = cmd
  376. 'da.Fill(dt)
  377. 'dgv2.DataSource = dt
  378. ElseIf OpenFileDialog1.SafeFileName Like "贝孚*" Then
  379. ElseIf OpenFileDialog1.SafeFileName Like "Samil*" Then
  380. ElseIf OpenFileDialog1.SafeFileName Like "PUMA*" Then '-----------------PUMA
  381. Dim conn1 As New SqlConnection
  382. conn1.ConnectionString = connstring
  383. conn1.Open()
  384. Dim cmd1 As New SqlCommand
  385. cmd1.Connection = conn1
  386. Dim dr As SqlDataReader
  387. sql = "delete from rt_ship_daily_puma"
  388. cmd.CommandText = sql
  389. cmd.ExecuteNonQuery()
  390. For i = 1 To xlApp.Worksheets.Count
  391. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  392. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  393. xlSheet.Activate()
  394. Exit For
  395. End If
  396. Next
  397. Dim y As Integer = 0
  398. For y = 4 To xlApp.ActiveSheet.UsedRange.Rows.Count
  399. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  400. Exit For
  401. End If
  402. Next y
  403. xlApp.Range("A4:v" & y - 1).Select()
  404. If xlApp.Selection.mergecells = True Then
  405. xlApp.Selection.UnMerge
  406. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  407. xlApp.CutCopyMode = False
  408. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  409. End If
  410. For y = 4 To y - 1
  411. sql = "insert into rt_ship_daily_puma (no,name,color,qty_sf,gw1,po_no,unit_price) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "',N'" & xlSheet.Cells(y, 4).value & "'," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 12).value & ",N'" & xlSheet.Cells(y, 14).value & "'," & xlSheet.Cells(y, 19).value & ")"
  412. cmd.CommandText = sql
  413. cmd.ExecuteScalar()
  414. Next
  415. sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,2)) as 货值,po_no as 订单号,sum(重量) as 毛重, sum(袋重) as 袋重,sum(重量)-sum(袋重) as 净重 from
  416. (select no,name,qty_sf,unit_price,po_no,gw1,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,2)) as 重量,cast(pa/SUM(pa) OVER (PARTITION BY no)*0.1 as numeric(10,2)) as 袋重 from
  417. (select no,name,color,qty_sf,unit_price,po_no,gw1,cast(count as numeric(10,1)) as pa from
  418. (SELECT no, name,case when name<>'' then 1 end as count, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  419. FROM RT_SHIP_DAILY_PUMA) as r) as s) as t group by name,po_no order by 品名,po_no"
  420. cmd.CommandText = sql
  421. dt = New DataTable
  422. da.SelectCommand = cmd
  423. da.Fill(dt)
  424. dgv1.DataSource = dt
  425. sql = "select 品名,sum(尺数) as 尺数,cast(sum(净重) as numeric(10,1)) as 淨重 from(select case when 品名 like '%PU%' or 品名 like '%action%' or 品名 like N'%榔%' then 'pu' else '反毛' end as 品名,尺数,净重 from
  426. (select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,2)) as 货值,po_no as 订单号,sum(重量) as 毛重, sum(袋重) as 袋重,sum(重量)-sum(袋重) as 净重 from
  427. (select no,name,qty_sf,unit_price,po_no,gw1,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,2)) as 重量,cast(pa/SUM(pa) OVER (PARTITION BY no)*0.1 as numeric(10,3)) as 袋重 from
  428. (select no,name,color,qty_sf,unit_price,po_no,gw1,cast(count as numeric(10,2)) as pa from
  429. (SELECT no, name,case when name<>'' then 1 end as count, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,2)) as weight
  430. FROM RT_SHIP_DAILY_PUMA) as r) as s) as t group by name,po_no) as u) as v group by 品名"
  431. cmd.CommandText = sql
  432. dt = New DataTable
  433. da.SelectCommand = cmd
  434. da.Fill(dt)
  435. dgv2.DataSource = dt
  436. ' sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,1)) as 总价,sum(weight) as 淨重 from (SELECT no, name, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  437. 'FROM RT_SHIP_DAILY_PUMA) as p group by name"
  438. ' cmd.CommandText = sql
  439. ' dt = New DataTable
  440. ' da.SelectCommand = cmd
  441. ' da.Fill(dt)
  442. 'sql = ""
  443. 'cmd.CommandText = sql
  444. 'dt = New DataTable
  445. 'da.SelectCommand = cmd
  446. 'da.Fill(dt)
  447. 'dgv2.DataSource = dt
  448. ElseIf OpenFileDialog1.SafeFileName Like "HATAY*" Then
  449. ElseIf OpenFileDialog1.SafeFileName Like "DCLASE*" Then
  450. ElseIf OpenFileDialog1.SafeFileName Like "078*" Then
  451. ElseIf OpenFileDialog1.SafeFileName Like "076发货*" Then '------------------------金威利/威弘
  452. sql = "delete from rt_ship_076_1"
  453. cmd.CommandText = sql
  454. cmd.ExecuteNonQuery()
  455. For i = 1 To xlApp.Worksheets.Count
  456. xlSheet = xlApp.Worksheets(i)
  457. xlSheet.Activate()
  458. Dim y As Integer
  459. For y = xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count To 3 Step -1
  460. If xlSheet.Cells(y, 1).value = Nothing Then
  461. GoTo OK
  462. End If
  463. If xlSheet.Cells(y, 1).value.ToString = "数量合计" Then
  464. Exit For
  465. End If
  466. OK:
  467. Next y
  468. Dim yyy As Integer
  469. For yyy = 3 To xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count
  470. If xlSheet.Cells(yyy, 11).value = "制 表" Then
  471. Exit For
  472. End If
  473. Next yyy
  474. xlSheet.Range("A3:A" & y - 1).Select()
  475. xlApp.Selection.UnMerge
  476. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  477. 'xlApp.CutCopyMode = False
  478. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  479. xlSheet.Range("c3:f" & y - 1).Select()
  480. xlApp.Selection.UnMerge
  481. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  482. 'xlApp.CutCopyMode = False
  483. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  484. xlSheet.Range("i3:i" & yyy - 1).Select()
  485. xlApp.Selection.UnMerge
  486. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  487. 'xlApp.CutCopyMode = False
  488. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  489. If xlSheet.Range("k3:n" & yyy - 1).MergeCells.ToString <> "False" Then
  490. xlSheet.Range("k3:n" & yyy - 1).Select()
  491. xlApp.Selection.UnMerge
  492. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  493. 'xlApp.CutCopyMode = False
  494. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  495. End If
  496. Dim my_no As String
  497. Dim my_po As String
  498. Dim my_work As String
  499. Dim my_color As String
  500. Dim my_thick As String
  501. Dim my_no1 As String
  502. Dim my_po1 As String
  503. Dim my_work1 As String
  504. Dim my_color1 As String
  505. Dim my_thick1 As String
  506. For y = 3 To y - 1
  507. 'If IsNumeric(xlSheet.Cells(y, 1).value) And Not (xlSheet.Cells(y, 2).value = Nothing) Then
  508. If y = 3 Then
  509. my_no = xlSheet.Cells(y, 1).value
  510. my_po = xlSheet.Cells(y, 3).value
  511. my_work = xlSheet.Cells(y, 4).value
  512. my_color = xlSheet.Cells(y, 5).value
  513. my_thick = xlSheet.Cells(y, 6).value
  514. my_no1 = xlSheet.Cells(y, 9).value
  515. my_po1 = xlSheet.Cells(y, 10).value
  516. my_work1 = xlSheet.Cells(y, 11).value
  517. my_color1 = xlSheet.Cells(y, 12).value
  518. my_thick1 = xlSheet.Cells(y, 13).value
  519. End If
  520. If xlSheet.Cells(y, 2).value = Nothing And xlSheet.Cells(y, 3).value = Nothing And xlSheet.Cells(y, 4).value = Nothing And xlSheet.Cells(y, 5).value = Nothing And xlSheet.Cells(y, 6).value = Nothing Then
  521. ' Exit For
  522. Else
  523. If xlSheet.Cells(y, 3).value Is Nothing Then
  524. 'my_no = xlSheet.Cells(y, 1).value
  525. 'my_po = xlSheet.Cells(y, 3).value
  526. ' my_work = xlSheet.Cells(y, 4).value
  527. ' my_color = xlSheet.Cells(y, 5).value
  528. ' my_thick = xlSheet.Cells(y, 6).value
  529. Else
  530. my_no = xlSheet.Cells(y, 1).value
  531. my_po = xlSheet.Cells(y, 3).value
  532. my_work = xlSheet.Cells(y, 4).value
  533. my_color = xlSheet.Cells(y, 5).value
  534. my_thick = xlSheet.Cells(y, 6).value
  535. End If
  536. sql = "insert into rt_ship_076_1 (no,sf,order_no,i_no,color,thick) values('" & my_no & "'," & xlSheet.Cells(y, 2).value & ",N'" & my_po & "',N'" & my_work & "',N'" & my_color & "','" & my_thick & "')"
  537. cmd.CommandText = sql
  538. cmd.ExecuteScalar()
  539. End If
  540. my_no1 = xlSheet.Cells(y, 9).value
  541. my_po1 = xlSheet.Cells(y, 11).value
  542. my_work1 = xlSheet.Cells(y, 12).value
  543. my_color1 = xlSheet.Cells(y, 13).value
  544. my_thick1 = xlSheet.Cells(y, 14).value
  545. If xlSheet.Cells(y, 10).value = Nothing And xlSheet.Cells(y, 11).value = Nothing And xlSheet.Cells(y, 12).value = Nothing And xlSheet.Cells(y, 13).value = Nothing And xlSheet.Cells(y, 14).value = Nothing Then
  546. ' Exit For
  547. Else
  548. If xlSheet.Cells(y, 10).value Is Nothing Then
  549. Else
  550. my_no1 = xlSheet.Cells(y, 9).value
  551. my_po1 = xlSheet.Cells(y, 11).value
  552. my_work1 = xlSheet.Cells(y, 12).value
  553. my_color1 = xlSheet.Cells(y, 13).value
  554. my_thick1 = xlSheet.Cells(y, 14).value
  555. End If
  556. sql = "insert into rt_ship_076_1 (no,sf,order_no,i_no,color,thick) values('" & my_no & "'," & xlSheet.Cells(y, 10).value & ",N'" & my_po & "',N'" & my_work & "',N'" & my_color & "','" & my_thick & "')"
  557. cmd.CommandText = sql
  558. cmd.ExecuteScalar()
  559. End If
  560. ' sql = "insert into rt_ship_076_1 (no,sf,order_no,i_no,color,thick) values('" & my_no & "'," & xlSheet.Cells(y, 5).valu & ",N'" & my_po & "',N'" & my_work & "',N'" & my_color & "','" & my_thick & "')"
  561. 'cmd.CommandText = sql
  562. ' cmd.ExecuteScalar()
  563. ''End If
  564. ''If IsNumeric(xlSheet.Cells(y, 1 + 8).value) And Not (xlSheet.Cells(y, 1 + 9).value = Nothing) Then
  565. 'sql = "insert into rt_ship_076_1 (no,sf,order_no,i_no,color,thick) values('" & xlSheet.Cells(y, 1 + 8).value & "'," & xlSheet.Cells(y, 2 + 8).value & ",N'" & xlSheet.Cells(y, 3 + 8).value & "',N'" & xlSheet.Cells(y, 4 + 8).value & "',N'" & xlSheet.Cells(y, 5 + 8).value & "','" & xlSheet.Cells(y, 6 + 8).value & "')"
  566. ' cmd.CommandText = sql
  567. ' cmd.ExecuteScalar()
  568. ''End If
  569. Next
  570. Next
  571. sql = "SELECT order_no AS 订单号, i_no AS 指令号, color AS 颜色, thick AS 厚度, cast(SUM(sf) as numeric(10,1)) AS 尺数 FROM RT_ship_076_1 GROUP BY order_no, i_no, color, thick ORDER BY 订单号, 指令号, 颜色"
  572. cmd.CommandText = sql
  573. dt = New DataTable
  574. da.SelectCommand = cmd
  575. da.Fill(dt)
  576. dgv1.DataSource = dt
  577. 'dt.Columns.Add("尺数")
  578. 'dt.Columns.Add("货值")
  579. sql = "SELECT 订单类别, 厚度, SUM(尺数) AS 尺数, 类别
  580. FROM (SELECT CASE WHEN LEFT(order_no, 2)
  581. = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  582. i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  583. CASE WHEN color LIKE '%pu%' OR
  584. color LIKE '%action%' OR
  585. color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  586. FROM RT_ship_076_1
  587. GROUP BY order_no, i_no, color, thick) AS p
  588. GROUP BY 订单类别, 厚度, 类别
  589. ORDER BY 订单类别"
  590. cmd.CommandText = sql
  591. dt = New DataTable
  592. da.SelectCommand = cmd
  593. da.Fill(dt)
  594. dgv2.DataSource = dt
  595. sql = "SELECT 订单类别, SUM(尺数) AS 尺数, 类别
  596. FROM (SELECT CASE WHEN LEFT(order_no, 2)
  597. = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  598. i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  599. CASE WHEN color LIKE '%pu%' OR
  600. color LIKE '%action%' OR
  601. color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  602. FROM RT_ship_076_1
  603. GROUP BY order_no, i_no, color, thick) AS p
  604. GROUP BY 订单类别, 类别 ORDER BY 订单类别"
  605. cmd.CommandText = sql
  606. dt = New DataTable
  607. da.SelectCommand = cmd
  608. da.Fill(dt)
  609. dgv3.DataSource = dt
  610. For rr As Integer = 0 To dt.Rows.Count - 1
  611. 'sql = ""
  612. 'cmd.CommandText = sql
  613. 'dt.Rows(rr).Item("尺数") = cmd.ExecuteScalar
  614. Next
  615. For rr As Integer = 0 To dt.Rows.Count - 1
  616. 'sql = ""
  617. 'cmd.CommandText = sql
  618. 'dt.Rows(rr).Item("货值") = cmd.ExecuteScalar
  619. Next
  620. 'DataGridView1.DataSource = dt
  621. End If
  622. 'xlSheet = Nothing '釋放sheet物件
  623. 'xlApp.Quit() '關閉Excel
  624. 'xlApp = Nothing
  625. MsgBox("完成")
  626. End Sub
  627. Private Sub Frm_BG_main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  628. conn.ConnectionString = connstring
  629. conn.Open()
  630. cmd.Connection = conn
  631. End Sub
  632. Private Sub DataGridView2_MouseUp(sender As Object, e As MouseEventArgs) Handles dgv2.MouseUp
  633. Dim x As Double = 0
  634. Dim y As Double = 0
  635. For i As Integer = 0 To dgv2.SelectedRows.Count - 1
  636. x = x + Math.Round(dgv2.Rows(dgv2.SelectedRows.Item(i).Index).Cells("尺数").Value, 1)
  637. Next i
  638. TextBox3.Text = dgv2.SelectedRows.Count
  639. TextBox2.Text = x
  640. End Sub
  641. End Class