Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e) //Save
        {
            model.Food_ID     = textBox1.Text.Trim();
            model.Nama        = textBox2.Text.Trim();
            model.Category    = textBox3.Text.Trim();
            model.Harga       = textBox4.Text.Trim();
            model.Description = textBox5.Text.Trim();



            using (DBAdmin db = new DBAdmin())
            {
                if (model.Food_ID == null)
                {
                    db.FoodLists.Add(model);
                }
                else
                {
                    db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                }
                db.SaveChanges();
            }
            clear();
            PopulateDataGridView();
            MessageBox.Show("Submitted Successfully");
        }
Esempio n. 2
0
 private void button2_Click(object sender, EventArgs e) //Delete
 {
     if (MessageBox.Show("Apakah anda yakin?", "Yes or No", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (DBAdmin db = new DBAdmin())
         {
             var entry = db.Entry(model);
             if (entry.State == System.Data.Entity.EntityState.Detached)
             {
                 db.FoodLists.Attach(model);
             }
             db.FoodLists.Remove(model);
             db.SaveChanges();
             PopulateDataGridView();
             clear();
             MessageBox.Show("Delete Successful");
         }
     }
 }