我被捆綁在需要編寫的部分代碼上。 我得到了一個xml文件,我必須導入並重寫,以便我可以在datagridview中顯示我需要的內容。這完全是基於一類發票:c#linq分割列表按實體值分爲兩部分
public class Invoice
{
public bool import { get; set; }
public string InvoiceNbr { get; set; }
public string AltInvoiceNbr { get; set; }
public string CustomerNbr { get; set; }
public string AltCustomerNbr { get; set; }
public DateTime InvoiceDate { get; set; }
public string Amount { get; set; }
public string FreightAmount { get; set; }
public string InsuranceAmount { get; set; }
public string TaxAmount { get; set; }
public string TaxFreightAmount { get; set; }
public int PrintSeq { get; set; }
}
內的importfile有對invoicenbr多個條目。 (每個發票行一個) 所以我做了一個分組和以下聲明。
invoices = invoices.GroupBy(i => new
{
i.InvoiceNbr,
i.AltInvoiceNbr,
i.CCN,
i.CustomerNbr,
i.AltCustomerNbr,
i.InvoiceDate,
i.PrintSeq
}).Select(i => new Invoice()
{
InvoiceNbr = i.Key.InvoiceNbr,
AltInvoiceNbr = i.Key.AltInvoiceNbr,
CCN = i.Key.CCN,
CustomerNbr = i.Key.CustomerNbr,
AltCustomerNbr = i.Key.AltCustomerNbr,
InvoiceDate = i.Key.InvoiceDate,
Amount = i.Sum(x => decimal.Parse(x.Amount)).ToString("F"),
FreightAmount = i.Sum(x => decimal.Parse(x.FreightAmount)).ToString("F"),
InsuranceAmount = i.Sum(x => decimal.Parse(x.InsuranceAmount)).ToString("F"),
TaxAmount = i.Sum(x => decimal.Parse(x.TaxAmount)).ToString("F"),
TaxFreightAmount = i.Sum(x => decimal.Parse(x.TaxFreightAmount)).ToString("F"),
PrintSeq = i.Key.PrintSeq
}).ToList();
所以輸出在datagridview中看起來不錯。現在有一些行,例如對於發票號碼出現兩次或更多次的信用(或部分出貨)。在這種情況下,PrintSeq> 1。
我需要過濾掉這些數據。
例如對於一個信貸有兩個條目。 One with InvoiceNbr 20160420-1 with a amount of 50 $ and other with the InvoiceNbr with-amount -50 $。
的printSeq爲+ 50 $的發票是1 的printSeq爲-50 $發票是2
我試着用
.Where(x=>x.PrintSeq = 1)
過濾,但在這種情況下,一個項目停留在輸出。
如果我使用
.Where(x=>x.PrintSeq != 1)
我得到一個列表,它顯示了,我不想在輸出中顯示InvoiceNbrs。
因此,我現在正在搜索使用該列表的可能性,以便用Lambda表達式過濾掉原始輸出上的所有invoiceNbrs。
我不要使用外部庫等 (distinctby) 我試圖通過原始列表上使用不同的(選擇發票 其中originallist.invoicenbr IS NOT filterlist.invoicenbr *)首先使用嵌套組,但似乎不是正確的方法。
請幫