private void _statsByItemBackground_DoWork(object sender, DoWorkEventArgs e) { if (_bills != null) { foreach (Bill b in _bills) { foreach (Item i in b.Items) { using (StatsByItems statItem = _statsByItemsList.FirstOrDefault(x => x.Item.Id == i.Id)) { if (statItem != null) { statItem.Quantity++; statItem.Total += (int)(i.SalingPrice * (100 - b.DiscountRate)); } else { _statsByItemsList.Add(new StatsByItems { Item = i, Quantity = 1, Total = i.SalingPrice }); } } } } } }
private void _backgroundShowStats_DoWork(object sender, DoWorkEventArgs e) { DateTime fromDate = _dpickerFrom.Value; DateTime toDate = _dpickerTo.Value; List <Bill> bills = _billBo.GetBills(fromDate, toDate); if (bills != null) { foreach (Bill b in bills) { foreach (Item i in b.Items) { using (StatsByItems statItem = _statsItemList.FirstOrDefault(x => x.Item.Id == i.Id)) { if (statItem != null) { statItem.Quantity++; statItem.Total += (int)(i.SalingPrice * (100 - b.DiscountRate) / 100.0); } else { _statsItemList.Add(new StatsByItems { Item = i, Quantity = 1, Total = i.SalingPrice }); } } } } } }