private void btnAlterar_Click(object sender, EventArgs e) { if (statcon.verificaInsercao(Id) == true) { StatusOS stat = new StatusOS(); stat.Id = Id; stat.Status_Id = Convert.ToInt32(cmbStatus.SelectedValue); stat.OS_Id = OS; stat.Descricao = txtDescricao.Text; stat.dataAlteracao = DateTime.Now; statcon.trataRequisicao(btnAlterar.Text, stat); } this.Close(); }
public void trataRequisicao(String operacao, StatusOS fun) { if (operacao.Equals("Cadastrar")) { var erros = Validacao.Valida(fun); if (erros.Count() == 0) { try { db.StatusOS.Add(fun); db.SaveChanges(); MessageBox.Show("StatusOS cadastrado !!"); } catch (Exception e) { MessageBox.Show("Não foi possivel cadastrar o StatusOS : " + e.Message); } //fecha form } else { foreach (var e in erros) { MessageBox.Show(e.ToString()); } } } if (operacao.Equals("Alterar")) { var erros = Validacao.Valida(fun); if (erros.Count() == 0) { try { db.Entry(fun).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("StatusOS alterado com sucesso!"); } catch (Exception e) { MessageBox.Show("Não foi possivel alterar o StatusOS !" + e.Message); } //fecha form } else { foreach (var e in erros) { MessageBox.Show(e.ToString()); } } } if (operacao.Equals("Excluir")) { if (MessageBox.Show("Deseja realmente excluir este StatusOS?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { fun = db.StatusOS.Find(fun.Id); db.StatusOS.Remove(fun); db.SaveChanges(); MessageBox.Show("StatusOS excluido"); } catch (Exception e) { MessageBox.Show("Não foi possivel excluir: " + e.Message); } //Fecha form } } }