Beispiel #1
0
 private void dodajUSession(Anketa_vipdata.Anketa a)
 {
     Session["aID"]       = a.anketaID;
     Session["naslov"]    = a.naslovAnkete;
     Session["aktivnaOd"] = a.aktivnaOd;
     Session["aktivnaDo"] = a.aktivnaDo;
 }
Beispiel #2
0
    private void anketaClick(object sender, EventArgs e)
    {
        listaAnketa.Visible = false;
        Button btn = (Button)sender;
        int    recordNum;
        string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Korisnik\source\repos\Anketa-vipdata\Anketa-vipdata\App_Data\AnketaDB.mdf;Integrated Security=True;MultipleActiveResultSets=true;";
        string query            = "SELECT count(odgovorID) as brojOdgovora FROM Odgovori WHERE anketaID = " + int.Parse(btn.ID.Substring(btn.ID.IndexOf('_') + 1));

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            reader.Read();
            recordNum = reader.GetInt32(0);
            reader.Close();
        }

        Anketa_vipdata.Anketa anketa;

        if (recordNum > 0)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                query = "SELECT naslovAnkete,anketaID,aktivnaDo,aktivnaOD FROM Anketa WHERE anketaID = " + int.Parse(btn.ID.Substring(btn.ID.IndexOf('_') + 1));
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                reader.Read();
                anketa = new Anketa_vipdata.Anketa(reader.GetString(0), reader.GetInt32(1), reader.GetDateTime(2), reader.GetDateTime(3));

                query   = "SELECT tekstOdgovora,brojGlasova FROM Odgovori WHERE anketaID = " + anketa.anketaID;
                command = new SqlCommand(query, connection);
                reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    anketa.listaOdgovora.Add(new KeyValuePair <string, int>(reader.GetString(0), reader.GetInt32(1)));
                }

                reader.Close();
            }
            Label naslovAnkete = new Label();
            naslovAnkete.Text      = "Anketa: " + anketa.naslovAnkete;
            naslovAnkete.Font.Size = 15;
            Label aktivnost = new Label();
            aktivnost.Text = "Aktivna: " + anketa.aktivnaOd.ToLongDateString() + " - " + anketa.aktivnaDo.ToLongDateString();

            naslovAnkete.ForeColor = Color.White;
            aktivnost.ForeColor    = Color.White;

            pregledPojedinacneAnkete.Controls.Add(naslovAnkete);
            pregledPojedinacneAnkete.Controls.Add(new LiteralControl("<br /> <br />"));
            pregledPojedinacneAnkete.Controls.Add(aktivnost);
            pregledPojedinacneAnkete.Controls.Add(new LiteralControl("<br /> <br />"));

            Label ankete = new Label();
            ankete.Text      = "Ponuđeni odgovori:";
            ankete.ForeColor = Color.White;
            pregledPojedinacneAnkete.Controls.Add(ankete);

            Button naPopis = new Button();
            naPopis.Text = "Natrag na popis anketa";
            naPopis.ID   = "btn_napopis";

            BulletedList bList = new BulletedList();
            foreach (var i in anketa.listaOdgovora)
            {
                bList.Items.Add(new ListItem(i.Key + " --- " + "glasovi: " + i.Value));
            }
            pregledPojedinacneAnkete.Controls.Add(bList);
            bList.ForeColor = Color.White;
            Label inform = new Label();
            inform.ForeColor = Color.Red;
            inform.Text      = "Ovu anketu nije moguće modificirati jer postoje odgovori na nju !";
            pregledPojedinacneAnkete.Controls.Add(new LiteralControl("<br />"));
            pregledPojedinacneAnkete.Controls.Add(inform);
            pregledPojedinacneAnkete.Controls.Add(new LiteralControl("<br /> <br />"));
            pregledPojedinacneAnkete.Controls.Add(naPopis);
            pregledPojedinacneAnkete.Visible = true;
        }
        else
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                query = "SELECT naslovAnkete,anketaID,aktivnaDo,aktivnaOD FROM Anketa WHERE anketaID = " + int.Parse(btn.ID.Substring(btn.ID.IndexOf('_') + 1));
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                reader.Read();
                anketa = new Anketa_vipdata.Anketa(reader.GetString(0), reader.GetInt32(1), reader.GetDateTime(2), reader.GetDateTime(3));
            }
            dodajUSession(anketa);
            PrikazEditabilneAnkete();
        }
    }