public QuizTaker(int id, int number) :  this()
        {
            quizdata = new QuizData
            {
                QuizID   = id,
                UserID   = 0,
                QuizTime = 100000
            };

            this.DataContext    = quizdata;
            quizdata.quizEnded += Quizdata_quizEnded;
            octopusEntities1 db = new octopusEntities1();

            questionListBox.ItemsSource = db.fetchRandomQuestionsfromQuiz(id, number);
            answers = new bool[number];
            for (int i = 0; i < answers.Length; i++)
            {
                answers[i] = false;
            }

            // randomly select 10 of these questions

            myQuestion = (Octopus.fetchRandomQuestionsfromQuiz_Result) this.questionListBox.Items[pointer];
            questionHandler();
        }
예제 #2
0
        public void Insert_Quiz_Click(object sender, RoutedEventArgs e)
        {
            octopusEntities1 db = new octopusEntities1();

            // check validity of fields
            if (txtQuizName.Text.Trim() == "")
            {
                txtQuizName.Focus();
                MessageBox.Show("Quiz name is required!", "Validation");
            }

            else if (txtDescription.Text.Trim() == "")
            {
                txtDescription.Focus();
                MessageBox.Show("Description is required!", "Validation");
            }

            else if (txtNumber.Text.Trim() == "")
            {
                txtDescription.Focus();
                MessageBox.Show("Description is required!", "Validation");
            }

            else
            {
                //var newQuiz = new quiz { name = txtQuizName.Text, description = txtDescription.Text, count = int.Parse(txtNumber.Text) };
                try
                {
                    System.Data.Entity.Core.Objects.ObjectParameter param = new System.Data.Entity.Core.Objects.ObjectParameter("Identity", 0);
                    var id = db.insertQuiz(txtQuizName.Text, int.Parse(txtNumber.Text), txtDescription.Text, param);
                }
                catch (Exception er)
                { MessageBox.Show(er.Message, "Error"); }
            }
        }
        public QuizQuestions(int id) : this()
        {
            octopusEntities1 db = new octopusEntities1();

            quizid = id;

            questionListBox.ItemsSource = db.getQuizQuestions(id);
        }
예제 #4
0
        public ActivityDashboard()
        {
            InitializeComponent();
            octopusEntities1 co = new octopusEntities1();

            quizListBox.ItemsSource     = co.selectQuizzes();
            activityListBox.ItemsSource = co.selectActivities();
        }
        public void Submit_Quiz()
        {
            // QuizTaken should have 0. id, 1. userid, 2. quizid, 3. numberofcorrectanswers, 4. totalnumberofquestions, failedquestion ids, failed answers
            MessageBox.Show("Now submitting quiz with a score of " + getNumberCorrect() + "/" + answers.Length + ". A file has been uploaded to your my documents folder with more info ", "Validation");
            octopusEntities1 db = new octopusEntities1();

            writeToFile();
            //db.insertCompletedQuiz(quizdata.UserID, quizdata.QuizID,getNumberCorrect(),answers.Length, "5|10");
        }
        public void Add_File_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();



            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".png";
            dlg.Filter     = "XLSX Files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv";


            // Display OpenFileDialog by calling ShowDialog method
            Nullable <bool> result = dlg.ShowDialog();


            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                filename = dlg.FileName;
                //Supported spreadsheet formats for reading include: XLSX, XLS, CSV and TSV
                WorkBook  workbook = WorkBook.Load(filename);
                WorkSheet sheet    = workbook.DefaultWorkSheet;
                //Select cells easily in Excel notation and return the calculated value, date, text or formula
                int cellValue = sheet["A2"].IntValue;
                // Read from Ranges of cells elegantly.
                bool             stop = false;
                int              row  = 0;
                octopusEntities1 db   = new octopusEntities1();
                RangeRow         rowdata;
                while (!stop)
                {
                    // check if existing prior to inserting
                    ObjectResult <Octopus.checkForExistingQuestion_Result> number = db.checkForExistingQuestion(quizid, (string)sheet.GetCellAt(0, row).Text.Trim());
                    if (number.ToArray().Length == 0)
                    {
                        db.insertQuestionToQuiz(quizid, (string)sheet.GetCellAt(0, row).Text.Trim(), (string)sheet.GetCellAt(1, row).Text.Trim(), (string)sheet.GetCellAt(2, row).Text.Trim(), "basic");
                    }
                    else
                    {
                        Console.WriteLine("Question already existing");
                    }



                    row++;
                }
            }
        }
        public void Add_Question_Click(object sender, RoutedEventArgs e)
        {
            bool             pass = true;
            octopusEntities1 db   = new octopusEntities1();

            if (newQuestion.Text.Trim() == "" || newAnswer.Text.Trim() == "" || newOptions.Text.Trim() == "")
            {
                pass = false;
            }

            if (pass)
            {
                db.insertQuestionToQuiz(quizid, newQuestion.Text, newAnswer.Text, newOptions.Text, "basic");
                newQuestion.Text = "";
                newAnswer.Text   = "";
                newOptions.Text  = "";
                MessageBox.Show("Question inserted!", "Validation");
            }
            else
            {
                MessageBox.Show("Missing entry", "Validation");
            }
            // insert question
        }