【发布时间】:2012-10-30 15:52:55
【问题描述】:
好的,为了解释这一点,我将尝试总结一下我在做什么
有时我会在“供应商”类中创建一个项目列表。在此示例中,将零件列表添加到主类中存在的供应商列表中。
然后,我想选择一个特定的部分添加到作业(作业类),这个部分已经创建,我只是想把它添加到作业中。
该部分已使用以下内容添加: '在此之前,供应商已被选中'
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));
}
这是我打算如何实现的:
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;
}
}
}
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
那么,问题到底是什么?
-
那么什么不起作用?这个问题的哪一方面你不知道怎么办?您当前的解决方案距离解决问题有多近?
-
不太清楚这里要问什么...您在实现此代码时遇到任何问题吗?
-
我不知道你的代码打算做什么,但每次在 foreach 中分配给
foundSup和foundPart对我来说都是错误的。 -
不确定我是否理解您要执行的操作(如果不查看代码,很难理解供应商列表中的部件项目是什么),但看起来您可以对所有供应商执行一些 SelectMany零件和 AddRange。