Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

文件.vb 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. Option Strict Off
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  5. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  7. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  8. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  9. Imports Microsoft.Office.Interop.Excel.XlWindowState
  10. Imports Microsoft.Office.Interop.Excel
  11. Imports System.IO
  12. Imports Telerik.Windows.Documents.Fixed
  13. Imports System.Text.RegularExpressions
  14. Imports Telerik.WinControls.VirtualKeyboard
  15. Public Class 文件
  16. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  17. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  18. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  19. Dim 位置1 As String : Dim 已處理字串 As String
  20. Dim N2 As Integer : Dim N3 As Integer
  21. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
  22. Dim 圖片資料庫指定, WW(14), WA(14) As String
  23. Dim DGVX As Integer
  24. Private Sub 文件_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  25. Me.MdiParent = GRAMS_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  26. RadPdfViewerNavigator1.OpenButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
  27. RadPdfViewerNavigator1.SaveButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
  28. PDF_P.BringToFront()
  29. 已核准的營運成本收支單_rb.Checked = True
  30. 作廢的營運成本收支單_rb.Checked = False
  31. Set_清單1() : Set_清單3()
  32. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = False : 發行_bt.Enabled = False : 指定人員_bt.Enabled = False
  33. End Sub
  34. Private Sub 文件_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
  35. SQL_圖片資料庫查詢() : If dr.Read() Then : 圖片資料庫指定 = dr("圖片資料庫") : Else : MsgBox("圖片資料庫已滿,請聯繫系統管理員!!!") : Me.Close() : End If
  36. End Sub
  37. Private Sub Set_清單3()
  38. Dim ds As New DataSet
  39. 人員1_dgv.DataSource = Nothing : ds.Clear()
  40. 人員1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  41. 人員1_dgv.ColumnHeadersHeight = 25
  42. 人員1_dgv.AllowUserToAddRows = False
  43. SQL_通用_人員清單()
  44. da.Fill(ds) : 人員1_dgv.DataSource = ds.Tables(0) : conn.Close()
  45. Dim chkColumn As New DataGridViewCheckBoxColumn()
  46. End Sub
  47. Private Sub Set_清單1()
  48. 控制表_dgv.DataSource = Nothing : ds1.Clear()
  49. 控制表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  50. 控制表_dgv.ColumnHeadersHeight = 25
  51. 控制表_dgv.AllowUserToAddRows = False
  52. 控制表_dgv.RowTemplate.Height = 30
  53. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  54. If 作廢的營運成本收支單_rb.Checked = True And 已核准的營運成本收支單_rb.Checked = False And 已發行的營運成本收支單_rb.Checked = False Then
  55. SQL_通用_控制表清單1()
  56. ElseIf 作廢的營運成本收支單_rb.Checked = False And 已核准的營運成本收支單_rb.Checked = True And 已發行的營運成本收支單_rb.Checked = False Then
  57. SQL_通用_控制表清單()
  58. ElseIf 作廢的營運成本收支單_rb.Checked = False And 已核准的營運成本收支單_rb.Checked = False And 已發行的營運成本收支單_rb.Checked = True Then
  59. SQL_通用_控制表清單2()
  60. End If
  61. da.Fill(ds1) : 控制表_dgv.DataSource = ds1.Tables(0) : conn.Close()
  62. 控制表_dgv.Columns(0).Visible = False : 控制表_dgv.Columns(1).FillWeight = 60 : 控制表_dgv.Columns(2).Visible = False
  63. 控制表_dgv.Columns(3).Visible = False : 控制表_dgv.Columns(4).Visible = False : 控制表_dgv.Columns(5).Visible = False
  64. 控制表_dgv.Columns(6).Visible = False : 控制表_dgv.Columns(7).Visible = False : 控制表_dgv.Columns(8).Visible = False
  65. 控制表_dgv.Columns(9).Visible = False : 控制表_dgv.Columns(10).Visible = False
  66. End Sub
  67. Private Sub Set_清單2()
  68. 人員_dgv.DataSource = Nothing : ds2.Clear()
  69. 人員_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  70. 人員_dgv.ColumnHeadersHeight = 25
  71. 人員_dgv.AllowUserToAddRows = False
  72. 人員_dgv.RowTemplate.Height = 50
  73. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  74. SQL_通用_明細表讀取()
  75. da.Fill(ds2) : 人員_dgv.DataSource = ds2.Tables(0) : conn.Close()
  76. 人員_dgv.Columns(0).Visible = False : 人員_dgv.Columns(1).FillWeight = 20 : 人員_dgv.Columns(2).Visible = False
  77. 人員_dgv.Columns(3).Visible = False : 人員_dgv.Columns(4).FillWeight = 50 : 人員_dgv.Columns(5).FillWeight = 30
  78. Dim imgColumn As DataGridViewImageColumn = TryCast(人員_dgv.Columns("圖片"), DataGridViewImageColumn)
  79. If imgColumn IsNot Nothing Then
  80. imgColumn.ImageLayout = DataGridViewImageCellLayout.Zoom
  81. End If
  82. Dim transparentImage As New Bitmap(50, 50) ' Adjust size as needed
  83. Using g As Graphics = Graphics.FromImage(transparentImage)
  84. g.Clear(Color.Transparent)
  85. End Using
  86. For i As Integer = 0 To 人員_dgv.Rows.Count - 1
  87. If 人員_dgv.Rows(i).Cells("圖片資料庫").Value.ToString <> "" And 人員_dgv.Rows(i).Cells("圖片流水號").Value.ToString <> "" Then
  88. 圖片庫 = 人員_dgv.Rows(i).Cells("圖片資料庫").Value.ToString
  89. SQL_連線字串_圖片資料庫()
  90. PA2 = 人員_dgv.Rows(i).Cells("圖片流水號").Value.ToString
  91. SQL_簽名圖()
  92. While dr.Read() = True
  93. Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  94. Dim oStream As New MemoryStream(bytes) : 人員_dgv.Rows(i).Cells("圖片").Value = Bitmap.FromStream(oStream)
  95. End While : conn.Close()
  96. Else
  97. ' Set empty value if no image is available
  98. 人員_dgv.Rows(i).Cells("圖片").Value = transparentImage
  99. End If
  100. Next
  101. End Sub
  102. Private Sub 控制表_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 控制表_dgv.CellClick
  103. If e.RowIndex = -1 Then : Else
  104. 單號_tb.Text = 控制表_dgv(2, e.RowIndex).Value.ToString
  105. Dim dateString As String = 控制表_dgv(0, e.RowIndex).Value.ToString
  106. Dim dateParts() As String = dateString.Split("/"c)
  107. Dim year As Integer = Integer.Parse(dateParts(0)) + 1911 ' 將民國年轉換為西元年
  108. Dim month As Integer = Integer.Parse(dateParts(1))
  109. Dim day As Integer = Integer.Parse(dateParts(2))
  110. Dim dateTime As New DateTime(year, month, day)
  111. 選擇日期_dtp.Value = dateTime
  112. 選擇日期_dtp.CustomFormat = "yyyy/MM/dd"
  113. 選擇日期_dtp.Format = DateTimePickerFormat.Custom
  114. 檔案名稱_tb.Text = 控制表_dgv(1, e.RowIndex).Value.ToString
  115. 主旨_tb.Text = 控制表_dgv(3, e.RowIndex).Value.ToString
  116. 說明_tb.Text = 控制表_dgv(4, e.RowIndex).Value.ToString
  117. 開單人_tb.Text = 控制表_dgv("開單人", e.RowIndex).Value.ToString
  118. 全選_cb.Checked = 控制表_dgv("全選", e.RowIndex).Value
  119. 圖片庫_tb.Text = 控制表_dgv("圖片庫", e.RowIndex).Value.ToString
  120. PA57 = 單號_tb.Text
  121. Set_清單2()
  122. If (全選_cb.Checked = True) Then
  123. For I As Integer = 0 To 人員1_dgv.Rows.Count - 1
  124. Dim skip As Boolean = False ' 用于标记是否跳过当前外层循环
  125. For II As Integer = 0 To 人員_dgv.Rows.Count - 1
  126. If 人員1_dgv.Rows(I).Cells("姓名").Value.ToString() = 人員_dgv.Rows(II).Cells("姓名").Value.ToString() Then
  127. skip = True ' 标记跳过当前外层循环
  128. Exit For ' 跳出内层循环
  129. End If
  130. Next
  131. If skip Then
  132. Continue For ' 跳过当前外层循环的当前迭代
  133. End If
  134. PA58 = 人員1_dgv.Rows(I).Cells("姓名").Value.ToString()
  135. SQL_通用_明細表新增()
  136. Next
  137. Set_清單2()
  138. End If
  139. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 發行_bt.Enabled = True : 指定人員_bt.Enabled = True
  140. PA1 = 單號_tb.Text : 圖片_pb.Image = Nothing : 圖片1_pb.Image = Nothing : Set_文件圖片()
  141. End If
  142. End Sub
  143. Private Sub 查詢_tb_Click(sender As Object, e As EventArgs) Handles 查詢_tb.Click
  144. PA56 = InputBox("請輸入要查詢的單號資料。") : Set_清單1() : PA56 = ""
  145. End Sub
  146. Private Sub 檔案名稱_tb_KeyPress(sender As Object, e As KeyPressEventArgs) Handles 檔案名稱_tb.KeyPress
  147. ' 允许字母、数字和空格,禁止其他字符
  148. If Not Char.IsLetterOrDigit(e.KeyChar) AndAlso Not Char.IsWhiteSpace(e.KeyChar) Then
  149. e.Handled = True
  150. End If
  151. End Sub
  152. Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
  153. 單號_tb.Text = "" : 檔案名稱_tb.Text = "" : 主旨_tb.Text = "" : 說明_tb.Text = "" : 開單人_tb.Text = gUserName : 全選_cb.Checked = False
  154. Dim NUM1 As Integer
  155. Dim dat1 As String
  156. 選擇日期_dtp.Value = DateTime.Now
  157. Dim selectedDate As DateTime = 選擇日期_dtp.Value
  158. Dim taiwanYear As Integer = selectedDate.Year - 1911
  159. Dim str As String = String.Format("{0}{1:00}{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  160. PA1 = String.Format("{0}/{1:00}/{2:00}", taiwanYear, selectedDate.Month, selectedDate.Day)
  161. SQL_通用_查詢第一筆單號()
  162. If dr.Read() Then : 單號_tb.Text = dr("流水號").ToString : Else : 單號_tb.Text = str & "00" : End If
  163. dat1 = 單號_tb.Text.Substring(0, 7)
  164. If dat1 <> str Then : NUM1 = 1 : Else : NUM1 = Double.Parse(單號_tb.Text.Substring(7, 2)) + 1 : End If
  165. If NUM1 < 10 Then : 單號_tb.Text = str & "0" & NUM1
  166. ElseIf NUM1 > 9 Then : 單號_tb.Text = str & NUM1
  167. End If
  168. PA = 單號_tb.Text
  169. PA10 = 圖片資料庫指定
  170. SQL_通用_新增一筆公函控制表() : conn.Close()
  171. PA57 = "" : Set_清單2()
  172. 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 發行_bt.Enabled = True : 指定人員_bt.Enabled = True
  173. 'ComboBox1.SelectedIndex = 2
  174. 'ComboBox2.SelectedIndex = 3
  175. 'ComboBox3.SelectedIndex = 7
  176. 'ComboBox4.SelectedIndex = 8
  177. End Sub
  178. Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
  179. If 單號_tb.Text = "" Then : MsgBox("請先選擇文件檔案名稱!!") : Else
  180. Dim result As DialogResult = MsgBox("是否要刪除該筆資料?", MessageBoxButtons.OKCancel)
  181. If result = DialogResult.OK Then : 圖片庫 = 圖片庫_tb.Text : SQL_連線字串_圖片資料庫() : SQL_文件圖片刪除()
  182. PA57 = 單號_tb.Text : SQL_通用_明細表刪除()
  183. SQL_通用_控制表刪除(單號_tb.Text) : conn.Close() : MsgBox("刪除成功!!")
  184. 單號_tb.Text = "" : 檔案名稱_tb.Text = "" : 主旨_tb.Text = "" : 說明_tb.Text = "" : 開單人_tb.Text = ""
  185. Set_清單1() : Set_清單2()
  186. Set_文件圖片() : 圖片_pb.Image = Nothing : 圖片1_pb.Image = Nothing
  187. 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = False : 列印_bt.Enabled = False : 發行_bt.Enabled = False : 指定人員_bt.Enabled = False
  188. End If
  189. End If
  190. End Sub
  191. Private Sub 儲存_bt_Click(sender As Object, e As EventArgs) Handles 儲存_bt.Click
  192. PA57 = 單號_tb.Text
  193. If (全選_cb.Checked = True) Then
  194. If 人員1_dgv.Rows.Count < 1 Then
  195. For I As Integer = 0 To 人員1_dgv.Rows.Count - 1
  196. PA58 = 人員1_dgv.Rows(I).Cells("姓名").Value.ToString()
  197. SQL_通用_明細表新增()
  198. Next
  199. Else
  200. For I As Integer = 0 To 人員1_dgv.Rows.Count - 1
  201. Dim skip As Boolean = False ' 用于标记是否跳过当前外层循环
  202. For II As Integer = 0 To 人員_dgv.Rows.Count - 1
  203. If 人員1_dgv.Rows(I).Cells("姓名").Value.ToString() = 人員_dgv.Rows(II).Cells("姓名").Value.ToString() Then
  204. skip = True ' 标记跳过当前外层循环
  205. Exit For ' 跳出内层循环
  206. End If
  207. Next
  208. If skip Then
  209. Continue For ' 跳过当前外层循环的当前迭代
  210. End If
  211. PA58 = 人員1_dgv.Rows(I).Cells("姓名").Value.ToString()
  212. SQL_通用_明細表新增()
  213. Next
  214. End If
  215. End If
  216. SQL_通用_控制表修改(檔案名稱_tb.Text, 主旨_tb.Text, 說明_tb.Text, 單號_tb.Text, 全選_cb.Checked) : conn.Close() : MsgBox("儲存成功!!") : Set_清單1() : Set_清單2()
  217. 'If 開單人_tb.Text = gUserName Or 登入人級別 = "00" Then
  218. ' SQL_通用_控制表修改(檔案名稱_tb.Text, 主旨_tb.Text, 說明_rtb.Text, 單號_tb.Text) : conn.Close() : MsgBox("儲存成功!!") : Set_清單1()
  219. ' If 登入人級別 <> "00" Then
  220. ' 刪除_bt.Enabled = True : 儲存_bt.Enabled = True : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  221. ' End If
  222. 'Else
  223. ' MsgBox("請確認開單人是否為本人")
  224. 'End If
  225. End Sub
  226. Private Sub 發行_bt_Click(sender As Object, e As EventArgs) Handles 發行_bt.Click
  227. SQL_通用_控制表發行(單號_tb.Text) : conn.Close() : MsgBox("發行成功!!") : Set_清單1()
  228. End Sub
  229. Private Sub 作廢_bt_Click(sender As Object, e As EventArgs) Handles 作廢_bt.Click
  230. SQL_通用_控制表作廢(單號_tb.Text) : conn.Close() : MsgBox("作廢成功!!") : Set_清單1()
  231. End Sub
  232. Private Sub 編輯人員_bt_Click(sender As Object, e As EventArgs) Handles 指定人員_bt.Click
  233. 全選_cb.Checked = False
  234. PA57 = 單號_tb.Text : 選擇人員.ShowDialog() : Set_清單2()
  235. End Sub
  236. Private Sub 作廢的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 作廢的營運成本收支單_rb.Click
  237. 作廢的營運成本收支單_rb.Checked = True : 已核准的營運成本收支單_rb.Checked = False : 已發行的營運成本收支單_rb.Checked = False
  238. Set_清單1()
  239. End Sub
  240. Private Sub 已核准的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 已核准的營運成本收支單_rb.Click
  241. 作廢的營運成本收支單_rb.Checked = False : 已核准的營運成本收支單_rb.Checked = True : 已發行的營運成本收支單_rb.Checked = False
  242. Set_清單1()
  243. End Sub
  244. Private Sub 已發行的營運成本收支單_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 已發行的營運成本收支單_rb.Click
  245. 作廢的營運成本收支單_rb.Checked = False : 已核准的營運成本收支單_rb.Checked = False : 已發行的營運成本收支單_rb.Checked = True
  246. Set_清單1()
  247. End Sub
  248. Private Sub 圖片清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 圖片清單_dgv.CellClick
  249. If e.RowIndex = -1 Then : Else : DGVX = e.RowIndex : 圖片清單讀取() : End If
  250. End Sub
  251. Private Sub 物料圖_pb_Click(sender As Object, e As EventArgs) Handles 圖片_pb.Click
  252. If IsNothing(圖片_pb.Image) = False Then
  253. If 圖片清單_dgv.Rows(DGVX).Cells("File.").Value.ToString = "JPG" Then
  254. 圖片傳遞 = 圖片_pb.Image : 圖片放大視窗.ShowDialog()
  255. Else
  256. If 版本號 = "2024050101" Or 版本號 = "2024042801" Then : MsgBox("該版本尚未開放開啟PDF,預計下個版本改板後開放(下個版本將變更成需要安裝的版本)!!") : Else
  257. PA1 = 單號_tb.Text : 圖片庫 = 圖片庫_tb.Text : PA2 = 圖片清單_dgv.Rows(DGVX).Cells("Item").Value : SQL_連線字串_圖片資料庫()
  258. Dim Str As String = System.Windows.Forms.Application.StartupPath : Dim ds1 As New DataSet : ds1.Clear() : SQL_文件圖片讀取1() : da.Fill(ds1)
  259. If ds1.Tables(0).Rows.Count > 0 Then
  260. Dim imgData() As Byte : imgData = ds1.Tables(0).Rows(0).Item("圖片")
  261. Dim fs As FileStream : fs = File.Create(Str + "\" & PA2 & ".pdf", imgData.Length - 1)
  262. fs.Write(imgData, 0, imgData.Length - 1) : fs.Close()
  263. End If : conn.Close() : PDF路徑 = Str + "\" & PA2 & ".pdf" : PDF預覽.ShowDialog()
  264. End If
  265. End If
  266. End If
  267. End Sub
  268. Private Sub 圖檔入系統_rbt_Click(sender As Object, e As EventArgs) Handles 圖檔入系統_rbt.Click
  269. If 單號_tb.Text = "" Then : MsgBox("請先選擇會議/專案項目!!") : Else
  270. PA1 = 單號_tb.Text : 圖片庫 = 圖片庫_tb.Text : SQL_連線字串_圖片資料庫()
  271. For i As Integer = 0 To NU1
  272. If WW(i) = "" Then : Else
  273. Dim 文件號 As String : Dim 文件編號 As Integer : SQL_文件圖片最後一筆編號查詢()
  274. If dr.Read() Then : 文件編號 = Double.Parse(Strings.Right(dr("項次").ToString, 2)) : Else : 文件編號 = 0 : End If
  275. conn.Close() : 文件編號 += 1
  276. If 文件編號 < 10 Then : 文件號 = "IM" & "0" & 文件編號
  277. ElseIf 文件編號 > 9 Then : 文件號 = "IM" & 文件編號 : End If
  278. PA2 = 文件號 : PA49 = WW(i) : PA3 = WA(i) : SQL_文件圖片入系統()
  279. End If
  280. Next
  281. For i As Integer = 0 To 5 : WW(i) = "" : Dim 選擇 As PictureBox = CType(Me.Controls.Find("PB" & i + 1, True)(0), PictureBox) : 選擇.Image = Nothing : Next
  282. Set_文件圖片() : MsgBox("上傳完畢!!")
  283. End If
  284. End Sub
  285. Private Sub Set_文件圖片()
  286. Dim ds6 As New DataSet : 圖片清單_dgv.DataSource = Nothing : ds6.Clear()
  287. 圖片清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  288. 圖片清單_dgv.ColumnHeadersHeight = 25 : 圖片清單_dgv.AllowUserToAddRows = False
  289. If 圖片庫_tb.Text = "" Then : 圖片庫 = 圖片資料庫指定 : Else : 圖片庫 = 圖片庫_tb.Text : End If
  290. SQL_連線字串_圖片資料庫() : SQL_文件圖片()
  291. da.Fill(ds6) : 圖片清單_dgv.DataSource = ds6.Tables(0) : conn.Close()
  292. 圖片清單_dgv.Columns(0).ReadOnly = True
  293. If 圖片清單_dgv.Rows.Count > 0 Then : DGVX = 0 : 圖片清單讀取() : Else
  294. 圖片_pb.Image = Nothing : 圖片1_pb.Image = Nothing : 圖片_P.BringToFront()
  295. 圖片1_pb.Image = My.Resources.無檔案 : 圖片_pb.SizeMode = 4
  296. End If
  297. End Sub
  298. Private Sub 圖片清單讀取()
  299. 圖片_pb.Image = Nothing : 圖片1_pb.Image = Nothing : PA1 = 單號_tb.Text : 圖片庫 = 圖片庫_tb.Text : SQL_連線字串_圖片資料庫()
  300. PA2 = 圖片清單_dgv.Rows(DGVX).Cells("Item").Value
  301. If 圖片清單_dgv.Rows(DGVX).Cells("File.").Value.ToString = "JPG" Then : 圖片_P.BringToFront()
  302. SQL_文件圖片讀取()
  303. While dr.Read() = True
  304. Dim unused As Byte() = New Byte(-1) {}
  305. Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  306. Dim oStream As New MemoryStream(bytes)
  307. 圖片_pb.Image = Bitmap.FromStream(oStream)
  308. 圖片1_pb.Image = Bitmap.FromStream(oStream)
  309. End While : conn.Close() : 圖片_pb.SizeMode = 4 : 圖片1_pb.SizeMode = 4
  310. ElseIf 圖片清單_dgv.Rows(DGVX).Cells("File.").Value.ToString <> "JPG" Then : PDF_P.BringToFront()
  311. 圖片_pb.Image = My.Resources.PDF : 圖片_pb.SizeMode = 4
  312. PA1 = 單號_tb.Text : 圖片庫 = 圖片庫_tb.Text : PA2 = 圖片清單_dgv.Rows(DGVX).Cells("Item").Value : SQL_連線字串_圖片資料庫()
  313. Dim Str As String = System.Windows.Forms.Application.StartupPath : Dim ds1 As New DataSet : ds1.Clear() : SQL_文件圖片讀取1() : da.Fill(ds1)
  314. If ds1.Tables(0).Rows.Count > 0 Then
  315. Dim imgData() As Byte : imgData = ds1.Tables(0).Rows(0).Item("圖片")
  316. Dim fs As FileStream : fs = File.Create(Str + "\" & PA2 & ".pdf", imgData.Length - 1)
  317. fs.Write(imgData, 0, imgData.Length - 1) : fs.Close()
  318. End If : conn.Close() : PDF路徑 = Str + "\" & PA2 & ".pdf" : Me.RadPdfViewer1.LoadDocument(PDF路徑)
  319. End If
  320. End Sub
  321. Private Sub 讀取資料夾路徑_rbt_Click(sender As Object, e As EventArgs) Handles 讀取資料夾路徑_rbt.Click
  322. If OpenFileDialog1.ShowDialog <> DialogResult.Cancel Then
  323. If OpenFileDialog1.FileNames.Length > 6 Then : MsgBox("選取檔案不能超過6個!!") : Else
  324. For i As Integer = 0 To 5 : WW(i) = "" : WA(i) = "" : Dim 選擇 As PictureBox = CType(Me.Controls.Find("PB" & i + 1, True)(0), PictureBox) : 選擇.Image = Nothing : Next
  325. NU1 = OpenFileDialog1.FileNames.Length - 1
  326. For i As Integer = 0 To OpenFileDialog1.FileNames.Length - 1 : WW(i) = OpenFileDialog1.FileNames(i) : Next
  327. For i As Integer = 0 To NU1
  328. Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(WW(i))
  329. For ii As Integer = 1 To 10
  330. If ii = 1 Then : 驗證 = Strings.Left(取變數, ii) : Else
  331. If Strings.Mid(取變數, ii, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, ii, 1) : End If
  332. End If
  333. Next
  334. If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or
  335. 驗證 = "JPEG" Or 驗證 = "jpeg" Then : WA(i) = "JPG"
  336. Dim 選擇 As PictureBox = CType(Me.Controls.Find("PB" & i + 1, True)(0), PictureBox) : 選擇.Image = Image.FromFile(WW(i)) : 選擇.SizeMode = 4
  337. ElseIf 驗證 = "PDF" Or 驗證 = "pdf" Then : WA(i) = "PDF"
  338. Dim 選擇 As PictureBox = CType(Me.Controls.Find("PB" & i + 1, True)(0), PictureBox) : 選擇.Image = My.Resources.PDF : 選擇.SizeMode = 4
  339. Else : WW(i) = "" : WA(i) = "" : End If
  340. Next
  341. End If
  342. End If
  343. End Sub
  344. Private Sub 查詢_tb_MouseEnter(sender As Object, e As EventArgs) Handles 查詢_tb.MouseEnter
  345. ToolTip1.SetToolTip(Me.查詢_tb, "關鍵字搜尋")
  346. End Sub
  347. Private Sub 新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
  348. ToolTip1.SetToolTip(Me.新增_bt, "新增")
  349. End Sub
  350. Private Sub 確認新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 儲存_bt.MouseEnter
  351. ToolTip1.SetToolTip(Me.儲存_bt, "儲存")
  352. End Sub
  353. Private Sub 發行_bt_MouseEnter(sender As Object, e As EventArgs) Handles 發行_bt.MouseEnter
  354. ToolTip1.SetToolTip(Me.發行_bt, "發行")
  355. End Sub
  356. Private Sub 修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 作廢_bt.MouseEnter
  357. ToolTip1.SetToolTip(Me.作廢_bt, "作廢")
  358. End Sub
  359. Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
  360. ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
  361. End Sub
  362. Private Sub 匯出EXCEL_bt_MouseEnter(sender As Object, e As EventArgs) Handles 列印_bt.MouseEnter
  363. ToolTip1.SetToolTip(Me.列印_bt, "匯出PDF")
  364. End Sub
  365. Private Sub 讀取資料夾路徑_rbt_MouseEnter(sender As Object, e As EventArgs) Handles 讀取資料夾路徑_rbt.MouseEnter
  366. ToolTip1.SetToolTip(Me.讀取資料夾路徑_rbt, "選擇電腦的資料夾路徑")
  367. End Sub
  368. Private Sub 圖檔入系統_rbt_MouseEnter(sender As Object, e As EventArgs) Handles 圖檔入系統_rbt.MouseEnter
  369. ToolTip1.SetToolTip(Me.圖檔入系統_rbt, "檔案存入系統")
  370. End Sub
  371. Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
  372. 主旨_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  373. 說明_tb.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
  374. End Sub
  375. Private Sub 列印_bt_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
  376. 'If 登入人級別 <> "00" Then
  377. ' 刪除_bt.Enabled = False : 儲存_bt.Enabled = False : 作廢_bt.Enabled = True : 列印_bt.Enabled = True : 新增_bt.Enabled = True
  378. 'End If
  379. If 檔案名稱_tb.Text = "" Then
  380. MsgBox("檔案名稱不可空白!!!")
  381. Exit Sub
  382. End If
  383. Set_清單1()
  384. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application) : xlApp.Visible = True : xlApp.DisplayAlerts = True
  385. xlApp.Application.WindowState = xlMaximized : xlBook = xlApp.Workbooks.Add : xlSheet = NewMethod(xlBook) : xlBook.Activate() : xlSheet.Activate()
  386. xlSheet.Cells(1, 1) = "黃柏翰皮膚科診所"
  387. xlSheet.Cells(2, 1) = 主旨_tb.Text
  388. Dim largeText As String = 說明_tb.Text
  389. ' 使用正则表达式去除多余的换行符
  390. Dim cleanedText As String = Regex.Replace(largeText, "(\r\n|\r|\n)+", vbCrLf)
  391. ' 现在根据换行符拆分文本
  392. Dim lines() As String = cleanedText.Split(New String() {vbCrLf}, StringSplitOptions.None)
  393. For i As Integer = 0 To lines.Count - 1
  394. 字串處理(lines(i))
  395. lines(i) = 已處理字串
  396. Next
  397. For i = 0 To Lines.Count - 1
  398. xlSheet.Cells(3 + i, 1) = lines(i)
  399. N2 = i + 3
  400. Next
  401. BB(xlApp, xlSheet)
  402. xlApp.Sheets(2).Delete : xlSheet.PageSetup.PrintArea = ""
  403. Dim pdfFolderPath As String = Path.Combine(System.Windows.Forms.Application.StartupPath, "pdf")
  404. If Not Directory.Exists(pdfFolderPath) Then
  405. Directory.CreateDirectory(pdfFolderPath)
  406. End If
  407. Dim pdfFilePath As String = Path.Combine(pdfFolderPath, 檔案名稱_tb.Text & ".pdf")
  408. xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfFilePath, XlFixedFormatQuality.xlQualityStandard, True)
  409. xlApp.Cells.Select() : xlApp.Application.WindowState = xlMinimized : xlBook.Close(False)
  410. Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
  411. Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
  412. Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
  413. xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
  414. Try
  415. Dim chromePath As String = "C:\Program Files\Google\Chrome\Application\chrome.exe"
  416. If System.IO.File.Exists(chromePath) Then
  417. Dim process As New Process()
  418. process.StartInfo.FileName = "chrome"
  419. process.StartInfo.Arguments = """" & pdfFilePath & """"
  420. process.Start()
  421. Else : Dim edgePath As String = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  422. If System.IO.File.Exists(edgePath) Then
  423. Dim process As New Process()
  424. process.StartInfo.FileName = "msedge"
  425. process.StartInfo.Arguments = """" & pdfFilePath & """"
  426. process.Start()
  427. Else
  428. Process.Start(pdfFilePath)
  429. End If
  430. End If
  431. Catch ex As Exception
  432. MsgBox("以存檔至桌面 。" & vbCrLf & "檔案名稱:" & 檔案名稱_tb.Text & ".pdf")
  433. End Try
  434. End Sub
  435. Public Sub 字串處理(ByVal 說明1 As String)
  436. Dim 前面空白數量 As Integer = 0
  437. While Strings.Right(說明1, 1) = " " : 說明1 = 說明1.Substring(0, 說明1.Length - 1) : End While
  438. While 說明1.StartsWith(" ") : 說明1 = 說明1.Substring(1) : 前面空白數量 += 1 : End While
  439. If 說明1.Contains(" ") Then
  440. Dim 空白數量() As String = 說明1.Split(" ") : Dim 中間空白數量 As Integer = 1
  441. For j As Integer = 0 To 空白數量.Length - 1 : If 空白數量(j) = "" Then : 中間空白數量 += 1 : End If : Next
  442. Dim 要去除的空白數量 As Integer = 中間空白數量 \ 2 : Dim 已去除的數量 As Integer = 0 : Dim 除2字串 As String = ""
  443. For i As Integer = 0 To 空白數量.Length - 1
  444. If 空白數量(i) = "" Then : If 已去除的數量 < 要去除的空白數量 Then : 已去除的數量 += 1 : Else : 除2字串 &= " " : End If : Else : 除2字串 &= 空白數量(i) : End If
  445. Next : 說明1 = 除2字串
  446. End If
  447. If 前面空白數量 > 0 Then : Dim 要增加的空白數量 As Integer = 前面空白數量 \ 2 : For i As Integer = 0 To 要增加的空白數量 - 1 : 說明1 = " " & 說明1 : Next : End If
  448. 已處理字串 = 說明1
  449. End Sub
  450. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  451. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  452. End Function
  453. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  454. xlSheet.Activate() ' 激活工作表
  455. myExcel.ActiveWindow.View = XlWindowView.xlPageLayoutView
  456. myExcel.Application.PrintCommunication = False
  457. With myExcel.ActiveSheet.PageSetup
  458. .PrintTitleRows = ""
  459. .PrintTitleColumns = ""
  460. End With
  461. myExcel.Application.PrintCommunication = True
  462. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  463. myExcel.Application.PrintCommunication = False
  464. With myExcel.ActiveSheet.PageSetup
  465. .LeftHeader = ""
  466. .CenterHeader = ""
  467. .RightHeader = ""
  468. .LeftFooter = ""
  469. .CenterFooter = ""
  470. .RightFooter = ""
  471. .LeftMargin = myExcel.Application.InchesToPoints(0.7)
  472. .RightMargin = myExcel.Application.InchesToPoints(0.7)
  473. .TopMargin = myExcel.Application.InchesToPoints(0.3)
  474. .BottomMargin = myExcel.Application.InchesToPoints(0.3)
  475. .HeaderMargin = myExcel.Application.InchesToPoints(0.3)
  476. .FooterMargin = myExcel.Application.InchesToPoints(0.3)
  477. .PrintHeadings = False
  478. .PrintGridlines = False
  479. .CenterHorizontally = True
  480. .CenterVertically = False
  481. .Draft = False
  482. .FirstPageNumber = xlAutomatic
  483. .BlackAndWhite = False
  484. .Zoom = False
  485. .FitToPagesWide = 0
  486. .FitToPagesTall = 0
  487. .OddAndEvenPagesHeaderFooter = False
  488. .DifferentFirstPageHeaderFooter = False
  489. .ScaleWithDocHeaderFooter = True
  490. .AlignMarginsHeaderFooter = True
  491. .EvenPage.LeftHeader.Text = ""
  492. .EvenPage.CenterHeader.Text = ""
  493. .EvenPage.RightHeader.Text = ""
  494. .EvenPage.LeftFooter.Text = ""
  495. .EvenPage.CenterFooter.Text = ""
  496. .EvenPage.RightFooter.Text = ""
  497. .FirstPage.LeftHeader.Text = ""
  498. .FirstPage.CenterHeader.Text = ""
  499. .FirstPage.RightHeader.Text = ""
  500. .FirstPage.LeftFooter.Text = ""
  501. .FirstPage.CenterFooter.Text = ""
  502. .FirstPage.RightFooter.Text = ""
  503. End With
  504. myExcel.Application.PrintCommunication = True
  505. xlSheet.Cells.Select()
  506. With myExcel.Selection.Font
  507. .Name = "微軟正黑體"
  508. .Size = 14
  509. .Strikethrough = False
  510. .Superscript = False
  511. .Subscript = False
  512. .OutlineFont = False
  513. .Shadow = False
  514. .Underline = xlUnderlineStyleNone
  515. .ThemeColor = xlThemeColorLight1
  516. .TintAndShade = 0
  517. .ThemeFont = xlThemeFontNone
  518. End With
  519. xlSheet.Columns("A:A").ColumnWidth = 80
  520. xlSheet.Columns("A:A").Select
  521. With myExcel.Selection
  522. .HorizontalAlignment = xlGeneral
  523. .VerticalAlignment = xlCenter
  524. .WrapText = True
  525. .Orientation = 0
  526. .AddIndent = False
  527. .IndentLevel = 0
  528. .ShrinkToFit = False
  529. .ReadingOrder = xlContext
  530. .MergeCells = False
  531. End With
  532. xlSheet.Range("A1").Select()
  533. With myExcel.Selection
  534. .HorizontalAlignment = xlCenter
  535. .VerticalAlignment = xlCenter
  536. .WrapText = True
  537. .Orientation = 0
  538. .AddIndent = False
  539. .IndentLevel = 0
  540. .ShrinkToFit = False
  541. .ReadingOrder = xlContext
  542. .MergeCells = False
  543. End With
  544. With myExcel.Selection.Font
  545. .Name = "微軟正黑體"
  546. .Size = 20
  547. .Strikethrough = False
  548. .Superscript = False
  549. .Subscript = False
  550. .OutlineFont = False
  551. .Shadow = False
  552. .Underline = xlUnderlineStyleNone
  553. .ThemeColor = xlThemeColorLight1
  554. .TintAndShade = 0
  555. .ThemeFont = xlThemeFontNone
  556. .Bold = True
  557. End With
  558. xlSheet.Range("A2").Select()
  559. With myExcel.Selection
  560. .HorizontalAlignment = xlCenter
  561. .VerticalAlignment = xlCenter
  562. .WrapText = True
  563. .Orientation = 0
  564. .AddIndent = False
  565. .IndentLevel = 0
  566. .ShrinkToFit = False
  567. .ReadingOrder = xlContext
  568. .MergeCells = False
  569. End With
  570. With myExcel.Selection.Font
  571. .Name = "微軟正黑體"
  572. .Size = 18
  573. .Strikethrough = False
  574. .Superscript = False
  575. .Subscript = False
  576. .OutlineFont = False
  577. .Shadow = False
  578. .Underline = xlUnderlineStyleNone
  579. .ThemeColor = xlThemeColorLight1
  580. .TintAndShade = 0
  581. .ThemeFont = xlThemeFontNone
  582. .Bold = True
  583. End With
  584. xlSheet.Rows("1:1").EntireRow.AutoFit
  585. xlSheet.Rows(1).RowHeight = xlSheet.Rows(1).RowHeight + 5
  586. xlSheet.Rows("2:2").EntireRow.AutoFit
  587. xlSheet.Rows(2).RowHeight = xlSheet.Rows(1).RowHeight + 5
  588. For i = 3 To N2
  589. xlSheet.Rows(i & ":" & i).Select
  590. xlSheet.Rows(i & ":" & i).EntireRow.AutoFit
  591. If xlSheet.Rows(i).RowHeight + 5 > 409 Then
  592. xlSheet.Rows(i).RowHeight = 409
  593. Else
  594. xlSheet.Rows(i).RowHeight = xlSheet.Rows(i).RowHeight + 5
  595. End If
  596. Next
  597. End Sub
  598. End Class