Ejemplo n.º 1
0
        private void EndRent()
        {
            bool DistanceCheck = false;

            if (String.IsNullOrWhiteSpace(TxB_Distance.Text))
            {
                Lb_DistanceError.Content    = "Podaj przejechany dystans";
                Lb_DistanceError.Visibility = Visibility.Visible;
                DistanceCheck = false;
            }
            else
            {
                car.Course   += int.Parse(TxB_Distance.Text);
                DistanceCheck = true;
            }


            car.Status = "wolny";
            if (DistanceCheck == true)
            {
                try
                {
                    using (CarRentalEntities db = new CarRentalEntities())
                    {
                        var rentToDel = (from item in db.Rent where item.Id_Rent == rent.Id_Rent select item).First();
                        if (rentToDel != null)
                        {
                            db.Rent.Remove(rentToDel);
                        }
                        db.Cars.AddOrUpdate(car);
                        db.SaveChanges();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                Close();
            }
        }
Ejemplo n.º 2
0
 public CrNewEmpWindow(int userId)
 {
     InitializeComponent();
     using (CarRentalEntities db = new CarRentalEntities())
     {
         employee = db.Employees.Where(i => i.Id_Employee == userId).First();
         TxB_EmpFirstName.IsEnabled = false;
         TxB_EmpLastName.IsEnabled  = false;
         TxB_EmpFirstName.Text      = employee.FirstName;
         TxB_EmpLastName.Text       = employee.LastName;
         TxB_EmpPhone.Text          = employee.PhoneNumber.ToString();
         if (employee.Id_Employee == 1)
         {
             CheckB_Perm.IsEnabled = false;
             if (employee.AdvancePermission == true)
             {
                 CheckB_Perm.IsChecked = true;
             }
         }
         TxB_EmpSalary.Text = employee.Salary.ToString();
     }
 }
Ejemplo n.º 3
0
        //zwalnianie pracownika
        private void DelEmp()
        {
            if (LisView_Emp.SelectedIndex >= 0)
            {
                Bt_DelEmp.IsEnabled = true;
                var emp = (Employees)LisView_Emp.SelectedItem;



                if (MessageBox.Show("Na pewno chcesz zwolnic tego pracownika?", "Potwierdzenie", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    try
                    {
                        using (CarRentalEntities db = new CarRentalEntities())
                        {
                            var loginToDelete = (from item in db.LoginData where item.Id_Emp == emp.Id_Employee select item).First();
                            var empToDelete   = (from item in db.Employees where item.Id_Employee == emp.Id_Employee select item).First();
                            if (empToDelete != null)
                            {
                                db.LoginData.Remove(loginToDelete);
                                db.Employees.Remove(empToDelete);
                            }
                            db.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        //throw;
                    }
                }
            }
            else
            {
            }
        }
Ejemplo n.º 4
0
        public void SetLoginData()
        {
            bool loginCheck = false;
            bool passCheck = false;

            if (String.IsNullOrWhiteSpace(TxB_EmpLogin.Text))
            {
                Lb_LoginError.Content = "Podaj login";
                Lb_LoginError.Visibility = Visibility.Visible;
                loginCheck = false;
            }
            else
            {
                Lb_LoginError.Visibility = Visibility.Collapsed;
                loginData.Login = TxB_EmpLogin.Text;
                loginCheck = true;
            }

            if (String.IsNullOrWhiteSpace(PassBox_Emp.Password))
            {
                Lb_PassError.Content = "Podaj haslo";
                Lb_PassError.Visibility = Visibility.Visible;
                passCheck = false;
            }
            else
            {
                if (PassBox_Emp.Password.Length<8)
                {
                    Lb_PassError.Content = "Hasło musi mieć conajmniej 8 znaków";
                    Lb_PassError.Visibility = Visibility.Visible;
                    passCheck = false;
                }
                else
                {
                    Lb_PassError.Visibility = Visibility.Collapsed;
                    loginData.Password = PassBox_Emp.Password;
                    passCheck = true;
                }
                
            }


            loginData.Id_Emp = id;
            
            if(loginCheck && passCheck==true)
            {
                try
                {
                    using (CarRentalEntities db = new CarRentalEntities())
                    {
                        db.LoginData.Add(loginData);
                        db.SaveChanges();
                    }
                    Close();
                }
                catch (Exception)
                {

                    throw;
                }
            }

            
        }
Ejemplo n.º 5
0
        //dodawanie samochodu
        public void AddCar()
        {
            bool RNumberCheck = false;
            bool MarkCheck    = false;
            bool ModelCheck   = false;
            bool CourseCheck  = false;
            bool ClassCheck   = false;
            bool PriceCheck   = false;


            if (String.IsNullOrWhiteSpace(TxB_RNumber.Text))
            {
                Lb_RNumberError.Content    = "Podaj nr. rejestracyjny";
                Lb_RNumberError.Visibility = Visibility.Visible;
                RNumberCheck = false;
            }
            else
            {
                try
                {
                    Lb_RNumberError.Visibility = Visibility.Collapsed;
                    car.Reg_Number             = TxB_RNumber.Text;
                    RNumberCheck = true;
                }
                catch (Exception ex)
                {
                    Lb_RNumberError.Content    = ex.Message;
                    Lb_RNumberError.Visibility = Visibility.Visible;
                    RNumberCheck = false;
                    //throw;
                }
            }

            if (String.IsNullOrWhiteSpace(TxB_Mark.Text))
            {
                Lb_MarkError.Content    = "Podaj markę";
                Lb_MarkError.Visibility = Visibility.Visible;
                MarkCheck = false;
            }
            else
            {
                try
                {
                    Lb_MarkError.Visibility = Visibility.Collapsed;
                    car.Mark  = TxB_Mark.Text;
                    MarkCheck = true;
                }
                catch (Exception ex)
                {
                    Lb_MarkError.Content    = ex.Message;
                    Lb_MarkError.Visibility = Visibility.Visible;
                    MarkCheck = false;
                    //throw;
                }
            }

            if (String.IsNullOrWhiteSpace(TxB_Model.Text))
            {
                Lb_ModelError.Content    = "Podaj model";
                Lb_ModelError.Visibility = Visibility.Visible;
                ModelCheck = false;
            }
            else
            {
                try
                {
                    Lb_ModelError.Visibility = Visibility.Collapsed;
                    car.Model  = TxB_Model.Text;
                    ModelCheck = true;
                }
                catch (Exception ex)
                {
                    Lb_ModelError.Content    = ex.Message;
                    Lb_ModelError.Visibility = Visibility.Visible;
                    ModelCheck = false;
                    //throw;
                }
            }

            if (String.IsNullOrWhiteSpace(TxB_Course.Text))
            {
                Lb_CourseError.Content    = "Podaj przebieg";
                Lb_CourseError.Visibility = Visibility.Visible;
                CourseCheck = false;
            }
            else
            {
                try
                {
                    Lb_CourseError.Visibility = Visibility.Collapsed;
                    car.Course  = int.Parse(TxB_Course.Text);
                    CourseCheck = true;
                }
                catch (Exception ex)
                {
                    Lb_CourseError.Content    = ex.Message;
                    Lb_CourseError.Visibility = Visibility.Visible;
                    CourseCheck = false;
                    //throw;
                }
            }


            if (ComboB_Class.SelectedIndex == -1)
            {
                Lb_ClassError.Content    = "Wybierz klase";
                Lb_ClassError.Visibility = Visibility.Visible;
                ClassCheck = false;
            }
            else
            {
                Lb_ClassError.Visibility = Visibility.Collapsed;
                //car.Class = ComboB_Class.SelectedItem.ToString();
                car.Class  = ComboB_Class.Text;
                ClassCheck = true;
            }



            if (String.IsNullOrWhiteSpace(TxB_Price.Text))
            {
                Lb_PriceError.Content    = "Podaj cene";
                Lb_PriceError.Visibility = Visibility.Visible;
                PriceCheck = false;
            }
            else
            {
                try
                {
                    Lb_PriceError.Visibility = Visibility.Collapsed;
                    car.Price  = double.Parse(TxB_Price.Text);
                    PriceCheck = true;
                }
                catch (Exception ex)
                {
                    Lb_PriceError.Content    = ex.Message;
                    Lb_PriceError.Visibility = Visibility.Visible;
                    PriceCheck = false;
                    //throw;
                }
            }

            car.Status = "wolny";


            if (RNumberCheck && MarkCheck && ModelCheck && CourseCheck && ClassCheck && PriceCheck == true)
            {
                try
                {
                    using (CarRentalEntities db = new CarRentalEntities())
                    {
                        db.Cars.Add(car);
                        db.SaveChanges();
                        Close();
                    }
                }
                catch (Exception)
                {
                    //MessageBox.Show(ex.Message);
                    throw;
                }
            }
        }
Ejemplo n.º 6
0
        private void Rent()
        {
            bool FNameCheck   = false;
            bool LNameCheck   = false;
            bool PhoneCheck   = false;
            bool AddressCheck = false;
            bool CityCheck    = false;
            bool IdNumCheck   = false;

            bool carCheck     = false;
            bool endDateCheck = false;

            //customer = null;
            if (Radio_NewCust.IsChecked == true)
            {
                if (String.IsNullOrWhiteSpace(TxB_CustFirstName.Text))
                {
                    Lb_FNameError.Content    = "Podaj imie";
                    Lb_FNameError.Visibility = Visibility.Visible;
                    FNameCheck = false;
                }
                else
                {
                    Lb_FNameError.Visibility = Visibility.Collapsed;
                    customer.FirstName       = TxB_CustFirstName.Text;
                    FNameCheck = true;
                }

                if (String.IsNullOrWhiteSpace(TxB_CustLastName.Text))
                {
                    Lb_LNameError.Content    = "Podaj nazwisko";
                    Lb_LNameError.Visibility = Visibility.Visible;
                    LNameCheck = false;
                }
                else
                {
                    Lb_LNameError.Visibility = Visibility.Collapsed;
                    customer.LastName        = TxB_CustLastName.Text;
                    LNameCheck = true;
                }

                if (String.IsNullOrWhiteSpace(TxB_CustPhone.Text))
                {
                    Lb_PhoneError.Content    = "Podaj telefon";
                    Lb_PhoneError.Visibility = Visibility.Visible;
                    PhoneCheck = false;
                }
                else
                {
                    try
                    {
                        Lb_PhoneError.Visibility = Visibility.Collapsed;
                        customer.PhoneNumber     = int.Parse(TxB_CustPhone.Text);
                        PhoneCheck = true;
                    }
                    catch (Exception ex)
                    {
                        Lb_PhoneError.Content    = ex.Message;
                        Lb_PhoneError.Visibility = Visibility.Visible;
                        PhoneCheck = false;
                        //throw;
                    }
                }

                if (String.IsNullOrWhiteSpace(TxB_CustAddress.Text))
                {
                    Lb_AddressError.Content    = "Podaj adres";
                    Lb_AddressError.Visibility = Visibility.Visible;
                    AddressCheck = false;
                }
                else
                {
                    Lb_AddressError.Visibility = Visibility.Collapsed;
                    customer.Address           = TxB_CustAddress.Text;
                    AddressCheck = true;
                }

                if (String.IsNullOrWhiteSpace(TxB_CustCity.Text))
                {
                    Lb_CityError.Content    = "Podaj ulice";
                    Lb_CityError.Visibility = Visibility.Visible;
                    CityCheck = false;
                }
                else
                {
                    Lb_CityError.Visibility = Visibility.Collapsed;
                    customer.City           = TxB_CustCity.Text;
                    CityCheck = true;
                }

                if (String.IsNullOrWhiteSpace(TxB_CustIdNum.Text))
                {
                    Lb_IdNumError.Content    = "Podaj numer dowodu";
                    Lb_IdNumError.Visibility = Visibility.Visible;
                    IdNumCheck = false;
                }
                else
                {
                    Lb_IdNumError.Visibility = Visibility.Collapsed;
                    customer.Id_Number       = TxB_CustIdNum.Text;
                    IdNumCheck = true;
                }
            }
            else if (Radio_Cust.IsChecked == true)
            {
                FNameCheck      = LNameCheck = PhoneCheck = AddressCheck = CityCheck = IdNumCheck = true;
                rent.CustomerID = customer.Id_Customer;
            }
            else
            {
                MessageBox.Show("Dokonaj byworu");
            }



            if (String.IsNullOrWhiteSpace(TxB_CarReg_Number.Text))
            {
                Lb_SelectedCarError.Content    = "Wybierz samochód";
                Lb_SelectedCarError.Visibility = Visibility.Visible;
                carCheck = false;
            }
            else
            {
                Lb_SelectedCarError.Visibility = Visibility.Collapsed;
                rent.Reg_Number = TxB_CarReg_Number.Text;
                carCheck        = true;
            }

            rent.StartDate = startDate.ToString("dd/MM/yyyy");

            if (DatePicker_End.SelectedDate == null)
            {
                Lb_EndDateError.Content    = "Wybierz datę";
                Lb_EndDateError.Visibility = Visibility.Visible;
                endDateCheck = false;
            }
            else if (DatePicker_End.SelectedDate <= DateTime.Now)
            {
                Lb_EndDateError.Content    = "Błędna data";
                Lb_EndDateError.Visibility = Visibility.Visible;
                EndDateCheck = false;
            }
            else
            {
                Lb_EndDateError.Visibility = Visibility.Collapsed;
                rent.EndDate = endDate.ToString("dd/MM/yyyy");
                endDateCheck = true;
            }

            rent.Cost = cost;

            car.Status = "zajety";


            if (FNameCheck && LNameCheck && PhoneCheck && AddressCheck && CityCheck && IdNumCheck && EndDateCheck && carCheck && endDateCheck == true)
            {
                try
                {
                    using (CarRentalEntities db = new CarRentalEntities())
                    {
                        db.Customers.AddOrUpdate(customer);
                        db.Rent.Add(rent);
                        db.Cars.AddOrUpdate(car);
                        db.SaveChanges();
                        Close();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 7
0
        //tworzenie uzytkownika
        public void CreateEmp()
        {
            bool fNameCheck  = false;
            bool lNameCheck  = false;
            bool phoneCheck  = false;
            bool salaryCheck = false;


            if (String.IsNullOrWhiteSpace(TxB_EmpFirstName.Text))
            {
                Lb_EmpFNameError.Content    = "Podaj imie";
                Lb_EmpFNameError.Visibility = Visibility.Visible;
                fNameCheck = false;
            }
            else
            {
                Lb_EmpFNameError.Visibility = Visibility.Collapsed;
                employee.FirstName          = TxB_EmpFirstName.Text;
                fNameCheck = true;
            }

            if (String.IsNullOrWhiteSpace(TxB_EmpLastName.Text))
            {
                Lb_EmpLNameError.Content    = "Podaj nazwisko";
                Lb_EmpLNameError.Visibility = Visibility.Visible;
                lNameCheck = false;
            }
            else
            {
                Lb_EmpLNameError.Visibility = Visibility.Collapsed;
                employee.LastName           = TxB_EmpLastName.Text;
                lNameCheck = true;
            }

            if (String.IsNullOrWhiteSpace(TxB_EmpPhone.Text))
            {
                Lb_EmpPhoneError.Content    = "Podaj telefon";
                Lb_EmpPhoneError.Visibility = Visibility.Visible;
                phoneCheck = false;
            }
            else
            {
                try
                {
                    Lb_EmpPhoneError.Visibility = Visibility.Collapsed;
                    employee.PhoneNumber        = int.Parse(TxB_EmpPhone.Text);
                    phoneCheck = true;
                }
                catch (Exception ex)
                {
                    Lb_EmpPhoneError.Content    = ex.Message;
                    Lb_EmpPhoneError.Visibility = Visibility.Visible;
                    phoneCheck = false;
                    //throw;
                }
            }

            if (CheckB_Perm.IsChecked == true)
            {
                employee.AdvancePermission = true;
            }
            else
            {
                employee.AdvancePermission = false;
            }


            if (String.IsNullOrWhiteSpace(TxB_EmpSalary.Text))
            {
                Lb_EmpSalaryError.Content    = "Podaj kwotę wynagrodzenia";
                Lb_EmpSalaryError.Visibility = Visibility.Visible;
                salaryCheck = false;
            }
            else
            {
                try
                {
                    Lb_EmpSalaryError.Visibility = Visibility.Collapsed;
                    employee.Salary = double.Parse(TxB_EmpSalary.Text);
                    salaryCheck     = true;
                }
                catch (Exception ex)
                {
                    Lb_EmpSalaryError.Content    = ex.Message;
                    Lb_EmpSalaryError.Visibility = Visibility.Visible;
                    salaryCheck = false;
                    //throw;
                }
            }



            if (fNameCheck && lNameCheck && phoneCheck && salaryCheck == true)
            {
                try
                {
                    using (CarRentalEntities db = new CarRentalEntities())
                    {
                        db.Employees.Add(employee);
                        db.SaveChanges();
                        Close();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 8
0
        //modyfikowanie uzytkownika
        public void ModUser()
        {
            bool phoneCheck  = false;
            bool salaryCheck = false;

            if (String.IsNullOrWhiteSpace(TxB_EmpPhone.Text))
            {
                Lb_EmpPhoneError.Content    = "Podaj telefon";
                Lb_EmpPhoneError.Visibility = Visibility.Visible;
                phoneCheck = false;
            }
            else
            {
                Lb_EmpPhoneError.Visibility = Visibility.Collapsed;

                phoneCheck = true;
            }



            if (String.IsNullOrWhiteSpace(TxB_EmpSalary.Text))
            {
                Lb_EmpSalaryError.Content    = "Podaj kwotę wynagrodzenia";
                Lb_EmpSalaryError.Visibility = Visibility.Visible;
                salaryCheck = false;
            }
            else
            {
                Lb_EmpSalaryError.Visibility = Visibility.Collapsed;

                salaryCheck = true;
            }

            if (phoneCheck && salaryCheck == true)
            {
                try
                {
                    using (CarRentalEntities db = new CarRentalEntities())
                    {
                        var toMod = db.Employees.SingleOrDefault(i => i.Id_Employee == employee.Id_Employee);
                        if (toMod != null)
                        {
                            toMod.PhoneNumber = int.Parse(TxB_EmpPhone.Text);
                            toMod.Salary      = double.Parse(TxB_EmpSalary.Text);
                            if (CheckB_Perm.IsChecked == true)
                            {
                                toMod.AdvancePermission = true;
                            }
                            else
                            {
                                toMod.AdvancePermission = false;
                            }
                        }
                        db.SaveChanges();
                        Close();
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Błąd");
                    //throw;
                }
            }
        }