/// <summary> /// Generates containers and ships sets of data after clicking the button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { var containerService = new ContainerService(); containerService.GenerateContainerSets(new List <int>() { 100, 60, 30 }); var shipService = new ShipService(); shipService.GenerateShipSet(); Controls.Clear(); InitializeComponent(); MessageBox.Show("Data generated succesfully", "Save", MessageBoxButtons.OK); }
/// <summary> /// After clicking the button: /// - Fetches the data from files /// - Optimizes of puts containers on ship creating shipments /// - Draws a visual shipments report /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { Graphics loadingGraphic = CreateGraphics(); ShowLoading(loadingGraphic); ContainerService containerService = new ContainerService(); List <Shipment> shipmentsList = new List <Shipment>(); Shipment shipment; for (int i = 0; i < 2; i++) { List <Shipment> tempShipmentsList = new List <Shipment>(); List <Container> containersLeft = ChooseTheShipAndSendIt(containerService.GetContainersList(), i, out shipment); tempShipmentsList.Add(shipment); while (containersLeft.Count > 0) { containersLeft = ChooseTheShipAndSendIt(containersLeft, i, out shipment); tempShipmentsList.Add(shipment); } if (shipmentsList.Count == 0 || shipmentsList.Count > tempShipmentsList.Count) { shipmentsList = tempShipmentsList; } } ComboBox comboBox1 = new ComboBox(); comboBox1.Location = new System.Drawing.Point((Screen.PrimaryScreen.Bounds.Width / 2) - 100, 20); comboBox1.Name = "comboBox1"; comboBox1.Size = new System.Drawing.Size(200, 50); comboBox1.BackColor = System.Drawing.Color.White; comboBox1.ForeColor = System.Drawing.Color.Black; comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; ComboBox comboBox2 = new ComboBox(); comboBox2.Location = new System.Drawing.Point((Screen.PrimaryScreen.Bounds.Width / 2) - 350, 20); comboBox2.Name = "comboBox1"; comboBox2.Size = new System.Drawing.Size(200, 50); comboBox2.BackColor = System.Drawing.Color.White; comboBox2.ForeColor = System.Drawing.Color.Black; comboBox2.DropDownStyle = ComboBoxStyle.DropDownList; for (int i = 0; i < shipmentsList.Count; i++) { comboBox2.Items.Add("Shipment " + i + ", ShipID: " + shipmentsList[i].GetShip().id); } comboBox2.SelectedIndex = 0; Controls.Add(comboBox2); shipment = shipmentsList.First(); for (int i = 0; i < shipment.GetNoLevels(); i++) { comboBox1.Items.Add("Level " + i); } comboBox1.SelectedIndex = 0; Controls.Add(comboBox1); DrawShipmentLevel(shipment, 0); comboBox1.SelectedIndexChanged += (senderCombo, eCombo) => comboBox1_SelectedIndexChanged(senderCombo, eCombo, shipment); comboBox2.SelectedIndexChanged += (senderCombo2, eCombo2) => comboBox2_SelectedIndexChanged(senderCombo2, eCombo2, shipmentsList, comboBox1, out shipment); DisposeLoading(loadingGraphic); }
/// <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(); }