Untitled

 avatar
unknown
csharp
2 years ago
3.1 kB
5
Indexable
using System;
using System.Data.OleDb;
using System.Windows.Forms;

namespace Quiz_game
{
    public partial class MainMenu : Form
    {
        private ContextMenuStrip menu;
        public MainMenu()
        {
            InitializeComponent();
            menu = new ContextMenuStrip();
            ToolStripMenuItem revisionButton = new ToolStripMenuItem("Revise Questions");
            revisionButton.Click += (s, ev) =>
            {
                new Revise_Questions().Show();
                this.Close();
            };
            menu.Items.Add(revisionButton);
            pictureBox1.ContextMenuStrip = menu;
            UpdateNotificationButton();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new Create_Questions().Show();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            new Play_Questions().Show();
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int questionsLeft = ReviseQuizChecker();
            if (questionsLeft == 0)
            {
                MessageBox.Show("No questions left to revise");
            }
            else
            {
                new Revise_Questions().Show();
                this.Close();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            new Login_Form().Show();
            this.Close();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private int ReviseQuizChecker()
        {
            using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=usersdatabase.mdb"))
            {
                connection.Open();
                OleDbCommand command = new OleDbCommand("SELECT COUNT(*) FROM QuestionTable WHERE IsCompleted = ? AND IsCorrect = ?", connection);
                command.Parameters.AddWithValue("@IsCompleted", true);
                command.Parameters.AddWithValue("@IsCorrect", false);
                int questionsLeft = (int)command.ExecuteScalar();
                connection.Close();
                return questionsLeft;
            }
        }
        private void UpdateNotificationButton()
        {
            int questionsLeft = ReviseQuizChecker();

            if (questionsLeft > 0)
            {
                pictureBox1.Image = Properties.Resources.turn_notifications_on_button_1_;
                pictureBox1.Enabled = true;
            }
            else
            {
                pictureBox1.Image = Properties.Resources.notifications_button_1_;
                pictureBox1.Enabled = false;
            }
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                pictureBox1.ContextMenuStrip.Show(pictureBox1, e.Location);
            }
        }
    }
}
Editor is loading...