private void ShowStackInfo() { Lbx_StackContainers.Items.Clear(); int stackId = Convert.ToInt32(DGV_Stacks.CurrentCell.Value.ToString().Split(';')[0]); Stack stacko = _cargoShip.FindStackWithId(stackId); foreach (var conto in stacko.Containers) { Lbx_StackContainers.Items.Add(conto); } stacko.CalcStackWeight(); Lbl_StackWeight.Text = "Stack Weight: " + stacko.StackWeight; }
private void RefreshListsCargoShip() { Lbx_StackContainers.Items.Clear(); if (Lbx_CargoShips.SelectedIndex != -1) { if (DGV_Stacks.DataSource != null) { DGV_Stacks.DataSource = null; } _cargoShip = Lbx_CargoShips.SelectedItem as CargoShip; DataTable dt = new DataTable(); DGV_Stacks.DataSource = dt; for (int j = 0; j < _cargoShip.Width; j++) { dt.Columns.Add("Column: " + j); } int counter = 0; for (int currentRow = 0; currentRow < _cargoShip.Length; currentRow++) { DataRow dr = dt.NewRow(); for (int currentColumn = 0; currentColumn < _cargoShip.Width; currentColumn++) { int amountContainers = 0; if (_cargoShip.Stacks[counter].Containers != null) { amountContainers = _cargoShip.Stacks[counter].Containers.Count; } int stackId = _cargoShip.Stacks[counter].StackID; Stack stock = _cargoShip.FindStackWithId(stackId); stock.CalcStackWeight(); Lbl_StackWeight.Text = "Stack Weight: " + stock.StackWeight; dr[currentColumn] = stackId + "; Cont:" + amountContainers + " Cool:" + stock.HasCooling; counter++; } dt.Rows.Add(dr); } } }
private void Btn_AddContainerToStack_Click(object sender, EventArgs e) { if (Lbx_CargoShips.SelectedIndex != -1 && Lbx_Containers.SelectedIndex != -1) { Lbx_StackContainers.Items.Clear(); int stackId = Convert.ToInt32(DGV_Stacks.CurrentCell.Value.ToString().Split(';')[0]); _cargoShip = Lbx_CargoShips.SelectedItem as CargoShip; Stack selectedStack = _cargoShip.FindStackWithId(stackId); Container selectedContainer = Lbx_Containers.SelectedItem as Container; if (selectedStack.CanContainerBeAddedToStack()) { selectedStack.AddContainer(selectedContainer); } else { MessageBox.Show("Can't add the container to this stack"); } foreach (var conto in selectedStack.Containers) { Lbx_StackContainers.Items.Add(conto); } _dock.AllContainers.Remove(Lbx_Containers.SelectedItems[0] as Container); Lbx_Containers.Items.Remove(Lbx_Containers.SelectedItems[0]); UpdateCargoShipStats(); RefreshListsCargoShip(); ShowStackInfo(); } else { MessageBox.Show("Select a CargoShip and a Container!"); } }