예제 #1
0
        public static Users Login(string UserLogin, string Password)
        {
            Users user = new Users();

            using (PodrozeEntities context = new PodrozeEntities())
            {
                List <Users> users = context.Users.Where(c => c.Login == UserLogin.ToLower()).ToList();
                if (users.Count > 0)
                {
                    string _password = users[0].Password;
                    if (_password == Password)
                    {
                        return(users[0]);
                    }
                    else
                    {
                        MessageBox.Show("Nieprawidłowe hasło");
                    }
                }
                else
                {
                    MessageBox.Show("Nie znaleziono użytkownika");
                }
            }
            return(user);
        }
예제 #2
0
        public string AddCar(string Brand, string Model, string RegistrationNumber, short NumberOfSeats)
        {
            if (NumberOfSeats <= maxNumberOfSeats)
            {
                if (checkCarInDatabase(RegistrationNumber) == false)
                {
                    using (PodrozeEntities context = new PodrozeEntities())
                    {
                        Cars cars = new Cars();
                        cars.Brand = Brand;
                        cars.Model = Model;
                        cars.RegistrationNumber = RegistrationNumber;
                        cars.NumberOfSeats      = NumberOfSeats;
                        cars.Active             = true;
                        context.Cars.Add(cars);

                        context.SaveChanges();
                        System.Windows.Forms.MessageBox.Show("Pojazd " + Brand + " " + Model + " " + RegistrationNumber + " został utworzony");
                        return("CarAdded");
                    }
                }
                else
                {
                    // System.Windows.Forms.MessageBox.Show("Pojazd " + Brand + " " + Model + " " + RegistrationNumber + " istnieje w bazie");

                    using (PodrozeEntities context = new PodrozeEntities())
                    {
                        Cars carar = new Cars();
                        carar = context.Cars.Where(c => c.RegistrationNumber == RegistrationNumber).First();
                        if (carar.Active == true)
                        {
                            System.Windows.Forms.MessageBox.Show("Pojazd " + Brand + " " + Model + " " + RegistrationNumber + " istnieje w bazie");
                            return("CarExists");
                        }
                        else
                        {
                            if (System.Windows.Forms.DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Pojazd o numerze rejestracyjnym " + RegistrationNumber + " istnieje w bazie pojazdów jako nieaktywny. Czy chcesz przywrócić samochód? Pojazd zostanie przywrócony z poprzednimi parametrami", "Info", System.Windows.Forms.MessageBoxButtons.YesNo))
                            {
                                carar.Active = true;
                                context.SaveChanges();
                                return("CarAdded");
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("Zaniechano dodawania pojazdu");
                                return("addAborted");
                            }
                        }
                    }
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("liczba miejsc w samochodze nie może być większa niż " + maxNumberOfSeats.ToString());
                return("toManySeats");
            }
        }
예제 #3
0
 public static void RemoveTrip(int TripId)
 {
     using (PodrozeEntities context = new PodrozeEntities())
     {
         BusinessTrips businessTrip = context.BusinessTrips.Where(c => c.Id == TripId).First();
         businessTrip.Active = false;
         context.SaveChanges();
     }
 }
예제 #4
0
        public static List <string> GetUsers()
        {
            List <string> users = new List <string>();

            using (PodrozeEntities context = new PodrozeEntities())
            {
                users = context.Users.Where(c => c.Active == true).Select(c => c.Login).ToList();
            }
            return(users);
        }
예제 #5
0
        public static int GetCarIdByRegistration(string registration)
        {
            int car;

            using (PodrozeEntities context = new PodrozeEntities())
            {
                car = context.Cars.Where(c => c.RegistrationNumber == registration).Select(c => c.Id).First();
            }
            return(car);
        }
예제 #6
0
 public void deleteUser(Users user)
 {
     using (PodrozeEntities context = new PodrozeEntities())
     {
         int Id = user.Id;
         user        = context.Users.Where(c => c.Id == Id).First();
         user.Active = false;
         context.SaveChanges();
     }
 }
예제 #7
0
 public void deleteCar(Cars cars)
 {
     using (PodrozeEntities context = new PodrozeEntities())
     {
         int Id = cars.Id;
         cars        = context.Cars.Where(c => c.Id == Id).First();
         cars.Active = false;
         context.SaveChanges();
     }
 }
예제 #8
0
 public static int GetNotReservedPlaces(BusinessClasses.TravelsGrid tg)
 {
     using (PodrozeEntities context = new PodrozeEntities())
     {
         int carId          = context.Cars.Where(c => c.RegistrationNumber == tg.RegistrationNumber).Select(c => c.Id).First();
         int reservedPlaces = context.BusinessTrips.Where(c => c.ArrivalDate == tg.ArrivalDate && c.DepartureDate == tg.DepartureDate && c.CarId == carId).Count();
         int carPlaces      = context.Cars.Where(c => c.Id == carId).Select(c => c.NumberOfSeats).First();
         return(carPlaces - reservedPlaces);
     }
 }
        public void refreshCarList()
        {
            List <Cars>     cars     = new List <Cars>();
            PodrozeEntities context1 = new PodrozeEntities();

            cars = context1.Cars.Where(c => c.Active == true).ToList();
            dataGridViewCars.DataSource         = cars;
            dataGridViewCars.Columns[5].Visible = false;
            dataGridViewCars.Columns[6].Visible = false;
        }
예제 #10
0
        public List <string> getDepartments()
        {
            PodrozeEntities context1              = new PodrozeEntities();
            List <string>   departments           = new List <string>();
            var             departmentsInDatabase = (from department in context1.Departments
                                                     where department.Active == true
                                                     select department.DepartmentName);

            departments = departmentsInDatabase.ToList();
            return(departments);
        }
        public void refreshUserList()
        {
            List <Users>    user     = new List <Users>();
            PodrozeEntities context1 = new PodrozeEntities();

            user = context1.Users.Where(c => c.Active == true).ToList();
            dataGridViewUsers.DataSource         = user;
            dataGridViewUsers.Columns[5].Visible = false;
            dataGridViewUsers.Columns[6].Visible = false;
            dataGridViewUsers.Columns[7].Visible = false;
            dataGridViewUsers.Columns[8].Visible = false;
        }
예제 #12
0
        public static List <TravelsGrid> GetTravelsList(DateTime DepartureDate, DateTime ArrivalDate, int DayTolerance, string Lat, string Lng)
        {
            List <TravelsGrid> TravelsGridList = new List <TravelsGrid>();

            using (PodrozeEntities context = new PodrozeEntities())
            {
                DateTime departureDateFrom = DepartureDate.AddDays(DayTolerance * (-1));
                DateTime departureDateTo   = DepartureDate.AddDays(DayTolerance);
                DateTime arrivalDateFrom   = ArrivalDate.AddDays(DayTolerance * (-1));
                DateTime arrivalDateTo     = ArrivalDate.AddDays(DayTolerance);

                var travelListQuery = (from BusinessTrip in context.BusinessTrips
                                       where BusinessTrip.DepartureDate >= departureDateFrom &&
                                       BusinessTrip.DepartureDate <= departureDateTo &&
                                       BusinessTrip.ArrivalDate >= arrivalDateFrom &&
                                       BusinessTrip.ArrivalDate <= arrivalDateTo &&
                                       BusinessTrip.Active == true
                                       select BusinessTrip)
                                      .Include(x => x.Users)
                                      .Include(x => x.Destinations)
                                      .Include(x => x.Cars);

                List <BusinessTrips> BusinessTripsList = travelListQuery.ToList();

                foreach (BusinessTrips businessTrip in BusinessTripsList)
                {
                    TravelsGrid travel = new TravelsGrid();
                    travel.TripId             = businessTrip.Id;
                    travel.UserName           = businessTrip.Users.SurName + " " + businessTrip.Users.FirstName;
                    travel.Address            = businessTrip.Destinations.Address;
                    travel.RegistrationNumber = businessTrip.Cars.RegistrationNumber;
                    travel.DepartureDate      = businessTrip.DepartureDate;
                    travel.ArrivalDate        = businessTrip.ArrivalDate;
                    travel.Lat = businessTrip.Destinations.Latitude;
                    travel.Lng = businessTrip.Destinations.Longitude;
                    string startGeolocation = travel.Lat.ToString().Replace(',', '.') + ',' + travel.Lng.ToString().Replace(',', '.');
                    string endGeolocation   = Lat.Replace(',', '.') + ',' + Lng.Replace(',', '.');
                    if (startGeolocation == endGeolocation)
                    {
                        travel.Distance = "0";
                        travel.Duration = "0";
                    }
                    else
                    {
                        Dictionary <string, string> result = GoogleApi.GenerateRoute.GetDistance(startGeolocation, endGeolocation, "");
                        travel.Distance = result["distance"];
                        travel.Duration = result["duration"];
                    }
                    TravelsGridList.Add(travel);
                }
            }
            return(TravelsGridList);
        }
예제 #13
0
        public List <string> getUsersLogins()
        {
            List <string> users = new List <string>();

            using (PodrozeEntities context1 = new PodrozeEntities())
            {
                var usersInDatabase = (from user in context1.Users
                                       where user.Active == true
                                       select user.Login);
                users = usersInDatabase.ToList();
            }
            return(users);
        }
예제 #14
0
 public static int AddDestination(string Address, string Latitude, string Longitude)
 {
     using (PodrozeEntities context = new PodrozeEntities())
     {
         Destinations destination = new Destinations();
         destination.Address   = Address;
         destination.Latitude  = Latitude;
         destination.Longitude = Longitude;
         destination.Active    = true;
         context.Destinations.Add(destination);
         context.SaveChanges();
         return(destination.Id);
     }
 }
예제 #15
0
        public static List <Cars> GetCars(List <string> reservedCars)
        {
            List <Cars> cars = new List <Cars>();

            using (PodrozeEntities context = new PodrozeEntities())
            {
                cars = context.Cars.Where(c => c.Active == true).ToList();
                foreach (string registration in reservedCars)
                {
                    cars.RemoveAll(c => c.RegistrationNumber == registration);
                }
            }
            return(cars);
        }
예제 #16
0
 public static int AddBusinessTrip(int CarId, int DestinationId, int UserId, DateTime DepartureDate, DateTime ArrivalDate)
 {
     using (PodrozeEntities context = new PodrozeEntities())
     {
         BusinessTrips businessTrip = new BusinessTrips();
         businessTrip.CarId         = CarId;
         businessTrip.DestinationId = DestinationId;
         businessTrip.UserId        = UserId;
         businessTrip.DepartureDate = DepartureDate;
         businessTrip.ArrivalDate   = ArrivalDate;
         businessTrip.Active        = true;
         context.BusinessTrips.Add(businessTrip);
         int savesDate = context.SaveChanges();
         return(businessTrip.Id);
     }
 }
 private void button1_Click_1(object sender, EventArgs e)
 {
     using (PodrozeEntities context = new PodrozeEntities())
     {
         if (dataGridViewUsers.SelectedRows.Count > 0)
         {
             Users           user   = (Users)dataGridViewUsers.SelectedRows[0].DataBoundItem;
             SuperVisorUsers superV = new SuperVisorUsers();
             superV.deleteUser(user);
         }
         else
         {
             MessageBox.Show("Zaznacz wiersz na liście poniżej w celu usunięcia użytkownika");
         }
     }
     refreshUserList();
 }
예제 #18
0
        public static int GetUserId(string Login)
        {
            int userId = -1;

            using (PodrozeEntities context = new PodrozeEntities())
            {
                List <int> users = context.Users.Where(c => c.Login == Login.ToLower()).Select(c => c.Id).ToList();
                if (users.Count > 0)
                {
                    userId = users[0];
                }
                else
                {
                    MessageBox.Show("Nie znaleziono użytkownika");
                }
            }
            return(userId);
        }
예제 #19
0
        public bool checkUserInDatabase(string checkedUser)
        {
            bool isUserInDatabase = false;

            using (PodrozeEntities context = new PodrozeEntities())
            {
                var userInDatabase = (from user in context.Users
                                      where user.Login == checkedUser
                                      select user
                                      );
                List <Users> userList = userInDatabase.ToList();
                if (userList.Count != 0)
                {
                    isUserInDatabase = true;
                }
            }
            return(isUserInDatabase);
        }
예제 #20
0
 public void AddUser(string Login, string Password, string FirstName, string SurName, int DepartmentId)
 {
     if (checkUserInDatabase(Login) == false)
     {
         using (PodrozeEntities context = new PodrozeEntities())
         {
             Users users = new Users();
             users.Login        = Login.ToLower();
             users.Password     = Password;
             users.FirstName    = FirstName;
             users.SurName      = SurName;
             users.DepartmentId = DepartmentId;
             users.Active       = true;
             context.Users.Add(users);
             context.SaveChanges();
             System.Windows.Forms.MessageBox.Show("Użytkownik " + Login + " został utworzony");
         }
     }
     else
     {
         System.Windows.Forms.MessageBox.Show("Użytkownik " + Login + " znajduje się już w bazie danych");
     }
 }
예제 #21
0
        public bool checkCarInDatabase(string registrationNumber)
        {
            bool isCarInDatabase = false;

            using (PodrozeEntities context = new PodrozeEntities())
            {
                var carInDatabase = (from car in context.Cars
                                     where car.RegistrationNumber == registrationNumber
                                     select car
                                     );
                List <Cars> carList = carInDatabase.ToList();
                if (carList.Count != 0)
                {
                    isCarInDatabase = true;

                    //  System.Windows.Forms.MessageBox.Show("w bazie jest "+ carList.Count.ToString() + " samochodów o rejestracji " + registrationNumber);
                }
                else
                {
                    //  System.Windows.Forms.MessageBox.Show("Brak w bazie samochodu o rejestracji " + registrationNumber);
                }
            }
            return(isCarInDatabase);
        }
예제 #22
0
        public string AddUser(string Login, string Password, string Password2, string FirstName, string SurName, string Department)
        {
            int DepartmentId = 1;

            if (checkUserInDatabase(Login) == false)
            {
                if (Password == Password2)
                {
                    using (PodrozeEntities context = new PodrozeEntities())
                    {
                        var depart = (from department in context.Departments
                                      where department.DepartmentName == Department
                                      select department.Id
                                      );
                        DepartmentId = depart.ToList()[0];
                        Users users = new Users();
                        //  users.Id = Id;
                        users.Login        = Login;
                        users.Password     = Password;
                        users.FirstName    = FirstName;
                        users.SurName      = SurName;
                        users.DepartmentId = DepartmentId;
                        users.Active       = true;
                        context.Users.Add(users);
                        context.SaveChanges();
                        System.Windows.Forms.MessageBox.Show("Użytkownik " + Login + " został utworzony");
                    }
                    return("userAdded");
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("wpisane hasła nie są jednakowe");
                    return("passwordMismatch");
                }
            }
            else
            {
                using (PodrozeEntities context = new PodrozeEntities())
                {
                    Users user = new Users();
                    user = context.Users.Where(c => c.Login == Login).First();
                    if (user.Active == true)
                    {
                        System.Windows.Forms.MessageBox.Show("Użytkownik " + Login + " znajduje się już w bazie danych");
                        return("userExists");
                    }
                    else
                    {
                        if (System.Windows.Forms.DialogResult.Yes == System.Windows.Forms.MessageBox.Show("Użytkownik " + Login + " znajduje się w bazie użytkowników jako nieaktywny. Czy chcesz przywrócić użytkownika? Użytkownik zostanie przywrócony z poprzednimi parametrami", "Info", System.Windows.Forms.MessageBoxButtons.YesNo))
                        {
                            user.Active = true;
                            context.SaveChanges();
                            return("userReplaced");
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("Zaniechano dodawania użytkownika");
                            return("userAddAbort");
                        }
                    }
                }
            }
        }