.net 集合去除重复数据,数量累加,生成新的集合

List<JE_PartInventoryTran> listtran = new List<JE_PartInventoryTran>();

foreach (DataGridViewRow item in dataGridView10.Rows)
{

JM_LabelList ll = new JM_LabelList();
JE_PartInventoryTran tran = new JE_PartInventoryTran();
ll.StayLocation = Convert.ToString(item.Cells["NSPNo3"].Value);
ll.LabelNo = Convert.ToString(item.Cells["LabelNo3"].Value);
string stat = Convert.ToString(item.Cells["LabelStatus3"].Value);
if (stat== "无效的标签")
{
MessageBox.Show("包含无效标签,请检查后删除","Waring",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
tran.FromSPNo = Convert.ToString(item.Cells["SPNo3"].Value);
tran.SPNo = Convert.ToString(item.Cells["NSPNo3"].Value);
if (tran.SPNo=="" || tran.SPNo==null) { MessageBox.Show("仓位为空,无法保存", "Waring", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
tran.PartNo= Convert.ToString(item.Cells["PartNo3"].Value);
tran.PkgCode= Convert.ToInt32(item.Cells["PkgCode3"].Value);
decimal puno= Convert.ToDecimal(item.Cells["PUNo3"].Value);
tran.StockQty = Convert.ToDecimal(item.Cells["Qty3"].Value);
tran.PkgQty = Convert.ToDecimal(tran.StockQty / puno);
tran.Status = 3;
tran.SubmitBy = BaseInfo.CurrentUser.appInfo.APLAccount;
list.Add(ll);
if (listtran.Exists(p=>p.PartNo==tran.PartNo&&p.FromSPNo==tran.FromSPNo&&p.SPNo==tran.SPNo ))
{
for (int i = 0; i < listtran.Count; i++)
{
if (listtran[i].PartNo==tran.PartNo&& listtran[i].FromSPNo == tran.FromSPNo&&listtran[i].SPNo == tran.SPNo)
{
listtran[i].StockQty =listtran[i].StockQty+ tran.StockQty;
}
}
}
else
{
//sum = sum + Convert.ToDecimal(tran.StockQty);
tran.RefNo = FormCommon.GatePassNo("615", "RFN");//生成单号
listtran.Add(tran);
}

}

猜你喜欢

转载自www.cnblogs.com/xiaomihu-0001/p/11315262.html
net