설명 없음
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 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Imports System.IO
  4. Imports System.Net
  5. Public Class 楦頭圖片資料庫
  6. Public Property Credentials As ICredentials
  7. ReadOnly conn As New SqlConnection : ReadOnly conn1 As New SqlConnection
  8. ReadOnly da As New SqlDataAdapter
  9. ReadOnly cmd As New SqlCommand : ReadOnly cmd1 As New SqlCommand
  10. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet
  11. Dim dr As SqlDataReader
  12. Dim TT As String
  13. Private Sub Set_DGV1載入前設定()
  14. DataGridView1.DataSource = Nothing : ds.Clear()
  15. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  16. DataGridView1.ColumnHeadersHeight = 25
  17. DataGridView1.AllowUserToAddRows = False
  18. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  19. End Sub
  20. Private Sub Set_DGV1載入後設定()
  21. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  22. End Sub
  23. Private Sub Set_圖片清單()
  24. Set_DGV1載入前設定()
  25. SQL1 = "SELECT 楦頭編號, 楦頭圖片編號 FROM 楦頭圖片庫 ORDER BY 楦頭圖片編號"
  26. Set_DGV1載入後設定() : Set_grid()
  27. End Sub
  28. Private Sub Set_grid()
  29. DataGridView1.Columns(0).Width = 120 : DataGridView1.Columns(1).Width = 100
  30. End Sub
  31. Private Sub 楦頭圖片資料庫_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  32. Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  33. Set_圖片清單()
  34. TextBox1.Enabled = False : TextBox2.Enabled = False : TextBox7.Visible = False
  35. Target1 = Target & AA(13) & "/"
  36. WebBrowser1.Url = New Uri(Target1)
  37. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  38. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  39. End If
  40. End Sub
  41. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  42. If e.RowIndex = -1 Then : Else
  43. TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString
  44. TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
  45. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  46. SQL1 = "SELECT 楦頭圖片 FROM 楦頭圖片庫 WHERE 楦頭圖片編號 LIKE N'" & TextBox2.Text & "'"
  47. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  48. While dr.Read() = True
  49. Dim unused As Byte() = New Byte(-1) {}
  50. Dim bytes As Byte() = DirectCast(dr.Item("楦頭圖片"), Byte())
  51. Dim oStream As New MemoryStream(bytes)
  52. PictureBox1.Image = Bitmap.FromStream(oStream)
  53. End While
  54. conn.Close()
  55. PictureBox1.SizeMode = 4
  56. End If
  57. End Sub
  58. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  59. PA = InputBox("請輸入關鍵字")
  60. Set_DGV1載入前設定()
  61. SQL1 = "SELECT 楦頭編號, 楦頭圖片編號 FROM 楦頭圖片庫 WHERE (楦頭編號 LIKE N'%" & PA & "%') ORDER BY 楦頭圖片編號"
  62. Set_DGV1載入後設定() : Set_grid()
  63. End Sub
  64. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  65. If TextBox1.Text = "" Then
  66. MsgBox("選擇要下載的圖片")
  67. Else
  68. With SaveFileDialog1 : .Filter = "所有文件(*.*)|*.*" : End With
  69. TT = TextBox2.Text
  70. SaveFileDialog1.FileName = TT & "-" & TextBox1.Text & ".jpg"
  71. SaveFileDialog1.ShowDialog() : TextBox3.Text = SaveFileDialog1.FileName
  72. ds1.Clear()
  73. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  74. SQL1 = "SELECT 楦頭圖片 FROM 楦頭圖片庫 WHERE 楦頭編號 LIKE N'" & TextBox1.Text & "'"
  75. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : conn.Close()
  76. If ds1.Tables(0).Rows.Count > 0 Then
  77. Dim imgData() As Byte
  78. imgData = ds1.Tables(0).Rows(0).Item("楦頭圖片")
  79. Dim fs As FileStream
  80. fs = File.Create(TextBox3.Text, imgData.Length - 1)
  81. fs.Write(imgData, 0, imgData.Length - 1)
  82. fs.Close()
  83. End If
  84. TextBox3.Text = ""
  85. MsgBox("下載完成")
  86. End If
  87. End Sub
  88. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click
  89. If TextBox3.Text = "" Then
  90. MsgBox("請確定圖片資料已準備完畢")
  91. Else
  92. conn.Close()
  93. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  94. SQL1 = "UPDATE 楦頭圖片庫 SET 楦頭圖片 = BULKCOLUMN FROM OPENROWSET ( BULK '" & FTP實體位置 & AA(13) & "\" & TextBox3.Text & "', SINGLE_BLOB) AS EMPLOYEEPICTURE " &
  95. "WHERE (楦頭圖片編號 = '" & TextBox2.Text & "') AND (楦頭編號 = '" & TextBox1.Text & "')"
  96. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  97. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  98. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  99. frq = CType(WebRequest.Create(New Uri(Target1 & TextBox3.Text)), FtpWebRequest)
  100. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  101. frq.Credentials = fcr
  102. frq.Method = WebRequestMethods.Ftp.DeleteFile
  103. frq.UseBinary = True
  104. frp = CType(frq.GetResponse, FtpWebResponse)
  105. frp.Close()
  106. WebBrowser1.Refresh()
  107. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  108. TextBox3.Text = ""
  109. MsgBox("修改完成")
  110. Set_圖片清單()
  111. End If
  112. End Sub
  113. Private Sub TextBox3_DragEnter(sender As Object, e As DragEventArgs) Handles TextBox3.DragEnter
  114. If e.Data.GetDataPresent(DataFormats.FileDrop) Then
  115. Dim files As String()
  116. Try
  117. files = CType(e.Data.GetData(DataFormats.FileDrop), String())
  118. TextBox3.Text = files(files.Length - 1)
  119. Catch ex As Exception
  120. MessageBox.Show(ex.Message)
  121. Return
  122. End Try
  123. End If
  124. Dim STR2 As Integer = 0
  125. TextBox7.Text = TextBox3.Text
  126. If TextBox3.Text = "" Then
  127. Else
  128. For i As Integer = 0 To 9999
  129. Dim STR1 As Integer = Strings.Len(TextBox7.Text)
  130. If Strings.Right((TextBox7.Text), 1) <> "\" Then
  131. STR1 -= 1 : STR2 += 1
  132. If STR1 = 0 Then
  133. TextBox7.Text = ""
  134. TextBox3.Text = ""
  135. i = 9999
  136. Else
  137. TextBox7.Text = Strings.Left((TextBox7.Text), STR1)
  138. End If
  139. Else
  140. TextBox7.Text = Strings.Right((TextBox3.Text), STR2)
  141. TextBox3.Text = TextBox7.Text
  142. i = 9999
  143. End If
  144. Next
  145. End If
  146. End Sub
  147. Private Sub TextBox3_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBox3.DragDrop
  148. Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
  149. For Each file As String In files
  150. TextBox3.AppendText(file + Environment.NewLine)
  151. Next
  152. End Sub
  153. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  154. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  155. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  156. End If
  157. End Sub
  158. End Class