private void btCadastrar_Click(object sender, EventArgs e) { if (dgvSalas.RowCount != 1) { using (var db = new dbEscala()) { try { for (int op = 0; op < dgvSalas.RowCount - 1; op++) { salas sa = new salas(); sa.DESCRICAO = Convert.ToString(dgvSalas.Rows[op].Cells[0].Value); db.Entry(sa).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } MessageBox.Show("Cadastro realizado com sucesso!!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvSalas.Rows.Clear(); TxtSala.Focus(); } catch (Exception err) { MessageBox.Show("Erro" + err, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Não há nada cadastrado", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void btCadastrar_Click(object sender, EventArgs e) { try { using (var db = new dbEscala()) { if (dgvEscalas.RowCount > 1) { for (int op = 0; op < dgvEscalas.RowCount - 1; op++) { int idsal = Convert.ToInt32(dgvEscalas.Rows[op].Cells[1].Value); int ides = db.escala.Where(d => d.IDSAL_ALUNO == idsal).FirstOrDefault().ID; escala es = db.escala.Find(ides); es.DT_INICIO = Convert.ToDateTime(dtpInicio.Text); es.DT_FINAL = Convert.ToDateTime(dtpTermino.Text).AddDays(30); es.USE = 1; db.Entry(es).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } config cf = db.config.Find(1); cf.DT_INICIO = Convert.ToDateTime(dtpInicio.Text); cf.DT_FINAL = Convert.ToDateTime(dtpTermino.Text); db.Entry(cf).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Escalas cadastradas com sucesso!!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); txtDescAluno.Clear(); txtIDAluno.Clear(); txtIDSala.Clear(); txtNomeSala.Clear(); dgvEscalas.Rows.Clear(); } else { MessageBox.Show("Nenhum aluno cadastrado ", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch (Exception err) { MessageBox.Show("Erro " + err, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btCadastrar_Click(object sender, EventArgs e) { if (dgvAlunos.RowCount > 1) { DateTime hoje = DateTime.Now.Date; try { using (var db = new dbEscala()) { for (int op = 0; op < dgvAlunos.RowCount - 1; op++) { string cpf = Convert.ToString(dgvAlunos.Rows[op].Cells[1].Value); int prima = db.alunos.Where(d => d.CPF == cpf).Count(); if (prima != 0) { int idaluno = db.alunos.Where(d => d.CPF == cpf).FirstOrDefault().ID; alunos al = db.alunos.Find(idaluno); sal_aluno sa = new sal_aluno(); sa.IDALUNO = al.ID; sa.IDSALA = Convert.ToInt32(dgvAlunos.Rows[op].Cells[4].Value); db.Entry(sa).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); escala es = new escala(); es.IDSAL_ALUNO = sa.ID; es.DT_INICIO = hoje; es.DT_FINAL = hoje; db.Entry(es).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } else { alunos al = new alunos(); al.NOME = Convert.ToString(dgvAlunos.Rows[op].Cells[0].Value); al.CPF = Convert.ToString(dgvAlunos.Rows[op].Cells[1].Value); al.DT_INICIO = Convert.ToDateTime(dgvAlunos.Rows[op].Cells[2].Value); al.DT_FINAL = Convert.ToDateTime(dgvAlunos.Rows[op].Cells[3].Value); al.ATIVO = 1; al.DELETADO = 0; db.Entry(al).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); sal_aluno sa = new sal_aluno(); sa.IDALUNO = al.ID; sa.IDSALA = Convert.ToInt32(dgvAlunos.Rows[op].Cells[4].Value); db.Entry(sa).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); escala es = new escala(); es.IDSAL_ALUNO = sa.ID; es.DT_INICIO = hoje; es.DT_FINAL = hoje; db.Entry(es).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } } dgvAlunos.Rows.Clear(); MessageBox.Show("Aluno cadastrado com sucesso!!! ", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); txtNome.Focus(); } } catch (Exception err) { MessageBox.Show("Erro " + err, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Nenhum Aluno cadastrado!! ", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }