/// <summary> /// Creates and displays general chore elements in the designer. /// Adds TimePicker for due time. /// Adds CheckedListBox for days. /// </summary> public EditChoreUI(Model.Reoccurring chore) { //Display general UI elements InitializeComponent(); //Adds ChildUsers to combobox LoadChildren(); foreach (var child in Model.ChildUser.Load($"c.child_id = {_reoccurring.Assignment}")) { childAssignedComboBox.Text = child.FirstName; } this.Controls.Add(this.childAssignedComboBox); //Sets the chore being editted and fills in existing chore info from DB _reoccurring = chore; choreNameTextBox.Text = _reoccurring.Name; chorePointsTextBox.Text = _reoccurring.Points.ToString(); choreDescriptionRichTextBox.Text = _reoccurring.Description; //Adds type specific UI elements this.Controls.Add(dueDateLabel); dueDateLabel.Text = "Due time"; this.Controls.Add(dueTimeDateTimePicker); dueTimeDateTimePicker.Text = _reoccurring.DueTime.ToString(); this.Controls.Add(daysLabel); this.Controls.Add(daysCheckedListBox); this.Size = new Size(350, 525); //Fills in days in days from DB. Checks each day in CheckedListBox with each day in the Chore for (int i = 0; i < daysCheckedListBox.Items.Count; i++) { for (int j = 0; j < _reoccurring.Days.Count; j++) { //Reqular expression removing whitespace from string. string formItem = Regex.Replace(daysCheckedListBox.Items[i].ToString(), @"\s", ""); string choreItem = Regex.Replace(_reoccurring.Days[j], @"\s", ""); //Is true if day is found bool equals = String.Equals(formItem, choreItem, StringComparison.OrdinalIgnoreCase); //Checks checkbox if day is found in list if (equals) { daysCheckedListBox.SetItemChecked(i, true); } } } saveChangesButton.Location = new System.Drawing.Point(69, 440); _choreType = 3; }
/// <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 and buttons</returns> public Panel LoadReocurringChore(Model.Reoccurring chore, int width, int yLocation) { //Sets type specific info string status = "Active"; string type = "Reocurring"; //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"); } } } }