public bool inserir(ClasseEntity classeEntity) { classe classe = new classe(); classe.nome = classeEntity.Nome; DB.classes.InsertOnSubmit(classe); try { DB.SubmitChanges(); classeEntity.Id = classe.id; if (classeEntity.Professores.Count > 0) { foreach (PessoaEntity professor in classeEntity.Professores.Values) { professor_classe pfClasse = new professor_classe(); pfClasse.id_classe = classe.id; pfClasse.id_pessoa = professor.Id; DB.professor_classes.InsertOnSubmit(pfClasse); DB.SubmitChanges(); } } DB.SubmitChanges(); MessageBox.Show("Classe inserida com sucesso", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } catch (Exception ex) { Validator.tratarErrosSql("Classe", Validator.INSERIR, ex.Message); DB.Transaction.Rollback(); DB = new db_entityDataContext(); return(false); } }
public ClasseEntity GetOne(int id) { using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["API"].ConnectionString)) { using (SqlCommand cmd = c.CreateCommand()) { cmd.CommandText = "SELECT * FROM Classes WHERE Id = @Id AND Active = 1"; cmd.Parameters.AddWithValue("Id", id); c.Open(); using (SqlDataReader Tab = cmd.ExecuteReader()) { if (Tab.Read()) { ClasseEntity S = new ClasseEntity() { Id = (int)Tab["Id"], NameEN = Tab["NameEN"].ToString(), NameFR = Tab["NameFR"].ToString(), Active = (int)Tab["Active"] }; return(S); } else { return(null); } } } } }
public bool editar(ClasseEntity classeEntity, List <int> idsExcluirProfessor) { var query = from c in DB.classes where c.id == classeEntity.Id select c; foreach (classe ci in query) { ci.nome = classeEntity.Nome; } try { DB.SubmitChanges(); if (idsExcluirProfessor.Count > 0) { foreach (int idpessoa in idsExcluirProfessor) { var queryClasses = from c in DB.professor_classes where c.id_classe == classeEntity.Id where c.id_pessoa == idpessoa select c; foreach (professor_classe pc in queryClasses) { DB.professor_classes.DeleteOnSubmit(pc); DB.SubmitChanges(); } } } if (classeEntity.Professores.Count > 0) { //exclui todos os professores e inclui novamente var classeProfessor = from cp in DB.professor_classes where cp.classe.id == classeEntity.Id select cp; foreach (var cp in classeProfessor) { DB.professor_classes.DeleteOnSubmit(cp); } foreach (PessoaEntity professor in classeEntity.Professores.Values) { professor_classe pfClasse = new professor_classe(); pfClasse.id_classe = classeEntity.Id; pfClasse.id_pessoa = professor.Id; DB.professor_classes.InsertOnSubmit(pfClasse); DB.SubmitChanges(); } } MessageBox.Show("Classe editada com sucesso", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } catch (Exception ex) { Validator.tratarErrosSql("Classe", Validator.EDITAR, ex.Message); DB = new db_entityDataContext(); return(false); } }
public FormCadastroClasse(bool isSubCadastro) { InitializeComponent(); this.isSubCadastro = isSubCadastro; dao = new ClasseDAO(); daoProfessor = new ProfessorDAO(); formSearchProfessores = new FormSearch(daoProfessor); formSearchProfessores.FormAdd = new FormCadastroPessoaMembro(true); classe = new ClasseEntity(); idProfessoresExcluir = new List <int>(); configTela(); configEvents(); }
private void reset() { if (gridDados.RowCount > 0) { textBoxNome.Text = ""; gridDados.CurrentRow.Selected = false; classe = new ClasseEntity(); gridDados.Enabled = true; gridProfessores.Rows.Clear(); setEditarExcluirEnable(false); idProfessoresExcluir = new List <int>(); } }
public override Entity getEntityByIdentificador(int id) { ClasseEntity classe = new ClasseEntity(); var query = from c in DB.classes where c.id == id select new { c.id, c.nome }; foreach (var c in query) { classe.Id = c.id; classe.Nome = c.nome; } return(classe); }
private void getDadosRow() { foreach (DataGridViewColumn column in gridDados.Columns) { if (column.DataPropertyName == "Código") { int id = Int32.Parse((gridDados.CurrentRow.Cells[column.DisplayIndex].Value).ToString()); classe = dao.getClasseComProfessores(id); textBoxNome.Text = classe.Nome; gridProfessores.Rows.Clear(); foreach (PessoaEntity professor in classe.Professores.Values) { gridProfessores.Rows.Add(new Object[] { professor.Id, professor.Nome, professor.DataNascimento.ToString("dd/MM/yyyy") }); } gridProfessores.Refresh(); } } }
public ClasseEntity getClasseComProfessores(int id) { ClasseEntity classeEntity = new ClasseEntity(); var query = from cp in DB.professor_classes where cp.id_classe == id orderby cp.classe.nome select new { cp.id_classe, nomeClasse = cp.classe.nome, cp.professor }; foreach (var cp in query) { classeEntity.Id = cp.id_classe; classeEntity.Nome = cp.nomeClasse; PessoaEntity professor = new PessoaEntity(); professor.Id = cp.professor.id; professor.Nome = cp.professor.nome; professor.DataNascimento = (DateTime)cp.professor.data_nascimento; classeEntity.Professores.Add(professor.Id, professor); } return(classeEntity); }
public void Create(ClasseEntity T) { using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["API"].ConnectionString)) { using (SqlCommand cmd = c.CreateCommand()) { if (T != null && T.NameFR != null && T.NameEN != null) { cmd.CommandText = "SP_AddClasse"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter NameFR = new SqlParameter("NameFR", T.NameFR); SqlParameter NameEN = new SqlParameter("NameEN", T.NameEN); cmd.Parameters.Add(NameFR); cmd.Parameters.Add(NameEN); c.Open(); cmd.ExecuteNonQuery(); } } } }