Ejemplo n.º 1
0
        private void SingleReport_Click(object sender, RoutedEventArgs e)
        {
            Button        btn     = sender as Button;
            ListeningTest test    = btn.DataContext as ListeningTest;
            MainWindow    mainwin = (MainWindow)Application.Current.MainWindow;

            bool isSuccess = false; Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("uid", mainwin.User.id.ToString());
            parameters.Add("tid", test.id);
            string rtext = HttpRequestHelper.HttpGet(Setting.BASE_URL + "test/getAnswerStatus", parameters, ref isSuccess);

            if (!isSuccess)
            {
                MessageBox.Show("网络错误,请重试!", "抱歉");
            }
            else
            {
                //if(rtext=="" || rtext== null)
                //{
                //    TestQuestionaire testQuestionaire = new TestQuestionaire(test.id);
                //    testQuestionaire.ShowDialog();
                //}
                ReportQRCode page = new ReportQRCode(test.id, 0, test.testno);
                mainwin.frmMain.Content = page;
            }
        }
Ejemplo n.º 2
0
        private void LoadTest(object sender, RoutedEventArgs e)
        {
            if (isLoaded)
            {
                return;
            }
            isLoaded = true;

            //加载测试
            loadFinished(false);
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("id", JsonConvert.SerializeObject(-1));
            Boolean isSuccess = false;
            string  rtext     = HttpRequestHelper.HttpGet(Setting.BASE_URL + "test/loadTest", parameters, ref isSuccess);

            if (isSuccess)
            {
                ListeningTest test = JsonConvert.DeserializeObject <ListeningTest>(rtext);
                TestName.Text += test.title;
                MainWindow mainwin = (MainWindow)Application.Current.MainWindow;
                mainwin.ListeningTest = test;

                if (IsFinished(test))
                {
                    MessageBox.Show("您已完成所有测试!");
                    mainwin.FrameNavigator("funclist");
                    return;
                }

                //开启一个线程加载音频
                Task task = new Task(() => LoadAudios(test));
                task.Start();

                if (test.testno == 1 && (mainwin.User.questionaireBF == "" || mainwin.User.questionaireBF == null))
                {
                    TestQuestionaire testQuestionaire = new TestQuestionaire(test.testno);
                    testQuestionaire.Owner = mainwin;
                    testQuestionaire.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("网络错误请重试!");
                return;
            }
        }
Ejemplo n.º 3
0
        //加载所有音频
        private void LoadAudios(ListeningTest test)
        {
            Dispatcher.BeginInvoke(new Action(() => LoadingAudiosText.Text = "正在加载音频,请稍后...(0/16)"));
            if (Directory.Exists("TEMP/") == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory("TEMP/");
            }
            else
            {
                ClearAudios();
            }
            int loadnum = 0;

            foreach (Part part in test.parts)
            {
                foreach (PartExer partExer in part.partExers)
                {
                    Exercise exercise = partExer.exercise;
                    foreach (Question question in exercise.questions)
                    {
                        bool check = false;
                        while (!check)
                        {
                            try
                            {
                                check = LoadAuido(question.audio);
                            }
                            catch (Exception)
                            {
                                check = false;
                            }
                        }
                        loadnum++;
                        Dispatcher.BeginInvoke(new Action(() => LoadingAudiosText.Text = string.Format("正在加载音频,请稍后...({0}/16)", loadnum)));
                    }
                }
            }
            Dispatcher.BeginInvoke(new Action(() => loadFinished(true)));
        }
Ejemplo n.º 4
0
        //是否已经做过该测试
        private bool IsFinished(ListeningTest test)
        {
            MainWindow mainwin = (MainWindow)Application.Current.MainWindow;
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("type", JsonConvert.SerializeObject(0));
            parameters.Add("tid", test.id);
            parameters.Add("uid", mainwin.User.id.ToString());
            Boolean isSuccess = false;

            while (!isSuccess)
            {
                string rtext = HttpRequestHelper.HttpGet(Setting.BASE_URL + "test/getStatus", parameters, ref isSuccess);
                if (rtext == "1")
                {
                    return(true);
                }
                else if ((rtext == "0"))
                {
                    return(false);
                }
            }
            return(false);
        }