private double SumLessonPeriod(List <Lesson> list) { var res = 0.00; foreach (var item in list) { res += LessonHelper.GetTimeOfLesson(item.LessonPeriod); } return(res); }
async void sessionLoad_Start_lazy() // timing will start on the first keystroke. { LessonText = LessonHelper.GetLesson(LesnTyp, SubLesnId); LessonLen = LesnTyp == LessonType.PhrasesRandm ? LessonText.Length - LessonHelper.PaddingLen : LessonText.Length; PupilInput = ""; _swMain.Reset(); /*updateUserLessonLst(false)*/ ; PrgsChart.Clear(); IsInSsn = IsCorrect = true; IsFocusedSB = false; await Task.Delay(9); refreshUiSynch(); await refreshUi(); IsFocusedPI = false; await Task.Delay(9); refreshUiSynch(); await refreshUi(); IsFocusedPI = true; await Task.Delay(99); refreshUiSynch(); await refreshUi(); //this acrobatics seems to bring focus to the textbox. }
async void prepLessonType(string x, bool doF1 = true) { SubLesnId = x.Split('-').Last(); switch (x[0]) { case 'B': LesnTyp = LessonType.BasicLessons; break; case 'C': LesnTyp = LessonType.Combinations; break; case 'D': LesnTyp = LessonType.DigitSymbols; break; case 'F': LesnTyp = LessonType.EditableFile; break; case 'S': LesnTyp = LessonType.SpecialDrill; break; case 'P': LesnTyp = LessonType.PhrasesRandm; break; case 'X': LesnTyp = LessonType.Experimental; break; default: break; } LessonText = LessonHelper.GetLesson(LesnTyp, SubLesnId); LessonLen = LesnTyp == LessonType.PhrasesRandm ? LessonText.Length - LessonHelper.PaddingLen : LessonText.Length; if (doF1) { using (var db = A0DbMdl.GetA0DbMdlAzureDb) { loadListsFromDB(DashName, SelectUser, db); await updateDoneTodo(SelectUser, synth, db); } } CurInfo = $"{(LesnTyp)} - {SubLesnId:N0} ";// ({DashName})"; }
void onShowChart(object mode) { string f; switch ((string)mode) { case "Full": f = "y-M-d"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.OrderByDescending(r => r.DoneAt)); break; case "Year": f = "MMM d"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.Where(r => r.DoneAt > DateTime.Now.AddYears(-1)).OrderByDescending(r => r.DoneAt)); break; case "3Mon": f = "ddd d"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.Where(r => r.DoneAt > DateTime.Now.AddMonths(-3)).OrderByDescending(r => r.DoneAt)); break; case "Mont": f = "ddd d"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.Where(r => r.DoneAt > DateTime.Now.AddMonths(-1)).OrderByDescending(r => r.DoneAt)); break; case "Week": f = "ddd H:mm"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.Where(r => r.DoneAt > DateTime.Now.AddDays(-7)).OrderByDescending(r => r.DoneAt)); break; case "PreX": f = "ddd H:mm"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.OrderByDescending(r => r.DoneAt).Take(10)); break; case "Pre5": f = "H:mm"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.OrderByDescending(r => r.DoneAt).Take(05)); break; case "24hr": f = "H:mm"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.Where(r => r.DoneAt > DateTime.Now.AddDays(-1)).OrderByDescending(r => r.DoneAt)); break; case "1Day": f = "H:mm"; /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.Where(r => r.DoneAt > DateTime.Today).OrderByDescending(r => r.DoneAt)); break; case null: default: f = "MMM-dd"; break; } _chartUC.AxisX.First().LabelFormatter = value => DateTime.FromOADate(value).ToString(f); } void onDeleteSR(object x) { if (SelectSnRt == null) { return; } synth.SpeakAsyncCancelAll(); synth.SpeakFaF($"Are you sure?"); if (MessageBox.Show($"{SelectSnRt.DoneAt:MMM-dd HH:mm} \r\n\n{SelectSnRt.CpM} cpm\r\n\n{(SelectSnRt.IsRecord == true ? "It's a Record!!" : "")}", "Are you sure?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { DeleteSaveSsnRsltToDb(SelectSnRt, A0DbMdl.GetA0DbMdlAzureDb); } } void promptSample() { /* * var ps = new PromptStyle * { * Emphasis = PromptEmphasis.Strong, * Volume = PromptVolume.ExtraLoud * }; * * var pb = new PromptBuilder(); * pb.StartStyle(ps); * pb.StartParagraph(); * * pb.StartVoice(VoiceGender.Female, VoiceAge.Child); * pb.StartSentence(); * pb.AppendText($"Female Child", PromptRate.Medium); * pb.AppendBreak(TimeSpan.FromSeconds(.3)); * pb.EndSentence(); * pb.EndVoice(); * * pb.StartVoice(VoiceGender.Female, VoiceAge.Senior); * pb.StartSentence(); * pb.AppendText($"Female Senior", PromptRate.Medium); * pb.AppendBreak(TimeSpan.FromSeconds(.3)); * pb.EndSentence(); * pb.EndVoice(); * * pb.StartVoice(VoiceGender.Male, VoiceAge.Senior); * pb.StartSentence(); * pb.AppendText($"Male Senior", PromptRate.Medium); * pb.AppendBreak(TimeSpan.FromSeconds(.3)); * pb.EndSentence(); * pb.EndVoice(); * * pb.StartVoice(VoiceGender.Male, VoiceAge.Child); * pb.StartSentence(); * pb.AppendText($"Male Child", PromptRate.Medium); * pb.AppendBreak(TimeSpan.FromSeconds(.3)); * pb.EndSentence(); * pb.EndVoice(); * * pb.EndParagraph(); * pb.EndStyle(); * synth.SpeakAsyncCancelAll(); synth.SpeakFaF(pb); */ } async void prepLessonType(string x, bool doF1 = true) { SubLesnId = x.Split('-').Last(); switch (x[0]) { case 'A': case 'D': LesnTyp = LessonType.DrillsInFile; break; case 'B': LesnTyp = LessonType.BasicLessons; break; case 'C': LesnTyp = LessonType.Combinations; break; case 'N': LesnTyp = LessonType.NumerSymbols; break; case 'F': LesnTyp = LessonType.EditableFile; break; case 'S': LesnTyp = LessonType.SpecialDrill; break; case 'P': LesnTyp = LessonType.PhrasesRandm; break; case 'X': LesnTyp = LessonType.Experimental; break; default: break; } var(lessonTxt, lessonLen) = LessonHelper.GetLesson(LesnTyp, SubLesnId); LessonText = lessonTxt; LessonLen = lessonLen; if (doF1) { using (var db = A0DbMdl.GetA0DbMdlAzureDb) { loadListsFromDB(DashName, SelectUser, db); await updateDoneTodo(SelectUser, synth, db); } } CurInfo = $"{(LesnTyp)} - {SubLesnId:N0} ";// ({DashName})"; } async Task updateDoneTodo(string selectUser, SpeechSynthesizer synth, A0DbMdl db) { int doneToday = -1, sinceRcrd = -1, todoToday = -1; try { doneToday = db.SessionResults.Count(r => r.UserId.Equals(selectUser, StringComparison.OrdinalIgnoreCase) && r.DoneAt > DateTime.Today); //if (!db.SessionResults.Any(r => r.UserId.Equals(selectUser, StringComparison.OrdinalIgnoreCase))) //{ // sinceRcrd = 0; // todoToday = _planPerDay - doneToday; //} //else { var latestGlobalRecordDate = await getLatestGlobalRecordDate(selectUser, db); sinceRcrd = db.SessionResults.Count(r => r.UserId == selectUser && r.DoneAt > latestGlobalRecordDate); todoToday = ((DateTime.Today < latestGlobalRecordDate)) ? 0 : // if done a record today ==> 0 left ((DateTime.Today - latestGlobalRecordDate).Days + 1) * _planPerDay - sinceRcrd; } if (todoToday < 0) { todoToday = _planPerDay - doneToday; } } catch (Exception ex) { ex.Log(); synth.SpeakAsyncCancelAll(); synth.SpeakFaF($"Something is not right: {ex.Message}. Talk to you later"); } DoneToday = doneToday; ExrzeRuns = sinceRcrd; TodoToday = todoToday; }
public async Task <bool> UpdateObjStatus() { try { var courses = await _context.Courses .Where(x => !x.VirtualDeleted && (x.Status == CourseStatus.NotStarted || x.Status == CourseStatus.Started)) .Include(x => x.Customer) .Include(x => x.Lessons) .ToListAsync(); foreach (var course in courses) { if (course.Status == CourseStatus.NotStarted) { course.Status = course.StartCourse.HasValue && course.StartCourse.Value <= DateTime.Now.Date ? CourseStatus.Started : CourseStatus.NotStarted; _context.Entry(course).State = EntityState.Modified; } else { if (course.Lessons.Any(x => x.Status == LessonStatus.NotStarted || x.Status == LessonStatus.Active)) { var nextLessonNotStatrted = course.Lessons.Any(x => !x.VirtualDeleted && x.Status == LessonStatus.NotStarted) ? course.Lessons.Where(x => x.Status == LessonStatus.NotStarted && x.Date.HasValue).OrderBy(y => y.Date).ThenBy(y => y.Time).FirstOrDefault() : null; var nextLessonStatrted = course.Lessons.Any(x => !x.VirtualDeleted && x.Status == LessonStatus.Active) ? course.Lessons.Where(x => x.Status == LessonStatus.Active && x.Date.HasValue).OrderBy(y => y.Date).ThenBy(y => y.Time).FirstOrDefault() : null; var timeAfterAddLessonTime = nextLessonStatrted != null?DateTime.Now.AddHours(LessonHelper.GetTimeOfLesson(nextLessonStatrted.LessonPeriod)) : DateTime.Now; if (nextLessonNotStatrted != null && nextLessonNotStatrted.Date.HasValue && nextLessonNotStatrted.Time.HasValue && (nextLessonNotStatrted.Date.Value < DateTime.Now.Date || (nextLessonNotStatrted.Date.Value == DateTime.Now.Date && nextLessonNotStatrted.Time.Value.TimeOfDay <= DateTime.Now.TimeOfDay))) { nextLessonNotStatrted.Status = LessonStatus.Active; _context.Entry(nextLessonNotStatrted).State = EntityState.Modified; } //if (nextLessonStatrted != null && // nextLessonStatrted.Date.HasValue && // nextLessonStatrted.Time.HasValue && // (nextLessonStatrted.Date.Value < DateTime.Now.Date || // (nextLessonStatrted.Date.Value == DateTime.Now.Date && nextLessonStatrted.Time.Value.TimeOfDay <= timeAfterAddLessonTime.TimeOfDay))) //{ // nextLessonStatrted.Status = LessonStatus.Finished; // _context.Entry(nextLessonStatrted).State = EntityState.Modified; //} } } } await _context.SaveChangesAsync(); return(true); } catch (Exception e) { return(false); } }