private void OnCartChanged(object sender, CartChangedEventArgs e) { if (CartChanged != null) { CartChanged(this, e); } }
void RefreshCartGUI(object sender, CartChangedEventArgs e) { switch (e.Action) { case CartChangedEventArgs.Reason.Add: bool tableContains = false; int rowIndex = -1; foreach (DataGridViewRow row in dgvCartTable.Rows) { if (row.Cells["colObject"].Value == e.Article) { tableContains = true; rowIndex = row.Index; } } if (!tableContains) dgvCartTable.Rows.Insert(0, e.Article, e.Article.Deposit.Name, cart[e.Article].Count, e.Article.Deposit.AmountString, cart[e.Article].Count * (e.Article.PriceWithDeposit - e.Article.Price), "-", "x"); else { dgvCartTable.Rows.RemoveAt(rowIndex); dgvCartTable.Rows.Insert(0, e.Article, e.Article.Deposit.Name, cart[e.Article].Count, e.Article.Deposit.AmountString, cart[e.Article].Count * (e.Article.PriceWithDeposit - e.Article.Price), "-", "x"); } break; case CartChangedEventArgs.Reason.Remove: foreach (DataGridViewRow row in dgvCartTable.Rows) { if (((Article)row.Cells["colObject"].Value) == e.Article) { dgvCartTable.Rows.Remove(row); break; } } break; case CartChangedEventArgs.Reason.Decrement: foreach (DataGridViewRow row in dgvCartTable.Rows) { Article art = (Article)row.Cells["colObject"].Value; if (art.ArticleID == e.Article.ArticleID) { dgvCartTable.Rows.Remove(row); break; } } dgvCartTable.Rows.Insert(0, e.Article, e.Article.Deposit.Name, cart[e.Article].Count, e.Article.Deposit.Amount, cart[e.Article].Count * (e.Article.PriceWithDeposit - e.Article.Price), "-", "x"); break; case CartChangedEventArgs.Reason.Clear: dgvCartTable.Rows.Clear(); foreach (Article a in primaryProfile.Articles) { a.Button.Count = 0; } break; } if (printDevice.PrintStatus == PrintStatus.Printing) btnPrint.Enabled = false; else btnPrint.Enabled = cart.Count > 0; btnReset.Enabled = btnPrint.Enabled; txtTotalSum.Text = string.Format("{0:0.00}", cart.AmountWithDeposit); }
private void CartChanged(object sender, CartChangedEventArgs e) { if (cart.Contains(article)) this.Count = cart[article].Count; else this.Count = 0; }