/// <summary> /// Creates a Concrete Chore from the Repeatable Chore in approval pending state /// </summary> private void RepeatableChoreDoneButton_Click(object sender, EventArgs e) { //Set currentChore to the Repeatable Chore in clicked button's tag Button clickedButton = (Button)sender; Model.Repeatable currentChore = (Model.Repeatable)clickedButton.Tag; //Calculate diminishing returns double calculateDiminishingReturn = currentChore.Points; for (int i = 0; i < currentChore.Completions; i++) { calculateDiminishingReturn *= 0.75; } int diminishedPoints = (int)calculateDiminishingReturn; //Create a Concrete Chore Model.Concrete.Insert(currentChore.Name, currentChore.Description, diminishedPoints, currentChore.Assignment, new DateTime(2000, 1, 1, 0, 0, 0), "rep"); //Increment completions and update currentChore.Completions++; 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(); }
/// <summary> /// Creates and displays general chore elements in the designer. /// Adds NavigationUpDown for limit. /// </summary> public EditChoreUI(Model.Repeatable chore) { //Display general UI elements InitializeComponent(); //Adds ChildUsers to combobox LoadChildren(); foreach (var child in Model.ChildUser.Load($"c.child_id = {_repeatable.Assignment}")) { childAssignedComboBox.Text = child.FirstName; } this.Controls.Add(childAssignedComboBox); //Sets the chore being editted and fills in existing chore info from DB _repeatable = chore; choreNameTextBox.Text = _repeatable.Name; chorePointsTextBox.Text = _repeatable.Points.ToString(); choreDescriptionRichTextBox.Text = _repeatable.Description; //Adds type specific UI elements this.Size = new Size(350, 385); this.Controls.Add(dueDateLabel); dueDateLabel.Text = "Limit"; this.Controls.Add(completionLimitUpDown); completionLimitUpDown.Value = _repeatable.Limit; _choreType = 2; }
/// <summary> /// Creates a complete button to a Repeatable Chore /// </summary> private Button AddRepeatableChoreDoneButton(int locationX, int locationY, Model.Repeatable chore) { //Creates a standard image button from library var reatableChoreDoneButton = TechnicalPlatform.UILibrary.StandardElements.AddImageButton(new Point(locationX, locationY - 15), chore, global::ChoreApplication.Properties.Resources.thumbs_up); //Disables the button if limit is reached if (chore.Completions >= chore.Limit) { reatableChoreDoneButton.Enabled = false; } //Adds event handler reatableChoreDoneButton.Click += new EventHandler(RepeatableChoreDoneButton_Click); return(reatableChoreDoneButton); }
/// <summary> /// Creates an individual panel for a single Repeatable Chore. Adds buttons for editting and deleting the Chore. /// </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, edit button and delete button</returns> public Panel LoadRepeatableChore(Model.Repeatable chore, int width, int yLocation) { //Sets type specific info string status = "Active"; string type = "Repeatable"; //Creates the panel Panel currentPanel = LoadChore(chore, width, yLocation, status, type); //Adds status specific buttons currentPanel.Controls.Add(AddEditChoreButton(330, currentPanel.Height / 2, chore)); currentPanel.Controls.Add(AddDeleteChoreButton(365, currentPanel.Height / 2, chore)); return(currentPanel); }
/// <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"); } } } }
/// <summary> /// Creates an individual panel for a single Repeatable Chore. /// Points are diminished by 25% for each completion. /// Adds buttons for completing it Chore. /// Button is disabled if limit is reached. /// </summary> private Panel LoadRepeatableChore(Model.Repeatable chore, int width, int yLocation) { //Calculates diminishing returns on points double calcDimishingReturn = chore.Points; for (int j = 0; j < chore.Completions; j++) { calcDimishingReturn *= 0.75; } int diminishedPoints = (int)calcDimishingReturn; //Sets label text var chorePoints = "Points: " + diminishedPoints.ToString(); var choreLimit = "Completion limit: " + chore.Limit.ToString(); var choreCompletions = "Amount completed today: " + chore.Completions.ToString(); //Creates the panel var individualChorePanel = LoadChore(chore, new Point(1, yLocation), diminishedPoints, choreLimit, choreCompletions); //Add complete button var repChoreDoneButton = AddRepeatableChoreDoneButton(330, individualChorePanel.Height / 2, chore); //If limit is reached disables button if (chore.Completions >= chore.Limit) { var limitReachedLabel = TechnicalPlatform.UILibrary.StandardElements.AddLabel("Limit reached", false, new Point(290, individualChorePanel.Height / 2)); limitReachedLabel.Enabled = false; individualChorePanel.Controls.Add(limitReachedLabel); } else { individualChorePanel.Controls.Add(repChoreDoneButton); individualChorePanel.Controls.Add(TechnicalPlatform.UILibrary.StandardElements.AddLabel("Completed?", false, new Point(305, individualChorePanel.Height / 2 + 20))); } return(individualChorePanel); }