public IntervalProductivityPopUp(SurveyEntry previousSurveyEntry)
        {
            this.InitializeComponent();

            // set default values
            _previousSurveyEntry = previousSurveyEntry;

            if (_previousSurveyEntry != null && _previousSurveyEntry.TimeStampFinished  != null && // if available
                _previousSurveyEntry.TimeStampFinished.Day == DateTime.Now.Day) // only if it was answered today
            {
                var hint = string.Format(CultureInfo.InvariantCulture, "Last entry was: {0} {1}",
                    _previousSurveyEntry.TimeStampFinished.ToShortDateString(),
                    _previousSurveyEntry.TimeStampFinished.ToShortTimeString());

                if (_previousSurveyEntry.Productivity > 0 && _previousSurveyEntry.Productivity < 7)
                    hint += ", you answered: " + _previousSurveyEntry.Productivity;

                LastTimeFilledOut.Text = hint;
            }

            // start timer to close if not responded within a few hours
            _closeIfNotAnsweredAfterHoursTimer = new DispatcherTimer();
            _closeIfNotAnsweredAfterHoursTimer.Interval = Settings.IntervalCloseIfNotAnsweredInterval;
            _closeIfNotAnsweredAfterHoursTimer.Tick += NotAnsweredAfterHours;
            _closeIfNotAnsweredAfterHoursTimer.Start();
        }
Beispiel #2
0
        /// <summary>
        /// returns the previous survey entry if available
        /// (only get interval survey responses)
        /// </summary>
        /// <returns>previous survey entry or null, if there isn't any</returns>
        internal static SurveyEntry GetPreviousIntervalSurveyEntry()
        {
            var query = "SELECT surveyNotifyTime, surveyStartTime, surveyEndTime, userProductivity FROM '" + Settings.DbTableIntervalPopup + "' ORDER BY time DESC;";
            var res = Database.GetInstance().ExecuteReadQuery(query);
            if (res == null || res.Rows.Count == 0) return null;

            var entry = new SurveyEntry();

            if (res.Rows[0]["surveyNotifyTime"] != null)
            {
                try
                {
                    var val = DateTime.Parse((string)res.Rows[0]["surveyNotifyTime"], CultureInfo.InvariantCulture);
                    entry.TimeStampNotification = val;
                }
                catch { } // necessary, if we run it after the DB initialization, there is no value
            }
            if (res.Rows[0]["surveyStartTime"] != null)
            {
                try
                {
                    var val = DateTime.Parse((string)res.Rows[0]["surveyStartTime"], CultureInfo.InvariantCulture);
                    entry.TimeStampStarted = val;
                }
                catch { } // necessary, if we run it after the DB initialization, there is no value
            }
            if (res.Rows[0]["surveyEndTime"] != null)
            {
                try
                {
                    var val = DateTime.Parse((string)res.Rows[0]["surveyEndTime"], CultureInfo.InvariantCulture);
                    entry.TimeStampFinished = val;
                }
                catch { } // necessary, if we run it after the DB initialization, there is no value
            }
            if (res.Rows[0]["userProductivity"] != null)
            {
                try
                {
                    var val = Convert.ToInt32(res.Rows[0]["userProductivity"], CultureInfo.InvariantCulture);
                    entry.Productivity = val;
                }
                catch { } // necessary, if we run it after the DB initialization, there is no value
            }
            return entry;
        }
Beispiel #3
0
        /// <summary>
        /// Saves the survey entry to the database
        /// </summary>
        /// <param name="entry"></param>
        internal static void SaveIntervalEntry(SurveyEntry entry)
        {
            if (entry == null) return;

            try
            {
                var query = "INSERT INTO " + Settings.DbTableIntervalPopup + " (time, surveyNotifyTime, surveyStartTime, surveyEndTime, userProductivity) VALUES " +
                            "(strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime'), " +
                            Database.GetInstance().QTime(entry.TimeStampNotification) + ", " +
                            Database.GetInstance().QTime(entry.TimeStampStarted) + ", " +
                            Database.GetInstance().QTime(entry.TimeStampFinished) + ", " +
                            Database.GetInstance().Q(entry.Productivity.ToString(CultureInfo.InvariantCulture)) + ");";

                Database.GetInstance().ExecuteDefaultQuery(query);
            }
            catch { }
        }
Beispiel #4
0
        /// <summary>
        /// Saves the interval-survey results in the db & resets some items
        /// </summary>
        /// <param name="popup"></param>
        private void SaveIntervalSurvey(IntervalProductivityPopUp popup)
        {
            _timeRemainingUntilNextSurvey = PopUpIntervalInMins; // set new default interval

            _currentSurveyEntry.Productivity = popup.UserSelectedProductivity;
            _currentSurveyEntry.TimeStampFinished = DateTime.Now;
            Queries.SaveIntervalEntry(_currentSurveyEntry);
            _currentSurveyEntry = null; // reset
        }
Beispiel #5
0
        /// <summary>
        /// Saves the daily survey result in the db & resets some items
        /// </summary>
        /// <param name="popup"></param>
        private void SaveDailySurvey(DailyProductivityPopUp popup)
        {
            _lastDailyPopUpResponse = DateTime.Now.Date; // no more daily pop-up for today

            _currentSurveyEntry.Productivity = popup.UserSelectedProductivity;
            _currentSurveyEntry.TimeStampFinished = DateTime.Now;
            Queries.SaveDailyEntry(_currentSurveyEntry);
            _currentSurveyEntry = null; // reset
        }
Beispiel #6
0
        /// <summary>
        /// runs the survey and handles the response
        /// </summary>
        /// <returns></returns>
        private void RunSurvey(SurveyMode mode)
        {
            try
            {
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(
                () =>
                {
                    var previousActiveWorkday = Queries.GetPreviousActiveWorkDay();

                    // if it's the first time the notification is shown
                    if (_currentSurveyEntry == null)
                    {
                        _currentSurveyEntry = new SurveyEntry();
                        _currentSurveyEntry.TimeStampNotification = DateTime.Now;
                        if (previousActiveWorkday > DateTime.MinValue) _currentSurveyEntry.PreviousWorkDay = previousActiveWorkday;
                    }

                    // (re-)set the timestamp of filling out the survey
                    _currentSurveyEntry.TimeStampStarted = DateTime.Now;

                    // set previous entry to show previous entry time in popup
                    var popup = (mode == SurveyMode.IntervalPopUp)
                        ? (Window)new IntervalProductivityPopUp(Queries.GetPreviousIntervalSurveyEntry())
                        : (Window)new DailyProductivityPopUp(previousActiveWorkday);

                    // show popup & handle response
                    if (mode == SurveyMode.DailyPopUp
                        && ((DailyProductivityPopUp)popup).ShowDialog() == true)
                    {
                        HandleDailyPopUpResponse((DailyProductivityPopUp)popup);
                    }
                    else if (mode == SurveyMode.IntervalPopUp
                        && ((IntervalProductivityPopUp)popup).ShowDialog() == true)
                    {
                        HandleIntervalPopUpResponse((IntervalProductivityPopUp)popup);
                    }
                    else
                    {
                        // we get here when DialogResult is set to false (which never happens)
                        Database.GetInstance().LogErrorUnknown(Name);

                        // to ensure it still shows some pop-ups later
                        _timeRemainingUntilNextSurvey = PopUpIntervalInMins;
                    }
                }));
            }
            catch (ThreadAbortException e) { Database.GetInstance().LogError(Name + ": " + e.Message); }
            catch (Exception e) { Database.GetInstance().LogError(Name + ": " + e.Message); }
        }
Beispiel #7
0
 /// <summary>
 /// handles the response to the interval popup
 /// </summary>
 /// <param name="popup"></param>
 private void HandleIntervalPopUpResponse(IntervalProductivityPopUp popup)
 {
     // user took the survey || user didn't work
     if ((popup.UserSelectedProductivity >= 1 && popup.UserSelectedProductivity <= 7) || popup.UserSelectedProductivity == -1)
     {
         SaveIntervalSurvey(popup);
     }
     // user postponed the survey
     else if (popup.PostPoneSurvey != PostPoneSurvey.None)
     {
         PostponeIntervalSurvey(popup);
         Database.GetInstance().LogInfo(string.Format(CultureInfo.InvariantCulture, "The participant postponed the interval-survey ({0}).", popup.PostPoneSurvey));
     }
     // something strange happened
     else
     {
         _currentSurveyEntry = null;
         _timeRemainingUntilNextSurvey = Settings.IntervalPostponeShortInterval;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Handles the response to the daily popup
 /// </summary>
 /// <param name="popup"></param>
 private void HandleDailyPopUpResponse(DailyProductivityPopUp popup)
 {
     // user took the survey || user didn't work
     if ((popup.UserSelectedProductivity >= 1 && popup.UserSelectedProductivity <= 7) || popup.UserSelectedProductivity == -1)
     {
         SaveDailySurvey(popup);
     }
     // something strange happened
     else
     {
         _currentSurveyEntry = null;
         _timeRemainingUntilNextSurvey = Settings.IntervalPostponeShortInterval;
     }
 }