Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Frm_00_Retan_rcp.vb 115KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. Imports NPOI.XSSF.UserModel
  2. Imports NPOI.SS.UserModel
  3. Imports System.IO
  4. Imports System.Data.SqlClient
  5. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  6. Imports Microsoft.Office.Interop.Excel.Constants
  7. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  8. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  9. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  10. Imports Microsoft.Office.Interop.Excel.XlPrintLocation
  11. Imports Microsoft.Office.Interop.Excel.XlPageOrientation
  12. Imports Microsoft.Office.Interop.Excel.XlOrder
  13. Imports Microsoft.Office.Interop.Excel.XlPrintErrors
  14. Imports Microsoft.Office.Core
  15. Imports System.ComponentModel
  16. Imports Microsoft.Office.Interop
  17. Imports System.Drawing.Imaging
  18. Imports System.Windows.Media.Media3D
  19. Imports System.Text.RegularExpressions
  20. Public Class Frm_00_Retan_rcp
  21. Private originalLocation As Point ' 声明全局变量来存储原始位置和大小
  22. Private originalSize As Size
  23. Private isMaximized As Boolean = False ' 用于标记当前是否是放大状态
  24. Dim dt1 As New DataTable
  25. Dim gWeight(), gPrice() As Double
  26. Dim gCoin(), sql_rcp, sql_print As String
  27. Dim rr As String = "" : Dim rcp_name As String = ""
  28. Dim gAddfromOther As Boolean = False
  29. Dim dt_print As DataTable
  30. Dim DT2 As New DataTable
  31. Dim colorArray(10) As Color
  32. Dim card As String = "" : Dim cust As String = "" : Dim thickness As String = "" : Dim r_type As String = ""
  33. Dim source As String = "" : Dim comment As String = "" : Dim color1 As String = ""
  34. Dim wb_weight As Double = 0
  35. Private Sub Set_清單1(queryname As String)
  36. Dim ds1 As New DataSet
  37. 處方清單_dgv.DataSource = Nothing : ds1.Clear()
  38. 處方清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  39. 處方清單_dgv.ColumnHeadersHeight = 30 : 處方清單_dgv.AllowUserToAddRows = False : 處方清單_dgv.RowTemplate.Height = 20
  40. 處方清單_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
  41. SQL_染色處方清單(queryname)
  42. da.Fill(ds1) : 處方清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
  43. 處方清單_dgv.Columns(0).FillWeight = 80 : 處方清單_dgv.Columns(1).FillWeight = 280 : 處方清單_dgv.Columns(2).FillWeight = 120
  44. 處方清單_dgv.Columns(3).FillWeight = 55 : 處方清單_dgv.Columns(4).FillWeight = 105 : 處方清單_dgv.Columns(5).FillWeight = 55
  45. 處方清單_dgv.Columns(6).FillWeight = 75 : 處方清單_dgv.Columns(7).FillWeight = 55 : 處方清單_dgv.Columns(8).FillWeight = 145
  46. For i As Integer = 0 To 處方清單_dgv.Columns.Count - 1 : 處方清單_dgv.Columns(i).ReadOnly = True : Next
  47. Dim selectedRowIndex As Integer = 處方清單_dgv.CurrentRow?.Index
  48. Dim selectedColumnIndex As Integer = 處方清單_dgv.CurrentCell?.ColumnIndex ' 保存当前选中的行和列
  49. If selectedRowIndex >= 0 AndAlso selectedRowIndex < 處方清單_dgv.Rows.Count Then ' 如果之前有选中行,刷新后重新选中
  50. 處方清單_dgv.CurrentCell = 處方清單_dgv.Rows(selectedRowIndex).Cells(selectedColumnIndex)
  51. Else : 處方清單_dgv.CurrentCell = 處方清單_dgv.Rows(0).Cells(0) : End If
  52. '--------指定顏色--------------------------------------------------------------
  53. If 處方清單_dgv.Rows.Count < 2 Then Exit Sub ' 若資料筆數過少則不執行
  54. Dim p(處方清單_dgv.Rows.Count - 1) As Integer : Dim c As Integer = 0 : p(0) = 0
  55. For x = 1 To 處方清單_dgv.Rows.Count - 1 ' 修正範圍,避免 -2 的問題
  56. If Not 處方清單_dgv.Rows(x).Cells(0).Value Is Nothing AndAlso Not 處方清單_dgv.Rows(x - 1).Cells(0).Value Is Nothing AndAlso
  57. 處方清單_dgv.Rows(x).Cells(0).Value.ToString <> 處方清單_dgv.Rows(x - 1).Cells(0).Value.ToString Then : c += 1 : p(c) = x
  58. End If
  59. Next : c += 1 : p(c) = 處方清單_dgv.Rows.Count : ReDim Preserve p(c) ' 確保最後一組範圍正確
  60. If c = 1 Then : For z As Integer = 0 To 處方清單_dgv.Rows.Count - 1 : 處方清單_dgv.Rows(z).DefaultCellStyle.BackColor = colorArray(1) : Next : Else
  61. For cc As Integer = 0 To c - 1 ' 修正範圍
  62. Dim startIdx As Integer = p(cc) : Dim endIdx As Integer = If(cc + 1 < c, p(cc + 1) - 1, 處方清單_dgv.Rows.Count - 1)
  63. For z As Integer = startIdx To endIdx : 處方清單_dgv.Rows(z).DefaultCellStyle.BackColor = colorArray(cc Mod 5) : Next
  64. Next
  65. End If
  66. 建立日期_lb.Text = "" : 片数_lb.Text = "" : 选级_lb.Text = "" : 流程卡号_lb.Text = "" : 重量_lb.Text = "" : 平均_lb.Text = ""
  67. End Sub
  68. Private Sub Frm_00HF_Retan_Rcp_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  69. Me.MdiParent = FrmMDI : Me.WindowState = 2 : Me.AutoScroll = True
  70. FrmMDI.WindowState = FormWindowState.Maximized : Panel1.SendToBack()
  71. dgv2.CausesValidation = False : Button17.Visible = False
  72. 建立日期_lb.Text = "" : 片数_lb.Text = "" : 选级_lb.Text = ""
  73. 流程卡号_lb.Text = "" : 重量_lb.Text = "" : 平均_lb.Text = ""
  74. colorArray(0) = Color.FromName("Aquamarine") : colorArray(1) = Color.FromName("azure") : colorArray(2) = Color.FromName("beige")
  75. colorArray(3) = Color.FromName("gainsboro") : colorArray(4) = Color.FromName("LightBlue") : colorArray(5) = Color.FromName("LightSalmon")
  76. End Sub
  77. Private Sub Frm_00HF_Retan_Rcp_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
  78. Application.DoEvents()
  79. SQL_HT_RetanRcp時間整理() : Set_清單1("")
  80. isMaximized = True : originalLocation = 處方_dgv.Location : originalSize = 處方_dgv.Size
  81. End Sub
  82. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  83. If 模式通知_lb.Visible = True Then : 模式通知_lb.Visible = False : Else : 模式通知_lb.Visible = True : End If
  84. End Sub
  85. Private Sub 處方清單_sgv_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles 處方清單_dgv.CellMouseUp
  86. 模式通知_lb.ForeColor = Color.Red : Timer1.Enabled = False
  87. 單寧_tb.Text = "" : 烤膠_bt.Text = "" : 油脂_tb.Text = "" : 染料_tb.Text = "" : 助劑_tb.Text = "" : 丙烯酸_tb.Text = "" : 复鞣剂_tb.Text = ""
  88. Dim 位置 As Integer = 處方清單_dgv.CurrentRow.Index
  89. 品名_lb.Text = 處方清單_dgv.Rows(位置).Cells("品名").Value.ToString : 開削_lb.Text = "开削" & 處方清單_dgv.Rows(位置).Cells("开削").Value.ToString
  90. 片数_lb.Text = 處方清單_dgv.Rows(位置).Cells("片数").Value.ToString & " P" : 选级_lb.Text = 處方清單_dgv.Rows(位置).Cells("选级").Value.ToString
  91. 重量_lb.Text = 處方清單_dgv.Rows(位置).Cells("重量").Value.ToString & " KG" : 平均_lb.Text = 處方清單_dgv.Rows(位置).Cells("平均").Value.ToString & " KG"
  92. 建立日期_lb.Text = Strings.Format(處方清單_dgv.Rows(位置).Cells("日期").Value, "yyyy-DD-mm")
  93. 流程卡号_lb.Text = 處方清單_dgv.Rows(位置).Cells("流程卡号").Value.ToString
  94. Set_處方明細()
  95. End Sub
  96. Private Sub Set_處方明細()
  97. Dim ds1 As New DataSet
  98. 處方_dgv.DataSource = Nothing : ds1.Clear()
  99. 處方_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  100. 處方_dgv.ColumnHeadersHeight = 30 : 處方_dgv.AllowUserToAddRows = False : 處方_dgv.RowTemplate.Height = 25
  101. 處方_dgv.SelectionMode = DataGridViewSelectionMode.CellSelect
  102. SQL_染色處方(處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value,
  103. 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("表格编号").Value)
  104. da.Fill(ds1) : 處方_dgv.DataSource = ds1.Tables(0) : conn.Close()
  105. For i As Integer = 0 To 處方_dgv.Columns.Count - 1 : 處方_dgv.Columns(i).ReadOnly = True : Next
  106. For I As Integer = 0 To 處方_dgv.Rows.Count - 1
  107. 處方_dgv.Rows(I).Cells("標記1").Value = "" : 處方_dgv.Rows(I).Cells("標記2").Value = "" : 處方_dgv.Rows(I).Cells("標記3").Value = ""
  108. 處方_dgv.Rows(I).Cells("標記4").Value = "" : 處方_dgv.Rows(I).Cells("標記5").Value = ""
  109. Next
  110. set_grid1() : cal_cost1()
  111. 處方_dgv.Columns("用量").DefaultCellStyle.Format = "#,##0.00"
  112. 處方_dgv.Columns("用量").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 計算(25.4)
  113. End Sub
  114. Private Sub 化工分类_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 化工分类_ch.Click
  115. If 化工分类_ch.Checked = False Then : 化工分类_ch.Checked = False : Else : 化工分类_ch.Checked = True : End If : set_grid1()
  116. End Sub
  117. Private Sub 系统代码_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 系统代码_ch.Click
  118. If 系统代码_ch.Checked = False Then : 系统代码_ch.Checked = False : Else : 系统代码_ch.Checked = True : End If : set_grid1()
  119. End Sub
  120. Private Sub 类别_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 类别_ch.Click
  121. If 类别_ch.Checked = False Then : 类别_ch.Checked = False : Else : 类别_ch.Checked = True : End If : set_grid1()
  122. End Sub
  123. Private Sub 进货单价_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 进货单价_ch.Click
  124. If 进货单价_ch.Checked = False Then : 进货单价_ch.Checked = False : Else : 进货单价_ch.Checked = True : End If : set_grid1()
  125. End Sub
  126. Private Sub zdhc_code_ch_CheckedChanged(sender As Object, e As EventArgs) Handles zdhc_code_ch.Click
  127. If zdhc_code_ch.Checked = False Then : zdhc_code_ch.Checked = False : Else : zdhc_code_ch.Checked = True : End If : set_grid1()
  128. End Sub
  129. Private Sub 系统分类_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 系统分类_ch.Click
  130. If 系统分类_ch.Checked = False Then : 系统分类_ch.Checked = False : Else : 系统分类_ch.Checked = True : End If : set_grid1()
  131. End Sub
  132. Private Sub 系统品名_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 系统品名_ch.Click
  133. If 系统品名_ch.Checked = False Then : 系统品名_ch.Checked = False : Else : 系统品名_ch.Checked = True : End If : set_grid1()
  134. End Sub
  135. Private Sub set_grid1()
  136. 處方_dgv.Columns(0).FillWeight = 80 : 處方_dgv.Columns(1).FillWeight = 200 : 處方_dgv.Columns(2).FillWeight = 120
  137. 處方_dgv.Columns(3).FillWeight = 80 : 處方_dgv.Columns(4).FillWeight = 80 : 處方_dgv.Columns(5).FillWeight = 80
  138. 處方_dgv.Columns(6).FillWeight = 200 : 處方_dgv.Columns("系统品名").FillWeight = 300
  139. 處方_dgv.Columns("系统代码").FillWeight = 100 : For x As Integer = 7 To 16 : 處方_dgv.Columns(x).Visible = False : Next
  140. 處方_dgv.Columns("化工分类").Visible = 化工分类_ch.Checked : 處方_dgv.Columns("类别").Visible = 类别_ch.Checked
  141. 處方_dgv.Columns("zdhc_code").Visible = zdhc_code_ch.Checked : 處方_dgv.Columns("系统品名").Visible = 系统品名_ch.Checked
  142. 處方_dgv.Columns("系统代码").Visible = 系统代码_ch.Checked : 處方_dgv.Columns("进货单价").Visible = 进货单价_ch.Checked
  143. 處方_dgv.Columns("系统分类").Visible = 系统分类_ch.Checked
  144. 處方_dgv.Columns("標記1").Visible = False : 處方_dgv.Columns("標記2").Visible = False : 處方_dgv.Columns("標記3").Visible = False
  145. 處方_dgv.Columns("標記4").Visible = False : 處方_dgv.Columns("標記5").Visible = False
  146. End Sub
  147. Private Sub cal_cost1()
  148. Dim selectedRowIndex As Integer = 處方清單_dgv.CurrentCell.RowIndex ' 获取 DataGridView1 中当前选中行的索引
  149. Dim weight As Double = Convert.ToDouble(處方清單_dgv.Rows(selectedRowIndex).Cells("重量").Value) ' 获取 DataGridView1 中选中行的 "重量"
  150. If Not 處方_dgv.DataSource Is Nothing Then ' 在 DataGridView2 的 DataTable 中添加一列用于存储“金额小计”
  151. Dim dt2 As DataTable = CType(處方_dgv.DataSource, DataTable)
  152. If Not dt2.Columns.Contains("用量") Then : dt2.Columns.Add("用量", GetType(Double)) : End If ' 检查是否已添加过金额小计列
  153. For Each row As DataRow In dt2.Rows ' 遍历 DataGridView2 中的每一行,计算金额小计
  154. Dim percentage As Double = Convert.ToDouble(row("百分比")) ' 获取 DataGridView2 中的百分比和进货单价
  155. Dim purchasePrice As Double = 0
  156. If Not IsDBNull(row("进货单价")) Then : purchasePrice = Convert.ToDouble(row("进货单价")) : End If ' 检查进货单价是否为 DBNull
  157. If purchasePrice > 0 Then ' 如果进货单价有效,计算金额小计
  158. Dim amount As Double = weight * purchasePrice * percentage / 100 : row("用量") = amount ' 将金额小计添加到该行
  159. Else : row("用量") = 0 : End If ' 如果进货单价无效,则设置金额小计为 0
  160. Next
  161. End If
  162. Dim groupedData = From row In 處方_dgv.Rows.Cast(Of DataGridViewRow)() ' 使用 LINQ 进行 Group By 操作,并按化工分类汇总百分比和金额小计
  163. Group row By category = row.Cells("系统分类").Value.ToString() Into Group
  164. Select category, TotalPercentage1 = Group.Sum(Function(r) Convert.ToDouble(r.Cells("百分比").Value)),
  165. TotalAmount1 = Group.Sum(Function(r) Convert.ToDouble(r.Cells("用量").Value))
  166. groupedData = groupedData.OrderBy(Function(item) item.category).ToList()
  167. Dim newDataTable As New DataTable() ' 创建一个新的 DataTable 来存储汇总结果
  168. newDataTable.Columns.Add("分类", GetType(String)) ' 分类
  169. newDataTable.Columns.Add("百分比", GetType(Double)) ' 汇总的百分比
  170. newDataTable.Columns.Add("小计", GetType(Double)) ' 汇总的金额小计
  171. For Each item In groupedData ' 将汇总数据添加到 DataTable
  172. Dim newRow As DataRow = newDataTable.NewRow() : newRow("分类") = item.category
  173. newRow("百分比") = Math.Round(item.TotalPercentage1, 1) : newRow("小计") = Math.Floor(item.TotalAmount1) ' 保留整数 ' 保留1位小数
  174. newDataTable.Rows.Add(newRow)
  175. Next
  176. Dim totalPercentage As Double = groupedData.Where(Function(g) g.category <> "").Sum(Function(g) g.TotalPercentage1) ' 计算总百分比和总金额,排除 "水" 分类
  177. Dim totalAmount As Double = groupedData.Where(Function(g) g.category <> "").Sum(Function(g) g.TotalAmount1)
  178. Dim totalRow As DataRow = newDataTable.NewRow() ' 添加总汇总行
  179. totalRow("分类") = "Total"
  180. totalRow("百分比") = Math.Round(totalPercentage, 1) ' 保留1位小数
  181. totalRow("小计") = Math.Floor(totalAmount) : newDataTable.Rows.Add(totalRow) ' 保留整数
  182. 合計_dgv.DataSource = newDataTable : 合計_dgv.ReadOnly = True ' 将结果绑定到 DataGridView3
  183. 合計_dgv.Columns("小计").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 合計_dgv.Columns("小计").DefaultCellStyle.Format = "N0"
  184. 合計_dgv.Columns("百分比").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 合計_dgv.Columns("百分比").DefaultCellStyle.Format = "N1"
  185. 合計_dgv.Columns("分类").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  186. Dim 最後 As Integer = 合計_dgv.Rows.Count - 2 : 合計_dgv.Rows(最後).DefaultCellStyle.ForeColor = Color.Red ' 设置最后一行的字体颜色为红色
  187. End Sub
  188. Private Sub 處方_dgv_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles 處方_dgv.RowPostPaint
  189. If e.RowIndex + 1 > 處方_dgv.Rows.Count - 1 Then Exit Sub
  190. If 處方_dgv.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "PF" Then : Dim aa As String : aa = "" : End If
  191. If 處方_dgv.Rows(e.RowIndex + 1).Cells("化料名称").Value Is Nothing Then Exit Sub
  192. If Microsoft.VisualBasic.Trim(處方_dgv.Rows(e.RowIndex).Cells("zdhc_code").Value.ToString) = "" And
  193. 處方_dgv.Rows(e.RowIndex).Cells("系统分类").Value.ToString <> "基础材料" And Not (處方_dgv.Rows(e.RowIndex).Cells("化料名称").Value.ToString Like "水*") Then
  194. 處方_dgv.Rows(e.RowIndex).Cells("化工分类").Style.BackColor = Color.LightBlue
  195. End If
  196. If 處方_dgv.Rows(e.RowIndex).Cells("標記1").Value.ToString = "1" Then
  197. 處方_dgv.Rows(e.RowIndex).Cells("项次").Style.BackColor = Color.OrangeRed
  198. Else : 處方_dgv.Rows(e.RowIndex).Cells("项次").Style.BackColor = Color.White : End If
  199. If 處方_dgv.Rows(e.RowIndex).Cells("標記2").Value.ToString = "1" Then
  200. 處方_dgv.Rows(e.RowIndex).Cells("化料名称").Style.BackColor = Color.OrangeRed
  201. Else : 處方_dgv.Rows(e.RowIndex).Cells("化料名称").Style.BackColor = Color.White : End If
  202. If 處方_dgv.Rows(e.RowIndex).Cells("標記3").Value.ToString = "1" Then
  203. 處方_dgv.Rows(e.RowIndex).Cells("百分比").Style.BackColor = Color.OrangeRed
  204. Else : 處方_dgv.Rows(e.RowIndex).Cells("百分比").Style.BackColor = Color.White : End If
  205. If 處方_dgv.Rows(e.RowIndex).Cells("標記4").Value.ToString = "1" Then
  206. 處方_dgv.Rows(e.RowIndex).Cells("时间").Style.BackColor = Color.OrangeRed
  207. Else : 處方_dgv.Rows(e.RowIndex).Cells("时间").Style.BackColor = Color.White : End If
  208. If 處方_dgv.Rows(e.RowIndex).Cells("標記5").Value.ToString = "1" Then
  209. 處方_dgv.Rows(e.RowIndex).Cells("备注").Style.BackColor = Color.OrangeRed
  210. Else : 處方_dgv.Rows(e.RowIndex).Cells("备注").Style.BackColor = Color.White : End If
  211. Dim linePen As New Pen(Color.Red, 2)
  212. If e.RowIndex = 處方_dgv.Rows.Count - 1 Then
  213. Dim startX As Integer = IIf(處方_dgv.RowHeadersVisible, 處方_dgv.RowHeadersWidth, 0)
  214. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  215. Dim endX As Integer = startX + 處方_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 處方_dgv.HorizontalScrollingOffset - 10
  216. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  217. End If
  218. If 處方_dgv.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
  219. Dim startX As Integer = IIf(處方_dgv.RowHeadersVisible, 處方_dgv.RowHeadersWidth, 0)
  220. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  221. Dim endX As Integer = startX + 處方_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 處方_dgv.HorizontalScrollingOffset - 10
  222. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  223. End If
  224. End Sub
  225. Private Sub 處方縮放_bt_Click(sender As Object, e As EventArgs) Handles 處方縮放_bt.Click
  226. Application.DoEvents()
  227. If 處方_dgv.DataSource Is Nothing Then : MsgBox("数据为空") : Exit Sub : End If
  228. If isMaximized = False Then
  229. 處方_dgv.Location = originalLocation : 處方_dgv.Size = New Size(771, SplitContainer1.Height) ' 恢复原始位置和大小 771, 897
  230. 處方縮放_bt.Text = "放大" : isMaximized = True ' 更新状态标记为恢复
  231. 查詢_bt.Enabled = True : 存檔_bt.Enabled = True : 刪除工藝_bt.Enabled = True : 另存工藝_bt.Enabled = True
  232. 化工分类_ch.Checked = False : 类别_ch.Checked = False : zdhc_code_ch.Checked = False : 系统品名_ch.Checked = False
  233. 系统代码_ch.Checked = False : 进货单价_ch.Checked = False : 系统分类_ch.Checked = False : set_grid1()
  234. Else
  235. 處方_dgv.Location = New Point(2, 90) ' 移动到左上角
  236. 處方_dgv.Size = New Size(1669, SplitContainer1.Height) ' 设置为放大后的大小
  237. 處方縮放_bt.Text = "恢复" : isMaximized = False ' 更新状态标记为放大
  238. 查詢_bt.Enabled = False : 存檔_bt.Enabled = False : 刪除工藝_bt.Enabled = False : 另存工藝_bt.Enabled = False
  239. 化工分类_ch.Checked = True : 类别_ch.Checked = True : zdhc_code_ch.Checked = True : 系统品名_ch.Checked = True
  240. 系统代码_ch.Checked = True : 进货单价_ch.Checked = True : 系统分类_ch.Checked = True : set_grid1()
  241. End If : 處方_dgv.BringToFront()
  242. End Sub
  243. Private Sub 計算_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 計算_bt.Click '计算成本
  244. 計算(InputBox("请输入平均尺数", "输入平均尺数"))
  245. End Sub
  246. Private Sub 計算(userInput)
  247. Dim avgSize As Double
  248. 平均尺数_tb.Text = userInput : Dim pieces As Integer
  249. If 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("片数").Value.ToString = "" Then
  250. If 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("重量").Value <> "0" Then
  251. pieces = CInt(處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("重量").Value) / 4.5
  252. ElseIf 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("重量").Value = "0" Then
  253. pieces = 1
  254. End If
  255. Else : pieces = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("片数").Value : End If
  256. If Double.TryParse(userInput, avgSize) AndAlso avgSize > 0 Then ' 检查输入是否有效
  257. Dim dt3 As New DataTable : Dim dt4 As New DataTable ' 创建一个新的 DataTable 来存储计算结果
  258. dt3 = DirectCast(合計_dgv.DataSource, DataTable) ' 获取 DataGridView2 的数据源并创建副本
  259. dt4 = dt3.Copy() ' 创建 dt3 的副本
  260. For x As Integer = 0 To dt4.Rows.Count - 1 ' 假设 pieces 和 userInput 已经赋值
  261. dt4.Rows(x).Item(2) = dt4.Rows(x).Item(2) / (pieces * userInput) ' 对副本 dt4 进行修改
  262. Next
  263. 每尺合計_dgv.DataSource = dt4 ' 将修改后的结果绑定到 dgv3
  264. 每尺合計_dgv.Columns("小计").DefaultCellStyle.Format = "N2" : 每尺合計_dgv.Columns("百分比").DefaultCellStyle.Format = "N1"
  265. 每尺合計_dgv.Columns("分类").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  266. 每尺合計_dgv.Columns("小计").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  267. 每尺合計_dgv.Columns("百分比").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  268. Dim lastRowIndex As Integer = 每尺合計_dgv.Rows.Count - 2 : 每尺合計_dgv.Rows(lastRowIndex).DefaultCellStyle.ForeColor = Color.Red ' 设置最后一行的字体颜色为红色
  269. Else : MessageBox.Show("请输入有效的数字", "无效输入", MessageBoxButtons.OK, MessageBoxIcon.Warning) : End If
  270. End Sub
  271. Private Sub 插入一行_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 插入一行_bt.Click
  272. gMsg = MsgBox("要插入前方列請按--是" & vbCrLf & "要插入後方列請按--否" & vbCrLf & "或按取消離開", MsgBoxStyle.YesNoCancel)
  273. 模式通知_lb.Text = "修改模式" : Timer1.Enabled = True
  274. If gMsg <> MsgBoxResult.Cancel Then : FrmEditChem_Choose.ShowDialog()
  275. set_grid1() : cal_cost1() : 修改存檔_bt.Visible = True
  276. End If
  277. End Sub
  278. Private Sub 修改指定_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 修改指定_bt.Click
  279. 'If 處方_dgv.SelectedRows.Count = 0 Then : MsgBox("請先選擇要修改的項目") : Exit Sub : End If
  280. 模式通知_lb.Text = "修改模式" : Timer1.Enabled = True
  281. Dim f2 As New FrmEditChem_Choose : f2.Owner = Me : f2.ShowDialog()
  282. 修改存檔_bt.Visible = True : cmdCancelEdit.Visible = True
  283. If my_chem = Nothing Then : Else : 處方_dgv.Rows(處方_dgv.CurrentRow.Index).Cells("化料名称").Value = my_chem : End If
  284. 處方_dgv.Focus() : cal_cost1()
  285. End Sub
  286. Private Sub 刪除一行_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 刪除一行_bt.Click
  287. If Not (處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font Is Nothing) Then
  288. If 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font.Style = FontStyle.Strikeout Then
  289. 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font = New Font(處方_dgv.DefaultCellStyle.Font, FontStyle.Regular)
  290. Else : 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font = New Font(處方_dgv.DefaultCellStyle.Font, FontStyle.Strikeout) : End If
  291. Else : 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font = New Font(處方_dgv.DefaultCellStyle.Font, FontStyle.Strikeout) : End If
  292. 模式通知_lb.Text = "修改模式" : Timer1.Enabled = True : 模式通知_lb.ForeColor = Color.Red
  293. 修改存檔_bt.Visible = True : cmdCancelEdit.Visible = True
  294. End Sub
  295. Private Sub 修改存檔_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 修改存檔_bt.Click
  296. Dim result As DialogResult = MessageBox.Show("存档后将会覆盖之前的的染色工艺请确认是否进行存档?", "请选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
  297. If result = DialogResult.Yes Then
  298. '-------------先讀取必要條件----------------------------------------
  299. Dim no1, name1, date1, spec1, weight1, selection1, rcp_no1 As String : Dim 化料 As String : Dim 百分比 As String
  300. Dim 時間 As String : Dim 備註 As String : Dim 項次 As Integer = 1
  301. no1 = "" : name1 = "" : date1 = "" : spec1 = "" : weight1 = "" : selection1 = "" : rcp_no1 = ""
  302. Dim 品名 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value.ToString
  303. Dim 日期 As String = Strings.Format(處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value, "yyyy-MM-dd")
  304. Dim 选级 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value.ToString
  305. Dim 表格编号 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("表格编号").Value.ToString
  306. SQL_染色處方條件讀取(品名, 日期, 选级, 表格编号)
  307. If dr.Read Then
  308. no1 = dr("no").ToString : name1 = dr("name").ToString : date1 = Convert.ToDateTime(dr("date")).ToString("yyyy-MM-dd")
  309. spec1 = dr("spec").ToString : weight1 = dr("weight").ToString : selection1 = dr("selection").ToString : rcp_no1 = dr("rcp_no").ToString
  310. End If
  311. '-------------刪除原本的處方----------------------------------------
  312. SQL_染色處方刪除(品名, 日期, 选级, 表格编号)
  313. '-------------將新的處方存檔----------------------------------------
  314. Dim sqlInsert As New Text.StringBuilder() : Dim hasData As Boolean = False ' 是否有要寫入的資料
  315. For i As Integer = 0 To 處方_dgv.Rows.Count - 1
  316. 化料 = 處方_dgv.Rows(i).Cells("化料名称").Value.ToString()
  317. 百分比 = 處方_dgv.Rows(i).Cells("百分比").Value.ToString()
  318. 時間 = 處方_dgv.Rows(i).Cells("时间").Value.ToString()
  319. 備註 = 處方_dgv.Rows(i).Cells("备注").Value.ToString()
  320. Dim cellFont As Font = 處方_dgv.Rows(i).DefaultCellStyle.Font
  321. If cellFont Is Nothing OrElse cellFont.Style <> FontStyle.Strikeout Then
  322. If hasData Then sqlInsert.AppendLine(",") ' 不是第一筆則加上逗號
  323. sqlInsert.AppendFormat("(N'{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}', N'{11}')",
  324. no1, name1, date1, spec1, weight1, selection1, 化料, 百分比, 時間, 備註, rcp_no1, 項次)
  325. 項次 += 1 : hasData = True
  326. End If
  327. Next : If hasData Then : SQL_染色處方新增(sqlInsert.ToString()) : End If : MsgBox("存檔完成!!") : Set_處方明細()
  328. End If
  329. End Sub
  330. Private Sub 領料_bt_Click(sender As Object, e As EventArgs) Handles 領料_bt.Click '领料
  331. Dim processCardNo As String = InputBox("请输入流程卡号:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("流程卡号").Value)
  332. SQL_染色處方領料判斷(processCardNo)
  333. If dr.Read Then : MsgBox("該流程卡已經領過料!!") : Exit Sub : Else
  334. Dim my_chem As String = "" : conn.Close()
  335. For Each row As DataGridViewRow In 處方_dgv.Rows
  336. If row.Cells("类别").Value = "不列印" Then : Continue For : End If
  337. Dim cellFont As Font = row.DefaultCellStyle.Font
  338. If cellFont IsNot Nothing Then : Dim aa As String = "" : Dim fontStyle As FontStyle = cellFont.Style
  339. If fontStyle = FontStyle.Strikeout Then : aa = "" : End If
  340. Else
  341. If row.Cells("类别").Value = "不列印" And Not (row.Cells("化料名称").Value Like "水*") Then
  342. my_chem += "项次" & row.Cells("项次").Value & " " & row.Cells("化料名称").Value & vbNewLine
  343. End If
  344. End If
  345. Next
  346. If Microsoft.VisualBasic.Len(my_chem) > 0 Then
  347. MsgBox("以下化工品名有误:" & vbNewLine & vbNewLine & my_chem) : Exit Sub
  348. End If
  349. Dim 片數 As String = InputBox("请输入片数:", "", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("片数").Value.ToString())
  350. Dim inputDateString As String = InputBox("请输入日期:", "", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value.ToString())
  351. Dim inputDate As Date
  352. If Not Date.TryParse(inputDateString, inputDate) Then
  353. MessageBox.Show("输入的日期格式无效,请重新输入。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
  354. Exit Sub ' 退出子程序,避免后续报错
  355. End If
  356. Dim weightString As String = InputBox("请输入重量:", "", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("重量").Value.ToString())
  357. Dim weight As Double
  358. If Not Double.TryParse(weightString, weight) Then
  359. MessageBox.Show("输入的重量格式无效,请重新输入。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
  360. Exit Sub ' 退出子程序,防止后续代码执行
  361. End If
  362. ConnOpen()
  363. For Each row As DataGridViewRow In 處方_dgv.Rows ' 获取每一行的数据
  364. Dim no As String = row.Cells("项次").Value.ToString()
  365. Dim chem As String = row.Cells("系统品名").Value.ToString()
  366. Dim percents As String = row.Cells("百分比").Value.ToString()
  367. Dim time As String = If(IsDBNull(row.Cells("时间").Value), "", row.Cells("时间").Value.ToString())
  368. Dim comment As String = row.Cells("备注").Value.ToString()
  369. Dim cellFont As Font = row.DefaultCellStyle.Font ' 获取字体样式
  370. If cellFont IsNot Nothing Then : Else ' 插入数据到数据库(使用参数化查询)
  371. SQL1 = "INSERT INTO ht_retan_chem_out (item, rcp_name, chem_name,chem_code,chem_weight, outdate, weight, chem_percent, time, comment,card)
  372. VALUES (@item, @rcp_name, @chem_name,@chem_code,@chem_weight, @out_date, @weight, @percents, @time, @comment,@card)"
  373. cmd.CommandText = SQL1 : cmd.Parameters.Clear()
  374. cmd.Parameters.AddWithValue("@item", no) ' 使用行号作为 item
  375. cmd.Parameters.AddWithValue("@rcp_name", 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value)
  376. cmd.Parameters.AddWithValue("@chem_name", chem)
  377. cmd.Parameters.AddWithValue("@chem_code", row.Cells("系统代码").Value)
  378. cmd.Parameters.AddWithValue("@chem_weight", weight * row.Cells("百分比").Value / 100)
  379. cmd.Parameters.AddWithValue("@out_date", inputDate)
  380. cmd.Parameters.AddWithValue("@weight", weight)
  381. cmd.Parameters.AddWithValue("@percents", percents)
  382. cmd.Parameters.AddWithValue("@time", If(time = "", DBNull.Value, time)) ' 如果 time 为空,插入 DBNull
  383. cmd.Parameters.AddWithValue("@comment", comment)
  384. cmd.Parameters.AddWithValue("@card", processCardNo & " " & 片數 & "P")
  385. cmd.ExecuteNonQuery() ' 执行插入操作
  386. End If
  387. Next : MessageBox.Show("数据已成功保存!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information) : conn.Close()
  388. End If
  389. End Sub
  390. Private Sub 重新讀取_bt_Click(sender As Object, e As EventArgs) Handles 重新讀取_bt.Click
  391. Set_清單1("")
  392. End Sub
  393. Private Sub 打印工藝_bt_Click_1(sender As Object, e As EventArgs) Handles 打印工藝_bt.Click
  394. Dim xlApp As Excel.Application : Dim xlBook As Excel.Workbook : Dim xlSheet As Excel.Worksheet
  395. Dim my_card As String = InputBox("请输入卡号", "询问", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("流程卡号").Value)
  396. If my_card = "" Then Exit Sub
  397. Dim my_weight As String = InputBox("请输入重量", "询问", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("重量").Value)
  398. Dim userInput As Double : If Double.TryParse(my_weight, userInput) Then : Else : MsgBox("请输入有效的数字!") : Exit Sub : End If
  399. Dim my_selection As String = InputBox("请输入选级", "询问", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value)
  400. my_card = my_card : Dim d_no As String = InputBox("请输入鼓号", "询问")
  401. xlApp = CreateObject("Excel.Application") : xlBook = xlApp.Workbooks.Add : xlApp.DisplayAlerts = False : xlBook.Activate()
  402. xlBook.Parent.Windows(1).Visible = True : xlSheet = xlBook.Worksheets.Add : xlSheet.Activate() : xlApp.Visible = True
  403. xlApp.Application.ScreenUpdating = False : editFormat(xlApp, xlSheet) : xlApp.Visible = False
  404. xlSheet.Cells(1, 1) = "流程卡号" : xlSheet.Cells(2, 1) = "打印日期" : xlSheet.Cells(3, 1) = "皮源" : xlSheet.Cells(1, 7) = "工艺名稱"
  405. xlSheet.Cells(2, 6) = "規格" : xlSheet.Cells(2, 10) = "鼓号" : xlSheet.Cells(1, 12) = "染色日期" : xlSheet.Cells(2, 12) = "重量"
  406. xlSheet.Cells(3, 7) = "备注" : xlSheet.Cells(2, 12) = "重量" : xlSheet.Cells(3, 4) = comment : xlSheet.Cells(2, 4) = String.Format("{0:d}", DateTime.Now)
  407. xlSheet.Cells(1, 10) = cust & " " & color1 & "--" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value
  408. xlSheet.Cells(2, 7) = thickness : xlSheet.Cells(2, 11) = d_no : xlSheet.Cells(2, 14) = userInput & " 公斤" : xlSheet.Cells(1, 4) = my_card
  409. xlSheet.Cells(3, 4) = source : xlSheet.Cells(3, 10) = comment : xlSheet.Cells(5, 3) = "百分比" : xlSheet.Cells(5, 5) = "用量(Kgs)"
  410. xlSheet.Cells(5, 6) = "化 料 名 稱" : xlSheet.Cells(5, 9) = "时间" : xlSheet.Cells(5, 11) = "備註"
  411. xlSheet.Rows("5:5").Select() : xlApp.Selection.Font.Underline = xlUnderlineStyleSingle
  412. For i As Integer = 0 To 處方_dgv.Rows.Count - 1
  413. xlSheet.Cells(i + 6, 1) = Val(處方_dgv.Rows(i).Cells("项次").Value)
  414. xlSheet.Cells(i + 6, 3) = Math.Round(Val(處方_dgv.Rows(i).Cells("百分比").Value), 2)
  415. xlSheet.Cells(i + 6, 4) = "%"
  416. xlSheet.Cells(i + 6, 5) = Math.Round(處方_dgv.Rows(i).Cells("百分比").Value * userInput / 100, 2)
  417. xlSheet.Cells(i + 6, 6) = 處方_dgv.Rows(i).Cells("化料名称").Value
  418. xlSheet.Cells(i + 6, 9) = 處方_dgv.Rows(i).Cells("时间").Value
  419. xlSheet.Cells(i + 6, 11) = 處方_dgv.Rows(i).Cells("备注").Value
  420. xlSheet.Cells(i + 6, 10).Select()
  421. With xlApp.Selection : .Font.Bold = True : End With
  422. If 處方_dgv.Rows(i).Cells("化料名称").Value = "流水洗" Or 處方_dgv.Rows(i).Cells("化料名称").Value = "洗水" Or
  423. 處方_dgv.Rows(i).Cells("化料名称").Value = "排水" Or 處方_dgv.Rows(i).Cells("化料名称").Value = "轉動" Or
  424. 處方_dgv.Rows(i).Cells("化料名称").Value = "自動過夜" Or 處方_dgv.Rows(i).Cells("化料名称").Value = "停止" Then
  425. xlSheet.Rows(i + 5 & ":" & i + 5).Select() : With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlNone : End With
  426. xlSheet.Rows(i + 6 & ":" & i + 6).Select() : With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlDash : .Weight = xlHairline : End With
  427. xlSheet.Cells(i + 6, 3) = "" : xlSheet.Cells(i + 6, 4) = "" : xlSheet.Cells(i + 6, 5) = ""
  428. End If
  429. If 處方_dgv.Rows(i).Cells("时间").Value.ToString <> "" Then
  430. xlSheet.Rows(i + 6 & ":" & i + 6).Select() : With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMaximum : End With
  431. End If
  432. Next i
  433. Dim a As Integer = xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count : Dim b As Integer = xlApp.Workbooks(1).Worksheets(1).UsedRange.Columns.Count
  434. Dim area As String = "A4" & ":" & Chr(b + 64) & a
  435. xlSheet.Range(area).Font.Size = 10 : xlSheet.Range(area).Font.Name = "Times New Roman" : xlApp.Selection.Font.Name = "Times New Roman"
  436. xlSheet.Columns("A:O").Select()
  437. With xlApp.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
  438. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = XlReadingOrder.xlContext
  439. End With
  440. xlSheet.Cells(3, 4).Select() : With xlApp.Selection : .HorizontalAlignment = xlLeft : End With
  441. For x As Integer = 6 To a
  442. If xlSheet.Cells(x, 9).value Is Nothing And xlSheet.Cells(x, 6).value Is Nothing Then : xlSheet.Rows(x).RowHeight = 3 : Else : xlSheet.Rows(x).RowHeight = 18 : End If
  443. Next x
  444. xlSheet.Range("a:a").HorizontalAlignment = xlCenter : xlSheet.Range("c:c").HorizontalAlignment = xlRight
  445. xlSheet.Range("e:e ").HorizontalAlignment = xlCenter : xlSheet.Range("g:g").HorizontalAlignment = xlCenter
  446. xlSheet.Range("c:c").NumberFormatLocal = "G/通用格式" : With xlApp.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
  447. xlSheet.PageSetup.PrintArea = ""
  448. With xlApp.ActiveSheet.PageSetup : .TopMargin = xlApp.InchesToPoints(0.2) : .BottomMargin = xlApp.InchesToPoints(0) : .LeftMargin = xlApp.InchesToPoints(0)
  449. .RightMargin = xlApp.InchesToPoints(0) : .HeaderMargin = xlApp.InchesToPoints(0.511811023622047) : .FooterMargin = xlApp.InchesToPoints(0.511811023622047)
  450. .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 1 : .PrintErrors = xlPrintErrorsDisplayed
  451. End With
  452. xlApp.Cells.Select() : With xlApp.Selection.Font : .Name = "Times New Roman" : End With
  453. xlSheet.Range("f:f").HorizontalAlignment = xlLeft : xlSheet.Range("j:j").HorizontalAlignment = xlLeft
  454. xlSheet.Range("a1:o3").HorizontalAlignment = xlCenter : xlApp.Visible = True : xlApp.Application.ScreenUpdating = True
  455. MsgBox("打印完成!!")
  456. End Sub
  457. Private Sub editFormat(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  458. xlSheet.Columns("A:A").ColumnWidth = 3 : xlSheet.Columns("B:B").ColumnWidth = 1 : xlSheet.Columns("C:C").ColumnWidth = 8
  459. xlSheet.Columns("D:D").ColumnWidth = 1.5 : xlSheet.Columns("e:e").ColumnWidth = 9.63 : xlSheet.Columns("f:f").ColumnWidth = 14.25
  460. xlSheet.Columns("g:g").ColumnWidth = 3 : xlSheet.Columns("h:h").ColumnWidth = 3 : xlSheet.Columns("i:i").ColumnWidth = 3
  461. xlSheet.Columns("j:j").ColumnWidth = 10 : xlSheet.Columns("k:k").ColumnWidth = 10 : xlSheet.Columns("l:l").ColumnWidth = 4.5
  462. xlSheet.Columns("m:m").ColumnWidth = 4.5 : xlSheet.Columns("n:n").ColumnWidth = 8.25 : xlSheet.Columns("o:o").ColumnWidth = 6
  463. xlSheet.Range("A1:C1").Merge() '-------流程卡号-------
  464. xlSheet.Range("A1:C1").Borders(xlDiagonalDown).LineStyle = xlNone : xlSheet.Range("A1:C1").Borders(xlDiagonalUp).LineStyle = xlNone
  465. With xlSheet.Range("A1:C1").Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  466. With xlSheet.Range("A1:C1").Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  467. With xlSheet.Range("A1:C1").Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  468. With xlSheet.Range("A1:C1").Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  469. xlSheet.Range("A2:C2").Select() : myExcel.Selection.Merge() '-------打印日期-------
  470. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  471. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  472. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  473. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  474. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  475. xlSheet.Range("A3:C3").Select() : myExcel.Selection.Merge() '-------皮源-------
  476. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  477. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  478. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  479. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  480. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  481. xlSheet.Range("d1:f1").Select() : myExcel.Selection.Merge() '-------流程卡号1-------
  482. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  483. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  484. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  485. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  486. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  487. xlSheet.Range("d2:e2").Select() : myExcel.Selection.Merge() '-------打印日期1-------
  488. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  489. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  490. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  491. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  492. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  493. xlSheet.Range("f2:f2").Select() : myExcel.Selection.Merge() '-------规格1-------
  494. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  495. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  496. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  497. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  498. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  499. xlSheet.Range("j2:j2").Select() : myExcel.Selection.Merge() '--------鼓号1
  500. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  501. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  502. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  503. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  504. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  505. xlSheet.Range("d3:f3").Select() : myExcel.Selection.Merge() '-------皮源
  506. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  507. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  508. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  509. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  510. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  511. xlSheet.Range("g3:i3").Select() : myExcel.Selection.Merge() '-------备注
  512. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  513. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  514. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  515. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  516. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  517. xlSheet.Range("j3:o3").Select() : myExcel.Selection.Merge() '-------备注
  518. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  519. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  520. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  521. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  522. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  523. xlSheet.Range("g1:i1").Select() : myExcel.Selection.Merge() '--------工艺名称
  524. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  525. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  526. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  527. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  528. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  529. xlSheet.Range("g2:i2").Select() : myExcel.Selection.Merge() '-------规格1
  530. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  531. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  532. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  533. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  534. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  535. xlSheet.Range("j1:o1").Select() : myExcel.Selection.Merge() '------工艺名称1
  536. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  537. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  538. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  539. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  540. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  541. xlSheet.Range("J2:j2").Select() '------
  542. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  543. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  544. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  545. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  546. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  547. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  548. xlSheet.Range("k2:K2").Select() '------
  549. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  550. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  551. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  552. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  553. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  554. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  555. xlSheet.Range("l2:m2").Select() : myExcel.Selection.Merge() '----------重量
  556. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  557. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  558. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  559. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  560. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  561. xlSheet.Range("n1:o1").Select() : myExcel.Selection.Merge() '--------
  562. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  563. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  564. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  565. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  566. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  567. xlSheet.Range("n2:o2").Select() : myExcel.Selection.Merge() '-------重量
  568. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  569. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  570. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  571. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  572. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
  573. End Sub
  574. Private Sub 打印標籤_bt_Click_1(sender As Object, e As EventArgs) Handles 打印標籤_bt.Click
  575. Dim my_card As String : Dim my_weight As Double : Dim d_no As String
  576. Do
  577. my_card = InputBox("请输入卡号:", "查询", 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells(4).Value)
  578. If my_card = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub ' 立即退出子程序
  579. ElseIf my_card = "" Then : MsgBox("请重新输入!", vbExclamation, "错误") : Else : Exit Do
  580. End If
  581. Loop
  582. Do ' 验证重量输入
  583. Dim weightInput As String
  584. weightInput = InputBox("请输入重量:", "查询", 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells(3).Value)
  585. If weightInput = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub
  586. ElseIf Not IsNumeric(weightInput) Then : MsgBox("重量必须是数字,请重新输入!", vbExclamation, "错误")
  587. ElseIf CDbl(weightInput) <= 0 Then : MsgBox("重量必须大于0,请重新输入!", vbExclamation, "错误")
  588. Else : my_weight = CDbl(weightInput) : Exit Do : End If
  589. Loop
  590. Do ' 验证编号输入
  591. d_no = InputBox("请输入编号:", "查询", 10)
  592. If d_no = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub
  593. ElseIf d_no Like "*-*" Then
  594. Else : Exit Do : End If
  595. Loop
  596. Dim imagePaths As Image() = {
  597. My.Resources._1, My.Resources._2, My.Resources._3,
  598. My.Resources._4, My.Resources._5, My.Resources._6,
  599. My.Resources._7, My.Resources._8, My.Resources._9
  600. }
  601. Dim dataTable As New DataTable() : dataTable = 處方_dgv.DataSource
  602. Dim workbook As IWorkbook = New XSSFWorkbook() : Dim sheet As ISheet = workbook.CreateSheet("Chemicals") ' 创建 Excel 工作簿
  603. Dim imageSheet As ISheet = workbook.CreateSheet("ImageLibrary") ' 创建隐藏的图片库工作表
  604. Dim drawing As IDrawing = imageSheet.CreateDrawingPatriarch() ' 加载图片到图片库
  605. For i As Integer = 0 To imagePaths.Length - 1
  606. Dim image As Image = imagePaths(i) : Dim imageBytes As Byte() ' 把 Image 轉成 Byte 陣列
  607. Using ms As New MemoryStream()
  608. image.Save(ms, Imaging.ImageFormat.Jpeg) : imageBytes = ms.ToArray()
  609. End Using
  610. Dim pictureIdx As Integer = workbook.AddPicture(imageBytes, PictureType.JPEG)
  611. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor() ' 插入图片到隐藏工作表
  612. anchor.Col1 = i + 2 ' 每张图片占一列
  613. anchor.Row1 = 0
  614. anchor.AnchorType = AnchorType.DontMoveAndResize
  615. Dim picture As IPicture = drawing.CreatePicture(anchor, pictureIdx)
  616. picture.Resize(1)
  617. Next
  618. For col As Integer = 0 To 5 : sheet.SetColumnWidth(col, 10 * 256) : Next ' 图片列宽度
  619. Dim currentRow As Integer = 0 ' 初始行位置
  620. dataTable.DefaultView.Sort = "类别 ASC, 项次 ASC"
  621. Dim sortedTable As DataTable = dataTable.DefaultView.ToTable()
  622. ProgressBar1.Visible = True : ProgressBar1.Minimum = 0
  623. ProgressBar1.Maximum = sortedTable.Rows.Count ' 假设 dt 是一个 DataTable
  624. ProgressBar1.Value = 0 ' 初始进度为 0
  625. For Each row As DataRow In sortedTable.Rows ' 遍历 DataTable 的每一行
  626. ProgressBar1.Value += 1 : Application.DoEvents()
  627. If row("类别") <> "不列印" Then '生成二维码图片
  628. Dim qrCodeImage As Image = MakeQrCode("http://www.ruitaileather.com:10494/" & Uri.EscapeDataString(row("filename").ToString()))
  629. Dim imageBytes As Byte() = ImageToByteArray(qrCodeImage) ' 插入二维码图片到第4列
  630. Dim drawingQrCode As IDrawing = sheet.CreateDrawingPatriarch()
  631. Dim anchorQrCode As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  632. anchorQrCode.Col1 = 4 ' 第4列
  633. anchorQrCode.Row1 = currentRow + 7 ' 当前行
  634. anchorQrCode.Col2 = 5 ' 跨1列
  635. anchorQrCode.Row2 = currentRow + 11 ' 占用4行
  636. Dim qrPictureIdx As Integer = workbook.AddPicture(imageBytes, PictureType.PNG) : Dim qrPicture As IPicture = drawingQrCode.CreatePicture(anchorQrCode, qrPictureIdx)
  637. qrPicture.Resize(1) ' 缩放二维码
  638. Dim rowToInsert = sheet.CreateRow(currentRow) ' 创建行并插入数据-- 只创建一行
  639. rowToInsert.CreateCell(0).SetCellValue($"卡号:{my_card}") ' 在第 4 列插入卡号
  640. rowToInsert.CreateCell(4).SetCellValue($"项次:{row("项次")}") ' 在第 8 列插入项次
  641. Dim cellStyle As ICellStyle = workbook.CreateCellStyle() : Dim font As IFont = workbook.CreateFont()
  642. font.FontHeightInPoints = 18 : cellStyle.SetFont(font) ' 设置字体大小为 18 ' 将字体应用到样式
  643. Dim row1 = sheet.CreateRow(currentRow + 1) : row1.CreateCell(0).SetCellValue($"化料名称:{row("化料名称")}")
  644. row1.Cells(0).CellStyle = cellStyle : sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 1, currentRow + 1, 0, 4))
  645. Dim row2 = sheet.CreateRow(currentRow + 2) : row2.CreateCell(0).SetCellValue($"重量:{row("百分比") * my_weight / 100}")
  646. row2.CreateCell(3).SetCellValue($"{row("化工分类")}") : row2.Cells(0).CellStyle = cellStyle : row2.Cells(1).CellStyle = cellStyle
  647. Dim row3 = sheet.CreateRow(currentRow + 3) : row3.CreateCell(4).SetCellValue($"鼓号")
  648. Dim row4 = sheet.CreateRow(currentRow + 4) : row4.CreateCell(4).SetCellValue($"{d_no}")
  649. Dim row5 = sheet.CreateRow(currentRow + 5) : row5.CreateCell(3).SetCellValue("百分比") : row5.CreateCell(4).SetCellValue("下鼓重")
  650. Dim row6 = sheet.CreateRow(currentRow + 6) : row6.CreateCell(3).SetCellValue($"{row("百分比")}") : row6.CreateCell(4).SetCellValue($"{my_weight}")
  651. Dim row7 = sheet.CreateRow(currentRow + 10) : row7.CreateCell(1).SetCellValue($"{處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells(1).Value}")
  652. Dim row9 = sheet.CreateRow(currentRow + 12) : row9.CreateCell(1).SetCellValue($"打印时间:{DateTime.Now}")
  653. sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 2, currentRow + 2, 0, 2))
  654. sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 2, currentRow + 2, 3, 4))
  655. Dim cellStyle1 As ICellStyle = workbook.CreateCellStyle() ' 创建一个字体和边框样式
  656. cellStyle.BorderTop = BorderStyle.Double : cellStyle.BorderRight = BorderStyle.Double ' 设置外边框为粗线
  657. cellStyle.BorderBottom = BorderStyle.Double : cellStyle.BorderLeft = BorderStyle.Double
  658. ' 为 A2:E3 区域设置边框 ' 设置粗外框
  659. For rowX As Integer = currentRow + 1 To currentRow + 2 ' 行索引从 1 开始
  660. For col As Integer = 0 To 4 ' 列索引从 0 到 4 (A 到 E)
  661. Dim cell As ICell = sheet.GetRow(rowX).GetCell(col)
  662. If cell Is Nothing Then : cell = sheet.GetRow(rowX).CreateCell(col) : End If : cell.CellStyle = cellStyle
  663. Next
  664. Next
  665. ' 插入 d1-d9 对应的图片
  666. Dim rowStart As Integer = currentRow ' 图片从当前行开始
  667. Dim colStart1 As Integer = 0
  668. Dim colStart As Integer = 0 ' d1-d9 的起始列
  669. Dim imgPerRow As Integer = 3 ' 每行放3张图片
  670. Dim row_start As Integer = 0
  671. For i As Integer = 1 To 9 : Dim colName As String = "d" & i
  672. If row(colName).ToString() = "√" Then : row_start += 1
  673. Dim imageRes As Image = Nothing ' 取得內嵌圖片資源
  674. Select Case i
  675. Case 1 : imageRes = My.Resources._1 : Case 2 : imageRes = My.Resources._2 : Case 3 : imageRes = My.Resources._3
  676. Case 4 : imageRes = My.Resources._4 : Case 5 : imageRes = My.Resources._5 : Case 6 : imageRes = My.Resources._6
  677. Case 7 : imageRes = My.Resources._7 : Case 8 : imageRes = My.Resources._8 : Case 9 : imageRes = My.Resources._9
  678. End Select
  679. If imageRes IsNot Nothing Then
  680. Dim imgStream As New MemoryStream() : imageRes.Save(imgStream, Imaging.ImageFormat.Jpeg) ' 轉換圖片為 Byte 陣列
  681. Dim bytes As Byte() = imgStream.ToArray()
  682. Dim pictureIdx As Integer = workbook.AddPicture(bytes, PictureType.JPEG)
  683. Dim drawingMain As IDrawing = sheet.CreateDrawingPatriarch()
  684. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  685. anchor.Col1 = colStart
  686. anchor.Row1 = rowStart + 3 ' 图片放在二维码下方,开始于第5行
  687. anchor.Col2 = colStart + 1 ' 图片跨2列
  688. anchor.Row2 = rowStart + 8 ' 图片占用5行
  689. ' 设置偏移量(像素)
  690. anchor.Dx1 = 200 ' 左上角水平偏移(单位:EMU)
  691. anchor.Dy1 = 20000 ' 左上角垂直偏移
  692. anchor.Dx2 = 500 ' 右下角水平偏移
  693. anchor.Dy2 = 0 ' 右下角垂直偏移
  694. anchor.AnchorType = AnchorType.DontMoveAndResize ' 设置锚点类型,图片不随单元格变化
  695. Dim picture As IPicture = drawingMain.CreatePicture(anchor, pictureIdx)
  696. picture.Resize(1) ' 缩放比例
  697. colStart += 1 ' 更新列位置
  698. If colStart >= imgPerRow Then
  699. colStart1 = 1
  700. colStart = 0 ' 回到第一列
  701. rowStart += 5 ' 换行后行数增加5
  702. End If
  703. End If
  704. End If
  705. Next
  706. If colStart1 = 1 Then rowStart -= 5 ' 更新当前行位置,确保下一个化工占用新行
  707. currentRow = rowStart + 13 ' 增加行数以容纳二维码和图片
  708. sheet.SetRowBreak(currentRow - 1) ' 插入换页符
  709. End If
  710. Next
  711. Dim filePath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"卡号标签_{my_card}.xlsx")
  712. Using fs As New FileStream(filePath, FileMode.Create, FileAccess.Write)
  713. workbook.Write(fs)
  714. End Using
  715. If File.Exists(filePath) Then
  716. Process.Start(New ProcessStartInfo With {
  717. .FileName = filePath,
  718. .UseShellExecute = True
  719. })
  720. End If : 處方_dgv.Sort(處方_dgv.Columns("项次"), ListSortDirection.Ascending)
  721. End Sub
  722. Function ImageToByteArray(image As Image) As Byte()
  723. Using ms As New MemoryStream() : image.Save(ms, ImageFormat.Png) : Return ms.ToArray() : End Using
  724. End Function
  725. Private Sub 刪除工藝_bt_Click_1(sender As Object, e As EventArgs) Handles 刪除工藝_bt.Click '删除’
  726. Dim msg As MsgBoxResult = MsgBox("确定要删除工艺 '" & 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value & "' ? ", MsgBoxStyle.YesNoCancel)
  727. If msg = MsgBoxResult.Yes Then
  728. Dim 確認 As String = InputBox("请输入 [YES] 来完成删除!!")
  729. If 確認 = "YES" Then
  730. SQL_染色處方刪除(處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value, 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("表格编号").Value,
  731. 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("日期").Value) : MsgBox("工艺已删除")
  732. End If
  733. End If : Set_清單1("") : conn.Close()
  734. End Sub
  735. Private Sub 另存工藝_bt_Click(sender As Object, e As EventArgs) Handles 另存工藝_bt.Click '另存工艺
  736. ' 获取用户输入的日期、流程卡号、片数、批号、重量
  737. Dim inputDate As Date = Date.Now : Dim processCardNo As String = InputBox("请输入流程卡号:")
  738. SQL_染色處方流程卡號判斷(processCardNo) : If dr.Read Then : MsgBox("该流程卡已经有对应的染色工艺!!") : Exit Sub : End If
  739. Dim inputQuantity As String = InputBox("请输入片数:") : Dim quantity As Integer
  740. If Integer.TryParse(inputQuantity, quantity) Then ' 尝试将用户输入的值转换为整数
  741. ' 转换成功,quantity 已被赋值
  742. Else ' 如果转换失败,设置默认值或者根据需要进行处理
  743. quantity = 0 ' 设置为默认值
  744. End If
  745. Dim spec As String = InputBox("请输入厚度:") : Dim batchNo As String = InputBox("请输入蓝皮批号:")
  746. Dim inputweight As String = InputBox("请输入重量:") : Dim weight As Double
  747. If Integer.TryParse(inputweight, weight) Then ' 尝试将用户输入的值转换为整数
  748. ' 转换成功,weight 已被赋值
  749. Else ' 如果转换失败,设置默认值或者根据需要进行处理
  750. weight = 0 ' 设置为默认值
  751. End If
  752. Dim name As String = InputBox("请输入工艺名:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value)
  753. Dim rcp_no As String : SQL_染色處方流水號查詢(Strings.Format(inputDate, "yyyyMMdd"))
  754. If dr.Read Then
  755. Dim input As String = dr("rcp_no").ToString : Dim pattern As String = "(.*_)(\d+)$" ' 匹配最後的 "_" 及其後的數字
  756. Dim result As String = input : Dim match As Match = Regex.Match(input, pattern)
  757. If match.Success Then
  758. Dim prefix As String = match.Groups(1).Value ' "_前面的部分"
  759. Dim number As Integer = Integer.Parse(match.Groups(2).Value) ' "_後面的數字"
  760. result = prefix & (number + 1).ToString() ' 數字 +1
  761. End If : rcp_no = result
  762. Else : rcp_no = Strings.Format(inputDate, "yyyyMMdd") & "_1" : End If ' 生成 rcp_no:根据日期和流水号生成唯一的 rcp_no
  763. ConnOpen()
  764. For Each row As DataGridViewRow In 處方_dgv.Rows ' 获取每一行的数据
  765. Dim no As String = row.Cells("项次").Value.ToString() : Dim chem As String = row.Cells("化料名称").Value.ToString()
  766. Dim percents As String = row.Cells("百分比").Value.ToString() : Dim comment As String = row.Cells("备注").Value.ToString()
  767. Dim time As String = If(IsDBNull(row.Cells("时间").Value), "", row.Cells("时间").Value.ToString())
  768. SQL1 = "INSERT INTO ht_retanrcp (item, rcp_no, no, name, date, spec, weight, selection, chem, percents, time, comment)
  769. VALUES (@item, @rcp_no, @no, @name, @retan_date, @spec, @weight, @selection, @chem, @percents, @time, @comment)"
  770. cmd.CommandText = SQL1 : cmd.Parameters.Clear()
  771. cmd.Parameters.AddWithValue("@item", row.Index + 1) : cmd.Parameters.AddWithValue("@rcp_no", rcp_no)
  772. cmd.Parameters.AddWithValue("@no", processCardNo & " " & quantity & "P") : cmd.Parameters.AddWithValue("@name", name)
  773. cmd.Parameters.AddWithValue("@retan_date", inputDate) : cmd.Parameters.AddWithValue("@spec", spec)
  774. cmd.Parameters.AddWithValue("@weight", weight) : cmd.Parameters.AddWithValue("@selection", batchNo)
  775. cmd.Parameters.AddWithValue("@chem", chem) : cmd.Parameters.AddWithValue("@percents", percents)
  776. cmd.Parameters.AddWithValue("@time", If(time = "", DBNull.Value, time)) : cmd.Parameters.AddWithValue("@comment", comment)
  777. cmd.Parameters.AddWithValue("@process_card_no", processCardNo) : cmd.ExecuteNonQuery()
  778. Next : MessageBox.Show("数据已成功保存!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information) : Set_清單1("")
  779. End Sub
  780. Private Sub 存檔_bt_Click_2(sender As Object, e As EventArgs) Handles 存檔_bt.Click '修改
  781. Dim inputDate As Date = InputBox("请输入日期:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value)
  782. Dim processCardNo As String = InputBox("请输入流程卡号:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("流程卡号").Value)
  783. Dim inputQuantity As Integer = InputBox("请输入片数:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("片数").Value)
  784. Dim spec As String = InputBox("请输入开削厚度:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("开削").Value)
  785. Dim batchNo As String = InputBox("请输入蓝皮批号:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value)
  786. Dim weight As Double = CDbl(InputBox("请输入重量:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("重量").Value))
  787. Dim name As String = InputBox("请输入工艺名:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value)
  788. Dim 品名 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value
  789. Dim 表格编号 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("表格编号").Value
  790. Dim 日期 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("日期").Value
  791. SQL_染色處方基本資料修改(name, inputDate, spec, weight, batchNo, processCardNo & " " & inputQuantity & "P", 品名, 表格编号, 日期)
  792. MsgBox("更新完成") : Set_清單1("")
  793. End Sub
  794. Private Sub 查詢_bt_Click_1(sender As Object, e As EventArgs) Handles 查詢_bt.Click
  795. Dim rcp1 As String = InputBox("请输入要查询的处方名称") : rcp1 = "WHERE HT_RetanRcp.name LIKE '%" & rcp1 & "%'" : Set_清單1(rcp1)
  796. End Sub
  797. Private Sub 選客戶_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonHD.CheckedChanged, RadioButtonYT.CheckedChanged, RadioButtonDB.CheckedChanged,
  798. RadioButtonHS.CheckedChanged, RadioButtonZY.CheckedChanged, RadioButtonXJM.CheckedChanged, RadioButtonSM.CheckedChanged, RadioButtonCW.CheckedChanged, RadioButtonJD.
  799. CheckedChanged, RadioButtonDCS.CheckedChanged '------------选取客户
  800. Dim 篩選條件 As String = CType(sender, RadioButton).Text
  801. If 篩選條件 <> "HD" Then
  802. If 篩選條件 = "ALL" Then : 篩選條件 = "" : Else : 篩選條件 = " WHERE HT_RetanRcp.name LIKE '%" & 篩選條件 & "%'" : End If
  803. Else
  804. 篩選條件 = "WHERE ((no Like '%20240224035%') OR (no Like '%20240508135%') OR (no Like '%20240703035%') OR (no Like '%20240725055%') OR
  805. (no Like '%20240731065%') OR (no Like '%20241006235%') OR (no Like '%20241010185%') OR (no Like '%20241010195%') OR
  806. (no Like '%20241012115%') OR (no Like '%20241024015%') OR (no Like '%20241024025%') OR (no Like '%20241024045%') OR
  807. (no Like '%20241024055%') OR (no Like '%20241024065%') OR (no Like '%20241029105%') OR (no Like '%20241030035%') OR
  808. (no Like '%202411001085%') OR (no Like '%20241107015%') OR (no Like '%20241107025%') OR (no Like '%20241107035%') OR
  809. (no Like '%20241113055%') OR (no Like '%20241113065%') OR (no Like '%20241113117%') OR (no Like '%20241118025%') OR
  810. (no Like '%20241119075%') OR (no Like '%20241119085%') OR (no Like '%20241125035%') OR (no Like '%20241210117%') OR
  811. (no Like '%20241217117%') OR (no Like '%20241217127%') OR (no Like '%WGSTR20241107%'))"
  812. End If
  813. Set_清單1(篩選條件)
  814. End Sub
  815. '------------------------以下未整理-----------------------------------------------------------------------------------------------------------------------------------------------------
  816. Sub ExportToExcel()
  817. ' 获取输入信息
  818. Dim my_card As String = InputBox("请输入卡号:", "查询")
  819. If my_card = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub : End If
  820. Dim my_weight As Double = 0
  821. Dim weightInput As String = InputBox("请输入重量:", "查询")
  822. If weightInput = "" OrElse Not IsNumeric(weightInput) OrElse CDbl(weightInput) <= 0 Then : MsgBox("请输入有效的重量!", vbExclamation, "错误") : Exit Sub
  823. Else : my_weight = CDbl(weightInput) : End If
  824. Dim d_no As String = InputBox("请输入编号:", "查询")
  825. If d_no = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub : End If
  826. ' 创建一个新的工作簿
  827. Dim workbook As New XSSFWorkbook() : Dim sheet As ISheet = workbook.CreateSheet("Sheet1")
  828. ' 数据示例(例如 DataGridView1 的行数据)
  829. Dim rowIndex As Integer = 0
  830. For x As Integer = 0 To 處方_dgv.Rows.Count - 2
  831. If 處方_dgv.Rows(x).Cells("类别").Value <> "不列印" Then
  832. Dim row As IRow = sheet.CreateRow(rowIndex)
  833. row.CreateCell(0).SetCellValue("卡号: " & my_card) : row.CreateCell(1).SetCellValue("编号: " & d_no)
  834. row.CreateCell(2).SetCellValue("重量: " & my_weight) : rowIndex += 1
  835. ' 插入图片(假设图片路径在 p 数组中)
  836. Dim pictureData As Byte() = File.ReadAllBytes("c:\GHS\1.jpg") : Dim pictureIndex As Integer = workbook.AddPicture(pictureData, PictureType.JPEG)
  837. ' 创建 DrawingPatriarch
  838. Dim drawing As XSSFDrawing = CType(sheet.CreateDrawingPatriarch(), XSSFDrawing)
  839. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  840. anchor.Col1 = 3 ' 图片插入列
  841. anchor.Row1 = rowIndex ' 图片插入行
  842. drawing.CreatePicture(anchor, pictureIndex) ' 插入图片
  843. rowIndex += 1
  844. End If
  845. Next
  846. ' 设置输出文件路径
  847. Dim outputPath As String = "C:\path\to\your\output.xlsx"
  848. Using fs As New FileStream(outputPath, FileMode.Create, FileAccess.Write) : workbook.Write(fs) : End Using : MsgBox("输出完成")
  849. End Sub
  850. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  851. Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
  852. con.ConnectionString = connstring : con.Open() : cmd.Connection = con
  853. dgv2.Visible = False : ListBox2.Visible = True : ListBox3.Visible = True : ListBox4.Visible = True : TextBox2.Visible = True : TextBox3.Visible = True
  854. TextBox4.Visible = True : Button11.Visible = True : Button12.Visible = True : Button13.Visible = True : Button14.Visible = True : Button15.Visible = True
  855. sql = "select cust_name from customer order by cust_name"
  856. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox2.Items.Add(dr("cust_name")) : End While : dr.Close()
  857. sql = "select prod_name from tblproduct order by prod_name"
  858. cmd.CommandText = sql : dr = cmd.ExecuteReader
  859. While dr.Read : ListBox3.Items.Add(dr("prod_name")) : End While : dr.Close()
  860. sql = "select color_name from color order by color_name"
  861. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox4.Items.Add(dr("color_name")) : End While : dr.Close() : Timer1.Enabled = True
  862. End Sub
  863. Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp
  864. Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
  865. con.ConnectionString = connstring : con.Open() : cmd.Connection = con
  866. ListBox2.Items.Clear()
  867. sql = "select cust_name from customer where cust_name like '%" & TextBox2.Text & "%'"
  868. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox2.Items.Add(dr("cust_name")) : End While : dr.Close()
  869. If e.KeyCode = Keys.Enter Then
  870. If ListBox2.Items.Count = 0 Then Exit Sub : ListBox2.Focus() : ListBox2.SelectedIndex = 1
  871. End If
  872. End Sub
  873. Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp
  874. Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
  875. con.ConnectionString = connstring : con.Open() : cmd.Connection = con
  876. ListBox3.Items.Clear()
  877. sql = "select prod_name from tblproduct where prod_name like '%" & TextBox3.Text & "%'"
  878. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox3.Items.Add(dr("prod_name")) : End While : dr.Close()
  879. If e.KeyCode = Keys.Enter Then
  880. If ListBox3.Items.Count = 0 Then Exit Sub : ListBox3.Focus() : ListBox3.SelectedIndex = 1
  881. End If
  882. End Sub
  883. Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyUp
  884. Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
  885. con.ConnectionString = connstring : con.Open() : cmd.Connection = con
  886. ListBox4.Items.Clear()
  887. sql = "select color_name from color where color_name like '%" & TextBox4.Text & "%'"
  888. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox4.Items.Add(dr("color_name")) : End While : dr.Close()
  889. If e.KeyCode = Keys.Enter Then
  890. If ListBox3.Items.Count = 0 Then Exit Sub : ListBox4.Focus() : ListBox4.SelectedIndex = 1
  891. End If
  892. End Sub
  893. Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
  894. If ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Then : MsgBox("請先選擇客戶產品顏色", , "錯誤") : Exit Sub : End If
  895. Dim con As New SqlConnection
  896. Dim sql As String = "" : Dim rcp_no As String = "" : Dim cust_no As String = "" : Dim prod_id As String = "" : Dim color_no As String = ""
  897. con.ConnectionString = connstring : con.Open() : cmd.Connection = con
  898. sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
  899. cmd.CommandText = sql : cust_no = cmd.ExecuteScalar
  900. sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
  901. cmd.CommandText = sql : prod_id = cmd.ExecuteScalar
  902. sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
  903. cmd.CommandText = sql : color_no = cmd.ExecuteScalar
  904. sql = "select count(*) from " & rcp & " where substring(rcp_no,4,3)='" & cust_no & "' and substring(rcp_no,1,1)='" & prod_id & "' and substring(rcp_no,7,2)='" & color_no & "'"
  905. cmd.CommandText = sql : Dim c As Integer = cmd.ExecuteScalar
  906. If c = 0 Then : rr = prod_id & String.Format("{0:D2}", c) & String.Format("{0:D3}", cust_no) & color_no
  907. Else : rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no : End If
  908. sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
  909. cmd.CommandText = sql : c = cmd.ExecuteScalar : rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem
  910. rcp_name = InputBox("處方名稱", "詢問", rcp_name)
  911. sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
  912. cmd.CommandText = sql : Dim a As Integer = cmd.ExecuteScalar
  913. If a = 0 Then : Else : MsgBox("處方編號重覆") : gAddfromOther = False : Exit Sub : End If
  914. Dim msg As MsgBoxResult : msg = MsgBox("是否要由其他處方修改?", vbYesNoCancel, "詢問")
  915. gAddfromOther = True
  916. Dim my_rcp As String = "" : my_rcp = InputBox("請輸入處方編號")
  917. If my_rcp = "" Then Exit Sub
  918. sql_rcp = "select RCP_NO as 處方編號, RCP_NAME as 品名, CREAT_D, LAST_EDITED, LAST_USED from " & rcp & " where rcp_no like '%" & my_rcp & "%' or rcp_name like '%" & my_rcp & "%'"
  919. cmd.CommandText = sql_rcp : da.SelectCommand = cmd
  920. Dim ds As New DataSet : da.Fill(ds) : 處方清單_dgv.DataSource = ds.Tables(0) : Timer1.Enabled = True : con.Close()
  921. End Sub
  922. Private Sub cmdAddrcp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddrcp.Click
  923. If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  924. Dim sql As String = "insert into " & rcp & " (rcp_no,rcp_name,creat_d) values ( '" & rr & "','" & rcp_name & "','" & String.Format("{0:d}", DateTime.Now) & "')"
  925. cmd.CommandText = sql : cmd.Connection = conn : Dim b As Integer = cmd.ExecuteNonQuery
  926. If b <> 0 Then : MsgBox("已新增處方編號:" & rr & vbCrLf & " 處方名稱:" & rcp_name) : Else : MsgBox("新增處方失敗") : End If
  927. Dim dt As DataTable : dt = dgv2.DataSource
  928. For x As Integer = 0 To dt.Rows.Count - 1
  929. cmd.CommandText = "insert into rcp_content (item,matl_no,percents,rcp_no,time,comment)
  930. values ('" & dt.Rows(x).Item("項目").ToString & "','" & dt.Rows(x).Item("化料編號").ToString & "',
  931. '" & dt.Rows(x).Item("百分比").ToString & "','" & rr & "','" & dt.Rows(x).Item("时间").ToString & "',
  932. '" & dt.Rows(x).Item("備註").ToString & "')"
  933. cmd.ExecuteNonQuery()
  934. Next : cmdAddrcp.Visible = False : cmdcanceladd.Visible = False : Timer1.Enabled = False : 模式通知_lb.Visible = False : conn.Close()
  935. End Sub
  936. Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
  937. dgv2.Visible = True : ListBox2.Visible = False : ListBox3.Visible = False : ListBox4.Visible = False : TextBox2.Visible = False : TextBox3.Visible = False
  938. TextBox4.Visible = False : Button11.Visible = False : Button12.Visible = False : Button13.Visible = False : Button14.Visible = False : Button15.Visible = False
  939. Button17.Visible = False : cmdAddrcp.Visible = False : cmdcanceladd.Visible = False : Timer1.Enabled = False : 模式通知_lb.Visible = False
  940. End Sub
  941. Private Sub cmdCancelEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelEdit.Click
  942. 修改存檔_bt.Visible = False : cmdCancelEdit.Visible = False : Timer1.Enabled = False : 模式通知_lb.Visible = False
  943. End Sub
  944. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  945. If dgv_record.Visible = False Then : dgv_record.BringToFront() : dgv_record.Visible = True : Else : dgv_record.Visible = False : End If
  946. End Sub
  947. Private Sub dgv_record_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgv_record.RowPostPaint
  948. Dim linePen As New Pen(Color.SkyBlue, 2)
  949. If e.RowIndex = dgv_record.Rows.Count - 1 Then
  950. dgv_record.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  951. Dim startX As Integer = IIf(dgv_record.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
  952. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  953. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
  954. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  955. Exit Sub
  956. End If
  957. If dgv_record.Rows(e.RowIndex).Cells("時间").Value.ToString <> "" And (dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "流水洗" Or
  958. dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "洗水" Or dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value = "排水") Then
  959. ElseIf dgv_record.Rows(e.RowIndex).Cells("時间").Value.ToString <> "" Then
  960. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
  961. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  962. Dim endX As Integer = startX + dgv_record.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
  963. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  964. End If
  965. If (dgv_record.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or dgv_record.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or
  966. dgv_record.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
  967. dgv_record.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  968. Dim startX As Integer = IIf(dgv_record.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
  969. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  970. Dim endX As Integer = startX + dgv_record.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
  971. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  972. End If
  973. End Sub
  974. Private Function chem_balance(ByVal matl_no As String, ByVal quantity As Double, ByVal x As Integer, ByVal id As Integer)
  975. Dim conn5 As New SqlConnection : Dim dt1 As New DataTable : Dim sql As String = ""
  976. sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "' and quantity-w<>0"
  977. cmd.CommandText = sql : da.Fill(dt1)
  978. If dt1.Rows.Count = 0 Then
  979. Dim dt2 As New DataTable : sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "'"
  980. cmd.CommandText = sql : da.Fill(dt2)
  981. If dt2.Rows.Count = 0 Then
  982. sql = "insert into tblchem_lot (matl_no,lot_no,quantity,coin,price) values ('" & matl_no & "','120229','" & 0 & "','" & "NTD" & "','" & 0 & "')"
  983. cmd.CommandText = sql : cmd.ExecuteScalar()
  984. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
  985. values ('" & dt2.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt2.Rows(0).Item("coin") & "',
  986. '" & dt2.Rows(0).Item("price") & "','" & id & "')"
  987. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  988. sql = "update tblchem_lot set w=w+'" & quantity & "'
  989. where lot_no='" & dt2.Rows(0).Item("lot_no") & "' and quantity ='" & dt2.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  990. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  991. Else
  992. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
  993. values ('" & dt2.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt2.Rows(0).Item("coin") & "',
  994. '" & dt2.Rows(0).Item("price") & "','" & id & "')"
  995. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  996. sql = "update tblchem_lot set w=w+'" & quantity & "'
  997. where lot_no='" & dt2.Rows(0).Item("lot_no") & "' and quantity ='" & dt2.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  998. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  999. End If
  1000. End If
  1001. If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") - quantity > 0 Then
  1002. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
  1003. values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "',
  1004. '" & dt1.Rows(0).Item("price") & "','" & id & "')"
  1005. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  1006. sql = "update tblchem_lot set w=w+'" & quantity & "'
  1007. where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  1008. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  1009. Else
  1010. If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") > 0 Then
  1011. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
  1012. values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "',
  1013. '" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  1014. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  1015. sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "'
  1016. where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
  1017. cmd.CommandText = sql : dr = cmd.ExecuteScalar : chem_balance(matl_no, quantity - (dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w")), x + 1, id)
  1018. Else
  1019. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
  1020. values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "',
  1021. '" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  1022. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  1023. sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "'
  1024. where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
  1025. cmd.CommandText = sql : dr = cmd.ExecuteScalar
  1026. End If
  1027. End If
  1028. End Function
  1029. Private Sub TXT_PID_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TXT_PID.KeyUp
  1030. Dim sql As String = "" : Dim dr2 As SqlDataReader
  1031. sql = "select article from leather_io where production_id='" & TXT_PID.Text & "'"
  1032. cmd.CommandText = sql : cmd.Connection = conn
  1033. If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  1034. dr2 = cmd.ExecuteReader : If dr2.Read Then : txtsum.Text = dr2("article") : End If
  1035. dr2.Close() : conn.Close()
  1036. sql = "select weight/piece as my_avg from production where production_id='" & TXT_PID.Text & "'"
  1037. cmd.CommandText = sql : cmd.Connection = conn
  1038. If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  1039. dr2 = cmd.ExecuteReader : If dr2.Read Then : txtwb_weight.Text = dr2("my_avg") : End If
  1040. dr2.Close() : conn.Close()
  1041. End Sub
  1042. Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
  1043. Dim sql As String = "" : cmd.Connection = conn : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  1044. ListBox2.Visible = True : ListBox3.Visible = True : ListBox4.Visible = True : TextBox2.Visible = True
  1045. TextBox3.Visible = True : TextBox4.Visible = True : Button15.Visible = True
  1046. sql = "select cust_name from customer order by cust_name"
  1047. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox2.Items.Add(dr("cust_name")) : End While : dr.Close()
  1048. sql = "select prod_name from tblproduct order by prod_name"
  1049. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox3.Items.Add(dr("prod_name")) : End While : dr.Close()
  1050. sql = "select color_name from color order by color_name"
  1051. cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox4.Items.Add(dr("color_name")) : End While : dr.Close()
  1052. Button17.Visible = True : conn.Close()
  1053. End Sub
  1054. Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
  1055. Dim sql As String = "" : Dim cust_no As String = "" : Dim prod_id As String = "" : Dim color_no As String = ""
  1056. If cmd.Connection.State = ConnectionState.Closed Then : conn.Open() : End If
  1057. sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
  1058. cmd.CommandText = sql : cust_no = cmd.ExecuteScalar
  1059. sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
  1060. cmd.CommandText = sql : prod_id = cmd.ExecuteScalar
  1061. sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
  1062. cmd.CommandText = sql : color_no = cmd.ExecuteScalar
  1063. sql = "select count(*) from " & rcp & " where substring(rcp_no,4,3)='" & cust_no & "' and substring(rcp_no,1,1)='" & prod_id & "' and substring(rcp_no,7,2)='" & color_no & "'"
  1064. cmd.CommandText = sql
  1065. Dim c As Integer = cmd.ExecuteScalar : If c = 0 Then : rr = prod_id & String.Format("{0:D2}", c) & String.Format("{0:D3}", cust_no) & color_no
  1066. Else : rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no : End If
  1067. sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
  1068. cmd.CommandText = sql : c = cmd.ExecuteScalar : If c <> 0 Then : MsgBox("重覆") : Exit Sub : End If
  1069. rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem : rcp_name = InputBox("處方名稱", "詢問", rcp_name)
  1070. sql = "insert into " & rcp & " (rcp_no,rcp_name,creat_d) values ( '" & rr & "',N'" & rcp_name & "','" & String.Format("{0:d}", DateTime.Now) & "')"
  1071. cmd.CommandText = sql : cmd.ExecuteNonQuery()
  1072. For x As Integer = 0 To dgv2.RowCount - 1
  1073. If (dgv2.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1074. Dim item As String = "" : If x <= 8 Then : item = "0" & x + 1 : Else : item = x + 1 : End If
  1075. sql = "insert into rcp_content (item,matl_no,percents,time,comment,rcp_no)
  1076. values ('" & item & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "',
  1077. N'" & dgv2.Rows(x).Cells(5).Value & "','" & rr & "')"
  1078. cmd.CommandText = sql : cmd.ExecuteNonQuery()
  1079. Else
  1080. If dgv2.Rows(x).DefaultCellStyle.Font.Style <> FontStyle.Strikeout Then
  1081. Dim item As String = "" : If Microsoft.VisualBasic.Len(x) = 1 Then : item = "0" & x + 1 : Else : item = x + 1 : End If
  1082. sql = "insert into rcp_content (item,matl_no,percents,time,comment,rcp_no)
  1083. values ('" & item & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "',
  1084. N'" & dgv2.Rows(x).Cells(5).Value & "','" & rr & "')"
  1085. cmd.CommandText = sql : cmd.ExecuteNonQuery()
  1086. End If
  1087. End If
  1088. Next : MsgBox("處方" & rr & rcp_name & "新增完成") : conn.Close()
  1089. Button17.Visible = False : ListBox2.Visible = False : ListBox3.Visible = False : ListBox4.Visible = False
  1090. TextBox2.Visible = False : TextBox3.Visible = False : TextBox4.Visible = False
  1091. End Sub
  1092. Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
  1093. Dim rcp_name As String = "" : Dim sql As String = "" : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  1094. rcp_name = InputBox("輸入新的處方名", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(1).Value)
  1095. sql = "update " & rcp & " set rcp_name=N'" & rcp_name & "' where rcp_no='" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(0).Value & "'"
  1096. cmd.Connection = conn : cmd.CommandText = sql : cmd.ExecuteScalar() : conn.Close()
  1097. End Sub
  1098. Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
  1099. Dim rcp_name As String = "" : Dim sql As String = "" : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  1100. sql = "delete from " & rcp & " where rcp_no='" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(0).Value & "'"
  1101. cmd.Connection = conn : cmd.CommandText = sql : cmd.ExecuteScalar() : conn.Close()
  1102. End Sub
  1103. Private Sub Button14_Click_1(sender As Object, e As EventArgs) Handles Button14.Click
  1104. If ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Then : MsgBox("請先選擇客戶產品顏色", , "錯誤") : Exit Sub : End If
  1105. Dim sql As String = "" : Dim con As New SqlConnection : Dim rcp_no As String = "" : Dim cust_no As String = "" : Dim prod_id As String = "" : Dim color_no As String = ""
  1106. con.ConnectionString = connstring : con.Open() : cmd.Connection = con
  1107. sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
  1108. cmd.CommandText = sql : cust_no = cmd.ExecuteScalar
  1109. sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
  1110. cmd.CommandText = sql : prod_id = cmd.ExecuteScalar
  1111. sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
  1112. cmd.CommandText = sql : color_no = cmd.ExecuteScalar
  1113. sql = "select count(*) from prescription_main where substring(rcp_no,4,3)='" & cust_no & "' and substring(rcp_no,1,1)='" & prod_id & "' and substring(rcp_no,7,2)='" & color_no & "'"
  1114. cmd.CommandText = sql : Dim c As Integer = cmd.ExecuteScalar
  1115. If c = 0 Then : rr = prod_id & String.Format("{0:D2}", c) & String.Format("{0:D3}", cust_no) & color_no
  1116. Else : rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no : End If
  1117. sql = "select count(*) from prescription_main where rcp_no='" & rr & "'"
  1118. cmd.CommandText = sql : c = cmd.ExecuteScalar
  1119. rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem : rcp_name = InputBox("處方名稱", "詢問", rcp_name)
  1120. sql = "select count(*) from prescription_main where rcp_no='" & rr & "'"
  1121. cmd.CommandText = sql : Dim a As Integer = cmd.ExecuteScalar
  1122. If a = 0 Then : Else : MsgBox("處方編號重覆") : gAddfromOther = False : Exit Sub : End If
  1123. Dim msg As MsgBoxResult : msg = MsgBox("是否要由其他處方修改?", vbYesNoCancel, "詢問") : gAddfromOther = True
  1124. Dim my_rcp As String = "" : my_rcp = InputBox("請輸入處方編號") : If my_rcp = "" Then Exit Sub
  1125. sql_rcp = "select RCP_NO as 處方編號, RCP_NAME as 品名, CREAT_D, LAST_EDITED, LAST_USED from prescription_main
  1126. where rcp_no like '%" & my_rcp & "%' or rcp_name like '%" & my_rcp & "%'"
  1127. cmd.CommandText = sql_rcp : da.SelectCommand = cmd : Dim ds As New DataSet : da.Fill(ds)
  1128. 處方清單_dgv.DataSource = ds.Tables(0) : Timer1.Enabled = True : con.Close()
  1129. End Sub
  1130. Private Sub dgv_cost_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_cost.CellEnter
  1131. Dim ds1 As New DataSet : Dim ds2 As New DataSet : Dim cn As New SqlConnection
  1132. cn.ConnectionString = connstring : cn.Open() : cmd.Connection = cn
  1133. sql_rcp = "select rcp_content.ITEM AS 項目,rcp_content.MATL_NO AS 編號,tblMaterial.MATL_NAME AS 品名,rcp_content.percents AS 比例
  1134. FROM " & rcp & " INNER JOIN rcp_content ON " & rcp & ".RCP_NO = rcp_content.RCP_NO INNER JOIN tblMaterial ON rcp_content.MATL_NO = tblMaterial.MATL_NO
  1135. WHERE rcp_content.RCP_NO='" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(0).Value & "' and
  1136. tblMaterial.MATL_ID='" & dgv_cost.Rows(dgv_cost.CurrentRow.Index).Cells(1).Value & "' order by rcp_content.item"
  1137. cmd.CommandText = sql_rcp : da.SelectCommand = cmd : da.Fill(ds2) : dgv_chem_detail.DataSource = ds2.Tables(0)
  1138. dgv_chem_detail.Columns(0).Width = 38 : dgv_chem_detail.Columns(1).Width = 50 : dgv_chem_detail.Columns(2).Width = 80 : dgv_chem_detail.Columns(3).Width = 50
  1139. End Sub
  1140. Private Sub cal_cost()
  1141. ' 使用 LINQ 进行 Group By 操作,并取每个分组中的进货单价
  1142. Dim groupedData = From row In DT2.AsEnumerable()
  1143. Group row By category = row.Field(Of String)("化工分类") Into Group
  1144. Select category,
  1145. TotalAmount = Group.Sum(Function(r) If(IsNumeric(r.Field(Of Object)("百分比")), Convert.ToDouble(r.Field(Of Object)("百分比")), 0)),
  1146. PurchasePrice = If(Group.Any(Function(r) IsNumeric(r.Field(Of Object)("进货单价"))),
  1147. Convert.ToDouble(Group.Select(Function(r) r.Field(Of Object)("进货单价")).FirstOrDefault()),
  1148. 0)
  1149. ' 创建新的 DataTable 来存储分组后的数据
  1150. Dim newDataTable As New DataTable()
  1151. newDataTable.Columns.Add("Category", GetType(String)) : newDataTable.Columns.Add("TotalAmount", GetType(Double)) : newDataTable.Columns.Add("PurchasePrice", GetType(Double))
  1152. ' 将 groupedData 中的数据插入到新的 DataTable 中
  1153. For Each item In groupedData
  1154. Dim newRow As DataRow = newDataTable.NewRow() : newRow("Category") = item.category : newRow("TotalAmount") = item.TotalAmount
  1155. newRow("PurchasePrice") = item.PurchasePrice : newDataTable.Rows.Add(newRow)
  1156. Next : 處方_dgv.DataSource = newDataTable : 處方_dgv.ReadOnly = True
  1157. End Sub
  1158. Private Sub dgv2_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles dgv2.RowPostPaint
  1159. Dim linePen As New Pen(Color.Aquamarine, 2)
  1160. If e.RowIndex = dgv2.Rows.Count - 1 Then
  1161. dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  1162. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  1163. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  1164. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
  1165. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  1166. End If
  1167. If dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" And (dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "流水洗" Or
  1168. dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "洗水" Or dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value = "排水") Then
  1169. ElseIf dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
  1170. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  1171. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  1172. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
  1173. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  1174. End If
  1175. If (dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or
  1176. dgv2.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
  1177. dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  1178. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  1179. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  1180. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
  1181. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  1182. End If
  1183. End Sub
  1184. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click 'msds
  1185. cmd.Connection = conn : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  1186. Dim sql As String : Dim folderPath As String = "\\DS920plus\华峰业务\AA化料文件资料\2024年整理MSDS和ZDHC\MSDS\MSDS总表" ' 检查文件夹是否存在
  1187. If Directory.Exists(folderPath) Then ' 获取文件夹内所有文件的路径
  1188. Dim files As String() = Directory.GetFiles(folderPath) ' 遍历文件数组并输出文件名
  1189. For Each file As String In files ' 输出文件名
  1190. Console.WriteLine(Path.GetFileName(file))
  1191. sql = "insert into ht_msds_file (filename) values (N'" & Path.GetFileName(file) & "')" : cmd.CommandText = sql : cmd.ExecuteScalar()
  1192. Next
  1193. Else : Console.WriteLine("目录不存在!") : End If : MsgBox("")
  1194. End Sub
  1195. Sub InsertImageWithNPOI(start_row As Integer, start_column As Integer)
  1196. Dim workbook As New XSSFWorkbook() ' 创建 NPOI 工作簿和工作表
  1197. Dim sheet As XSSFSheet = workbook.CreateSheet("Sheet1")
  1198. Dim pictureData As Byte() = Nothing ' 图片数据
  1199. Using ms As New MemoryStream()
  1200. PictureBox1.Image.Save(ms, Imaging.ImageFormat.Png) ' 从 PictureBox1 中获取图片
  1201. pictureData = ms.ToArray()
  1202. End Using
  1203. Dim pictureIndex As Integer = workbook.AddPicture(pictureData, PictureType.PNG) ' 将图片添加到工作簿中
  1204. Dim drawing As XSSFDrawing = sheet.CreateDrawingPatriarch() ' 创建绘图对象
  1205. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor() ' 创建图片锚点
  1206. anchor.Col1 = start_column ' 起始列(从 0 开始计数)
  1207. anchor.Row1 = start_row ' 起始行(从 0 开始计数)
  1208. anchor.Col2 = start_column ' 结束列
  1209. anchor.Row2 = start_row ' 结束行
  1210. Dim picture As IPicture = drawing.CreatePicture(anchor, pictureIndex) ' 插入图片
  1211. picture.Resize(0.29) ' 调整图片大小' 设置缩放比例,例如 0.29 表示缩放为原大小的 29%
  1212. Dim saveFilePath As String = "c:\GHS\output.xlsx" ' 保存文件
  1213. Using fs As New FileStream(saveFilePath, FileMode.Create, FileAccess.Write)
  1214. workbook.Write(fs)
  1215. End Using
  1216. End Sub
  1217. End Class