コード例 #1
0
ファイル: DishPage.xaml.cs プロジェクト: kubarenatioN/cs_labs
        public DishPage(Dishes dish, MainWindow w)
        {
            InitializeComponent();

            Dish         = dish;
            ParentWindow = w;

            title.Text       = Dish.Name;
            description.Text = Dish.Description;
            weight.Text      = (Math.Round((double)Dish.Weight, 2)).ToString();
            rating.Text      = (Math.Round((double)Dish.Rating, 2)).ToString();
            calories.Text    = (Math.Round((double)Dish.Calories, 2)).ToString();
            price.Text       = (Math.Round((double)Dish.Price, 2)).ToString();

            string imageWay = "../../Images/Dishes/" + Dish.Image.Trim() + ".jpg";

            dishPageHeader.ImageSource = new BitmapImage(new Uri(imageWay, UriKind.Relative));

            using (DeliciousEntities context = new DeliciousEntities())
            {
                List <Restaurants> dishRestaurants = context.Menus.Where(menu => menu.DishId == Dish.Id).Select(menu => menu.Restaurants).ToList();

                foreach (Restaurants rest in dishRestaurants)
                {
                    DishRestaurants.Add(new RestaurantCard(rest, ParentWindow));
                }
            }

            restContainer.ItemsSource = DishRestaurants;
        }
コード例 #2
0
        public RestaurantPage(Restaurants r, MainWindow w)
        {
            InitializeComponent();

            Restaurant   = r;
            ParentWindow = w;

            title.Text    = Restaurant.Name;
            location.Text = Restaurant.Location;

            string opens;
            string closes;

            if (Restaurant.OpensTime < 10)
            {
                opens = "0" + Restaurant.OpensTime.ToString();
            }
            else
            {
                opens = Restaurant.OpensTime.ToString();
            }
            if (Restaurant.ClosesTime < 10)
            {
                closes = "0" + Restaurant.ClosesTime.ToString();
            }
            else
            {
                closes = Restaurant.ClosesTime.ToString();
            }
            opensTime.Text  = opens + ":00";
            closesTime.Text = closes + ":00";

            string imageWay = "../../Images/Restaurants/" + Restaurant.Image.Trim() + ".jpg";

            restHeaderImage.ImageSource = new BitmapImage(new Uri(imageWay, UriKind.Relative));

            using (DeliciousEntities context = new DeliciousEntities())
            {
                List <Dishes> restDishes = context.Menus.Where(menu => menu.RestaurantId == Restaurant.Id).Select(menu => menu.Dishes).ToList();

                foreach (Dishes dish in restDishes)
                {
                    RestDishes.Add(new DishCard(dish, ParentWindow));
                }
            }
            dishesContainer.ItemsSource = RestDishes;


            using (DeliciousEntities context = new DeliciousEntities())
            {
                List <RestaurantsPlaces> restPlaces = context.RestaurantsPlaces.Where(places => places.RestaurantId == Restaurant.Id).ToList();

                foreach (RestaurantsPlaces place in restPlaces)
                {
                    BookingControls.Add(new BookingControl(place, ParentWindow, this));
                }
            }
            placesContainer.ItemsSource = BookingControls;
        }
コード例 #3
0
        private void LoginUser(object sender, RoutedEventArgs e)
        {
            string _username     = username.Text;
            string _password     = password.Password;
            string _userRealName = userRealName.Text;

            username.BorderBrush     = (SolidColorBrush)(new BrushConverter()).ConvertFrom("#FFCDEACE");
            password.BorderBrush     = (SolidColorBrush)(new BrushConverter()).ConvertFrom("#FFCDEACE");
            userRealName.BorderBrush = (SolidColorBrush)(new BrushConverter()).ConvertFrom("#FFCDEACE");

            bool usernameMatch     = usernameRegex.IsMatch(_username);
            bool passwordMatch     = passwordRegex.IsMatch(_password);
            bool userRealNameMatch = userRealNameRegex.IsMatch(_userRealName);

            if (!usernameMatch)
            {
                username.BorderBrush = Brushes.Red;
            }
            if (!passwordMatch)
            {
                password.BorderBrush = Brushes.Red;
            }
            if (!userRealNameMatch)
            {
                userRealName.BorderBrush = Brushes.Red;
            }

            if (usernameMatch && passwordMatch && userRealNameMatch)
            {
                List <Users> alreadyUsers = new List <Users>();
                using (DeliciousEntities context = new DeliciousEntities())
                {
                    alreadyUsers = context.Users.Where(user => user.Username == _username && user.Password == _password).ToList();
                }
                if (alreadyUsers.Count != 0)
                {
                    MessageBox.Show("Пользователь с таким логином и паролем уже есть.");
                }
                else
                {
                    Users newUser = new Users()
                    {
                        Username = _username,
                        Password = _password,
                        Name     = _userRealName
                    };
                    using (DeliciousEntities context = new DeliciousEntities())
                    {
                        context.Users.Add(newUser);
                        context.SaveChanges();
                    }
                    MainWindow mainWindow = new MainWindow(newUser);
                    mainWindow.Show();
                    LoginWindow.Close();
                }
            }
        }
コード例 #4
0
        // TEST CTOR DELETE AFTERWARDS
        public MainWindow()
        {
            InitializeComponent();

            using (DeliciousEntities context = new DeliciousEntities())
            {
                CurrentUser = context.Users.Where(u => u.Id == 7).FirstOrDefault();
            }
            //userButton.Content = CurrentUser.Name;

            frame.Content = new RestaurantsPage(this);
        }
コード例 #5
0
        private void BookClick(object sender, RoutedEventArgs e)
        {
            DateTime?selectedDate = calendar.Value;

            if (selectedDate != null)
            {
                // дата на которую забронирован столик в нужном формате (без минут)
                string bookDateTime = selectedDate.Value.ToString("dd-MM-yyyy HH:00", CultureInfo.CurrentCulture);
                Orders newOrder     = new Orders()
                {
                    UserId            = ParentWindow.CurrentUser.Id,
                    RestaurantPlaceId = Place.Id,
                    BookDate          = bookDateTime
                };
                using (DeliciousEntities context = new DeliciousEntities())
                {
                    // добавляем новый заказ в бд
                    context.Orders.Add(newOrder);

                    // уменьшаем кол-во свободных столиков конкретного типа в этом ресторане
                    context.RestaurantsPlaces.Where(place => place.Id == Place.Id).FirstOrDefault().CurrentPlaceCount = Place.CurrentPlaceCount - 1;
                    context.SaveChanges();
                }

                List <BookingControl> restNewBookings = new List <BookingControl>();
                using (DeliciousEntities context = new DeliciousEntities())
                {
                    // формируем новый список мест конкретно этого ресторана
                    List <RestaurantsPlaces> restPlaces = context.RestaurantsPlaces.Where(places => places.RestaurantId == RestaurantPage.Restaurant.Id).ToList();

                    // Очищаем список с вариантами брони
                    //RestaurantPage.BookingControls.Clear();

                    // заполняем список брони элементами управления
                    foreach (RestaurantsPlaces place in restPlaces)
                    {
                        restNewBookings.Add(new BookingControl(place, ParentWindow, RestaurantPage));
                    }
                }
                // Выводим новый список
                RestaurantPage.placesContainer.ItemsSource = restNewBookings;

                MessageBox.Show("Бронь прошла успешно!");
                this.Close();
            }
            else
            {
                MessageBox.Show("Выберите дату.");
                return;
            }
        }
コード例 #6
0
        public RestaurantsPage(MainWindow w)
        {
            InitializeComponent();

            ParentWindow = w;

            using (DeliciousEntities context = new DeliciousEntities())
            {
                List <Restaurants> restaurants = context.Restaurants.ToList();
                foreach (Restaurants restaurant in restaurants)
                {
                    PageRestaurants.Add(new RestaurantCard(restaurant, ParentWindow));
                }
            }

            restaurantsContainer.ItemsSource = PageRestaurants;
        }
コード例 #7
0
        public DishesPage(MainWindow w)
        {
            InitializeComponent();

            ParentWindow = w;

            using (DeliciousEntities context = new DeliciousEntities())
            {
                List <Dishes> dishes = context.Dishes.ToList();
                foreach (Dishes dish in dishes)
                {
                    PageDishes.Add(new DishCard(dish, ParentWindow));
                }
            }

            dishesContainer.ItemsSource = PageDishes;
        }
コード例 #8
0
ファイル: UserPage.xaml.cs プロジェクト: kubarenatioN/cs_labs
        public UserPage(MainWindow w)
        {
            InitializeComponent();

            ParentWindow = w;
            User         = ParentWindow.CurrentUser;

            userRealName.Text = User.Name;

            using (DeliciousEntities context = new DeliciousEntities())
            {
                List <Orders> orders = context.Orders.Where(order => order.UserId == User.Id).ToList();
                foreach (Orders order in orders)
                {
                    UserOrders.Add(new OrderControl(order, ParentWindow, this));
                }
            }
            ordersContainer.ItemsSource = UserOrders;
        }
コード例 #9
0
ファイル: SignPage.xaml.cs プロジェクト: kubarenatioN/cs_labs
        private void SignUser(object sender, RoutedEventArgs e)
        {
            string _username = username.Text;
            string _password = password.Password;

            username.BorderBrush = (SolidColorBrush)(new BrushConverter()).ConvertFrom("#FFCDEACE");
            password.BorderBrush = (SolidColorBrush)(new BrushConverter()).ConvertFrom("#FFCDEACE");

            bool usernameMatch = usernameRegex.IsMatch(_username);
            bool passwordMatch = passwordRegex.IsMatch(_password);

            if (!usernameMatch)
            {
                username.BorderBrush = Brushes.Red;
            }
            if (!passwordMatch)
            {
                password.BorderBrush = Brushes.Red;
            }

            if (usernameMatch && passwordMatch)
            {
                Users user;
                using (DeliciousEntities context = new DeliciousEntities())
                {
                    user = context.Users.Where(u => u.Username == _username && u.Password == _password).FirstOrDefault();
                }
                if (user == null)
                {
                    MessageBox.Show("Пользователь не найден.");
                }
                else
                {
                    MainWindow mainWindow = new MainWindow(user);
                    mainWindow.Show();
                    LoginWindow.Close();
                }
            }
        }
コード例 #10
0
        private void CancelBook(object sender, RoutedEventArgs e)
        {
            // получаем ресторан этого заказа
            Restaurants orederRestaurant = Order.RestaurantsPlaces.Restaurants;

            using (DeliciousEntities context = new DeliciousEntities())
            {
                // удаляем заказ
                // если объекта не существует локально
                if (!context.Orders.Local.Contains(Order))
                {
                    // тогда взять его копию локально
                    context.Orders.Attach(Order);
                }
                // удалить объект
                context.Orders.Remove(Order);

                // увеличиваем кол-во свободных мест в ресторане
                context.RestaurantsPlaces.Where(place => place.Id == Order.RestaurantPlaceId).FirstOrDefault().CurrentPlaceCount += 1;
                context.SaveChanges();
            }

            List <OrderControl> NewOrders = new List <OrderControl>();

            using (DeliciousEntities context = new DeliciousEntities())
            {
                // формируем новый список мест конкретно этого ресторана
                List <Orders> newOrders = context.Orders.Where(order => order.UserId == ParentWindow.CurrentUser.Id).ToList();

                // заполняем список брони элементами управления
                foreach (Orders order in newOrders)
                {
                    NewOrders.Add(new OrderControl(order, ParentWindow, UserPage));
                }
            }
            // Выводим новый список
            UserPage.ordersContainer.ItemsSource = NewOrders;
        }