private void button1_Click(object sender, EventArgs e)
{
dataGridView2.Visible = true;
List<ProductList> _product = new List<ProductList>();
int Count = 1;
foreach (DataGridViewRow row in dataGridView1APen.Rows)
{
if (row.Cells[0].Value != "" && row.Cells[0].Value != null)
{
if (_product.Where(x => x.SoinikNo.ToLower() == row.Cells[0].Value.ToString().ToLower()).Any())
{
string Utsob = (Convert.ToInt32(_product.Where(x => x.SoinikNo.ToLower() == row.Cells[0].Value.ToString().ToLower()).Select(x => x.Utsob).FirstOrDefault()) + Convert.ToInt32(row.Cells[13].Value.ToString())).ToString();
string Pension = (Convert.ToInt32(_product.Where(x => x.SoinikNo.ToLower() == row.Cells[0].Value.ToString().ToLower()).Select(x => x.Pension).FirstOrDefault()) + Convert.ToInt32(row.Cells[12].Value.ToString())).ToString();
_product.Where(x => x.SoinikNo.ToLower() == row.Cells[0].Value.ToString().ToLower()).ToList().ForEach(x => { x.Utsob = Utsob; x.Pension = Pension; });
}
else
{
_product.Add(new ProductList
{
Sno = Count,
SoinikNo = row.Cells[2].Value.ToString(),
APenName = row.Cells[3].Value.ToString(),
Pension = row.Cells[12].Value.ToString(),
Utsob = row.Cells[13].Value.ToString()
});
Count++;
}
}
dataGridView2.DataSource = _product;
}
}
}