Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CekPengguna()
- SQL = "Select * From Pengguna Where KodePengguna='" & KodePengguna.Text & "'"
- ProsesData(0)
- If RS.HasRows = True Then
- RS.Read()
- NamaPengguna.Text = RS("NamaPengguna")
- Alamat.Text = RS("AlamatPengguna")
- Telepon.Text = RS("Telepon")
- Username.Text = RS("Username")
- password.Text = RS("Password")
- status.Text = RS("level")
- 'Dim imageBytes() As Byte = CType(RS!Gambar, Byte())
- 'Dim ImgMS As New System.IO.MemoryStream(imageBytes)
- 'Foto.Image = Image.FromStream(ImgMS)
- 'Foto.SizeMode = PictureBoxSizeMode.StretchImage
- rawData = DirectCast(RS.Item("gambar"), Byte())
- ms = New MemoryStream(rawData)
- Foto.Image = Image.FromStream(ms)
- Foto.SizeMode = PictureBoxSizeMode.StretchImage
- RubahTombol(2, Baru, Simpan, Hapus, Batal, Keluar)
- Simpan.Image = My.Resources.onebit_19
- Cari.Enabled = True
- Else
- RubahTombol(1, Baru, Simpan, Hapus, Batal, Keluar)
- Simpan.Image = My.Resources.onebit_11
- Cari.Enabled = True
- End If
- RS.Close()
- CMD.Dispose()
- ValidasiForm(Me, 0)
- KodePengguna.Enabled = False
- NamaPengguna.Focus()
- End Sub
- Private Sub SaveGambar(ByVal namanya As String)
- Try
- fs = New FileStream(pathfile, FileMode.Open, FileAccess.Read)
- fileSize = fs.Length
- rawData = New Byte(fileSize) {}
- fs.Read(rawData, 0, fileSize)
- fs.Close()
- fs.Dispose()
- SQL = "update Pengguna set Gambar=@File where KodePengguna ='" & KodePengguna.Text & "'"
- CMD.Connection = DB
- CMD.CommandText = SQL
- CMD.Parameters.AddWithValue("@File", rawData)
- CMD.ExecuteNonQuery()
- Catch ex As Exception
- MessageBox.Show("There was an error: " & ex.Message, "Error", _
- MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- RS.Close()
- cmd.Dispose()
- End Sub
- Private Sub Simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan.Click
- If Foto.Image Is Nothing Then
- MsgBox("Foto Tidak Boleh Kosong", MsgBoxStyle.Exclamation, "PERINGATAN")
- Return
- End If
- If Not CekData(Me) Then
- If Simpan.Text = "Simpan" Then
- SQL = "insert into Pengguna (KodePengguna,NamaPengguna,AlamatPengguna,Telepon,Username,Password,Level) Values ('" & KodePengguna.Text & _
- "','" & NamaPengguna.Text & _
- "','" & Alamat.Text & _
- "','" & Telepon.Text & _
- "','" & Username.Text & _
- "','" & password.Text & _
- "','" & status.Text & "')"
- MsgBox(NamaPengguna.Text & " Berhasil Disimpan", MsgBoxStyle.Information, "Berhasil")
- ProsesData(1)
- SaveGambar(pathfile)
- ElseIf Simpan.Text = "Edit" Then
- SQL = "Update Pengguna Set NamaPengguna='" & NamaPengguna.Text & _
- "', AlamatPengguna='" & Alamat.Text & _
- "', Telepon='" & Telepon.Text & _
- "', UserName='" & Username.Text & _
- "', Password='" & password.Text & "', Level='" & status.Text & " ' " & _
- " Where KodePengguna='" & KodePengguna.Text & "'"
- MsgBox(NamaPengguna.Text & " Berhasil Diperbarui", MsgBoxStyle.Information, "Berhasil")
- ProsesData(1)
- SaveGambar(pathfile)
- End If
- Bersih()
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement