Exemplo n.º 1
0
 /*
  * StartButtonClicked - Method that start, pauses and resumes a session.
  */
 void StartButtonClicked(object sender, EventArgs args)
 {
     if (Start.Text.CompareTo("Start") == 0)
     {
         Session  new_session        = new Session();
         DateTime toBeClonedDateTime = DateTime.Now;
         DateTime initial            = toBeClonedDateTime;
         new_session.start   = initial;
         new_session.end     = null;
         new_session.project = selected_project.Id;
         new_session.taskId  = selected_task.Id;
         int id = database.SaveSession(new_session);
         new_session.Id = id;
         current        = new_session;
         Start.Text     = "Pause";
         getlocation    = true;
         askLocation();
         //Timer_Counter.Text = "Session is live";
         accelometeractive = true;
         GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable;
         RefreshTime();
     }
     else if (Start.Text.CompareTo("Pause") == 0)
     {
         accelometeractive = false;
         GlobalUtilities.accelerometer.ReadingAvailable -= Accelerometer_ReadingAvailable;
         getlocation = false;
         Start.Text  = "Resume";
         if (database.GetliveInterrupt() is null)
         {
             interrupt        = new Interrupts();
             interrupt.reason = "User reason";
             DateTime toBeClonedDateTime = DateTime.Now;
             interrupt.start     = toBeClonedDateTime;
             interrupt.sessionId = current.Id;
             interrupt.Id        = database.SaveInterrupt(interrupt);
         }
         Timer_Counter.Text = "Session is paused";
     }
     else if (Start.Text.CompareTo("Resume") == 0)
     {
         Start.Text = "Pause";
         interrupt  = database.GetliveInterrupt();
         DateTime toBeClonedDateTime = DateTime.Now;
         interrupt.end = toBeClonedDateTime;
         database.UpdateInterrupt(interrupt);
         getlocation        = true;
         Timer_Counter.Text = "Session is live";
         accelometeractive  = true;
         GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable;
     }
 }