private void Add(object sender, RoutedEventArgs e)
        {
            this.exercises.Add(exercise_box.Text);

            WrapPanel new_panel = new WrapPanel();
            XButton   remove    = new XButton();

            remove.Width      = 20; remove.btn.Width = 20;
            remove.Height     = 20; remove.btn.Height = 20;
            remove.btn.Click += remove_click;
            TextBlock text = new TextBlock();

            text.Text = exercise_box.Text;
            new_panel.Children.Add(remove);
            new_panel.Children.Add(text);
            View.Children.Add(new_panel);

            StreamWriter sw = new StreamWriter(path);

            foreach (string element in this.exercises)
            {
                sw.WriteLine(element);
            }
            sw.Close();
        }
        private void remove_click(object sender, RoutedEventArgs e)
        {
            Button     button   = (Button)sender;
            XButton    x        = (XButton)button.Parent;
            WrapPanel  parent   = (WrapPanel)x.Parent;
            TextBlock  text     = (TextBlock)parent.Children[1];
            string     exercise = text.Text;
            StackPanel elder    = (StackPanel)parent.Parent;

            elder.Children.Remove(parent);
            exercises.Remove(exercise);

            File.Delete(this.path);
            FileStream new_file = File.Create(this.path);

            new_file.Close();

            StreamWriter sw = new StreamWriter(this.path);

            foreach (string element in this.exercises)
            {
                sw.WriteLine(element);
            }
            sw.Close();
        }
        public ExerciseEdit(string path)
        {
            InitializeComponent();
            this.path = "templates\\" + path + ".WORKOUT";
            exercises = new List <string>();

            StreamReader sr   = new StreamReader(this.path);
            string       line = sr.ReadLine();

            while (line != null)
            {
                exercises.Add(line);
                WrapPanel new_panel = new WrapPanel();
                XButton   remove    = new XButton();
                remove.Width      = 20; remove.btn.Width = 20;
                remove.Height     = 20; remove.btn.Height = 20;
                remove.btn.Click += remove_click;
                TextBlock text = new TextBlock();
                text.Text = line;
                new_panel.Children.Add(remove);
                new_panel.Children.Add(text);
                View.Children.Add(new_panel);

                line = sr.ReadLine();
            }
            sr.Close();
        }
Ejemplo n.º 4
0
 private void RefreshPanel()
 {
     day_view.Children.Clear();
     foreach (string exercise in current_day)
     {
         XButton remove = new XButton();
         remove.btn.Click += RemoveEvent;
         TextBlock text = new TextBlock();
         text.Text = exercise;
         WrapPanel panel = new WrapPanel();
         panel.HorizontalAlignment = HorizontalAlignment.Center;
         panel.VerticalAlignment   = VerticalAlignment.Center;
         panel.Children.Add(remove); panel.Children.Add(text);
         day_view.Children.Add(panel);
     }
 }
Ejemplo n.º 5
0
        private void RemoveEvent(object sender, RoutedEventArgs e)
        {
            Button    button   = (Button)sender;
            XButton   x        = (XButton)button.Parent;
            WrapPanel panel    = (WrapPanel)x.Parent;
            TextBlock text     = (TextBlock)panel.Children[1];
            string    exercise = text.Text;

            foreach (string element in current_day)
            {
                if (element == exercise)
                {
                    current_day.Remove(element);
                    if (exercise.Split('_').Length - 1 == 2)
                    {
                        exercise_count--;
                    }
                    break;
                }
            }
            day_view.Children.Remove((UIElement)button.Parent);
            RefreshPanel();
        }