private void btnNew_Click(object sender, EventArgs e) { tbId.Text = EstadoReparacao.GetNewId().ToString(); tbNome.Text = string.Empty; tbNome.Enabled = true; // btnEdit.Visible = false; btnDelete.Visible = false; btnNew.Visible = false; btnClose.Visible = false; btnCancelar.Visible = true; btnGuardar.Visible = true; tbDefault.SelectedIndex = 1; }
private void btnGuardar_Click(object sender, EventArgs e) { bool check = false; int id = -1; foreach (DataGridViewRow row in dgvList.Rows) { if (row.Cells[0].Value.ToString().Equals(tbId.Text)) { check = true; id = Convert.ToInt32(row.Cells[0].Value); } } if (!check) { if (EstadoReparacao.NewStates(tbNome.Text)) { MessageBox.Show("Estado adicionado com sucesso."); } else { MessageBox.Show("Não foi possivel adicionar o novo estado."); } } else if (id != -1) { if (EstadoReparacao.UpdateStates(id, tbNome.Text)) { MessageBox.Show("Estado atualizado com sucesso."); } else { MessageBox.Show("Não foi possivel atualizar o estado."); } } tbNome.Enabled = false; btnEdit.Visible = true; btnDelete.Visible = true; btnNew.Visible = true; btnClose.Visible = true; btnCancelar.Visible = false; btnGuardar.Visible = false; tbDefault.SelectedIndex = 0; }
private void btnDelete_Click(object sender, EventArgs e) { /*Obter o veiculo*/ if (dgvList.SelectedRows.Count != 0 && MessageBox.Show(string.Format("Secção: {0}\n\nTem certeza que deseja eliminar esta secção?", dgvList.SelectedRows[0].Cells[1].Value.ToString()), "Eliminar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { /*Eliminar o veiculo*/ if (EstadoReparacao.DeleteStates(Convert.ToInt32(dgvList.SelectedRows[0].Cells[0].Value.ToString()))) { MessageBox.Show("Secção eliminada com sucesso.", "Resultado", MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateGrid(); } else { MessageBox.Show("Não foi possivel eliminar esta secção.", "Resultado", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void UpdateGrid() { dgvList.DataSource = EstadoReparacao.GetAllStates(); }