SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.Odbc
  2.  
  3. Public Class Form1
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         Call koneksi()
  6.         Call tampilkan_pesanan()
  7.         Call tampilgrid()
  8.     End Sub
  9.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  10.         Call koneksi()
  11.         Call Otomatis()
  12.         cmd = New OdbcCommand("select * from jenis_makanan where id_jenis='" & ComboBox1.Text & "'", conn)
  13.         dr = cmd.ExecuteReader
  14.         If dr.HasRows Then
  15.             TextBox1.Text = dr(1)
  16.         End If
  17.     End Sub
  18.  
  19.     Sub tampilkan_pesanan()
  20.         Call koneksi()
  21.         cmd = New OdbcCommand(" select distinct id_jenis from jenis_makanan", conn)
  22.         dr = cmd.ExecuteReader
  23.         ComboBox1.Items.Clear()
  24.         Do While dr.Read ' ngelopping
  25.             ComboBox1.Items.Add(dr.Item("id_jenis"))
  26.         Loop
  27.     End Sub
  28.     Sub Otomatis()
  29.         Dim id As String
  30.         id = ComboBox1.Text
  31.         Call koneksi()
  32.         cmd = New OdbcCommand("select * from masakan where id_masakan in(select max(id_masakan) from masakan where LEFT(id_masakan, 5)='" & id & "')", conn)
  33.         dr = cmd.ExecuteReader
  34.         dr.Read()
  35.         If Not dr.HasRows Then
  36.             TextBox2.Text = id + Format(Now, "yyyy") + "01"
  37.         Else
  38.             If Microsoft.VisualBasic.Left(dr.Item("id_masakan"), 9) <> id + Format(Now, "yyyy") Then
  39.                 TextBox2.Text = id + Format(Now, "yyyy") + "01"
  40.             Else
  41.                 Dim a As String = CInt(Microsoft.VisualBasic.Right(dr.Item("id_masakan"), 2)) + 1
  42.                 TextBox2.Text = id + Format(Now, "yyyy") + Microsoft.VisualBasic.Right("00" & a, 2)
  43.             End If
  44.         End If
  45.     End Sub
  46.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  47.         OpenFileDialog1.Reset()
  48.         OpenFileDialog1.ShowDialog() 'menampilkan Browser Gambar
  49.         OpenFileDialog1.Filter = "(*.jpg) | *.jpg "
  50.         PictureBox1.Text = PictureBox1.Text + "<img>" + OpenFileDialog1.FileName + "</img>"
  51.         'menampilan pacth nya muncul foto ada di textbox4  
  52.         TextBox6.Text = OpenFileDialog1.FileName
  53.     End Sub
  54.  
  55.     Sub gambar() 'menampilkan gambar
  56.         On Error Resume Next
  57.         PictureBox1.Load(TextBox6.Text)
  58.         PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
  59.     End Sub
  60.  
  61.     Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
  62.         Call gambar()
  63.     End Sub
  64.     Sub bersihkan()
  65.         TextBox1.Text = ""
  66.         TextBox4.Text = ""
  67.         TextBox5.Text = ""
  68.         TextBox6.Text = ""
  69.         TextBox2.Text = ""
  70.         ComboBox2.Text = ""
  71.         TextBox3.Text = ""
  72.         ComboBox1.Text = ""
  73.         PictureBox1.Text = ""
  74.     End Sub
  75.  
  76.     Sub panggil_data()
  77.         On Error Resume Next
  78.         TextBox2.Text = dr.Item(0)
  79.         TextBox3.Text = dr.Item(1)
  80.         TextBox4.Text = dr.Item(2)
  81.         ComboBox1.Text = dr.Item(3)
  82.         ComboBox2.Text = dr.Item(4)
  83.         TextBox6.Text = dr.Item(5)
  84.     End Sub
  85.     Sub tampilgrid()
  86.         Call koneksi()
  87.         da = New OdbcDataAdapter("select * from masakan", conn)
  88.         ds = New DataSet
  89.         da.Fill(ds)
  90.         DGV.DataSource = ds.Tables(0)
  91.         DGV.ReadOnly = True
  92.     End Sub
  93.     Sub panggil_kode()
  94.         Call koneksi()
  95.         cmd = New OdbcCommand("select * from masakan where id_masakan='" & TextBox3.Text & "'", conn)
  96.         dr = cmd.ExecuteReader
  97.         dr.Read()
  98.     End Sub
  99.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  100.         If ComboBox1.Text = "" Or ComboBox2.Text = "" Or TextBox2.Text = "" Then
  101.             MsgBox("Data Belum Lengkap", MsgBoxStyle.Information, "INFORMASI NIH BOY")
  102.             Exit Sub
  103.         Else
  104.             Call panggil_kode()
  105.             'Koding Khusus Ketika Di Run Dan Enter ID Foto Bisa Muncul
  106.             Dim newtext As String
  107.             Dim oldtext As String = TextBox6.Text
  108.             newtext = oldtext.Replace("\", "\\")
  109.  
  110.             If Not dr.HasRows Then
  111.                 Dim simpan As String = "insert into masakan values('" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "', '" & ComboBox1.Text & "','" & ComboBox2.Text & "', '" & newtext & "')"
  112.                 cmd = New OdbcCommand(simpan, conn)
  113.                 cmd.ExecuteNonQuery()
  114.                 MsgBox("Data Berhasil Di Simpan", MsgBoxStyle.Information, "INFORMASI NIH BOY")
  115.                 Call bersihkan()
  116.             Else
  117.                 Dim edit As String = "update masakan set nama_masakan= '" & TextBox4.Text & "', harga_masakan='" & TextBox5.Text & "', status_masakan='" & ComboBox1.Text & "',id_jenis='" & ComboBox2.Text & "', foto_masakan='" & newtext & "' where id_masakan='" & TextBox3.Text & "'"
  118.                 cmd = New OdbcCommand(edit, conn)
  119.                 cmd.ExecuteNonQuery()
  120.                 MsgBox("BERHASIL DI UPDATE")
  121.             End If
  122.             Call tampilgrid()
  123.             Call bersihkan()
  124.         End If
  125.     End Sub
  126.  
  127.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  128.         Call bersihkan()
  129.     End Sub
  130.  
  131.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  132.         Me.Close()
  133.     End Sub
  134.     Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick
  135.         On Error Resume Next
  136.         TextBox3.Text = DGV.Rows(e.RowIndex).Cells(0).Value
  137.         Call panggil_kode()
  138.         If dr.HasRows Then
  139.             Call panggil_data()
  140.         End If
  141.     End Sub
  142.  
  143.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  144.         If TextBox1.Text = "" Then
  145.             MsgBox("Kode harus diisi")
  146.             TextBox1.Focus()
  147.             Exit Sub
  148.         End If
  149.         If MessageBox.Show("Hapus Jangan?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
  150.             Dim hapus As String = "delete from masakan where id_masakan='" & TextBox2.Text & "'"
  151.             cmd = New OdbcCommand(hapus, conn)
  152.             cmd.ExecuteNonQuery()
  153.             Call bersihkan()
  154.             Call tampilgrid()
  155.         End If
  156.     End Sub
  157.  
  158.     Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
  159.         Call koneksi()
  160.         da = New OdbcDataAdapter("select * from masakan where nama_masakan like '%" & TextBox3.Text & "%'", conn)
  161.         ds = New DataSet
  162.         da.Fill(ds)
  163.         DGV.DataSource = ds.Tables(0)
  164.         DGV.ReadOnly = True
  165.     End Sub
  166. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top