Пример #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (emailInput.Text.Length == 0 || passwordInput.Text.Length == 0)
            {
                MessageBox.Show("Please fill in the email and password !");
                return;
            }
            loading.Visible = true;


            var examSystemAPI = ExamSystemAPI.GetInstance();
            var result        = await examSystemAPI.Login(emailInput.Text, passwordInput.Text);

            if (result["success"] == "true")
            {
                this.Hide();
                var homePage = new HomePage();
                homePage.Closed += (s, args) => this.Close();
                homePage.Show();
            }
            else
            {
                MessageBox.Show("Invalid data !");
            }

            loading.Visible = false;
        }
Пример #2
0
        private async void newQuestionButton_Click(object sender, EventArgs e)
        {
            if (marksInput.Text.Length == 0)
            {
                MessageBox.Show("Please enter the marks for this question");
            }
            if (questionInput.Text.Length == 0)
            {
                MessageBox.Show("Enter the question title !");
                return;
            }
            if (optionsList.Items.Count == 0)
            {
                MessageBox.Show("There needs to be choices !");
                return;
            }

            if (optionsList.SelectedIndex < 0)
            {
                MessageBox.Show("You need to select an answer !");
                return;
            }

            String options = "[";

            foreach (var item in optionsList.Items)
            {
                options += '"' + item.ToString() + '"' + ",";
            }


            options  = options.Remove(options.Length - 1);
            options += "]";

            String type        = truefalseButton.Checked ? "truefalse" : "multichoice";
            var    addQuestion = await ExamSystemAPI.GetInstance().AddQuestion(examId, questionInput.Text, optionsList.SelectedItem.ToString(), options, type, marksInput.Text);

            if (addQuestion)
            {
                MessageBox.Show("Question added successfully");
            }
            else
            {
                MessageBox.Show("Something went wrong when adding the question !");
            }
        }
Пример #3
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (nameInput.Text.Length == 0 || textBox1.Text.Length == 0)
            {
                MessageBox.Show("Can't add questions until you fill in the exam data !");
                return;
            }

            var startTime = startsAtTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            var result    = await ExamSystemAPI.GetInstance().NewExam(nameInput.Text, int.Parse(textBox1.Text), startTime);

            if (result == -1)
            {
                MessageBox.Show("Error adding new exam !");
                return;
            }

            examId = result;

            panel1.Hide();
            panel2.Visible = true;
        }
Пример #4
0
        private async void submitAnswersButton_Click(object sender, EventArgs e)
        {
            int index = 0;

            foreach (var item in answersLists)
            {
                // MessageBox.Show(item.ElementAt(index).Value.SelectedItem.ToString());
                if (item.ElementAt(0).Value.SelectedIndex < 0)
                {
                    MessageBox.Show("You need to select the answer for all the questions !!");
                    return;
                }
                index++;
            }

            String jsonAnswers = "[";

            index = 0;
            foreach (var item in answersLists)
            {
                // MessageBox.Show(item.ElementAt(index).Value.SelectedItem.ToString());
                jsonAnswers += "{\"question_id\": " + item.ElementAt(0).Key + ",";
                jsonAnswers += "\"answer\": \"" + item.ElementAt(0).Value.SelectedItem.ToString() + "\"},";

                index++;
            }

            jsonAnswers  = jsonAnswers.Remove(jsonAnswers.Length - 1);
            jsonAnswers += "]";

            var result = await ExamSystemAPI.GetInstance().SolveExam(HomePage.selectedExamId, jsonAnswers);

            if (result != -1)
            {
                MessageBox.Show("You answers Have been submitted, Your mark is :" + result.ToString());
                this.Hide();
            }
        }
Пример #5
0
        private async void SolveExam_Load(object sender, EventArgs e)
        {
            this.MaximizeBox = false;
            var result = await ExamSystemAPI.GetInstance().GetExam(HomePage.selectedExamId);

            int index = 0;


            foreach (var item in result)
            {
                Panel panel = new Panel();
                panel.Size      = new Size(751, 73);
                panel.Location  = new Point(4, (index * 80) + 90);
                panel.BackColor = Color.FromKnownColor(KnownColor.ButtonHighlight);


                Label questionTitle = new Label();
                questionTitle.Text     = item["question"];
                questionTitle.Location = new Point(8, 7);
                questionTitle.Font     = new Font(new FontFamily("Arial"), 12f, FontStyle.Regular);
                questionTitle.Size     = new Size(600, 21);
                questionTitle.Visible  = true;
                panel.Controls.Add(questionTitle);


                Label marksLabel = new Label();
                marksLabel.Text     = item["marks"] + " Marks";
                marksLabel.Location = new Point(649, 7);
                marksLabel.Font     = new Font(new FontFamily("Arial"), 12f, FontStyle.Regular);
                marksLabel.Size     = new Size(83, 21);
                marksLabel.Visible  = true;
                panel.Controls.Add(marksLabel);


                Label answerLabel = new Label();
                answerLabel.Text     = "Your Answer: ";
                answerLabel.Location = new Point(8, 43);
                answerLabel.Font     = new Font(new FontFamily("Arial"), 9f, FontStyle.Regular);
                answerLabel.Size     = new Size(114, 17);
                answerLabel.Visible  = true;
                panel.Controls.Add(answerLabel);

                ComboBox answersList = new ComboBox();
                answersList.Size     = new Size(254, 23);
                answersList.Location = new Point(147, 40);
                answersList.Font     = new Font(new FontFamily("Arial"), 12f, FontStyle.Regular);
                answersList.Visible  = true;
                panel.Controls.Add(answersList);

                var options = JsonConvert.DeserializeObject <List <string> >(item["options"]);
                foreach (var option in options)
                {
                    answersList.Items.Add(option);
                }

                answersLists.Add(new Dictionary <int, ComboBox> {
                    { int.Parse(item["id"]), answersList }
                });



                panel.Visible = true;

                questionsPanel.Controls.Add(panel);
                panel.Update();
                index++;

                questionsPanel.AutoScroll = false;
                questionsPanel.HorizontalScroll.Enabled = false;
                questionsPanel.HorizontalScroll.Visible = false;
                questionsPanel.HorizontalScroll.Maximum = 0;
                questionsPanel.AutoScroll = true;
            }
        }
Пример #6
0
        private async void HomePage_Load(object sender, EventArgs e)
        {
            this.MaximizeBox = false;
            var examSystemApi = ExamSystemAPI.GetInstance();
            var result        = await examSystemApi.Home();

            if (result == null)
            {
                MessageBox.Show("Something went wrong !!");
                return;
            }

            if (examSystemApi.role == "professor")
            {
                newExamButton.Visible = true;
            }

            welcomeLabel.Text = "Welcome, " + examSystemApi.name;


            int index = 0;

            foreach (var exam in result)
            {
                Panel panel = new Panel();
                panel.Size      = new Size(764, 63);
                panel.Location  = new Point(7, (index * 70) + 90);
                panel.BackColor = Color.FromKnownColor(KnownColor.Gainsboro);


                Label examName = new Label();
                examName.Text     = exam["name"];
                examName.Location = new Point(6, 3);
                examName.Font     = new Font(new FontFamily("Arial"), 20.25f, FontStyle.Regular);
                examName.Size     = new Size(600, 35);
                examName.Visible  = true;
                panel.Controls.Add(examName);


                Label startsAtLabel = new Label();
                startsAtLabel.Text     = "Starts at: " + exam["starts_at"];
                startsAtLabel.Location = new Point(8, 39);
                startsAtLabel.Font     = new Font(new FontFamily("Arial"), 8.25f, FontStyle.Regular);
                startsAtLabel.Visible  = true;
                startsAtLabel.Size     = new Size(600, 15);
                panel.Controls.Add(startsAtLabel);

                if (ExamSystemAPI.GetInstance().role == "student")
                {
                    Button participateButton = new Button();
                    participateButton.Text = "Participate";
                    participateButton.UseVisualStyleBackColor = false;
                    participateButton.FlatStyle = FlatStyle.Flat;
                    participateButton.ForeColor = Color.FromKnownColor(KnownColor.White);
                    participateButton.BackColor = Color.FromKnownColor(KnownColor.RoyalBlue);
                    participateButton.FlatAppearance.BorderSize = 0;
                    participateButton.Size     = new Size(87, 56);
                    participateButton.Location = new Point(672, 4);
                    participateButton.Click   += (object s, EventArgs ee) => { ParticipateInExam(s, ee, exam["id"]); };
                    participateButton.Visible  = true;
                    panel.Controls.Add(participateButton);
                }

                panel.Visible = true;

                panel1.Controls.Add(panel);
                panel.Update();
                index++;
            }

            panel1.AutoScroll = false;
            panel1.HorizontalScroll.Enabled = false;
            panel1.HorizontalScroll.Visible = false;
            panel1.HorizontalScroll.Maximum = 0;
            panel1.AutoScroll = true;
        }