int CompareLendByDateReservationDescending(ListViewItem a, ListViewItem b)
        {
            LendList first  = (LendList)a.Content;
            LendList second = (LendList)b.Content;
            DateTime firstDate;
            DateTime secondDate;

            if (first.ReservationDate.CompareTo("") != 0)
            {
                firstDate = Convert.ToDateTime(first.ReservationDate);
            }
            else
            {
                firstDate = DateTime.MinValue;
            }
            if (second.ReservationDate.CompareTo("") != 0)
            {
                secondDate = Convert.ToDateTime(second.ReservationDate);
            }
            else
            {
                secondDate = DateTime.MinValue;
            }
            return(DateTime.Compare(secondDate, firstDate));
        }
        int CompareLendByDatePlannedEndAscending(ListViewItem a, ListViewItem b)
        {
            LendList first  = (LendList)a.Content;
            LendList second = (LendList)b.Content;
            DateTime firstDate;
            DateTime secondDate;

            if (first.LendPlannedEnd.CompareTo("") != 0)
            {
                firstDate = Convert.ToDateTime(first.LendPlannedEnd);
            }
            else
            {
                firstDate = DateTime.MinValue;
            }
            if (second.LendPlannedEnd.CompareTo("") != 0)
            {
                secondDate = Convert.ToDateTime(second.LendPlannedEnd);
            }
            else
            {
                secondDate = DateTime.MinValue;
            }
            return(DateTime.Compare(firstDate, secondDate));
        }
        int CompareCarDescending(ListViewItem a, ListViewItem b)
        {
            LendList first  = (LendList)a.Content;
            LendList second = (LendList)b.Content;

            return(String.Compare(second.Vehicle, first.Vehicle));
        }
        int CompareLendByPersonDescending(ListViewItem a, ListViewItem b)
        {
            LendList first  = (LendList)a.Content;
            LendList second = (LendList)b.Content;

            return(String.Compare(second.Person, first.Person));
        }
        int CompareLendByIdDescending(ListViewItem a, ListViewItem b)
        {
            LendList first  = (LendList)a.Content;
            LendList second = (LendList)b.Content;

            return(second.LendId.CompareTo(first.LendId));
        }
        private void Statystyki_Wypozyczenia(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();
                var      lends       = db.Lends;
                Lend     lendChange  = null;


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

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

                if (lendChange.lendDate > DateTime.Now.Date || lendChange.returnDate <= lendChange.lendDate.Date)
                {
                    MessageBox.Show("Wypożyczenie nie zaczeło się!", "Komunikat");
                }
                else
                {
                    System.Windows.Window glowneOkno = System.Windows.Application.Current.MainWindow;
                    glowneOkno.DataContext = new StatystykiWypozyczenia(lendChange, true);
                }
            }
            else
            {
                MessageBox.Show("Niczego nie wybrano !", "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");
            }
        }