private void EditMachinesButtonClick(object sender, RoutedEventArgs e)
        {
            EditMachinesWindow machinesWindow = new EditMachinesWindow();
            machinesWindow.bl = new BindingList<string>();

            foreach (Machine item in machines)
                machinesWindow.bl.Add(item.Name.PadRight(10) + " No " + item.MachineNumber);

            machinesWindow.NameCombo.ItemsSource = machinesWindow.bl;
            machinesWindow.ShowDialog();

            if (machinesWindow.currentMachine > -1)
            {
                if (machinesWindow.currentMachine == machines.Count)
                {
                    Machine machineToAdd = new Machine();
                    machineToAdd.Name = machinesWindow.NameBox.Text;
                    int number;
                    bool isNumber = int.TryParse(machinesWindow.NoBox.Text, out number);

                    if (!isNumber)
                    {
                        MessageBox.Show("Invalid machine number");
                        return;
                    }
                    else
                        machineToAdd.MachineNumber = int.Parse(machinesWindow.NoBox.Text);
                    engine.MachineRepository.Insert(machineToAdd);
                    UpdateMachines();
                    MachineNumber.ItemsSource = new BindingList<ITool>(machines);
                }
                else
                {
                    if ((machines[machinesWindow.currentMachine] as Machine).ContractId != null)
                        MessageBox.Show("Cannot delete this machine. It's in use in contract No " + (machines[machinesWindow.currentMachine] as Machine).ContractId);
                    else
                    {
                        engine.MachineRepository.Delete(machines[machinesWindow.currentMachine] as Machine);
                        UpdateMachines();
                        MachineName.SelectedIndex = -1;
                        MachineNumber.ItemsSource = new BindingList<ITool>(machines);
                        MachineNumber.SelectedIndex = -1;
                    }
                }
            }
        }
        private void EditAccButtonClick(object sender, RoutedEventArgs e)
        {
            EditMachinesWindow machinesWindow = new EditMachinesWindow();
            machinesWindow.NoBlock.Visibility = UIResources.Hidden;
            machinesWindow.NoBox.Visibility = UIResources.Hidden;
            machinesWindow.bl = new BindingList<string>();

            foreach (ITool item in accesories)
                machinesWindow.bl.Add(item.Name);

            machinesWindow.NameCombo.ItemsSource = machinesWindow.bl;
            machinesWindow.ShowDialog();

            if (machinesWindow.currentMachine > -1)
            {
                if (machinesWindow.currentMachine == accesories.Count)
                {
                    Accessory accessoryToAdd = new Accessory();
                    accessoryToAdd.Name = machinesWindow.NameBox.Text;
                    engine.AccessoryRepository.Insert(accessoryToAdd);
                }
                else
                {
                    engine.AccessoryRepository.Delete(accesories[machinesWindow.currentMachine] as Accessory);
                    accesories.RemoveAt(machinesWindow.currentMachine);
                    AccessoryName.SelectedIndex = -1;
                }
                UpdateAccesories();
            }
        }