暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

驗貨報告資料庫.vb 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 As New DataSet
  7. Dim TT As String
  8. Private m_Leftx As Integer = 152
  9. Private m_Lefty As Integer = 0
  10. Dim m_MousePosX, m_MousePosY, m_DeltaX, m_DeltaY As Integer
  11. Private Sub Set_工程圖片資料庫狀態()
  12. Dim ds9 As New DataSet : 圖片資料庫管理_dgv.DataSource = Nothing : ds9.Clear()
  13. 圖片資料庫管理_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  14. 圖片資料庫管理_dgv.ColumnHeadersHeight = 25
  15. 圖片資料庫管理_dgv.AllowUserToAddRows = False
  16. SQL_圖片資料庫管理查詢()
  17. da.Fill(ds9) : 圖片資料庫管理_dgv.DataSource = ds9.Tables(0) : conn.Close()
  18. 圖片資料庫管理_dgv.Columns(0).FillWeight = 100 : 圖片資料庫管理_dgv.Columns(1).Visible = False
  19. End Sub
  20. Private Sub Set_DGV1載入前設定()
  21. 主表單_dgv.DataSource = Nothing : ds.Clear()
  22. 主表單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  23. 主表單_dgv.ColumnHeadersHeight = 25
  24. 主表單_dgv.AllowUserToAddRows = False
  25. End Sub
  26. Private Sub Set_DGV1載入後設定()
  27. da.Fill(ds) : 主表單_dgv.DataSource = ds.Tables(0) : conn.Close()
  28. End Sub
  29. Private Sub Set_圖片清單()
  30. Set_DGV1載入前設定() : SQL_驗貨報告圖庫表單() : Set_DGV1載入後設定()
  31. End Sub
  32. Private Sub Set_grid()
  33. 主表單_dgv.Columns(0).Width = 140 : 主表單_dgv.Columns(1).Width = 80 : 主表單_dgv.Columns(2).Width = 100
  34. 主表單_dgv.Columns(3).Width = 100 : 主表單_dgv.Columns(4).Width = 70 : 主表單_dgv.Columns(5).Width = 100
  35. End Sub
  36. Private Sub 驗貨報告資料庫_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  37. WINPROFIT_ERP_SYS.WindowState = 2 : Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  38. 驗貨報告編號_tb.Enabled = False : 年份季度_tb.Enabled = False : 客戶訂單號_tb.Enabled = False : 型體名稱_tb.Enabled = False
  39. 文件夾_tb.Visible = False : 伺服器FTP文件夾_tb.Visible = False : 圖片修改存檔_bt.Enabled = True
  40. Set_工程圖片資料庫狀態()
  41. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then : WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath) : End If
  42. End Sub
  43. Private Sub 圖片資料庫管理_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 圖片資料庫管理_dgv.CellClick
  44. If e.RowIndex = -1 Then : Else : PA20 = 圖片資料庫管理_dgv(0, e.RowIndex).Value.ToString : Set_圖片清單() : Set_grid() : Panel1.Visible = False : End If
  45. End Sub
  46. Private Sub 主表單_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 主表單_dgv.CellClick
  47. If e.RowIndex = -1 Then : Else
  48. 驗貨報告編號_tb.Text = 主表單_dgv(5, e.RowIndex).Value.ToString : 年份季度_tb.Text = 主表單_dgv(1, e.RowIndex).Value.ToString
  49. 客戶訂單號_tb.Text = 主表單_dgv(2, e.RowIndex).Value.ToString : 型體名稱_tb.Text = 主表單_dgv(3, e.RowIndex).Value.ToString
  50. SQL_資料庫選擇() : If dr.Read() Then : PA1 = dr("圖片資料庫").ToString : PA20 = PA1 : End If : SQL_驗貨報告圖庫3() : PictureBox1.Image = Nothing
  51. While dr.Read() = True
  52. Dim unused As Byte() = New Byte(-1) {}
  53. Dim bytes As Byte() = DirectCast(dr.Item("驗貨報告"), Byte())
  54. Dim oStream As New MemoryStream(bytes)
  55. PictureBox1.Image = Bitmap.FromStream(oStream)
  56. End While : conn.Close() : PictureBox1.SizeMode = 4
  57. End If
  58. End Sub
  59. Private Sub 主表單_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 主表單_dgv.RowPostPaint
  60. Dim linePen As New Pen(Color.Blue, 2)
  61. If e.RowIndex = 主表單_dgv.Rows.Count - 1 Then : Exit Sub : Else
  62. If 主表單_dgv(2, e.RowIndex).Value.ToString <> 主表單_dgv(2, e.RowIndex + 1).Value.ToString Then
  63. Dim startX As Integer = IIf(主表單_dgv.RowHeadersVisible, 主表單_dgv.RowHeadersWidth, 0)
  64. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  65. Dim endX As Integer = startX + 主表單_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 主表單_dgv.HorizontalScrollingOffset
  66. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  67. End If
  68. End If
  69. End Sub
  70. Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
  71. PA = InputBox("請輸入關鍵字") : Set_DGV1載入前設定() : SQL_驗貨報告圖庫查詢() : Set_DGV1載入後設定() : Set_grid()
  72. End Sub
  73. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 下載圖片_bt.Click
  74. If 驗貨報告編號_tb.Text = "" Then : MsgBox("選擇要下載的圖片") : Else
  75. SQL_資料庫選擇() : If dr.Read() Then : PA1 = dr("圖片資料庫").ToString : PA20 = PA1 : End If
  76. With SaveFileDialog1 : .Filter = "所有文件(*.*)|*.*" : End With : TT = "驗貨報告"
  77. SaveFileDialog1.FileName = TT & "-" & 年份季度_tb.Text & "-" & 客戶訂單號_tb.Text & "-" & 型體名稱_tb.Text & ".jpg"
  78. SaveFileDialog1.ShowDialog() : 文件夾_tb.Text = SaveFileDialog1.FileName
  79. SQL_驗貨報告圖庫1() : da.Fill(ds) : conn.Close()
  80. If ds.Tables(0).Rows.Count > 0 Then
  81. Dim imgData() As Byte
  82. imgData = ds.Tables(0).Rows(0).Item("驗貨報告")
  83. Dim fs As FileStream
  84. fs = File.Create(文件夾_tb.Text, imgData.Length - 1)
  85. fs.Write(imgData, 0, imgData.Length - 1)
  86. fs.Close()
  87. End If : 文件夾_tb.Text = "" : MsgBox("下載完成")
  88. End If
  89. End Sub
  90. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles 順時鐘90度旋轉_bt.Click
  91. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  92. End Sub
  93. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles 逆時鐘90度旋轉_bt.Click
  94. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  95. End Sub
  96. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 水平翻轉_bt.Click
  97. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipY) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  98. End Sub
  99. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 垂直翻轉_bt.Click
  100. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipX) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  101. End Sub
  102. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles 放大_bt.Click
  103. Dim image = PictureBox1.Image
  104. Dim g As Graphics = PictureBox1.CreateGraphics
  105. g.DrawImage(image, New Rectangle(0, 0, image.Width * 1.01, image.Height * 1.01))
  106. End Sub
  107. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 復原_bt.Click
  108. PictureBox1.Refresh()
  109. End Sub
  110. '@#处理鼠标按键抬起的事件,根据鼠标按下时保存的鼠标位置,和当前鼠标的位置,
  111. '计算鼠标移动偏移量,借此调用移动图片的函数,移动图片
  112. Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseUp
  113. m_DeltaX = m_MousePosX - e.X
  114. m_DeltaY = m_MousePosY - e.Y
  115. m_Leftx -= m_DeltaX
  116. m_Lefty -= m_DeltaY
  117. Picturemove(sender, e)
  118. Me.Cursor = Cursors.Arrow
  119. End Sub
  120. '@#当鼠标按下时,将鼠标变成手形,并且记录下当前鼠标的位置
  121. Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
  122. Me.Cursor = Cursors.Hand
  123. m_MousePosX = e.X
  124. m_MousePosY = e.Y
  125. End Sub
  126. '@#根据偏移量计算出的图片位置,重画图片
  127. Private Sub Picturemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  128. Dim myBit As New Bitmap(PictureBox1.Image)
  129. Dim myPicGrh As Graphics = Me.PictureBox1.CreateGraphics
  130. myPicGrh.Clear(Me.PictureBox1.BackColor)
  131. myPicGrh.DrawImageUnscaled(myBit, m_Leftx - 152, m_Lefty)
  132. myBit.Dispose()
  133. myPicGrh.Dispose()
  134. End Sub
  135. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles 讀取料夾路徑_bt.Click
  136. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  137. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  138. End If
  139. End Sub
  140. Private Sub TextBox6_DragEnter(sender As Object, e As DragEventArgs) Handles 檔案名稱_tb.DragEnter
  141. If e.Data.GetDataPresent(DataFormats.FileDrop) Then : Dim files As String()
  142. Try : files = CType(e.Data.GetData(DataFormats.FileDrop), String()) : 檔案名稱_tb.Text = files(files.Length - 1)
  143. Catch ex As Exception : MessageBox.Show(ex.Message) : Return : End Try
  144. End If
  145. Dim STR2 As Integer = 0 : 伺服器FTP文件夾_tb.Text = 檔案名稱_tb.Text
  146. If 檔案名稱_tb.Text = "" Then : Else
  147. For i As Integer = 0 To 9999 : Dim STR1 As Integer = Strings.Len(伺服器FTP文件夾_tb.Text)
  148. If Strings.Right((伺服器FTP文件夾_tb.Text), 1) <> "\" Then : STR1 -= 1 : STR2 += 1
  149. If STR1 = 0 Then : 伺服器FTP文件夾_tb.Text = "" : 檔案名稱_tb.Text = "" : i = 9999
  150. Else : 伺服器FTP文件夾_tb.Text = Strings.Left((伺服器FTP文件夾_tb.Text), STR1) : End If
  151. Else
  152. 伺服器FTP文件夾_tb.Text = Strings.Right((檔案名稱_tb.Text), STR2)
  153. 檔案名稱_tb.Text = 伺服器FTP文件夾_tb.Text : i = 9999
  154. End If
  155. Next
  156. Dim files As String() : files = CType(e.Data.GetData(DataFormats.FileDrop), String())
  157. 伺服器FTP文件夾_tb.Text = files(files.Length - 1)
  158. End If
  159. End Sub
  160. Private Sub TextBox6_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles 檔案名稱_tb.DragDrop
  161. Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
  162. For Each file As String In files
  163. 檔案名稱_tb.AppendText(file + Environment.NewLine)
  164. Next
  165. End Sub
  166. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles 圖片修改存檔_bt.Click
  167. conn.Close()
  168. If 驗貨報告編號_tb.Text = "" Then : MsgBox("請先選擇需要修改的圖片") : Else
  169. If 檔案名稱_tb.Text = "" Then : MsgBox("請確認圖片已準備完畢") : Else
  170. SQL_資料庫選擇() : If dr.Read() Then : PA1 = dr("圖片資料庫").ToString : PA20 = PA1 : End If
  171. Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱_tb.Text)
  172. For i As Integer = 1 To 10
  173. If i = 1 Then : 驗證 = Strings.Left(取變數, i) : Else
  174. If Strings.Mid(取變數, i, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, i, 1) : End If
  175. End If
  176. Next
  177. If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
  178. PA49 = 伺服器FTP文件夾_tb.Text : SQL_修改驗貨報告圖庫() : conn.Close() : MsgBox("修改完成") : 檔案名稱_tb.Text = ""
  179. Else : 檔案名稱_tb.Text = "" : MsgBox("上傳文件並非常用圖片格式,文件已自動刪除,請專換成常用圖片檔案再行操作。") : End If : Set_圖片清單() : Set_grid()
  180. End If
  181. End If
  182. End Sub
  183. End Class