/// <summary> /// Determines which ship will be the best choice to send containers in. /// </summary> /// <param name="containersList"></param> /// <param name="algorithm"></param> /// <param name="shipment"></param> /// <returns>List of containers the haven't been sent yet.</returns> private List <Container> ChooseTheShipAndSendIt(List <Container> containersList, int algorithm, out Shipment shipment) { var containerHeight = containersList.First().height; List <Container> containersLeft = new List <Container>(); List <Ship> shipsList = new ShipService().GetShipsList(); var bestShipId = 0; var prevContainersCount = Int32.MaxValue; foreach (var item in shipsList) { shipment = new Shipment(item.id, containerHeight); containersLeft = shipment.FillTheShip(containersList, algorithm); if (containersLeft.Count < prevContainersCount) { bestShipId = item.id; prevContainersCount = containersLeft.Count; } } shipment = new Shipment(bestShipId, containerHeight); containersLeft = shipment.FillTheShip(containersList, algorithm); return(containersLeft); }
/// <summary> /// Refreshes the shipment visual representation after changing shipment combobox selection. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="shipmentsList"></param> /// <param name="combobox"></param> /// <param name="shipment"></param> private void comboBox2_SelectedIndexChanged(object sender, EventArgs e, List <Shipment> shipmentsList, ComboBox combobox, out Shipment shipment) { shipment = shipmentsList[(sender as ComboBox).SelectedIndex]; combobox.Items.Clear(); for (int i = 0; i < shipment.GetNoLevels(); i++) { combobox.Items.Add("Level " + i); } if (combobox.SelectedIndex == 0) { DrawShipmentLevel(shipment, combobox.SelectedIndex); } else { combobox.SelectedIndex = 0; } }
/// <summary> /// Draws the visual representation of containers for particular shipment and level. /// </summary> /// <param name="shipment"></param> /// <param name="level"></param> private void DrawShipmentLevel(Shipment shipment, int level) { Refresh(); var table = shipment.GetSpaceArrayForLevel(level); var constX = (Screen.PrimaryScreen.Bounds.Width - 40) / table.GetLength(0); var constY = (Screen.PrimaryScreen.Bounds.Height - 140) / table.GetLength(1); var wholeRectanglePositionX = Screen.PrimaryScreen.Bounds.Width / 2 - constX * table.GetLength(0) / 2; var wholeRectanglePositionY = Screen.PrimaryScreen.Bounds.Height / 2 - constY * table.GetLength(1) / 2; Graphics formGraphics = CreateGraphics(); formGraphics.DrawRectangle(new Pen(Color.Black), new Rectangle(wholeRectanglePositionX, wholeRectanglePositionY, table.GetLength(0) * constX, table.GetLength(1) * constY)); for (int i = 0; i < table.GetLength(0); i++) { for (int j = 0; j < table.GetLength(1); j++) { if (table[i, j] == true) { formGraphics.FillRectangle(new SolidBrush(Color.Green), new Rectangle(wholeRectanglePositionX + i * constX, wholeRectanglePositionY + j * constY, constX, constY)); } else { formGraphics.FillRectangle(new SolidBrush(Color.Brown), new Rectangle(wholeRectanglePositionX + i * constX, wholeRectanglePositionY + j * constY, constX, constY)); } } } foreach (var item in shipment.GetContainerLocations().FindAll(x => x.level == level)) { var container = new ContainerService().GetContainerById(item.containerId); int containerXSize, containerYSize; if (item.orientation == true) { containerXSize = container.length; containerYSize = container.width; } else { containerXSize = container.width; containerYSize = container.length; } var xPos = wholeRectanglePositionX + item.xPosition * constX; var yPos = wholeRectanglePositionY + item.yPosition * constY; var xSize = containerXSize * constX; var ySize = containerYSize * constY; var fontSize = 14; var rect1 = new Rectangle(xPos, yPos, xSize, ySize); formGraphics.DrawRectangle(new Pen(Color.Black), rect1); if (containerYSize < 2) { fontSize = 5; } else if (containerXSize < 3 || containerYSize < 4) { fontSize = 10; } StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; formGraphics.DrawString("C" + container.id, new Font("Arial", fontSize, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, rect1, format); } formGraphics.Dispose(); }
/// <summary> /// Refreshes the level visual representation after changing level combobox selection. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="shipment"></param> private void comboBox1_SelectedIndexChanged(object sender, EventArgs e, Shipment shipment) { DrawShipmentLevel(shipment, (sender as ComboBox).SelectedIndex); }