Advertisement
Guest User

SUB

a guest
Aug 15th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. Sub CekPengguna()
  2. SQL = "Select * From Pengguna Where KodePengguna='" & KodePengguna.Text & "'"
  3. ProsesData(0)
  4. If RS.HasRows = True Then
  5. RS.Read()
  6. NamaPengguna.Text = RS("NamaPengguna")
  7. Alamat.Text = RS("AlamatPengguna")
  8. Telepon.Text = RS("Telepon")
  9. Username.Text = RS("Username")
  10. password.Text = RS("Password")
  11. status.Text = RS("level")
  12.  
  13. 'Dim imageBytes() As Byte = CType(RS!Gambar, Byte())
  14. 'Dim ImgMS As New System.IO.MemoryStream(imageBytes)
  15.  
  16. 'Foto.Image = Image.FromStream(ImgMS)
  17. 'Foto.SizeMode = PictureBoxSizeMode.StretchImage
  18.  
  19. rawData = DirectCast(RS.Item("gambar"), Byte())
  20. ms = New MemoryStream(rawData)
  21. Foto.Image = Image.FromStream(ms)
  22. Foto.SizeMode = PictureBoxSizeMode.StretchImage
  23.  
  24. RubahTombol(2, Baru, Simpan, Hapus, Batal, Keluar)
  25. Simpan.Image = My.Resources.onebit_19
  26. Cari.Enabled = True
  27. Else
  28. RubahTombol(1, Baru, Simpan, Hapus, Batal, Keluar)
  29. Simpan.Image = My.Resources.onebit_11
  30. Cari.Enabled = True
  31.  
  32. End If
  33. RS.Close()
  34. CMD.Dispose()
  35. ValidasiForm(Me, 0)
  36. KodePengguna.Enabled = False
  37. NamaPengguna.Focus()
  38. End Sub
  39. Private Sub SaveGambar(ByVal namanya As String)
  40. Try
  41. fs = New FileStream(pathfile, FileMode.Open, FileAccess.Read)
  42. fileSize = fs.Length
  43. rawData = New Byte(fileSize) {}
  44. fs.Read(rawData, 0, fileSize)
  45. fs.Close()
  46. fs.Dispose()
  47. SQL = "update Pengguna set Gambar=@File where KodePengguna ='" & KodePengguna.Text & "'"
  48. CMD.Connection = DB
  49. CMD.CommandText = SQL
  50. CMD.Parameters.AddWithValue("@File", rawData)
  51. CMD.ExecuteNonQuery()
  52. Catch ex As Exception
  53. MessageBox.Show("There was an error: " & ex.Message, "Error", _
  54. MessageBoxButtons.OK, MessageBoxIcon.Error)
  55. End Try
  56. RS.Close()
  57. cmd.Dispose()
  58. End Sub
  59. Private Sub Simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan.Click
  60. If Foto.Image Is Nothing Then
  61. MsgBox("Foto Tidak Boleh Kosong", MsgBoxStyle.Exclamation, "PERINGATAN")
  62. Return
  63. End If
  64. If Not CekData(Me) Then
  65. If Simpan.Text = "Simpan" Then
  66. SQL = "insert into Pengguna (KodePengguna,NamaPengguna,AlamatPengguna,Telepon,Username,Password,Level) Values ('" & KodePengguna.Text & _
  67. "','" & NamaPengguna.Text & _
  68. "','" & Alamat.Text & _
  69. "','" & Telepon.Text & _
  70. "','" & Username.Text & _
  71. "','" & password.Text & _
  72. "','" & status.Text & "')"
  73. MsgBox(NamaPengguna.Text & " Berhasil Disimpan", MsgBoxStyle.Information, "Berhasil")
  74. ProsesData(1)
  75. SaveGambar(pathfile)
  76. ElseIf Simpan.Text = "Edit" Then
  77. SQL = "Update Pengguna Set NamaPengguna='" & NamaPengguna.Text & _
  78. "', AlamatPengguna='" & Alamat.Text & _
  79. "', Telepon='" & Telepon.Text & _
  80. "', UserName='" & Username.Text & _
  81. "', Password='" & password.Text & "', Level='" & status.Text & " ' " & _
  82. " Where KodePengguna='" & KodePengguna.Text & "'"
  83. MsgBox(NamaPengguna.Text & " Berhasil Diperbarui", MsgBoxStyle.Information, "Berhasil")
  84. ProsesData(1)
  85. SaveGambar(pathfile)
  86. End If
  87. Bersih()
  88. End If
  89. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement