Exemple #1
0
        private void newform()                                                                                              // Redirect to main form
        {
            ChoseTopic mainform = new ChoseTopic();

            this.Hide();
            mainform.Show();
        }
        private void btnctpc_Click(object sender, EventArgs e)
        {
            WhoWantsToBeAMillionaire_form2.points = 0;
            ChoseTopic mainform = new ChoseTopic();

            this.Hide();
            mainform.Show();
        }
        //////////////////////////////////////////////////////////////////

        private void database_function()                                                    //Vse funkcije v podatkovnih bazah za igro so tukej
        {
            int i = 1;

            if (chosenone == 3)
            {
                SQL_command_topic_based =
                    "SELECT " +
                    "   questions.content, " +
                    "   topics.name, questions.id " +
                    "FROM " +
                    "   questions, " +
                    "   topics " +
                    "WHERE (" +
                    "   (questions.topic = 1) " +
                    "   OR " +
                    "       (questions.topic = 2) " +
                    "   OR " +
                    "       (questions.topic = 3))" +
                    "   AND (topics.id = questions.topic) " +
                    "ORDER BY " +
                    "   (questions.id) " +
                    "LIMIT " +
                    "   " + index + "," +
                    "    1;";
            }
            else if (chosenone == 7)
            {
                SQL_command_topic_based = "" +
                                          "SELECT " +
                                          "   questions.content, " +
                                          "   topics.name, " +
                                          "   questions.id   " +
                                          "FROM " +
                                          "   questions, " +
                                          "   topics " +
                                          "WHERE (" +
                                          "   (questions.topic = 1) " +
                                          "   OR " +
                                          "       (questions.topic = 2) " +
                                          "   OR " +
                                          "       (questions.topic = 3) " +
                                          "   OR " +
                                          "       (questions.topic = 4) " +
                                          "   OR " +
                                          "       (questions.topic = 5) " +
                                          "   OR  " +
                                          "       (questions.topic = 6) " +
                                          "   OR " +
                                          "       (questions.topic = 7) " +
                                          "   OR  " +
                                          "       (questions.topic = 8)) " +
                                          "   AND " +
                                          "       (topics.id = questions.topic) " +
                                          "ORDER BY " +
                                          "   (questions.id) " +
                                          "LIMIT " +
                                          "   " + index + ", " +
                                          "1;";
            }
            else if (chosenone == 8 || chosenone == 9 || chosenone == 10 || chosenone == 17 || chosenone == 18 || chosenone == 19)
            {
                MessageBox.Show("This action was not acaunted for. Perhaps try again with choosing your topic ? DO NOT CHOSE FUKIN PLACEHOLDER. It Does Not Work.");
                ChoseTopic mainform = new ChoseTopic();
                this.Hide();
                mainform.Show();
            }
            else if (chosenone == 20)
            {
                SQL_command_topic_based =
                    "SELECT " +
                    "   questions.content, " +
                    "   topics.name, " +
                    "   questions.id " +
                    "FROM " +
                    "   questions, " +
                    "   topics " +
                    "WHERE (" +
                    "   topics.id = questions.topic) " +
                    "ORDER BY " +
                    "   (questions.id) " +
                    "LIMIT " +
                    "   " + index + "," +
                    " 1;";
            }
            else
            {
                SQL_command_topic_based =
                    "SELECT " +
                    "   questions.content, " +
                    "   topics.name, questions.id " +
                    "FROM " +
                    "   questions, " +
                    "   topics " +
                    "WHERE " +
                    "   (questions.topic = " + chosenone + " ) " +
                    "AND" +
                    "   (topics.id = questions.topic) " +
                    "ORDER BY " +
                    "   (questions.id) " +
                    "LIMIT " +
                    "   " + index + ", " +
                    "1 ; ";
            }

            connection.Open();
            using (SQLiteCommand command = new SQLiteCommand(connection))
            {
                command.CommandText = SQL_command_topic_based;
                SQLiteDataReader reader = command.ExecuteReader();
                reader.Read();
                btnq.Text = reader.GetString(0);
                qid       = reader.GetInt32(2);
                reader.Close();
                command.Dispose();
            }

            using (SQLiteCommand command = new SQLiteCommand(connection))
            {
                command.CommandText =
                    "SELECT " +
                    "   content, " +
                    "   true " +
                    "FROM " +
                    "   answers " +
                    "WHERE " +
                    "   (q_id = " + qid + ") " +
                    "ORDER BY " +
                    "   RANDOM() " +
                    "LIMIT 4;";
                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    answertrue = reader.GetInt32(1);
                    if (answertrue == 1)
                    {
                        answerDB = i;
                    }
                    switch (i)
                    {
                    case 1: btnansa.Text = reader.GetString(0);
                        break;

                    case 2: btnansb.Text = reader.GetString(0);
                        break;

                    case 3: btnansc.Text = reader.GetString(0);
                        break;

                    case 4: btnansd.Text = reader.GetString(0);
                        break;
                    }
                    i++;
                }
                reader.Close();
                command.Dispose();
            }
            connection.Close();
        }