コード例 #1
0
 private void btnHapus_Click(object sender, EventArgs e)
 {
     using (var db = new MenuModel())
     {
         db.Menus.RemoveRange(db.Menus.Where(item => item.Nama == lblMenu.Text));
         db.SaveChanges();
         lblMenu.Text     = "-";
         lblHarga.Text    = "-";
         lblStock.Text    = "-";
         btnEdit.Enabled  = false;
         btnHapus.Enabled = false;
     }
 }
コード例 #2
0
 private void EditMenu()
 {
     using (var db = new MenuModel())
     {
         var result = db.Menus.SingleOrDefault(m => m.Nama == menu.Nama);
         if (result != null)
         {
             if (tbNama.Text != "" && tbHarga.Text != "" && tbStock.Text != "")
             {
                 result.Nama  = tbNama.Text;
                 result.Harga = tbHarga.Text;
                 result.Stock = tbStock.Text;
                 db.SaveChanges();
                 MessageBox.Show("Menu berhasil diperbarui");
                 Close();
             }
             else
             {
                 MessageBox.Show("Detail menu yang dimasukkan belum lengkap");
             }
         }
     }
 }
コード例 #3
0
 private void TambahMenu()
 {
     if (tbNama.Text != "" && tbHarga.Text != "" && tbStock.Text != "")
     {
         using (var db = new MenuModel())
         {
             Menu newMenu = new Menu
             {
                 Nama  = tbNama.Text,
                 Harga = tbHarga.Text,
                 Stock = tbStock.Text,
             };
             db.Menus.Add(newMenu);
             db.SaveChanges();
             MessageBox.Show("Menu berhasil ditambahkan");
             Close();
         }
     }
     else
     {
         MessageBox.Show("Data yang dimasukkan belum lengkap");
     }
 }