示例#1
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SupportActionBar.Elevation = 0;
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SetContentView(Resource.Layout.exercise_question);
            WebView            = FindViewById <WebView>(Resource.Id.webView1);
            group              = FindViewById <RadioGroup>(Resource.Id.radio_group);
            NextBtn            = FindViewById <ImageButton>(Resource.Id.btn_floating_action);
            pb                 = FindViewById <ProgressBar>(Resource.Id.pb);
            TimerText          = FindViewById <TextView>(Resource.Id.text_timer);
            TextQuestionNumber = FindViewById <TextView>(Resource.Id.question_number);

            tv = FindViewById <TextView>(Resource.Id.tv);
            // TextQuestion = FindViewById<TextView>(Resource.Id.question);
            ExaminationID  = Intent.GetIntExtra(nameof(ExaminationID), 0);
            CurExamination = await Data.Examination.DB.RowsAsync.FirstOrDefaultAsync(c => c.ID == ExaminationID);

            await CurExamination.LoadCourse();

            await CurExamination.LoadModule();

            //await CurExamination.LoadQuestions();
            var guid = Guid.NewGuid();

            UserExamination = new UserExamination {
                CreationDate = DateTime.Now, UserID = SessionManager.User.ID, StartTime = DateTime.Now, CourseID = CurExamination.CourseID.Value, ModuleID = CurExamination.ModuleID.Value
            };
            UserExamination.ID            = guid;
            UserExamination.ExaminationID = CurExamination.ID;
            Questions = Question.DB.Rows.Where(c => c.ExaminationID == ExaminationID).ToList().Shuffled().ToList();// (List<Question>)CurExamination.Questions.Shuffled();
            Count     = Questions.Count;
            pb.Max    = Count;
            // uptask = new UpdatePB(this, pb, tv, Count);
            // uptask.Execute(100);
            if (Questions.Count > 0)
            {
                Question = Questions.FirstOrDefault();
                SessionManager.CanViewResults = false;
            }
            UserExamination.DB.Insert(UserExamination);
            var answers = Answer.DB.Rows.Where(c => c.QuestionID == Question.ID).ToList().Shuffled().ToList();

            StartExercise(Question, answers, group);
            StartTimer = new StartTimer(this, TimerText)
            {
                StartDate = DateTime.Now,
            };
            StartTimer.Start();
            tv.Text = $"Question {Counter} of {Count}";
            TextQuestionNumber.Text = $"Question number {Counter}";
            pb.Progress             = Counter; // SetProgress(Counter, true);
        }
        async void LoadExamination()
        {
            if (CurExamination == null)
            {
                CurExamination = await Examination.DB.RowsAsync.Where(d => d.ID == CurExaminationID).FirstOrDefaultAsync();
            }
            await CurExamination.LoadCourse(); await CurExamination.LoadModule();

            TextTopic.Text      = CurExamination.Topic;
            TextCourseName.Text = $"{CurExamination.Course.Name} {CurExamination.Course.Code}";
            TextDuration.Text   = CurExamination.DurationString;
            TextModuleName.Text = CurExamination.Module.Name;
            TextEndDate.Text    = CurExamination.EndDate.ToString("dd MMM yyy");
            if (string.IsNullOrWhiteSpace(CurExamination.DurationString))
            {
                ViewDuration.Visibility = ViewStates.Gone;
            }
        }