Esempio n. 1
0
        private void checkoutButton_Click(object sender, RoutedEventArgs e)
        {
            if (customMiniMenuBlockList.Count != 0)
            {
                OrderAccounting orderAccounting = new OrderAccounting();

                CardLoyality card = new CardLoyality();

                using (SQLiteConnection con = new SQLiteConnection(App.databasePath))
                {
                    card = con.Table <CardLoyality>().Where(x => x.CardLoyalityID == App.currentUser.CardLoyality)
                           .FirstOrDefault();
                }

                double costWithDiscount = CostCalculation.GetCostWithDiscount(card.Score);

                orderAccounting.Cost        = costWithDiscount;
                orderAccounting.TableNumber = 99; // Need to fix
                orderAccounting.IsActive    = true;
                orderAccounting.Date        = DateTime.Now.ToString("dd/MM/yyyy");

                string temp    = String.Empty;
                string message = String.Empty;

                foreach (var dish in customMiniMenuBlockList)
                {
                    card.Score += dish.Count;
                    string buffer  = dish.Dish.Name + "_" + dish.Count;
                    string mbuffer = dish.Dish.Name + " кол-во " + dish.Count;

                    if (temp == String.Empty)
                    {
                        temp    = buffer;
                        message = mbuffer;
                    }
                    else
                    {
                        temp    += ", " + buffer;
                        message += "\n" + mbuffer;
                    }
                }

                orderAccounting.Dish = temp;

                message += "\n\n Цена cо скидкой: " + costWithDiscount + "руб.";

                var result = MessageBox.Show(message, "Заказ", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    using (SQLiteConnection con = new SQLiteConnection(App.databasePath))
                    {
                        ServiceHelper.Core.DataHandler.AddIncome(costWithDiscount);
                        con.Insert(orderAccounting, typeof(OrderAccounting));
                        con.Update(card, typeof(CardLoyality));
                    }
                }
            }
        }
Esempio n. 2
0
        private void registrationButton_Click(object sender, RoutedEventArgs e)
        {
            CardLoyality cardLoyality = new CardLoyality();
            int          ID;

            bool isAccountExist;

            using (SQLiteConnection con = new SQLiteConnection(App.databasePath))
            {
                isAccountExist = con.Table <User>().Where(x => x.Login == loginTextBox.Text).Any();
                con.Insert(cardLoyality, typeof(CardLoyality));
                ID = con.Table <CardLoyality>().Last().CardLoyalityID;
            }

            if (isAccountExist)
            {
                MessageBox.Show("Невозможна регистрация, такой аккаунт уже существует!");
                return;
            }

            User user = new User()
            {
                FullName     = fullNameTextBox.Text,
                Adress       = addressTextBox.Text,
                Level        = int.Parse(levelTextBox.Text),
                Login        = loginTextBox.Text,
                Passport     = passportTextBox.Text,
                Password     = passwordTextBox.Text,
                Phone        = "+" + phoneTextBox.Text,
                CardLoyality = ID
            };

            using (SQLiteConnection con = new SQLiteConnection(App.databasePath))
            {
                con.Insert(user, typeof(User));
            }

            this.Close();
        }