C# Need help How can I allow for synchronization of multiple related list objects?

Sn0wb0yE

Coder
Sep 14, 2019
4
2
13
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:

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:

disdatasample.png

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:
  • Like
Reactions: TableFlipGod

Crow

Active Coder
Sep 7, 2019
119
16
28
I'm not a C# Programmer and I do not know anything about the Language.

But, I can point you to @TableFlipGod. He's good with C# and he could probably help you with this.
 
  • Like
Reactions: Sn0wb0yE

TableFlipGod

Active Coder
May 13, 2019
126
25
29
14
w
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:

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:

View attachment 195

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
Can you elaborate a little bit more on what you get vs what you expect to happen? Because I can’t seem to see what you’re talking about. (Im really bad when it comes to logic and whatnot)
 

Sn0wb0yE

Coder
Sep 14, 2019
4
2
13
Hi @TableFlipGod,

Thanks for replying to my thread and please accept my apologies for doing a poor job at explaining my application.

To answer your question, at the moment, I can only create a shipment and add containers to it.

What I can't get working is the adding of packages to each container despite having a list for them inside my container class. I thought that I would have access to my container packing from there without having to initialize that separately.

My thoughts were that whenever I add a new container to a shipment, a new list to hold all the packages is created for it, but it turns out to be more complex than that because a shipment can have multiple containers and thus multiple lists packing details. The relationship between shipment container and container package is key here.

You follow?
 

TableFlipGod

Active Coder
May 13, 2019
126
25
29
14
Hi @TableFlipGod,

Thanks for replying to my thread and please accept my apologies for doing a poor job at explaining my application.

To answer your question, at the moment, I can only create a shipment and add containers to it.

What I can't get working is the adding of packages to each container despite having a list for them inside my container class. I thought that I would have access to my container packing from there without having to initialize that separately.

My thoughts were that whenever I add a new container to a shipment, a new list to hold all the packages is created for it, but it turns out to be more complex than that because a shipment can have multiple containers and thus multiple lists packing details. The relationship between shipment container and container package is key here.

You follow?
Just to confirm, I have terrible understanding of logic and im very very sorry if im not helping or im confusing you. You kind of want it to be in like a tree organisation for each shipment -> container -> product in container.


Can you possibly draw what you want in like a small diagram?

Maybe add a seperate tree of visuals?

I have a low IQ.
 

TableFlipGod

Active Coder
May 13, 2019
126
25
29
14
Hi @TableFlipGod,

Thanks for replying to my thread and please accept my apologies for doing a poor job at explaining my application.

To answer your question, at the moment, I can only create a shipment and add containers to it.

What I can't get working is the adding of packages to each container despite having a list for them inside my container class. I thought that I would have access to my container packing from there without having to initialize that separately.

My thoughts were that whenever I add a new container to a shipment, a new list to hold all the packages is created for it, but it turns out to be more complex than that because a shipment can have multiple containers and thus multiple lists packing details. The relationship between shipment container and container package is key here.

You follow?
And again im sorry if im unable to help. As i am also learning c# along with being a freshmen in HS.