private void AddTasksToPanel(Grid grid, TaskPanelType type, int row, RouteDiffRecordDto record)
        {
            //plan
            string name;
            List <TimedTaskDto> tasks;

            switch (type)
            {
            case TaskPanelType.Plan:
                name  = "план";
                tasks = record.EventsPlan;
                break;

            case TaskPanelType.Fact:
                name  = "факт";
                tasks = record.EventsFact;
                break;

            default:
                throw new Exception("unknown TaskPanelType");
            }

            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(60, GridUnitType.Pixel)
            });

            var txtc1 = new TextBlock
            {
                Foreground          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff3c5466")),
                Background          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(record.BgColor)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                FontSize            = 27,
                FontFamily          = new FontFamily("AvantGardeGothicC"),
                Text = record.RouteName
            };

            grid.Children.Add(txtc1);
            Grid.SetRow(txtc1, row);
            Grid.SetColumn(txtc1, 0);

            var txtc2 = new TextBlock
            {
                Foreground          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff3c5466")),
                Background          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(record.BgColor)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                FontSize            = 27,
                FontFamily          = new FontFamily("AvantGardeGothicC"),
                Text = record.TrainName
            };

            grid.Children.Add(txtc2);
            Grid.SetRow(txtc2, row);
            Grid.SetColumn(txtc2, 1);

            var txtc3 = new TextBlock
            {
                Foreground          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff3c5466")),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                FontSize            = 27,
                FontFamily          = new FontFamily("AvantGardeGothicC"),
                Text = name
            };

            grid.Children.Add(txtc3);
            Grid.SetRow(txtc3, row);
            Grid.SetColumn(txtc3, 2);

            var ganntRow = new GanttRowPanel
            {
                MinDate = _minDate,
                MaxDate = _maxDate
            };

            foreach (var task in tasks)
            {
                if (task.Start > _maxDate)
                {
                    continue;
                }
                if (task.End.HasValue && task.End.Value < _minDate)
                {
                    continue;
                }

                var brd = new Border
                {
                    Height     = 45,
                    Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(task.BgColor))
                };
                if (task.BorderColor != null)
                {
                    brd.BorderThickness = new Thickness(2);
                    brd.BorderBrush     = new SolidColorBrush((Color)ColorConverter.ConvertFromString(task.BorderColor));
                }
                brd.SetValue(GanttRowPanel.StartDateProperty, task.Start);
                brd.SetValue(GanttRowPanel.EndDateProperty, task.End);
                //
                var txt = new TextBlock
                {
                    Foreground          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(task.FgColor)),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    FontSize            = 30,
                    FontFamily          = new FontFamily("AvantGardeGothicC"),
                    Text = task.Name
                };
                brd.Child = txt;
                ganntRow.Children.Add(brd);
            }

            var tmpDate1 = _minDate;

            while (tmpDate1 + new TimeSpan(1, 0, 0) <= _maxDate)
            {
                tmpDate1 = tmpDate1.AddHours(1);

                var hour     = tmpDate1.Hour;
                var tmpDate2 = ChangeTime(tmpDate1, hour, 0, 0, 0);
                var hourLine = new Line
                {
                    X1              = 0,
                    X2              = 0,
                    Y1              = 0,
                    Y2              = 60,
                    Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffb7b7b7")),
                    Stretch         = Stretch.Fill,
                    StrokeThickness = 1,
                    StrokeDashArray = new DoubleCollection {
                        5, 5
                    }
                };
                hourLine.SetValue(GanttRowPanel.StartDateProperty, tmpDate2);
                hourLine.SetValue(GanttRowPanel.EndDateProperty, tmpDate2);
                ganntRow.Children.Add(hourLine);
            }
            grid.Children.Add(ganntRow);
            Grid.SetRow(ganntRow, row);
            Grid.SetColumn(ganntRow, 3);
        }
        private void AddTableHeaders(Grid grid)
        {
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(142)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(182)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(158)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1211)
            });
            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(60)
            });
            //table headers
            for (int l = 2; l <= 3; l++)
            {
                var brdh1 = new Border
                {
                    Background      = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff3c5466")),
                    BorderBrush     = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffffffff")),
                    BorderThickness = new Thickness(0, 0, 0, 0)
                };
                grid.Children.Add(brdh1);
                Grid.SetRow(brdh1, 0);
                Grid.SetColumn(brdh1, l);
            }
            var columns = new List <string> {
                "Маршрут", "Поезд"
            };
            int i = 0;

            foreach (var colname in columns)
            {
                //header border
                var thickness = new Thickness(1, 0, 1, 0);
                if (i == 0)
                {
                    thickness = new Thickness(0, 0, 1, 0);
                }

                var brdh = new Border
                {
                    Background      = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff3c5466")),
                    BorderBrush     = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffffffff")),
                    BorderThickness = thickness
                };
                grid.Children.Add(brdh);
                Grid.SetRow(brdh, 0);
                Grid.SetColumn(brdh, i);

                var txt1 = new TextBlock
                {
                    Foreground          = new SolidColorBrush(Colors.White),
                    FontSize            = 27,
                    FontFamily          = new FontFamily("AvantGardeGothicC"),
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Text = colname
                };
                grid.Children.Add(txt1);
                Grid.SetRow(txt1, 0);
                Grid.SetColumn(txt1, i);

                i++;
            }
            var brdh2 = new Border
            {
                Background      = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff3c5466")),
                BorderBrush     = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffffffff")),
                BorderThickness = new Thickness(1, 0, 0, 0)
            };

            grid.Children.Add(brdh2);
            Grid.SetRow(brdh2, 0);
            Grid.SetColumn(brdh2, 2);
            //end table headers

            //hours timeline
            var ganntHeader = new GanttRowPanel
            {
                MinDate = _minDate,
                MaxDate = _maxDate
            };

            var tmpDate = _minDate;

            while (tmpDate <= _maxDate)
            {
                tmpDate = tmpDate.AddHours(1);

                var hour     = tmpDate.Hour;
                var tmpDate1 = ChangeTime(tmpDate, hour, 0, 0, 0);
                var txtHour  = new TextBlock
                {
                    Foreground          = new SolidColorBrush(Colors.White),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    FontSize            = 27,
                    FontFamily          = new FontFamily("AvantGardeGothicC"),
                    Text = hour.ToString(),
                };
                txtHour.SetValue(GanttRowPanel.StartDateProperty, tmpDate1 - new TimeSpan(0, 15, 0));
                txtHour.SetValue(GanttRowPanel.EndDateProperty, tmpDate1 + new TimeSpan(0, 15, 0));
                ganntHeader.Children.Add(txtHour);
            }
            //
            grid.Children.Add(ganntHeader);
            Grid.SetRow(ganntHeader, 0);
            Grid.SetColumn(ganntHeader, 3);
            //end hours timeline
        }