123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254 |
- Imports NPOI.XSSF.UserModel
- Imports NPOI.SS.UserModel
- Imports System.IO
- Imports System.Data.SqlClient
- Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
- Imports Microsoft.Office.Interop.Excel.Constants
- Imports Microsoft.Office.Interop.Excel.XlBordersIndex
- Imports Microsoft.Office.Interop.Excel.XlLineStyle
- Imports Microsoft.Office.Interop.Excel.XlBorderWeight
- Imports Microsoft.Office.Interop.Excel.XlPrintLocation
- Imports Microsoft.Office.Interop.Excel.XlPageOrientation
- Imports Microsoft.Office.Interop.Excel.XlOrder
- Imports Microsoft.Office.Interop.Excel.XlPrintErrors
- Imports Microsoft.Office.Core
- Imports System.ComponentModel
- Imports Microsoft.Office.Interop
- Imports System.Drawing.Imaging
- Imports System.Windows.Media.Media3D
- Imports System.Text.RegularExpressions
- Public Class Frm_00_Retan_rcp
- Private originalLocation As Point ' 声明全局变量来存储原始位置和大小
- Private originalSize As Size
- Private isMaximized As Boolean = False ' 用于标记当前是否是放大状态
- Dim dt1 As New DataTable
- Dim gWeight(), gPrice() As Double
- Dim gCoin(), sql_rcp, sql_print As String
- Dim rr As String = "" : Dim rcp_name As String = ""
- Dim gAddfromOther As Boolean = False
- Dim dt_print As DataTable
- Dim DT2 As New DataTable
- Dim colorArray(10) As Color
- Dim card As String = "" : Dim cust As String = "" : Dim thickness As String = "" : Dim r_type As String = ""
- Dim source As String = "" : Dim comment As String = "" : Dim color1 As String = ""
- Dim wb_weight As Double = 0
- Private Sub Set_清單1(queryname As String)
- Dim ds1 As New DataSet
- 處方清單_dgv.DataSource = Nothing : ds1.Clear()
- 處方清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 處方清單_dgv.ColumnHeadersHeight = 30 : 處方清單_dgv.AllowUserToAddRows = False : 處方清單_dgv.RowTemplate.Height = 20
- 處方清單_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect
- SQL_染色處方清單(queryname)
- da.Fill(ds1) : 處方清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
- 處方清單_dgv.Columns(0).FillWeight = 80 : 處方清單_dgv.Columns(1).FillWeight = 280 : 處方清單_dgv.Columns(2).FillWeight = 120
- 處方清單_dgv.Columns(3).FillWeight = 55 : 處方清單_dgv.Columns(4).FillWeight = 105 : 處方清單_dgv.Columns(5).FillWeight = 55
- 處方清單_dgv.Columns(6).FillWeight = 75 : 處方清單_dgv.Columns(7).FillWeight = 55 : 處方清單_dgv.Columns(8).FillWeight = 145
- For i As Integer = 0 To 處方清單_dgv.Columns.Count - 1 : 處方清單_dgv.Columns(i).ReadOnly = True : Next
- Dim selectedRowIndex As Integer = 處方清單_dgv.CurrentRow?.Index
- Dim selectedColumnIndex As Integer = 處方清單_dgv.CurrentCell?.ColumnIndex ' 保存当前选中的行和列
- If selectedRowIndex >= 0 AndAlso selectedRowIndex < 處方清單_dgv.Rows.Count Then ' 如果之前有选中行,刷新后重新选中
- 處方清單_dgv.CurrentCell = 處方清單_dgv.Rows(selectedRowIndex).Cells(selectedColumnIndex)
- Else : 處方清單_dgv.CurrentCell = 處方清單_dgv.Rows(0).Cells(0) : End If
- '--------指定顏色--------------------------------------------------------------
- If 處方清單_dgv.Rows.Count < 2 Then Exit Sub ' 若資料筆數過少則不執行
- Dim p(處方清單_dgv.Rows.Count - 1) As Integer : Dim c As Integer = 0 : p(0) = 0
- For x = 1 To 處方清單_dgv.Rows.Count - 1 ' 修正範圍,避免 -2 的問題
- If Not 處方清單_dgv.Rows(x).Cells(0).Value Is Nothing AndAlso Not 處方清單_dgv.Rows(x - 1).Cells(0).Value Is Nothing AndAlso
- 處方清單_dgv.Rows(x).Cells(0).Value.ToString <> 處方清單_dgv.Rows(x - 1).Cells(0).Value.ToString Then : c += 1 : p(c) = x
- End If
- Next : c += 1 : p(c) = 處方清單_dgv.Rows.Count : ReDim Preserve p(c) ' 確保最後一組範圍正確
- If c = 1 Then : For z As Integer = 0 To 處方清單_dgv.Rows.Count - 1 : 處方清單_dgv.Rows(z).DefaultCellStyle.BackColor = colorArray(1) : Next : Else
- For cc As Integer = 0 To c - 1 ' 修正範圍
- Dim startIdx As Integer = p(cc) : Dim endIdx As Integer = If(cc + 1 < c, p(cc + 1) - 1, 處方清單_dgv.Rows.Count - 1)
- For z As Integer = startIdx To endIdx : 處方清單_dgv.Rows(z).DefaultCellStyle.BackColor = colorArray(cc Mod 5) : Next
- Next
- End If
- 建立日期_lb.Text = "" : 片数_lb.Text = "" : 选级_lb.Text = "" : 流程卡号_lb.Text = "" : 重量_lb.Text = "" : 平均_lb.Text = ""
- End Sub
- Private Sub Frm_00HF_Retan_Rcp_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Me.MdiParent = FrmMDI : Me.WindowState = 2 : Me.AutoScroll = True
- FrmMDI.WindowState = FormWindowState.Maximized : Panel1.SendToBack()
- dgv2.CausesValidation = False : Button17.Visible = False
- 建立日期_lb.Text = "" : 片数_lb.Text = "" : 选级_lb.Text = ""
- 流程卡号_lb.Text = "" : 重量_lb.Text = "" : 平均_lb.Text = ""
- colorArray(0) = Color.FromName("Aquamarine") : colorArray(1) = Color.FromName("azure") : colorArray(2) = Color.FromName("beige")
- colorArray(3) = Color.FromName("gainsboro") : colorArray(4) = Color.FromName("LightBlue") : colorArray(5) = Color.FromName("LightSalmon")
- End Sub
- Private Sub Frm_00HF_Retan_Rcp_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
- Application.DoEvents()
- SQL_HT_RetanRcp時間整理() : Set_清單1("")
- isMaximized = True : originalLocation = 處方_dgv.Location : originalSize = 處方_dgv.Size
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- If 模式通知_lb.Visible = True Then : 模式通知_lb.Visible = False : Else : 模式通知_lb.Visible = True : End If
- End Sub
- Private Sub 處方清單_sgv_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles 處方清單_dgv.CellMouseUp
- 模式通知_lb.ForeColor = Color.Red : Timer1.Enabled = False
- 單寧_tb.Text = "" : 烤膠_bt.Text = "" : 油脂_tb.Text = "" : 染料_tb.Text = "" : 助劑_tb.Text = "" : 丙烯酸_tb.Text = "" : 复鞣剂_tb.Text = ""
- Dim 位置 As Integer = 處方清單_dgv.CurrentRow.Index
- 品名_lb.Text = 處方清單_dgv.Rows(位置).Cells("品名").Value.ToString : 開削_lb.Text = "开削" & 處方清單_dgv.Rows(位置).Cells("开削").Value.ToString
- 片数_lb.Text = 處方清單_dgv.Rows(位置).Cells("片数").Value.ToString & " P" : 选级_lb.Text = 處方清單_dgv.Rows(位置).Cells("选级").Value.ToString
- 重量_lb.Text = 處方清單_dgv.Rows(位置).Cells("重量").Value.ToString & " KG" : 平均_lb.Text = 處方清單_dgv.Rows(位置).Cells("平均").Value.ToString & " KG"
- 建立日期_lb.Text = Strings.Format(處方清單_dgv.Rows(位置).Cells("日期").Value, "yyyy-DD-mm")
- 流程卡号_lb.Text = 處方清單_dgv.Rows(位置).Cells("流程卡号").Value.ToString
- Set_處方明細()
- End Sub
- Private Sub Set_處方明細()
- Dim ds1 As New DataSet
- 處方_dgv.DataSource = Nothing : ds1.Clear()
- 處方_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 處方_dgv.ColumnHeadersHeight = 30 : 處方_dgv.AllowUserToAddRows = False : 處方_dgv.RowTemplate.Height = 25
- 處方_dgv.SelectionMode = DataGridViewSelectionMode.CellSelect
- SQL_染色處方(處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value,
- 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("表格编号").Value)
- da.Fill(ds1) : 處方_dgv.DataSource = ds1.Tables(0) : conn.Close()
- For i As Integer = 0 To 處方_dgv.Columns.Count - 1 : 處方_dgv.Columns(i).ReadOnly = True : Next
- For I As Integer = 0 To 處方_dgv.Rows.Count - 1
- 處方_dgv.Rows(I).Cells("標記1").Value = "" : 處方_dgv.Rows(I).Cells("標記2").Value = "" : 處方_dgv.Rows(I).Cells("標記3").Value = ""
- 處方_dgv.Rows(I).Cells("標記4").Value = "" : 處方_dgv.Rows(I).Cells("標記5").Value = ""
- Next
- set_grid1() : cal_cost1()
- 處方_dgv.Columns("用量").DefaultCellStyle.Format = "#,##0.00"
- 處方_dgv.Columns("用量").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 計算(25.4)
- End Sub
- Private Sub 化工分类_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 化工分类_ch.Click
- If 化工分类_ch.Checked = False Then : 化工分类_ch.Checked = False : Else : 化工分类_ch.Checked = True : End If : set_grid1()
- End Sub
- Private Sub 系统代码_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 系统代码_ch.Click
- If 系统代码_ch.Checked = False Then : 系统代码_ch.Checked = False : Else : 系统代码_ch.Checked = True : End If : set_grid1()
- End Sub
- Private Sub 类别_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 类别_ch.Click
- If 类别_ch.Checked = False Then : 类别_ch.Checked = False : Else : 类别_ch.Checked = True : End If : set_grid1()
- End Sub
- Private Sub 进货单价_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 进货单价_ch.Click
- If 进货单价_ch.Checked = False Then : 进货单价_ch.Checked = False : Else : 进货单价_ch.Checked = True : End If : set_grid1()
- End Sub
- Private Sub zdhc_code_ch_CheckedChanged(sender As Object, e As EventArgs) Handles zdhc_code_ch.Click
- If zdhc_code_ch.Checked = False Then : zdhc_code_ch.Checked = False : Else : zdhc_code_ch.Checked = True : End If : set_grid1()
- End Sub
- Private Sub 系统分类_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 系统分类_ch.Click
- If 系统分类_ch.Checked = False Then : 系统分类_ch.Checked = False : Else : 系统分类_ch.Checked = True : End If : set_grid1()
- End Sub
- Private Sub 系统品名_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 系统品名_ch.Click
- If 系统品名_ch.Checked = False Then : 系统品名_ch.Checked = False : Else : 系统品名_ch.Checked = True : End If : set_grid1()
- End Sub
- Private Sub set_grid1()
- 處方_dgv.Columns(0).FillWeight = 80 : 處方_dgv.Columns(1).FillWeight = 200 : 處方_dgv.Columns(2).FillWeight = 120
- 處方_dgv.Columns(3).FillWeight = 80 : 處方_dgv.Columns(4).FillWeight = 80 : 處方_dgv.Columns(5).FillWeight = 80
- 處方_dgv.Columns(6).FillWeight = 200 : 處方_dgv.Columns("系统品名").FillWeight = 300
- 處方_dgv.Columns("系统代码").FillWeight = 100 : For x As Integer = 7 To 16 : 處方_dgv.Columns(x).Visible = False : Next
- 處方_dgv.Columns("化工分类").Visible = 化工分类_ch.Checked : 處方_dgv.Columns("类别").Visible = 类别_ch.Checked
- 處方_dgv.Columns("zdhc_code").Visible = zdhc_code_ch.Checked : 處方_dgv.Columns("系统品名").Visible = 系统品名_ch.Checked
- 處方_dgv.Columns("系统代码").Visible = 系统代码_ch.Checked : 處方_dgv.Columns("进货单价").Visible = 进货单价_ch.Checked
- 處方_dgv.Columns("系统分类").Visible = 系统分类_ch.Checked
- 處方_dgv.Columns("標記1").Visible = False : 處方_dgv.Columns("標記2").Visible = False : 處方_dgv.Columns("標記3").Visible = False
- 處方_dgv.Columns("標記4").Visible = False : 處方_dgv.Columns("標記5").Visible = False
- End Sub
- Private Sub cal_cost1()
- Dim selectedRowIndex As Integer = 處方清單_dgv.CurrentCell.RowIndex ' 获取 DataGridView1 中当前选中行的索引
- Dim weight As Double = Convert.ToDouble(處方清單_dgv.Rows(selectedRowIndex).Cells("重量").Value) ' 获取 DataGridView1 中选中行的 "重量"
- If Not 處方_dgv.DataSource Is Nothing Then ' 在 DataGridView2 的 DataTable 中添加一列用于存储“金额小计”
- Dim dt2 As DataTable = CType(處方_dgv.DataSource, DataTable)
- If Not dt2.Columns.Contains("用量") Then : dt2.Columns.Add("用量", GetType(Double)) : End If ' 检查是否已添加过金额小计列
- For Each row As DataRow In dt2.Rows ' 遍历 DataGridView2 中的每一行,计算金额小计
- Dim percentage As Double = Convert.ToDouble(row("百分比")) ' 获取 DataGridView2 中的百分比和进货单价
- Dim purchasePrice As Double = 0
- If Not IsDBNull(row("进货单价")) Then : purchasePrice = Convert.ToDouble(row("进货单价")) : End If ' 检查进货单价是否为 DBNull
- If purchasePrice > 0 Then ' 如果进货单价有效,计算金额小计
- Dim amount As Double = weight * purchasePrice * percentage / 100 : row("用量") = amount ' 将金额小计添加到该行
- Else : row("用量") = 0 : End If ' 如果进货单价无效,则设置金额小计为 0
- Next
- End If
- Dim groupedData = From row In 處方_dgv.Rows.Cast(Of DataGridViewRow)() ' 使用 LINQ 进行 Group By 操作,并按化工分类汇总百分比和金额小计
- Group row By category = row.Cells("系统分类").Value.ToString() Into Group
- Select category, TotalPercentage1 = Group.Sum(Function(r) Convert.ToDouble(r.Cells("百分比").Value)),
- TotalAmount1 = Group.Sum(Function(r) Convert.ToDouble(r.Cells("用量").Value))
- groupedData = groupedData.OrderBy(Function(item) item.category).ToList()
- Dim newDataTable As New DataTable() ' 创建一个新的 DataTable 来存储汇总结果
- newDataTable.Columns.Add("分类", GetType(String)) ' 分类
- newDataTable.Columns.Add("百分比", GetType(Double)) ' 汇总的百分比
- newDataTable.Columns.Add("小计", GetType(Double)) ' 汇总的金额小计
- For Each item In groupedData ' 将汇总数据添加到 DataTable
- Dim newRow As DataRow = newDataTable.NewRow() : newRow("分类") = item.category
- newRow("百分比") = Math.Round(item.TotalPercentage1, 1) : newRow("小计") = Math.Floor(item.TotalAmount1) ' 保留整数 ' 保留1位小数
- newDataTable.Rows.Add(newRow)
- Next
- Dim totalPercentage As Double = groupedData.Where(Function(g) g.category <> "").Sum(Function(g) g.TotalPercentage1) ' 计算总百分比和总金额,排除 "水" 分类
- Dim totalAmount As Double = groupedData.Where(Function(g) g.category <> "").Sum(Function(g) g.TotalAmount1)
- Dim totalRow As DataRow = newDataTable.NewRow() ' 添加总汇总行
- totalRow("分类") = "Total"
- totalRow("百分比") = Math.Round(totalPercentage, 1) ' 保留1位小数
- totalRow("小计") = Math.Floor(totalAmount) : newDataTable.Rows.Add(totalRow) ' 保留整数
- 合計_dgv.DataSource = newDataTable : 合計_dgv.ReadOnly = True ' 将结果绑定到 DataGridView3
- 合計_dgv.Columns("小计").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 合計_dgv.Columns("小计").DefaultCellStyle.Format = "N0"
- 合計_dgv.Columns("百分比").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 合計_dgv.Columns("百分比").DefaultCellStyle.Format = "N1"
- 合計_dgv.Columns("分类").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
- Dim 最後 As Integer = 合計_dgv.Rows.Count - 2 : 合計_dgv.Rows(最後).DefaultCellStyle.ForeColor = Color.Red ' 设置最后一行的字体颜色为红色
- End Sub
- Private Sub 處方_dgv_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles 處方_dgv.RowPostPaint
- If e.RowIndex + 1 > 處方_dgv.Rows.Count - 1 Then Exit Sub
- If 處方_dgv.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "PF" Then : Dim aa As String : aa = "" : End If
- If 處方_dgv.Rows(e.RowIndex + 1).Cells("化料名称").Value Is Nothing Then Exit Sub
- If Microsoft.VisualBasic.Trim(處方_dgv.Rows(e.RowIndex).Cells("zdhc_code").Value.ToString) = "" And
- 處方_dgv.Rows(e.RowIndex).Cells("系统分类").Value.ToString <> "基础材料" And Not (處方_dgv.Rows(e.RowIndex).Cells("化料名称").Value.ToString Like "水*") Then
- 處方_dgv.Rows(e.RowIndex).Cells("化工分类").Style.BackColor = Color.LightBlue
- End If
- If 處方_dgv.Rows(e.RowIndex).Cells("標記1").Value.ToString = "1" Then
- 處方_dgv.Rows(e.RowIndex).Cells("项次").Style.BackColor = Color.OrangeRed
- Else : 處方_dgv.Rows(e.RowIndex).Cells("项次").Style.BackColor = Color.White : End If
- If 處方_dgv.Rows(e.RowIndex).Cells("標記2").Value.ToString = "1" Then
- 處方_dgv.Rows(e.RowIndex).Cells("化料名称").Style.BackColor = Color.OrangeRed
- Else : 處方_dgv.Rows(e.RowIndex).Cells("化料名称").Style.BackColor = Color.White : End If
- If 處方_dgv.Rows(e.RowIndex).Cells("標記3").Value.ToString = "1" Then
- 處方_dgv.Rows(e.RowIndex).Cells("百分比").Style.BackColor = Color.OrangeRed
- Else : 處方_dgv.Rows(e.RowIndex).Cells("百分比").Style.BackColor = Color.White : End If
- If 處方_dgv.Rows(e.RowIndex).Cells("標記4").Value.ToString = "1" Then
- 處方_dgv.Rows(e.RowIndex).Cells("时间").Style.BackColor = Color.OrangeRed
- Else : 處方_dgv.Rows(e.RowIndex).Cells("时间").Style.BackColor = Color.White : End If
- If 處方_dgv.Rows(e.RowIndex).Cells("標記5").Value.ToString = "1" Then
- 處方_dgv.Rows(e.RowIndex).Cells("备注").Style.BackColor = Color.OrangeRed
- Else : 處方_dgv.Rows(e.RowIndex).Cells("备注").Style.BackColor = Color.White : End If
- Dim linePen As New Pen(Color.Red, 2)
- If e.RowIndex = 處方_dgv.Rows.Count - 1 Then
- Dim startX As Integer = IIf(處方_dgv.RowHeadersVisible, 處方_dgv.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + 處方_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 處方_dgv.HorizontalScrollingOffset - 10
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
- End If
- If 處方_dgv.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
- Dim startX As Integer = IIf(處方_dgv.RowHeadersVisible, 處方_dgv.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + 處方_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 處方_dgv.HorizontalScrollingOffset - 10
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- End If
- End Sub
- Private Sub 處方縮放_bt_Click(sender As Object, e As EventArgs) Handles 處方縮放_bt.Click
- Application.DoEvents()
- If 處方_dgv.DataSource Is Nothing Then : MsgBox("数据为空") : Exit Sub : End If
- If isMaximized = False Then
- 處方_dgv.Location = originalLocation : 處方_dgv.Size = New Size(771, SplitContainer1.Height) ' 恢复原始位置和大小 771, 897
- 處方縮放_bt.Text = "放大" : isMaximized = True ' 更新状态标记为恢复
- 查詢_bt.Enabled = True : 存檔_bt.Enabled = True : 刪除工藝_bt.Enabled = True : 另存工藝_bt.Enabled = True
- 化工分类_ch.Checked = False : 类别_ch.Checked = False : zdhc_code_ch.Checked = False : 系统品名_ch.Checked = False
- 系统代码_ch.Checked = False : 进货单价_ch.Checked = False : 系统分类_ch.Checked = False : set_grid1()
- Else
- 處方_dgv.Location = New Point(2, 90) ' 移动到左上角
- 處方_dgv.Size = New Size(1669, SplitContainer1.Height) ' 设置为放大后的大小
- 處方縮放_bt.Text = "恢复" : isMaximized = False ' 更新状态标记为放大
- 查詢_bt.Enabled = False : 存檔_bt.Enabled = False : 刪除工藝_bt.Enabled = False : 另存工藝_bt.Enabled = False
- 化工分类_ch.Checked = True : 类别_ch.Checked = True : zdhc_code_ch.Checked = True : 系统品名_ch.Checked = True
- 系统代码_ch.Checked = True : 进货单价_ch.Checked = True : 系统分类_ch.Checked = True : set_grid1()
- End If : 處方_dgv.BringToFront()
- End Sub
- Private Sub 計算_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 計算_bt.Click '计算成本
- 計算(InputBox("请输入平均尺数", "输入平均尺数"))
- End Sub
- Private Sub 計算(userInput)
- Dim avgSize As Double
- 平均尺数_tb.Text = userInput : Dim pieces As Integer
- If 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("片数").Value.ToString = "" Then
- If 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("重量").Value <> "0" Then
- pieces = CInt(處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("重量").Value) / 4.5
- ElseIf 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("重量").Value = "0" Then
- pieces = 1
- End If
- Else : pieces = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("片数").Value : End If
-
- If Double.TryParse(userInput, avgSize) AndAlso avgSize > 0 Then ' 检查输入是否有效
- Dim dt3 As New DataTable : Dim dt4 As New DataTable ' 创建一个新的 DataTable 来存储计算结果
- dt3 = DirectCast(合計_dgv.DataSource, DataTable) ' 获取 DataGridView2 的数据源并创建副本
- dt4 = dt3.Copy() ' 创建 dt3 的副本
- For x As Integer = 0 To dt4.Rows.Count - 1 ' 假设 pieces 和 userInput 已经赋值
- dt4.Rows(x).Item(2) = dt4.Rows(x).Item(2) / (pieces * userInput) ' 对副本 dt4 进行修改
- Next
- 每尺合計_dgv.DataSource = dt4 ' 将修改后的结果绑定到 dgv3
- 每尺合計_dgv.Columns("小计").DefaultCellStyle.Format = "N2" : 每尺合計_dgv.Columns("百分比").DefaultCellStyle.Format = "N1"
- 每尺合計_dgv.Columns("分类").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
- 每尺合計_dgv.Columns("小计").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
- 每尺合計_dgv.Columns("百分比").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
- Dim lastRowIndex As Integer = 每尺合計_dgv.Rows.Count - 2 : 每尺合計_dgv.Rows(lastRowIndex).DefaultCellStyle.ForeColor = Color.Red ' 设置最后一行的字体颜色为红色
- Else : MessageBox.Show("请输入有效的数字", "无效输入", MessageBoxButtons.OK, MessageBoxIcon.Warning) : End If
- End Sub
- Private Sub 插入一行_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 插入一行_bt.Click
- gMsg = MsgBox("要插入前方列請按--是" & vbCrLf & "要插入後方列請按--否" & vbCrLf & "或按取消離開", MsgBoxStyle.YesNoCancel)
- 模式通知_lb.Text = "修改模式" : Timer1.Enabled = True
- If gMsg <> MsgBoxResult.Cancel Then : FrmEditChem_Choose.ShowDialog()
- set_grid1() : cal_cost1() : 修改存檔_bt.Visible = True
- End If
- End Sub
- Private Sub 修改指定_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 修改指定_bt.Click
- 'If 處方_dgv.SelectedRows.Count = 0 Then : MsgBox("請先選擇要修改的項目") : Exit Sub : End If
- 模式通知_lb.Text = "修改模式" : Timer1.Enabled = True
- Dim f2 As New FrmEditChem_Choose : f2.Owner = Me : f2.ShowDialog()
- 修改存檔_bt.Visible = True : cmdCancelEdit.Visible = True
- If my_chem = Nothing Then : Else : 處方_dgv.Rows(處方_dgv.CurrentRow.Index).Cells("化料名称").Value = my_chem : End If
- 處方_dgv.Focus() : cal_cost1()
- End Sub
- Private Sub 刪除一行_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 刪除一行_bt.Click
- If Not (處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font Is Nothing) Then
- If 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font.Style = FontStyle.Strikeout Then
- 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font = New Font(處方_dgv.DefaultCellStyle.Font, FontStyle.Regular)
- Else : 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font = New Font(處方_dgv.DefaultCellStyle.Font, FontStyle.Strikeout) : End If
- Else : 處方_dgv.Rows(處方_dgv.CurrentRow.Index).DefaultCellStyle.Font = New Font(處方_dgv.DefaultCellStyle.Font, FontStyle.Strikeout) : End If
- 模式通知_lb.Text = "修改模式" : Timer1.Enabled = True : 模式通知_lb.ForeColor = Color.Red
- 修改存檔_bt.Visible = True : cmdCancelEdit.Visible = True
- End Sub
- Private Sub 修改存檔_bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 修改存檔_bt.Click
- Dim result As DialogResult = MessageBox.Show("存档后将会覆盖之前的的染色工艺请确认是否进行存档?", "请选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
- If result = DialogResult.Yes Then
- '-------------先讀取必要條件----------------------------------------
- Dim no1, name1, date1, spec1, weight1, selection1, rcp_no1 As String : Dim 化料 As String : Dim 百分比 As String
- Dim 時間 As String : Dim 備註 As String : Dim 項次 As Integer = 1
- no1 = "" : name1 = "" : date1 = "" : spec1 = "" : weight1 = "" : selection1 = "" : rcp_no1 = ""
- Dim 品名 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value.ToString
- Dim 日期 As String = Strings.Format(處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value, "yyyy-MM-dd")
- Dim 选级 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value.ToString
- Dim 表格编号 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("表格编号").Value.ToString
- SQL_染色處方條件讀取(品名, 日期, 选级, 表格编号)
- If dr.Read Then
- no1 = dr("no").ToString : name1 = dr("name").ToString : date1 = Convert.ToDateTime(dr("date")).ToString("yyyy-MM-dd")
- spec1 = dr("spec").ToString : weight1 = dr("weight").ToString : selection1 = dr("selection").ToString : rcp_no1 = dr("rcp_no").ToString
- End If
- '-------------刪除原本的處方----------------------------------------
- SQL_染色處方刪除(品名, 日期, 选级, 表格编号)
- '-------------將新的處方存檔----------------------------------------
- Dim sqlInsert As New Text.StringBuilder() : Dim hasData As Boolean = False ' 是否有要寫入的資料
- For i As Integer = 0 To 處方_dgv.Rows.Count - 1
- 化料 = 處方_dgv.Rows(i).Cells("化料名称").Value.ToString()
- 百分比 = 處方_dgv.Rows(i).Cells("百分比").Value.ToString()
- 時間 = 處方_dgv.Rows(i).Cells("时间").Value.ToString()
- 備註 = 處方_dgv.Rows(i).Cells("备注").Value.ToString()
- Dim cellFont As Font = 處方_dgv.Rows(i).DefaultCellStyle.Font
- If cellFont Is Nothing OrElse cellFont.Style <> FontStyle.Strikeout Then
- If hasData Then sqlInsert.AppendLine(",") ' 不是第一筆則加上逗號
- 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}')",
- no1, name1, date1, spec1, weight1, selection1, 化料, 百分比, 時間, 備註, rcp_no1, 項次)
- 項次 += 1 : hasData = True
- End If
- Next : If hasData Then : SQL_染色處方新增(sqlInsert.ToString()) : End If : MsgBox("存檔完成!!") : Set_處方明細()
- End If
- End Sub
- Private Sub 領料_bt_Click(sender As Object, e As EventArgs) Handles 領料_bt.Click '领料
- Dim processCardNo As String = InputBox("请输入流程卡号:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("流程卡号").Value)
- SQL_染色處方領料判斷(processCardNo)
- If dr.Read Then : MsgBox("該流程卡已經領過料!!") : Exit Sub : Else
- Dim my_chem As String = "" : conn.Close()
- For Each row As DataGridViewRow In 處方_dgv.Rows
- If row.Cells("类别").Value = "不列印" Then : Continue For : End If
- Dim cellFont As Font = row.DefaultCellStyle.Font
- If cellFont IsNot Nothing Then : Dim aa As String = "" : Dim fontStyle As FontStyle = cellFont.Style
- If fontStyle = FontStyle.Strikeout Then : aa = "" : End If
- Else
- If row.Cells("类别").Value = "不列印" And Not (row.Cells("化料名称").Value Like "水*") Then
- my_chem += "项次" & row.Cells("项次").Value & " " & row.Cells("化料名称").Value & vbNewLine
- End If
- End If
- Next
- If Microsoft.VisualBasic.Len(my_chem) > 0 Then
- MsgBox("以下化工品名有误:" & vbNewLine & vbNewLine & my_chem) : Exit Sub
- End If
- Dim 片數 As String = InputBox("请输入片数:", "", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("片数").Value.ToString())
- Dim inputDateString As String = InputBox("请输入日期:", "", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value.ToString())
- Dim inputDate As Date
- If Not Date.TryParse(inputDateString, inputDate) Then
- MessageBox.Show("输入的日期格式无效,请重新输入。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Exit Sub ' 退出子程序,避免后续报错
- End If
-
- Dim weightString As String = InputBox("请输入重量:", "", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("重量").Value.ToString())
- Dim weight As Double
- If Not Double.TryParse(weightString, weight) Then
- MessageBox.Show("输入的重量格式无效,请重新输入。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Exit Sub ' 退出子程序,防止后续代码执行
- End If
-
- ConnOpen()
- For Each row As DataGridViewRow In 處方_dgv.Rows ' 获取每一行的数据
- Dim no As String = row.Cells("项次").Value.ToString()
- Dim chem As String = row.Cells("系统品名").Value.ToString()
- Dim percents As String = row.Cells("百分比").Value.ToString()
- Dim time As String = If(IsDBNull(row.Cells("时间").Value), "", row.Cells("时间").Value.ToString())
- Dim comment As String = row.Cells("备注").Value.ToString()
- Dim cellFont As Font = row.DefaultCellStyle.Font ' 获取字体样式
- If cellFont IsNot Nothing Then : Else ' 插入数据到数据库(使用参数化查询)
- SQL1 = "INSERT INTO ht_retan_chem_out (item, rcp_name, chem_name,chem_code,chem_weight, outdate, weight, chem_percent, time, comment,card)
- VALUES (@item, @rcp_name, @chem_name,@chem_code,@chem_weight, @out_date, @weight, @percents, @time, @comment,@card)"
- cmd.CommandText = SQL1 : cmd.Parameters.Clear()
- cmd.Parameters.AddWithValue("@item", no) ' 使用行号作为 item
- cmd.Parameters.AddWithValue("@rcp_name", 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value)
- cmd.Parameters.AddWithValue("@chem_name", chem)
- cmd.Parameters.AddWithValue("@chem_code", row.Cells("系统代码").Value)
- cmd.Parameters.AddWithValue("@chem_weight", weight * row.Cells("百分比").Value / 100)
- cmd.Parameters.AddWithValue("@out_date", inputDate)
- cmd.Parameters.AddWithValue("@weight", weight)
- cmd.Parameters.AddWithValue("@percents", percents)
- cmd.Parameters.AddWithValue("@time", If(time = "", DBNull.Value, time)) ' 如果 time 为空,插入 DBNull
- cmd.Parameters.AddWithValue("@comment", comment)
- cmd.Parameters.AddWithValue("@card", processCardNo & " " & 片數 & "P")
- cmd.ExecuteNonQuery() ' 执行插入操作
- End If
- Next : MessageBox.Show("数据已成功保存!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information) : conn.Close()
- End If
- End Sub
- Private Sub 重新讀取_bt_Click(sender As Object, e As EventArgs) Handles 重新讀取_bt.Click
- Set_清單1("")
- End Sub
- Private Sub 打印工藝_bt_Click_1(sender As Object, e As EventArgs) Handles 打印工藝_bt.Click
- Dim xlApp As Excel.Application : Dim xlBook As Excel.Workbook : Dim xlSheet As Excel.Worksheet
- Dim my_card As String = InputBox("请输入卡号", "询问", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("流程卡号").Value)
- If my_card = "" Then Exit Sub
- Dim my_weight As String = InputBox("请输入重量", "询问", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("重量").Value)
- Dim userInput As Double : If Double.TryParse(my_weight, userInput) Then : Else : MsgBox("请输入有效的数字!") : Exit Sub : End If
- Dim my_selection As String = InputBox("请输入选级", "询问", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value)
- my_card = my_card : Dim d_no As String = InputBox("请输入鼓号", "询问")
-
- xlApp = CreateObject("Excel.Application") : xlBook = xlApp.Workbooks.Add : xlApp.DisplayAlerts = False : xlBook.Activate()
- xlBook.Parent.Windows(1).Visible = True : xlSheet = xlBook.Worksheets.Add : xlSheet.Activate() : xlApp.Visible = True
- xlApp.Application.ScreenUpdating = False : editFormat(xlApp, xlSheet) : xlApp.Visible = False
-
- xlSheet.Cells(1, 1) = "流程卡号" : xlSheet.Cells(2, 1) = "打印日期" : xlSheet.Cells(3, 1) = "皮源" : xlSheet.Cells(1, 7) = "工艺名稱"
- xlSheet.Cells(2, 6) = "規格" : xlSheet.Cells(2, 10) = "鼓号" : xlSheet.Cells(1, 12) = "染色日期" : xlSheet.Cells(2, 12) = "重量"
- xlSheet.Cells(3, 7) = "备注" : xlSheet.Cells(2, 12) = "重量" : xlSheet.Cells(3, 4) = comment : xlSheet.Cells(2, 4) = String.Format("{0:d}", DateTime.Now)
- xlSheet.Cells(1, 10) = cust & " " & color1 & "--" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value
- xlSheet.Cells(2, 7) = thickness : xlSheet.Cells(2, 11) = d_no : xlSheet.Cells(2, 14) = userInput & " 公斤" : xlSheet.Cells(1, 4) = my_card
- xlSheet.Cells(3, 4) = source : xlSheet.Cells(3, 10) = comment : xlSheet.Cells(5, 3) = "百分比" : xlSheet.Cells(5, 5) = "用量(Kgs)"
- xlSheet.Cells(5, 6) = "化 料 名 稱" : xlSheet.Cells(5, 9) = "时间" : xlSheet.Cells(5, 11) = "備註"
-
- xlSheet.Rows("5:5").Select() : xlApp.Selection.Font.Underline = xlUnderlineStyleSingle
- For i As Integer = 0 To 處方_dgv.Rows.Count - 1
- xlSheet.Cells(i + 6, 1) = Val(處方_dgv.Rows(i).Cells("项次").Value)
- xlSheet.Cells(i + 6, 3) = Math.Round(Val(處方_dgv.Rows(i).Cells("百分比").Value), 2)
- xlSheet.Cells(i + 6, 4) = "%"
- xlSheet.Cells(i + 6, 5) = Math.Round(處方_dgv.Rows(i).Cells("百分比").Value * userInput / 100, 2)
- xlSheet.Cells(i + 6, 6) = 處方_dgv.Rows(i).Cells("化料名称").Value
- xlSheet.Cells(i + 6, 9) = 處方_dgv.Rows(i).Cells("时间").Value
- xlSheet.Cells(i + 6, 11) = 處方_dgv.Rows(i).Cells("备注").Value
- xlSheet.Cells(i + 6, 10).Select()
- With xlApp.Selection : .Font.Bold = True : End With
- If 處方_dgv.Rows(i).Cells("化料名称").Value = "流水洗" Or 處方_dgv.Rows(i).Cells("化料名称").Value = "洗水" Or
- 處方_dgv.Rows(i).Cells("化料名称").Value = "排水" Or 處方_dgv.Rows(i).Cells("化料名称").Value = "轉動" Or
- 處方_dgv.Rows(i).Cells("化料名称").Value = "自動過夜" Or 處方_dgv.Rows(i).Cells("化料名称").Value = "停止" Then
- xlSheet.Rows(i + 5 & ":" & i + 5).Select() : With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlNone : End With
- xlSheet.Rows(i + 6 & ":" & i + 6).Select() : With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlDash : .Weight = xlHairline : End With
- xlSheet.Cells(i + 6, 3) = "" : xlSheet.Cells(i + 6, 4) = "" : xlSheet.Cells(i + 6, 5) = ""
- End If
- If 處方_dgv.Rows(i).Cells("时间").Value.ToString <> "" Then
- xlSheet.Rows(i + 6 & ":" & i + 6).Select() : With xlApp.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMaximum : End With
- End If
- Next i
- Dim a As Integer = xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count : Dim b As Integer = xlApp.Workbooks(1).Worksheets(1).UsedRange.Columns.Count
- Dim area As String = "A4" & ":" & Chr(b + 64) & a
- xlSheet.Range(area).Font.Size = 10 : xlSheet.Range(area).Font.Name = "Times New Roman" : xlApp.Selection.Font.Name = "Times New Roman"
- xlSheet.Columns("A:O").Select()
- With xlApp.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
- .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = XlReadingOrder.xlContext
- End With
- xlSheet.Cells(3, 4).Select() : With xlApp.Selection : .HorizontalAlignment = xlLeft : End With
- For x As Integer = 6 To a
- 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
- Next x
- xlSheet.Range("a:a").HorizontalAlignment = xlCenter : xlSheet.Range("c:c").HorizontalAlignment = xlRight
- xlSheet.Range("e:e ").HorizontalAlignment = xlCenter : xlSheet.Range("g:g").HorizontalAlignment = xlCenter
- xlSheet.Range("c:c").NumberFormatLocal = "G/通用格式" : With xlApp.ActiveSheet.PageSetup : .PrintTitleRows = "" : .PrintTitleColumns = "" : End With
- xlSheet.PageSetup.PrintArea = ""
- With xlApp.ActiveSheet.PageSetup : .TopMargin = xlApp.InchesToPoints(0.2) : .BottomMargin = xlApp.InchesToPoints(0) : .LeftMargin = xlApp.InchesToPoints(0)
- .RightMargin = xlApp.InchesToPoints(0) : .HeaderMargin = xlApp.InchesToPoints(0.511811023622047) : .FooterMargin = xlApp.InchesToPoints(0.511811023622047)
- .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = 1 : .PrintErrors = xlPrintErrorsDisplayed
- End With
- xlApp.Cells.Select() : With xlApp.Selection.Font : .Name = "Times New Roman" : End With
- xlSheet.Range("f:f").HorizontalAlignment = xlLeft : xlSheet.Range("j:j").HorizontalAlignment = xlLeft
- xlSheet.Range("a1:o3").HorizontalAlignment = xlCenter : xlApp.Visible = True : xlApp.Application.ScreenUpdating = True
- MsgBox("打印完成!!")
- End Sub
- Private Sub editFormat(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
- xlSheet.Columns("A:A").ColumnWidth = 3 : xlSheet.Columns("B:B").ColumnWidth = 1 : xlSheet.Columns("C:C").ColumnWidth = 8
- xlSheet.Columns("D:D").ColumnWidth = 1.5 : xlSheet.Columns("e:e").ColumnWidth = 9.63 : xlSheet.Columns("f:f").ColumnWidth = 14.25
- xlSheet.Columns("g:g").ColumnWidth = 3 : xlSheet.Columns("h:h").ColumnWidth = 3 : xlSheet.Columns("i:i").ColumnWidth = 3
- xlSheet.Columns("j:j").ColumnWidth = 10 : xlSheet.Columns("k:k").ColumnWidth = 10 : xlSheet.Columns("l:l").ColumnWidth = 4.5
- xlSheet.Columns("m:m").ColumnWidth = 4.5 : xlSheet.Columns("n:n").ColumnWidth = 8.25 : xlSheet.Columns("o:o").ColumnWidth = 6
- xlSheet.Range("A1:C1").Merge() '-------流程卡号-------
- xlSheet.Range("A1:C1").Borders(xlDiagonalDown).LineStyle = xlNone : xlSheet.Range("A1:C1").Borders(xlDiagonalUp).LineStyle = xlNone
- With xlSheet.Range("A1:C1").Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With xlSheet.Range("A1:C1").Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With xlSheet.Range("A1:C1").Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With xlSheet.Range("A1:C1").Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("A2:C2").Select() : myExcel.Selection.Merge() '-------打印日期-------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("A3:C3").Select() : myExcel.Selection.Merge() '-------皮源-------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("d1:f1").Select() : myExcel.Selection.Merge() '-------流程卡号1-------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("d2:e2").Select() : myExcel.Selection.Merge() '-------打印日期1-------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("f2:f2").Select() : myExcel.Selection.Merge() '-------规格1-------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("j2:j2").Select() : myExcel.Selection.Merge() '--------鼓号1
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("d3:f3").Select() : myExcel.Selection.Merge() '-------皮源
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("g3:i3").Select() : myExcel.Selection.Merge() '-------备注
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("j3:o3").Select() : myExcel.Selection.Merge() '-------备注
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("g1:i1").Select() : myExcel.Selection.Merge() '--------工艺名称
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("g2:i2").Select() : myExcel.Selection.Merge() '-------规格1
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("j1:o1").Select() : myExcel.Selection.Merge() '------工艺名称1
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("J2:j2").Select() '------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("k2:K2").Select() '------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("l2:m2").Select() : myExcel.Selection.Merge() '----------重量
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("n1:o1").Select() : myExcel.Selection.Merge() '--------
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- xlSheet.Range("n2:o2").Select() : myExcel.Selection.Merge() '-------重量
- myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .Weight = xlMedium : .ColorIndex = xlAutomatic : End With
- End Sub
- Private Sub 打印標籤_bt_Click_1(sender As Object, e As EventArgs) Handles 打印標籤_bt.Click
- Dim my_card As String : Dim my_weight As Double : Dim d_no As String
- Do
- my_card = InputBox("请输入卡号:", "查询", 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells(4).Value)
- If my_card = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub ' 立即退出子程序
- ElseIf my_card = "" Then : MsgBox("请重新输入!", vbExclamation, "错误") : Else : Exit Do
- End If
- Loop
- Do ' 验证重量输入
- Dim weightInput As String
- weightInput = InputBox("请输入重量:", "查询", 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells(3).Value)
- If weightInput = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub
- ElseIf Not IsNumeric(weightInput) Then : MsgBox("重量必须是数字,请重新输入!", vbExclamation, "错误")
- ElseIf CDbl(weightInput) <= 0 Then : MsgBox("重量必须大于0,请重新输入!", vbExclamation, "错误")
- Else : my_weight = CDbl(weightInput) : Exit Do : End If
- Loop
- Do ' 验证编号输入
- d_no = InputBox("请输入编号:", "查询", 10)
- If d_no = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub
- ElseIf d_no Like "*-*" Then
- Else : Exit Do : End If
- Loop
- Dim imagePaths As Image() = {
- My.Resources._1, My.Resources._2, My.Resources._3,
- My.Resources._4, My.Resources._5, My.Resources._6,
- My.Resources._7, My.Resources._8, My.Resources._9
- }
- Dim dataTable As New DataTable() : dataTable = 處方_dgv.DataSource
- Dim workbook As IWorkbook = New XSSFWorkbook() : Dim sheet As ISheet = workbook.CreateSheet("Chemicals") ' 创建 Excel 工作簿
- Dim imageSheet As ISheet = workbook.CreateSheet("ImageLibrary") ' 创建隐藏的图片库工作表
- Dim drawing As IDrawing = imageSheet.CreateDrawingPatriarch() ' 加载图片到图片库
- For i As Integer = 0 To imagePaths.Length - 1
- Dim image As Image = imagePaths(i) : Dim imageBytes As Byte() ' 把 Image 轉成 Byte 陣列
- Using ms As New MemoryStream()
- image.Save(ms, Imaging.ImageFormat.Jpeg) : imageBytes = ms.ToArray()
- End Using
- Dim pictureIdx As Integer = workbook.AddPicture(imageBytes, PictureType.JPEG)
- Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor() ' 插入图片到隐藏工作表
- anchor.Col1 = i + 2 ' 每张图片占一列
- anchor.Row1 = 0
- anchor.AnchorType = AnchorType.DontMoveAndResize
- Dim picture As IPicture = drawing.CreatePicture(anchor, pictureIdx)
- picture.Resize(1)
- Next
- For col As Integer = 0 To 5 : sheet.SetColumnWidth(col, 10 * 256) : Next ' 图片列宽度
- Dim currentRow As Integer = 0 ' 初始行位置
- dataTable.DefaultView.Sort = "类别 ASC, 项次 ASC"
- Dim sortedTable As DataTable = dataTable.DefaultView.ToTable()
- ProgressBar1.Visible = True : ProgressBar1.Minimum = 0
- ProgressBar1.Maximum = sortedTable.Rows.Count ' 假设 dt 是一个 DataTable
- ProgressBar1.Value = 0 ' 初始进度为 0
- For Each row As DataRow In sortedTable.Rows ' 遍历 DataTable 的每一行
- ProgressBar1.Value += 1 : Application.DoEvents()
- If row("类别") <> "不列印" Then '生成二维码图片
- Dim qrCodeImage As Image = MakeQrCode("http://www.ruitaileather.com:10494/" & Uri.EscapeDataString(row("filename").ToString()))
- Dim imageBytes As Byte() = ImageToByteArray(qrCodeImage) ' 插入二维码图片到第4列
- Dim drawingQrCode As IDrawing = sheet.CreateDrawingPatriarch()
- Dim anchorQrCode As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
- anchorQrCode.Col1 = 4 ' 第4列
- anchorQrCode.Row1 = currentRow + 7 ' 当前行
- anchorQrCode.Col2 = 5 ' 跨1列
- anchorQrCode.Row2 = currentRow + 11 ' 占用4行
- Dim qrPictureIdx As Integer = workbook.AddPicture(imageBytes, PictureType.PNG) : Dim qrPicture As IPicture = drawingQrCode.CreatePicture(anchorQrCode, qrPictureIdx)
- qrPicture.Resize(1) ' 缩放二维码
- Dim rowToInsert = sheet.CreateRow(currentRow) ' 创建行并插入数据-- 只创建一行
- rowToInsert.CreateCell(0).SetCellValue($"卡号:{my_card}") ' 在第 4 列插入卡号
- rowToInsert.CreateCell(4).SetCellValue($"项次:{row("项次")}") ' 在第 8 列插入项次
- Dim cellStyle As ICellStyle = workbook.CreateCellStyle() : Dim font As IFont = workbook.CreateFont()
- font.FontHeightInPoints = 18 : cellStyle.SetFont(font) ' 设置字体大小为 18 ' 将字体应用到样式
- Dim row1 = sheet.CreateRow(currentRow + 1) : row1.CreateCell(0).SetCellValue($"化料名称:{row("化料名称")}")
- row1.Cells(0).CellStyle = cellStyle : sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 1, currentRow + 1, 0, 4))
- Dim row2 = sheet.CreateRow(currentRow + 2) : row2.CreateCell(0).SetCellValue($"重量:{row("百分比") * my_weight / 100}")
- row2.CreateCell(3).SetCellValue($"{row("化工分类")}") : row2.Cells(0).CellStyle = cellStyle : row2.Cells(1).CellStyle = cellStyle
- Dim row3 = sheet.CreateRow(currentRow + 3) : row3.CreateCell(4).SetCellValue($"鼓号")
- Dim row4 = sheet.CreateRow(currentRow + 4) : row4.CreateCell(4).SetCellValue($"{d_no}")
- Dim row5 = sheet.CreateRow(currentRow + 5) : row5.CreateCell(3).SetCellValue("百分比") : row5.CreateCell(4).SetCellValue("下鼓重")
- Dim row6 = sheet.CreateRow(currentRow + 6) : row6.CreateCell(3).SetCellValue($"{row("百分比")}") : row6.CreateCell(4).SetCellValue($"{my_weight}")
- Dim row7 = sheet.CreateRow(currentRow + 10) : row7.CreateCell(1).SetCellValue($"{處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells(1).Value}")
- Dim row9 = sheet.CreateRow(currentRow + 12) : row9.CreateCell(1).SetCellValue($"打印时间:{DateTime.Now}")
- sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 2, currentRow + 2, 0, 2))
- sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 2, currentRow + 2, 3, 4))
- Dim cellStyle1 As ICellStyle = workbook.CreateCellStyle() ' 创建一个字体和边框样式
- cellStyle.BorderTop = BorderStyle.Double : cellStyle.BorderRight = BorderStyle.Double ' 设置外边框为粗线
- cellStyle.BorderBottom = BorderStyle.Double : cellStyle.BorderLeft = BorderStyle.Double
- ' 为 A2:E3 区域设置边框 ' 设置粗外框
- For rowX As Integer = currentRow + 1 To currentRow + 2 ' 行索引从 1 开始
- For col As Integer = 0 To 4 ' 列索引从 0 到 4 (A 到 E)
- Dim cell As ICell = sheet.GetRow(rowX).GetCell(col)
- If cell Is Nothing Then : cell = sheet.GetRow(rowX).CreateCell(col) : End If : cell.CellStyle = cellStyle
- Next
- Next
- ' 插入 d1-d9 对应的图片
- Dim rowStart As Integer = currentRow ' 图片从当前行开始
- Dim colStart1 As Integer = 0
- Dim colStart As Integer = 0 ' d1-d9 的起始列
- Dim imgPerRow As Integer = 3 ' 每行放3张图片
- Dim row_start As Integer = 0
- For i As Integer = 1 To 9 : Dim colName As String = "d" & i
- If row(colName).ToString() = "√" Then : row_start += 1
- Dim imageRes As Image = Nothing ' 取得內嵌圖片資源
- Select Case i
- Case 1 : imageRes = My.Resources._1 : Case 2 : imageRes = My.Resources._2 : Case 3 : imageRes = My.Resources._3
- Case 4 : imageRes = My.Resources._4 : Case 5 : imageRes = My.Resources._5 : Case 6 : imageRes = My.Resources._6
- Case 7 : imageRes = My.Resources._7 : Case 8 : imageRes = My.Resources._8 : Case 9 : imageRes = My.Resources._9
- End Select
- If imageRes IsNot Nothing Then
- Dim imgStream As New MemoryStream() : imageRes.Save(imgStream, Imaging.ImageFormat.Jpeg) ' 轉換圖片為 Byte 陣列
- Dim bytes As Byte() = imgStream.ToArray()
- Dim pictureIdx As Integer = workbook.AddPicture(bytes, PictureType.JPEG)
- Dim drawingMain As IDrawing = sheet.CreateDrawingPatriarch()
- Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
- anchor.Col1 = colStart
- anchor.Row1 = rowStart + 3 ' 图片放在二维码下方,开始于第5行
- anchor.Col2 = colStart + 1 ' 图片跨2列
- anchor.Row2 = rowStart + 8 ' 图片占用5行
- ' 设置偏移量(像素)
- anchor.Dx1 = 200 ' 左上角水平偏移(单位:EMU)
- anchor.Dy1 = 20000 ' 左上角垂直偏移
- anchor.Dx2 = 500 ' 右下角水平偏移
- anchor.Dy2 = 0 ' 右下角垂直偏移
- anchor.AnchorType = AnchorType.DontMoveAndResize ' 设置锚点类型,图片不随单元格变化
- Dim picture As IPicture = drawingMain.CreatePicture(anchor, pictureIdx)
- picture.Resize(1) ' 缩放比例
- colStart += 1 ' 更新列位置
- If colStart >= imgPerRow Then
- colStart1 = 1
- colStart = 0 ' 回到第一列
- rowStart += 5 ' 换行后行数增加5
- End If
- End If
- End If
- Next
- If colStart1 = 1 Then rowStart -= 5 ' 更新当前行位置,确保下一个化工占用新行
- currentRow = rowStart + 13 ' 增加行数以容纳二维码和图片
- sheet.SetRowBreak(currentRow - 1) ' 插入换页符
- End If
- Next
- Dim filePath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"卡号标签_{my_card}.xlsx")
- Using fs As New FileStream(filePath, FileMode.Create, FileAccess.Write)
- workbook.Write(fs)
- End Using
- If File.Exists(filePath) Then
- Process.Start(New ProcessStartInfo With {
- .FileName = filePath,
- .UseShellExecute = True
- })
- End If : 處方_dgv.Sort(處方_dgv.Columns("项次"), ListSortDirection.Ascending)
- End Sub
- Function ImageToByteArray(image As Image) As Byte()
- Using ms As New MemoryStream() : image.Save(ms, ImageFormat.Png) : Return ms.ToArray() : End Using
- End Function
- Private Sub 刪除工藝_bt_Click_1(sender As Object, e As EventArgs) Handles 刪除工藝_bt.Click '删除’
- Dim msg As MsgBoxResult = MsgBox("确定要删除工艺 '" & 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value & "' ? ", MsgBoxStyle.YesNoCancel)
- If msg = MsgBoxResult.Yes Then
- Dim 確認 As String = InputBox("请输入 [YES] 来完成删除!!")
- If 確認 = "YES" Then
- SQL_染色處方刪除(處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value, 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("表格编号").Value,
- 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("日期").Value) : MsgBox("工艺已删除")
- End If
- End If : Set_清單1("") : conn.Close()
- End Sub
- Private Sub 另存工藝_bt_Click(sender As Object, e As EventArgs) Handles 另存工藝_bt.Click '另存工艺
- ' 获取用户输入的日期、流程卡号、片数、批号、重量
- Dim inputDate As Date = Date.Now : Dim processCardNo As String = InputBox("请输入流程卡号:")
- SQL_染色處方流程卡號判斷(processCardNo) : If dr.Read Then : MsgBox("该流程卡已经有对应的染色工艺!!") : Exit Sub : End If
- Dim inputQuantity As String = InputBox("请输入片数:") : Dim quantity As Integer
- If Integer.TryParse(inputQuantity, quantity) Then ' 尝试将用户输入的值转换为整数
- ' 转换成功,quantity 已被赋值
- Else ' 如果转换失败,设置默认值或者根据需要进行处理
- quantity = 0 ' 设置为默认值
- End If
- Dim spec As String = InputBox("请输入厚度:") : Dim batchNo As String = InputBox("请输入蓝皮批号:")
- Dim inputweight As String = InputBox("请输入重量:") : Dim weight As Double
- If Integer.TryParse(inputweight, weight) Then ' 尝试将用户输入的值转换为整数
- ' 转换成功,weight 已被赋值
- Else ' 如果转换失败,设置默认值或者根据需要进行处理
- weight = 0 ' 设置为默认值
- End If
- Dim name As String = InputBox("请输入工艺名:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value)
- Dim rcp_no As String : SQL_染色處方流水號查詢(Strings.Format(inputDate, "yyyyMMdd"))
- If dr.Read Then
- Dim input As String = dr("rcp_no").ToString : Dim pattern As String = "(.*_)(\d+)$" ' 匹配最後的 "_" 及其後的數字
- Dim result As String = input : Dim match As Match = Regex.Match(input, pattern)
- If match.Success Then
- Dim prefix As String = match.Groups(1).Value ' "_前面的部分"
- Dim number As Integer = Integer.Parse(match.Groups(2).Value) ' "_後面的數字"
- result = prefix & (number + 1).ToString() ' 數字 +1
- End If : rcp_no = result
- Else : rcp_no = Strings.Format(inputDate, "yyyyMMdd") & "_1" : End If ' 生成 rcp_no:根据日期和流水号生成唯一的 rcp_no
- ConnOpen()
- For Each row As DataGridViewRow In 處方_dgv.Rows ' 获取每一行的数据
- Dim no As String = row.Cells("项次").Value.ToString() : Dim chem As String = row.Cells("化料名称").Value.ToString()
- Dim percents As String = row.Cells("百分比").Value.ToString() : Dim comment As String = row.Cells("备注").Value.ToString()
- Dim time As String = If(IsDBNull(row.Cells("时间").Value), "", row.Cells("时间").Value.ToString())
- SQL1 = "INSERT INTO ht_retanrcp (item, rcp_no, no, name, date, spec, weight, selection, chem, percents, time, comment)
- VALUES (@item, @rcp_no, @no, @name, @retan_date, @spec, @weight, @selection, @chem, @percents, @time, @comment)"
- cmd.CommandText = SQL1 : cmd.Parameters.Clear()
- cmd.Parameters.AddWithValue("@item", row.Index + 1) : cmd.Parameters.AddWithValue("@rcp_no", rcp_no)
- cmd.Parameters.AddWithValue("@no", processCardNo & " " & quantity & "P") : cmd.Parameters.AddWithValue("@name", name)
- cmd.Parameters.AddWithValue("@retan_date", inputDate) : cmd.Parameters.AddWithValue("@spec", spec)
- cmd.Parameters.AddWithValue("@weight", weight) : cmd.Parameters.AddWithValue("@selection", batchNo)
- cmd.Parameters.AddWithValue("@chem", chem) : cmd.Parameters.AddWithValue("@percents", percents)
- cmd.Parameters.AddWithValue("@time", If(time = "", DBNull.Value, time)) : cmd.Parameters.AddWithValue("@comment", comment)
- cmd.Parameters.AddWithValue("@process_card_no", processCardNo) : cmd.ExecuteNonQuery()
- Next : MessageBox.Show("数据已成功保存!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information) : Set_清單1("")
- End Sub
- Private Sub 存檔_bt_Click_2(sender As Object, e As EventArgs) Handles 存檔_bt.Click '修改
- Dim inputDate As Date = InputBox("请输入日期:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("日期").Value)
- Dim processCardNo As String = InputBox("请输入流程卡号:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("流程卡号").Value)
- Dim inputQuantity As Integer = InputBox("请输入片数:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("片数").Value)
- Dim spec As String = InputBox("请输入开削厚度:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("开削").Value)
- Dim batchNo As String = InputBox("请输入蓝皮批号:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("选级").Value)
- Dim weight As Double = CDbl(InputBox("请输入重量:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("重量").Value))
- Dim name As String = InputBox("请输入工艺名:",, 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells("品名").Value)
- Dim 品名 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("品名").Value
- Dim 表格编号 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("表格编号").Value
- Dim 日期 As String = 處方清單_dgv.Rows(處方清單_dgv.CurrentCell.RowIndex).Cells("日期").Value
- SQL_染色處方基本資料修改(name, inputDate, spec, weight, batchNo, processCardNo & " " & inputQuantity & "P", 品名, 表格编号, 日期)
- MsgBox("更新完成") : Set_清單1("")
- End Sub
- Private Sub 查詢_bt_Click_1(sender As Object, e As EventArgs) Handles 查詢_bt.Click
- Dim rcp1 As String = InputBox("请输入要查询的处方名称") : rcp1 = "WHERE HT_RetanRcp.name LIKE '%" & rcp1 & "%'" : Set_清單1(rcp1)
- End Sub
- Private Sub 選客戶_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonHD.CheckedChanged, RadioButtonYT.CheckedChanged, RadioButtonDB.CheckedChanged,
- RadioButtonHS.CheckedChanged, RadioButtonZY.CheckedChanged, RadioButtonXJM.CheckedChanged, RadioButtonSM.CheckedChanged, RadioButtonCW.CheckedChanged, RadioButtonJD.
- CheckedChanged, RadioButtonDCS.CheckedChanged '------------选取客户
- Dim 篩選條件 As String = CType(sender, RadioButton).Text
- If 篩選條件 <> "HD" Then
- If 篩選條件 = "ALL" Then : 篩選條件 = "" : Else : 篩選條件 = " WHERE HT_RetanRcp.name LIKE '%" & 篩選條件 & "%'" : End If
- Else
- 篩選條件 = "WHERE ((no Like '%20240224035%') OR (no Like '%20240508135%') OR (no Like '%20240703035%') OR (no Like '%20240725055%') OR
- (no Like '%20240731065%') OR (no Like '%20241006235%') OR (no Like '%20241010185%') OR (no Like '%20241010195%') OR
- (no Like '%20241012115%') OR (no Like '%20241024015%') OR (no Like '%20241024025%') OR (no Like '%20241024045%') OR
- (no Like '%20241024055%') OR (no Like '%20241024065%') OR (no Like '%20241029105%') OR (no Like '%20241030035%') OR
- (no Like '%202411001085%') OR (no Like '%20241107015%') OR (no Like '%20241107025%') OR (no Like '%20241107035%') OR
- (no Like '%20241113055%') OR (no Like '%20241113065%') OR (no Like '%20241113117%') OR (no Like '%20241118025%') OR
- (no Like '%20241119075%') OR (no Like '%20241119085%') OR (no Like '%20241125035%') OR (no Like '%20241210117%') OR
- (no Like '%20241217117%') OR (no Like '%20241217127%') OR (no Like '%WGSTR20241107%'))"
- End If
- Set_清單1(篩選條件)
- End Sub
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- '------------------------以下未整理-----------------------------------------------------------------------------------------------------------------------------------------------------
- Sub ExportToExcel()
- ' 获取输入信息
- Dim my_card As String = InputBox("请输入卡号:", "查询")
- If my_card = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub : End If
- Dim my_weight As Double = 0
- Dim weightInput As String = InputBox("请输入重量:", "查询")
- If weightInput = "" OrElse Not IsNumeric(weightInput) OrElse CDbl(weightInput) <= 0 Then : MsgBox("请输入有效的重量!", vbExclamation, "错误") : Exit Sub
- Else : my_weight = CDbl(weightInput) : End If
- Dim d_no As String = InputBox("请输入编号:", "查询")
- If d_no = "" Then : MsgBox("操作已取消。", vbInformation, "退出") : Exit Sub : End If
- ' 创建一个新的工作簿
- Dim workbook As New XSSFWorkbook() : Dim sheet As ISheet = workbook.CreateSheet("Sheet1")
- ' 数据示例(例如 DataGridView1 的行数据)
- Dim rowIndex As Integer = 0
- For x As Integer = 0 To 處方_dgv.Rows.Count - 2
- If 處方_dgv.Rows(x).Cells("类别").Value <> "不列印" Then
- Dim row As IRow = sheet.CreateRow(rowIndex)
- row.CreateCell(0).SetCellValue("卡号: " & my_card) : row.CreateCell(1).SetCellValue("编号: " & d_no)
- row.CreateCell(2).SetCellValue("重量: " & my_weight) : rowIndex += 1
- ' 插入图片(假设图片路径在 p 数组中)
- Dim pictureData As Byte() = File.ReadAllBytes("c:\GHS\1.jpg") : Dim pictureIndex As Integer = workbook.AddPicture(pictureData, PictureType.JPEG)
- ' 创建 DrawingPatriarch
- Dim drawing As XSSFDrawing = CType(sheet.CreateDrawingPatriarch(), XSSFDrawing)
- Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
- anchor.Col1 = 3 ' 图片插入列
- anchor.Row1 = rowIndex ' 图片插入行
- drawing.CreatePicture(anchor, pictureIndex) ' 插入图片
- rowIndex += 1
- End If
- Next
- ' 设置输出文件路径
- Dim outputPath As String = "C:\path\to\your\output.xlsx"
- Using fs As New FileStream(outputPath, FileMode.Create, FileAccess.Write) : workbook.Write(fs) : End Using : MsgBox("输出完成")
- End Sub
- Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
- Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
- con.ConnectionString = connstring : con.Open() : cmd.Connection = con
- dgv2.Visible = False : ListBox2.Visible = True : ListBox3.Visible = True : ListBox4.Visible = True : TextBox2.Visible = True : TextBox3.Visible = True
- TextBox4.Visible = True : Button11.Visible = True : Button12.Visible = True : Button13.Visible = True : Button14.Visible = True : Button15.Visible = True
- sql = "select cust_name from customer order by cust_name"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox2.Items.Add(dr("cust_name")) : End While : dr.Close()
- sql = "select prod_name from tblproduct order by prod_name"
- cmd.CommandText = sql : dr = cmd.ExecuteReader
- While dr.Read : ListBox3.Items.Add(dr("prod_name")) : End While : dr.Close()
- sql = "select color_name from color order by color_name"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox4.Items.Add(dr("color_name")) : End While : dr.Close() : Timer1.Enabled = True
- End Sub
- Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp
- Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
- con.ConnectionString = connstring : con.Open() : cmd.Connection = con
- ListBox2.Items.Clear()
- sql = "select cust_name from customer where cust_name like '%" & TextBox2.Text & "%'"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox2.Items.Add(dr("cust_name")) : End While : dr.Close()
- If e.KeyCode = Keys.Enter Then
- If ListBox2.Items.Count = 0 Then Exit Sub : ListBox2.Focus() : ListBox2.SelectedIndex = 1
- End If
- End Sub
- Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp
- Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
- con.ConnectionString = connstring : con.Open() : cmd.Connection = con
- ListBox3.Items.Clear()
- sql = "select prod_name from tblproduct where prod_name like '%" & TextBox3.Text & "%'"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox3.Items.Add(dr("prod_name")) : End While : dr.Close()
- If e.KeyCode = Keys.Enter Then
- If ListBox3.Items.Count = 0 Then Exit Sub : ListBox3.Focus() : ListBox3.SelectedIndex = 1
- End If
- End Sub
- Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyUp
- Dim con As New SqlConnection : Dim sql As String : Dim dr As SqlDataReader
- con.ConnectionString = connstring : con.Open() : cmd.Connection = con
- ListBox4.Items.Clear()
- sql = "select color_name from color where color_name like '%" & TextBox4.Text & "%'"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox4.Items.Add(dr("color_name")) : End While : dr.Close()
- If e.KeyCode = Keys.Enter Then
- If ListBox3.Items.Count = 0 Then Exit Sub : ListBox4.Focus() : ListBox4.SelectedIndex = 1
- End If
- End Sub
- Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
- If ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Then : MsgBox("請先選擇客戶產品顏色", , "錯誤") : Exit Sub : End If
- Dim con As New SqlConnection
- Dim sql As String = "" : Dim rcp_no As String = "" : Dim cust_no As String = "" : Dim prod_id As String = "" : Dim color_no As String = ""
- con.ConnectionString = connstring : con.Open() : cmd.Connection = con
- sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
- cmd.CommandText = sql : cust_no = cmd.ExecuteScalar
- sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
- cmd.CommandText = sql : prod_id = cmd.ExecuteScalar
- sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
- cmd.CommandText = sql : color_no = cmd.ExecuteScalar
- 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 & "'"
- cmd.CommandText = sql : 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
- Else : rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no : End If
- sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
- cmd.CommandText = sql : c = cmd.ExecuteScalar : rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem
- rcp_name = InputBox("處方名稱", "詢問", rcp_name)
- sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
- cmd.CommandText = sql : Dim a As Integer = cmd.ExecuteScalar
- If a = 0 Then : Else : MsgBox("處方編號重覆") : gAddfromOther = False : Exit Sub : End If
- Dim msg As MsgBoxResult : msg = MsgBox("是否要由其他處方修改?", vbYesNoCancel, "詢問")
- gAddfromOther = True
- Dim my_rcp As String = "" : my_rcp = InputBox("請輸入處方編號")
- If my_rcp = "" Then Exit Sub
- 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 & "%'"
- cmd.CommandText = sql_rcp : da.SelectCommand = cmd
- Dim ds As New DataSet : da.Fill(ds) : 處方清單_dgv.DataSource = ds.Tables(0) : Timer1.Enabled = True : con.Close()
- End Sub
- Private Sub cmdAddrcp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddrcp.Click
- If conn.State = ConnectionState.Closed Then : conn.Open() : End If
- Dim sql As String = "insert into " & rcp & " (rcp_no,rcp_name,creat_d) values ( '" & rr & "','" & rcp_name & "','" & String.Format("{0:d}", DateTime.Now) & "')"
- cmd.CommandText = sql : cmd.Connection = conn : Dim b As Integer = cmd.ExecuteNonQuery
- If b <> 0 Then : MsgBox("已新增處方編號:" & rr & vbCrLf & " 處方名稱:" & rcp_name) : Else : MsgBox("新增處方失敗") : End If
- Dim dt As DataTable : dt = dgv2.DataSource
- For x As Integer = 0 To dt.Rows.Count - 1
- cmd.CommandText = "insert into rcp_content (item,matl_no,percents,rcp_no,time,comment)
- values ('" & dt.Rows(x).Item("項目").ToString & "','" & dt.Rows(x).Item("化料編號").ToString & "',
- '" & dt.Rows(x).Item("百分比").ToString & "','" & rr & "','" & dt.Rows(x).Item("时间").ToString & "',
- '" & dt.Rows(x).Item("備註").ToString & "')"
- cmd.ExecuteNonQuery()
- Next : cmdAddrcp.Visible = False : cmdcanceladd.Visible = False : Timer1.Enabled = False : 模式通知_lb.Visible = False : conn.Close()
- End Sub
- Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
- dgv2.Visible = True : ListBox2.Visible = False : ListBox3.Visible = False : ListBox4.Visible = False : TextBox2.Visible = False : TextBox3.Visible = False
- TextBox4.Visible = False : Button11.Visible = False : Button12.Visible = False : Button13.Visible = False : Button14.Visible = False : Button15.Visible = False
- Button17.Visible = False : cmdAddrcp.Visible = False : cmdcanceladd.Visible = False : Timer1.Enabled = False : 模式通知_lb.Visible = False
- End Sub
- Private Sub cmdCancelEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelEdit.Click
- 修改存檔_bt.Visible = False : cmdCancelEdit.Visible = False : Timer1.Enabled = False : 模式通知_lb.Visible = False
- End Sub
- Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- If dgv_record.Visible = False Then : dgv_record.BringToFront() : dgv_record.Visible = True : Else : dgv_record.Visible = False : End If
- End Sub
- Private Sub dgv_record_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgv_record.RowPostPaint
- Dim linePen As New Pen(Color.SkyBlue, 2)
- If e.RowIndex = dgv_record.Rows.Count - 1 Then
- dgv_record.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
- Dim startX As Integer = IIf(dgv_record.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- Exit Sub
- End If
- If dgv_record.Rows(e.RowIndex).Cells("時间").Value.ToString <> "" And (dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "流水洗" Or
- dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "洗水" Or dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value = "排水") Then
- ElseIf dgv_record.Rows(e.RowIndex).Cells("時间").Value.ToString <> "" Then
- Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + dgv_record.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- End If
- If (dgv_record.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or dgv_record.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or
- dgv_record.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
- dgv_record.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
- Dim startX As Integer = IIf(dgv_record.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + dgv_record.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- End If
- End Sub
- Private Function chem_balance(ByVal matl_no As String, ByVal quantity As Double, ByVal x As Integer, ByVal id As Integer)
- Dim conn5 As New SqlConnection : Dim dt1 As New DataTable : Dim sql As String = ""
- sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "' and quantity-w<>0"
- cmd.CommandText = sql : da.Fill(dt1)
- If dt1.Rows.Count = 0 Then
- Dim dt2 As New DataTable : sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "'"
- cmd.CommandText = sql : da.Fill(dt2)
- If dt2.Rows.Count = 0 Then
- sql = "insert into tblchem_lot (matl_no,lot_no,quantity,coin,price) values ('" & matl_no & "','120229','" & 0 & "','" & "NTD" & "','" & 0 & "')"
- cmd.CommandText = sql : cmd.ExecuteScalar()
- sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
- values ('" & dt2.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt2.Rows(0).Item("coin") & "',
- '" & dt2.Rows(0).Item("price") & "','" & id & "')"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- sql = "update tblchem_lot set w=w+'" & quantity & "'
- where lot_no='" & dt2.Rows(0).Item("lot_no") & "' and quantity ='" & dt2.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- Else
- sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
- values ('" & dt2.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt2.Rows(0).Item("coin") & "',
- '" & dt2.Rows(0).Item("price") & "','" & id & "')"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- sql = "update tblchem_lot set w=w+'" & quantity & "'
- where lot_no='" & dt2.Rows(0).Item("lot_no") & "' and quantity ='" & dt2.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- End If
- End If
- If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") - quantity > 0 Then
- sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
- values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "',
- '" & dt1.Rows(0).Item("price") & "','" & id & "')"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- sql = "update tblchem_lot set w=w+'" & quantity & "'
- where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- Else
- If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") > 0 Then
- sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
- values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "',
- '" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "'
- where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar : chem_balance(matl_no, quantity - (dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w")), x + 1, id)
- Else
- sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id)
- values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "',
- '" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "'
- where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
- cmd.CommandText = sql : dr = cmd.ExecuteScalar
- End If
- End If
- End Function
- Private Sub TXT_PID_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TXT_PID.KeyUp
- Dim sql As String = "" : Dim dr2 As SqlDataReader
- sql = "select article from leather_io where production_id='" & TXT_PID.Text & "'"
- cmd.CommandText = sql : cmd.Connection = conn
- If conn.State = ConnectionState.Closed Then : conn.Open() : End If
- dr2 = cmd.ExecuteReader : If dr2.Read Then : txtsum.Text = dr2("article") : End If
- dr2.Close() : conn.Close()
- sql = "select weight/piece as my_avg from production where production_id='" & TXT_PID.Text & "'"
- cmd.CommandText = sql : cmd.Connection = conn
- If conn.State = ConnectionState.Closed Then : conn.Open() : End If
- dr2 = cmd.ExecuteReader : If dr2.Read Then : txtwb_weight.Text = dr2("my_avg") : End If
- dr2.Close() : conn.Close()
- End Sub
- Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
- Dim sql As String = "" : cmd.Connection = conn : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
- ListBox2.Visible = True : ListBox3.Visible = True : ListBox4.Visible = True : TextBox2.Visible = True
- TextBox3.Visible = True : TextBox4.Visible = True : Button15.Visible = True
- sql = "select cust_name from customer order by cust_name"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox2.Items.Add(dr("cust_name")) : End While : dr.Close()
- sql = "select prod_name from tblproduct order by prod_name"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox3.Items.Add(dr("prod_name")) : End While : dr.Close()
- sql = "select color_name from color order by color_name"
- cmd.CommandText = sql : dr = cmd.ExecuteReader : While dr.Read : ListBox4.Items.Add(dr("color_name")) : End While : dr.Close()
- Button17.Visible = True : conn.Close()
- End Sub
- Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
- Dim sql As String = "" : Dim cust_no As String = "" : Dim prod_id As String = "" : Dim color_no As String = ""
- If cmd.Connection.State = ConnectionState.Closed Then : conn.Open() : End If
- sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
- cmd.CommandText = sql : cust_no = cmd.ExecuteScalar
- sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
- cmd.CommandText = sql : prod_id = cmd.ExecuteScalar
- sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
- cmd.CommandText = sql : color_no = cmd.ExecuteScalar
- 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 & "'"
- cmd.CommandText = sql
- 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
- Else : rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no : End If
- sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
- cmd.CommandText = sql : c = cmd.ExecuteScalar : If c <> 0 Then : MsgBox("重覆") : Exit Sub : End If
- rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem : rcp_name = InputBox("處方名稱", "詢問", rcp_name)
- sql = "insert into " & rcp & " (rcp_no,rcp_name,creat_d) values ( '" & rr & "',N'" & rcp_name & "','" & String.Format("{0:d}", DateTime.Now) & "')"
- cmd.CommandText = sql : cmd.ExecuteNonQuery()
- For x As Integer = 0 To dgv2.RowCount - 1
- If (dgv2.Rows(x).DefaultCellStyle.Font Is Nothing) Then
- Dim item As String = "" : If x <= 8 Then : item = "0" & x + 1 : Else : item = x + 1 : End If
- sql = "insert into rcp_content (item,matl_no,percents,time,comment,rcp_no)
- values ('" & item & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "',
- N'" & dgv2.Rows(x).Cells(5).Value & "','" & rr & "')"
- cmd.CommandText = sql : cmd.ExecuteNonQuery()
- Else
- If dgv2.Rows(x).DefaultCellStyle.Font.Style <> FontStyle.Strikeout Then
- Dim item As String = "" : If Microsoft.VisualBasic.Len(x) = 1 Then : item = "0" & x + 1 : Else : item = x + 1 : End If
- sql = "insert into rcp_content (item,matl_no,percents,time,comment,rcp_no)
- values ('" & item & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "',
- N'" & dgv2.Rows(x).Cells(5).Value & "','" & rr & "')"
- cmd.CommandText = sql : cmd.ExecuteNonQuery()
- End If
- End If
- Next : MsgBox("處方" & rr & rcp_name & "新增完成") : conn.Close()
- Button17.Visible = False : ListBox2.Visible = False : ListBox3.Visible = False : ListBox4.Visible = False
- TextBox2.Visible = False : TextBox3.Visible = False : TextBox4.Visible = False
- End Sub
- Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
- Dim rcp_name As String = "" : Dim sql As String = "" : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
- rcp_name = InputBox("輸入新的處方名", 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(1).Value)
- sql = "update " & rcp & " set rcp_name=N'" & rcp_name & "' where rcp_no='" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(0).Value & "'"
- cmd.Connection = conn : cmd.CommandText = sql : cmd.ExecuteScalar() : conn.Close()
- End Sub
- Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
- Dim rcp_name As String = "" : Dim sql As String = "" : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
- sql = "delete from " & rcp & " where rcp_no='" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(0).Value & "'"
- cmd.Connection = conn : cmd.CommandText = sql : cmd.ExecuteScalar() : conn.Close()
- End Sub
- Private Sub Button14_Click_1(sender As Object, e As EventArgs) Handles Button14.Click
- If ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Then : MsgBox("請先選擇客戶產品顏色", , "錯誤") : Exit Sub : End If
- 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 = ""
- con.ConnectionString = connstring : con.Open() : cmd.Connection = con
- sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
- cmd.CommandText = sql : cust_no = cmd.ExecuteScalar
- sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
- cmd.CommandText = sql : prod_id = cmd.ExecuteScalar
- sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
- cmd.CommandText = sql : color_no = cmd.ExecuteScalar
- 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 & "'"
- cmd.CommandText = sql : 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
- Else : rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no : End If
- sql = "select count(*) from prescription_main where rcp_no='" & rr & "'"
- cmd.CommandText = sql : c = cmd.ExecuteScalar
- rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem : rcp_name = InputBox("處方名稱", "詢問", rcp_name)
- sql = "select count(*) from prescription_main where rcp_no='" & rr & "'"
- cmd.CommandText = sql : Dim a As Integer = cmd.ExecuteScalar
- If a = 0 Then : Else : MsgBox("處方編號重覆") : gAddfromOther = False : Exit Sub : End If
- Dim msg As MsgBoxResult : msg = MsgBox("是否要由其他處方修改?", vbYesNoCancel, "詢問") : gAddfromOther = True
- Dim my_rcp As String = "" : my_rcp = InputBox("請輸入處方編號") : If my_rcp = "" Then Exit Sub
- sql_rcp = "select RCP_NO as 處方編號, RCP_NAME as 品名, CREAT_D, LAST_EDITED, LAST_USED from prescription_main
- where rcp_no like '%" & my_rcp & "%' or rcp_name like '%" & my_rcp & "%'"
- cmd.CommandText = sql_rcp : da.SelectCommand = cmd : Dim ds As New DataSet : da.Fill(ds)
- 處方清單_dgv.DataSource = ds.Tables(0) : Timer1.Enabled = True : con.Close()
- End Sub
- Private Sub dgv_cost_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_cost.CellEnter
- Dim ds1 As New DataSet : Dim ds2 As New DataSet : Dim cn As New SqlConnection
- cn.ConnectionString = connstring : cn.Open() : cmd.Connection = cn
- sql_rcp = "select rcp_content.ITEM AS 項目,rcp_content.MATL_NO AS 編號,tblMaterial.MATL_NAME AS 品名,rcp_content.percents AS 比例
- 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
- WHERE rcp_content.RCP_NO='" & 處方清單_dgv.Rows(處方清單_dgv.CurrentRow.Index).Cells(0).Value & "' and
- tblMaterial.MATL_ID='" & dgv_cost.Rows(dgv_cost.CurrentRow.Index).Cells(1).Value & "' order by rcp_content.item"
- cmd.CommandText = sql_rcp : da.SelectCommand = cmd : da.Fill(ds2) : dgv_chem_detail.DataSource = ds2.Tables(0)
- 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
- End Sub
- Private Sub cal_cost()
- ' 使用 LINQ 进行 Group By 操作,并取每个分组中的进货单价
- Dim groupedData = From row In DT2.AsEnumerable()
- Group row By category = row.Field(Of String)("化工分类") Into Group
- Select category,
- TotalAmount = Group.Sum(Function(r) If(IsNumeric(r.Field(Of Object)("百分比")), Convert.ToDouble(r.Field(Of Object)("百分比")), 0)),
- PurchasePrice = If(Group.Any(Function(r) IsNumeric(r.Field(Of Object)("进货单价"))),
- Convert.ToDouble(Group.Select(Function(r) r.Field(Of Object)("进货单价")).FirstOrDefault()),
- 0)
- ' 创建新的 DataTable 来存储分组后的数据
- Dim newDataTable As New DataTable()
- newDataTable.Columns.Add("Category", GetType(String)) : newDataTable.Columns.Add("TotalAmount", GetType(Double)) : newDataTable.Columns.Add("PurchasePrice", GetType(Double))
- ' 将 groupedData 中的数据插入到新的 DataTable 中
- For Each item In groupedData
- Dim newRow As DataRow = newDataTable.NewRow() : newRow("Category") = item.category : newRow("TotalAmount") = item.TotalAmount
- newRow("PurchasePrice") = item.PurchasePrice : newDataTable.Rows.Add(newRow)
- Next : 處方_dgv.DataSource = newDataTable : 處方_dgv.ReadOnly = True
- End Sub
- Private Sub dgv2_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles dgv2.RowPostPaint
- Dim linePen As New Pen(Color.Aquamarine, 2)
- If e.RowIndex = dgv2.Rows.Count - 1 Then
- dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
- Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
- End If
- If dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" And (dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "流水洗" Or
- dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "洗水" Or dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value = "排水") Then
- ElseIf dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
- Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- End If
- If (dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or
- dgv2.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
- dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
- Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
- Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
- Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
- e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
- End If
- End Sub
- Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click 'msds
- cmd.Connection = conn : If conn.State = ConnectionState.Closed Then : conn.Open() : End If
- Dim sql As String : Dim folderPath As String = "\\DS920plus\华峰业务\AA化料文件资料\2024年整理MSDS和ZDHC\MSDS\MSDS总表" ' 检查文件夹是否存在
- If Directory.Exists(folderPath) Then ' 获取文件夹内所有文件的路径
- Dim files As String() = Directory.GetFiles(folderPath) ' 遍历文件数组并输出文件名
- For Each file As String In files ' 输出文件名
- Console.WriteLine(Path.GetFileName(file))
- sql = "insert into ht_msds_file (filename) values (N'" & Path.GetFileName(file) & "')" : cmd.CommandText = sql : cmd.ExecuteScalar()
- Next
- Else : Console.WriteLine("目录不存在!") : End If : MsgBox("")
- End Sub
- Sub InsertImageWithNPOI(start_row As Integer, start_column As Integer)
- Dim workbook As New XSSFWorkbook() ' 创建 NPOI 工作簿和工作表
- Dim sheet As XSSFSheet = workbook.CreateSheet("Sheet1")
- Dim pictureData As Byte() = Nothing ' 图片数据
- Using ms As New MemoryStream()
- PictureBox1.Image.Save(ms, Imaging.ImageFormat.Png) ' 从 PictureBox1 中获取图片
- pictureData = ms.ToArray()
- End Using
- Dim pictureIndex As Integer = workbook.AddPicture(pictureData, PictureType.PNG) ' 将图片添加到工作簿中
- Dim drawing As XSSFDrawing = sheet.CreateDrawingPatriarch() ' 创建绘图对象
- Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor() ' 创建图片锚点
- anchor.Col1 = start_column ' 起始列(从 0 开始计数)
- anchor.Row1 = start_row ' 起始行(从 0 开始计数)
- anchor.Col2 = start_column ' 结束列
- anchor.Row2 = start_row ' 结束行
- Dim picture As IPicture = drawing.CreatePicture(anchor, pictureIndex) ' 插入图片
- picture.Resize(0.29) ' 调整图片大小' 设置缩放比例,例如 0.29 表示缩放为原大小的 29%
- Dim saveFilePath As String = "c:\GHS\output.xlsx" ' 保存文件
- Using fs As New FileStream(saveFilePath, FileMode.Create, FileAccess.Write)
- workbook.Write(fs)
- End Using
- End Sub
- End Class
|