/// <summary> /// Open session window /// </summary> public void OpenSessionWindow() { if (_group == null || _group.Length < 1 || _indiv == null || _indiv.Length < 1 || _eval == null || _eval.Length < 1 || _cond == null || _cond.Length < 1 || _keys == null || _keys.Length < 1 || _sessionNumber == null || _sessionNumber.Length < 1 || _ther == null || _ther.Length < 1 || _collect == null || _collect.Length < 1 || _dataRole == null || _dataRole.Length < 1 || _sessionTime == null || _sessionTime.Length < 1) { return; } int session; if (!int.TryParse(_sessionNumber, out session)) { return; } try { string savedStatePath = Path.Combine(Properties.Settings.Default.SaveLocation, "SavedState.json"); var savedState = new SavedState(); savedState.Group = _group; savedState.Individual = _indiv; savedState.Evaluation = _eval; savedState.Condition = _cond; savedState.KeySet = _keys; savedState.Therapist = _ther; savedState.DataCollector = _collect; savedState.Role = _dataRole; savedState.Duration = _sessionTime; string json = JsonConvert.SerializeObject(savedState); File.WriteAllText(savedStatePath, json); } catch { } var window = new SessionWindow("Recording Session: Session #" + SessionNumber); window.GroupName = _group; window.PatientName = _indiv; window.EvaluationName = _eval; window.ConditionName = _cond; window.KeyboardName = _keys + ".json"; window.SessionCount = session; window.TherapistName = _ther; window.CollectorName = _collect; window.CollectorRole = _dataRole; window.SetKeys(keyboardListViewModel.keyboardSelection); window.SessionTime = GetSessionLength(_sessionTime); window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.ShowDialog(); var kbWindow = new ResultsWindow(); kbWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; kbWindow.mFrequencyColumns = window.GetFrequencyKeys(); kbWindow.mDurationColumns = window.GetDurationKeys(); kbWindow.mainFreqCounts = window.GetMainFrequencyCounts(); kbWindow.mainFreqMinutes = window.GetMainFrequencyTotals(); kbWindow.mainFreqRPM = window.GetMainFrequencyRPM(); kbWindow.mainDurCounts = window.GetMainDurationTime(); kbWindow.mainDurMinutes = window.GetMainDurationTotalTime(); kbWindow.mainDurPercent = window.GetMainDurationPercentageSession(); kbWindow.schOneFreqCounts = window.GetSchOneFrequencyCounts(); kbWindow.schOneFreqMinutes = window.GetSchOneFrequencyTotals(); kbWindow.schOneFreqRPM = window.GetSchOneFrequencyRPM(); kbWindow.schOneDurCounts = window.GetSchOneDurationTime(); kbWindow.schOneDurMinutes = window.GetSchOneDurationTotalTime(); kbWindow.schOneDurPercent = window.GetSchOneDurationPercentageSession(); kbWindow.schTwoFreqCounts = window.GetSchTwoFrequencyCounts(); kbWindow.schTwoFreqMinutes = window.GetSchTwoFrequencyTotals(); kbWindow.schTwoFreqRPM = window.GetSchTwoFrequencyRPM(); kbWindow.schTwoDurCounts = window.GetSchTwoDurationTime(); kbWindow.schTwoDurMinutes = window.GetSchTwoDurationTotalTime(); kbWindow.schTwoDurPercent = window.GetSchTwoDurationPercentageSession(); kbWindow.schThreeFreqCounts = window.GetSchThreeFrequencyCounts(); kbWindow.schThreeFreqMinutes = window.GetSchThreeFrequencyTotals(); kbWindow.schThreeFreqRPM = window.GetSchThreeFrequencyRPM(); kbWindow.schThreeDurCounts = window.GetSchThreeDurationTime(); kbWindow.schThreeDurMinutes = window.GetSchThreeDurationTotalTime(); kbWindow.schThreeDurPercent = window.GetSchThreeDurationPercentageSession(); kbWindow.ShowDialog(); if (kbWindow.SaveData && window.stopWatch.Elapsed.TotalSeconds > 0) { XSSFWorkbook hssfworkbook = new XSSFWorkbook(); try { ISheet page = hssfworkbook.CreateSheet("Cover Page"); window.WriteResults(page, window.freqIntervalListMain, window.stopWatch, window.durationIntervalListMain, window.mMultiScheds[0], true, 0); page = hssfworkbook.CreateSheet("Schedule 1 Only"); window.WriteResults(page, window.freqIntervalListSchOne, window.scheduleOne, window.durationIntervalListSchOne, window.mMultiScheds[1], false, 1); page = hssfworkbook.CreateSheet("Schedule 2 Only"); window.WriteResults(page, window.freqIntervalListSchTwo, window.scheduleTwo, window.durationIntervalListSchTwo, window.mMultiScheds[2], false, 2); page = hssfworkbook.CreateSheet("Schedule 3 Only"); window.WriteResults(page, window.freqIntervalListSchThree, window.scheduleThree, window.durationIntervalListSchThree, window.mMultiScheds[3], false, 3); page = hssfworkbook.CreateSheet("FrequencyIntervals"); window.WriteFreqIntervalResults(page, window.keyFrequency, window.mKeyboards.frequencyKeys, window.freqIntervalListMain); page = hssfworkbook.CreateSheet("DurationIntervals"); window.WriteDurIntervalResults(page, window.keyDuration, window.mKeyboards.durationKeys, window.durationIntervalListMain); var task = new Task <bool>(() => { var targetDir = Path.Combine(Properties.Settings.Default.SaveLocation, window.GroupName, window.PatientName, window.EvaluationName, window.ConditionName); var di = new DirectoryInfo(targetDir); return(di.Exists); }); task.Start(); bool resp = task.Wait(100) && task.Result; if (resp) { var targetFile = Path.Combine(Properties.Settings.Default.SaveLocation, window.GroupName, window.PatientName, window.EvaluationName, window.ConditionName, "Session_" + window.SessionCount + "_" + window.CollectorRole + ".xlsx"); using (FileStream file = new FileStream(targetFile, FileMode.Create)) { hssfworkbook.Write(file); } } else { var targetFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "DataTracker", window.GroupName, window.PatientName, window.EvaluationName, window.ConditionName, "Session_" + window.SessionCount + "_" + window.CollectorRole + ".xlsx"); using (FileStream file = new FileStream(targetFile, FileMode.Create)) { hssfworkbook.Write(file); } MessageBox.Show("Saved to local location!"); } } catch (IOException e2) { Console.WriteLine(e2.ToString()); } } CountSessions(); }