Geen omschrijving
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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. Option Strict Off
  2. Imports System.IO
  3. Imports System.Net
  4. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  5. Imports Microsoft.Office.Interop.Excel.Constants
  6. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  7. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  8. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  9. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  10. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  11. Imports Microsoft.Office.Interop.Excel.XlWindowState
  12. Public Class 物料資料庫
  13. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
  14. Dim EDR, N As Integer : Dim ESTR, file_name As String
  15. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  16. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  17. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  18. Private Sub Set_DGV1開始()
  19. 物料清單_dgv.DataSource = Nothing : ds.Clear()
  20. 物料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  21. 物料清單_dgv.ColumnHeadersHeight = 40
  22. 物料清單_dgv.AllowUserToAddRows = False
  23. 物料清單_dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
  24. 物料清單_dgv.MultiSelect = True
  25. End Sub
  26. Private Sub Set_物料清單()
  27. NU1 = True : NU2 = False : Set_DGV1開始() : SQL__物料資料庫清單() : Set_DGV1結束()
  28. End Sub
  29. Private Sub Set_DGV1結束()
  30. da.Fill(ds) : 物料清單_dgv.DataSource = ds.Tables(0) : conn.Close()
  31. 物料清單_dgv.Columns(0).FillWeight = 8 : 物料清單_dgv.Columns(1).FillWeight = 6 : 物料清單_dgv.Columns(2).FillWeight = 20 : 物料清單_dgv.Columns(3).FillWeight = 5
  32. 物料清單_dgv.Columns(4).FillWeight = 5 : 物料清單_dgv.Columns(5).FillWeight = 5 : 物料清單_dgv.Columns(6).FillWeight = 10 : 物料清單_dgv.Columns(7).FillWeight = 10
  33. 物料清單_dgv.Columns(8).Visible = False : 物料清單_dgv.Columns(9).FillWeight = 10 : 物料清單_dgv.Columns(10).FillWeight = 5 : 物料清單_dgv.Columns(11).FillWeight = 3
  34. 物料清單_dgv.EditMode = DataGridViewEditMode.EditOnEnter
  35. 物料清單_dgv.Columns(3).DefaultCellStyle.Format = "#,##0" : 物料清單_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" : 物料清單_dgv.Columns(5).DefaultCellStyle.Format = "#,##0"
  36. 物料清單_dgv.Columns(10).DefaultCellStyle.Format = "#,##0"
  37. 物料清單_dgv.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : 物料清單_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
  38. 物料清單_dgv.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter : 物料清單_dgv.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  39. 物料清單_dgv.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter : 物料清單_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
  40. 物料清單_dgv.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter : 物料清單_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
  41. 物料清單_dgv.Columns(1).ReadOnly = True : 物料清單_dgv.Columns(2).ReadOnly = True : 物料清單_dgv.Columns(3).ReadOnly = True : 物料清單_dgv.Columns(4).ReadOnly = True
  42. 物料清單_dgv.Columns(5).ReadOnly = True : 物料清單_dgv.Columns(6).ReadOnly = True : 物料清單_dgv.Columns(7).ReadOnly = True : 物料清單_dgv.Columns(8).ReadOnly = True
  43. 物料清單_dgv.Columns(9).ReadOnly = True : 物料清單_dgv.Columns(11).ReadOnly = True : 物料清單_dgv.Columns(0).ReadOnly = True
  44. For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
  45. If 物料清單_dgv.Rows(i).Cells("最低庫存量").Value.ToString = "" Then
  46. 物料清單_dgv.Rows(i).Cells("最低庫存量").Value = 0
  47. End If
  48. Next
  49. End Sub
  50. Private Sub Set_未配置圖片的物料清單()
  51. 無圖料號_dgv.DataSource = Nothing : ds1.Clear()
  52. 無圖料號_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  53. 無圖料號_dgv.ColumnHeadersHeight = 25
  54. 無圖料號_dgv.AllowUserToAddRows = False
  55. 無圖料號_dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
  56. 無圖料號_dgv.MultiSelect = True
  57. SQL_未配置圖片的物料清單()
  58. da.Fill(ds1) : 無圖料號_dgv.DataSource = ds1.Tables(0) : conn.Close()
  59. 無圖料號_dgv.Columns(0).FillWeight = 10 : 無圖料號_dgv.Columns(0).ReadOnly = True
  60. End Sub
  61. Private Sub ComboBox1下拉表單資料載入()
  62. SQL_物料頁碼清單()
  63. 頁碼_cb.Items.Clear() : While (dr.Read()) : 頁碼_cb.Items.Add(dr("頁碼")) : End While : conn.Close()
  64. End Sub
  65. Private Sub 圖片導入()
  66. 物料圖_pb.Image = Nothing : PA = 圖片編碼_tb.Text : SQL_物料圖庫_圖片顯示()
  67. While dr.Read() = True
  68. Dim unused As Byte() = New Byte(-1) {}
  69. Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  70. Dim oStream As New MemoryStream(bytes)
  71. 物料圖_pb.Image = Bitmap.FromStream(oStream)
  72. End While
  73. conn.Close() : 物料圖_pb.SizeMode = 4 : PA = ""
  74. End Sub
  75. Private Sub 物料資料庫_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  76. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  77. 料號_tb.Enabled = False : 批量存檔_bt.Enabled = False
  78. 圖片編碼_tb.Visible = False : 檔名讀取_tb.Visible = False : 下載檔名_tb.Visible = False
  79. ComboBox1下拉表單資料載入() : Set_物料清單() : Set_未配置圖片的物料清單()
  80. If gUserName = "李協叡" Then : 資料刪除ToolStripMenuItem.Enabled = True : Else : 資料刪除ToolStripMenuItem.Enabled = False : End If
  81. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then : 本機資料夾_wb.Navigate(FolderBrowserDialog1.SelectedPath) : End If
  82. Target1 = Target & AA(1) & "/"
  83. FTP資料夾_wb.Url = New Uri(Target1)
  84. End Sub
  85. Private Sub 物料清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 物料清單_dgv.CellClick
  86. If e.RowIndex = -1 Then : Else
  87. 料號_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString : 頁碼_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("頁碼").Value.ToString
  88. 品名_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("品名").Value.ToString : 成本_nud.Value = 物料清單_dgv.Rows(e.RowIndex).Cells("成本").Value.ToString
  89. 售價_nud.Value = 物料清單_dgv.Rows(e.RowIndex).Cells("售價").Value.ToString : 件數_nud.Value = 物料清單_dgv.Rows(e.RowIndex).Cells("件數").Value.ToString
  90. 尺寸_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("尺寸").Value.ToString : 材質_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("材質").Value.ToString
  91. 圖片編碼_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("圖片編碼").Value.ToString : 備註_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("備註").Value.ToString
  92. 停用料號_ch.Checked = 物料清單_dgv.Rows(e.RowIndex).Cells("停用").Value : 最低庫存量_nud.Value = 物料清單_dgv.Rows(e.RowIndex).Cells("最低庫存量").Value
  93. 圖片導入()
  94. For i As Integer = 0 To 無圖料號_dgv.Rows.Count - 1
  95. If 物料清單_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString = 無圖料號_dgv.Rows(i).Cells("料號").Value.ToString Then
  96. 圖片用料號_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString : Exit For
  97. Else
  98. 圖片用料號_tb.Text = ""
  99. End If
  100. Next
  101. End If
  102. End Sub
  103. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 無圖料號_dgv.CellClick
  104. If e.RowIndex = -1 Then : Else
  105. 圖片用料號_tb.Text = 無圖料號_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString
  106. End If
  107. End Sub
  108. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 頁碼_cb.SelectedIndexChanged
  109. PA = 頁碼_cb.Text : NU1 = False : NU2 = True : Set_DGV1開始() : SQL__物料資料庫清單() : Set_DGV1結束() : PA = ""
  110. End Sub
  111. Private Sub TextBox9_DragEnter(sender As Object, e As DragEventArgs) Handles 檔案名稱_tb.DragEnter
  112. If e.Data.GetDataPresent(DataFormats.FileDrop) Then
  113. Dim files As String()
  114. Try
  115. files = CType(e.Data.GetData(DataFormats.FileDrop), String())
  116. 檔案名稱_tb.Text = files(files.Length - 1)
  117. Catch ex As Exception
  118. MessageBox.Show(ex.Message)
  119. Return
  120. End Try
  121. End If
  122. Dim STR2 As Integer = 0
  123. 檔名讀取_tb.Text = 檔案名稱_tb.Text
  124. If 檔案名稱_tb.Text = "" Then
  125. Else
  126. For i As Integer = 0 To 9999
  127. Dim STR1 As Integer = Strings.Len(檔名讀取_tb.Text)
  128. If Strings.Right((檔名讀取_tb.Text), 1) <> "\" Then
  129. STR1 -= 1 : STR2 += 1
  130. If STR1 = 0 Then
  131. 檔名讀取_tb.Text = ""
  132. 檔案名稱_tb.Text = ""
  133. i = 9999
  134. Else
  135. 檔名讀取_tb.Text = Strings.Left((檔名讀取_tb.Text), STR1)
  136. End If
  137. Else
  138. 檔名讀取_tb.Text = Strings.Right((檔案名稱_tb.Text), STR2)
  139. 檔案名稱_tb.Text = 檔名讀取_tb.Text
  140. i = 9999
  141. End If
  142. Next
  143. End If
  144. End Sub
  145. Private Sub TextBox9_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles 檔案名稱_tb.DragDrop
  146. Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
  147. For Each file As String In files
  148. 檔案名稱_tb.AppendText(file + Environment.NewLine)
  149. Next
  150. End Sub
  151. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 關鍵字查詢_bt.Click
  152. PA = InputBox("請輸入要查詢的關鍵字") : Set_物料清單()
  153. End Sub
  154. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles 新增物料資料.Click
  155. 物料清單_dgv.Enabled = False
  156. 頁碼_tb.Text = "0" : 品名_tb.Text = "" : 尺寸_tb.Text = "" : 材質_tb.Text = "" : 圖片編碼_tb.Text = "" : 備註_tb.Text = ""
  157. 成本_nud.Value = 0 : 售價_nud.Value = 0 : 件數_nud.Value = 0 : 停用料號_ch.Checked = False : ComboBox1下拉表單資料載入()
  158. '----------------------自动生成流水号-------------------------------------------------------------------------
  159. SQL_物料圖庫流水號最後一筆()
  160. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("料號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
  161. If EDR < 10 Then : ESTR = "PR" & "0000000" & EDR
  162. ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PR" & "000000" & EDR
  163. ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PR" & "00000" & EDR
  164. ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PR" & "0000" & EDR
  165. ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PR" & "000" & EDR
  166. ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PR" & "00" & EDR
  167. ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PR" & "0" & EDR
  168. ElseIf EDR > 9999999 Then : ESTR = "PR" & EDR : End If : 料號_tb.Text = ESTR
  169. MsgBox("請注意頁碼格式前三碼為數字後續再用符號-隔開,在頁碼前三碼大於999之後請通知系統開發商更新程4碼。")
  170. End Sub
  171. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 單筆存檔_bt.Click
  172. If 物料清單_dgv.Enabled = False Then
  173. If 頁碼_tb.Text = "0" Then : MsgBox("沒有輸入頁碼,請注意頁碼格式前三碼為數字後續再用符號-隔開,在頁碼前三碼大於999之後請通知系統開發商更新程4碼。")
  174. Else
  175. SQL_物料資料庫新增() : conn.Close()
  176. MsgBox("資料新增完畢 。") : Set_物料清單() : Set_未配置圖片的物料清單() : PA = "" : 物料清單_dgv.Enabled = True
  177. End If
  178. Else
  179. PA1 = 頁碼_tb.Text : PA2 = 品名_tb.Text : NU1 = 成本_nud.Value : NU2 = 售價_nud.Value : NU3 = 件數_nud.Value : PA3 = 尺寸_tb.Text : PA4 = 材質_tb.Text
  180. PA5 = 圖片編碼_tb.Text : PA6 = 備註_tb.Text : 布林1 = 停用料號_ch.Checked : PA7 = 料號_tb.Text : NU4 = 最低庫存量_nud.Value
  181. SQL_物料資料庫修改() : conn.Close()
  182. MsgBox("資料存檔完畢 。") : Set_物料清單() : PA = "" : 物料清單_dgv.Enabled = True
  183. End If
  184. End Sub
  185. Private Sub Button14_Click(sender As Object, e As EventArgs) Handles 讀取資料夾路徑_bt.Click
  186. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then : 本機資料夾_wb.Navigate(FolderBrowserDialog1.SelectedPath) : End If
  187. End Sub
  188. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles 下載圖檔_bt.Click
  189. If 圖片編碼_tb.Text = "" Then : MsgBox("所選擇的資料沒有圖片檔案,無法下載。")
  190. Else
  191. With SaveFileDialog1 : .Filter = "所有文件(*.jpg)|*.jpg" : End With
  192. SaveFileDialog1.FileName = 圖片編碼_tb.Text & "-" & Strings.Format(Today(), "yyyyMMdd") & ".jpg"
  193. SaveFileDialog1.ShowDialog() : 下載檔名_tb.Text = SaveFileDialog1.FileName
  194. ds2.Clear() : SQL_物料圖庫_圖片下載() : da.Fill(ds2) : conn.Close()
  195. If ds2.Tables(0).Rows.Count > 0 Then
  196. Dim imgData() As Byte
  197. imgData = ds2.Tables(0).Rows(0).Item("圖片")
  198. Dim fs As FileStream
  199. fs = File.Create(下載檔名_tb.Text, imgData.Length - 1)
  200. fs.Write(imgData, 0, imgData.Length - 1)
  201. fs.Close()
  202. End If : MsgBox("下載完成")
  203. End If
  204. End Sub
  205. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 刪除圖檔_bt.Click
  206. Dim aa As MsgBoxResult = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  207. If aa = MsgBoxResult.Ok Then
  208. PA = 圖片編碼_tb.Text
  209. SQL_物料圖庫_圖片刪除() : conn.Close()
  210. SQL_物料圖庫_圖片刪除後圖片編號取消() : conn.Close()
  211. MsgBox("刪除完成") : Set_物料清單() : Set_未配置圖片的物料清單() : PA = ""
  212. End If
  213. End Sub
  214. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles 圖檔入系統_bt.Click
  215. If 圖片用料號_tb.Text = "" Then : MsgBox("請先選擇未指定圖片的物料料號")
  216. Else
  217. SQL_物料圖庫_圖片新增時圖片編號註冊() : conn.Close() : SQL_物料圖庫_圖片新增() : conn.Close()
  218. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  219. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  220. frq = CType(WebRequest.Create(New Uri(Target1 & 檔案名稱_tb.Text)), FtpWebRequest)
  221. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  222. frq.Credentials = fcr
  223. frq.Method = WebRequestMethods.Ftp.DeleteFile
  224. frq.UseBinary = True
  225. frp = CType(frq.GetResponse, FtpWebResponse)
  226. frp.Close()
  227. FTP資料夾_wb.Refresh()
  228. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  229. 物料圖_pb.Image = Nothing : PA = 圖片用料號_tb.Text : SQL_物料圖庫_圖片顯示()
  230. While dr.Read() = True
  231. Dim unused As Byte() = New Byte(-1) {}
  232. Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  233. Dim oStream As New MemoryStream(bytes)
  234. 物料圖_pb.Image = Bitmap.FromStream(oStream)
  235. End While
  236. conn.Close()
  237. 物料圖_pb.SizeMode = 4
  238. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  239. 檔案名稱_tb.Text = "" : 圖片用料號_tb.Text = "" : PA = "" : Set_物料清單() : Set_未配置圖片的物料清單()
  240. End If
  241. End Sub
  242. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 修改圖片_bt.Click
  243. If 圖片編碼_tb.Text = "" Then : MsgBox("請先選擇要修改圖片的物料料號")
  244. Else
  245. SQL_物料圖庫_圖片修改()
  246. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  247. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  248. frq = CType(WebRequest.Create(New Uri(Target1 & 檔案名稱_tb.Text)), FtpWebRequest)
  249. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  250. frq.Credentials = fcr
  251. frq.Method = WebRequestMethods.Ftp.DeleteFile
  252. frq.UseBinary = True
  253. frp = CType(frq.GetResponse, FtpWebResponse)
  254. frp.Close()
  255. FTP資料夾_wb.Refresh()
  256. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  257. 檔案名稱_tb.Text = "" : MsgBox("修改完成") : Set_物料清單() : 圖片導入()
  258. End If
  259. End Sub
  260. Private Sub 格式1()
  261. 批量修改_ch.Checked = False : 批量存檔_bt.Enabled = False
  262. 物料清單_dgv.Columns(3).ReadOnly = True : 物料清單_dgv.Columns(4).ReadOnly = True : 物料清單_dgv.Columns(5).ReadOnly = True : 物料清單_dgv.Columns(6).ReadOnly = True
  263. 物料清單_dgv.Columns(7).ReadOnly = True : 物料清單_dgv.Columns(9).ReadOnly = True : 物料清單_dgv.Columns(10).ReadOnly = True
  264. End Sub
  265. Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles 批量修改_ch.Click
  266. If 批量修改_ch.Checked = False Then
  267. 格式1()
  268. Else
  269. 批量修改_ch.Checked = True : 批量存檔_bt.Enabled = True
  270. 物料清單_dgv.Columns(3).ReadOnly = False : 物料清單_dgv.Columns(4).ReadOnly = False : 物料清單_dgv.Columns(5).ReadOnly = False : 物料清單_dgv.Columns(6).ReadOnly = False
  271. 物料清單_dgv.Columns(7).ReadOnly = False : 物料清單_dgv.Columns(9).ReadOnly = False : 物料清單_dgv.Columns(10).ReadOnly = False
  272. MsgBox("請注意成本,售價,件數,三格欄位內的資料必須是阿拉伯數字,不然存檔時會出錯喔。")
  273. End If
  274. End Sub
  275. Private Sub 存檔1()
  276. For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
  277. 資料數 = 物料清單_dgv.Rows.Count : MyModule1.進度條()
  278. PA1 = 物料清單_dgv.Rows(i).Cells("頁碼").Value : PA2 = 物料清單_dgv.Rows(i).Cells("品名").Value : NU1 = 物料清單_dgv.Rows(i).Cells("成本").Value
  279. NU2 = 物料清單_dgv.Rows(i).Cells("售價").Value : NU3 = 物料清單_dgv.Rows(i).Cells("件數").Value : PA3 = 物料清單_dgv.Rows(i).Cells("尺寸").Value
  280. PA4 = 物料清單_dgv.Rows(i).Cells("材質").Value : PA5 = 物料清單_dgv.Rows(i).Cells("圖片編碼").Value : PA6 = 物料清單_dgv.Rows(i).Cells("備註").Value
  281. 布林1 = 物料清單_dgv.Rows(i).Cells("停用").Value : PA7 = 物料清單_dgv.Rows(i).Cells("料號").Value : NU4 = 物料清單_dgv.Rows(i).Cells("最低庫存量").Value
  282. SQL_物料資料庫修改() : conn.Close()
  283. Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  284. End Sub
  285. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles 批量存檔_bt.Click
  286. 存檔1() : MsgBox("修改完成") : 格式1()
  287. End Sub
  288. '-----------------------------滑鼠右鍵------------------------------------------------------------------------------------------------------------------------------------------
  289. Private Sub 重新整理ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新整理ToolStripMenuItem.Click
  290. Set_物料清單() : Set_未配置圖片的物料清單()
  291. End Sub
  292. Private Sub 關鍵字查詢ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 關鍵字查詢ToolStripMenuItem.Click
  293. Me.關鍵字查詢_bt.PerformClick()
  294. End Sub
  295. Private Sub 新增物料資料ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 新增物料資料ToolStripMenuItem.Click
  296. Me.新增物料資料.PerformClick()
  297. End Sub
  298. Private Sub 資料存檔ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 資料存檔ToolStripMenuItem.Click
  299. Me.單筆存檔_bt.PerformClick()
  300. End Sub
  301. Private Sub 下載圖片ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 下載圖片ToolStripMenuItem.Click
  302. Me.下載圖檔_bt.PerformClick()
  303. End Sub
  304. Private Sub 讀取料夾路徑ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 讀取料夾路徑ToolStripMenuItem.Click
  305. Me.讀取資料夾路徑_bt.PerformClick()
  306. End Sub
  307. Private Sub 圖檔入系統ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 圖檔入系統ToolStripMenuItem.Click
  308. Me.圖檔入系統_bt.PerformClick()
  309. End Sub
  310. Private Sub 圖片修改ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 圖片修改ToolStripMenuItem.Click
  311. Me.修改圖片_bt.PerformClick()
  312. End Sub
  313. Private Sub 刪除圖檔ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 刪除圖檔ToolStripMenuItem.Click
  314. Me.刪除圖檔_bt.PerformClick()
  315. End Sub
  316. Private Sub 刪除物料ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 資料刪除ToolStripMenuItem.Click
  317. Dim aa As MsgBoxResult
  318. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  319. If aa = MsgBoxResult.Ok Then
  320. PA = 料號_tb.Text
  321. SQL_物料圖庫_圖片刪除() : conn.Close() : SQL_物料資料庫刪除() : conn.Close()
  322. MsgBox("刪除完成") : Set_物料清單() : Set_未配置圖片的物料清單() : PA = ""
  323. End If
  324. End Sub
  325. Private Sub 批量修改_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 批量修改_ch.CheckedChanged
  326. End Sub
  327. Private Sub 導出EXCEL_bt_Click_1(sender As Object, e As EventArgs) Handles 導出EXCEL_bt.Click
  328. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  329. xlBook = xlApp.Workbooks.Add
  330. xlApp.DisplayAlerts = True
  331. xlBook.Activate()
  332. xlSheet = NewMethod(xlBook)
  333. xlSheet.Activate()
  334. xlApp.Visible = True
  335. xlApp.Application.WindowState = xlMaximized
  336. xlSheet.Cells(1, 1) = "系統物料資料庫總表"
  337. xlSheet.Cells(2, 1) = "請注意,料號欄位為系統主要參考項目,請勿修改,如有新增品項的需求,清直接新增在EXCEL資料表最下方,從新導入時系統會自動新增品項到資料庫中。"
  338. xlSheet.Cells(3, 1) = "料號"
  339. xlSheet.Cells(3, 2) = "頁碼"
  340. xlSheet.Cells(3, 3) = "品名"
  341. xlSheet.Cells(3, 4) = "成本"
  342. xlSheet.Cells(3, 5) = "售價"
  343. xlSheet.Cells(3, 6) = "件數"
  344. xlSheet.Cells(3, 7) = "尺寸"
  345. xlSheet.Cells(3, 8) = "材質"
  346. xlSheet.Cells(3, 9) = "備註"
  347. xlSheet.Cells(3, 10) = "最低庫存量"
  348. For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
  349. xlSheet.Cells(i + 4, 1) = 物料清單_dgv.Rows(i).Cells("料號").Value
  350. xlSheet.Cells(i + 4, 2) = 物料清單_dgv.Rows(i).Cells("頁碼").Value
  351. xlSheet.Cells(i + 4, 3) = 物料清單_dgv.Rows(i).Cells("品名").Value
  352. xlSheet.Cells(i + 4, 4) = 物料清單_dgv.Rows(i).Cells("成本").Value
  353. xlSheet.Cells(i + 4, 5) = 物料清單_dgv.Rows(i).Cells("售價").Value
  354. xlSheet.Cells(i + 4, 6) = 物料清單_dgv.Rows(i).Cells("件數").Value
  355. xlSheet.Cells(i + 4, 7) = 物料清單_dgv.Rows(i).Cells("尺寸").Value
  356. xlSheet.Cells(i + 4, 8) = 物料清單_dgv.Rows(i).Cells("材質").Value
  357. xlSheet.Cells(i + 4, 9) = 物料清單_dgv.Rows(i).Cells("備註").Value
  358. xlSheet.Cells(i + 4, 10) = 物料清單_dgv.Rows(i).Cells("最低庫存量").Value
  359. With xlApp.Selection
  360. .Font.Bold = True
  361. End With
  362. N = i + 4
  363. Next i
  364. BB(xlApp, xlSheet)
  365. xlSheet.PageSetup.PrintArea = ""
  366. xlApp.Cells.Select()
  367. xlSheet.Range("B1").Select()
  368. xlApp.Application.WindowState = xlMinimized
  369. MsgBox("列印完成")
  370. End Sub
  371. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  372. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  373. End Function
  374. Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  375. xlSheet.Cells.Select()
  376. With myExcel.Selection.Font
  377. .Name = "微軟正黑體" : .Size = 12
  378. .Strikethrough = False : .Superscript = False : .Subscript = False
  379. .OutlineFont = False : .Shadow = False
  380. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1
  381. .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
  382. End With
  383. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 12
  384. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 10
  385. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 35
  386. xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 30
  387. xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 30
  388. xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 30
  389. xlSheet.Range("A1:J1").Select()
  390. With myExcel.Selection
  391. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0
  392. .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  393. End With
  394. myExcel.Selection.Merge
  395. xlSheet.Range("A2:J2").Select()
  396. With myExcel.Selection
  397. .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False
  398. .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  399. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  400. End With
  401. myExcel.Selection.Merge
  402. xlSheet.Range("A2:J2").Select()
  403. With myExcel.Selection.Font
  404. .Color = -16776961 : .TintAndShade = 0
  405. End With
  406. xlSheet.Range("A1:J1").Select()
  407. With myExcel.Selection.Font
  408. .Name = "微軟正黑體" : .Size = 18
  409. .Strikethrough = False : .Superscript = False
  410. .Subscript = False : .OutlineFont = False
  411. .Shadow = False : .Underline = xlUnderlineStyleNone
  412. .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0
  413. .ThemeFont = xlThemeFontNone
  414. End With
  415. xlSheet.Range("A1:J3").Select()
  416. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  417. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  418. With myExcel.Selection.Borders(xlEdgeLeft)
  419. .LineStyle = xlContinuous : .ColorIndex = 0
  420. .TintAndShade = 0 : .Weight = xlThin
  421. End With
  422. With myExcel.Selection.Borders(xlEdgeTop)
  423. .LineStyle = xlContinuous : .ColorIndex = 0
  424. .TintAndShade = 0 : .Weight = xlThin
  425. End With
  426. With myExcel.Selection.Borders(xlEdgeBottom)
  427. .LineStyle = xlContinuous
  428. .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin
  429. End With
  430. With myExcel.Selection.Borders(xlEdgeRight)
  431. .LineStyle = xlContinuous : .ColorIndex = 0
  432. .TintAndShade = 0 : .Weight = xlThin
  433. End With
  434. With myExcel.Selection.Borders(xlInsideVertical)
  435. .LineStyle = xlContinuous : .ColorIndex = 0
  436. .TintAndShade = 0 : .Weight = xlThin
  437. End With
  438. With myExcel.Selection.Borders(xlInsideHorizontal)
  439. .LineStyle = xlContinuous : .ColorIndex = 0
  440. .TintAndShade = 0 : .Weight = xlThin
  441. End With
  442. xlSheet.Range("A4:J" & N).Select()
  443. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  444. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  445. With myExcel.Selection.Borders(xlEdgeLeft)
  446. .LineStyle = xlContinuous : .ColorIndex = 0
  447. .TintAndShade = 0 : .Weight = xlThin
  448. End With
  449. With myExcel.Selection.Borders(xlEdgeTop)
  450. .LineStyle = xlContinuous : .ColorIndex = 0
  451. .TintAndShade = 0 : .Weight = xlThin
  452. End With
  453. With myExcel.Selection.Borders(xlEdgeBottom)
  454. .LineStyle = xlContinuous : .ColorIndex = 0
  455. .TintAndShade = 0 : .Weight = xlThin
  456. End With
  457. With myExcel.Selection.Borders(xlEdgeRight)
  458. .LineStyle = xlContinuous : .ColorIndex = 0
  459. .TintAndShade = 0 : .Weight = xlThin
  460. End With
  461. With myExcel.Selection.Borders(xlInsideVertical)
  462. .LineStyle = xlContinuous : .ColorIndex = 0
  463. .TintAndShade = 0 : .Weight = xlThin
  464. End With
  465. With myExcel.Selection.Borders(xlInsideHorizontal)
  466. .LineStyle = xlContinuous : .ColorIndex = 0
  467. .TintAndShade = 0 : .Weight = xlThin
  468. End With
  469. xlSheet.Rows("3:3").Select
  470. myExcel.Selection.RowHeight = 35
  471. With myExcel.Selection
  472. .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter
  473. .WrapText = True : .Orientation = 0 : .AddIndent = False
  474. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
  475. End With
  476. With myExcel.Selection
  477. .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop
  478. .WrapText = True : .Orientation = 0 : .AddIndent = False
  479. .IndentLevel = 0 : .ShrinkToFit = False
  480. .ReadingOrder = xlContext : .MergeCells = False
  481. End With
  482. xlSheet.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = False
  483. xlSheet.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = True
  484. xlSheet.Rows("3:3").Select : myExcel.Selection.AutoFilter
  485. myExcel.ActiveWindow.DisplayGridlines = False
  486. End Sub
  487. Private Sub 導入EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 導入EXCEL_bt.Click
  488. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  489. file_name = OpenFileDialog1.FileName
  490. xlApp = CreateObject("Excel.Application")
  491. xlApp.DisplayAlerts = False
  492. xlApp.Visible = True
  493. xlApp.Workbooks.Open(file_name)
  494. xlSheet = xlApp.Worksheets(1)
  495. xlSheet.Activate()
  496. xlApp.Visible = False
  497. Dim 次數 As Integer = 0
  498. For YY As Integer = 1 To 3000
  499. 資料數 = 3000 : MyModule1.進度條()
  500. If IsNothing(xlSheet.Cells(YY + 3, 3).value) Then
  501. Exit For
  502. End If
  503. If IsNothing(xlSheet.Cells(YY + 3, 1).value) Then
  504. '----------------------自动生成流水号-------------------------------------------------------------------------
  505. SQL_物料圖庫流水號最後一筆()
  506. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("料號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
  507. If EDR < 10 Then : ESTR = "PR" & "0000000" & EDR
  508. ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PR" & "000000" & EDR
  509. ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PR" & "00000" & EDR
  510. ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PR" & "0000" & EDR
  511. ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PR" & "000" & EDR
  512. ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PR" & "00" & EDR
  513. ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PR" & "0" & EDR
  514. ElseIf EDR > 9999999 Then : ESTR = "PR" & EDR : End If
  515. ConnOpen()
  516. SQL1 = "INSERT INTO 物料資料庫 (料號, 頁碼, 品名, 成本, 售價, 件數, 尺寸, 材質, 圖片編碼, 備註, 停用, 最低庫存量)
  517. VALUES (N'" & ESTR & "', N'" & xlSheet.Cells(YY + 3, 2).value & "', N'" & xlSheet.Cells(YY + 3, 3).value & "',
  518. N'" & xlSheet.Cells(YY + 3, 4).value & "', N'" & xlSheet.Cells(YY + 3, 5).value & "', N'" & xlSheet.Cells(YY + 3, 6).value & "',
  519. N'" & xlSheet.Cells(YY + 3, 7).value & "', N'" & xlSheet.Cells(YY + 3, 8).value & "', '', N'" & xlSheet.Cells(YY + 3, 9).value & "',
  520. '0', N'" & xlSheet.Cells(YY + 3, 10).value & "')"
  521. CmdSet_For_dr() : conn.Close()
  522. 次數 += 1
  523. Else
  524. ConnOpen()
  525. SQL1 = "UPDATE 物料資料庫 SET 頁碼 = N'" & xlSheet.Cells(YY + 3, 2).value & "', 品名 = N'" & xlSheet.Cells(YY + 3, 3).value & "',
  526. 成本 = N'" & xlSheet.Cells(YY + 3, 4).value & "', 售價 = N'" & xlSheet.Cells(YY + 3, 5).value & "',
  527. 件數 = N'" & xlSheet.Cells(YY + 3, 6).value & "', 尺寸 = N'" & xlSheet.Cells(YY + 3, 7).value & "',
  528. 材質 = N'" & xlSheet.Cells(YY + 3, 8).value & "', 備註 = N'" & xlSheet.Cells(YY + 3, 9).value & "',
  529. 最低庫存量 = N'" & xlSheet.Cells(YY + 3, 10).value & "'
  530. WHERE 料號 LIKE N'" & xlSheet.Cells(YY + 3, 1).value & "'"
  531. CmdSet_For_dr() : conn.Close()
  532. 次數 += 1
  533. End If
  534. Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  535. MsgBox("已修改 " & 次數 & " 次!")
  536. xlApp.Quit() : xlApp = Nothing
  537. ElseIf OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.No Then
  538. End If : Set_物料清單()
  539. End Sub
  540. End Class