Sin descripción
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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. Option Explicit On
  2. Imports System.Net
  3. Imports System.IO
  4. Public Class 車輛保養紀錄表
  5. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet
  6. Dim EDR As Integer = 0 : Dim ESTR As String
  7. Private m_Leftx As Integer = 152
  8. Private m_Lefty As Integer = 0
  9. Dim m_MousePosX As Integer
  10. Dim m_MousePosY As Integer
  11. Dim m_DeltaX As Integer
  12. Dim m_DeltaY As Integer
  13. ReadOnly m_StrecthX As Double
  14. ReadOnly m_StrecthY As Double
  15. Private Sub Set_清單()
  16. DataGridView1.DataSource = Nothing : ds.Clear()
  17. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  18. DataGridView1.ColumnHeadersHeight = 25
  19. DataGridView1.AllowUserToAddRows = False
  20. SQL_車輛保養紀錄表()
  21. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  22. DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).FillWeight = 100 : DataGridView1.Columns(3).FillWeight = 100
  23. DataGridView1.Columns(4).FillWeight = 100
  24. DataGridView1.Columns(4).DefaultCellStyle.Format = "#,##0"
  25. DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  26. End Sub
  27. Private Sub ComboBox1下拉表單資料載入()
  28. SQL_車牌號碼清單()
  29. ComboBox1.Items.Clear()
  30. While (dr.Read()) : ComboBox1.Items.Add(dr("車牌號碼")) : End While : conn.Close()
  31. End Sub
  32. Private Sub 車輛保養紀錄表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  33. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  34. TextBox1.Visible = False : TextBox3.Visible = False : ComboBox1下拉表單資料載入()
  35. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  36. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  37. End If
  38. Target1 = Target & AA(1) & "/"
  39. WebBrowser1.Url = New Uri(Target1)
  40. End Sub
  41. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  42. If e.RowIndex = -1 Then : Else
  43. DateTimePicker2.Value = DataGridView1.Rows(e.RowIndex).Cells("保養日期").Value.ToString : DateTimePicker1.Value = DataGridView1.Rows(e.RowIndex).Cells("預保日期").Value.ToString
  44. NumericUpDown1.Value = DataGridView1.Rows(e.RowIndex).Cells("里程數").Value.ToString : TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells("流水號").Value.ToString
  45. Set_圖片顯示()
  46. End If
  47. End Sub
  48. Private Sub TextBox4_DragEnter(sender As Object, e As DragEventArgs) Handles TextBox4.DragEnter
  49. If e.Data.GetDataPresent(DataFormats.FileDrop) Then
  50. Dim files As String()
  51. Try
  52. files = CType(e.Data.GetData(DataFormats.FileDrop), String())
  53. TextBox4.Text = files(files.Length - 1)
  54. Catch ex As Exception
  55. MessageBox.Show(ex.Message)
  56. Return
  57. End Try
  58. End If
  59. Dim STR2 As Integer = 0
  60. TextBox3.Text = TextBox4.Text
  61. If TextBox4.Text = "" Then
  62. Else
  63. For i As Integer = 0 To 9999
  64. Dim STR1 As Integer = Strings.Len(TextBox3.Text)
  65. If Strings.Right((TextBox3.Text), 1) <> "\" Then
  66. STR1 -= 1 : STR2 += 1
  67. If STR1 = 0 Then
  68. TextBox3.Text = ""
  69. TextBox4.Text = ""
  70. i = 9999
  71. Else
  72. TextBox3.Text = Strings.Left((TextBox3.Text), STR1)
  73. End If
  74. Else
  75. TextBox3.Text = Strings.Right((TextBox4.Text), STR2)
  76. TextBox4.Text = TextBox3.Text
  77. i = 9999
  78. End If
  79. Next
  80. End If
  81. End Sub
  82. Private Sub TextBox4_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles TextBox4.DragDrop
  83. Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
  84. For Each file As String In files
  85. TextBox4.AppendText(file + Environment.NewLine)
  86. Next
  87. End Sub
  88. Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
  89. If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
  90. WebBrowser2.Navigate(FolderBrowserDialog1.SelectedPath)
  91. End If
  92. End Sub
  93. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  94. Set_清單()
  95. End Sub
  96. Private Sub Set_日期格式轉換()
  97. DTP1 = Format(DateTimePicker2.Value, "yyyy/MM/dd") : DTP2 = Format(DateTimePicker1.Value, "yyyy/MM/dd")
  98. End Sub
  99. Private Sub Set_流水號()
  100. SQL_車輛保養紀錄表流水號最後一筆()
  101. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("流水號").ToString, 8)) : Else : EDR = 0 : End If
  102. conn.Close()
  103. EDR += 1
  104. If EDR < 10 Then : ESTR = "VM" & "0000000" & EDR
  105. ElseIf EDR > 9 And EDR < 100 Then : ESTR = "VM" & "000000" & EDR
  106. ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "VM" & "00000" & EDR
  107. ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "VM" & "0000" & EDR
  108. ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "VM" & "000" & EDR
  109. ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "VM" & "00" & EDR
  110. ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "VM" & "0" & EDR
  111. ElseIf EDR > 9999999 Then : ESTR = "VM" & EDR
  112. End If
  113. TextBox1.Text = ESTR
  114. Set_日期格式轉換()
  115. End Sub
  116. Private Sub Set_圖片顯示()
  117. PictureBox1.Image = Nothing
  118. SQL_車輛保養紀錄表圖片讀取()
  119. While dr.Read() = True
  120. Dim unused As Byte() = New Byte(-1) {}
  121. Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  122. Dim oStream As New MemoryStream(bytes)
  123. PictureBox1.Image = Bitmap.FromStream(oStream)
  124. End While
  125. conn.Close()
  126. PictureBox1.SizeMode = 4
  127. End Sub
  128. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  129. If ComboBox1.Text = "" Then
  130. MsgBox("請先輸入車牌,或選擇車牌")
  131. Else
  132. If TextBox4.Text = "" Then
  133. Set_流水號() : SQL_車輛保養紀錄表新增_無圖片() : conn.Close() : TextBox4.Text = "" : Set_圖片顯示() : TextBox1.Text = ""
  134. Else
  135. Set_流水號() : SQL_車輛保養紀錄表新增_有圖片() : conn.Close()
  136. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  137. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  138. frq = CType(WebRequest.Create(New Uri(Target1 & TextBox4.Text)), FtpWebRequest)
  139. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  140. frq.Credentials = fcr
  141. frq.Method = WebRequestMethods.Ftp.DeleteFile
  142. frq.UseBinary = True
  143. frp = CType(frq.GetResponse, FtpWebResponse)
  144. frp.Close()
  145. WebBrowser1.Refresh()
  146. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  147. TextBox4.Text = ""
  148. Set_圖片顯示()
  149. TextBox1.Text = ""
  150. End If
  151. Set_清單()
  152. End If
  153. End Sub
  154. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  155. If ComboBox1.Text = "" Then
  156. MsgBox("請先輸入車牌,或選擇車牌")
  157. Else
  158. If TextBox4.Text = "" Then
  159. Set_日期格式轉換()
  160. SQL_車輛保養紀錄表修改_無圖片() : conn.Close()
  161. TextBox4.Text = "" : Set_圖片顯示() : TextBox1.Text = ""
  162. Else
  163. conn.Close() : Set_日期格式轉換()
  164. SQL_車輛保養紀錄表修改_有圖片() : conn.Close()
  165. '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  166. Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
  167. frq = CType(WebRequest.Create(New Uri(Target1 & TextBox4.Text)), FtpWebRequest)
  168. fcr = New NetworkCredential(FTP帳號, FTP密碼)
  169. frq.Credentials = fcr
  170. frq.Method = WebRequestMethods.Ftp.DeleteFile
  171. frq.UseBinary = True
  172. frp = CType(frq.GetResponse, FtpWebResponse)
  173. frp.Close()
  174. WebBrowser1.Refresh()
  175. '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  176. TextBox4.Text = ""
  177. Set_圖片顯示()
  178. TextBox1.Text = ""
  179. End If
  180. MsgBox("修改完成") : Set_清單()
  181. End If
  182. End Sub
  183. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  184. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  185. End Sub
  186. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
  187. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  188. End Sub
  189. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  190. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipY) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  191. End Sub
  192. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  193. PictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipX) : PictureBox1.Refresh() : PictureBox1.SizeMode = 4
  194. End Sub
  195. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  196. Dim image = PictureBox1.Image
  197. Dim g As Graphics = PictureBox1.CreateGraphics
  198. g.DrawImage(image, New Rectangle(0, 0, image.Width * 2, image.Height * 2))
  199. End Sub
  200. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  201. PictureBox1.Refresh()
  202. End Sub
  203. '@#处理鼠标按键抬起的事件,根据鼠标按下时保存的鼠标位置,和当前鼠标的位置,
  204. '计算鼠标移动偏移量,借此调用移动图片的函数,移动图片
  205. Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseUp
  206. m_DeltaX = m_MousePosX - e.X
  207. m_DeltaY = m_MousePosY - e.Y
  208. m_Leftx -= m_DeltaX
  209. m_Lefty -= m_DeltaY
  210. Picturemove(sender, e)
  211. Me.Cursor = Cursors.Arrow
  212. End Sub
  213. '@#当鼠标按下时,将鼠标变成手形,并且记录下当前鼠标的位置
  214. Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
  215. Me.Cursor = Cursors.Hand
  216. m_MousePosX = e.X
  217. m_MousePosY = e.Y
  218. End Sub
  219. '@#根据偏移量计算出的图片位置,重画图片
  220. Private Sub Picturemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  221. Dim myBit As New Bitmap(PictureBox1.Image)
  222. Dim myPicGrh As Graphics = Me.PictureBox1.CreateGraphics
  223. myPicGrh.Clear(Me.PictureBox1.BackColor)
  224. myPicGrh.DrawImageUnscaled(myBit, m_Leftx - 152, m_Lefty)
  225. myBit.Dispose()
  226. myPicGrh.Dispose()
  227. End Sub
  228. End Class