Bez popisu
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_TM.vb 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. Imports System.Data.SqlClient
  2. Imports System.Net
  3. Imports System.Windows.Forms.VisualStyles.VisualStyleElement
  4. Public Class Frm_TM
  5. Dim cmd As New SqlCommand
  6. Dim da As New SqlDataAdapter
  7. Dim dt As New DataTable
  8. Dim sql As String
  9. Dim conn As New SqlConnection
  10. Private dateTimePicker1 As DateTimePicker
  11. Dim p() As String
  12. Dim my_cust As String = ""
  13. Dim colorArray(10) As Color
  14. Dim sql_retan As String = ""
  15. Dim sql_retan_re As String = ""
  16. Dim sql_spray As String = ""
  17. Dim sql_buff As String = ""
  18. Dim dt_retan As DataTable
  19. Dim dt_retan_re As DataTable
  20. Dim dt_spray As DataTable
  21. Dim dt_buff As DataTable
  22. Private Sub Frm_TM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  23. conn.ConnectionString = connstring
  24. conn.Open()
  25. cmd.Connection = conn
  26. sql = "SELECT CARD as 卡号, card2 as 卡号1, 类别, type as 类别1, AVG(下鼓重) AS 下鼓重, cast(AVG(price) as numeric(10,2)) AS 单价, code, 选级, card_shaving as 出库卡, CUST as 客户, COLOR as 颜色, source as 皮源,
  27. DATE as 日期, 厚度, dd as 技术员, 皮源1, 皮源代码, AVG(挑级仓出库重) AS 出库重, SUM(chem) AS 化工成本, cast(SUM(chem)
  28. / AVG(投鼓重) / 6 as numeric(10,2)) AS 每尺化工
  29. FROM (SELECT TOP (100) PERCENT p.CARD, CASE WHEN substring(p.CARD, 3, 1) = 'F' THEN substring(p.CARD, 4, 10)
  30. + 'F' ELSE substring(p.CARD, 4, 10) + 'P' END AS card2, CASE WHEN substring(p.card, 3, 1)
  31. = 'P' THEN N'贴膜' WHEN substring(p.card, 3, 1) = 'F' THEN '反毛' ELSE '其他' END AS 类别, p.type,
  32. AVG(p.WEIGHT) / 2 AS 下鼓重, COUNT(*) AS Expr2, CASE WHEN rt_shaving_out.price IS NULL
  33. THEN 30 ELSE rt_shaving_out.price END AS price, CASE WHEN rt_shaving_out.weight IS NULL
  34. THEN AVG(p.WEIGHT) / 2 ELSE rt_shaving_out.weight END AS weight, CASE WHEN rt_shaving_out.code IS NULL
  35. THEN '212F.XX.2.1' ELSE rt_shaving_out.code END AS code, CASE WHEN rt_shaving_out.name IS NULL
  36. THEN N'D级' ELSE rt_shaving_out.name END AS 选级, rt_shaving_out.card1,
  37. rt_shaving_out.card AS card_shaving, p.CUST, p.COLOR, p.source, CASE WHEN rt_wetblue_name.code IS NULL
  38. THEN '212F.XX' ELSE rt_wetblue_name.code END AS 编码, CASE WHEN rt_wetblue_name.name IS NULL
  39. THEN N'杂皮 二层' ELSE rt_wetblue_name.name END AS 皮源, p.DATE,
  40. CASE WHEN substring(rt_shaving_out.code, 13, 1) = '1' THEN '1.02' WHEN substring(rt_shaving_out.code, 13, 1)
  41. = '2' THEN '1.24' WHEN substring(rt_shaving_out.code, 13, 1)
  42. = '3' THEN '1.46' WHEN substring(rt_shaving_out.code, 13, 1)
  43. = '4' THEN '1.68' WHEN substring(rt_shaving_out.code, 13, 1) IS NULL THEN '1.24' END AS 厚度, p.dd,
  44. CASE WHEN rt_shaving_out.card1 IS NULL AND
  45. p.type = N'套染' THEN N'套染' WHEN rt_shaving_out.price IS NULL AND
  46. p.type = N'打底' THEN N'回鼓' ELSE N'打底' END AS 备注,
  47. CASE WHEN p.source LIKE N'%无铬鞣%' THEN N'无铬鞣 二层' WHEN p.source LIKE N'%阿根廷%' THEN N'阿根廷 二层'
  48. WHEN p.source LIKE N'%澳%' THEN N'澳大利亚 二层' WHEN (p.source LIKE N'%巴西%' OR
  49. p.source LIKE N'%bx%')
  50. THEN N'巴西 二层' WHEN p.source LIKE N'%智利%' THEN N'智利 二层' WHEN p.source LIKE N'%德国%' THEN N'德国 二层'
  51. WHEN p.source LIKE N'%西班牙%' THEN N'西班牙 二层' WHEN p.source LIKE N'%欧洲%' THEN N'欧洲 二层' WHEN
  52. p.source LIKE N'%法国%' THEN N'法国 二层' WHEN p.source LIKE N'%爱尔兰%' THEN N'爱尔兰 二层' WHEN p.source
  53. LIKE N'%APP%' THEN N'美国 二层' WHEN p.source LIKE N'%日本%' THEN N'日本 二层' WHEN p.source LIKE N'%美国%'
  54. THEN N'美国 二层' WHEN p.source LIKE N'%新西兰%' THEN N'新西兰 二层' WHEN p.source LIKE N'%小皮%' THEN
  55. N'小皮 二层' WHEN p.source LIKE N'%英国%' THEN N'英国 二层' WHEN p.source LIKE N'%墨西哥%' THEN N'墨西哥 二层'
  56. WHEN p.source LIKE N'%乌拉圭%' THEN N'乌拉圭 二层' WHEN p.source LIKE N'%南非%' THEN N'南非 二层' WHEN
  57. p.source LIKE N'%孟加拉%' THEN N'孟加拉 二层' WHEN p.source LIKE N'%泰国%' THEN N'泰国 二层' ELSE N'杂皮 二层'
  58. END AS 皮源1,
  59. CASE WHEN p.source LIKE N'%无铬鞣%' THEN N'CT' WHEN p.source LIKE N'%阿根廷%' THEN N'AR' WHEN p.source
  60. LIKE N'%澳%' THEN N'AU' WHEN (p.source LIKE N'%巴西%' OR
  61. p.source LIKE N'%bx%')
  62. THEN N'BR' WHEN p.source LIKE N'%智利%' THEN N'CL' WHEN p.source LIKE N'%德国%' THEN N'DE' WHEN p.source
  63. LIKE N'%西班牙%' THEN N'ES' WHEN p.source LIKE N'%欧洲%' THEN N'EU' WHEN p.source LIKE N'%法国%' THEN
  64. N'FR' WHEN p.source LIKE N'%爱尔兰%' THEN N'IE' WHEN p.source LIKE N'%日本%' THEN N'JP' WHEN p.source LIKE
  65. N'%越南APP%' THEN N'US' WHEN p.source LIKE N'%美国%' THEN N'US' WHEN p.source LIKE N'%新西兰%' THEN N'NZ'
  66. WHEN p.source LIKE N'%小皮%' THEN N'SS' WHEN p.source LIKE N'%英国%' THEN N'UK' WHEN p.source LIKE N'%墨西哥%'
  67. THEN N'MX' WHEN p.source LIKE N'%乌拉圭%' THEN N'UY' WHEN p.source LIKE N'%南非%' THEN N'ZA' WHEN p.source
  68. LIKE N'%孟加拉%' THEN N'BD' WHEN p.source LIKE N'%泰国%' THEN N'TH' ELSE N'XX' END AS 皮源代码,
  69. rt_shaving_out.weight AS 挑级仓出库重, CASE WHEN rt_shaving_out.weight IS NULL THEN AVG(p.weight)
  70. / 2 ELSE rt_shaving_out.weight END AS 投鼓重, RT_SYS_CHEM_OUT.CODE AS Expr1,
  71. RT_SYS_CHEM_OUT.NAME, rt_chem_price_li.price1 AS chemprice,
  72. RT_SYS_CHEM_OUT.WEIGHT AS chemweight, CASE WHEN rt_chem_price_li.price1 IS NULL
  73. THEN 0 ELSE rt_chem_price_li.price1 * rt_sys_chem_out.weight END AS chem
  74. FROM RT_SYS_CHEM_OUT INNER JOIN
  75. rt_chem_price_li ON RT_SYS_CHEM_OUT.CODE = rt_chem_price_li.code RIGHT OUTER JOIN
  76. (SELECT NO, AREA, MONTH, HEADER, HEADER2, DATE, CARD, CARD1, CUST, COLOR, W1, P1, A1, W2, P2, A2,
  77. W3, P3, A3, W4, P4, A4, source, TOTAL, class, type, DATE1, WEIGHT, P, COMa, COMb, COMc, dd, ee, ff,
  78. gg, hh, Dep
  79. FROM RT_RETAN_RECORD_D
  80. WHERE (DATE BETWEEN '2024/6/1' AND '2024/6/30') AND (COMa NOT LIKE N'%叠皮%') AND
  81. (WEIGHT IS NOT NULL)) AS p ON RT_SYS_CHEM_OUT.CARD = p.CARD LEFT OUTER JOIN
  82. rt_wetblue_name RIGHT OUTER JOIN
  83. rt_shaving_out ON LEFT(rt_wetblue_name.code, 7) = LEFT(rt_shaving_out.code, 7) ON
  84. p.CARD = rt_shaving_out.card1
  85. GROUP BY p.type, p.CARD, p.CARD1, rt_shaving_out.price, rt_shaving_out.weight, rt_shaving_out.code,
  86. rt_shaving_out.name, rt_shaving_out.card1, rt_shaving_out.card, p.CUST, p.COLOR, p.source,
  87. rt_wetblue_name.code, rt_wetblue_name.name, p.DATE, p.dd, RT_SYS_CHEM_OUT.CODE,
  88. RT_SYS_CHEM_OUT.NAME, rt_chem_price_li.price1, RT_SYS_CHEM_OUT.WEIGHT
  89. ORDER BY p.CARD) AS s
  90. GROUP BY CARD, card2, 类别, type, 下鼓重, code, 选级, card1, card_shaving, CUST, COLOR, source, 编码, 皮源, DATE, 厚度, dd,
  91. 备注, 皮源1, 皮源代码
  92. HAVING (type = N'打底') and card_shaving is not null" ''----蓝皮下鼓
  93. cmd.CommandText = sql
  94. dt_retan = New DataTable
  95. da.SelectCommand = cmd
  96. da.Fill(dt_retan)
  97. End Sub
  98. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  99. Dim aa As String
  100. Dim my_card As String = ""
  101. Dim my_date As Date
  102. aa = TextBox8.Text
  103. If aa = "" Then
  104. MsgBox("请输入起始单号")
  105. Exit Sub
  106. End If
  107. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  108. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  109. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  110. Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
  111. Dim file_name As String = ""
  112. Dim file_name1 As String = ""
  113. Dim my_weight As Double = 0
  114. Dim a As Integer = 0
  115. Dim my_count As Integer = 0
  116. Dim my_x As Integer = 0
  117. xlApp = CreateObject("Excel.Application")
  118. xlApp.Visible = True
  119. xlApp.DisplayAlerts = False
  120. xlBook = xlApp.Workbooks.Open("D:\K3\k3表格模板\下鼓染色入库.xls",, True)
  121. xlBook.Activate()
  122. Dim dt2 As New DataTable
  123. For i = 1 To xlApp.Worksheets.Count
  124. If xlApp.Workbooks(1).Worksheets(i).name = "Page1" Then
  125. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  126. xlSheet.Activate()
  127. Exit For
  128. End If
  129. Next
  130. Dim my_no As String = "CPRK"
  131. Dim yy As Integer = 1
  132. Dim x As Integer = 0
  133. Dim dt_inprocess As New DataTable
  134. sql = "select * from rt_TM240630 order by no"
  135. cmd.CommandText = sql
  136. da.SelectCommand = cmd
  137. da.Fill(dt_inprocess)
  138. For x = 0 To dt_inprocess.Rows.Count - 1 '-----------loop
  139. xlSheet.Cells(my_x + 2, 1) = "2024/06/30"
  140. xlSheet.Cells(my_x + 2, 2) = "2024/06/30"
  141. xlSheet.Cells(my_x + 2, 3) = "'曾添梅"
  142. xlSheet.Cells(my_x + 2, 4) = "'" & my_no & aa
  143. xlSheet.Cells(my_x + 2, 5) = "'zhang"
  144. xlSheet.Cells(my_x + 2, 6) = "'1"
  145. xlSheet.Cells(my_x + 2, 7) = "'2"
  146. xlSheet.Cells(my_x + 2, 8) = "'165701"
  147. xlSheet.Cells(my_x + 2, 9) = "'620-R"
  148. xlSheet.Cells(my_x + 2, 10) = "'生产部-R"
  149. xlSheet.Cells(my_x + 2, 11) = "'103"
  150. xlSheet.Cells(my_x + 2, 12) = "'曾添梅"
  151. xlSheet.Cells(my_x + 2, 13) = "'103"
  152. xlSheet.Cells(my_x + 2, 14) = "'曾添梅"
  153. xlSheet.Cells(my_x + 2, 15) = "'85"
  154. For i = 1 To xlApp.Worksheets.Count
  155. If xlApp.Workbooks(1).Worksheets(i).name = "Page2" Then
  156. xlSheet2 = xlApp.Workbooks(1).Worksheets(i)
  157. xlSheet2.Activate()
  158. Exit For
  159. End If
  160. Next
  161. ' sql = "SELECT TOP (100) PERCENT p.CARD, CASE WHEN substring(p.CARD, 3, 1) = 'F' THEN substring(p.CARD, 4, 10)
  162. ' + 'F' ELSE substring(p.CARD, 4, 10) + 'P' END AS card2, CASE WHEN substring(p.card, 3, 1)
  163. ' = 'P' THEN N'贴膜' WHEN substring(p.card, 3, 1) = 'F' THEN '反毛' ELSE '其他' END AS 类别, p.type, AVG(p.WEIGHT)
  164. ' / 2 AS 下鼓重, COUNT(*) AS Expr2, CASE WHEN rt_shaving_out.price IS NULL
  165. ' THEN 30 ELSE rt_shaving_out.price END AS price, CASE WHEN rt_shaving_out.weight IS NULL THEN AVG(p.WEIGHT)
  166. ' / 2 ELSE rt_shaving_out.weight END AS weight, CASE WHEN rt_shaving_out.code IS NULL
  167. ' THEN '212F.XX.2.1' ELSE rt_shaving_out.code END AS code, CASE WHEN rt_shaving_out.name IS NULL
  168. ' THEN N'D级' ELSE rt_shaving_out.name END AS 选级, rt_shaving_out.card1, rt_shaving_out.card AS Expr3, p.CUST,
  169. ' p.COLOR, p.source, CASE WHEN rt_wetblue_name.code IS NULL
  170. ' THEN '212F.XX' ELSE rt_wetblue_name.code END AS 编码, CASE WHEN rt_wetblue_name.name IS NULL
  171. ' THEN N'杂皮 二层' ELSE rt_wetblue_name.name END AS 皮源, p.DATE, CASE WHEN substring(rt_shaving_out.code, 13, 1)
  172. ' = '1' THEN '1.02' WHEN substring(rt_shaving_out.code, 13, 1) = '2' THEN '1.24' WHEN substring(rt_shaving_out.code, 13, 1)
  173. ' = '3' THEN '1.46' WHEN substring(rt_shaving_out.code, 13, 1) = '4' THEN '1.68' WHEN substring(rt_shaving_out.code, 13, 1)
  174. ' IS NULL THEN '1.24' END AS 厚度, p.dd, CASE WHEN rt_shaving_out.card1 IS NULL AND
  175. ' p.type = N'套染' THEN N'套染' WHEN rt_shaving_out.price IS NULL AND
  176. ' p.type = N'打底' THEN N'回鼓' ELSE N'打底' END AS 备注,
  177. ' CASE WHEN p.source LIKE N'%无铬鞣%' THEN N'无铬鞣 二层' WHEN p.source LIKE N'%阿根廷%' THEN N'阿根廷 二层' WHEN
  178. ' p.source LIKE N'%澳%' THEN N'澳大利亚 二层' WHEN (p.source LIKE N'%巴西%' OR
  179. ' p.source LIKE N'%bx%')
  180. ' THEN N'巴西 二层' WHEN p.source LIKE N'%智利%' THEN N'智利 二层' WHEN p.source LIKE N'%德国%' THEN N'德国 二层' WHEN
  181. ' p.source LIKE N'%西班牙%' THEN N'西班牙 二层' WHEN p.source LIKE N'%欧洲%' THEN N'欧洲 二层' WHEN p.source LIKE N'%法国%'
  182. ' THEN N'法国 二层' WHEN p.source LIKE N'%爱尔兰%' THEN N'爱尔兰 二层' WHEN p.source LIKE N'%APP%' THEN N'美国 二层'
  183. ' WHEN p.source LIKE N'%日本%' THEN N'日本 二层' WHEN p.source LIKE N'%美国%' THEN N'美国 二层' WHEN p.source LIKE
  184. ' N'%新西兰%' THEN N'新西兰 二层' WHEN p.source LIKE N'%小皮%' THEN N'小皮 二层' WHEN p.source LIKE N'%英国%' THEN
  185. ' N'英国 二层' WHEN p.source LIKE N'%墨西哥%' THEN N'墨西哥 二层' WHEN p.source LIKE N'%乌拉圭%' THEN N'乌拉圭 二层'
  186. ' WHEN p.source LIKE N'%南非%' THEN N'南非 二层' WHEN p.source LIKE N'%孟加拉%' THEN N'孟加拉 二层' WHEN p.source
  187. ' LIKE N'%泰国%' THEN N'泰国 二层' ELSE N'杂皮 二层' END AS 皮源1,
  188. ' CASE WHEN p.source LIKE N'%无铬鞣%' THEN N'CT' WHEN p.source LIKE N'%阿根廷%' THEN N'AR' WHEN p.source LIKE N'%澳%'
  189. ' THEN N'AU' WHEN (p.source LIKE N'%巴西%' OR
  190. ' p.source LIKE N'%bx%')
  191. ' THEN N'BR' WHEN p.source LIKE N'%智利%' THEN N'CL' WHEN p.source LIKE N'%德国%' THEN N'DE' WHEN p.source LIKE N'%西班牙%'
  192. ' THEN N'ES' WHEN p.source LIKE N'%欧洲%' THEN N'EU' WHEN p.source LIKE N'%法国%' THEN N'FR' WHEN p.source LIKE N'%爱尔兰%'
  193. ' THEN N'IE' WHEN p.source LIKE N'%日本%' THEN N'JP' WHEN p.source LIKE N'%APP%' THEN N'US' WHEN p.source LIKE
  194. ' N'%美国%' THEN N'US' WHEN p.source LIKE N'%新西兰%' THEN N'NZ' WHEN p.source LIKE N'%小皮%' THEN N'SS' WHEN p.source
  195. ' LIKE N'%英国%' THEN N'UK' WHEN p.source LIKE N'%墨西哥%' THEN N'MX' WHEN p.source LIKE N'%乌拉圭%' THEN N'UY' WHEN
  196. ' p.source LIKE N'%南非%' THEN N'ZA' WHEN p.source LIKE N'%孟加拉%' THEN N'BD' WHEN p.source LIKE N'%泰国%' THEN
  197. ' N'TH' ELSE N'XX' END AS 皮源代码, rt_shaving_out.weight AS 挑级仓出库重, CASE WHEN rt_shaving_out.weight IS NULL
  198. ' THEN AVG(p.weight) / 2 ELSE rt_shaving_out.weight END AS 投鼓重
  199. 'FROM rt_wetblue_name RIGHT OUTER JOIN
  200. ' rt_shaving_out ON LEFT(rt_wetblue_name.code, 7) = LEFT(rt_shaving_out.code, 7) RIGHT OUTER JOIN
  201. ' (SELECT NO, AREA, MONTH, HEADER, HEADER2, DATE, CARD, CARD1, CUST, COLOR, W1, P1, A1, W2, P2, A2, W3, P3,
  202. ' A3, W4, P4, A4, source, TOTAL, class, type, DATE1, WEIGHT, P, COMa, COMb, COMc, dd, ee, ff, gg, hh, Dep
  203. ' FROM RT_RETAN_RECORD_D
  204. ' WHERE (DATE BETWEEN '2024/6/1' AND '2024/6/30') AND (COMa NOT LIKE N'%叠皮%') AND (WEIGHT IS NOT NULL) and card=N'" & dt_retan.Rows(x).Item("卡号") & "'And date=N'" & dt_retan.Rows(x).Item("日期") & "') AS p
  205. ' ON rt_shaving_out.card1 = p.CARD
  206. 'GROUP BY p.type, p.CARD, p.CARD1, rt_shaving_out.price, rt_shaving_out.weight, rt_shaving_out.code, rt_shaving_out.name,
  207. ' rt_shaving_out.card1, rt_shaving_out.card, p.CUST, p.COLOR, p.source, rt_wetblue_name.code, rt_wetblue_name.name,
  208. ' p.DATE, p.dd
  209. 'ORDER BY p.CARD"
  210. sql = "SELECT TOP (200) rt_TM240630.date, rt_TM240630.no, rt_TM240630.card, rt_TM240630.type, rt_TM240630.word, rt_TM240630.cust,
  211. rt_TM240630.color, rt_TM240630.weight_ini, rt_TM240630.tech, rt_TM240630.source, rt_TM240630.thick, rt_TM240630.word1,
  212. rt_TM240630.weight, rt_TM240630.commentB, rt_TM240630.commentC, rt_TM240630.commentD, rt_TM240630.commentE,
  213. rt_TM240630.serial, rt_TM240630.comment, rt_TM240630.source1, rt_TM240630.code, rt_shaving_price.price
  214. FROM rt_TM240630 LEFT OUTER JOIN
  215. rt_shaving_price ON rt_TM240630.code = rt_shaving_price.source where rt_TM240630.no='" & dt_inprocess.Rows(x).Item("no") & "'"
  216. dt2 = New DataTable
  217. cmd.CommandText = sql
  218. da.SelectCommand = cmd
  219. da.Fill(dt2)
  220. Dim serial As Integer = 1
  221. For y = 0 To dt2.Rows.Count - 1
  222. xlSheet2.Cells(yy + 1 + y, 2) = "'" & serial '行号
  223. xlSheet2.Cells(yy + 1 + y, 3) = "'" & my_no & aa
  224. If dt2.Rows(y).Item("type") = "反绒" Then
  225. xlSheet2.Cells(yy + 1 + y, 5) = "313.FM"
  226. xlSheet2.Cells(yy + 1 + y, 6) = "二层皮"
  227. Else
  228. xlSheet2.Cells(yy + 1 + y, 5) = "313.PU"
  229. xlSheet2.Cells(yy + 1 + y, 6) = "贴膜皮"
  230. End If
  231. xlSheet2.Cells(yy + 1 + y, 14) = dt2.Rows(y).Item("weight") / 2
  232. If (dt2.Rows(y).Item("color") Like "*4300*" Or dt2.Rows(y).Item("color") Like "*4800*" Or dt2.Rows(y).Item("color") Like "*白*") And dt2.Rows(y).Item("type") = "反绒" Then
  233. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + (1.7 + 1.4) * 6
  234. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * (dt2.Rows(y).Item("price") + (1.7 + 1.4) * 6)
  235. xlSheet2.Cells(yy + 1 + y, 46) = 1.7
  236. xlSheet2.Cells(yy + 1 + y, 45) = 1.4
  237. ElseIf dt2.Rows(y).Item("type") = "反绒" And dt2.Rows(y).Item("color") Like "*黑*" Then
  238. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + (1.3 + 1.4) * 6
  239. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * (dt2.Rows(y).Item("price") + (1.3 + 1.4) * 6)
  240. xlSheet2.Cells(yy + 1 + y, 46) = 1.3
  241. xlSheet2.Cells(yy + 1 + y, 45) = 1.4
  242. ElseIf dt2.Rows(y).Item("type") = "反绒" Then
  243. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + (1.5 + 1.4) * 6
  244. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * (dt2.Rows(y).Item("price") + (1.5 + 1.4) * 6)
  245. xlSheet2.Cells(yy + 1 + y, 46) = 1.5
  246. xlSheet2.Cells(yy + 1 + y, 45) = 1.4
  247. ElseIf dt2.Rows(y).Item("type") = "PU" And dt2.Rows(y).Item("color") Like "*白*" Then
  248. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + (0.6 + 1) * 6
  249. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * xlSheet2.Cells(yy + 1 + y, 15).value
  250. xlSheet2.Cells(yy + 1 + y, 46) = 0.6
  251. xlSheet2.Cells(yy + 1 + y, 45) = 1
  252. ElseIf dt2.Rows(y).Item("type") = "PU" And dt2.Rows(y).Item("color") Like "*黑*" Then
  253. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + (0.8 + 1) * 6
  254. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * xlSheet2.Cells(yy + 1 + y, 15).value
  255. xlSheet2.Cells(yy + 1 + y, 46) = 0.8
  256. xlSheet2.Cells(yy + 1 + y, 45) = 1
  257. ElseIf dt2.Rows(y).Item("type") = "PU" Then
  258. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + (0.7 + 1) * 6
  259. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * xlSheet2.Cells(yy + 1 + y, 15).value
  260. xlSheet2.Cells(yy + 1 + y, 46) = 0.7
  261. xlSheet2.Cells(yy + 1 + y, 45) = 1
  262. ElseIf dt2.Rows(y).Item("code") = "小皮 二层" Then
  263. xlSheet2.Cells(yy + 1 + y, 15) = 5.4 * 6
  264. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * 5.4 * 6
  265. End If
  266. If dt2.Rows(y).Item("commentE") = "在制水场" And Not (dt2.Rows(y).Item("type") = "PU") Then
  267. xlSheet2.Cells(yy + 1 + y, 15) = xlSheet2.Cells(yy + 1 + y, 15).value - 0.6 * 6
  268. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * xlSheet2.Cells(yy + 1 + y, 15).value
  269. ElseIf dt2.Rows(y).Item("commentE") = "在制涂饰" And Not (dt2.Rows(y).Item("type") = "PU") Then
  270. xlSheet2.Cells(yy + 1 + y, 15) = xlSheet2.Cells(yy + 1 + y, 15).value - 0.4 * 6
  271. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * xlSheet2.Cells(yy + 1 + y, 15).value
  272. ElseIf Not (dt2.Rows(y).Item("type") = "PU") Then
  273. xlSheet2.Cells(yy + 1 + y, 15) = xlSheet2.Cells(yy + 1 + y, 15).value + 0.2 * 6
  274. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("weight") / 2 * xlSheet2.Cells(yy + 1 + y, 15).value
  275. End If
  276. xlSheet2.Cells(yy + 1 + y, 17) = "313 " & dt2.Rows(y).Item("code")
  277. xlSheet2.Cells(yy + 1 + y, 18) = "2024/6/30盘点"
  278. If dt2.Rows(y).Item("commentE") = "在制水场" Then
  279. xlSheet2.Cells(yy + 1 + y, 25) = "'213A-R.01"
  280. xlSheet2.Cells(yy + 1 + y, 26) = "染色仓/蓝皮下鼓"
  281. ElseIf dt2.Rows(y).Item("commentE") = "在制涂饰" Then
  282. xlSheet2.Cells(yy + 1 + y, 25) = "'313"
  283. xlSheet2.Cells(yy + 1 + y, 26) = "涂饰在制品"
  284. ElseIf dt2.Rows(y).Item("commentE") = "待打包" Then
  285. xlSheet2.Cells(yy + 1 + y, 25) = "'517"
  286. xlSheet2.Cells(yy + 1 + y, 26) = "成品仓"
  287. End If
  288. xlSheet2.Cells(yy + 1 + y, 38) = "'" & dt2.Rows(y).Item("cust")
  289. xlSheet2.Cells(yy + 1 + y, 39) = "'" & dt2.Rows(y).Item("commentD")
  290. xlSheet2.Cells(yy + 1 + y, 40) = dt2.Rows(y).Item("tech")
  291. xlSheet2.Cells(yy + 1 + y, 41) = dt2.Rows(y).Item("source")
  292. xlSheet2.Cells(yy + 1 + y, 42) = dt2.Rows(y).Item("color")
  293. ' xlSheet2.Cells(yy + 1 + y, 43) = dt2.Rows(y).Item("厚度")
  294. xlSheet2.Cells(yy + 1 + y, 44) = dt2.Rows(y).Item("card")
  295. 'xlSheet2.Cells(yy + 1 + y, 45) = dt2.Rows(y).Item("选级")
  296. xlSheet2.Cells(yy + 1 + y, 47) = dt2.Rows(y).Item("weight_ini")
  297. xlSheet2.Cells(yy + 1 + y, 48) = dt2.Rows(y).Item("type")
  298. serial = serial + 1
  299. Next
  300. yy = yy + dt2.Rows.Count
  301. aa = aa + 1
  302. my_x = my_x + 1
  303. my_card = dt_inprocess.Rows(x).Item("card")
  304. my_date = dt_inprocess.Rows(x).Item("date")
  305. Next
  306. xlSheet2.Range("A2:A" & x + 1).FillDown()
  307. 'xlSheet2.Range("B2:B" & x + 1).FillDown()
  308. xlSheet2.Range("D2:D" & x + 1).FillDown()
  309. xlSheet2.Range("J2:J" & x + 1).FillDown()
  310. xlSheet2.Range("L2:L" & x + 1).FillDown()
  311. xlSheet2.Range("M2:M" & x + 1).FillDown()
  312. 'xlSheet2.Range("O2:O" & x + 1).FillDown()
  313. 'xlSheet2.Range("P2:P" & x + 1).FillDown()
  314. MsgBox("")
  315. End Sub
  316. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click '成品仓
  317. Dim aa As String
  318. Dim my_card As String = ""
  319. Dim my_date As Date
  320. aa = TextBox8.Text
  321. If aa = "" Then
  322. MsgBox("请输入起始单号")
  323. Exit Sub
  324. End If
  325. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  326. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  327. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  328. Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
  329. Dim file_name As String = ""
  330. Dim file_name1 As String = ""
  331. Dim my_weight As Double = 0
  332. Dim a As Integer = 0
  333. Dim my_count As Integer = 0
  334. Dim my_x As Integer = 0
  335. xlApp = CreateObject("Excel.Application")
  336. xlApp.Visible = True
  337. xlApp.DisplayAlerts = False
  338. xlBook = xlApp.Workbooks.Open("D:\K3\k3表格模板\下鼓染色入库.xls",, True)
  339. xlBook.Activate()
  340. Dim dt2 As New DataTable
  341. For i = 1 To xlApp.Worksheets.Count
  342. If xlApp.Workbooks(1).Worksheets(i).name = "Page1" Then
  343. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  344. xlSheet.Activate()
  345. Exit For
  346. End If
  347. Next
  348. Dim my_no As String = "CPRK"
  349. Dim yy As Integer = 1
  350. Dim x As Integer = 0
  351. Dim dt_inprocess As New DataTable
  352. sql = "SELECT rt_finish_stock_0630.date, rt_finish_stock_0630.cust, rt_finish_stock_0630.color, rt_finish_stock_0630.card,
  353. rt_finish_stock_0630.pattern, rt_finish_stock_0630.sf, rt_finish_stock_0630.comment, rt_finish_stock_0630.type,
  354. rt_finish_stock_0630.source, rt_finish_stock_0630.size, rt_finish_stock_0630.lot, rt_finish_stock_0630.wh,
  355. rt_finish_stock_0630.id, CASE WHEN rt_shaving_price.price IS NOT NULL
  356. THEN CAST(rt_shaving_price.price / 5.8 AS numeric(10, 2))
  357. WHEN lot LIKE '%12+%' THEN 4.8 WHEN lot LIKE '%8-12%' THEN 4.2 WHEN lot LIKE '%4-8%' THEN 3.6 END AS price,
  358. CASE WHEN type LIKE '%反毛%' AND color LIKE '%白%' THEN 1.7 + 0.2 WHEN type LIKE '%反毛%' AND
  359. color LIKE '%黑%' THEN 1.3 + 0.2 WHEN type LIKE '%反毛%' THEN 1.5 + 0.2 WHEN type LIKE N'%贴膜%' AND
  360. color LIKE '%白%' THEN 0.6 + 1.6 WHEN type LIKE N'%贴膜%' THEN 0.8 + 1.4 END AS retan_cost,
  361. CASE WHEN type LIKE '%反毛%' THEN 1.5 WHEN type LIKE N'%贴膜%' THEN 1.5 END AS p_cost
  362. FROM rt_finish_stock_0630 LEFT OUTER JOIN
  363. rt_shaving_price ON rt_finish_stock_0630.lot = '516 ' + rt_shaving_price.source
  364. ORDER BY rt_finish_stock_0630.id"
  365. cmd.CommandText = sql
  366. da.SelectCommand = cmd
  367. da.Fill(dt_inprocess)
  368. For x = 0 To dt_inprocess.Rows.Count - 1 '-----------loop
  369. xlSheet.Cells(my_x + 2, 1) = "2024/06/30"
  370. xlSheet.Cells(my_x + 2, 2) = "2024/06/30"
  371. xlSheet.Cells(my_x + 2, 3) = "'吴小男"
  372. xlSheet.Cells(my_x + 2, 4) = "'" & my_no & aa
  373. xlSheet.Cells(my_x + 2, 5) = "'zhang"
  374. xlSheet.Cells(my_x + 2, 6) = "'1"
  375. xlSheet.Cells(my_x + 2, 7) = "'2"
  376. xlSheet.Cells(my_x + 2, 8) = "'165701"
  377. xlSheet.Cells(my_x + 2, 9) = "'620-R"
  378. xlSheet.Cells(my_x + 2, 10) = "'生产部-R"
  379. xlSheet.Cells(my_x + 2, 11) = "'120"
  380. xlSheet.Cells(my_x + 2, 12) = "'吴小男"
  381. xlSheet.Cells(my_x + 2, 13) = "'120"
  382. xlSheet.Cells(my_x + 2, 14) = "'吴小男"
  383. xlSheet.Cells(my_x + 2, 15) = "'85"
  384. For i = 1 To xlApp.Worksheets.Count
  385. If xlApp.Workbooks(1).Worksheets(i).name = "Page2" Then
  386. xlSheet2 = xlApp.Workbooks(1).Worksheets(i)
  387. xlSheet2.Activate()
  388. Exit For
  389. End If
  390. Next
  391. sql = "SELECT rt_finish_stock_0630.date, rt_finish_stock_0630.cust, rt_finish_stock_0630.color, rt_finish_stock_0630.card,
  392. rt_finish_stock_0630.pattern, cast(rt_finish_stock_0630.sf as numeric(10,1)) as sf, rt_finish_stock_0630.comment, rt_finish_stock_0630.type,
  393. rt_finish_stock_0630.source, rt_finish_stock_0630.size, rt_finish_stock_0630.lot, rt_finish_stock_0630.wh,
  394. rt_finish_stock_0630.id, CASE WHEN rt_shaving_price.price IS NOT NULL
  395. THEN CAST(rt_shaving_price.price / 6 AS numeric(10, 2))
  396. WHEN lot LIKE '%12+%' THEN 4.8 WHEN lot LIKE '%8-12%' THEN 4.2 WHEN lot LIKE '%4-8%' THEN 3.6 END AS price,
  397. CASE WHEN type LIKE '%反毛%' AND color LIKE '%白%' THEN 1.7 + 0.2 WHEN type LIKE '%反毛%' AND
  398. color LIKE '%黑%' THEN 1.3 + 0.2 WHEN type LIKE '%反毛%' THEN 1.5 + 0.2 WHEN type LIKE N'%贴膜%' AND
  399. color LIKE '%白%' THEN 1.8 WHEN type LIKE N'%贴膜%' AND color LIKE '%黑%' THEN 1.5 else 1.8 END AS retan_cost,
  400. CASE WHEN type LIKE '%反毛%' THEN 1.4 WHEN type LIKE N'%贴膜%' THEN 0.3 END AS p_cost
  401. FROM rt_finish_stock_0630 LEFT OUTER JOIN
  402. rt_shaving_price ON rt_finish_stock_0630.lot = '516 ' + rt_shaving_price.source where rt_finish_stock_0630.id='" & dt_inprocess.Rows(x).Item("id") & "'"
  403. dt2 = New DataTable
  404. cmd.CommandText = sql
  405. da.SelectCommand = cmd
  406. da.Fill(dt2)
  407. Dim serial As Integer = 1
  408. For y = 0 To dt2.Rows.Count - 1
  409. xlSheet2.Cells(yy + 1 + y, 2) = "'" & serial '行号
  410. xlSheet2.Cells(yy + 1 + y, 3) = "'" & my_no & aa
  411. If dt2.Rows(y).Item("type") Like "*反毛*" Then
  412. xlSheet2.Cells(yy + 1 + y, 5) = "516.F.FM"
  413. xlSheet2.Cells(yy + 1 + y, 6) = "二层皮"
  414. Else
  415. xlSheet2.Cells(yy + 1 + y, 5) = "516.P.PU"
  416. xlSheet2.Cells(yy + 1 + y, 6) = "贴膜皮"
  417. End If
  418. If dt2.Rows(y).Item("wh") = "待发货" Then
  419. If dt2.Rows(y).Item("wh") = "反毛" Then
  420. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + dt2.Rows(y).Item("retan_cost") + dt2.Rows(y).Item("p_cost")
  421. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("sf") * xlSheet2.Cells(yy + 1 + y, 15).value
  422. xlSheet2.Cells(yy + 1 + y, 45) = dt2.Rows(y).Item("retan_cost")
  423. xlSheet2.Cells(yy + 1 + y, 46) = dt2.Rows(y).Item("p_cost")
  424. Else
  425. xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price") + dt2.Rows(y).Item("retan_cost") + dt2.Rows(y).Item("p_cost")
  426. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("sf") * xlSheet2.Cells(yy + 1 + y, 15).value
  427. xlSheet2.Cells(yy + 1 + y, 45) = dt2.Rows(y).Item("retan_cost")
  428. xlSheet2.Cells(yy + 1 + y, 46) = dt2.Rows(y).Item("p_cost")
  429. End If
  430. Else
  431. xlSheet2.Cells(yy + 1 + y, 15) = 4
  432. xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("sf") * 4
  433. End If
  434. xlSheet2.Cells(yy + 1 + y, 14) = dt2.Rows(y).Item("sf")
  435. xlSheet2.Cells(yy + 1 + y, 17) = dt2.Rows(y).Item("lot")
  436. xlSheet2.Cells(yy + 1 + y, 18) = "2024/6/30成品盘点 " & dt2.Rows(y).Item("wh")
  437. xlSheet2.Cells(yy + 1 + y, 25) = "'516-R"
  438. xlSheet2.Cells(yy + 1 + y, 26) = "待售成品仓/赤湖"
  439. xlSheet2.Cells(yy + 1 + y, 38) = "'" & dt2.Rows(y).Item("cust")
  440. xlSheet2.Cells(yy + 1 + y, 40) = "'" & dt2.Rows(y).Item("wh")
  441. ' xlSheet2.Cells(yy + 1 + y, 40) = dt2.Rows(y).Item("tech")
  442. ' xlSheet2.Cells(yy + 1 + y, 41) = dt2.Rows(y).Item("")
  443. xlSheet2.Cells(yy + 1 + y, 42) = dt2.Rows(y).Item("color")
  444. xlSheet2.Cells(yy + 1 + y, 43) = dt2.Rows(y).Item("size")
  445. xlSheet2.Cells(yy + 1 + y, 44) = dt2.Rows(y).Item("card")
  446. 'xlSheet2.Cells(yy + 1 + y, 47) = dt2.Rows(y).Item("weight_ini")
  447. 'xlSheet2.Cells(yy + 1 + y, 48) = dt2.Rows(y).Item("type")
  448. xlSheet2.Cells(yy + 1 + y, 49) = dt2.Rows(y).Item("pattern")
  449. xlSheet2.Cells(yy + 1 + y, 50) = dt2.Rows(y).Item("type")
  450. serial = serial + 1
  451. Next
  452. yy = yy + dt2.Rows.Count
  453. aa = aa + 1
  454. my_x = my_x + 1
  455. my_card = dt_inprocess.Rows(x).Item("card")
  456. my_date = dt_inprocess.Rows(x).Item("date")
  457. Next
  458. xlSheet2.Range("A2:A" & x + 1).FillDown()
  459. 'xlSheet2.Range("B2:B" & x + 1).FillDown()
  460. xlSheet2.Range("D2:D" & x + 1).FillDown()
  461. xlSheet2.Range("J2:J" & x + 1).FillDown()
  462. xlSheet2.Range("L2:L" & x + 1).FillDown()
  463. xlSheet2.Range("M2:M" & x + 1).FillDown()
  464. 'xlSheet2.Range("O2:O" & x + 1).FillDown()
  465. 'xlSheet2.Range("P2:P" & x + 1).FillDown()
  466. MsgBox("")
  467. End Sub
  468. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  469. Dim dt As New DataTable
  470. Dim file_name As String = ""
  471. Dim a As Integer = 0
  472. Dim my_count As Integer = 0
  473. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  474. file_name = OpenFileDialog1.FileName
  475. Else
  476. Exit Sub
  477. End If
  478. ' Dim filepath As String = Me.Button28.Text
  479. Dim sourceFileName As String = file_name
  480. Dim address2 As String = "ftp://" & my_ip & ":7788/K3/打尺入库/" & OpenFileDialog1.SafeFileName
  481. Dim address3() As String
  482. address3 = Split(address2, "ftp://" & my_ip & ":7788/")
  483. Dim add4 As String
  484. add4 = "d:\k3\" & address3(1)
  485. add4 = "d:\k3\打尺入库\" & OpenFileDialog1.SafeFileName
  486. Dim userName As String = "matchy3c"
  487. Dim password As String = "Lafayette11"
  488. Dim showUI As Boolean = True
  489. Dim connectionTimeout As Integer = 500
  490. Dim client As WebClient = New WebClient
  491. client.Credentials = New NetworkCredential(userName, password)
  492. client.Proxy = GlobalProxySelection.GetEmptyWebProxy()
  493. client.UploadFile(address2, sourceFileName)
  494. sql = "delete from RT_tm_measure_in where year(date)=" & Year(dtp1.Value) & " and month(date)=" & Month(dtp1.Value) & "" '----
  495. cmd.CommandText = sql
  496. cmd.ExecuteNonQuery()
  497. sql = "Select * FROM OPENDATASOURCE ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=Yes;IMEX=1;Database=" & add4 & "')... [产品入库序时簿$]"
  498. cmd.CommandText = sql
  499. da.SelectCommand = cmd
  500. da.Fill(dt)
  501. dgv1.DataSource = dt
  502. Dim my_sqlbulk As New SqlBulkCopy(conn)
  503. my_sqlbulk.DestinationTableName = "dbo.RT_tm_measure_in"
  504. my_sqlbulk.WriteToServer(dt)
  505. MsgBox("导入完成!")
  506. End Sub
  507. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click '打尺入库
  508. Dim aa As String
  509. Dim my_card As String = ""
  510. Dim my_date As Date
  511. aa = TextBox8.Text
  512. If aa = "" Then
  513. MsgBox("请输入起始单号")
  514. Exit Sub
  515. End If
  516. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  517. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  518. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  519. Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
  520. Dim file_name As String = ""
  521. Dim file_name1 As String = ""
  522. Dim my_weight As Double = 0
  523. Dim a As Integer = 0
  524. Dim my_count As Integer = 0
  525. Dim my_x As Integer = 0
  526. xlApp = CreateObject("Excel.Application")
  527. xlApp.Visible = True
  528. xlApp.DisplayAlerts = False
  529. xlBook = xlApp.Workbooks.Open("D:\K3\k3表格模板\下鼓染色入库.xls",, True)
  530. xlBook.Activate()
  531. Dim dt2 As New DataTable
  532. For i = 1 To xlApp.Worksheets.Count
  533. If xlApp.Workbooks(1).Worksheets(i).name = "Page1" Then
  534. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  535. xlSheet.Activate()
  536. Exit For
  537. End If
  538. Next
  539. Dim my_no As String = "CPRK"
  540. Dim yy As Integer = 1
  541. Dim x As Integer = 0
  542. Dim dt_inprocess As New DataTable
  543. sql = "SELECT date, dep, no, wh, code, codename, spec, qty, price, amount, lot, comment, card, cust, spec1, color, pattern, order_sf,measure,
  544. CASE WHEN codename = N'杂皮贴膜 二层' AND (cust LIKE '%086%' OR
  545. cust LIKE '%088%') THEN N'516 贴膜 8-12' WHEN codename = N'杂皮贴膜 二层' AND (cust LIKE '%好兄弟%')
  546. THEN N'516 贴膜 12+' WHEN codename = N'杂皮贴膜 二层' AND (cust LIKE '%JX%')
  547. THEN N'516 贴膜 4-8' WHEN codename = N'杂皮贴膜 二层' THEN N'516 贴膜 8-12' WHEN codename <> N'杂皮贴膜 二层' THEN
  548. '516 ' + codename END AS name, id FROM RT_TM_measure_in where date between '2024/7/27' and '2024/7/31' ORDER BY measure "
  549. cmd.CommandText = sql
  550. da.SelectCommand = cmd
  551. da.Fill(dt_inprocess)
  552. For x = 0 To dt_inprocess.Rows.Count - 1 '-----------loop
  553. xlSheet.Cells(my_x + 2, 1) = dt_inprocess.Rows(x).Item("date")
  554. xlSheet.Cells(my_x + 2, 2) = dt_inprocess.Rows(x).Item("date")
  555. xlSheet.Cells(my_x + 2, 3) = "'曾添梅"
  556. xlSheet.Cells(my_x + 2, 4) = "'" & my_no & aa
  557. xlSheet.Cells(my_x + 2, 5) = "'zhang"
  558. xlSheet.Cells(my_x + 2, 6) = "'1"
  559. xlSheet.Cells(my_x + 2, 7) = "'2"
  560. xlSheet.Cells(my_x + 2, 8) = "'165701"
  561. xlSheet.Cells(my_x + 2, 9) = "'655P-R"
  562. xlSheet.Cells(my_x + 2, 10) = "'修剪、成检、量尺、包装-R"
  563. xlSheet.Cells(my_x + 2, 11) = "'120"
  564. xlSheet.Cells(my_x + 2, 12) = "'吴小男"
  565. xlSheet.Cells(my_x + 2, 13) = "'120"
  566. xlSheet.Cells(my_x + 2, 14) = "'吴小男"
  567. xlSheet.Cells(my_x + 2, 15) = "'85"
  568. For i = 1 To xlApp.Worksheets.Count
  569. If xlApp.Workbooks(1).Worksheets(i).name = "Page2" Then
  570. xlSheet2 = xlApp.Workbooks(1).Worksheets(i)
  571. xlSheet2.Activate()
  572. Exit For
  573. End If
  574. Next
  575. sql = "SELECT date, dep, no, wh, code, codename, spec, qty, price, amount, lot, comment, card, cust, spec1, color, pattern, order_sf,
  576. CASE WHEN codename like N'%贴膜%' AND (cust LIKE '%086%' OR
  577. cust LIKE '%088%') THEN N'516 贴膜 8-12' WHEN codename like N'%贴膜%' AND (cust LIKE '%好兄弟%')
  578. THEN N'516 贴膜 12+' WHEN codename like N'%贴膜%' AND (cust LIKE '%JX%')
  579. THEN N'516 贴膜 4-8' WHEN codename like N'%贴膜%' THEN N'516 贴膜 8-12' WHEN not(codename like N'%贴膜%') THEN
  580. '516 ' + codename END AS name, id
  581. FROM RT_TM_measure_in where measure='" & dt_inprocess.Rows(x).Item("measure") & "'"
  582. dt2 = New DataTable
  583. cmd.CommandText = sql
  584. da.SelectCommand = cmd
  585. da.Fill(dt2)
  586. Dim serial As Integer = 1
  587. For y = 0 To dt2.Rows.Count - 1
  588. xlSheet2.Cells(yy + 1 + y, 2) = "'" & serial '行号
  589. xlSheet2.Cells(yy + 1 + y, 3) = "'" & my_no & aa
  590. If dt2.Rows(y).Item("name") Like "*贴膜*" Then
  591. xlSheet2.Cells(yy + 1 + y, 5) = "516.P.PU"
  592. xlSheet2.Cells(yy + 1 + y, 6) = "贴膜皮"
  593. Else
  594. xlSheet2.Cells(yy + 1 + y, 5) = "516.F.FM"
  595. xlSheet2.Cells(yy + 1 + y, 6) = "二层皮"
  596. End If
  597. xlSheet2.Cells(yy + 1 + y, 14) = dt2.Rows(y).Item("qty")
  598. ' xlSheet2.Cells(yy + 1 + y, 15) = dt2.Rows(y).Item("price")
  599. 'xlSheet2.Cells(yy + 1 + y, 16) = dt2.Rows(y).Item("sf") * dt2.Rows(y).Item("price")
  600. xlSheet2.Cells(yy + 1 + y, 17) = dt2.Rows(y).Item("name")
  601. xlSheet2.Cells(yy + 1 + y, 18) = "打尺入库 " & dt2.Rows(y).Item("wh")
  602. xlSheet2.Cells(yy + 1 + y, 25) = "'516-R"
  603. xlSheet2.Cells(yy + 1 + y, 26) = "待售成品仓/赤湖"
  604. xlSheet2.Cells(yy + 1 + y, 38) = "'" & dt2.Rows(y).Item("cust")
  605. xlSheet2.Cells(yy + 1 + y, 39) = "'" & dt2.Rows(y).Item("comment")
  606. ' xlSheet2.Cells(yy + 1 + y, 40) = dt2.Rows(y).Item("tech")
  607. ' xlSheet2.Cells(yy + 1 + y, 41) = dt2.Rows(y).Item("")
  608. xlSheet2.Cells(yy + 1 + y, 42) = dt2.Rows(y).Item("color")
  609. ' xlSheet2.Cells(yy + 1 + y, 43) = dt2.Rows(y).Item("size")
  610. xlSheet2.Cells(yy + 1 + y, 44) = dt2.Rows(y).Item("card")
  611. ' xlSheet2.Cells(yy + 1 + y, 45) = dt2.Rows(y).Item("retan_cost")
  612. ' xlSheet2.Cells(yy + 1 + y, 46) = dt2.Rows(y).Item("p_cost")
  613. 'xlSheet2.Cells(yy + 1 + y, 47) = dt2.Rows(y).Item("weight_ini")
  614. 'xlSheet2.Cells(yy + 1 + y, 48) = dt2.Rows(y).Item("type")
  615. 'xlSheet2.Cells(yy + 1 + y, 49) = dt2.Rows(y).Item("pattern")
  616. ' xlSheet2.Cells(yy + 1 + y, 50) = dt2.Rows(y).Item("type")
  617. serial = serial + 1
  618. Next
  619. yy = yy + dt2.Rows.Count
  620. aa = aa + 1
  621. my_x = my_x + 1
  622. ' my_card = dt_inprocess.Rows(x).Item("card")
  623. ' my_date = dt_inprocess.Rows(x).Item("date")
  624. Next
  625. xlSheet2.Range("A2:A" & x + 1).FillDown()
  626. 'xlSheet2.Range("B2:B" & x + 1).FillDown()
  627. xlSheet2.Range("D2:D" & x + 1).FillDown()
  628. xlSheet2.Range("J2:J" & x + 1).FillDown()
  629. xlSheet2.Range("L2:L" & x + 1).FillDown()
  630. xlSheet2.Range("M2:M" & x + 1).FillDown()
  631. 'xlSheet2.Range("O2:O" & x + 1).FillDown()
  632. 'xlSheet2.Range("P2:P" & x + 1).FillDown()
  633. MsgBox("")
  634. End Sub
  635. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  636. End Sub
  637. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click '516调账
  638. Dim aa As String
  639. Dim my_card As String = ""
  640. Dim my_date As Date
  641. aa = TextBox8.Text
  642. If aa = "" Then
  643. MsgBox("请输入起始单号")
  644. Exit Sub
  645. End If
  646. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  647. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  648. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  649. Dim xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet
  650. Dim file_name As String = ""
  651. Dim file_name1 As String = ""
  652. Dim my_weight As Double = 0
  653. Dim a As Integer = 0
  654. Dim my_count As Integer = 0
  655. Dim my_x As Integer = 0
  656. xlApp = CreateObject("Excel.Application")
  657. xlApp.Visible = True
  658. xlApp.DisplayAlerts = False
  659. xlBook = xlApp.Workbooks.Open("D:\K3\k3表格模板\下鼓染色入库.xls",, True)
  660. xlBook.Activate()
  661. Dim dt2 As New DataTable
  662. For i = 1 To xlApp.Worksheets.Count
  663. If xlApp.Workbooks(1).Worksheets(i).name = "Page1" Then
  664. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  665. xlSheet.Activate()
  666. Exit For
  667. End If
  668. Next
  669. Dim my_no As String = "CPRK"
  670. Dim yy As Integer = 1
  671. Dim x As Integer = 0
  672. Dim dt_inprocess As New DataTable
  673. sql = "select * from rt_516_old_bal "
  674. cmd.CommandText = sql
  675. da.SelectCommand = cmd
  676. da.Fill(dt_inprocess)
  677. For x = 0 To dt_inprocess.Rows.Count - 1 '-----------loop
  678. xlSheet.Cells(my_x + 2, 1) = "2024/06/30"
  679. xlSheet.Cells(my_x + 2, 2) = "2024/06/30"
  680. xlSheet.Cells(my_x + 2, 3) = "'吴小男"
  681. xlSheet.Cells(my_x + 2, 4) = "'" & my_no & aa
  682. xlSheet.Cells(my_x + 2, 5) = "'zhang"
  683. If dt_inprocess.Rows(x).Item("qty") > 0 Then
  684. xlSheet.Cells(my_x + 2, 6) = "'-1"
  685. Else
  686. xlSheet.Cells(my_x + 2, 6) = "'1"
  687. End If
  688. xlSheet.Cells(my_x + 2, 7) = "'2"
  689. xlSheet.Cells(my_x + 2, 8) = "'165701"
  690. xlSheet.Cells(my_x + 2, 9) = "'655P-R"
  691. xlSheet.Cells(my_x + 2, 10) = "'修剪、成检、量尺、包装-R"
  692. xlSheet.Cells(my_x + 2, 11) = "'120"
  693. xlSheet.Cells(my_x + 2, 12) = "'吴小男"
  694. xlSheet.Cells(my_x + 2, 13) = "'120"
  695. xlSheet.Cells(my_x + 2, 14) = "'吴小男"
  696. xlSheet.Cells(my_x + 2, 15) = "'85"
  697. For i = 1 To xlApp.Worksheets.Count
  698. If xlApp.Workbooks(1).Worksheets(i).name = "Page2" Then
  699. xlSheet2 = xlApp.Workbooks(1).Worksheets(i)
  700. xlSheet2.Activate()
  701. Exit For
  702. End If
  703. Next
  704. sql = "select code,codename,lot,wh,whname,cast(qty as numeric(10,2)) as qty,qty1 from rt_516_old_bal where id='" & dt_inprocess.Rows(x).Item("id") & "'"
  705. dt2 = New DataTable
  706. cmd.CommandText = sql
  707. da.SelectCommand = cmd
  708. da.Fill(dt2)
  709. Dim serial As Integer = 1
  710. For y = 0 To dt2.Rows.Count - 1
  711. xlSheet2.Cells(yy + 1 + y, 2) = "'" & serial '行号
  712. xlSheet2.Cells(yy + 1 + y, 3) = "'" & my_no & aa
  713. xlSheet2.Cells(yy + 1 + y, 5) = dt2.Rows(y).Item("code")
  714. xlSheet2.Cells(yy + 1 + y, 6) = dt2.Rows(y).Item("codename")
  715. xlSheet2.Cells(yy + 1 + y, 14) = -dt2.Rows(y).Item("qty")
  716. xlSheet2.Cells(yy + 1 + y, 17) = "'" & dt2.Rows(y).Item("lot")
  717. xlSheet2.Cells(yy + 1 + y, 18) = "'2024/6/30 新编码调账"
  718. xlSheet2.Cells(yy + 1 + y, 25) = "'516-R"
  719. xlSheet2.Cells(yy + 1 + y, 26) = "待售成品仓/赤湖"
  720. 'xlSheet2.Cells(yy + 1 + y, 38) = "'" & dt2.Rows(y).Item("cust")
  721. 'xlSheet2.Cells(yy + 1 + y, 39) = "'" & dt2.Rows(y).Item("comment")
  722. ' xlSheet2.Cells(yy + 1 + y, 40) = dt2.Rows(y).Item("tech")
  723. ' xlSheet2.Cells(yy + 1 + y, 41) = dt2.Rows(y).Item("")
  724. 'xlSheet2.Cells(yy + 1 + y, 42) = dt2.Rows(y).Item("color")
  725. ' xlSheet2.Cells(yy + 1 + y, 43) = dt2.Rows(y).Item("size")
  726. 'xlSheet2.Cells(yy + 1 + y, 44) = dt2.Rows(y).Item("card")
  727. ' xlSheet2.Cells(yy + 1 + y, 45) = dt2.Rows(y).Item("retan_cost")
  728. ' xlSheet2.Cells(yy + 1 + y, 46) = dt2.Rows(y).Item("p_cost")
  729. 'xlSheet2.Cells(yy + 1 + y, 47) = dt2.Rows(y).Item("weight_ini")
  730. 'xlSheet2.Cells(yy + 1 + y, 48) = dt2.Rows(y).Item("type")
  731. 'xlSheet2.Cells(yy + 1 + y, 49) = dt2.Rows(y).Item("pattern")
  732. ' xlSheet2.Cells(yy + 1 + y, 50) = dt2.Rows(y).Item("type")
  733. serial = serial + 1
  734. Next
  735. yy = yy + dt2.Rows.Count
  736. aa = aa + 1
  737. my_x = my_x + 1
  738. ' my_card = dt_inprocess.Rows(x).Item("card")
  739. ' my_date = dt_inprocess.Rows(x).Item("date")
  740. Next
  741. xlSheet2.Range("A2:A" & x + 1).FillDown()
  742. 'xlSheet2.Range("B2:B" & x + 1).FillDown()
  743. xlSheet2.Range("D2:D" & x + 1).FillDown()
  744. xlSheet2.Range("J2:J" & x + 1).FillDown()
  745. xlSheet2.Range("L2:L" & x + 1).FillDown()
  746. xlSheet2.Range("M2:M" & x + 1).FillDown()
  747. 'xlSheet2.Range("O2:O" & x + 1).FillDown()
  748. 'xlSheet2.Range("P2:P" & x + 1).FillDown()
  749. MsgBox("")
  750. End Sub
  751. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  752. dt = New DataTable
  753. sql = "SELECT t3 as 皮源,cast(sum(sf) as numeric(10,1)) as 尺数 FROM Rt_measure_daily WHERE (date BETWEEN '2024/7/1' AND '2024/7/31') group by t3"
  754. cmd.CommandText = sql
  755. da.Fill(dt)
  756. DGV1.DataSource = dt
  757. End Sub
  758. End Class