Bez popisu
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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 m_Leftx As Integer = 152
  14. Private m_Lefty As Integer = 0
  15. Dim m_MousePosX As Integer
  16. Dim m_MousePosY As Integer
  17. Dim m_DeltaX As Integer
  18. Dim m_DeltaY As Integer
  19. 'Dim m_StrecthX As Double
  20. ' Dim m_StrecthY As Double
  21. Private Sub Set_DGV1載入前設定()
  22. DataGridView1.DataSource = Nothing : ds.Clear()
  23. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  24. DataGridView1.ColumnHeadersHeight = 25
  25. DataGridView1.AllowUserToAddRows = False
  26. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  27. End Sub
  28. Private Sub Set_DGV1載入後設定()
  29. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  30. End Sub
  31. Private Sub Set_圖片清單()
  32. Set_DGV1載入前設定()
  33. SQL1 = "SELECT 訂單控制表.訂單流水號, 訂單控制表.年份季度, 驗貨報告圖庫.客戶訂單號, 驗貨報告圖庫.型體名稱, 訂單控制表.APMA確認 AS 顏色, 驗貨報告圖庫.驗貨報告編號 " &
  34. "FROM 驗貨報告圖庫 LEFT OUTER JOIN 訂單控制表 ON 驗貨報告圖庫.客戶訂單號 = 訂單控制表.客戶訂單號 GROUP BY 訂單控制表.訂單流水號, 訂單控制表.年份季度, " &
  35. "驗貨報告圖庫.客戶訂單號, 驗貨報告圖庫.型體名稱, 訂單控制表.APMA確認, 驗貨報告圖庫.驗貨報告編號 ORDER BY 驗貨報告圖庫.客戶訂單號, 驗貨報告圖庫.型體名稱"
  36. Set_DGV1載入後設定()
  37. End Sub
  38. Private Sub Set_grid()
  39. DataGridView1.Columns(0).Width = 140 : DataGridView1.Columns(1).Width = 80 : DataGridView1.Columns(2).Width = 100
  40. DataGridView1.Columns(3).Width = 100 : DataGridView1.Columns(4).Width = 70 : DataGridView1.Columns(5).Width = 100
  41. End Sub
  42. Private Sub 驗貨報告資料庫_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  43. Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  44. TextBox1.Enabled = False : TextBox2.Enabled = False : TextBox3.Enabled = False : TextBox4.Enabled = False : TextBox5.Visible = False : TextBox7.Visible = False : Button24.Enabled = False
  45. 'If CC(92) = True Then : Button24.Enabled = True : End If
  46. Target1 = Target & AA(13) & "/"
  47. WebBrowser1.Url = New Uri(Target1)
  48. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  49. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  50. End If
  51. Set_圖片清單() : Set_grid()
  52. End Sub
  53. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  54. If e.RowIndex = -1 Then : Else
  55. TextBox1.Text = DataGridView1(5, e.RowIndex).Value.ToString
  56. TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
  57. TextBox3.Text = DataGridView1(2, e.RowIndex).Value.ToString
  58. TextBox4.Text = DataGridView1(3, e.RowIndex).Value.ToString
  59. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  60. SQL1 = "SELECT 驗貨報告 FROM 驗貨報告圖庫 WHERE 驗貨報告編號 LIKE '" & TextBox1.Text & "'"
  61. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  62. While dr.Read() = True
  63. Dim unused As Byte() = New Byte(-1) {}
  64. Dim bytes As Byte() = DirectCast(dr.Item("驗貨報告"), Byte())
  65. Dim oStream As New MemoryStream(bytes)
  66. PictureBox1.Image = Bitmap.FromStream(oStream)
  67. End While
  68. conn.Close()
  69. PictureBox1.SizeMode = 4
  70. End If
  71. End Sub
  72. Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
  73. Dim linePen As New Pen(Color.Blue, 2)
  74. If e.RowIndex = DataGridView1.Rows.Count - 1 Then
  75. Exit Sub
  76. Else
  77. If DataGridView1(2, e.RowIndex).Value.ToString <> DataGridView1(2, e.RowIndex + 1).Value.ToString Then
  78. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  79. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  80. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  81. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  82. Exit Sub
  83. End If
  84. End If
  85. End Sub
  86. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  87. PA = InputBox("請輸入關鍵字")
  88. Set_DGV1載入前設定()
  89. SQL1 = "SELECT 訂單控制表.訂單流水號, 訂單控制表.年份季度, 驗貨報告圖庫.客戶訂單號, 驗貨報告圖庫.型體名稱, 訂單控制表.APMA確認 AS 顏色, 驗貨報告圖庫.驗貨報告編號
  90. FROM 驗貨報告圖庫 LEFT OUTER JOIN 訂單控制表 ON 驗貨報告圖庫.客戶訂單號 = 訂單控制表.客戶訂單號
  91. WHERE 訂單控制表.訂單流水號 LIKE '%" & PA & "%' OR 訂單控制表.年份季度 LIKE '%" & PA & "%' OR 驗貨報告圖庫.客戶訂單號 LIKE '%" & PA & "%' OR 驗貨報告圖庫.型體名稱 LIKE '%" & PA & "%'
  92. GROUP BY 訂單控制表.訂單流水號, 訂單控制表.年份季度, 驗貨報告圖庫.客戶訂單號, 驗貨報告圖庫.型體名稱, 訂單控制表.APMA確認, 驗貨報告圖庫.驗貨報告編號
  93. ORDER BY 驗貨報告圖庫.客戶訂單號, 驗貨報告圖庫.型體名稱"
  94. Set_DGV1載入後設定() : Set_grid()
  95. End Sub
  96. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  97. If TextBox1.Text = "" Then
  98. MsgBox("選擇要下載的圖片")
  99. Else
  100. With SaveFileDialog1 : .Filter = "所有文件(*.*)|*.*" : End With
  101. TT = "驗貨報告"
  102. SaveFileDialog1.FileName = TT & "-" & TextBox2.Text & "-" & TextBox3.Text & "-" & TextBox4.Text & ".jpg"
  103. SaveFileDialog1.ShowDialog() : TextBox5.Text = SaveFileDialog1.FileName
  104. ds1.Clear()
  105. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  106. SQL1 = "SELECT 驗貨報告 FROM 驗貨報告圖庫 WHERE 驗貨報告編號 LIKE '" & TextBox1.Text & "'"
  107. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : conn.Close()
  108. If ds1.Tables(0).Rows.Count > 0 Then
  109. Dim imgData() As Byte
  110. imgData = ds1.Tables(0).Rows(0).Item("驗貨報告")
  111. Dim fs As FileStream
  112. fs = File.Create(TextBox5.Text, imgData.Length - 1)
  113. fs.Write(imgData, 0, imgData.Length - 1)
  114. fs.Close()
  115. End If
  116. TextBox5.Text = ""
  117. MsgBox("下載完成")
  118. End If
  119. End Sub
  120. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
  121. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  122. End Sub
  123. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  124. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  125. End Sub
  126. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  127. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipY) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  128. End Sub
  129. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  130. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipX) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  131. End Sub
  132. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  133. Dim image = PictureBox1.Image
  134. Dim g As Graphics = PictureBox1.CreateGraphics
  135. g.DrawImage(image, New Rectangle(0, 0, image.Width * 1.01, image.Height * 1.01))
  136. End Sub
  137. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  138. PictureBox1.Refresh()
  139. End Sub
  140. '@#处理鼠标按键抬起的事件,根据鼠标按下时保存的鼠标位置,和当前鼠标的位置,
  141. '计算鼠标移动偏移量,借此调用移动图片的函数,移动图片
  142. Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseUp
  143. m_DeltaX = m_MousePosX - e.X
  144. m_DeltaY = m_MousePosY - e.Y
  145. m_Leftx -= m_DeltaX
  146. m_Lefty -= m_DeltaY
  147. Picturemove(sender, e)
  148. Me.Cursor = Cursors.Arrow
  149. End Sub
  150. '@#当鼠标按下时,将鼠标变成手形,并且记录下当前鼠标的位置
  151. Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
  152. Me.Cursor = Cursors.Hand
  153. m_MousePosX = e.X
  154. m_MousePosY = e.Y
  155. End Sub
  156. '@#根据偏移量计算出的图片位置,重画图片
  157. Private Sub Picturemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  158. Dim myBit As New Bitmap(PictureBox1.Image)
  159. Dim myPicGrh As Graphics = Me.PictureBox1.CreateGraphics
  160. myPicGrh.Clear(Me.PictureBox1.BackColor)
  161. myPicGrh.DrawImageUnscaled(myBit, m_Leftx - 152, m_Lefty)
  162. myBit.Dispose()
  163. myPicGrh.Dispose()
  164. End Sub
  165. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  166. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  167. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  168. End If
  169. End Sub
  170. Private Sub TextBox6_DragEnter(sender As Object, e As DragEventArgs) Handles TextBox6.DragEnter
  171. If e.Data.GetDataPresent(DataFormats.FileDrop) Then
  172. Dim files As String()
  173. Try
  174. files = CType(e.Data.GetData(DataFormats.FileDrop), String())
  175. TextBox6.Text = files(files.Length - 1)
  176. Catch ex As Exception
  177. MessageBox.Show(ex.Message)
  178. Return
  179. End Try
  180. End If
  181. Dim STR2 As Integer = 0
  182. TextBox7.Text = TextBox6.Text
  183. If TextBox6.Text = "" Then
  184. Else
  185. For i As Integer = 0 To 9999
  186. Dim STR1 As Integer = Strings.Len(TextBox7.Text)
  187. If Strings.Right((TextBox7.Text), 1) <> "\" Then
  188. STR1 -= 1 : STR2 += 1
  189. If STR1 = 0 Then
  190. TextBox7.Text = ""
  191. TextBox6.Text = ""
  192. i = 9999
  193. Else
  194. TextBox7.Text = Strings.Left((TextBox7.Text), STR1)
  195. End If
  196. Else
  197. TextBox7.Text = Strings.Right((TextBox6.Text), STR2)
  198. TextBox6.Text = TextBox7.Text
  199. i = 9999
  200. End If
  201. Next
  202. End If
  203. End Sub
  204. Private Sub TextBox6_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBox6.DragDrop
  205. Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
  206. For Each file As String In files
  207. TextBox6.AppendText(file + Environment.NewLine)
  208. Next
  209. End Sub
  210. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click
  211. conn.Close()
  212. If TextBox1.Text = "" Then
  213. MsgBox("請先選擇需要修改的圖片")
  214. Else
  215. If TextBox6.Text = "" Then
  216. MsgBox("請確認圖片已準備完畢")
  217. Else
  218. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  219. SQL1 = "UPDATE 驗貨報告圖庫 SET 驗貨報告 = BULKCOLUMN FROM OPENROWSET ( BULK 'E:\TENDENZA\0004\" & TextBox6.Text & "', SINGLE_BLOB) AS EMPLOYEEPICTURE " &
  220. "WHERE (驗貨報告編號 = '" & TextBox1.Text & "')"
  221. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  222. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  223. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  224. frq = CType(WebRequest.Create(New Uri(Target1 & TextBox6.Text)), FtpWebRequest)
  225. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  226. frq.Credentials = fcr
  227. frq.Method = WebRequestMethods.Ftp.DeleteFile
  228. frq.UseBinary = True
  229. frp = CType(frq.GetResponse, FtpWebResponse)
  230. frp.Close()
  231. WebBrowser1.Refresh()
  232. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  233. TextBox6.Text = ""
  234. MsgBox("修改完成")
  235. Set_圖片清單() : Set_grid()
  236. End If
  237. End If
  238. End Sub
  239. End Class