コード例 #1
0
        //Admin Login Method
        private void Login(object sender, RoutedEventArgs e)
        {
            username = Username.Text;
            password = Password.Password;

            RentalCarModel RCM = new RentalCarModel();
            _Admin         a   = new _Admin(RCM);

            /*Admin data called and loop through.
             * Because we only have one admin this method should work. If more admins existed this method wouldn't be ideal*/
            List <Admin> adminlist = a.GetData();

            foreach (Admin i in adminlist)
            {
                if (username == i.Name && password == i.Surname)
                {
                    MessageBox.Show("Login Succesful");
                    Status s = new Status();
                    s.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please Try Again");
                }
            }
        }
コード例 #2
0
        //Method retrieving car and car cost from db
        public void CarData()
        {
            RentalCarModel RCM = new RentalCarModel();
            _CarRental     cr  = new _CarRental(RCM);

            List <CarRental> carlist = cr.GetData();

            ListCar.ItemsSource = carlist;
        }
コード例 #3
0
ファイル: Status.xaml.cs プロジェクト: Tarek1989/CarRental
        //Method that displays all Users that rented a car
        public void UserData()
        {
            RentalCarModel RCM = new RentalCarModel();
            _Users         u   = new _Users(RCM);

            List <Users> userlist = u.GetData();

            UserList.ItemsSource = userlist;
        }
コード例 #4
0
        public void UserDeletion()
        {
            RentalCarModel RCM = new RentalCarModel();
            _Users         u   = new _Users(RCM);

            userdata = u.GetData();

            UserList.ItemsSource = userdata;
        }
コード例 #5
0
        private void Delete(object sender, RoutedEventArgs e)
        {
            RentalCarModel RCM = new RentalCarModel();
            _Users         u   = new _Users(RCM);

            userdata = u.GetData();
            foreach (Users i in userdata)
            {
                if (i.ID == Convert.ToInt16(UserList.Text))
                {
                    u.DeleteData(i);
                    MessageBox.Show("User succesfully deleted");
                    Status s = new Status();
                    s.Show();
                    this.Close();
                }
            }
        }
コード例 #6
0
        //Method adding new users
        private void AddUser(object sender, RoutedEventArgs e)
        {
            RentalCarModel RCM = new RentalCarModel();
            _Users         u   = new _Users(RCM);


            try
            {
                if (Days.Text == "" || Convert.ToInt16(Days.Text) == 0)
                {
                    MessageBox.Show("Days required needs value");
                }
                else if (Convert.ToInt16(Days.Text) >= 1)
                {
                    Users users = new Users();
                    users.Name    = Name.Text;
                    users.Surname = Surname.Text;
                    users.Age     = Convert.ToInt16(Age.Text);
                    users.Car     = ListCar.Text;


                    users.Cost = Convert.ToInt16(Days.Text) * Convert.ToInt16(Cost.Text);

                    if (users.Age < 18)
                    {
                        MessageBox.Show("Please be 18+");
                    }
                    else
                    {
                        u.AddData(users);

                        MessageBox.Show("Thank you for registering with CarRental");

                        MainWindow mw = new MainWindow();
                        mw.Show();
                        this.Close();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Please try again");
            }
        }
コード例 #7
0
 public _Users(RentalCarModel rcm) : base(rcm)
 {
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: Tarek1989/CarRental
        static void Main(string[] args)
        {
            /*First phase:
             * Give user or admin direction to appropriate UI*/
            Console.WriteLine("   xxxxxx");
            Console.WriteLine(" x");
            Console.WriteLine("x");
            Console.WriteLine("x");
            Console.WriteLine("  x");
            Console.WriteLine("   xxxxxx" + "\n");

            RentalCarModel rcm = new RentalCarModel();
            _CarRental     c   = new _CarRental(rcm);
            _Users         u   = new _Users(rcm);
            _Admin         a   = new _Admin(rcm);

            Console.WriteLine("Welcome to Car rental. Please indicate if you are a user or admin" + "\n");

            bool h = true;

            while (h)
            {
                string userinput = Console.ReadLine().ToLower();

                switch (userinput)
                {
                case "user":
                    Console.WriteLine("\n" + "User Registration Form");
                    Console.WriteLine("\n" + "Please Add Name");
                    string name = Console.ReadLine();

                    Console.WriteLine("\n" + "Please Add Surname");
                    string surname = Console.ReadLine();

                    Console.WriteLine("\n" + "Please Add Age");
                    int age = Convert.ToInt16(Console.ReadLine());

                    Console.WriteLine("\n" + "Please type a car with cost/day ");
                    foreach (CarRental item in c.GetData())
                    {
                        Console.Write(item.Car + "\t" + item.Cost + "\n");
                    }

                    /*Dictionary seems to do the trick with the issue encounter with foreach loop.
                     * Foreach loop usually enumerates through each item followed by the condition. Therefore
                     * if the condition asked for a fifth element , the loop should have iterated 5 times before reaching desire value*/

                    Dictionary <string, int> cardic = c.GetData().ToDictionary(car => car.Car, cost => cost.Cost);

                    foreach (KeyValuePair <string, int> test in cardic)
                    {
                        Console.WriteLine("\n" + "Please type the car of choice: ");
                        string usercar = Console.ReadLine();
                        int    days, sum;
                        if (cardic.ContainsKey(usercar))
                        {
                            Console.WriteLine("\n" + "How many days?");
                            days = Convert.ToInt32(Console.ReadLine());
                            sum  = days * test.Value;    //value is the cost

                            Users customers = new Users();
                            customers.Name    = name;
                            customers.Surname = surname;
                            customers.Age     = age;
                            customers.Car     = usercar;
                            customers.Cost    = sum;

                            u.AddData(customers);

                            Console.WriteLine("Thank you for registering");
                            break;
                        }
                    }



                    h = false;
                    break;     // if break statement is not place then you get following error Severity	Code	Control cannot fall out of switch from final case label('case "user":'******'s true it will loop indefinetely until a false value is isnerted*/

                    bool x = true;
                    while (x)
                    {
                        Console.WriteLine("\n" + "Please enter username");
                        string username = Console.ReadLine();
                        Console.WriteLine("\n" + "Please enter password");
                        string password = Console.ReadLine();

                        foreach (Admin i in a.GetData())
                        {
                            if (i.Name == username && i.Surname == password)
                            {
                                Console.WriteLine("\n" + "Your data is loading...." + "\n");
                                for (int users = 0; users < u.GetData().Count; users++)
                                {
                                    Console.Write(u.GetData()[users].Name + "\t" + u.GetData()[users].Surname + "\t" + u.GetData()[users].Age + "\t" + u.GetData()[users].Car + "\t" + u.GetData()[users].Cost + "\n"); //users access property (?)
                                }

                                x = false;
                            }
                            else
                            {
                                Console.WriteLine("try again");
                            }
                        }
                    }


                    h = false;
                    break;

                default:
                    Console.WriteLine("Please select one of the two");
                    break;
                }
            }

            Console.ReadLine();
        }
コード例 #9
0
 public Repositories(RentalCarModel rcm)
 {
     RCM = rcm;
 }
コード例 #10
0
ファイル: _CarRental.cs プロジェクト: Tarek1989/CarRental
 public _CarRental(RentalCarModel rcm) : base(rcm)
 {
 }
コード例 #11
0
 public _Admin(RentalCarModel rcm) : base(rcm)
 {
 }