Brak opisu
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 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. Option Strict Off
  2. Imports System.IO
  3. Imports System.Net
  4. Public Class 楦頭圖片資料庫
  5. Public Property Credentials As ICredentials
  6. Private ReadOnly ds, ds1 As New DataSet
  7. Dim TT As String
  8. Private Sub Set_DGV1載入前設定()
  9. 主表單_dgv.DataSource = Nothing : ds.Clear()
  10. 主表單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  11. 主表單_dgv.ColumnHeadersHeight = 25
  12. 主表單_dgv.AllowUserToAddRows = False
  13. End Sub
  14. Private Sub Set_DGV1載入後設定()
  15. da.Fill(ds) : 主表單_dgv.DataSource = ds.Tables(0) : conn.Close()
  16. End Sub
  17. Private Sub Set_圖片清單()
  18. Set_DGV1載入前設定()
  19. SQL_楦頭圖片資料庫表單()
  20. Set_DGV1載入後設定() : Set_grid()
  21. End Sub
  22. Private Sub Set_grid()
  23. 主表單_dgv.Columns(0).Width = 120 : 主表單_dgv.Columns(1).Width = 100
  24. End Sub
  25. Private Sub 楦頭圖片資料庫_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  26. WINPROFIT_ERP_SYS.WindowState = 2 : Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  27. Set_圖片清單()
  28. 楦頭編號_tb.Enabled = False : 楦頭圖片編號_tb.Enabled = False : 檔案名稱1_tb.Visible = False
  29. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  30. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  31. End If
  32. End Sub
  33. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 主表單_dgv.CellClick
  34. If e.RowIndex = -1 Then : Else
  35. 楦頭編號_tb.Text = 主表單_dgv(0, e.RowIndex).Value.ToString
  36. 楦頭圖片編號_tb.Text = 主表單_dgv(1, e.RowIndex).Value.ToString
  37. SQL_讀取楦頭圖片庫()
  38. While dr.Read() = True
  39. Dim unused As Byte() = New Byte(-1) {}
  40. Dim bytes As Byte() = DirectCast(dr.Item("楦頭圖片"), Byte())
  41. Dim oStream As New MemoryStream(bytes)
  42. PictureBox1.Image = Bitmap.FromStream(oStream)
  43. End While
  44. conn.Close()
  45. PictureBox1.SizeMode = 4
  46. End If
  47. End Sub
  48. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
  49. PA = InputBox("請輸入關鍵字")
  50. Set_DGV1載入前設定()
  51. SQL_查詢楦頭圖片資料庫()
  52. Set_DGV1載入後設定() : Set_grid()
  53. End Sub
  54. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 下載圖片_bt.Click
  55. If 楦頭編號_tb.Text = "" Then
  56. MsgBox("選擇要下載的圖片")
  57. Else
  58. With SaveFileDialog1 : .Filter = "所有文件(*.*)|*.*" : End With
  59. TT = 楦頭圖片編號_tb.Text
  60. SaveFileDialog1.FileName = TT & "-" & 楦頭編號_tb.Text & ".jpg"
  61. SaveFileDialog1.ShowDialog() : 檔案名稱_tb.Text = SaveFileDialog1.FileName
  62. ds1.Clear()
  63. SQL_讀取楦頭圖片庫1()
  64. da.Fill(ds1) : conn.Close()
  65. If ds1.Tables(0).Rows.Count > 0 Then
  66. Dim imgData() As Byte
  67. imgData = ds1.Tables(0).Rows(0).Item("楦頭圖片")
  68. Dim fs As FileStream
  69. fs = File.Create(檔案名稱_tb.Text, imgData.Length - 1)
  70. fs.Write(imgData, 0, imgData.Length - 1)
  71. fs.Close()
  72. End If
  73. 檔案名稱_tb.Text = ""
  74. MsgBox("下載完成")
  75. End If
  76. End Sub
  77. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles 圖片修改存檔_bt.Click
  78. If 檔案名稱_tb.Text = "" Then : MsgBox("請確定圖片資料已準備完畢") : Else
  79. Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱_tb.Text)
  80. For i As Integer = 1 To 10
  81. If i = 1 Then : 驗證 = Strings.Left(取變數, i) : Else
  82. If Strings.Mid(取變數, i, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, i, 1) : End If
  83. End If
  84. Next
  85. If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
  86. PA49 = 檔案名稱1_tb.Text : SQL_更改楦頭圖片庫() : conn.Close() : MsgBox("修改完成") : 檔案名稱_tb.Text = ""
  87. Else : 檔案名稱_tb.Text = "" : MsgBox("上傳文件並非常用圖片格式,文件已自動刪除,請專換成常用圖片檔案再行操作。") : End If : Set_圖片清單()
  88. End If
  89. End Sub
  90. Private Sub TextBox3_DragEnter(sender As Object, e As DragEventArgs) Handles 檔案名稱_tb.DragEnter
  91. If e.Data.GetDataPresent(DataFormats.FileDrop) Then : Dim files As String()
  92. Try : files = CType(e.Data.GetData(DataFormats.FileDrop), String()) : 檔案名稱_tb.Text = files(files.Length - 1)
  93. Catch ex As Exception : MessageBox.Show(ex.Message) : Return : End Try
  94. End If
  95. Dim STR2 As Integer = 0 : 檔案名稱1_tb.Text = 檔案名稱_tb.Text
  96. If 檔案名稱_tb.Text = "" Then : Else
  97. For i As Integer = 0 To 9999
  98. Dim STR1 As Integer = Strings.Len(檔案名稱1_tb.Text)
  99. If Strings.Right((檔案名稱1_tb.Text), 1) <> "\" Then : STR1 -= 1 : STR2 += 1
  100. If STR1 = 0 Then : 檔案名稱1_tb.Text = "" : 檔案名稱_tb.Text = "" : i = 9999
  101. Else : 檔案名稱1_tb.Text = Strings.Left((檔案名稱1_tb.Text), STR1) : End If
  102. Else
  103. 檔案名稱1_tb.Text = Strings.Right((檔案名稱_tb.Text), STR2)
  104. 檔案名稱_tb.Text = 檔案名稱1_tb.Text : i = 9999
  105. End If
  106. Next
  107. Dim files As String() : files = CType(e.Data.GetData(DataFormats.FileDrop), String())
  108. 檔案名稱1_tb.Text = files(files.Length - 1)
  109. End If
  110. End Sub
  111. Private Sub TextBox3_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles 檔案名稱_tb.DragDrop
  112. Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
  113. For Each file As String In files
  114. 檔案名稱_tb.AppendText(file + Environment.NewLine)
  115. Next
  116. End Sub
  117. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 讀取料夾路徑_bt.Click
  118. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  119. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  120. End If
  121. End Sub
  122. End Class