Exemple #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure to Delete this Record ?", "SPM Connect", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         using (SPM_DatabaseEntities1 db = new SPM_DatabaseEntities1())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Materials.Attach(model);
             }
             db.Materials.Remove(model);
             db.SaveChanges();
             PopulateDataGridView();
             Clear();
             MessageBox.Show("Deleted Successfully", "SPM Connect", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Exemple #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     model.MaterialNames = custname.Text.Trim();
     using (SPM_DatabaseEntities1 db = new SPM_DatabaseEntities1())
     {
         if (model.id == 0)//Insert
         {
             db.Materials.Add(model);
         }
         else //Update
         {
             db.Entry(model).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
     Clear();
     PopulateDataGridView();
     MessageBox.Show("Submitted Successfully", "SPM Connect", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }