Пример #1
0
        private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                DataGridViewRow row = dataGridView.Rows[e.RowIndex];

                if (int.TryParse(row.Cells[0].Value.ToString(), out int id))
                {
                    Person person = DbData.Find(id);
                    FillForm(person);
                }
            }
        }
Пример #2
0
        private void InsertPerson()
        {
            Person person = new Person(txtFirstName.Text, txtLastName.Text, txtEmail.Text, txtPhone.Text);

            if (DbData.Insert(person) != -1)
            {
                MessageBox.Show("Registro agregado correctamente", "Nuevo registro", MessageBoxButtons.OK, MessageBoxIcon.Information);
                RefreshGrid();
                ClearForm();
                return;
            }

            MessageBox.Show("Hubo un error al registrar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Пример #3
0
        private void UpdatePerson()
        {
            Person person = new Person(txtFirstName.Text, txtLastName.Text, txtEmail.Text, txtPhone.Text);
            int    id     = Int32.Parse(lblID.Text);

            try
            {
                if (DbData.Update(person, id) != -1)
                {
                    MessageBox.Show("Registro actualizado correctamente", "Actualizar registro", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    RefreshGrid();
                    ClearForm();
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Hubo un error al actualizar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Пример #4
0
 private void RefreshGrid()
 {
     dataGridView.DataSource = DbData.GetData();
 }