private void Activate_Disactivate_Click(object sender, RoutedEventArgs e)
        {
            //Pobieram zaznaczony samochód
            ListViewItem selected = (ListViewItem)carList.SelectedItem;

            if (selected != null)
            {
                CarList selectedObj = (CarList)selected.Content;
                int     selectedId  = selectedObj.carId;

                var db   = new AEiI_2020_BD2_Drynda_FlotaEntities();
                var cars = db.Cars;
                foreach (var car in cars)
                {
                    if (car.id == selectedId)
                    {
                        if (car.onService == true)
                        {
                            car.onService = false;
                        }
                        else if (car.onService == false)
                        {
                            car.onService = true;
                        }
                    }
                }
                db.SaveChanges();
            }
            else
            {
                MessageBox.Show("Nie wybrano samochodu!", "Komunikat");
            }
        }
Beispiel #2
0
        private void Zmien(object sender, RoutedEventArgs e)
        {
            var db = new AEiI_2020_BD2_Drynda_FlotaEntities();
            // var people = db.People;

            Person person = db.People.Where(p => toChange.id == p.id).SingleOrDefault();

            if (newLogin.Text.Length >= 6)
            {
                int personSameLogin = db.People.Where(pp => pp.systemLogin == newLogin.Text && pp.id != toChange.id).Count();
                if (personSameLogin > 0)
                {
                    MessageBox.Show("Login jest już zajęty!", "Komunikat");
                    return;
                }
                else
                {
                    person.systemLogin = newLogin.Text;
                }



                MessageBox.Show("Udało sie zmienić\nlogin!", "Komunikat");
                db.SaveChanges();
            }
            else
            {
                MessageBox.Show("Zła długość loginu!", "Komunikat");
            }
        }
        private void Zmien(object sender, RoutedEventArgs e)
        {
            var db = new AEiI_2020_BD2_Drynda_FlotaEntities();

            if (newHaslo1.Password == newHaslo2.Password)
            {
                if (newHaslo1.Password.Length >= 6)
                {
                    var person = (from people in db.People
                                  where people.id == toChange.id
                                  select people).FirstOrDefault();


                    if (person != null)
                    {
                        person.passwordHash = getHash(newHaslo1.Password);
                    }

                    MessageBox.Show("Udało sie zmienić\nhasło!", "Komunikat");
                    db.SaveChanges();
                }
                else
                {
                    MessageBox.Show("Zła długość hasła!", "Komunikat");
                }
            }
            else
            {
                MessageBox.Show("Hasła są różne", "Komunikat");
            }
        }
Beispiel #4
0
        private void zlec(object sender, RoutedEventArgs e)
        {
            var db          = new AEiI_2020_BD2_Drynda_FlotaEntities();
            var activities  = db.Activities;
            var cars        = db.Cars;
            var contractors = db.Contractors;

            if (!Kontraktorzy.Text.Equals(""))
            {
                var contractorsList = Kontraktorzy.Items;
                if (!contractorsList.Contains(Kontraktorzy.Text))
                {
                    MessageBox.Show("Wybrany kontraktor nie istnieje!", "Nie można przypisać kontraktora", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                foreach (var activity in activities)
                {
                    if (activity.id == activity1.id)
                    {
                        if (this.Serwisowa.IsChecked == true)
                        {
                            activity.service = true;
                        }
                        else if (this.Eksploatacyjna.IsChecked == true)
                        {
                            activity.service = false;
                        }
                        activity.orderDate = DateTime.Now;
                        foreach (var contractor in contractors)
                        {
                            if (contractor.name == Kontraktorzy.Text)
                            {
                                activity.Contractor = contractor;
                                Console.WriteLine("dodano: " + activity.Contractor.name);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Musisz wybrać kontraktora!", "Nie można przypisać kontraktora", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }


            foreach (var car in cars)
            {
                if (car.id == car1.id)
                {
                    car.onService = true;
                }
            }
            db.SaveChanges();
            System.Windows.Window glowneOkno = System.Windows.Application.Current.MainWindow;
            glowneOkno.DataContext = new Usterkipojazdu(userPermission, car1);
        }
Beispiel #5
0
        private void UpdateReservations()
        {
            var db          = new AEiI_2020_BD2_Drynda_FlotaEntities();
            var reservation = db.Reservations;

            foreach (var res in reservation)
            {
                if (res.returnDate <= DateTime.Now.Date && res.ended == false)
                {
                    res.ended = true;     //zakańczamy rezerwację
                }
            }
            db.SaveChanges();
        }
Beispiel #6
0
        private void Zmien(object sender, RoutedEventArgs e)
        {
            var db = new AEiI_2020_BD2_Drynda_FlotaEntities();
            var peoplePermission = db.PeoplesPermissions;

            bool newPermission = true;

            var personPermission = (from workerPermission in db.PeoplesPermissions
                                    where workerPermission.personId == toChange.id && workerPermission.Permission.name == "Kierownik"

                                    select workerPermission).FirstOrDefault();

            if (personPermission != null)
            {
                personPermission.grantDate = (System.DateTime)newKierownikStart.SelectedDate;
                if (newKierownikEnd.Text != "")
                {
                    personPermission.revokeDate = (System.DateTime)newKierownikEnd.SelectedDate;
                }
                else
                {
                    personPermission.revokeDate = null;
                }

                newPermission = false;
            }

            if (newPermission == true)          //jeśli nie jest kierownikiem dodajemy mu uprawnienie
            {
                PeoplesPermission workerPermission = new PeoplesPermission();

                workerPermission.grantDate = (System.DateTime)newKierownikStart.SelectedDate;
                if (newKierownikEnd.Text != "")
                {
                    workerPermission.revokeDate = (System.DateTime)newKierownikEnd.SelectedDate;
                }
                else
                {
                    workerPermission.revokeDate = null;
                }

                workerPermission.personId = toChange.id;
                peoplePermission.Add(workerPermission);
            }
            MessageBox.Show("Zmienieono!", "Komunikat");
            db.SaveChanges();
        }
        private void Dodaj(object sender, RoutedEventArgs e)
        {
            if (Nazwa.Text == null)
            {
                MessageBox.Show("Podaj nazwę kontrahenta");
            }
            var newContractor = new Contractor()
            {
                name      = Nazwa.Text,
                startSate = StartDate.SelectedDate.Value
            };
            var db = new AEiI_2020_BD2_Drynda_FlotaEntities();

            db.Contractors.Add(newContractor);
            db.SaveChanges();
            MessageBox.Show($"Dodano kontrahenta \"{Nazwa.Text}\"");
            Cofnij(sender, e);
        }
        private void EndClick(object sender, RoutedEventArgs e)
        {
            ListViewItem selected = (ListViewItem)contractorList.SelectedItem;

            if (selected != null)
            {
                if (((ListItem)selected.Content).endDate != null)
                {
                    MessageBox.Show("Współpraca z tym kontrahentem została już zakończona!");
                    return;
                }
                int selectedId         = ((ListItem)selected.Content).contractorId;
                var db                 = new AEiI_2020_BD2_Drynda_FlotaEntities();
                var selectedContractor = db.Contractors.Where(c => c.id == selectedId).Single();
                selectedContractor.endDate = DateTime.Now;
                db.SaveChanges();
            }
            contractorList.UnselectAll();
        }
Beispiel #9
0
        private void AddDestination(object sender, RoutedEventArgs e)
        {
            var db = new AEiI_2020_BD2_Drynda_FlotaEntities();
            var CarDestinations = db.CarDestinations;

            if (Zastosowanie.Text.Length > 0)
            {
                CarDestination newDestination = new CarDestination();
                newDestination.name = Zastosowanie.Text;
                CarDestinations.Add(newDestination);
                db.SaveChanges();
                dodajPojazd.Zastosowanie.Items.Add(newDestination.name);
                this.Close();
                MessageBox.Show("Pomyślnie dodano nowe zastosowanie pojazdu.");
            }
            else
            {
                MessageBox.Show("Pole nie może być puste!", "Błąd przy dodawaniu!", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Beispiel #10
0
        private void AddModel(object sender, RoutedEventArgs e)
        {
            var db        = new AEiI_2020_BD2_Drynda_FlotaEntities();
            var CarModels = db.CarModels;

            if (Marka.Text.Length > 0 && Model.Text.Length > 0)
            {
                CarModel newModel = new CarModel();
                newModel.make  = Marka.Text;
                newModel.model = Model.Text;
                CarModels.Add(newModel);
                db.SaveChanges();
                dodajPojazd.Model.Items.Add(newModel.make + " " + newModel.model);
                this.Close();
                MessageBox.Show("Pomyślnie dodano nowy model pojazdu.");
            }
            else
            {
                MessageBox.Show("Pola nie mogą być puste!", "Błąd przy dodawaniu!", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void fixed_button(object sender, RoutedEventArgs e)
        {
            Activity selected = (Activity)ListViewActivities.SelectedItem;

            if (selected != null)
            {
                int selectedId = selected.IDusterki;
                var db         = new AEiI_2020_BD2_Drynda_FlotaEntities();
                var activities = db.Activities;
                var cars       = db.Cars;
                foreach (var activity in activities)
                {
                    if (activity.id == selectedId)
                    {
                        if (activity.orderDate != null)
                        {
                            activity.closeDate = DateTime.Now;

                            /*foreach (var car in cars)
                             * {
                             *  if(car.id == car1.id)
                             *  {
                             *      car.Activities.Count = 0;
                             *  }
                             * }*/
                        }
                        else
                        {
                            MessageBox.Show("Jeszcze nie serwisowana!", "Komunikat");
                        }
                    }
                }
                db.SaveChanges();
                loadTable();
            }
            else
            {
                MessageBox.Show("Nie wybrano usterki!", "Komunikat");
            }
        }
Beispiel #12
0
 private void zglos(object sender, RoutedEventArgs e)
 {
     if (comment.Text.Length == 0)
     {
         MessageBox.Show("Wprowadz opis usterki", "Brak opisu usterki");
         return;
     }
     else
     {
         var db         = new AEiI_2020_BD2_Drynda_FlotaEntities();
         var activities = db.Activities;
         var activity   = new Activity();
         activity.critical   = (bool)krytyczna.IsChecked;
         activity.comments   = comment.Text;
         activity.reportDate = DateTime.Now;
         activity.service    = false;
         activity.carId      = car1.id;
         if (Logowanie.actualUser != null)
         {
             activity.reporterId = Logowanie.actualUser.id;
         }
         else
         {
             activity.reporterId = 47;
         }
         activities.Add(activity);
         db.SaveChanges();
         System.Windows.Window glowneOkno = System.Windows.Application.Current.MainWindow;
         if (whereGo == 1)
         {
             glowneOkno.DataContext = new MojePojazdy();
         }
         else if (whereGo == 2)
         {
             glowneOkno.DataContext = new MojeWypozyczenia();
         }
     }
 }
Beispiel #13
0
        private void RepurchaseCar(object sender, RoutedEventArgs e)
        {
            //Pobieram zaznaczony samochód
            ListViewItem selected = (ListViewItem)carList.SelectedItem;

            if (selected != null)
            {
                ItemList selectedObj = (ItemList)selected.Content;
                int      selectedId  = selectedObj.carId;
                selectedObj.saleDate = null;

                var db   = new AEiI_2020_BD2_Drynda_FlotaEntities();
                var cars = db.Cars;

                //Usuwam datę sprzedaży
                foreach (var car in cars)
                {
                    if (car.id == selectedId)
                    {
                        if (car.saleDate == null)
                        {
                            MessageBox.Show("Nie można kupić niesprzedanego samochodu!", "Błąd przy zakupie!", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                        car.saleDate     = null;
                        car.purchaseDate = DateTime.Today;
                        break;
                    }
                }
                db.SaveChanges();
                //Odświeżenie listy
                selected.Background = Brushes.White;
            }
            else
            {
                MessageBox.Show("Nie wybrano samochodu!", "Komunikat");
            }
        }
        private void Dodaj_Rezerwacje(object sender, RoutedEventArgs e)
        {
            int id = Logowanie.actualUser.id;

            var      db                  = new AEiI_2020_BD2_Drynda_FlotaEntities();
            var      reservations        = db.Reservations;
            var      lends               = db.Lends;
            DateTime?datePersonOut       = null;
            DateTime?actualCarLendDate   = null;
            DateTime?actualCarReturnDate = null;
            Person   personReservation   = null;
            var      person              = (from persons in db.People
                                            where persons.id == id
                                            select persons).FirstOrDefault();

            if (person != null)
            {
                datePersonOut     = person.layoffDate;
                personReservation = person;
            }
            bool doReservationCar    = true;
            bool doReservationPerson = true;

            if (ReservationStart != null && ReservationEnd != null && ReservationEnd.SelectedDate > ReservationStart.SelectedDate &&
                (datePersonOut >= ReservationEnd.SelectedDate || datePersonOut == null))     //sprawdzanie poprawności danych
            {
                var query = from reserv in db.Reservations
                            where reserv.carId.ToString() == PojazdID.Text
                            select new
                {
                    Id         = reserv,
                    CarId      = reserv.carId,
                    LendDate   = reserv.lendDate,
                    ReturnDate = reserv.returnDate,
                    Ended      = reserv.ended,
                };


                foreach (var reserv in query)
                {
                    actualCarLendDate   = reserv.LendDate;
                    actualCarReturnDate = reserv.ReturnDate;

                    if (actualCarReturnDate <= ReservationStart.SelectedDate || (actualCarLendDate >= ReservationEnd.SelectedDate) ||
                        (actualCarLendDate == null && actualCarReturnDate == null) || reserv.Ended == true)
                    {
                        doReservationCar = true;
                    }
                    else
                    {
                        doReservationCar = false;
                        break;
                    }
                }
                var query2 = from reserv in db.Reservations
                             where reserv.personId.ToString() == personReservation.id.ToString()
                             select new
                {
                    Id         = reserv,
                    CarId      = reserv.carId,
                    LendDate   = reserv.lendDate,
                    ReturnDate = reserv.returnDate,
                    Ended      = reserv.ended,
                };

                foreach (var reserv in query2)
                {
                    actualCarLendDate   = reserv.LendDate;
                    actualCarReturnDate = reserv.ReturnDate;

                    if (actualCarReturnDate <= ReservationStart.SelectedDate || (actualCarLendDate >= ReservationEnd.SelectedDate) ||
                        (actualCarLendDate == null && actualCarReturnDate == null) || reserv.Ended == true)
                    {
                        doReservationPerson = true;
                    }
                    else
                    {
                        doReservationPerson = false;
                        break;
                    }
                }


                if (doReservationCar == true && doReservationPerson == true) //sprawdzanie czy samochod jest zareezrwowany w wybranym czasie lub pracownik ma rezerwacje w tym czasie
                {
                    var newReservation = new Reservation();
                    var newLend        = new Lend();


                    newReservation.carId           = Int16.Parse(PojazdID.Text);
                    newReservation.reservationDate = ReservationDate.SelectedDate.Value;
                    newReservation.lendDate        = ReservationStart.SelectedDate.Value;
                    newReservation.returnDate      = ReservationEnd.SelectedDate;
                    newReservation.ended           = false;


                    if (PrywatneBox.IsChecked == true)
                    {
                        newReservation.@private = true;
                    }
                    else
                    {
                        newReservation.@private = false;
                    }


                    newReservation.personId = id;


                    reservations.Add(newReservation);
                    db.SaveChanges();

                    newLend.carId             = newReservation.carId;
                    newLend.personId          = newReservation.personId;
                    newLend.lendDate          = newReservation.lendDate;
                    newLend.plannedReturnDate = newReservation.returnDate;
                    newLend.@private          = (bool)newReservation.@private;
                    newLend.reservationId     = newReservation.id;
                    newLend.comments          = "Zainicjowane przez kierownika";
                    lends.Add(newLend);

                    newReservation.lendId = newLend.id;

                    db.SaveChanges();

                    MessageBox.Show("Dodano rezerwację.", "Komunikat");
                }
                else
                {
                    if (doReservationCar == false)
                    {
                        MessageBox.Show("Samochód w tym czasie \njest już zarezerwowany!", "Komunikat");
                    }
                    else if (doReservationPerson == false)
                    {
                        MessageBox.Show("Pracownik w tym czasie \njest zajęty!", "Komunikat");
                    }
                    else
                    {
                        MessageBox.Show("Pracownik i samochód w tym czasie \nsą zajęci!", "Komunikat");
                    }
                }
            }
            else
            {
                if (ReservationEnd == null && datePersonOut < ReservationEnd.SelectedDate)
                {
                    MessageBox.Show("Wybrany pracownik zostaje zwolniony\nw czasie nowej rezerwacji.", "Komunikat");
                }
                else
                {
                    MessageBox.Show("Błędne dane.", "Komunikat");
                }
            }
        }
Beispiel #15
0
        private void Dodaj_Zwolnienie(object sender, RoutedEventArgs e)
        {
            if (Kalendarz.SelectedDate != null)
            {
                var db = new AEiI_2020_BD2_Drynda_FlotaEntities();

                var carSupervisior = (from carS in db.CarSupervisors
                                      where carS.personId == personChange.id
                                      select carS).FirstOrDefault();

                if (carSupervisior != null)
                {
                    carSupervisior.endDate = Kalendarz.SelectedDate;
                }

                var person = (from people in db.People
                              where people.id == personChange.id
                              select people).FirstOrDefault();

                if (person != null)
                {
                    person.layoffDate = Kalendarz.SelectedDate;
                }

                var reservation = db.Reservations;
                foreach (var res in reservation)
                {
                    if (res.personId == personChange.id && res.ended == false)
                    {
                        if (res.returnDate > Kalendarz.SelectedDate)
                        {
                            res.ended = true; //zakańczamy rezerwację przy zwolnienu pracownika zostawiamy daty startu i końca
                        }
                    }
                }
                var lends = db.Lends;
                foreach (var lend in lends)
                {
                    if (lend.personId == personChange.id)
                    {
                        lend.returnDate        = Kalendarz.SelectedDate;
                        lend.plannedReturnDate = Kalendarz.SelectedDate;
                        lend.comments          = "Zakończono przez zwolnienie pracownika - " + DateTime.Now.ToString();
                    }
                }
                var permissions = db.PeoplesPermissions;
                foreach (var permission in permissions)
                {
                    if (permission.personId == personChange.id)
                    {
                        permission.revokeDate = Kalendarz.SelectedDate; //zamykamy wszyskie uprawnienia pracownika
                    }
                }
                MessageBox.Show("Ustawiono zwolnienie!", "Komunikat");
                db.SaveChanges();
            }
            else
            {
                MessageBox.Show("Zła data zwolnienia!", "Komunikat");
            }
            this.Close();
        }
Beispiel #16
0
        private void DeleteCar(object sender, RoutedEventArgs e)
        {
            //Pobieram zaznaczony samochód
            ListViewItem selected = (ListViewItem)carList.SelectedItem;

            if (selected != null)
            {
                ItemList         selectedObj = (ItemList)selected.Content;
                int              selectedId  = selectedObj.carId;
                MessageBoxResult result      = MessageBox.Show("Czy na pewno chcesz usunąć pojazd " + selectedObj.registration + "?"
                                                               , "Potwierdź usunięcie", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
                if (result != MessageBoxResult.Yes)
                {
                    return;
                }
                //Usuwam zaznaczony samochód z listy

                /*items.Remove((ListViewItem)carList.SelectedItem);
                 * carList.ItemsSource = items;*/

                var db   = new AEiI_2020_BD2_Drynda_FlotaEntities();
                var cars = db.Cars;

                //Usuwam zaznaczony samochód z bazy
                foreach (var car in cars)
                {
                    if (car.id == selectedId)
                    {
                        db.Cars.Remove(car);
                        break;
                    }
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    var reservations = db.Reservations;
                    foreach (var reservation in reservations)
                    {
                        if (reservation.carId == selectedId)
                        {
                            MessageBox.Show("Istnieją rezerwacje powiązane z " + selectedObj.registration
                                            + ", nie można usunąć tego pojazdu?"
                                            , "Błąd przy usuwaniu", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }

                    var lends = db.Lends;
                    foreach (var lend in lends)
                    {
                        if (lend.carId == selectedId)
                        {
                            MessageBox.Show("Istnieją wypożyczenia powiązane z " + selectedObj.registration
                                            + ", nie można usunąć tego pojazdu?"
                                            , "Błąd przy usuwaniu", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }

                    MessageBox.Show("Usunięto samochód", "Informacja");
                    items.Remove(selected);
                    carList.ItemsSource = items;
                    carList.Items.Refresh();
                    db.SaveChanges();
                }
            }
            else
            {
                MessageBox.Show("Nie wybrano samochodu!", "Komunikat");
            }
        }
Beispiel #17
0
        private void Zakoncz_Rezerwacje(object sender, RoutedEventArgs e)
        {
            ListViewItem selected = (ListViewItem)ListViewReservations.SelectedItem;

            if (selected != null)
            {
                ReservationList selectedObj = (ReservationList)selected.Content;

                int selectedId        = selectedObj.ReservationId - 1;
                var reservationPerson = selectedObj.Person;
                var db = new AEiI_2020_BD2_Drynda_FlotaEntities();

                Reservation reservationChange = null;

                var reservation = (from reserv in db.Reservations
                                   where reserv.id == selectedId
                                   select reserv).FirstOrDefault();


                if (reservation != null)
                {
                    reservationChange = reservation;
                }

                if (reservationChange.ended == true)
                {
                    MessageBox.Show("Rezerwacja się zakończyła!", "Komunikat");
                }

                else
                {
                    DialogResult result = MessageBox.Show("Czy chcesz zakonczyc rezerwację " + reservationPerson + "?"
                                                          , "Komunikat", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        reservationChange.ended = true;
                        var lend = (from lends in db.Lends
                                    where lends.reservationId == reservationChange.id
                                    select lends).FirstOrDefault();


                        if (lend != null)
                        {
                            lend.returnDate = DateTime.Now.Date;
                            if (Logowanie.actualUser != null)
                            {
                                lend.comments += "Zakończono przez zakończenie\nrezerwacji przez Kierownika " + Logowanie.actualUser.id + ") " +
                                                 Logowanie.actualUser.firstName + " " + Logowanie.actualUser.lastName + " - " + DateTime.Now.ToString() + "\n";
                            }
                        }
                        db.SaveChanges();

                        ListViewReservations.ItemsSource = null;
                        items.Clear();
                        UpdateView();
                    }
                    else if (result == DialogResult.No)
                    {
                    }
                }
            }
            else
            {
                MessageBox.Show("Niczego nie wybrano !", "Komunikat");
            }
        }
Beispiel #18
0
        private void Zmien_Dane_Rezerwacji(object sender, RoutedEventArgs e)
        {
            var      db                  = new AEiI_2020_BD2_Drynda_FlotaEntities();
            DateTime?datePersonOut       = null;
            DateTime?actualCarLendDate   = null;
            DateTime?actualCarReturnDate = null;
            Person   personReservation   = null;

            if (Rejestracja.Text == "" || PojemnoscSilnika.Text == "" ||
                Marka.Text == "" || Model.Text == "" || Zastosowanie.Text == "")
            {
                MessageBox.Show("Złe dane pojazdu.", "Komunikat");
                return;
            }

            var worker = (from persons in db.People
                          where (persons.id.ToString() + ") " + persons.firstName + " " + persons.lastName).Equals(Pracownicy.Text)
                          select persons).FirstOrDefault();

            if (worker != null)
            {
                datePersonOut     = worker.layoffDate;
                personReservation = worker;
            }
            bool doReservationCar    = true;
            bool doReservationPerson = true;

            if (datePersonOut != null && ReservationEnd.SelectedDate != null && datePersonOut < ReservationEnd.SelectedDate)
            {
                MessageBox.Show("Wybrany pracownik zostaje zwolniony\nw czasie nowej rezerwacji.", "Komunikat");
            }
            else if (ReservationStart.SelectedDate != null && ReservationEnd.SelectedDate != null &&
                     ReservationEnd.SelectedDate > ReservationStart.SelectedDate //prawdopodobnie zbędna linia, DatePickery chyba przed tym bronią
                     )                                                           //sprawdzanie poprawności danych
            {
                var query = from reserv in db.Reservations
                            where reserv.carId.ToString() == PojazdID.SelectedItem.ToString() && reserv.id != this.reservationChange.id
                            select new
                {
                    Id         = reserv,
                    CarId      = reserv.carId,
                    LendDate   = reserv.lendDate,
                    ReturnDate = reserv.returnDate,
                    Ended      = reserv.ended,
                };

                if (query == null)
                {
                    doReservationCar = true;
                }
                else
                {
                    foreach (var reserv in query)
                    {
                        actualCarLendDate   = reserv.LendDate;
                        actualCarReturnDate = reserv.ReturnDate;

                        if (actualCarReturnDate <= ReservationStart.SelectedDate || (actualCarLendDate >= ReservationEnd.SelectedDate) ||
                            (actualCarLendDate == null && actualCarReturnDate == null) || reserv.Ended == true)
                        {
                            doReservationCar = true;
                        }
                        else
                        {
                            doReservationCar = false;
                            break;
                        }
                    }
                }
                var query2 = from reserv in db.Reservations
                             where reserv.personId.ToString() == personReservation.id.ToString() && reserv.id != this.reservationChange.id
                             select new
                {
                    Id         = reserv,
                    CarId      = reserv.carId,
                    LendDate   = reserv.lendDate,
                    ReturnDate = reserv.returnDate,
                    Ended      = reserv.ended,
                };
                if (query2 == null)
                {
                    doReservationPerson = true;
                }
                else
                {
                    foreach (var reserv in query2)
                    {
                        actualCarLendDate   = reserv.LendDate;
                        actualCarReturnDate = reserv.ReturnDate;

                        if (actualCarReturnDate <= ReservationStart.SelectedDate || (actualCarLendDate >= ReservationEnd.SelectedDate) ||
                            (actualCarLendDate == null && actualCarReturnDate == null) || reserv.Ended == true)
                        {
                            doReservationPerson = true;
                        }
                        else
                        {
                            doReservationPerson = false;
                            break;
                        }
                    }
                }

                if (doReservationCar == true && doReservationPerson == true) //sprawdzanie czy samochod jest zareezrwowany w wybranym czasie lub pracownik ma rezerwacje w tym czasie
                {
                    Reservation reservationChange = null;

                    var reservation = (from reserv in db.Reservations
                                       where reserv.id == this.reservationChange.id
                                       select reserv).FirstOrDefault();

                    if (reservation != null)
                    {
                        reservationChange = reservation;
                    }

                    reservationChange.carId           = Int16.Parse(PojazdID.SelectedItem.ToString());
                    reservationChange.reservationDate = ReservationDate.SelectedDate.Value;
                    reservationChange.lendDate        = ReservationStart.SelectedDate.Value;
                    reservationChange.returnDate      = ReservationEnd.SelectedDate;
                    reservationChange.ended           = false;

                    if (PrywatneBox.IsChecked == true)
                    {
                        reservationChange.@private = true;
                    }
                    else
                    {
                        reservationChange.@private = false;
                    }


                    reservationChange.personId = worker.id;

                    db.SaveChanges();

                    var lend = (from lendd in db.Lends
                                where lendd.reservationId == reservationChange.id
                                select lendd).FirstOrDefault();

                    if (lend != null)
                    {
                        lend.carId             = reservationChange.carId;
                        lend.personId          = reservationChange.personId;
                        lend.lendDate          = reservationChange.lendDate;
                        lend.plannedReturnDate = reservationChange.returnDate;
                        lend.@private          = (bool)reservationChange.@private;
                        lend.comments         += "\nZmiana w dniu " + DateTime.Now.ToShortDateString();
                    }

                    db.SaveChanges();

                    MessageBox.Show("Zmodyfikowano rezerwację.", "Komunikat");
                }
                else
                {
                    if (doReservationCar == false)
                    {
                        MessageBox.Show("Samochód w tym czasie \njest już zarezerwowany!", "Komunikat");
                    }
                    else if (doReservationPerson == false)
                    {
                        MessageBox.Show("Pracownik w tym czasie \njest zajęty!", "Komunikat");
                    }
                    else
                    {
                        MessageBox.Show("Pracownik i samochód w tym czasie \nsą zajęci!", "Komunikat");
                    }
                }
            }
            else
            {
                MessageBox.Show("Błędne dane.", "Komunikat");
            }
        }
        private void Zakoncz_Wypozyczenie(object sender, RoutedEventArgs e)
        {
            ListViewItem selected = (ListViewItem)ListViewLends.SelectedItem;

            if (selected != null)
            {
                LendList selectedObj = (LendList)selected.Content;

                int  selectedId = selectedObj.LendId - 1;
                var  db         = new AEiI_2020_BD2_Drynda_FlotaEntities();
                Lend lendChange = null;

                var lend = (from lendd in db.Lends
                            where lendd.id == selectedId
                            select lendd).FirstOrDefault();

                if (lend != null)
                {
                    lendChange = lend;
                }


                if (lendChange.returnDate <= DateTime.Now || lendChange.Reservation.ended == true)
                {
                    MessageBox.Show("Wypożyczenie się zakończyło!", "Komunikat");
                }
                else if (lendChange.lendDate > DateTime.Now)
                {
                    MessageBox.Show("Wypożyczenie się jeszcze\nnie rozpoczeło!", "Komunikat");
                }

                else
                {
                    DialogResult result = MessageBox.Show("Czy chcesz zakonczyc wypożyczenie ?"
                                                          , "Komunikat", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        lendChange.returnDate = DateTime.Now.Date;

                        lendChange.comments += "Zakończono przez zakończenie\nwypożyczenia przez pracownika " + Logowanie.actualUser.id + ") " +
                                               Logowanie.actualUser.firstName + " " + Logowanie.actualUser.lastName + " - " + DateTime.Now.ToString() + "\n";
                        //   var reservations = db.Reservations;

                        var reservation = (from reserv in db.Reservations
                                           where lendChange.id == reserv.lendId
                                           select reserv).FirstOrDefault();


                        reservation.ended = true;
                        db.SaveChanges();

                        ListViewLends.ItemsSource = null;
                        items.Clear();
                        UpdateView();
                    }
                    else if (result == DialogResult.No)
                    {
                    }
                }
            }
            else
            {
                MessageBox.Show("Nic nie wybrano !", "Komunikat");
            }
        }
Beispiel #20
0
        private void Dodaj_Pracownika(object sender, RoutedEventArgs e)
        {
            var  db         = new AEiI_2020_BD2_Drynda_FlotaEntities();
            var  workers    = db.People;
            var  newWorker  = new Person();
            bool loginCheck = true;

            if (Hasło1.Password != Hasło2.Password)
            {
                MessageBox.Show("Hasła są różne!", "Komunikat");
            }
            else
            if (Imie.Text.Length >= 3 && Nazwisko.Text.Length >= 3 && Login.Text.Length >= 6 && Hasło1.Password.Length >= 6)
            {
                int personSameLogin = db.People.Where(pp => pp.systemLogin == Login.Text).Count();

                if (personSameLogin > 0)
                {
                    loginCheck = false;
                }
                if (loginCheck == false)
                {
                    MessageBox.Show("Login jest zajęty!", "Komunikat");
                }
                else if (DzienZatrudnienia.SelectedDate != null)
                {
                    newWorker.firstName      = Imie.Text;
                    newWorker.lastName       = Nazwisko.Text;
                    newWorker.systemLogin    = Login.Text;
                    newWorker.employmentData = DzienZatrudnienia.SelectedDate.Value;
                    newWorker.passwordHash   = getHash(Hasło1.Password);
                    workers.Add(newWorker);
                    db.SaveChanges();

                    if (KierownikBox.IsChecked == true)
                    {
                        var permissionCompany = db.Permissions;
                        var peoplePermission  = db.PeoplesPermissions;
                        var workerPermission  = new PeoplesPermission();
                        if (DzienZatrudnienia.SelectedDate == null || DzienKierownictwaStart.SelectedDate < newWorker.employmentData) //jeżeli nie podano od kiedy kierownikiem, lub jest kierownikiem dłużej niż pracuje: błąd
                        {
                            workers.Remove(newWorker);
                            db.SaveChanges();
                            MessageBox.Show("Błedna data początku", "Komunikat");
                            return;
                        }
                        if (DzienKierownictwaEnd.SelectedDate <= DzienKierownictwaStart.SelectedDate)
                        {
                            workers.Remove(newWorker);
                            db.SaveChanges();
                            MessageBox.Show("Błedna data zakonczenia kierownictwa", "Komunikat");
                            return;
                        }
                        else if (DzienKierownictwaEnd.Text != "")
                        {
                            workerPermission.revokeDate = (System.DateTime)DzienKierownictwaEnd.SelectedDate;
                        }
                        else
                        {
                            workerPermission.revokeDate = null;
                        }

                        foreach (var permissionComp in permissionCompany)
                        {
                            if (permissionComp.name == "Kierownik")
                            {
                                workerPermission.permissionId = permissionComp.Id;
                            }
                        }
                        workerPermission.grantDate = DzienKierownictwaStart.SelectedDate.Value; //od razu staje się kierownikiem
                        workerPermission.personId  = newWorker.id;
                        peoplePermission.Add(workerPermission);
                        db.SaveChanges();
                    }

                    MessageBox.Show("Dodano Pracownika: " + (newWorker.id + 1).ToString() + " " + newWorker.firstName + "\n" + newWorker.lastName, "Komunikat");
                }
                else
                {
                    MessageBox.Show("Zła data zatrudnienia!", "Komunikat");
                }
            }
            else
            {
                MessageBox.Show("Błędne dane rejestracji!", "Komunikat");
            }
        }
Beispiel #21
0
        private void Zmiana_Opiekuna(object sender, RoutedEventArgs e)
        {
            var    db   = new AEiI_2020_BD2_Drynda_FlotaEntities();
            string temp = Opiekunowie.Text;

            if (!temp.Equals(""))
            {
                var carSupervisors = db.CarSupervisors;
                var newSupervisor  = new CarSupervisor();

                var carSupervisorsList = Opiekunowie.Items;
                if (!carSupervisorsList.Contains(temp))
                {
                    MessageBox.Show("Wybrany opiekun nie istnieje!", "Nie można przypisać opiekuna", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                //Szukam dotychczasowego opiekuna i ustawiam mu date konca
                foreach (var carSupervisor in carSupervisors)
                {
                    if (carSupervisor.carId == toChange.id && carSupervisor.endDate == null)
                    {
                        carSupervisor.endDate = DateTime.Today;
                        break;
                    }
                }

                newSupervisor.carId     = toChange.id;
                newSupervisor.beginDate = DateTime.Today;
                newSupervisor.endDate   = null;

                var People = db.People;

                foreach (var human in People)
                {
                    string fullName = human.firstName + " " + human.lastName;
                    if (fullName.Equals(temp))
                    {
                        newSupervisor.Person       = human;
                        itemToChange.carSupervisor = fullName;
                    }
                }

                bool againSupervisor = false;
                foreach (var carSupervisor in carSupervisors)
                {
                    //Sprawdzam czy taki opiekun już istnieje, jeżeli tak, zmieniam jego endDate?
                    if (carSupervisor.personId == newSupervisor.Person.id && carSupervisor.carId == newSupervisor.carId)
                    {
                        carSupervisor.endDate   = null;
                        carSupervisor.beginDate = DateTime.Today;
                        againSupervisor         = true;
                        break;
                    }
                }
                if (!againSupervisor)
                {
                    carSupervisors.Add(newSupervisor);
                }
                db.SaveChanges();
            }
            else
            {
                var carSupervisors = db.CarSupervisors;
                //Szukam dotychczasowego opiekuna i ustawiam mu date konca
                foreach (var carSupervisor in carSupervisors)
                {
                    if (carSupervisor.carId == toChange.id && carSupervisor.endDate == null)
                    {
                        carSupervisor.endDate      = DateTime.Today;
                        itemToChange.carSupervisor = "Brak";
                        break;
                    }
                }
                db.SaveChanges();
            }
            this.Close();
        }