private void Start(object sender, RoutedEventArgs e)
        {
            this._selectedItem = (TestItem)this.TestList.SelectedItem;
            ToeicTest _test =
                ToeicTestManager.GetTestManager().GetTest(this._selectedItem.ID);

            this.Visibility = Visibility.Hidden;
            ExamView exView = new ExamView(_test);

            if (exView.ShowDialog() == true)
            {
                IDataAccess dbAccess = LocalDataAccess.GetDBAccess();
                Dictionary <int, List <string> > testCorrectAnswer =
                    dbAccess.GetTestCorrectAnswer(int.Parse(this._selectedItem.ID));

                Dictionary <int, string> listeningAnswer = exView.GetListenningAnswers();
                Dictionary <int, string> readingAnswer   = exView.GetReadingAnswers();

                Dictionary <int, int> listeningScoreChecklist = dbAccess.GetListeningScoreCheckList();
                Dictionary <int, int> readingScoreChecklist   = dbAccess.GetReadingScoreCheckList();

                ResultView resultView = new ResultView();
                resultView.SetDataAndCalculate(
                    int.Parse(this._selectedItem.ID),
                    testCorrectAnswer,
                    listeningAnswer,
                    readingAnswer,
                    listeningScoreChecklist,
                    readingScoreChecklist);

                resultView.ShowDialog();
            }

            this.Visibility = Visibility.Visible;
        }
Example #2
0
        private void AddTest(string name, string listenning, string reading, string audio, string answer)
        {
            string            testPath;
            SQLiteTransaction transaction;
            IDataAccess       dataAccess = LocalDataAccess.GetDBAccess();

            transaction = dataAccess.GetCurrentConnection().BeginTransaction();

            testPath = Path.Combine(
                ConfigurationManager.AppSettings[Common.TEST_PATH],
                DateTime.Now.ToString("yyyyMMddHHmmss"));

            try
            {
                //Get Answer
                string[] lines             = File.ReadAllLines(answer);
                string   listenning_answer = lines.Where(x => x.Contains(Common.LISTEN) && x.Contains("=")).FirstOrDefault();
                string   reading_answer    = lines.Where(x => x.Contains(Common.READ) && x.Contains("=")).FirstOrDefault();

                if (listenning_answer == null)
                {
                    MessageBox.Show(
                        "Listenning data is incorrect",
                        "Incorrect data",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning);
                    return;
                }

                if (reading_answer == null)
                {
                    MessageBox.Show(
                        "Reading data is incorrect",
                        "Incorrect data",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning);
                    return;
                }

                listenning_answer = listenning_answer.Split(new char[] { '=' })[1];
                reading_answer    = reading_answer.Split(new char[] { '=' })[1];

                if (listenning_answer.Split(new char[] { ',' }).Length != 100)
                {
                    MessageBox.Show(
                        "Number of answer of listenning test is not equal to 100",
                        "Incorrect data",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning);
                    return;
                }

                if (reading_answer.Split(new char[] { ',' }).Length != 100)
                {
                    MessageBox.Show(
                        "Number of answer of reading test is not equal to 100",
                        "Incorrect data",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning);
                    return;
                }

                //Insert into DB
                dataAccess.InsertTestCorrectAnswer(name, listenning_answer, reading_answer, testPath, transaction);

                this.InsertProgressBar.Value = 25;

                string testFullPath = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    testPath);

                Directory.CreateDirectory(testFullPath);

                //Copy LC file

                string LC_path = Path.Combine(testFullPath, Common.LISTEN + @"\");

                Directory.CreateDirectory(LC_path);

                File.Copy(listenning, Path.Combine(LC_path, Common.LISTEN + ".pdf"));

                this.InsertProgressBar.Value = 50;

                //Copy RC file

                string RC_path = Path.Combine(testFullPath, Common.READ + @"\");

                Directory.CreateDirectory(RC_path);

                File.Copy(reading, Path.Combine(RC_path, Common.READ + ".pdf"));

                this.InsertProgressBar.Value = 75;
                //Copy Audio file

                string AU_path = Path.Combine(testFullPath, Common.AUDIO + @"\");

                Directory.CreateDirectory(AU_path);

                File.Copy(audio, Path.Combine(AU_path, Common.AUDIO + ".mp3"));

                this.InsertProgressBar.Value = 100;

                transaction.Commit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                this.InsertProgressBar.Value = 0;

                transaction.Rollback();

                if (Directory.Exists(testPath))
                {
                    Directory.Delete(testPath, true);
                }
            }
        }
        private void LoadTests()
        {
            Dictionary <int, List <string> > tests = LocalDataAccess.GetDBAccess().GetAllTest();

            for (int i = 1; i <= tests.Count; i++)
            {
                List <string> infor = tests[i];

                string testSourcePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, infor[1]);

                DirectoryInfo dirInfo = new DirectoryInfo(testSourcePath);

                DirectoryInfo[] parts = dirInfo.GetDirectories();

                ToeicTest test = new ToeicTest();
                this._tests.Add(i.ToString(), test);
                test.Name = infor[0];

                foreach (DirectoryInfo part in parts)
                {
                    if (string.Equals(part.Name, Common.AUDIO))
                    {
                        FileInfo[] audio = part.GetFiles();
                        if (audio.Length > 0)
                        {
                            test.Audio = audio[0].FullName;
                        }
                        else
                        {
                            this._tests.Remove(i.ToString());
                            break;
                        }
                    }
                    else if (string.Equals(part.Name, Common.LISTEN))
                    {
                        FileInfo[] listening = part.GetFiles();
                        if (listening.Length > 0)
                        {
                            test.Listening = listening[0].FullName;
                        }
                        else
                        {
                            this._tests.Remove(i.ToString());
                            break;
                        }
                    }
                    else if (string.Equals(part.Name, Common.READ))
                    {
                        FileInfo[] reading = part.GetFiles();
                        if (reading.Length > 0)
                        {
                            test.Reading = reading[0].FullName;
                        }
                        else
                        {
                            this._tests.Remove(i.ToString());
                            break;
                        }
                    }
                }
            }
        }