Esempio n. 1
0
 public Form1(string titulo)
 {
     InitializeComponent();
     this.aula = Aulas.GetAula(titulo);
 }
Esempio n. 2
0
        public static Aula GetAula(string titulo)
        {
            SqlConnection con = new SqlConnection();

            cs = cs.Substring(cs.IndexOf("Data Source"));
            con.ConnectionString = cs;

            SqlCommand     cmd;
            SqlDataAdapter adapt;
            DataSet        ds = new DataSet();
            DataRow        dr;

            cmd = new SqlCommand("Select texto from paginaAula where aula = @aula", con);
            cmd.Parameters.AddWithValue("@aula", titulo);

            con.Open();
            adapt = new SqlDataAdapter(cmd);

            ds = new DataSet();
            adapt.Fill(ds);
            con.Close();
            Pagina[] pag = new Pagina[ds.Tables[0].Rows.Count];

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dr     = ds.Tables[0].Rows[i];
                pag[i] = new Pagina(dr.ItemArray[0].ToString());
            }

            cmd = new SqlCommand("Select pergunta, alternativaA, alternativaB, alternativaC, alternativaD, resposta from pergunta where aula = @aula", con);
            cmd.Parameters.AddWithValue("@aula", titulo);

            con.Open();
            adapt = new SqlDataAdapter(cmd);

            ds = new DataSet();
            adapt.Fill(ds);
            con.Close();
            Pergunta[] perg = new Pergunta[ds.Tables[0].Rows.Count];

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dr      = ds.Tables[0].Rows[i];
                perg[i] = new Pergunta(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString(), dr.ItemArray[2].ToString(), dr.ItemArray[3].ToString(),
                                       dr.ItemArray[4].ToString(), dr.ItemArray[5].ToString().ToCharArray()[0]);
            }


            cmd = new SqlCommand("Select * from aula where titulo = @titulo", con);
            cmd.Parameters.AddWithValue("@titulo", titulo);

            con.Open();
            adapt = new SqlDataAdapter(cmd);

            ds = new DataSet();
            adapt.Fill(ds);
            con.Close();
            Aula ret;

            if (ds.Tables[0].Rows.Count == 1)
            {
                dr  = ds.Tables[0].Rows[0];
                ret = new Aula(dr.ItemArray[0].ToString(), dr.ItemArray[1].ToString(), dr.ItemArray[2].ToString(), pag, perg);
            }
            else
            {
                throw new Exception("Aula inexistente");
            }

            return(ret);
        }