public UpdateMaintenanceUC()
 {
     InitializeComponent();
     MachineController controller = new MachineController();
     this.comboBox.ItemsSource = controller.maintenance;
 
 }
 private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     MachineController controller = new MachineController();
     Machine newMachine = controller.FindSpecificMachine(Convert.ToInt32(comboBox.SelectedValue));
     machine = newMachine;
     comboBoxYear.ItemsSource = controller.GetListForComboBoxYear(newMachine.Lifespan);
     //Sæt maxværdi på valgt år box til lifespan         
 }
        private void btnDeleteMaintenance_Click(object sender, RoutedEventArgs e)
        {
            
            MachineController myMachine = new MachineController();

            int MaintenanceId = Convert.ToInt32(MaintenanceLv.SelectedValue);

            myMachine.DeleteMaintenance(MaintenanceId);
        }
        public ViewMaintenanceUC()
        {
            MachineController controller = new MachineController();
            InitializeComponent();
            comboBox.SelectedItem = null;
            comboBox.SelectedIndex = -1;
            comboBox.ItemsSource = controller.machines;

        }
 private void CalcBtn_Click(object sender, RoutedEventArgs e)
 {
     MachineController controller = new MachineController();
     List<double> values = controller.CalcDepreciation(machine, Convert.ToInt32(comboBoxYear.SelectedValue), method);
     if(method == 2)
     {
         BookValueLbl.Content = "Depreciation and interest pr year:"; 
     }
     prYearContent.Content = values[0];
     DepValueContentLbl.Content = values[1]; 
 }
 private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     MachineController controller = new MachineController();
     foreach (Machine tempMachine in controller.machines)
     {
         if (tempMachine.Id == Convert.ToInt32(comboBox.SelectedValue))
         {
             MaintenanceLv.ItemsSource = tempMachine.maintenanceDaysList;
         }
     }
 }
 private void btnRefreshMaintenance_Click(object sender, RoutedEventArgs e)
 {
     MachineController controller = new MachineController();
     comboBox.ItemsSource = controller.machines;
     foreach (Machine tempMachine in controller.machines)
     {
         if (tempMachine.Id == Convert.ToInt32(comboBox.SelectedValue))
         {
             MaintenanceLv.ItemsSource = tempMachine.maintenanceDaysList;
         }
     }
 }
        private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MachineController controller = new MachineController();
            Maintenance myMaint = controller.FindSpecificMaintenance(Convert.ToInt32(comboBox.SelectedValue));
            machineID = myMaint.MachineID; 
            StartDatePicker.SelectedDate = myMaint.StartTime.Date;
            StartTimeTxtB.Text = myMaint.StartTime.TimeOfDay.ToString();
            EndDatePicker.SelectedDate = myMaint.EndTime.Date;
            EndTimeTxtB.Text = myMaint.EndTime.TimeOfDay.ToString();       
            MachineIDContentlbl.Content = myMaint.MachineID;


        }
 private void UpdateMaintenanceBtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         MachineController controller = new MachineController();
         MessageBox.Show(controller.CreateAndUpdateMaintenance(Convert.ToInt32(comboBox.SelectedValue), machineID, StartDatePicker.SelectedDate.Value, Convert.ToDateTime(StartTimeTxtB.Text), EndDatePicker.SelectedDate.Value, Convert.ToDateTime(EndTimeTxtB.Text)));
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message); 
     }
    
 }
        private void btnSaveMachine_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MachineController MController = new MachineController();
                MessageBox.Show(MController.CreateMachineAndSave(txtBoxMachineName.Text, isProduction, DtPickerPurchaseDate.SelectedDate.Value, double.Parse(txtBoxPurchasePrice.Text), double.Parse(txtBoxScrapValue.Text), int.Parse(txtBoxLifespan.Text), double.Parse(txtBoxInterestRate.Text)));
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message); 
            }


        }
        private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MachineController controller = new MachineController();
            Machine newMachine = controller.FindSpecificMachine(Convert.ToInt32(comboBox.SelectedValue));
            txtBoxMachineName.Text = newMachine.Name;
            txtBoxLifespan.Text = newMachine.Lifespan.ToString();
            txtBoxScrapValue.Text = newMachine.ScrapValue.ToString();
            txtBoxPurchasePrice.Text = newMachine.PurchasePrice.ToString();
            if (newMachine.ProductionUse)
            {
                radioBtnYesMachine.IsChecked = true;
            }
            else
            {
                radioBtnNoMachine.IsChecked = true;
            }

            DTPickerpurchaseDate.SelectedDate = newMachine.DateBought;
            txtBoxInterestRate.Text = newMachine.InterestRate.ToString();
        }
 private void btnDeleteMachine_Click(object sender, RoutedEventArgs e)
 {
     MachineController controller = new MachineController();
     MessageBox.Show(controller.DeleteMachine(Convert.ToInt32(MachineLv.SelectedValue))); 
 }
 private void btnRefreshMachine_Click(object sender, RoutedEventArgs e)
 {
     MachineController controller = new MachineController();
     this.MachineLv.ItemsSource = controller.machines;
 }
 public ViewMachineUC()
 {
     InitializeComponent();
     MachineController controller = new MachineController();
     this.MachineLv.ItemsSource = controller.machines;
 }
 public RegisterMaintenanceUC()
 {
     InitializeComponent();
     MachineController controller = new MachineController();
     this.comboBox.ItemsSource = controller.machines;
 }
 public CalculateDepreciationUC()
 {
     InitializeComponent();
     MachineController controller = new MachineController();
     this.comboBox.ItemsSource = controller.machines;
 }