public void salvarProf(ProfessorEnt professor) { MySqlConnection con = new MySqlConnection(b.Conex()); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; con.Open(); cmd.CommandText = "INSERT INTO Professor (Login_Login, nome, email, cpf, telefone, data_nascimento, grau_formacao, formacao) VALUES (@login, @nome, @email, @cpf, @tel, @data, @grau, @formacao)"; cmd.Parameters.AddWithValue("@login", professor.Login); cmd.Parameters.AddWithValue("@nome", professor.Nome); cmd.Parameters.AddWithValue("@email", professor.Email); cmd.Parameters.AddWithValue("@cpf", professor.CPF); cmd.Parameters.AddWithValue("@tel", professor.Telefone); cmd.Parameters.AddWithValue("@data", professor.DataNasc); cmd.Parameters.AddWithValue("@grau", professor.Grau_Form); cmd.Parameters.AddWithValue("@formacao", professor.Form); try { cmd.Prepare(); cmd.ExecuteNonQuery(); MessageBox.Show("O dados do professor foram salvos com sucesso."); } catch (MySqlException) { MessageBox.Show("Erro com o login."); } con.Close(); }
public void alteraProf(ProfessorEnt profEnt, MaskedTextBox txtCod) { String login = txtCod.Text; MySqlConnection con = new MySqlConnection(b.Conex()); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; con.Open(); try { cmd.CommandText = "UPDATE Professor SET nome = '" + profEnt.Nome + "', email = '" + profEnt.Email + "', cpf = '" + profEnt.CPF + "', data_nascimento = '" + profEnt.DataNasc + "', telefone = '" + profEnt.Telefone + "', grau_formacao = '" + profEnt.Grau_Form + "', formacao = '" + profEnt.Form + "'"; } catch (Exception exp) { MessageBox.Show("Houve algum erro ao alterar. [Professor]" + exp.Message); } try { cmd.Prepare(); cmd.ExecuteNonQuery(); MessageBox.Show("Dados de professor alterados com sucesso."); } catch (Exception exc) { MessageBox.Show(exc.Message); } finally { con.Close(); } }
public RetornosDoModel AlterarProfessor(ref ProfessorEnt prof, ref string msg) { try { SqlCommand cmd = new SqlCommand(@"if(select COUNT(0) from tbl_professor where professor = @profe) > 0 print ('professor ja cadastrado') else UPDATE [tbl_professor] SET [professor] = @profe WHERE id_prof = @id", com.NovaConexaoBdAtaFinal()); cmd.Parameters.AddWithValue("@id", prof.id_prof); cmd.Parameters.AddWithValue("@profe", prof.professor); cmd.Connection.Open(); int linhasAfetadas = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (linhasAfetadas == -1) { msg = "já existe um professor com este nome"; return(RetornosDoModel.Existe); } else { return(RetornosDoModel.Cadastrado); } } catch (Exception erro) { msg = erro.Message; return(RetornosDoModel.Erro); } }
void CadastrarProfessor(ref ProfessorEnt prof) { string mensagem = ""; RetornosDoModel ret = turmas.InsertProfessor(ref prof, ref mensagem); switch (ret) { case RetornosDoModel.Erro: MessageBox.Show(mensagem); limpa(); break; case RetornosDoModel.Existe: MessageBox.Show(mensagem); limpa(); break; case RetornosDoModel.Cadastrado: Professores.Add(prof); LsBx.Items.Add(prof.professor); limpa(); break; } }
private void BtnSalvar_Click(object sender, RoutedEventArgs e) { switch (tras) { case transacao.Novo: ProfessorEnt prof = new ProfessorEnt { id_prof = 0, professor = txtProf.Text, login = "", tipo_de_usuario = "", senha = "" }; CadastrarProfessor(ref prof); tras = transacao.Indefinido; break; case transacao.Alterar: ProfessorEnt profe = new ProfessorEnt { id_prof = Professores[LsBx.SelectedIndex].id_prof, professor = Professores[LsBx.SelectedIndex].professor, tipo_de_usuario = Professores[LsBx.SelectedIndex].tipo_de_usuario, login = Professores[LsBx.SelectedIndex].login, senha = Professores[LsBx.SelectedIndex].senha, }; AlterarProfessor(ref profe); tras = transacao.Indefinido; break; } }
public RetornosDoModel CadastrarProfessor(ref ProfessorEnt prof, ref string mensagem) { try { SqlCommand cmd = new SqlCommand(@"if(select COUNT(0) from tbl_professor where professor = @prof) > 0 print ('professor ja esta cadastrado') else begin INSERT INTO [tbl_professor] ([professor] ,[tipo_de_usuario] ,[login] ,[senha]) VALUES (@prof ,@tipo ,@login ,@selnha) end", com.NovaConexaoBdAtaFinal()); cmd.Parameters.AddWithValue("@prof", prof.professor); cmd.Parameters.AddWithValue("@tipo", prof.tipo_de_usuario); cmd.Parameters.AddWithValue("@login", prof.login); cmd.Parameters.AddWithValue("@selnha", prof.senha); cmd.Connection.Open(); int linhasAfetadas = cmd.ExecuteNonQuery(); cmd.CommandText = "Select id_prof from tbl_professor where professor = @prof"; SqlDataReader data = cmd.ExecuteReader(); while (data.Read()) { prof.id_prof = int.Parse(data[0].ToString()); } cmd.Connection.Close(); if (linhasAfetadas == -1) { mensagem = "Professor já cadastrado"; return(RetornosDoModel.Existe); } else { mensagem = "professor cadastrado com sucesso"; return(RetornosDoModel.Cadastrado); } } catch (Exception erro) { mensagem = erro.Message; return(RetornosDoModel.Erro); } }
void DeletarProfessor(ref ProfessorEnt prof) { string msg = ""; RetornosDoModel retorno = turmas.DeletarProfessor(ref prof, ref msg); if (retorno == RetornosDoModel.Erro) { MessageBox.Show(msg); } else { LsBx.Items.Remove(prof.professor); Professores.Remove(prof); } }
public RetornosDoModel InsertProfessor(ref ProfessorEnt prof, ref string msg) { if (prof.professor.Length <= 5) { msg = "nome do professor inválido"; return(RetornosDoModel.Erro); } if (prof.professor == null) { msg = "nome do professor inválido"; return(RetornosDoModel.Erro); } return(bd.CadastrarProfessor(ref prof, ref msg)); }
public RetornosDoModel DeletaProfessor(ref ProfessorEnt prof, ref string mensage) { try { SqlCommand cmd = new SqlCommand("delete from tbl_professor where id_prof = @id", com.NovaConexaoBdAtaFinal()); cmd.Parameters.AddWithValue("@id", prof.id_prof); cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); mensage = "Deletado com sucesso"; return(RetornosDoModel.Cadastrado); } catch (Exception erro) { mensage = erro.Message; return(RetornosDoModel.Erro); } }
void AlterarProfessor(ref ProfessorEnt prof) { tras = transacao.Alterar; string mesg = ""; prof.professor = txtProf.Text; RetornosDoModel ret = turmas.AlterarProfessor(ref prof, ref mesg); if (ret == RetornosDoModel.Erro) { MessageBox.Show(mesg); } else if (ret == RetornosDoModel.Existe) { MessageBox.Show(mesg); } else { int i = LsBx.SelectedIndex; Professores[i] = prof; LsBx.Items[i] = prof.professor; } }
public RetornosDoModel AlterarProfessor(ref ProfessorEnt prof, ref string mesg) { return(bd.AlterarProfessor(ref prof, ref mesg)); }
public RetornosDoModel DeletarProfessor(ref ProfessorEnt prof, ref string msg) { return(bd.DeletaProfessor(ref prof, ref msg)); }
private void btnDeletar_Click(object sender, RoutedEventArgs e) { ProfessorEnt profe = Professores[LsBx.SelectedIndex]; DeletarProfessor(ref profe); }