protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Excluir") { int codigo; // Le o numero da linha selecionada int index = Convert.ToInt32(e.CommandArgument); // Copia o conteúdo da primeira célula da linha -> Código do Livro codigo = Convert.ToInt32(GridView1.Rows[index].Cells[0].Text); DAL.DALAlternativaDesafio dalalterna = new DAL.DALAlternativaDesafio(); Modelo.alternativaDesafio alterna = new Modelo.alternativaDesafio(); alterna = dalalterna.Select(codigo)[0]; dalalterna.Delete(alterna); // Chama a tela de edição Response.Redirect("~\\WebFormAlternativaDesafioNew.aspx"); } }
protected void Button1_Click(object sender, EventArgs e) { DAL.DALAlternativaDesafio dalaterna = new DAL.DALAlternativaDesafio(); Modelo.alternativaDesafio alterna; if (dalaterna.calcAlterna(Convert.ToInt32(Session["idDesafio"])) < 5) { if ((!dalaterna.verifCorreta(Convert.ToInt32(Session["idDesafio"]))) && (Session["correta"] == "verdade")) { alterna = new Modelo.alternativaDesafio(TextBox1.Text, true, Convert.ToInt32(Session["idDesafio"])); dalaterna.Insert(alterna); Response.Redirect("~/WebFormAlternativaDesafioNew.aspx"); } else { if (Session["correta"] != "verdade") { if ((!dalaterna.verifCorreta(Convert.ToInt32(Session["idDesafio"]))) && (dalaterna.calcAlterna(Convert.ToInt32(Session["idDesafio"])) == 4)) { Label1.Text = "Você precisa ter pelo menos 1 alternativa correta"; } else { alterna = new Modelo.alternativaDesafio(TextBox1.Text, false, Convert.ToInt32(Session["idDesafio"])); dalaterna.Insert(alterna); Response.Redirect("~/WebFormAlternativaDesafioNew.aspx"); } } else { Label1.Text = "A questão já possui uma alternativa correta, você não pode adicionar outra"; } } } else { Label1.Text = "A questão só pode possuir no máximo 5 alternativas"; } }
protected void Button1_Click(object sender, EventArgs e) { //Define a label como vazia e os radiobutton vazios Label6.Text = ""; RadioButton1.Checked = false; RadioButton2.Checked = false; RadioButton3.Checked = false; RadioButton4.Checked = false; RadioButton5.Checked = false; //Definindo variáveis que serão utilizadas na table TableRow tr1, tr2, tr3, tr4; TableCell tc0; Label titulo = new Label(); Label dificuldade = new Label(); Label questao = new Label(); Image fotoquestao = new Image(); Label c = new Label(); int codigo = Convert.ToInt32(DropDownList1.SelectedItem.Value); DAL.DALDesafio daldes = new DAL.DALDesafio(); Modelo.Desafio des = new Modelo.Desafio(); des = daldes.Select(codigo)[0]; DAL.DALDificuldade daldif = new DAL.DALDificuldade(); Modelo.Dificuldade dif = new Modelo.Dificuldade(); dif = daldif.Select(des.idDificuldade)[0]; //Adicionando título da questão do Desafio na table titulo.Text = des.titulo; titulo.Font.Name = "Segoe UI Light"; titulo.Font.Size = 16; titulo.Font.Bold = true; tc0 = new TableCell(); tc0.Controls.Add(titulo); tr1 = new TableRow(); tr1.Cells.Add(tc0); Table1.Rows.Add(tr1); dificuldade.Text = dif.grau; dificuldade.Font.Name = "Segoe UI Light"; dificuldade.Font.Size = 14; dificuldade.Font.Bold = true; tc0 = new TableCell(); tc0.Controls.Add(dificuldade); tr4 = new TableRow(); tr4.Cells.Add(tc0); Table1.Rows.Add(tr4); //Adicionando imagem da questão do Desafio na table if (des.fotoquestao != null) { fotoquestao.ImageUrl = "~/HandlerDesafio2.ashx?idDesafio=" + codigo; } tc0 = new TableCell(); tc0.Controls.Add(fotoquestao); tr2 = new TableRow(); tr2.Cells.Add(tc0); Table1.Rows.Add(tr2); //Adicionando texto da questão do Desafio na table questao.Text = des.questao; questao.Font.Name = "Segoe UI Light"; questao.Font.Size = 14; questao.Font.Bold = true; tc0 = new TableCell(); tc0.Controls.Add(questao); tr3 = new TableRow(); tr3.Cells.Add(tc0); Table1.Rows.Add(tr3); DAL.DALAlternativaDesafio dalalterna = new DAL.DALAlternativaDesafio(); List <Modelo.alternativaDesafio> alterna = new List <Modelo.alternativaDesafio>(); int aux; for (int i = 0; i < dalalterna.calcAlterna(codigo); i++) { aux = dalalterna.idAlternativa(codigo)[i]; alterna.Add(dalalterna.Select(aux)[0]); if (i == 0) { Label1.Text = alterna[i].texto; RadioButton1.Visible = true; if (alterna[i].correta == true) { RadioButton1.Font.Name = "Arial"; } else { RadioButton1.Font.Name = "Segoe UI Light"; } } if (i == 1) { Label2.Text = alterna[i].texto; RadioButton2.Visible = true; if (alterna[i].correta == true) { RadioButton2.Font.Name = "Arial"; } else { RadioButton2.Font.Name = "Segoe UI Light"; } } if (i == 2) { Label3.Text = alterna[i].texto; RadioButton3.Visible = true; if (alterna[i].correta == true) { RadioButton3.Font.Name = "Arial"; } else { RadioButton3.Font.Name = "Segoe UI Light"; } } if (i == 3) { Label4.Text = alterna[i].texto; RadioButton4.Visible = true; if (alterna[i].correta == true) { RadioButton4.Font.Name = "Arial"; } else { RadioButton4.Font.Name = "Segoe UI Light"; } } if (i == 4) { Label5.Text = alterna[i].texto; RadioButton5.Visible = true; if (alterna[i].correta == true) { RadioButton5.Font.Name = "Arial"; } else { RadioButton5.Font.Name = "Segoe UI Light"; } } } }
protected void Button2_Click(object sender, EventArgs e) { //Definindo variáveis que serão utilizadas na table TableRow tr1, tr2, tr3; TableCell tc0; Label titulo = new Label(); Label questao = new Label(); Image fotoquestao = new Image(); Label c = new Label(); int codigo = Convert.ToInt32(DropDownList1.SelectedItem.Value); DAL.DALDesafio daldes = new DAL.DALDesafio(); Modelo.Desafio des = new Modelo.Desafio(); des = daldes.Select(codigo)[0]; //Adicionando título da questão do Desafio na table titulo.Text = des.titulo; titulo.Font.Name = "Segoe UI Light"; titulo.Font.Size = 16; titulo.Font.Bold = true; tc0 = new TableCell(); tc0.Controls.Add(titulo); tr1 = new TableRow(); tr1.Cells.Add(tc0); Table1.Rows.Add(tr1); //Adicionando imagem da questão do Desafio na table if (des.fotoquestao != null) { fotoquestao.ImageUrl = "~/HandlerDesafio2.ashx?idDesafio=" + codigo; } tc0 = new TableCell(); tc0.Controls.Add(fotoquestao); tr2 = new TableRow(); tr2.Cells.Add(tc0); Table1.Rows.Add(tr2); //Adicionando texto da questão do Desafio na table questao.Text = des.questao; questao.Font.Name = "Segoe UI Light"; questao.Font.Size = 14; questao.Font.Bold = true; tc0 = new TableCell(); tc0.Controls.Add(questao); tr3 = new TableRow(); tr3.Cells.Add(tc0); Table1.Rows.Add(tr3); DAL.DALAlternativaDesafio dalalterna = new DAL.DALAlternativaDesafio(); List <Modelo.alternativaDesafio> alterna = new List <Modelo.alternativaDesafio>(); alterna = dalalterna.SelectAll(codigo); DAL.DALRespostaDoAlunoDesafio dalresposta = new DAL.DALRespostaDoAlunoDesafio(); Modelo.RespostaDoAlunoDesafio resposta; string nome = Session["Nome"].ToString(); for (int i = 0; i < dalalterna.calcAlterna(codigo); i++) { if (i == 0) { if ((RadioButton1.Font.Name == "Arial") && (RadioButton1.Checked)) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[i].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "✓"; break; } else if ((RadioButton2.Checked) && (RadioButton2.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[1].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton3.Checked) && (RadioButton3.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[2].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton4.Checked) && (RadioButton4.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[3].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton5.Checked) && (RadioButton5.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[4].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } } if (i == 1) { if ((RadioButton2.Font.Name == "Arial") && (RadioButton2.Checked)) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[i].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "✓"; break; } else if ((RadioButton1.Checked) && (RadioButton1.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[0].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton3.Checked) && (RadioButton3.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[2].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton4.Checked) && (RadioButton4.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[3].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton5.Checked) && (RadioButton5.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[4].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } } if (i == 2) { if ((RadioButton3.Font.Name == "Arial") && (RadioButton3.Checked)) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[i].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "✓"; break; } else if ((RadioButton1.Checked) && (RadioButton1.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[0].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton2.Checked) && (RadioButton2.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[1].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton4.Checked) && (RadioButton4.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[3].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton5.Checked) && (RadioButton5.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[4].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } } if (i == 3) { if ((RadioButton4.Font.Name == "Arial") && (RadioButton4.Checked)) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[i].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "✓"; break; } else if ((RadioButton1.Checked) && (RadioButton1.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[0].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton2.Checked) && (RadioButton2.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[1].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton3.Checked) && (RadioButton3.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[2].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton5.Checked) && (RadioButton5.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[4].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } } if (i == 4) { if ((RadioButton5.Font.Name == "Arial") && (RadioButton5.Checked)) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[i].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "✓"; break; } else if ((RadioButton1.Checked) && (RadioButton1.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[0].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton2.Checked) && (RadioButton2.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[1].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton3.Checked) && (RadioButton3.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[2].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } else if ((RadioButton4.Checked) && (RadioButton4.Font.Name != "Arial")) { resposta = new Modelo.RespostaDoAlunoDesafio(nome, alterna[3].idAlternativa); dalresposta.Insert(resposta); Label6.Text = "<g style='color: red;'>X</g>"; break; } } } }