예제 #1
0
 private void BtnFilter_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(txtData.Text))
     {
         dataGridView1.DataSource = PeopleDB.Filter(txtData.Text);
     }
 }
예제 #2
0
        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();
        }
예제 #3
0
        private void LoadPerson(int id)
        {
            Person person = PeopleDB.GetPeople(id);

            txtName.Text = person.Name;
            txtAge.Text  = person.Age.ToString();
        }
예제 #4
0
        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();
                }
            }
        }
예제 #5
0
 private void RefreshGrid()
 {
     dataGridView1.DataSource = PeopleDB.GetPeople();
 }