Okay, to explain this I’ll try to summarise what I’m doing
At some point I create a list of items in a class ‘Supplier’. In this example a list of parts is added to the list of Suppliers that exists in the masterclass.
At some point, I then want to choose a specific part to be added to a job (job class), this part has already been created, I would simply like to take the part and add it to the job.
That part has been added using this:
‘Previous to this, the supplier has been selected’
Class Supplier
public void AddParts( int PartNum, string PartName, string PartDescription, decimal Cost, decimal CostWithVAT, decimal Price, short Quantity)
{
m_partUsed.Add(new Part(PartNum, PartName, PartDescription, Cost, Price, Quantity));
}
Here is how I intend to implement this:
private void btnAddJobPart_Click(object sender, EventArgs e)
{
//Select the job that the part is to be added too
string selectedJob = cboJobPartRef.Text;
List<Job> foundJob = Program.AuspexDo.SelectJob(selectedJob);
//For the job found
foreach (Job j in foundJob)
{
//Select the supplier
string selectedSupplier = cboJobSupplier.Text;
List<Supplier> foundSup = Program.AuspexDo.SelectSupplier(selectedSupplier);
//For the supplier found, find the part to be added
foreach (Supplier s in foundSup)
{
string selectedPart = cboJobParts.Text;
List<Part> foundPart = s.SelectPart(selectedPart);
//Get those part details
//Add those details to the job
j.AddParts //the part item here from the supplier list;
}
}
}
Any help would be appreciated. Thanks.
Why don’t you just change the
AddPartsmethod to (and call itAddPartsince it adds only one part at a time):You can then add a part with
or using an object initializer
or using a constructor
If you prefer to keep your originial implementation you can have two
AddPartmethods side-by-side. This is called method overloading. You can then choose to add a part object or individual part values.You can have as many methods with the same name as you want, as long as their parameter lists differ. Either the number of parameters must be different or the parameter types must be different. The parameter names are not taken into account.