public void  ToContainerListIncludeVerticalPallet(List<Container> tempList)
 {
     FromTempListToContList fromTempListToContList = new FromTempListToContList();
    foreach (Object data in Blocks)
    {   
         if (data is VerticalBlock)
         {   
            VerticalBlock v=(VerticalBlock)data;
                v.ToContainerList(tempList);
         }
         else if (data is HorizontalBlock)
         {
             HorizontalBlock c = (HorizontalBlock)data;
             c.ToContainerList(tempList);
         }
         else if (data is Container)
         {
             Container c=(Container)data;
             c.ToContainerList(tempList);
         }
         else
         {
             MessageBox.Show("В процедуру выгрузки контейнеров класса VerticalBlock передан неверный тип данных:" + data.GetType());
         }
    }
 }
 public override void ToContainerList(List<Container> tempList)
 {
     FromTempListToContList fromTempListToContList = new FromTempListToContList();
     fromTempListToContList.ToContainerList(tempList, Blocks);
 }
        private void AddDescription(FlowDocument doc, Vehicle vehicle)
        {
            var fromTempListToContList = new FromTempListToContList();
            var tempList = vehicle.VehicleToContainerList();
            tempList = fromTempListToContList.ToContainerList(tempList);
            //tempList.AddRange(v.smallBlocks);
            var shipmentList = DistinctShipmentID(tempList);
            foreach (var order in shipmentList)
            {
                var tempList2 = tempList.Where(c => c.ShipmentId == order).ToList();
                AddRow(doc,
                    "Грузоотправление: " + tempList2[0].ShipmentId + ".    Грузополучатель: " + tempList2[0].ShipToName +
                    ".    Количество тар: " + tempList2.Count());
            }
            AddRow(doc, "Общий вес:" + vehicle.Mass + " кг.");

            VehicleAxisMass vehicleAxisMass = new VehicleAxisMass(vehicle, vehicle.Mass);
            var axisMassList=vehicleAxisMass.AxisMassCalculate();
            for (int i = 0; i < axisMassList.Count; i++)
            {
                AddRow(doc, String.Format("Нагрузка на ось{0} - {1:0.000} \n", (i + 1), axisMassList[i]));
            }
        }
        private List<Container> DownloadContainersToVehicle(List<Container> containers, int maxTonnage)
        {
            ClearVehicle();
            vehicle.MaxLength = vehicle.Length;
            //делим тары на вертикальные блоки 
            List<VerticalBlock> vBlocks = new List<VerticalBlock>();
            FromTempListToContList fromTempListToContList = new FromTempListToContList();
            //разные заказы обрабатываем отдельно т.к. их нужно будет выгружать из машины в разное время

            //Негабаритный товар отсекаем 
            List<Container> containerList = containers.Where(s => s.IsSuitableLength(vehicle.Width) == true).ToList();
            wasteList = containers.Where(s => s.IsSuitableLength(vehicle.Width) == false).ToList();
            List<Container> wasteList2 = containerList.Where(s => s.Height >= vehicle.MaxHeight).ToList();
            containerList = containerList.Where(s => s.Height <= vehicle.MaxHeight).ToList();
            foreach (Container c in wasteList2)
            {
                wasteList.Add(c);
            }

            //маленькие тары будем загружать после основных тар 
            List<Container> tempSmall =
                containerList.Where(c => c.Length <= 400 & c.Width <= 400 & c.Height <= 400)
                    .OrderBy(s => s.Priority)
                    .ThenByDescending(s => s.Price)
                    .ToList();
            containerList = containerList.Where(c => c.Length > 400 | c.Width > 400 | c.Height > 400).ToList();

            //получаем список заказов
            //List<Container> tempSmall2 = new List<Container>();
            List<int> orderList = DistinctOrders(containerList);
            foreach (int order in orderList.OrderBy(o => o))
            {
                List<Container> tempList = containerList.Where(c => c.Order == order).ToList();

                tempList = ProcessingCabin(tempList, maxTonnage).ToList();
                tempList = ProcessingChassis(tempList, maxTonnage).ToList();

                //Если есть кабины то строим лесенку для предотвращения повреждения кабин
                //формируем первый ряд в один ярус
                int minHeight = 100;
                if (NotEmpty())
                {
                    int ch = 0;
                    for (ch = 1; ch < 7; ch++)
                    {
                        if (ch > 1)
                        {
                            minHeight = vehicle.Blocks[vehicle.Blocks.Count() - 1].MinHeight;
                        }
                        tempList = CreateRow3(tempList, minHeight, vehicle.MaxHeight, vehicle.Width, 0, maxTonnage);
                    }
                }

                //контейнеры которые штабелируются в два яруса и ставятся только на пол
                tempList = CreateVerticalPalletsLevel2(tempList, vehicle.MaxHeight);
                //отбираем контейнеры которые штабелируются в 3 яруса и ставятся только на пол
                tempList = CreateVerticalPalletsLevel3(tempList, 800, 400, 390, vehicle.MaxHeight, "1-");
                tempList = CreateVerticalPalletsLevel3(tempList, 800, 400, 500, vehicle.MaxHeight, "2-");
                tempList = CreateVerticalPalletsLevel3(tempList, 900, 360, 420, vehicle.MaxHeight, "3-");
                tempList = CreateVerticalPalletsLevel3(tempList, 890, 570, 540, vehicle.MaxHeight, "4-");

                //Обрабатываем остальные контейнеры
                if (NotEmpty())
                {
                    minHeight = vehicle.Blocks[vehicle.Blocks.Count() - 1].MinHeight;
                } //если есть ряды, то смотрим высоту последнего
                else
                {
                    minHeight = vehicle.Height - 500;
                } //если нет, то берем максимальную высоту кузова
                while (tempList.Any() & minHeight > 0 & vehicle.MaxLength > 0)
                {
                    int ch2 = vehicle.Blocks.Count();
                    tempList = CreateRow3(tempList, minHeight, vehicle.MaxHeight, vehicle.Width, 0, maxTonnage);
                    if (ch2 == vehicle.Blocks.Count())
                    {
                        minHeight = minHeight - 100;
                    }
                }
                ////////////////////////////////////
                //пытаемся доложить контейнеры сверху на ряды
                /////////////////////////////////////
                wasteList.AddRange(tempList);
            }
            wasteList = fromTempListToContList.ToContainerList(wasteList);
            wasteList = AddOnTopRow(wasteList);

            LoadSmallContainersBySquare(tempSmall, orderList);
            return wasteList;
        }
        private List<Container> CreateVerticalPalletsLevel2(List<Container> containers, int maxHeight)
        {
            FromTempListToContList fromTempListToContList = new FromTempListToContList();
            List<Container> t1 = fromTempListToContList.ToContainerList(containers);
            //используется для контроля потери контейнеров
            //контейнеры которые штабелируются в два яруса и ставятся только на пол
            List<Container> tempOnly4Bottom =
                containers.Where(c => c.Only4Bottom == 2).OrderBy(c => c.ContainerType).ToList();
            List<Container> tempList = containers.Where(c => c.Only4Bottom != 2).ToList();

            int nameCh = 0;

            while (tempOnly4Bottom.Any())
            {
                VerticalBlock vBlock = new VerticalBlock { Kind = "VerticalPallet" };
                nameCh++;
                vBlock.Name = "Связка паллет в 2 яруса №" + nameCh;
                vBlock.Only4Bottom = 2;

                Container firstContainer = tempOnly4Bottom[0];
                List<Container> sameList =
                    tempOnly4Bottom.Where(c => c.ContainerType == firstContainer.ContainerType)
                        .OrderByDescending(c => c.Mass)
                        .ToList();
                tempOnly4Bottom = tempOnly4Bottom.Where(c => c.ContainerType != firstContainer.ContainerType).ToList();

                foreach (Container s in sameList)
                {
                    if (vBlock.Count < 2)
                    {
                        if (vBlock.Add(s, maxHeight) == false)
                        {
                            tempOnly4Bottom.Add(s);
                        }
                    }
                    else
                    {
                        tempOnly4Bottom.Add(s);
                    }
                }
                if (vBlock.Count == 2)
                {
                    vBlock.PressHeight = 0;
                    tempList.Add(vBlock);
                }
                else if (vBlock.Count == 1)
                {
                    tempList.Add(vBlock.Blocks[0]);
                }
            }
            List<Container> t2 = fromTempListToContList.ToContainerList(tempList);
            //используется для контроля потери контейнеров
            if (t1.Count() > t2.Count())
            {
                MessageBox.Show("Ошибка! Потеря контейнеров в процедуре CreateVerticalPalletsLevel2");
            }
            else if (t1.Count() < t2.Count())
            {
                MessageBox.Show("Ошибка! Дублирование контейнеров в процедуре CreateVerticalPalletsLevel2");
            }
            return tempList;
        }
        private List<Container> CreateVerticalPalletsLevel3(List<Container> containers, int length, int width, int height,
           int maxHeight, string prefix)
        {
            FromTempListToContList fromTempListToContList = new FromTempListToContList();
            List<Container> t1 = fromTempListToContList.ToContainerList(containers);
            //используется для контроля потери контейнеров

            List<Container> only4Bottom =
                containers.Where(c => c.Length == length & c.Width == width & c.Height == height)
                    .OrderBy(c => c.Color)
                    .ToList();
            List<Container> tempList =
                containers.Where(c => c.Length != length | c.Width != width | c.Height != height).ToList();
            List<VerticalBlock> vBlocks = new List<VerticalBlock>();
            List<Container> tempList2 = new List<Container>();
            int nameCh = 0;
            while (only4Bottom.Any())
            {
                VerticalBlock vBlock = new VerticalBlock { Kind = "VerticalPallet", PressHeight = 0 };
                List<Container> sameList = only4Bottom.ToList();
                only4Bottom = new List<Container>();
                foreach (Container s in sameList)
                {
                    if (vBlock.Count == 3)
                    {
                        only4Bottom.Add(s);
                    }
                    else if (vBlock.Add(s, maxHeight) == false)
                    {
                        //MessageBox.Show("Не удалось добавить контейнер в связку.Сообщите администратору");
                        tempList2.Add(s);
                    }
                }

                if (vBlock.Count == 1)
                {
                    tempList2.Add(vBlock.Blocks[0]);
                }
                else if (vBlock.Count == 2)
                {
                    nameCh++;
                    vBlock.Name = "Связка паллет в 2 яруса  №" + prefix + nameCh;

                    vBlocks.Add(vBlock);
                }
                else if (vBlock.Count == 3)
                {
                    nameCh++;
                    vBlock.Name = "Связка паллет в 3 яруса  №" + prefix + nameCh;
                    vBlocks.Add(vBlock);
                }
            }
            tempList.AddRange(vBlocks);
            tempList.AddRange(tempList2);

            List<Container> t2 = fromTempListToContList.ToContainerList(tempList);
            //используется для контроля потери контейнеров
            if (t1.Count() != t2.Count())
            {
                MessageBox.Show("Потеря контейнеров в процедуре CreateVerticalPalletsLevel3");
            }
            return tempList;
        }