예제 #1
0
        /// <summary>
        /// Add a new process to the tracked processes list in the database
        /// </summary>
        /// <param name="sender">Track button</param>
        /// <param name="e">Click</param>
        private void TrackNewVG(object sender, EventArgs e)
        {
            //Check that the given display name to associate with the process is between 1 and 50 characters
            if (VGName.Text.Length > 50 || VGName.Text.Length < 1)
            {
                MessageBox.Show("Invalid display name", "Invalid display name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //If there is a process selected, add it to the database with the given display name.
            if (Processes.SelectedRows.Count == 1)
            {
                //Attempt to add the process to be tracked.
                if (SQLconn.AddTracker(VGName.Text, (string)Processes.SelectedRows[0].Cells[0].Value))
                {
                    MessageBox.Show("Process successfully added", "Process for " + VGName.Text + " was added.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    host.SetTracked(); //reset the tracked list to be checked by the timer.
                }
                else
                {
                    MessageBox.Show("Process could not be added.  Check connection to database.", "Process failed to add",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("A process must be selected.", "No process selected", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }

            UpdateTables(); //Update the displayed tables
        }
예제 #2
0
        /// <summary>
        /// Submit edited cell data.
        /// </summary>
        /// <param name="sender">VG2Track</param>
        /// <param name="e">End edit cell</param>
        private void SubmitEdit(object sender, DataGridViewCellEventArgs e)
        {
            //only save for edits on display name column
            if (e.ColumnIndex == 0)
            {
                return;
            }

            string newDisplay  = (string)VG2Track.Rows[e.RowIndex].Cells[1].Value;
            string processName = (string)VG2Track.Rows[e.RowIndex].Cells[0].Value;

            //check length of new display name for range
            if (newDisplay.Length > 0 && newDisplay.Length < 51)
            {
                if (SQLconn.EditTracker(newDisplay, processName))
                {
                    MessageBox.Show(processName + " updated with new display name: " + newDisplay,
                                    "Update Success");
                }
                else
                {
                    MessageBox.Show(processName + " could not be updated with new display name: " + newDisplay +
                                    " Please check conneciton the the database.", "Update Failure", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Invalid display name detected.", "Invalid Text Entered", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            UpdateTables(); //update tables to either show changes or revert depending on entry validity.
        }
예제 #3
0
        /// <summary>
        /// Updates the display of actively tracked processes and the display of active processes.
        /// </summary>
        private void UpdateTables()
        {
            //update tracked view
            VG2Track.DataSource = SQLconn.GetVGs();


            //Get all the tracked processes from the database
            Process[] procs   = Process.GetProcesses(); //get all current processes
            DataTable dtProcs = new DataTable();

            dtProcs.Columns.Add("Running Processes");
            DataRow row;

            //Add all of the currently running processes from the list to the datatable.
            for (int i = 0; i < procs.Length; i++)
            {
                row = dtProcs.NewRow();
                row["Running Processes"] = procs[i].ProcessName;
                dtProcs.Rows.Add(row);
            }
            BindingSource procsBind = new BindingSource {
                DataSource = dtProcs
            };

            Processes.DataSource = procsBind; //Set the process view to the data
        }
예제 #4
0
        /// <summary>
        /// Set the day end time to record data if the program isn't turned off (it will save if shutoff)
        /// </summary>
        private void SetData()
        {
            //Set/reset dayEnd if necissary
            if (dayEnd == null || dayEnd.Day != DateTime.Today.Day)
            {
                DateTime now = DateTime.Today;                                 //get today's date
                dayEnd = new DateTime(now.Day, now.Month, now.Day, 23, 58, 0); //11:58 pm today
            }

            //Check if the data has been saved to the database, if not save it and flag saved.
            if (!saved)
            {
                saved = SavePlay();
            }

            //get the values for today abd create a new entry for today if not yet created
            DataTable todayData = SQLconn.RecordByDate(DateTime.Today);

            if (todayData == null) //make sure something was returned
            {
                MessageBox.Show("Database Error", "Could not load data for today.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            VGActive              = new Stopwatch();                              //create a new stopwatch for the daily session
            played                = (TimeSpan)todayData.Rows[0]["played"];        //retrieve the played time for the day
            exerciseTotal         = (TimeSpan)todayData.Rows[0]["exerciseTotal"]; //retrieve the exercise total time for the day
            ExerciseTotalLbl.Text = exerciseTotal.ToString();                     //set the text of the exercise total label.
            availableStart        = (TimeSpan)todayData.Rows[0]["availablePlay"]; //get the available play for today.
            UpdateTime(null, null);                                               //set the time active and time left labels
            if (vd != null)                                                       //update the data view if it has been created
            {
                vd.UpdateView();
            }
            saved = false;
        }
예제 #5
0
        /// <summary>
        /// Delete the selected process.
        /// </summary>
        /// <param name="sender">Delete Button</param>
        /// <param name="e">Click</param>
        private void DeleteTracker(object sender, EventArgs e)
        {
            if (VG2Track.SelectedRows.Count != 1)
            {
                return;
            }

            string process = (string)VG2Track.SelectedRows[0].Cells[1].Value; //get the process that is selected

            if (MessageBox.Show(string.Format("Delete tracker for {0}?", (string)VG2Track.SelectedRows[0].Cells[1].Value),
                                "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (SQLconn.RemoveTracker(process))
                {
                    MessageBox.Show(process + " will no longer be tracked.", "Process tracker removed");
                    host.SetTracked();
                }
                else
                {
                    MessageBox.Show(process + " could not be untracked.  Please check connection to the database.",
                                    "Process still tracked", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            UpdateTables();
        }
예제 #6
0
        /// <summary>
        /// Initialize the program: Start the check time and create a new entry for today if one hasn't been created.
        /// </summary>
        public TimerScreen()
        {
            InitializeComponent();

            treatmentStart = new DateTime(2019, 5, 29);          //May 29, 2019
            oneAM          = new DateTime(2019, 5, 22, 1, 0, 0); //1 AM

            CheckActive.Start();                                 //Start the activity checking timer
            SetData();                                           //setup for the day
            trackedProcesses = SQLconn.GetTracked();
        }
예제 #7
0
        /// <summary>
        /// Adds the time (in minutes) indicated in the spinner to the exercise time.
        /// </summary>
        /// <param name="sender">Exercise Add button</param>
        /// <param name="e">Click</param>
        private void AddExercise(object sender, EventArgs e)
        {
            //Get the exercise type from the radio buttons
            string type;

            if (walkRBtn.Checked)
            {
                type = "walk";
            }
            else if (yardworkRbtn.Checked)
            {
                type = "yardwork";
            }
            else if (cardioRBtn.Checked)
            {
                type = "cardio";
            }
            else if (workoutRBtn.Checked)
            {
                type = "workout";
            }
            else
            {
                MessageBox.Show("No exercise type selected", "An exercise type must be selected.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //Submit the exercise time to the database adding the entered hours and minutes together
            TimeSpan exercise = TimeSpan.FromMinutes((double)ExHours.Value * 60 + (double)ExMins.Value);

            if (SQLconn.AddExerciseTime(exercise, type))
            {
                availableStart = availableStart.Add(exercise);
                SetData();         //update displays
                ExMins.Value  = 0; //reset minutes counter to 0
                ExHours.Value = 0; //reset hour counter to 0
            }
            else
            {
                MessageBox.Show("An error occured which prevented the exercise from being added.\nPlease check connection to the database " + type,
                                "Exercise not added", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #8
0
        /// <summary>
        /// Saves the play time
        /// </summary>
        /// <returns></returns>
        private bool SavePlay()
        {
            played = played.Add(VGActive.Elapsed);
            TimeSpan left = availableStart.Subtract(VGActive.Elapsed);

            //save the new play time to the database
            if (SQLconn.SaveVGtime(played, left))
            {
                //if the save was successful, then reset playtime timer and the timeleft.
                if (VGActive.IsRunning)
                {
                    VGActive.Restart();
                }
                else
                {
                    VGActive.Reset();
                }
                availableStart = left;
                return(true);
            }
            return(false);
        }
예제 #9
0
        /// <summary>
        /// Updates the data in the Data View from the database.
        /// </summary>
        public void UpdateView()
        {
            //Only update when visible
            if (!Visible)
            {
                return;
            }

            DataView.DataSource = SQLconn.GetVGRecords();

            foreach (DataGridViewRow row in DataView.Rows)
            {
                //Get day of the week
                DateTime day = (DateTime)row.Cells[1].Value;
                row.Cells[0].Value = day.DayOfWeek;

                //Truncate milliseconds in VG played and Available Play
                TimeSpan time = (TimeSpan)row.Cells[2].Value;
                row.Cells[2].Value = new TimeSpan(time.Hours, time.Minutes, time.Seconds);
                time = (TimeSpan)row.Cells[3].Value;
                row.Cells[3].Value = new TimeSpan(time.Hours, time.Minutes, time.Seconds);
            }
            return;
        }
예제 #10
0
 /// <summary>
 /// Reset the tracked processes list.
 /// </summary>
 public void SetTracked()
 {
     trackedProcesses = SQLconn.GetTracked();
 }