Exemple #1
0
        private void tsUndoNuyenExpense_Click(object sender, EventArgs e)
        {
            ListViewItem objItem = new ListViewItem();

            try
            {
                objItem = lstNuyen.SelectedItems[0];
            }
            catch
            {
                return;
            }

            CommonFunctions objCommon = new CommonFunctions(_objCharacter);

            ExpenseLogEntry objEntry = new ExpenseLogEntry();
            objItem = lstNuyen.SelectedItems[0];

            // Find the selected Nuyen Expense.
            foreach (ExpenseLogEntry objCharacterEntry in _objCharacter.ExpenseEntries)
            {
                if (objCharacterEntry.InternalId == objItem.SubItems[3].Text)
                {
                    objEntry = objCharacterEntry;
                    break;
                }
            }

            if (objEntry.Undo == null)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoNoHistory"), LanguageManager.Instance.GetString("MessageTitle_NoUndoHistory"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (objEntry.Undo.KarmaType == KarmaExpenseType.ImproveInitiateGrade)
            {
                // Get the grade of the item we're undoing and make sure it's the highest grade
                int intMaxGrade = 0;
                foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades)
                {
                    intMaxGrade = Math.Max(intMaxGrade, objGrade.Grade);
                }
                foreach (InitiationGrade objGrade in _objCharacter.InitiationGrades)
                {
                    if (objGrade.InternalId == objEntry.Undo.ObjectId)
                    {
                        if (objGrade.Grade < intMaxGrade)
                        {
                            MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoNotHighestGrade"), LanguageManager.Instance.GetString("MessageTitle_NotHighestGrade"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        break;
                    }
                }
                if (MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoExpense"), LanguageManager.Instance.GetString("MessageTitle_UndoExpense"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    return;
            }
            else
            {
                if (MessageBox.Show(LanguageManager.Instance.GetString("Message_UndoExpense"), LanguageManager.Instance.GetString("MessageTitle_UndoExpense"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    return;
            }

            switch (objEntry.Undo.NuyenType)
            {
                case NuyenExpenseType.AddCyberware:
                    // Locate the Cyberware that was added.
                    int intOldPenalty = 0;
                    int intNewPenalty = 0;
                    foreach (Cyberware objCyberware in _objCharacter.Cyberware)
                    {
                        if (objCyberware.InternalId == objEntry.Undo.ObjectId)
                        {
                            foreach (Cyberware objChild in objCyberware.Children)
                            {
                                // Remove the Improvements created by child items.
                                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Cyberware, objChild.InternalId);
                                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Bioware, objChild.InternalId);
                            }
                            // Remove the Improvements created by the item.
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Cyberware, objCyberware.InternalId);
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Bioware, objCyberware.InternalId);

                            // Determine the character's Essence penalty before removing the Cyberware.
                            intOldPenalty = _objCharacter.EssencePenalty;
                            // Remove the Cyberware.
                            _objCharacter.Cyberware.Remove(objCyberware);
                            // Determine the character's Essence penalty after removing the Cyberware.
                            intNewPenalty = _objCharacter.EssencePenalty;

                            // Restore the character's MAG/RES if they have it.
                            //if (!_objCharacter.OverrideSpecialAttributeEssenceLoss && !_objCharacter.OverrideSpecialAttributeEssenceLoss)
                            //{
                            //    if (intOldPenalty != intNewPenalty)
                            //    {
                            //        if (_objCharacter.MAGEnabled)
                            //            _objCharacter.MAG.Value += (intOldPenalty - intNewPenalty);
                            //        if (_objCharacter.RESEnabled)
                            //            _objCharacter.RES.Value += (intOldPenalty - intNewPenalty);
                            //    }
                            //}

                            // Remove the item from the Tree.
                            foreach (TreeNode objNode in treCyberware.Nodes[0].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }
                            foreach (TreeNode objNode in treCyberware.Nodes[1].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }

                            // Remove any Weapon that the Cyberware created.
                            if (objCyberware.WeaponID != Guid.Empty.ToString())
                            {
                                foreach (Weapon objWeapon in _objCharacter.Weapons)
                                {
                                    if (objWeapon.InternalId == objCyberware.WeaponID)
                                    {
                                        _objCharacter.Weapons.Remove(objWeapon);
                                        break;
                                    }
                                }

                                // Remove the TreeNode for the Weapon.
                                foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                {
                                    if (objWeaponNode.Tag.ToString() == objCyberware.WeaponID)
                                    {
                                        treWeapons.Nodes[0].Nodes.Remove(objWeaponNode);
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                        else
                        {
                            foreach (Cyberware objChild in objCyberware.Children)
                            {
                                if (objChild.InternalId == objEntry.Undo.ObjectId)
                                {
                                    // Remove the Improvements created by the item.
                                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Cyberware, objChild.InternalId);
                                    objCyberware.Children.Remove(objChild);

                                    // Remove the item from the Tree.
                                    foreach (TreeNode objNode in treCyberware.Nodes[0].Nodes)
                                    {
                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                        {
                                            if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                            {
                                                objChildNode.Remove();
                                                break;
                                            }
                                        }
                                    }
                                    foreach (TreeNode objNode in treCyberware.Nodes[1].Nodes)
                                    {
                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                        {
                                            if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                            {
                                                objNode.Remove();
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }

                                // Remove any Weapon that the Cyberware created.
                                if (objChild.WeaponID != Guid.Empty.ToString())
                                {
                                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                                    {
                                        if (objWeapon.InternalId == objChild.WeaponID)
                                        {
                                            _objCharacter.Weapons.Remove(objWeapon);
                                            break;
                                        }
                                    }

                                    // Remove the TreeNode for the Weapon.
                                    foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                    {
                                        if (objWeaponNode.Tag.ToString() == objChild.WeaponID)
                                        {
                                            treWeapons.Nodes[0].Nodes.Remove(objWeaponNode);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddGear:
                    // Locate the Gear that was added.
                    //If the gear was already deleted manually we will not be able to locate it here
                    Gear objGear = objCommon.FindGear(objEntry.Undo.ObjectId, _objCharacter.Gear);
                    if (objGear == null)
                        break;
                    objGear.Quantity -= objEntry.Undo.Qty;

                    if (objGear.Quantity <= 0)
                    {
                        if (objGear.Parent != null)
                            objGear.Parent.Children.Remove(objGear);
                        else
                            _objCharacter.Gear.Remove(objGear);

                        objCommon.DeleteGear(objGear, treWeapons, _objImprovementManager);
                        TreeNode objNode = objCommon.FindNode(objGear.InternalId, treGear);
                        objNode.Remove();
                    }
                    else
                    {
                        TreeNode objNode = objCommon.FindNode(objGear.InternalId, treGear);
                        objNode.Text = objGear.DisplayName;
                    }

                    _objController.PopulateFocusList(treFoci);
                    break;
                case NuyenExpenseType.AddVehicle:
                    // Locate the Vehicle that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        if (objVehicle.InternalId == objEntry.Undo.ObjectId)
                        {
                            // Remove the Vehicle.
                            _objCharacter.Vehicles.Remove(objVehicle);
                            foreach (TreeNode objNode in treVehicles.Nodes[0].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleMod:
                    // Locate the Vehicle Mod that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            if (objMod.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Check for Improved Sensor bonus.
                                if (objMod.Bonus != null)
                                {
                                    if (objMod.Bonus["improvesensor"] != null)
                                    {
                                        ChangeVehicleSensor(objVehicle, false);
                                    }
                                }

                                // Remove the Vehicle Mod.
                                objVehicle.Mods.Remove(objMod);

                                // Remove the Vehicle Mod from the tree.
                                foreach (TreeNode objNode in treVehicles.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objChild in objNode.Nodes)
                                    {
                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objChild.Remove();
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleGear:
                    // Locate the Gear that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (Gear objVehicleGear in objVehicle.Gear)
                        {
                            if (objVehicleGear.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Deduct the Qty from the Gear.
                                objVehicleGear.Quantity -= objEntry.Undo.Qty;
                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objNode in objVNode.Nodes)
                                    {
                                        if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objNode.Text = objVehicleGear.DisplayName;
                                            // Remove the Node if its Qty has been reduced to 0.
                                            if (objVehicleGear.Quantity <= 0)
                                                objNode.Remove();
                                            break;
                                        }
                                    }
                                }

                                // Remove the Gear if its Qty has been reduced to 0.
                                if (objVehicleGear.Quantity <= 0)
                                {
                                    objVehicle.Gear.Remove(objVehicleGear);
                                }

                                break;
                            }
                            else
                            {
                                // Look in child items.
                                foreach (Gear objChild in objVehicleGear.Children)
                                {
                                    if (objChild.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Deduct the Qty from the Gear.
                                        objChild.Quantity -= objEntry.Undo.Qty;
                                        foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objVNode.Nodes)
                                            {
                                                foreach (TreeNode objChildNode in objNode.Nodes)
                                                {
                                                    if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                    {
                                                        objChildNode.Text = objChild.DisplayName;
                                                        // Remove the Node if its Qty has been reduced to 0.
                                                        if (objChild.Quantity <= 0)
                                                        {
                                                            objChildNode.Remove();
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                        }

                                        // Remove the Gear if its Qty has been reduce to 0.
                                        if (objChild.Quantity <= 0)
                                        {
                                            objVehicleGear.Children.Remove(objChild);
                                        }

                                        break;
                                    }
                                    else
                                    {
                                        foreach (Gear objSubChild in objChild.Children)
                                        {
                                            if (objSubChild.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Deduct the Qty from the Gear.
                                                objSubChild.Quantity -= objEntry.Undo.Qty;
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objSubChildNode in objChildNode.Nodes)
                                                            {
                                                                if (objSubChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                {
                                                                    objSubChildNode.Text = objSubChild.DisplayName;
                                                                    // Remove the Node if its Qty has been reduced to 0.
                                                                    if (objSubChild.Quantity <= 0)
                                                                    {
                                                                        objSubChildNode.Remove();
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                // Remove the Gear if its Qty has been reduce to 0.
                                                if (objSubChild.Quantity <= 0)
                                                {
                                                    objChild.Children.Remove(objSubChild);
                                                }

                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleWeapon:
                    // Locate the Weapon that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                if (objWeapon.InternalId == objEntry.Undo.ObjectId)
                                {
                                    // Remove the Weapon.
                                    objMod.Weapons.Remove(objWeapon);

                                    // Remove the Weapon from the Tree.
                                    foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                    {
                                        foreach (TreeNode objNode in objVNode.Nodes)
                                        {
                                            foreach (TreeNode objChild in objNode.Nodes)
                                            {
                                                if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                {
                                                    objChild.Remove();
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                                else
                                {
                                    if (objWeapon.UnderbarrelWeapons.Count > 0)
                                    {
                                        foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                        {
                                            if (objUnderbarrelWeapon.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Remove the Underbarrel Weapon.
                                                objWeapon.UnderbarrelWeapons.Remove(objUnderbarrelWeapon);

                                                // Remove the Underbarrel Weapon from the Tree.
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objChild in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objSubChild in objChild.Nodes)
                                                            {
                                                                if (objSubChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                {
                                                                    objSubChild.Remove();
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleWeaponAccessory:
                    // Locate the Weapon Accessory that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                                {
                                    if (objAccessory.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Remove the Weapon Accessory.
                                        objWeapon.WeaponAccessories.Remove(objAccessory);

                                        // Remove the Weapon Accessory from the Tree.
                                        foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objVNode.Nodes)
                                            {
                                                foreach (TreeNode objWNode in objNode.Nodes)
                                                {
                                                    foreach (TreeNode objChild in objWNode.Nodes)
                                                    {
                                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                        {
                                                            objChild.Remove();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        foreach (WeaponAccessory objAccessory in objUnderbarrelWeapon.WeaponAccessories)
                                        {
                                            if (objAccessory.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Remove the Weapon Accessory.
                                                objUnderbarrelWeapon.WeaponAccessories.Remove(objAccessory);

                                                // Remove the Weapon Accessory from the Tree.
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objWNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objChild in objWNode.Nodes)
                                                            {
                                                                foreach (TreeNode objSubChild in objChild.Nodes)
                                                                {
                                                                    if (objSubChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                    {
                                                                        objSubChild.Remove();
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleWeaponMod:
                    // Locate the Weapon Mod that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Weapon objWeapon in objMod.Weapons)
                            {
                                foreach (WeaponMod objWMod in objWeapon.WeaponMods)
                                {
                                    if (objMod.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Remove the Weapon Mod.
                                        objWeapon.WeaponMods.Remove(objWMod);

                                        // Remove the Weapon Mod from the Tree.
                                        foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objVNode.Nodes)
                                            {
                                                foreach (TreeNode objWNode in objNode.Nodes)
                                                {
                                                    foreach (TreeNode objChild in objWNode.Nodes)
                                                    {
                                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                        {
                                                            objChild.Remove();
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (objWeapon.UnderbarrelWeapons.Count > 0)
                                {
                                    foreach (Weapon objUnderbarrelWeapon in objWeapon.UnderbarrelWeapons)
                                    {
                                        foreach (WeaponMod objWMod in objUnderbarrelWeapon.WeaponMods)
                                        {
                                            if (objWMod.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Remove the Weapon Mod.
                                                objUnderbarrelWeapon.WeaponMods.Remove(objWMod);

                                                // Remove the Weapon Mod from the Tree.
                                                foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objVNode.Nodes)
                                                    {
                                                        foreach (TreeNode objWNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objChild in objWNode.Nodes)
                                                            {
                                                                foreach (TreeNode objSubChild in objChild.Nodes)
                                                                {
                                                                    if (objSubChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                    {
                                                                        objSubChild.Remove();
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddArmor:
                    // Locate the Armor that was added.
                    Armor objArmor = objCommon.FindArmor(objEntry.Undo.ObjectId, _objCharacter.Armor);

                    if (objArmor != null)
                    {
                        // Remove the Improvements for any child items.
                        foreach (ArmorMod objMod in objArmor.ArmorMods)
                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ArmorMod, objMod.InternalId);

                        // Remove the Improvements for the Armor.
                        _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Armor, objArmor.InternalId);

                        // Remove the Armor from the character.
                        _objCharacter.Armor.Remove(objArmor);

                        // Remove the Armor from the Tree.
                        TreeNode objArmorNode = objCommon.FindNode(objEntry.Undo.ObjectId, treArmor);
                        objArmorNode.Remove();
                    }

                    break;
                case NuyenExpenseType.AddArmorMod:
                    // Locate the Armor Mod that was added.
                    foreach (Armor objFoundArmor in _objCharacter.Armor)
                    {
                        foreach (ArmorMod objMod in objFoundArmor.ArmorMods)
                        {
                            if (objMod.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Remove the Improtements for the Armor Mod.
                                _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.ArmorMod, objMod.InternalId);

                                // Remove the Armor Mod from the Armor.
                                objFoundArmor.ArmorMods.Remove(objMod);

                                // Remove the Cyberweapon created by the Mod if applicable.
                                if (objMod.WeaponID != Guid.Empty.ToString())
                                {
                                    // Remove the Weapon from the TreeView.
                                    TreeNode objRemoveNode = new TreeNode();
                                    foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                    {
                                        if (objWeaponNode.Tag.ToString() == objMod.WeaponID)
                                            objRemoveNode = objWeaponNode;
                                    }
                                    treWeapons.Nodes.Remove(objRemoveNode);

                                    // Remove the Weapon from the Character.
                                    Weapon objRemoveWeapon = new Weapon(_objCharacter);
                                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                                    {
                                        if (objWeapon.InternalId == objMod.WeaponID)
                                            objRemoveWeapon = objWeapon;
                                    }
                                    _objCharacter.Weapons.Remove(objRemoveWeapon);
                                }

                                // Remove the Armor Mod from the Tree.
                                TreeNode objNode = objCommon.FindNode(objMod.InternalId, treArmor.Nodes[0]);
                                objNode.Remove();
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddWeapon:
                    // Locate the Weapon that was added.
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        if (objWeapon.InternalId == objEntry.Undo.ObjectId)
                        {
                            // Remove the Weapn from the character.
                            _objCharacter.Weapons.Remove(objWeapon);

                            // Remove the Weapon from the Tree.
                            foreach (TreeNode objNode in treWeapons.Nodes[0].Nodes)
                            {
                                if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                {
                                    objNode.Remove();
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                case NuyenExpenseType.AddWeaponAccessory:
                    // Locate the Weapon Accessory that was added.
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        foreach (WeaponAccessory objAccessory in objWeapon.WeaponAccessories)
                        {
                            if (objAccessory.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Remove the Weapon Accessory.
                                objWeapon.WeaponAccessories.Remove(objAccessory);

                                // Remove the Weapon Accessory from the tree.
                                foreach (TreeNode objNode in treWeapons.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objChild in objNode.Nodes)
                                    {
                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objChild.Remove();
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddWeaponMod:
                    // Locate the Weapon Mod that was added.
                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                    {
                        foreach (WeaponMod objMod in objWeapon.WeaponMods)
                        {
                            if (objMod.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Remove the Weapon Mod.
                                objWeapon.WeaponMods.Remove(objMod);

                                // Remove the Weapon Mod from the tree.
                                foreach (TreeNode objNode in treWeapons.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objChild in objNode.Nodes)
                                    {
                                        if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objChild.Remove();
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.IncreaseLifestyle:
                    // Locate the Lifestyle that was increased.
                    foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles)
                    {
                        if (objLifestyle.Name == objEntry.Undo.ObjectId)
                        {
                            objLifestyle.Months--;
                            RefreshSelectedLifestyle();
                            break;
                        }
                    }
                    break;
                case NuyenExpenseType.AddArmorGear:
                    // Locate the Armor Gear that was added.
                    foreach (Armor objFoundArmor in _objCharacter.Armor)
                    {
                        foreach (Gear objArmorGear in objFoundArmor.Gear)
                        {
                            if (objArmorGear.InternalId == objEntry.Undo.ObjectId)
                            {
                                // Deduct the Qty from the Gear.
                                objArmorGear.Quantity -= objEntry.Undo.Qty;
                                foreach (TreeNode objArmorNode in treArmor.Nodes[0].Nodes)
                                {
                                    foreach (TreeNode objNode in objArmorNode.Nodes)
                                    {
                                        if (objNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                        {
                                            objNode.Text = objArmorGear.DisplayName;
                                            // Remove the Node if its Qty has been reduced to 0.
                                            if (objArmorGear.Quantity <= 0)
                                                objNode.Remove();
                                            break;
                                        }
                                    }
                                }

                                // Remove the Gear if its Qty has been reduced to 0.
                                if (objArmorGear.Quantity <= 0)
                                {
                                    // Remove any Improvements created by the Gear.
                                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objArmorGear.InternalId);
                                    objFoundArmor.Gear.Remove(objArmorGear);

                                    // Remove any Weapons created by the Gear.
                                    foreach (Weapon objWeapon in _objCharacter.Weapons)
                                    {
                                        if (objWeapon.InternalId == objArmorGear.WeaponID)
                                        {
                                            _objCharacter.Weapons.Remove(objWeapon);
                                            foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                            {
                                                if (objWeaponNode.Tag.ToString() == objArmorGear.WeaponID)
                                                {
                                                    objWeaponNode.Remove();
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }

                                break;
                            }
                            else
                            {
                                // Look in child items.
                                foreach (Gear objChild in objArmorGear.Children)
                                {
                                    if (objChild.InternalId == objEntry.Undo.ObjectId)
                                    {
                                        // Deduct the Qty from the Gear.
                                        objChild.Quantity -= objEntry.Undo.Qty;
                                        foreach (TreeNode objArmorNode in treArmor.Nodes[0].Nodes)
                                        {
                                            foreach (TreeNode objNode in objArmorNode.Nodes)
                                            {
                                                foreach (TreeNode objChildNode in objNode.Nodes)
                                                {
                                                    if (objChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                    {
                                                        objChildNode.Text = objChild.DisplayName;
                                                        // Remove the Node if its Qty has been reduced to 0.
                                                        if (objChild.Quantity <= 0)
                                                        {
                                                            objChildNode.Remove();

                                                            // Remove any Weapons created by the Gear.
                                                            foreach (Weapon objWeapon in _objCharacter.Weapons)
                                                            {
                                                                if (objWeapon.InternalId == objChild.WeaponID)
                                                                {
                                                                    _objCharacter.Weapons.Remove(objWeapon);
                                                                    foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                                                    {
                                                                        if (objWeaponNode.Tag.ToString() == objChild.WeaponID)
                                                                        {
                                                                            objWeaponNode.Remove();
                                                                            break;
                                                                        }
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                        }

                                        // Remove the Gear if its Qty has been reduce to 0.
                                        if (objChild.Quantity <= 0)
                                        {
                                            // Remove any Improvements created by the Gear.
                                            _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objChild.InternalId);
                                            objArmorGear.Children.Remove(objChild);
                                        }

                                        break;
                                    }
                                    else
                                    {
                                        foreach (Gear objSubChild in objChild.Children)
                                        {
                                            if (objSubChild.InternalId == objEntry.Undo.ObjectId)
                                            {
                                                // Deduct the Qty from the Gear.
                                                objSubChild.Quantity -= objEntry.Undo.Qty;
                                                foreach (TreeNode objArmorNode in treArmor.Nodes[0].Nodes)
                                                {
                                                    foreach (TreeNode objNode in objArmorNode.Nodes)
                                                    {
                                                        foreach (TreeNode objChildNode in objNode.Nodes)
                                                        {
                                                            foreach (TreeNode objSubChildNode in objChildNode.Nodes)
                                                            {
                                                                if (objSubChildNode.Tag.ToString() == objEntry.Undo.ObjectId)
                                                                {
                                                                    objSubChildNode.Text = objSubChild.DisplayName;
                                                                    // Remove the Node if its Qty has been reduced to 0.
                                                                    if (objSubChild.Quantity <= 0)
                                                                    {
                                                                        objSubChildNode.Remove();

                                                                        // Remove any Weapons created by the Gear.
                                                                        foreach (Weapon objWeapon in _objCharacter.Weapons)
                                                                        {
                                                                            if (objWeapon.InternalId == objSubChild.WeaponID)
                                                                            {
                                                                                _objCharacter.Weapons.Remove(objWeapon);
                                                                                foreach (TreeNode objWeaponNode in treWeapons.Nodes[0].Nodes)
                                                                                {
                                                                                    if (objWeaponNode.Tag.ToString() == objSubChild.WeaponID)
                                                                                    {
                                                                                        objWeaponNode.Remove();
                                                                                        break;
                                                                                    }
                                                                                }
                                                                                break;
                                                                            }
                                                                        }
                                                                    }
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                // Remove the Gear if its Qty has been reduce to 0.
                                                if (objSubChild.Quantity <= 0)
                                                {
                                                    // Remove any Improvements created by the Gear.
                                                    _objImprovementManager.RemoveImprovements(Improvement.ImprovementSource.Gear, objSubChild.InternalId);
                                                    objChild.Children.Remove(objSubChild);
                                                }

                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddVehicleModCyberware:
                    // Locate the Cyberware that was added.
                    foreach (Vehicle objVehicle in _objCharacter.Vehicles)
                    {
                        foreach (VehicleMod objMod in objVehicle.Mods)
                        {
                            foreach (Cyberware objCyberware in objMod.Cyberware)
                            {
                                if (objCyberware.InternalId == objEntry.Undo.ObjectId)
                                {
                                    // Remove the Cyberware.
                                    objMod.Cyberware.Remove(objCyberware);

                                    // Remove the Cyberware from the Tree.
                                    foreach (TreeNode objVNode in treVehicles.Nodes[0].Nodes)
                                    {
                                        foreach (TreeNode objNode in objVNode.Nodes)
                                        {
                                            foreach (TreeNode objChild in objNode.Nodes)
                                            {
                                                if (objChild.Tag.ToString() == objEntry.Undo.ObjectId)
                                                {
                                                    objChild.Remove();
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case NuyenExpenseType.AddCyberwareGear:
                    // Locate the Gear that was added.
                    Cyberware objFoundCyberware = new Cyberware(_objCharacter);
                    Gear objFoundGear = _objFunctions.FindCyberwareGear(objEntry.Undo.ObjectId, _objCharacter.Cyberware, out objFoundCyberware);
                    _objFunctions.DeleteGear(objFoundGear, treWeapons, _objImprovementManager);
                    if (objFoundGear.Parent == null)
                        objFoundCyberware.Gear.Remove(objFoundGear);
                    else
                        objFoundGear.Parent.Children.Remove(objFoundGear);
                    TreeNode objFoundNode = _objFunctions.FindNode(objFoundGear.InternalId, treCyberware);
                    objFoundNode.Remove();
                    break;
                case NuyenExpenseType.AddWeaponGear:
                    // Locate the Gear that was added.
                    WeaponAccessory objFoundAccessory = new WeaponAccessory(_objCharacter);
                    Gear objFoundAccGear = _objFunctions.FindWeaponGear(objEntry.Undo.ObjectId, _objCharacter.Weapons, out objFoundAccessory);
                    _objFunctions.DeleteGear(objFoundAccGear, treWeapons, _objImprovementManager);
                    if (objFoundAccGear.Parent == null)
                        objFoundAccessory.Gear.Remove(objFoundAccGear);
                    else
                        objFoundAccGear.Parent.Children.Remove(objFoundAccGear);
                    TreeNode objFoundAccNode = _objFunctions.FindNode(objFoundAccGear.InternalId, treWeapons);
                    objFoundAccNode.Remove();
                    break;
                case NuyenExpenseType.ManualAdd:
                case NuyenExpenseType.ManualSubtract:
                    break;
            }
            // Refund the Nuyen amount and remove the Expense Entry.
            _objCharacter.Nuyen -= objEntry.Amount;
            _objCharacter.ExpenseEntries.Remove(objEntry);

            UpdateCharacterInfo();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }