示例#1
0
        private void Venue_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue is LayoutModel value && HasChanged)
            {
                HasChanged = false;
                Save(value);
            }

            ParentGrid.Children.Clear();
            ParentGrid.RowDefinitions.Clear();
            ParentGrid.ColumnDefinitions.Clear();

            if (e.NewValue is LayoutModel layout)
            {
                var areas = layout.Areas.Where(x => x.Status != ModelInfo.Deleted).ToList();
                if (areas.Count == 0)
                {
                    return;
                }

                // create rows
                var rowsCout = areas.Max(x => x.CoordY);
                for (int i = 0; i < rowsCout; i++)
                {
                    ParentGrid.RowDefinitions.Add(new RowDefinition());
                }

                // create columns
                var columnCount = areas.Max(x => x.CoordX);
                for (int i = 0; i < columnCount; i++)
                {
                    ParentGrid.ColumnDefinitions.Add(new ColumnDefinition());
                }

                // create layouts
                foreach (var area in areas)
                {
                    var element = new AreaGrid();
                    ParentGrid.Children.Add(element);
                    SetColumn(element, area.CoordX - 1);
                    SetRow(element, area.CoordY - 1);


                    if (area.Seats.Count == 0)
                    {
                        continue;
                    }
                    // create seat columns
                    var seatColumnsCount = area.Seats.Max(x => x.Number);
                    for (int i = 0; i < seatColumnsCount; i++)
                    {
                        element.ParentGrid.ColumnDefinitions.Add(new ColumnDefinition());
                    }

                    // create seat rows
                    var seatRowsCount = area.Seats.Max(x => x.Row);
                    for (int i = 0; i < seatRowsCount; i++)
                    {
                        element.ParentGrid.RowDefinitions.Add(new RowDefinition());
                    }

                    // create seats
                    foreach (var seat in area.Seats)
                    {
                        var elementSeat = new SeatLabel();
                        element.ParentGrid.Children.Add(elementSeat);
                        SetColumn(elementSeat, seat.Number - 1);
                        SetRow(elementSeat, seat.Row - 1);
                    }
                }
            }
        }
示例#2
0
        private void Border_Drop(object sender, DragEventArgs e)
        {
            if (DataContext == null)
            {
                return;
            }

            // checking that target cell is not a LayerGrid
            if (e.Source is AreaGrid)
            {
                return;
            }

            if (e.Data.GetData(typeof(TemplateSeat)) is TemplateSeat)
            {
                return;
            }

            var mousePosition = new { e.GetPosition(ParentBorder).X, e.GetPosition(ParentBorder).Y };

            var columnPositionPercent = (int)(mousePosition.X * 100 / ParentBorder.ActualWidth);
            var rowPositionPercent    = (int)(mousePosition.Y * 100 / ParentBorder.ActualHeight);

            UIElement element = null;

            if (!ParentGrid.Children.Cast <AreaGrid>().Any())
            {
                ParentGrid.ColumnDefinitions.Add(new ColumnDefinition());
                ParentGrid.RowDefinitions.Add(new RowDefinition());
            }
            else
            if (columnPositionPercent < rowPositionPercent)     // Row
            {
                if (!CheckPosition(e.GetPosition(ParentBorder)))
                {
                    ParentGrid.RowDefinitions.Add(new RowDefinition());
                }
            }
            else
            if (rowPositionPercent < columnPositionPercent)         // Column
            {
                if (!CheckPosition(e.GetPosition(ParentBorder)))
                {
                    ParentGrid.ColumnDefinitions.Add(new ColumnDefinition());
                }
            }

            HasChanged = true;

            if (e.Data.GetData(typeof(TemplateArea)) is TemplateArea)
            {
                element = new AreaGrid();
                ParentGrid.Children.Add(element);
            }
            else if (e.Data.GetData(typeof(AreaGrid)) is AreaGrid layerGrid)
            {
                element = layerGrid;
            }

            if (CheckPosition(e.GetPosition(ParentBorder)))
            {
                SetColumn(element, GetTargetColumn(mousePosition.X));
                SetRow(element, GetTargetRow(mousePosition.Y));
            }

            //clear empty row and column
            if (ParentGrid.Children.Cast <AreaGrid>().All(x => GetRow(x) != ParentGrid.RowDefinitions.Count - 1))
            {
                ParentGrid.RowDefinitions.RemoveAt(ParentGrid.RowDefinitions.Count - 1);
            }

            if (ParentGrid.Children.Cast <AreaGrid>().All(x => GetColumn(x) != ParentGrid.ColumnDefinitions.Count - 1))
            {
                ParentGrid.ColumnDefinitions.RemoveAt(ParentGrid.ColumnDefinitions.Count - 1);
            }
        }