private void Add2List(MenuItemForTag item, bool AtFirst) { if (item.No == 0) { Sub2List(item); return; } ListViewItem lvItem = FindByProductID(item.productID); double no = item.No; double money = item.Money(); if (lvItem != null) { lvItem.SubItems[2].Text = no.ToString(); lvItem.SubItems[3].Text = money.ToString();; } else { if (item.classcode != MyConstant.CanDiscountClass) { if (AtFirst) { lvItem = lvNoDiscount.Items.Insert(0, item.productID.ToString()); } else { lvItem = lvNoDiscount.Items.Add(item.productID.ToString()); } } else { if (AtFirst) { lvItem = lvCanDiscount.Items.Insert(0, item.productID.ToString()); } else { lvItem = lvCanDiscount.Items.Add(item.productID.ToString()); } } lvItem.SubItems.Add(item.name); lvItem.SubItems.Add(no.ToString()); lvItem.SubItems.Add(money.ToString()); } lvItem.Tag = item; CalcTotal(); }
// ListView的tag 指向MenuItem private bool Sub2List(MenuItemForTag item) { ListViewItem lvItem = FindByProductID(item.productID); if (lvItem == null) { return(false); // 沒東西刪 } if (item.No > 0) { lvItem.SubItems[2].Text = item.NoToString(); lvItem.SubItems[3].Text = item.Money().ToString(); } else { lvItem.Remove(); } CalcTotal(); return(true); // 刪除成功 }
private double CalcTotal() { double total = 0; double no = 0, sum = 0; foreach (ListViewItem lvItem in lvNoDiscount.Items) { MenuItemForTag item = (MenuItemForTag)lvItem.Tag; sum += item.Money(); no += item.No; } sum = Math.Round(sum, 1); lvNoDiscount.Columns[2].Text = no.ToString(); lvNoDiscount.Columns[3].Text = sum.ToString(); total = sum; sum = no = 0; foreach (ListViewItem lvItem in lvCanDiscount.Items) { MenuItemForTag item = (MenuItemForTag)lvItem.Tag; sum += item.Money(); no += item.No; } if (checkDiscount.Checked) { sum = sum * 0.88; } sum = Math.Round(sum, 0, MidpointRounding.AwayFromZero); // sum = Math.Round(sum, 1); 銀行家捨入 lvCanDiscount.Columns[2].Text = no.ToString(); lvCanDiscount.Columns[3].Text = sum.ToString(); total += sum; if (mtbDeduct.Text != "") { int deduct = Int32.Parse(mtbDeduct.Text); total -= deduct; } total = Math.Round(total, 0, MidpointRounding.AwayFromZero); labelTotal.Text = total.ToString(); return(total); }