Beispiel #1
0
        private void RefillBtnClick(object sender, RoutedEventArgs e)
        {
            //payment script should be called here
            var client = new BetServiceClient();

            try
            {
                client.Open();
                int amount;
                if (int.TryParse(refillTB.Text, out amount) && client.AccountRefill(account.Code, amount))
                {
                    account.Amount      += amount;
                    accountAmountTB.Text = account.Amount.ToString();
                    MessageBox.Show($"Successfully refilled account by {amount}");
                    refillTB.Text = "";
                }
                else
                {
                    MessageBox.Show($"Account cannot be refilled by {amount}");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection problem");
            }
            finally
            {
                client.Close();
            }
        }
Beispiel #2
0
        private void EventAddBtnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(EventFactorTB.Text) || string.IsNullOrEmpty(EventNameTB.Text))
            {
                return;
            }
            decimal factor;

            if (decimal.TryParse(EventFactorTB.Text, out factor))
            {
                var client = new BetServiceClient();
                try
                {
                    client.Open();
                    client.AddEvent(EventNameTB.Text, factor);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Connection problem");
                }
                finally
                {
                    client.Close();
                }
            }
            EventFactorTB.Text = "";
            EventNameTB.Text   = "";
            EventListUpdateBtnClick(sender, e);
        }
Beispiel #3
0
        private void BetUpdateBtnClick(object sender, RoutedEventArgs e)
        {
            var client = new BetServiceClient();

            try
            {
                client.Open();
                int betCode;
                if (!string.IsNullOrEmpty(betCodeTB.Text) && (int.TryParse(betCodeTB.Text, out betCode)))
                {
                    var bet = client.GetBet(betCode);
                    BetsListView.Items.Clear();
                    BetsListView.Items.Add(bet);
                }
                else
                {
                    var bets = client.GetBets(account.Code);
                    BetsListView.Items.Clear();
                    foreach (var bet in bets)
                    {
                        BetsListView.Items.Add(bet);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection problem");
            }
            finally
            {
                client.Close();
            }
        }
Beispiel #4
0
        private void WithdrawBtnClick(object sender, RoutedEventArgs e)
        {
            var client = new BetServiceClient();

            try
            {
                client.Open();
                int amount;
                if (int.TryParse(withdrawTB.Text, out amount) && client.AccountWithdraw(account.Code, amount))
                {
                    account.Amount      -= amount;
                    accountAmountTB.Text = account.Amount.ToString();

                    MessageBox.Show($"Successfully withdrew  {amount}");
                    withdrawTB.Text = "";
                }
                else
                {
                    MessageBox.Show($"Cannot withdrew {amount}");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection problem");
            }
            finally
            {
                client.Close();
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var proxy   = new BetServiceClient();
            var persons = await proxy.GetPersonsAsync();

            foreach (var item in persons)
            {
                Debug.WriteLine($"{item.Name}: {item.Age}");
            }
        }
Beispiel #6
0
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            var proxy = new BetServiceClient();

            var person = await proxy.GetPersonAsync();


            foreach (var item in person)
            {
                Debug.WriteLine(item.Name + item.Age);
            }
        }
Beispiel #7
0
 private void SimpleBetClick(object sender, RoutedEventArgs e)
 {
     if (EventsListView.SelectedItem == null)
     {
         MessageBox.Show("You should select event form the list");
     }
     else
     {
         var item    = (Event)EventsListView.SelectedItem;
         var results = new Event
         {
             Factor = item.Factor,
             Name   = item.Name
         };
         int betAmount;
         if (!int.TryParse(BetTextBox.Text, out betAmount))
         {
             MessageBox.Show("Wrong bet");
         }
         else
         {
             if (betAmount > account.Amount)
             {
                 MessageBox.Show("Not enough money");
             }
             else
             {
                 var client = new BetServiceClient();
                 try
                 {
                     client.Open();
                     client.AccountWithdraw(account.Code, betAmount);
                     client.MakeBet(account.Code, betAmount, BetType.Simple, new[] { results });
                     MessageBox.Show("Bet success");
                     BetTextBox.Text = "";
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Connection problem");
                 }
                 finally
                 {
                     client.Close();
                 }
             }
         }
     }
 }
Beispiel #8
0
        private void UpdateAccountInfo(int code)
        {
            var client = new BetServiceClient();

            try
            {
                client.Open();
                account = client.GetAccount(code);
                accountAmountTB.Text = account.Amount.ToString();
                accountCodeTB.Text   = account.Code.ToString();
                accountFIOTB.Text    = account.FIO;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection problem");
            }
            finally
            {
                client.Close();
            }
        }
Beispiel #9
0
        private void EventListUpdateBtnClick(object sender, RoutedEventArgs e)
        {
            var client = new BetServiceClient();

            try
            {
                client.Open();
                var events = client.GetEvents();
                EventsListView.Items.Clear();
                foreach (var ev in events)
                {
                    EventsListView.Items.Add(ev);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection problem");
            }
            finally
            {
                client.Close();
            }
        }
Beispiel #10
0
        private void AccountCreateBtnClick(object sender, RoutedEventArgs e)
        {
            accountCreateBtn.IsEnabled = false;

            if (string.IsNullOrEmpty(accNameTB.Text) || string.IsNullOrEmpty(accSurnameTB.Text) ||
                string.IsNullOrEmpty(accLastNameTB.Text))
            {
                accountCreationToolTip.Text = "Name, Surname or Lastname cannot be empty";
            }
            else
            {
                var client = new BetServiceClient();
                try
                {
                    client.Open();
                    var acc = client.CreateAccount($"{accNameTB.Text} {accSurnameTB.Text} {accLastNameTB.Text}");
                    if (acc.Code > 0)
                    {
                        accountCreationToolTip.Text = "Account creation succeed";
                        NavigationService?.Navigate(new AccountManager(acc.Code));
                    }
                    else
                    {
                        MessageBox.Show("Cannot create account");
                    }
                }
                catch (Exception ex)
                {
                    loginStatus.Text = "Cannot connect to server";
                }
                finally
                {
                    client.Close();
                }
            }
            accountCreateBtn.IsEnabled = true;
        }
Beispiel #11
0
        private void LoginBtnClick(object sender, RoutedEventArgs e)
        {
            loginBtn.IsEnabled = false;
            var accCode = -1;

            if (int.TryParse(accCodeTB.Text, out accCode))
            {
                var client = new BetServiceClient();
                try
                {
                    client.Open();
                    var acc = client.GetAccount(accCode);
                    if (acc.Code == 0)
                    {
                        loginStatus.Text = $"There is no account with code - {accCode}";
                    }
                    else
                    {
                        loginStatus.Text = "Succesful login";
                        NavigationService?.Navigate(new AccountManager(accCode));
                    }
                }
                catch (Exception ex)
                {
                    loginStatus.Text = "Cannot connect to server";
                }
                finally
                {
                    client.Close();
                }
            }
            else
            {
                loginStatus.Text = "Incorrect code";
            }
            loginBtn.IsEnabled = true;
        }