Exemplo n.º 1
0
        public void AddCell(AddressCell address, CarPartData[] carPartData)
        {
            var pallet = GetCell(address);

            var schemeCell = new SchemeCell(carPartData)
            {
                Address = address
            };

            if (pallet == null)
            {
                _schemeCells.Add(schemeCell);
            }
            else
            {
                _schemeCells[_schemeCells.IndexOf(pallet)] = schemeCell;
            }
        }
Exemplo n.º 2
0
        private void DrawTableArticlesInPallet(SchemeCell cell)
        {
            var grid = new Grid
            {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    }
                }
            };

            Canvas.SetLeft(grid, 20);
            Canvas.SetTop(grid, _schemeDrawingBlock.Size.Height + 20);

            var tableArtictesInPallet = new DataGrid
            {
                CanUserAddRows      = true,
                CanUserDeleteRows   = true,
                HeadersVisibility   = DataGridHeadersVisibility.Column,
                AutoGenerateColumns = false,
                Width     = _schemeDrawingBlock.Size.Width - 20,
                MaxHeight = 120
            };

            Grid.SetRow(tableArtictesInPallet, 0);

            var columnArticle = new DataGridTextColumn
            {
                Width   = new DataGridLength(1, DataGridLengthUnitType.Star),
                Header  = "Артикул",
                Binding = new Binding("Article"),
            };

            tableArtictesInPallet.Columns.Add(columnArticle);

            var columnCountArticle = new DataGridTextColumn
            {
                Width   = new DataGridLength(1, DataGridLengthUnitType.Star),
                Header  = "Количество",
                Binding = new Binding("CountCarParts")
            };

            tableArtictesInPallet.Columns.Add(columnCountArticle);

            var carPartsInPallet = new ObservableCollection <CarPartPallet>(cell.CarParts.Select(carPart => new CarPartPallet
            {
                Article       = carPart.CarPart.FullCarPartName,
                CountCarParts = carPart.CountCarParts
            }));

            tableArtictesInPallet.ItemsSource = carPartsInPallet;

            grid.Children.Add(tableArtictesInPallet);

            var textBlock = new TextBlock
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                Visibility          = Visibility.Collapsed,
                Foreground          = System.Windows.Media.Brushes.Brown,
                FontWeight          = FontWeight.FromOpenTypeWeight(999),
                Margin = new Thickness(0, 4, 0, 0)
            };

            Grid.SetRow(textBlock, 1);
            grid.Children.Add(textBlock);

            var stackPanel = new StackPanel
            {
                Orientation         = Orientation.Horizontal,
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(0, 15, 0, 0)
            };

            Grid.SetRow(stackPanel, 2);

            double buttonWidth = (tableArtictesInPallet.Width / 2 - 30) / 2;

            var buttonSave = new Button
            {
                Content   = "Сохранить",
                Width     = buttonWidth,
                Height    = 24,
                Margin    = new Thickness(0, 0, 15, 0),
                IsEnabled = false
            };

            buttonSave.Click += (sender, e) =>
            {
                var errorMessage = IsValidateTableArticles(tableArtictesInPallet);
                if (errorMessage != null)
                {
                    textBlock.Text       = errorMessage;
                    textBlock.Visibility = Visibility.Visible;
                    buttonSave.IsEnabled = false;
                }
                else
                {
                    textBlock.Text       = null;
                    textBlock.Visibility = Visibility.Collapsed;
                    buttonSave.IsEnabled = true;
                }

                if (!buttonSave.IsEnabled)
                {
                    return;
                }

                var address = new AddressCell
                {
                    Row   = _schemeDrawingWarehouse.SelectedBlock.Row,
                    Place = _schemeDrawingWarehouse.SelectedBlock.Place,
                    Floor = _schemeDrawingBlock.SelectedPallet.Floor,
                    Cell  = _schemeDrawingBlock.SelectedPallet.Cell
                };

                var carPartPallets = new List <CarPartPallet>();
                foreach (var item in tableArtictesInPallet.Items)
                {
                    var carPartPallet = item as CarPartPallet;
                    if (carPartPallet != null)
                    {
                        carPartPallets.Add(carPartPallet);
                    }
                }

                var palletContents = _bc.SavePalletContents(_schemeData.WarehouseName, address, carPartPallets.ToArray());
                var carPartsData   = palletContents.Select(c => new CarPartData
                {
                    CarPart       = c.CarPart,
                    CountCarParts = c.CountCarPart
                }).ToArray();

                _schemeData.AddCell(address, carPartsData);

                _isPalletSelected = false;

                SurfaceWarehouse.Children.Clear();
                _schemeDrawingWarehouse.DrawWarehouse(_warehouseSizeCell, _warehouseSizeRoad, _warehouseFontSize,
                                                      _schemeDrawingWarehouse.SelectedBlock);

                SurfaceBlock.Children.Clear();

                var block = _schemeDrawingWarehouse.SelectedBlock;
                var cells = _schemeData.GetCells(block.Row, block.Place);
                _schemeDrawingBlock.DrawBlock(_blockSizeCell, cells, _blockFontSize);
            };

            var buttonCancel = new Button
            {
                Content = "Отменить",
                Width   = buttonWidth,
                Height  = 24,
                Margin  = new Thickness(15, 0, 0, 0)
            };

            buttonCancel.Click += (sender, e) =>
            {
                _isPalletSelected = false;

                SurfaceBlock.Children.Clear();

                var block = _schemeDrawingWarehouse.SelectedBlock;
                var cells = _schemeData.GetCells(block.Row, block.Place);
                _schemeDrawingBlock.DrawBlock(_blockSizeCell, cells, _blockFontSize);
            };

            stackPanel.Children.Add(buttonSave);
            stackPanel.Children.Add(buttonCancel);

            grid.Children.Add(stackPanel);
            SurfaceBlock.Children.Add(grid);

            tableArtictesInPallet.CurrentCellChanged += (sender, e) =>
            {
                var errorMessage = IsValidateTableArticles(tableArtictesInPallet);
                if (errorMessage != null)
                {
                    textBlock.Text       = errorMessage;
                    textBlock.Visibility = Visibility.Visible;
                    buttonSave.IsEnabled = false;
                }
                else
                {
                    textBlock.Text       = null;
                    textBlock.Visibility = Visibility.Collapsed;
                    buttonSave.IsEnabled = true;
                }
            };
        }