示例#1
0
        public void OnLoginButtonIsPressed_MaterialCommissionerLoggedInCorrect_ReturnTrue()
        {
            //Arrange
            Member     m  = new Member();
            MainWindow mw = new MainWindow();
            int        result;

            using (var context = new BootDB())
            {
                Member m1 = new Member
                {
                    memberName             = "unittest",
                    memberUsername         = "******",
                    memberAccessLevelId    = 3,
                    memberRowLevelId       = 1,
                    memberSubscribedUntill = DateTime.Now.AddYears(1)
                };
                context.Members.Add(m1);
                context.SaveChanges();

                // Act
                m.OnLoginButtonIsPressed(new LoginScreen(), new LoginEventArgs("unittest3"));
                result = m.SortUser;

                context.Members.Attach(m1);
                context.Members.Remove(m1);
                context.SaveChanges();
            }
            // Assert
            Assert.AreEqual(3, result);
        }
示例#2
0
        public void OnLoginButtonIsPressed_UserSubscriptionExpired_ReturnFalse()
        {
            //Arrange
            Member     m  = new Member();
            MainWindow mw = new MainWindow();
            bool       result;

            using (var context = new BootDB())
            {
                Member m1 = new Member
                {
                    memberName             = "unittest",
                    memberUsername         = "******",
                    memberAccessLevelId    = 1,
                    memberRowLevelId       = 1,
                    memberSubscribedUntill = DateTime.Now.AddYears(-1)
                };
                context.Members.Add(m1);
                context.SaveChanges();

                // Act
                m.OnLoginButtonIsPressed(new LoginScreen(), new LoginEventArgs("unittest6"));
                result = m.Correct;

                context.Members.Attach(m1);
                context.Members.Remove(m1);
                context.SaveChanges();
            }
            // Assert
            Assert.IsFalse(result);
        }
        private void ReservationButton_Click(object sender, RoutedEventArgs e)
        {
            //getting the selected begin and end time
            try
            {
                SelectedBeginTime = (beginTimePicker.SelectedTime.Value).TimeOfDay;
                SelectedEndTime   = (endTimePicker.SelectedTime.Value).TimeOfDay;
            } catch (Exception)
            {
                ErrorLabel.Content = "Geen geldige invoer";
                return;
            }
            //check if selected times are possible
            var check = Reservation.CheckTime(SelectedBeginTime, SelectedEndTime, BeginTime, EndTime, SunUp, SunDown, true);

            //this will be executed when the selected times are not correct
            if (!check)
            {
                ErrorLabel.Content = "Deze tijden zijn niet mogelijk";
            }
            else //when it is possible to add reservation
            {
                using (var context = new BootDB())
                {
                    var reservation = new Reservations
                    {
                        memberId  = MemberId,
                        date      = SelectedDate,
                        beginTime = SelectedBeginTime,
                        endTime   = SelectedEndTime,
                    };

                    context.Reservations.Add(reservation);
                    context.SaveChanges();

                    //getting the last reservation id to add that to other table
                    var data = (from r in context.Reservations
                                orderby r.reservationId descending
                                select r.reservationId).First().ToString();

                    var id = int.Parse(data);

                    var reservation_boat = new Reservation_Boats
                    {
                        reservationId = id,
                        boatId        = BoatId
                    };

                    context.Reservation_Boats.Add(reservation_boat);
                    context.SaveChanges();
                }
                //show message when reservation is added to screen
                MessageBox.Show("Reservering is gelukt!", "Gelukt", MessageBoxButton.OK, MessageBoxImage.Information);

                Switcher.Switch(new ReservationsScreen(FullName, AccessLevel, MemberId));
            }
        }
示例#4
0
        //Unchecked takes boat out of maintenance
        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            // Get current boat from click row
            Boat boat = ((FrameworkElement)sender).DataContext as Boat;

            try
            {
                using (var context = new BootDB())
                {
                    var currentBoat = (from b in context.Boats
                                       where b.boatId == boat.boatId
                                       select b).SingleOrDefault();

                    currentBoat.boatOutOfService = 0;

                    context.SaveChanges();

                    MessageBox.Show(boat.boatName + " is uit onderhoud genomen en weer te reserveren.",
                                    "Boot weer beschikbaar", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception exception)
            {
                //Error message for exception that could occur
                MessageBox.Show(exception.Message, "Een fout is opgetreden", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#5
0
 public static void AddNewUserToDb(string nameInput, string usernameInput)
 {
     //add user as member, but not active yet
     if (CheckAmountUsers() != 0)
     {
         using (var context = new BootDB())
         {
             var member = new Member {
                 memberUsername = usernameInput, memberName = nameInput, memberAccessLevelId = 1, memberRowLevelId = 1
             };
             context.Members.Add(member);
             context.SaveChanges();
         }
     }//if system has no members, first one to register is admin
     else
     {
         using (var context = new BootDB())
         {
             var member = new Member {
                 memberUsername = usernameInput, memberName = nameInput, memberAccessLevelId = 4, memberRowLevelId = 1
             };
             context.Members.Add(member);
             context.SaveChanges();
         }
     }
 }
示例#6
0
        public static void DeleteReservation(int reservationId)
        {
            //delete row in reservations table
            using (var context = new BootDB())
            {
                var data = (from r in context.Reservations
                            where r.reservationId == reservationId
                            select new { r.reservationId, r.memberId, r.date, r.beginTime, r.endTime });

                foreach (var d in data)
                {
                    var res = new Reservations(d.reservationId, d.memberId, d.date, d.beginTime, d.endTime);
                    context.Reservations.Attach(res);
                    context.Reservations.Remove(res);
                }

                //delete row in Reservations_Boats table
                var data2 = (from rb in context.Reservation_Boats
                             where rb.reservationId == reservationId
                             select new { rb.reservationId, rb.boatId });

                foreach (var d in data2)
                {
                    var reservationBoats = new Reservation_Boats(d.reservationId, d.boatId);
                    context.Reservation_Boats.Attach(reservationBoats);
                    context.Reservation_Boats.Remove(reservationBoats);
                }

                context.SaveChanges();
            }
        }
示例#7
0
 //Method to add report to the database
 public static void AddReportToDb(BoatDamage report)
 {
     using (var context = new BootDB())
     {
         context.BoatDamages.Add(report);
         context.SaveChanges();
     }
 }
示例#8
0
 //Method to add member to the database
 public static void AddMemberToDb(Member member)
 {
     using (var context = new BootDB())
     {
         context.Members.Add(member);
         context.SaveChanges();
     }
 }
示例#9
0
 //Method that inserts the boat into the database
 private static void AddBoatToDb(Boat boat)
 {
     using (var context = new BootDB())
     {
         context.Boats.Add(boat);
         context.SaveChanges();
         MessageBox.Show("Boot is succesvol toegevoegd.", "Boot toegevoegd", MessageBoxButton.OK, MessageBoxImage.Information);
     }
 }
示例#10
0
 //for unit tests
 public static void RemoveLastAddedMember()
 {
     using (var context = new BootDB())
     {
         var data = (from m in context.Members
                     select m).ToList().Last();
         context.Members.Attach(data);
         context.Members.Remove(data);
         context.SaveChanges();
     }
 }
示例#11
0
        //Method that inserts the associated image into the database
        public static void AddImageToDb(BoatImages boatImage)
        {
            using (var context = new BootDB())
            {
                boatImage.boatId = (from b in context.Boats
                                    orderby b.boatId descending
                                    select b.boatId).FirstOrDefault();

                context.BoatImages.Add(boatImage);
                context.SaveChanges();
            }
        }
        //method for deleting a reservation and updating the indexes accordingly
        private void CancelMatchReservation(int batchReservationId)
        {
            using (var context = new BootDB())
            {
                var reservationsToDelete = from r in context.Reservations
                                           where r.reservationBatch == batchReservationId
                                           select r;

                var reservationsToUpdate = from r in context.Reservations
                                           where r.reservationBatch != 0 && r.reservationBatch > batchReservationId
                                           select r;

                var reservationDate = reservationsToDelete.First().date.Date.ToString("dd-MM-yyyy");
                var beginTimeString = reservationsToDelete.First().beginTime.ToString(@"hh\:mm");
                var endTimeString   = reservationsToDelete.First().endTime.ToString(@"hh\:mm");

                var result = MessageBox.Show($"Weet u zeker dat u wedstrijdreservering {batchReservationId} op {reservationDate} van {beginTimeString} uur tot {endTimeString} uur wilt annuleren?", "Annuleren", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);


                if (result != MessageBoxResult.Yes)
                {
                    return;
                }
                //Removes the batchReservation from the database
                foreach (var res in reservationsToDelete)
                {
                    context.Reservations.Remove(res);
                }
                context.SaveChanges();

                //Lowers the value of all the other batchReservations above it by 1 so that the indexes stay consistent
                foreach (var res in reservationsToUpdate)
                {
                    res.reservationBatch = res.reservationBatch - 1;
                }
                context.SaveChanges();
                Switcher.Switch(new BatchReservationScreen(FullName, AccessLevel, MemberId));
            }
        }
示例#13
0
        public void AddreportToDB_AddDamageReportToDataBase_ResultIsTrue()
        {
            //Arrange
            var report = new BoatDamage
            {
                boatId             = 1,
                memberId           = 1,
                boatDamageLevel    = 2,
                boatDamageLocation = "Voor",
                boatDamageReason   = "Sawwy",
                reportDate         = DateTime.Now,
                boatImageBlob      = ""
            };
            var result = false;

            //Act
            //Method is placed inside a try block, so if it cant connect the result is set to false
            try
            {
                BoatDamage.AddReportToDb(report);

                //Check if the member is actually in the database
                using (var context = new BootDB())
                {
                    var Damages = from d in context.BoatDamages
                                  where d.boatId == report.boatId && d.memberId == report.memberId && d.boatDamageLevel == report.boatDamageLevel && d.boatDamageLocation == report.boatDamageLocation && d.boatDamageReason == report.boatDamageReason
                                  select d;

                    if (Damages.ToList().Count > 0)
                    {
                        result = true;
                    }
                }

                //Remove test member form database
                using (var context = new BootDB())
                {
                    context.BoatDamages.Attach(report);
                    context.BoatDamages.Remove(report);
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                result = false;
            }

            //Assert
            Assert.True(result);
        }
示例#14
0
        public void AddMemberToDB_AddMemberToDataBase_ResultIsTrue()
        {
            //Arrange
            var member = new Member
            {
                memberUsername         = "******",
                memberName             = "Unit Test",
                memberRowLevelId       = 1,
                memberAccessLevelId    = 1,
                memberSubscribedUntill = DateTime.Now.AddYears(1)
            };
            var result = false;

            //Act
            //Method is placed inside a try block, so if it cant connect the result is set to false
            try
            {
                Member.AddMemberToDb(member);
            }
            catch (Exception e)
            {
                result = false;
            }

            //Check if the member is actually in the database
            using (var context = new BootDB())
            {
                var members = from m in context.Members
                              where m.memberUsername == member.memberUsername
                              select m;

                if (members.ToList().Count > 0)
                {
                    result = true;
                }
            }

            //Remove test member form database
            using (var context = new BootDB())
            {
                context.Members.Attach(member);
                context.Members.Remove(member);
                context.SaveChanges();
            }

            //Assert
            Assert.True(result);
        }
示例#15
0
        public void CheckIfMemberExists_EnterAMemberThatIsNotInTheDateBase_ResultIsTrue()
        {
            //Arrange
            var member1 = new Member
            {
                memberUsername         = "******",
                memberName             = "Unit Test",
                memberRowLevelId       = 1,
                memberAccessLevelId    = 1,
                memberSubscribedUntill = DateTime.Now.AddYears(1)
            };
            var member2 = new Member
            {
                memberUsername         = "******",
                memberName             = "Unit Tester",
                memberRowLevelId       = 2,
                memberAccessLevelId    = 2,
                memberSubscribedUntill = DateTime.Now.AddYears(1)
            };
            var result = false;

            //Act
            Member.AddMemberToDb(member1);

            try
            {
                //The method CheckIfMemberExists has a void return type and throws an Exception when the the member is already in the database
                Member.CheckIfMemberExists(member2);
                result = true;
            }
            catch (Exception e)
            {
                result = false;
            }

            //Remove test member form database
            using (var context = new BootDB())
            {
                context.Members.Attach(member1);
                context.Members.Remove(member1);
                context.SaveChanges();
            }

            //Assert
            Assert.True(result);
        }
示例#16
0
        private void ChangeUser_Click(object sender, RoutedEventArgs e)
        {
            //Save textBox content to variables
            var name        = NameBox.Text;
            var userName    = UserNameBox.Text;
            var rowLevel    = RowLevelBox.SelectedIndex + 1;    //Add 1 because combobox index start at 0 and values in database vary from 1 to 4
            var accessLevel = AccesslevelBox.SelectedIndex + 1; //Add 1 because combobox index start at 0 and values in database vary from 1 to 5

            //Check for empty fields, if a field is left empty show an error dialog
            if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(userName))
            {
                try
                {
                    using (var context = new BootDB())
                    {
                        var origin = context.Members.Find(MemberId);
                        var mU     = new DateTime?();
                        mU = DatePicker.SelectedDate;

                        //If DatePicker hasn't got a value, value null
                        var memberUntil = mU;

                        //Check for invalid characters in the strings
                        Member.CheckForInvalidCharacters(name);
                        Member.CheckForInvalidCharacters(userName);

                        //Check if the member already exists
                        if (Enumerable.Any(context.Members.Where(value => userName == value.memberUsername), value => origin.memberUsername != userName))
                        {
                            MessageBox.Show("Kan niet al een bestaande gebruikersnaam invoeren!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        //Update database with selected changes
                        origin.memberUsername         = userName;
                        origin.memberName             = name;
                        origin.memberRowLevelId       = rowLevel;
                        origin.memberAccessLevelId    = accessLevel;
                        origin.memberSubscribedUntill = memberUntil;
                        context.SaveChanges();
                        MessageBox.Show("Gebruiker is succesvol gewijzigd.", "Gebruiker gewijzigd", MessageBoxButton.OK, MessageBoxImage.Information);
                        Switcher.Switch(new EditUserScreen(FullName, AccessLevel, MemberId));
                    }
                }
                catch (FormatException)
                {
                    //Warning message for FormatException
                    MessageBox.Show("Een van de ingevulde waardes is niet geldig", "Ongeldige waarde", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (InvalidDateException ide)
                {
                    //Warning message for an invalid date
                    MessageBox.Show(ide.Message, "Datum is niet geldig", 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);
            }
        }
        private void InMaintenance_Click(object sender, RoutedEventArgs e)
        {
            var valid = true;
            var from  = DatePicker.SelectedDate;
            var until = DatePickerUntil.SelectedDate;

            //start date is not empty
            if (from == null)
            {
                valid = false;
                MessageBox.Show("Vult u de start datum in.");
            }
            else if (until == null) //end date is not empty
            {
                valid = false;
                MessageBox.Show("Vult u de eind datum in.");
            }
            else if (from > until) //startDate > endDates
            {
                valid = false;
                MessageBox.Show("Start datum mag niet voorbij eind datum zijn.");
            }



            //save to boatMaintenance
            if (!valid)
            {
                return;
            }
            int insertId;

            //set endDate time to 23:59:59 from day
            var now      = (DateTime)until;
            var newUntil = now.AddHours(23).AddMinutes(59).AddSeconds(59);


            using (var context = new BootDB())
            {
                var inmain = new BoatInMaintenances()
                {
                    boatId    = this.BoatID,
                    startDate = @from,
                    endDate   = newUntil
                };

                //save to boat in maintenances
                context.BoatInMaintenances.Add(inmain);
                context.SaveChanges();

                insertId = inmain.boatInMaintenanceId;

                //find reservation id
                int reservId;
                var query = context.Reservations
                            .FirstOrDefault(x => x.memberId == MemberId && x.date >= @from && x.date <= newUntil);

                if (query != null)
                {
                    reservId = query.reservationId;

                    //remove records from reservations
                    context.Reservations.RemoveRange(context.Reservations.Where(x => x.reservationId == reservId && x.memberId == MemberId));

                    //remove records from Resevervation_boats
                    context.Reservation_Boats.RemoveRange(context.Reservation_Boats.Where(x => x.reservationId == reservId));
                    context.SaveChanges();
                }
            }
            MessageBox.Show($"Boot \"{BoatName}\" is in onderhoud genomen van {@from?.ToString("dd-MM-yyyy")} t/m {until?.ToString("dd-MM-yyyy")}.");
            Switcher.Switch(new DamageReportsScreen(FullName, AccessLevel, MemberId));
        }
        private void ReservationButton_Click(object sender, RoutedEventArgs e)
        {
            //Check if there is already a batchreservation in the database. If not, assign 1 to reservationbatch number.
            using (var context = new BootDB())
            {
                var highestBatchCount = context.Reservations.Where(c => c.reservationBatch != 0).Max(x => (int?)x.reservationBatch) ?? 0;

                if (!highestBatchCount.Equals(0))
                {
                    BatchCount = highestBatchCount + 1;
                }
                else
                {
                    BatchCount = 1;
                }
            }

            //check if selected times are possible
            foreach (var boat in SelectionList)
            {
                //getting the selected begin and end time
                try
                {
                    selectedBeginTime = (beginTimePicker.SelectedTime.Value).TimeOfDay;
                    selectedEndTime   = (endTimePicker.SelectedTime.Value).TimeOfDay;
                }
                catch (Exception)
                {
                    ErrorLabel.Content = "Geen geldige invoer";
                    return;
                }
                var check = reservation.CheckTime(selectedBeginTime, selectedEndTime, beginTime, endTime, sunUp, sunDown, false);

                //this will be executed when the selected times are not correct
                if (!check)
                {
                    ErrorLabel.Content = "Deze tijden zijn niet mogelijk";
                }
                else //when it is possible to add reservation
                {
                    using (var context = new BootDB())
                    {
                        var reservation = new Reservations
                        {
                            memberId         = MemberId,
                            date             = selectedDate,
                            beginTime        = selectedBeginTime,
                            endTime          = selectedEndTime,
                            reservationBatch = BatchCount
                        };

                        context.Reservations.Add(reservation);
                        context.SaveChanges();

                        //getting the last reservation id to add that to other table
                        var data = (from r in context.Reservations
                                    orderby r.reservationId descending
                                    select r.reservationId).First().ToString();

                        var id = int.Parse(data);

                        var reservationBoat = new Reservation_Boats
                        {
                            reservationId = id,
                            boatId        = boat.boatId
                        };

                        context.Reservation_Boats.Add(reservationBoat);
                        context.SaveChanges();
                    }
                }
            }

            if (!reservation.CheckTime(selectedBeginTime, selectedEndTime, beginTime, endTime, sunUp, sunDown, false))
            {
                return;
            }
            //show message when reservation is added to screen
            MessageBox.Show("Reservering is gelukt!", "Gelukt", MessageBoxButton.OK, MessageBoxImage.Information);

            Switcher.BackToHomePage(AccessLevel, FullName, MemberId);
        }
        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);
            }
        }