Beispiel #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_DatabaseEntities db = new SPM_DatabaseEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Customers.Attach(model);
             }
             db.Customers.Remove(model);
             db.SaveChanges();
             PopulateDataGridView();
             Clear();
             MessageBox.Show("Deleted Successfully", "SPM Connect", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Beispiel #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     model.CustomerId = Convert.ToInt16(custidtxt.Text.ToString());
     model.Name       = custname.Text.Trim();
     model.ShortName  = shortname.Text.Trim();
     model.Alias      = alias.Text.Trim();
     using (SPM_DatabaseEntities db = new SPM_DatabaseEntities())
     {
         if (model.id == 0)//Insert
         {
             db.Customers.Add(model);
         }
         else //Update
         {
             db.Entry(model).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
     Clear();
     PopulateDataGridView();
     MessageBox.Show("Submitted Successfully", "SPM Connect", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }