Exemplo n.º 1
0
        /// <summary>
        /// Rejects a completed Chore. If the Chore was generated by a Repeatable Chore it is deleted.
        /// If the Chore is Concrete or generated by a Reoccurring Chore it is set to status active and postponed.
        /// </summary>
        private void DenyChoreButton_Click(object sender, System.EventArgs e)
        {
            //Sets currentChore to the clicked button's tag
            Button clickedButton = (Button)sender;

            Model.Concrete currentChore = (Model.Concrete)clickedButton.Tag;

            //Loads the Child the Chore is assigned to
            var currentChild = Model.ChildUser.Load("child_id=" + currentChore.Assignment);

            //If generated by a Repeatable Chore it's deleted
            if (currentChore.Type == "rep")
            {
                currentChore.Delete();
            }

            //Otherwise it's postponed by 1 day and set to active
            else
            {
                currentChore.DueDate  = DateTime.Now.AddDays(1);
                currentChore.Status   = 1;
                currentChore.Reminder = 0;
                currentChore.Update();
            }

            //Creates a notification to the assigned ChildUser
            Model.Notification.Insert(currentChild[0].ID, "Chore Denied", $"The chore {currentChore.Name} has been denied.");

            //Reload ChoreUI
            LoadAmountOfNotifications();
            DisplayChores();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Approves a Chore and reloads ChoreUI
        /// </summary>
        private void ApproveChoreButton_Click(object sender, System.EventArgs e)
        {
            //Sets currentChore to the clicked button's tag
            Button clickedButton = (Button)sender;

            Model.Concrete currentChore = (Model.Concrete)clickedButton.Tag;

            //Update the Chore's properties and update DB
            currentChore.Status    = 3;
            currentChore.FinalDate = DateTime.Now;
            currentChore.Update();

            //Load the ChildUser the Chore is assigned to
            var currentChild = Model.ChildUser.Load("child_id=" + currentChore.Assignment);

            //Update the ChildUser's points and update DB
            currentChild[0].Points += currentChore.Points;
            currentChild[0].Update();

            //Create a notification to the ChildUser
            Model.Notification.Insert(currentChild[0].ID, "Chore Approved", $"The chore {currentChore.Name} has been approved." +
                                      $"\n{currentChore.Points.ToString()} points has been added to your account");

            //Reload ChoresUI
            LoadAmountOfNotifications();
            DisplayChores();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an individual panel for a single Concrete Chore. Adds buttons for approving, denying,
        /// editting or deleting the Chore depending on status.
        /// </summary>
        /// <param name="chore">Chore to display</param>
        /// <param name="width">Width of the panel</param>
        /// <param name="yLocation">Location in chorePanel</param>
        /// <returns>Panel with Chore info and buttons</returns>
        public Panel LoadConcreteChore(Model.Concrete chore, int width, int yLocation)
        {
            //Sets type specific info
            string status = _statusValues[chore.Status];
            string type   = "Concrete";

            //Creates the panel
            Panel currentPanel = LoadChore(chore, width, yLocation, status, type);

            //Adds status specific buttons.
            //If the Chore is active add edit and delete buttons
            if (chore.Status == 1)
            {
                currentPanel.Controls.Add(AddEditChoreButton(330, currentPanel.Height / 2, chore));
                currentPanel.Controls.Add(AddDeleteChoreButton(365, currentPanel.Height / 2, chore));
            }

            //If the Chore is approval pending add approve and deny buttons
            else if (chore.Status == 2)
            {
                currentPanel.Controls.Add(AddApproveChoreButton(330, currentPanel.Height / 2, chore));
                currentPanel.Controls.Add(AddDenyChoreButton(365, currentPanel.Height / 2, chore));
            }
            return(currentPanel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates and displays general chore elements in the designer.
        /// Adds DateTimePicker for due date.
        /// </summary>
        public EditChoreUI(Model.Concrete chore)
        {
            //Display general UI elements
            InitializeComponent();

            //Adds ChildUsers to combobox
            LoadChildren();
            foreach (var child in Model.ChildUser.Load($"c.child_id = {_concrete.Assignment}"))
            {
                childAssignedComboBox.Text = child.FirstName;
            }

            //Sets the chore being editted and fills in existing chore info from DB
            _concrete                        = chore;
            choreNameTextBox.Text            = _concrete.Name;
            chorePointsTextBox.Text          = _concrete.Points.ToString();
            choreDescriptionRichTextBox.Text = _concrete.Description;

            //Adds type specific UI elements
            this.Controls.Add(dueDateLabel);
            this.Size         = new Size(350, 385);
            dueDateLabel.Text = "Due date";
            this.Controls.Add(dueDateDateTimePicker);
            dueDateDateTimePicker.Text = _concrete.DueDate.ToString();

            _choreType = 1;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a complete button to a Concrete Chore
        /// </summary>
        private Control AddConcreteChoreDoneButton(int locationX, int locationY, Model.Concrete chore)
        {
            //Creates a standard image button from library
            var concreteChoreDoneButton = TechnicalPlatform.UILibrary.StandardElements.AddImageButton(new Point(locationX, locationY - 15), chore, global::ChoreApplication.Properties.Resources.thumbs_up);

            //Adds event handler
            concreteChoreDoneButton.Click += new EventHandler(ConcreteChoreDoneButton_Click);
            return(concreteChoreDoneButton);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates overdue chore
        /// </summary>
        private void UpdateOverdue(Model.Concrete chore, Model.ChildUser child)
        {
            //Subtracks the Chore's points from the ChildUser's account and updates DB
            child.Points -= chore.Points;
            child.Update();

            //Sets the Chore to overdue and the ApprovalDate to now. Updates the DB
            chore.Status    = 4;
            chore.FinalDate = DateTime.ParseExact(DateTime.Now.ToString(Properties.Settings.Default.LongDateFormat), Properties.Settings.Default.LongDateFormat, null);
            chore.Update();

            //Creates a notification for the ChildUser
            Model.Notification.Insert(child.ID, $"A chore has gone over due", $"You did not complete {chore.Name} in time.");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sends the user to the EditChoreUI to edit the chosen Chore
        /// </summary>
        private void EditChoreButton_Click(object sender, System.EventArgs e)
        {
            //Disables ParentMenu
            this.Enabled = false;

            //Casts clicked button to a Button
            Button clickedButton = (Button)sender;

            //Tries to cast Chore from tag to Concrete. Opens EditChoreUI if succesful
            try
            {
                Model.Concrete selectedChore       = (Model.Concrete)clickedButton.Tag;
                var            editSelectedChoreUI = new UI.ParentUI.EditChoreUI(selectedChore);
                editSelectedChoreUI.Show();
                editSelectedChoreUI.FormClosing += ChoreNavigationButton_Click;
            }

            //If the Chore isn't a Concrete proceeds to next type
            catch
            {
                //Tries to cast Chore from tag to Reoccurring. Opens EditChoreUI if succesful
                try
                {
                    Model.Reoccurring selectedChore = (Model.Reoccurring)clickedButton.Tag;
                    var editSelectedChoreUI         = new UI.ParentUI.EditChoreUI(selectedChore);
                    editSelectedChoreUI.Show();
                    editSelectedChoreUI.FormClosing += ChoreNavigationButton_Click;
                }

                //If the Chore isn't a Concrete proceeds to next type
                catch
                {
                    //Tries to cast Chore from tag to Reoccurring. Opens EditChoreUI if succesful
                    try
                    {
                        Model.Repeatable selectedChore = (Model.Repeatable)clickedButton.Tag;
                        var editSelectedChoreUI        = new UI.ParentUI.EditChoreUI(selectedChore);
                        editSelectedChoreUI.Show();
                        editSelectedChoreUI.FormClosing += ChoreNavigationButton_Click;
                    }
                    catch
                    {
                        MessageBox.Show("Could not edit chore: Conversion failed", "Error");
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Completes a Concrete Chore
        /// </summary>
        private void ConcreteChoreDoneButton_Click(object sender, EventArgs e)
        {
            //Set currentChore to the Concrete Chore in clicked button's tag
            Button clickedButton = (Button)sender;

            Model.Concrete currentChore = (Model.Concrete)clickedButton.Tag;

            //Set status to approval pending and update DB
            currentChore.Status = 2;
            currentChore.Update();

            //Create a notification to ParentUser
            Model.Notification.Insert(1, $"{_childrenNames[currentChore.Assignment]} completed a chore.", $"{_childrenNames[currentChore.Assignment]} completed the chore {currentChore.Name}.");

            //Reload ChoreUI
            LoadAmountOfNotifications();
            DisplayChores();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an individual panel for a single Concrete Chore.
        /// </summary>
        private Panel LoadConcreteChore(Model.Concrete chore, int width, int yLocation)
        {
            //Sets label texts
            var choreStatus  = "Status: " + _statusValues[chore.Status];
            var choreDueDate = "Due date: " + chore.DueDate.ToString(Properties.Settings.Default.ShortDateFormat);

            //Creates the panel
            var individualChorePanel = LoadChore(chore, new Point(1, yLocation), chore.Points, choreStatus, choreDueDate);

            chorePanel.Controls.Add(individualChorePanel);

            //If the Chore is active ads complete button
            if (chore.Status == 1)
            {
                individualChorePanel.Controls.Add(AddConcreteChoreDoneButton(330, individualChorePanel.Height / 2, chore));
                individualChorePanel.Controls.Add(TechnicalPlatform.UILibrary.StandardElements.AddLabel("Completed?", false, new Point(305, individualChorePanel.Height / 2 + 20)));
            }

            return(individualChorePanel);
        }