private void UpdateBoat()
        {
            var boatNameInput       = BoatNameBox.Text;
            var boatTypeInput       = Boat.AssignSelectedType(BoatTypeBox.Text);
            var boatYoutubeUrlInput = YoutubeUrlBox.Text;

            if (!string.IsNullOrWhiteSpace(boatNameInput) && BoatTypeBox.SelectedValue != null)
            {
                try
                {
                    InputValidation.CheckForInvalidCharacters(boatNameInput);
                    InputValidation.IsYoutubeUrl(boatYoutubeUrlInput);

                    var selectedImageString = BoatImages.ImageToBase64(SelectedImageForConversion, System.Drawing.Imaging.ImageFormat.Png);
                    var selectedImageInput  = selectedImageString;


                    if (System.Windows.Forms.MessageBox.Show("Weet u zeker dat u deze wijzigingen wil toepassen?", "Bevestiging",
                                                             System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question,
                                                             System.Windows.Forms.MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                    {
                        using (var context = new BootDB())
                        {
                            var boot  = context.Boats.SingleOrDefault(b => b.boatId == BoatId);
                            var image = context.BoatImages.SingleOrDefault(i => i.boatId == BoatId);

                            boot.boatName       = boatNameInput;
                            boot.boatTypeId     = boatTypeInput;
                            boot.boatYoutubeUrl = YoutubeUrlBox.Text;

                            if (!string.IsNullOrWhiteSpace(selectedImageInput))
                            {
                                image.boatImageBlob = selectedImageInput;
                            }

                            context.SaveChanges();
                        }
                    }
                    Switcher.Switch(new boatOverviewScreen(FullName, AccessLevel, MemberId));
                }
                catch (FormatException)
                {
                    //Warning message for FormatException
                    MessageBox.Show("De ingevulde boot naam is niet geldig\n(let op: speciale tekens zijn niet toegestaan)", "Ongeldige waarde", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (InvalidYoutubeUrlException)
                {
                    //Warning message for InvalidYoutubeUrlException
                    MessageBox.Show("Vul een geldige YouTube URL in", "Ongeldige URL", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (FileTooLargeException)
                {
                    MessageBox.Show("De geselecteerde afbeelding is te groot. (Max. 256kb)", "Bestand te groot", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (Exception ex)
                {
                    //Error message for any other exception that could occur
                    MessageBox.Show(ex.Message, "Een fout is opgetreden", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Vul alle velden in.", "Niet alle velden zijn ingevuld", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Example #2
0
        //Method to execute when AddUser button is clicked
        private void ReportDamageButton_Click(object sender, RoutedEventArgs e)
        {
            //Save textBox content to variables for easy access
            var damageLevel = DamageLevel.SelectedIndex + 1; //Add 1 because combobox index start at 0 and values in database vary from 1 to 3
            var location    = LocationBox.Text;
            var reason      = ReasonBox.Text;

            //Check for empty fields, if a field is left empty show an error dialog
            if (!string.IsNullOrWhiteSpace(location) && !string.IsNullOrWhiteSpace(reason))
            {
                try
                {
                    //Convert image to blob
                    var selectedImageString = BoatImages.ImageToBase64(SelectedImageForConversion, System.Drawing.Imaging.ImageFormat.Png);
                    var selectedImageInput  = selectedImageString;

                    //Create new report to add to the DB
                    var boatDamage = new BoatDamage
                    {
                        boatId             = BoatId,
                        memberId           = MemberId,
                        boatDamageLevel    = damageLevel,
                        boatDamageLocation = location,
                        boatDamageReason   = reason,
                        reportDate         = DateTime.Now,
                        boatImageBlob      = selectedImageInput
                    };

                    //Add report to database
                    BoatDamage.AddReportToDb(boatDamage);

                    MessageBox.Show("Schade melding is succesvol toegevoegd.", "Melding toegevoegd", MessageBoxButton.OK, MessageBoxImage.Information);
                    switch (AccessLevel)
                    {
                    case 1:
                        Switcher.Switch(new HomePageMember(FullName, AccessLevel, MemberId));
                        break;

                    case 2:
                        Switcher.Switch(new HomePageMatchCommissioner(FullName, AccessLevel, MemberId));
                        break;

                    case 3:
                        Switcher.Switch(new HomePageMaterialCommissioner(FullName, AccessLevel, MemberId));
                        break;
                    }
                }
                catch (FileTooLargeException)
                {
                    MessageBox.Show("De geselecteerde afbeelding is te groot. (Max. 256kb)", "Bestand te groot", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (Exception exception)
                {
                    //Error message for any other exception that could occur
                    MessageBox.Show(exception.Message, "Een fout is opgetreden", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Vul alle velden in.", "Niet alle velden zijn ingevuld", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }