private void BtnFilter_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtData.Text)) { dataGridView1.DataSource = PeopleDB.Filter(txtData.Text); } }
private void BtnAdd_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtAge.Text)) { MessageBox.Show("Todos los datos son obligatorios", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Person person = new Person() { Name = txtName.Text, Age = Int32.Parse(txtAge.Text) }; if (Id != null) { if (PeopleDB.Update(person, (int)Id) == -1) { MessageBox.Show("No se pudo actualizar el registro, verifique", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { if (PeopleDB.Insert(person) == -1) { MessageBox.Show("No se pudo guardar el registro, verifique", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } this.Close(); }
private void LoadPerson(int id) { Person person = PeopleDB.GetPeople(id); txtName.Text = person.Name; txtAge.Text = person.Age.ToString(); }
private void BtnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("¿Desea eliminar este registro?", "Eliminar", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { int?id = GetId(); if (id != null) { PeopleDB.Delete((int)id); RefreshGrid(); } } }
private void RefreshGrid() { dataGridView1.DataSource = PeopleDB.GetPeople(); }