//Logic to split orders public void SplitOrderEvenly(List <Bill> billsAffected, BillItemControl bic) { int numberOfBills = 1 + billsAffected.Count; //Calculate the prices of an even split between affected parties List <double> prices = calculatePrices(bic.itemPrice, numberOfBills); //This loop looks for items inside existing bills or creates new bills bic.ChangePrice(prices[0]); int index = 1; foreach (Bill bill in billsAffected) { BillItemControl associatedBIC = bill.GetRespectiveItem(this); if (associatedBIC == null) { //New Bill must create it //Must retain properties of old bill item associatedBIC = new BillItemControl(this, prices[index]); if (bic.itemSent) { associatedBIC.itemSent = true; associatedBIC.CancelButton.Visibility = System.Windows.Visibility.Hidden; SolidColorBrush mySolidColorBrush = new SolidColorBrush(); mySolidColorBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#7F7F7F")); associatedBIC.BackgroundColor.Fill = mySolidColorBrush; } viewList.Add(associatedBIC); associatedBIC.Deleted += new EventHandler <BICEventArgs>(HandleViewDeletion); bill.AddExistingItem(associatedBIC); } else { //If it is not a new bill then the price is the old price + new price split into it associatedBIC.ChangePrice(prices[index] + associatedBIC.itemPrice); } index++; } }
//Combines two seperate BillItemControls // *** TO BE USED ONLY ON BILLITEMCONTROLS WITHIN THE SAME BILLLOGIC *** public void Combine(BillItemControl combined, BillItemControl destroyed) { combined.ChangePrice(combined.itemPrice + destroyed.itemPrice); //Destroy the second item destroyed.ChangePrice(0); }