示例#1
0
        private void btnSubmit_Click(object sender, EventArgs e)                                                                         //Event handler for when the submit button is clicked
        {
            if (!((txtQuiz.Text == "") || (txtBtn1.Text == "") || (txtBtn2.Text == "") || (txtBtn3.Text == "") || (txtBtn4.Text == ""))) //Ensures that all text input is filled in where required of the data handling
            {
                listData.Insert(listData.Count - 1, new string[] { "", "", "", "", "", "", "" });                                        //Insert a new empty string array to the list
                if (radBtnBoolean.Checked == true)                                                                                       //Assign data for question type
                {
                    listData[listData.Count - 2][0] = "Boolean";
                }
                else
                {
                    listData[listData.Count - 2][0] = "MultChoi";
                }
                listData[listData.Count - 2][1] = txtQuiz.Text; //Assign text box data to the string array
                listData[listData.Count - 2][2] = txtBtn1.Text;
                listData[listData.Count - 2][3] = txtBtn2.Text;
                listData[listData.Count - 2][4] = txtBtn3.Text;
                listData[listData.Count - 2][5] = txtBtn4.Text;
                if (radBtn1.Checked == true) //Assign the correct answer data to the string array
                {
                    listData[listData.Count - 2][6] = txtBtn1.Text;
                }
                else if (radBtn2.Checked == true)
                {
                    listData[listData.Count - 2][6] = txtBtn2.Text;
                }
                else if (radBtn3.Checked == true)

                {
                    listData[listData.Count - 2][6] = txtBtn3.Text;
                }
                else
                {
                    listData[listData.Count - 2][6] = txtBtn4.Text;
                }
                using (SubmitConfirmForm submit = new SubmitConfirmForm()) //Submition form scope
                {
                    if (submit.ShowDialog() == DialogResult.OK)            //If the confirmation of submission is achieved
                    {
                        for (int i = 1; i < 7; i++)                        //Insert null data into the appropriate places across the created list of string arrays where data must exist to properly enable the CSVs to be read later
                        {
                            listData[0][i] = "null";
                        }
                        for (int i = 3; i < 7; i++)
                        {
                            listData[listData.Count - 1][i] = "null";
                        }
                        Global.ArrayToCSV(listData);                              //Create a temporary csv with the list of string array data
                        string    csvPath   = Path.GetTempPath() + "tempcsv.csv"; //Get that path to the temp folder
                        FtpClient clientFTP = new FtpClient();
                        clientFTP.Host = "ftp://82.10.84.171";
                        clientFTP.Port = 54443;
                        clientFTP.Credentials.UserName         = "******";
                        clientFTP.Credentials.Password         = "******";
                        clientFTP.DataConnectionReadTimeout    = 2147483645;
                        clientFTP.ConnectTimeout               = 2147483645;
                        clientFTP.DataConnectionConnectTimeout = 2147483645;
                        clientFTP.ReadTimeout = 2147483645;
                        clientFTP.UploadFile(csvPath, $@"\Quizzes\{listData[0][0]}.csv"); //Upload that csv under the Quizzes name found inside the list of string array data
                        File.Delete(csvPath);                                             //Delete that temporary CSV
                        clientFTP.Disconnect();
                        MessageBox.Show("Success, Quiz Uploaded!");                       //Inform user uploading of the quiz was successful
                        this.Close();
                    }
                    else //Otherwise undo everything occured so far by sinmply removing the inserted array
                    {
                        listData.RemoveAt(listData.Count - 2);
                    }
                }
            }
            else //Informs user to fulfil data input
            {
                MessageBox.Show("Please complete all fields!");
            }
        }
示例#2
0
        private void BtnNext_Click(object sender, EventArgs e) //Event handler for when the next button is clicked
        {
            switch (formType)                                  //Switch case statement for the initialised quiz type
            {
            case 0:                                            //If it is a Student quiz type
                btnBack.Text = "Back";
                if (currentQuestion == listData.Count - 2)     //If the current question is the last, then it submits the score
                {
                    if (selectedAnswer == listData[currentQuestion][6])
                    {
                        score++;
                    }
                    using (SubmitConfirmForm submit = new SubmitConfirmForm())
                    {
                        if (submit.ShowDialog() == DialogResult.OK)
                        {
                            string    teacherAccount = listData[listData.Count - 1][3];  //Gets required data from the list of string arrays
                            string    className      = listData[listData.Count - 1][4];
                            string    csvPath        = Path.GetTempPath() + "tempcsv.csv";
                            FtpClient clientFTP      = new FtpClient();
                            clientFTP.Host = "ftp://82.10.84.171";
                            clientFTP.Port = 54443;
                            clientFTP.Credentials.UserName         = "******";
                            clientFTP.Credentials.Password         = "******";
                            clientFTP.DataConnectionReadTimeout    = 2147483645;
                            clientFTP.ConnectTimeout               = 2147483645;
                            clientFTP.DataConnectionConnectTimeout = 2147483645;
                            clientFTP.ReadTimeout = 2147483645;
                            clientFTP.DownloadFile(csvPath, $@"/Classes/{teacherAccount}/{className}/{Global.currentUser}.csv");     //obtains the current state of the students particular csv
                            using (StreamWriter csvData = File.AppendText(csvPath))
                            {
                                csvData.WriteLine($"\n{listData[0][0]},{score}");                                              //Writes the quiz title and resultant score
                            }
                            clientFTP.DeleteFile($@"/Students/{Global.currentUser}/{listData[0][0]}.csv");                     //Delete appropriate files
                            clientFTP.DeleteFile($@"/Classes/{teacherAccount}/{className}/{Global.currentUser}.csv");
                            clientFTP.UploadFile(csvPath, $@"/Classes/{teacherAccount}/{className}/{Global.currentUser}.csv"); //Upload edited file
                            File.Delete(csvPath);
                            MessageBox.Show("Successfully Submitted");                                                         //Inform user the score was successfully submitted
                            StudentFormIndex studentFormIndex = new StudentFormIndex();                                        //Go back to student index form and close this form
                            studentFormIndex.Show();
                            this.Close();
                        }
                    }
                }
                else if (currentQuestion == listData.Count - 3) //If the current question is the second to last
                {
                    btn1.Enabled = true;                        //Perform the usual
                    btn2.Enabled = true;
                    btn3.Enabled = true;
                    btn4.Enabled = true;
                    if (selectedAnswer == listData[currentQuestion][6])
                    {
                        score++;
                    }
                    btnNext.Text = "Submit";     //Simply rename the next button text Submit
                    currentQuestion++;
                    UpdateStudent();
                }
                else
                {
                    btn1.Enabled = true;     //Re-enable all buttons
                    btn2.Enabled = true;
                    btn3.Enabled = true;
                    btn4.Enabled = true;
                    if (selectedAnswer == listData[currentQuestion][6])     //Check if the answer was correct, if so then increment the score counter
                    {
                        score++;
                    }
                    currentQuestion++;     //increment current question pointer
                    UpdateStudent();
                }
                break;

            case 1:     //If it is a View quiz type
                currentQuestion++;
                btnBack.Text = "Back";
                if (currentQuestion == listData.Count - 1) //If current question is on the last question
                {
                    currentQuestion = 1;                   //Loop back to the first
                    btnBack.Text    = "Close";
                }
                UpdateView();
                break;

            case 2:     //If it is a Creation quiz type
                btnBack.Text = "Back";
                if (currentQuestion == 19)
                {
                    btnNext.Hide();     //When on last question, hide the next button so only back and submit are options for the user
                    CreateNext();
                    currentQuestion++;
                    DrawNextCreate();
                }
                else if (currentQuestion == 2)
                {
                    btnSubmit.Show();     //When past the 2nd question, enable user to submit whenever they want
                    CreateNext();
                    currentQuestion++;
                    DrawNextCreate();
                }
                else
                {
                    CreateNext();      //Applie creating next logic
                    currentQuestion++; //Increment current question pointer
                    DrawNextCreate();  //Draw a fresh question on form
                }
                break;
            }
        }