示例#1
0
        private void button_cancel_Click(object sender, EventArgs e) => Close(); //closes form without comitting any changes

        private void button_undo_Click(object sender, EventArgs e)               //undo the last change made to current _day state; can revert back up to when form 1st opened(no changes)
        {                                                                        //TODO: OPTIMIZE/Figure out better way(just use list?) Later!
            if (_daysPrevious.Count > 1)
            {
                _daysPrevious.Remove(_daysPrevious.Last());                           //removes last(same as current) day object from list
                _day = _daysPrevious.Last().Clone();                                  //sets current day as a New DayEntry object with 2nd to last values(cloning from _daysPrevious list to avoid values changing in list also because of the reference)

                comboBox_meals.DataSource = new BindingSource(_day._mealEntries, ""); //updates selected meal(in case meal get undone)
                if (_day._mealEntries.Count > 0)
                {
                    comboBox_meals.SelectedItem = _day._mealEntries.Last();
                }

                //resets UI values without calling updateDay() to dupe values don't show up
                output.Clear();
                output.AppendText(_day.ToString() + "\n\n");
                label_title.Text    = $"DAY: {_day._date.ToString("dd/MM/yyyy")}";
                label_subtitle.Text = _day._note.ToStringInfo();
                textBox_activ.Text  = _day._activ;
                this.Update();
            }
            else
            {
                MessageBox.Show("Cannot Undo Further!");            //initial state on form open
            }
        }
示例#2
0
 private void updateDay()    //method that updates various UI elementas(Title, Activ,Output text) to corespond with changed data and saves day state for undo
 {
     output.Clear();
     output.AppendText(_day.ToString() + "\n\n");
     label_title.Text    = $"DAY: {_day._date.ToString("dd/MM/yyyy")}";
     label_subtitle.Text = _day._note.ToStringInfo();
     textBox_activ.Text  = _day._activ;
     this.Update();
     _daysPrevious.Add(_day.Clone());    //adds current day state to undo list
 }