Beispiel #1
0
        /// <summary>
        /// Event Handler of the button Delete.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int id = 0;

            string[] items;
            if (!(lbPersonas.SelectedItem is null))
            {
                items = lbPersonas.SelectedItem.ToString().Split(' ');
                id    = Convert.ToInt32(items[0]);
                PersonaDAO.Borrar(id);
                UpdateListBox();
            }
        }
Beispiel #2
0
        private void btnModificar_Click(object sender, EventArgs e)
        {
            string nombre;
            string apellido;
            int    id;

            PersonaDAO personaDAO = new PersonaDAO();

            nombre   = txtNombre.Text;
            apellido = txtApellido.Text;
            id       = ((Persona)lstPersonas.SelectedItem).Id;

            personaDAO.Modificar(id, nombre, apellido);
        }
Beispiel #3
0
 private void btn_Modificar_Click(object sender, EventArgs e)
 {
     try
     {
         Persona auxP = (Persona)datagrid_Personas.CurrentRow.DataBoundItem;
         if (PersonaDAO.Modificar(auxP))
         {
             MessageBox.Show("Se Modificaron los datos correctamente", "Modificacion Exitosa", MessageBoxButtons.OK);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            string nombre;
            string apellido;

            PersonaDAO personaDAO;
            Persona    auxPersona;

            personaDAO = new PersonaDAO();

            nombre   = txtNombre.Text;
            apellido = txtApellido.Text;

            auxPersona = new Persona(nombre, apellido);

            personaDAO.Guardar(auxPersona);
        }
Beispiel #5
0
 private void btnLeer_Click(object sender, EventArgs e)
 {
     try
     {
         personas = PersonaDAO.Leer();
         ltsPersonas.Items.Clear();
         ltsPersonas.BeginUpdate();
         foreach (Persona p in personas)
         {
             ltsPersonas.Items.Add(String.Format("{0} {1}", p.Nombre, p.Apellido));
         }
         ltsPersonas.EndUpdate();
     }
     catch (Exception ex)
     {
         MessageBox.Show("ERROR: " + ex.ToString());
     }
 }
Beispiel #6
0
        private void btnLeer_Click(object sender, EventArgs e)
        {
            PersonaDAO     personaDAO;
            List <Persona> listaPersonas;

            personaDAO = new PersonaDAO();

            lstPersonas.Items.Clear();

            listaPersonas = personaDAO.Leer();

            foreach (Persona persona in listaPersonas)
            {
                lstPersonas.Items.Add(persona);
            }

            lstPersonas.DisplayMember = "Id";

            txtNombre.Clear();
            txtApellido.Clear();
        }
Beispiel #7
0
 private void btn_Guardar_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(txt_Name.Text) || string.IsNullOrEmpty(txt_LastName.Text))
         {
             throw new Exception("El o los campos de Nombre y Apellido no pueden quedar vacios.");
         }
         else
         {
             Persona persona = new Persona(txt_Name.Text, txt_LastName.Text, checkBox.Checked);
             if (PersonaDAO.Guardar(persona))
             {
                 MessageBox.Show("Se creo la persona con éxito", "Exito", MessageBoxButtons.OK);
                 ActualizarDataGrid();
             }
         }
         LimpiarTxtBox();
     }  catch (Exception ex) {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
     }
 }
Beispiel #8
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     if (txtNombre.Text.Length > 0 && txtApellido.Text.Length > 0)
     {
         Persona persona = new Persona(txtNombre.Text, txtApellido.Text);
         try
         {
             if (PersonaDAO.Guardar(persona))
             {
                 MessageBox.Show("Guardado correctamente!!");
                 btnLeer_Click(sender, e);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("ERROR: " + ex.ToString());
         }
     }
     else
     {
         MessageBox.Show("Para agregar las casillas de nombre y apellido no pueden estar vacías.");
     }
 }
Beispiel #9
0
 private void btnEliminar_Click(object sender, EventArgs e)
 {
     try
     {
         int index = ltsPersonas.SelectedIndex;
         if (index >= 0)
         {
             Persona p = personas[index];
             if (PersonaDAO.Borrar(p.Identificacion))
             {
                 MessageBox.Show("Eliminado correctamente!!");
                 btnLeer_Click(sender, e);
             }
         }
         else
         {
             MessageBox.Show("Debe seleccionar a alguien de la lista.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("ERROR: " + ex.ToString());
     }
 }
Beispiel #10
0
 public Form1()
 {
     InitializeComponent();
     dao = new PersonaDAO();
 }
Beispiel #11
0
 private void ActualizarDataGrid()
 {
     datagrid_Personas.DataSource = null;
     datagrid_Personas.DataSource = PersonaDAO.Leer();
 }
 private void Form1_Load(object sender, EventArgs e)
 {
     baseDeDatos = new PersonaDAO();
 }
 public Form1()
 {
     InitializeComponent();
     personaDAO    = new PersonaDAO();
     listaPersonas = new List <Persona>();
 }