private void SaveData()
        {
            if (ShowWarning && ShowWarningBox("All data related to the timetable will be deleted. Are you sure you want to continue?") == MessageBoxResult.Cancel)
            {
                return;
            }
            string         weekName              = null;
            IList <string> periods               = new List <string>();
            IList <string> days                  = new List <string>();
            IList <int>    uv_periods            = new List <int>();
            IList <TimetableStructureWeek> weeks = new List <TimetableStructureWeek>();

            foreach (UIElement grid_element in spWeeks.Children)
            {
                periods.Clear();
                days.Clear();
                uv_periods.Clear(); //resets the lists for each iteration
                if (!(grid_element is Grid grid))
                {
                    continue;
                }
                foreach (UIElement parent_element in grid.Children)
                {
                    int row = Grid.GetRow(parent_element), column = Grid.GetColumn(parent_element) - 1;
                    if (!(parent_element is Border border))
                    {
                        continue;
                    }
                    UIElement element = border.Child;
                    if (row == 0)
                    {
                        if (column == 0)
                        {
                            weekName = ((EditableText)element).Text;
                            continue;
                        }
                        days.InsertDefaultIndex(column - 1, ((EditableText)element).Text);
                        continue;
                    }
                    if (column == 0)
                    {
                        periods.InsertDefaultIndex(row - 1, ((EditableText)element).Text);
                        continue;
                    }
                    if (!(bool)((FrameworkElement)element).Tag)
                    {
                        uv_periods.Add(column - 1);
                        uv_periods.Add(row - 1);
                    }
                }
                int num_periods = periods.Count;
                weeks.Add(new TimetableStructureWeek(weekName, new List <string>(days), new List <string>(periods),                                                                                                      // adds the correct weeks to the list
                                                     Enumerable.Range(0, uv_periods.Count / 2).Select(i => TimetableStructureWeek.IndexesToPeriodNum(uv_periods[2 * i], uv_periods[2 * i + 1], num_periods)).ToList())); // generates the days and the periods
            }
            App.Data.SetTimetableStructure(weeks);                                                                                                                                                                       // set the current structure data
        }