Sn0wb0yE
New Coder
Hi folks,
Recently joined and this is my first post here.
I am creating a small shipment container packing tool and am having some difficulty getting it to store and keep track of the packages added to each of the containers.
To provide some further context, following is a general application usage summary together with some use-case data based on a sample shipment with two containers and five separate packing entries:
Shipment Creation
- User creates a shipment. Shipment ID generated. User can only work on one shipment at a time.
Container Selection / Addition
- User selects from a list of predefined containers to pack into and adds one or more containers to the shipment. Shipment Container ID is generated. Shipment can contain any number of containers.
Container Packing
- User selects any of the added containers and adds packing quantities. A Package ID is generated for each packing entry. Container can contain any number of packages.
Following is my current source:
Following is a sample of my use-case data:
At this time, I can create a shipment, add any number of containers to a shipment, and print them out. Where I am stuck is getting the packing entries aligned with each container. For example, referencing the above data, my application should be able to list out all the packages that were packed into CONTAINER # 1 only.
Console code:
How can I modify my code to allow for adding and tracking of the packages attached to each container in a shipment without losing anything?
I would greatly appreciate any and all the help I can get on this. Please feel free to reach out with any questions you may have about my project.
Sn0wb0yE
Recently joined and this is my first post here.
I am creating a small shipment container packing tool and am having some difficulty getting it to store and keep track of the packages added to each of the containers.
To provide some further context, following is a general application usage summary together with some use-case data based on a sample shipment with two containers and five separate packing entries:
Shipment Creation
- User creates a shipment. Shipment ID generated. User can only work on one shipment at a time.
Container Selection / Addition
- User selects from a list of predefined containers to pack into and adds one or more containers to the shipment. Shipment Container ID is generated. Shipment can contain any number of containers.
Container Packing
- User selects any of the added containers and adds packing quantities. A Package ID is generated for each packing entry. Container can contain any number of packages.
Following is my current source:
Code:
// A class that defines a shipment
public class Shipment
{
public int ShipmentID { get; set; }
public string ShipmentName { get; set; }
public int ContainerCount { get; }
public int PackageCount { get; }
public List<ShipmentContainer> Containers { get; } = new List<ShipmentContainer>();
public Shipment(int shipmentID, string shipmentName)
{
ShipmentID = shipmentID;
ShipmentName = shipmentName;
}
public void AddNewContainerToShipment(int containerID, int shipmentContainerID, string description, double weightCapacity)
{
Containers.Add(new ShipmentContainer()
{
ShipmentID = this.ShipmentID,
ContainerID = containerID,
ShipmentContainerID = shipmentContainerID,
Description = description,
CapacityWeight = weightCapacity
});
}
}
// A class for containers belonging to a shipment
public class ShipmentContainer
{
public int ShipmentID { get; set; }
public int ContainerID { get; set; }
public int ShipmentContainerID { get; set; }
public string Description { get; set; }
public double PackageLineCount { get; set; }
public int PackageCount { get; set; }
public double PackingWeight { get; set; }
public List<ContainerPackage> Packages { get; } = new List<ContainerPackage>();
public ShipmentContainer()
{
}
}
// A class for packages belonging to a container in a shipment
public class ContainerPackage
{
public int ShipmentContainerID { get; set; }
public int PackageID { get; set; }
public string Description { get; set; }
public double PackageWeight { get; set; }
public int PackingQuantity { get; set; }
public double PackingWeight { get { return (PackageWeight * PackingQuantity); } }
public ContainerPackage()
{
}
}
Following is a sample of my use-case data:
At this time, I can create a shipment, add any number of containers to a shipment, and print them out. Where I am stuck is getting the packing entries aligned with each container. For example, referencing the above data, my application should be able to list out all the packages that were packed into CONTAINER # 1 only.
Console code:
Code:
public class Program
{
private static void Main(string[] args)
{
// Create a new shipment, assign the ID for now
Shipment s = new Shipment(1, "TEST SHIPMENT - VORTEX MALAYSIA");
// Add two containers to the shipment. Assign the ID's for now.
s.AddNewContainerToShipment(1, 1, "20FT GENERAL PURPOSE", 23400);
s.AddNewContainerToShipment(1, 2, "40FT GENERAL PURPOSE", 25000);
// List out the containers inside the shipment.
DisplayContainersInShipment(s.Containers.ToList(), s.ShipmentName);
}
// Writes out the containers inside a shipment.
private static void DisplayContainersInShipment(List<ShipmentContainer> results, string shipmentName)
{
Console.WriteLine();
Console.WriteLine("Containers in shipment report for : " + shipmentName);
foreach (ShipmentContainer b in results)
{
Console.Write("\n{0}\t{1}\t{2}\t{3}", b.ContainerID,
b.Description, b.CapacityWeight, b.ContainerWeight);
}
Console.WriteLine();
}
}
How can I modify my code to allow for adding and tracking of the packages attached to each container in a shipment without losing anything?
I would greatly appreciate any and all the help I can get on this. Please feel free to reach out with any questions you may have about my project.
Sn0wb0yE
Last edited: