예제 #1
0
        private void Save()
        {
            //using EF
            using (DBPersonEntities db = new DBPersonEntities())
            {
                //Create a entity
                if (id == null)
                {
                    oPerson = new Person();
                }
                //Acess to data
                oPerson.Id          = int.Parse(this.txtDNI.Text);
                oPerson.FirstName   = txtFirstName.Text;
                oPerson.LastName    = txtLastName.Text;
                oPerson.DateOfBirth = dtpDateOfBirth.Value;
                oPerson.Age         = txtAge.Text;
                oPerson.Address     = txtAdress.Text;
                oPerson.City        = txtCity.Text;

                //Save in the tPerson
                if (id == null)
                {
                    db.People.Add(oPerson);
                }
                else
                {
                    db.Entry(oPerson).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();
                Clean();
            }

            MessageBox.Show("Save Successfull");
        }
예제 #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            int?id = getId();

            if (id != null)
            {
                using (DBPersonEntities db = new DBPersonEntities())
                {
                    Person oPerson = db.People.Find(id);
                    db.People.Remove(oPerson);
                    db.SaveChanges();
                }

                Refresh();
            }
        }