コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (EmpresaEntities db = new EmpresaEntities())
            {
                if (id == null)
                {
                    oPersona = new Persona();
                }
                oPersona.Nombre   = name.Text;
                oPersona.Apellido = lastname.Text;
                oPersona.Genero   = gender.Text;
                oPersona.Correo   = mail.Text;
                oPersona.Telefono = Convert.ToInt32(phone.Text);

                if (id == null)
                {
                    db.Persona.Add(oPersona);
                }
                else
                {
                    db.Entry(oPersona).State = System.Data.Entity.EntityState.Modified;
                }
                db.SaveChanges();
                this.Close();
            }
        }
コード例 #2
0
 private void Listar()
 {
     using (EmpresaEntities db = new EmpresaEntities())
     {
         var lst = from d in db.Persona select d;
         tabla.DataSource = lst.ToList();
     }
 }
コード例 #3
0
 private void cargarDatos()
 {
     using (EmpresaEntities db = new EmpresaEntities())
     {
         oPersona      = db.Persona.Find(id);
         name.Text     = oPersona.Nombre;
         lastname.Text = oPersona.Apellido;
         gender.Text   = oPersona.Genero;
         phone.Text    = oPersona.Telefono.ToString();
         mail.Text     = oPersona.Correo;
     }
 }
コード例 #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            int?id;

            try
            {
                id = int.Parse(tabla.Rows[tabla.CurrentRow.Index].Cells[0].Value.ToString());
            }
            catch
            {
                id = null;
            }
            using (EmpresaEntities db = new EmpresaEntities())
            {
                Persona p = db.Persona.Find(id);
                db.Persona.Remove(p);
                db.SaveChanges();
            }
            Listar();
        }