Ejemplo n.º 1
0
        async private void Button_Click(object sender, RoutedEventArgs e)
        {
            AddButton.IsEnabled     = false;
            ErrorEllipse.Visibility = System.Windows.Visibility.Collapsed;

            ErrorText.Text       = "";
            ErrorText.Foreground = Brushes.Green;

            if (string.IsNullOrWhiteSpace(PasswordTextbox.Text))
            {
                ErrorEllipse.Visibility = System.Windows.Visibility.Visible;
                return;
            }

            try
            {
                Customer c = await ResellerAPI.CreateUser(Tag as Reseller, UsernameTextbox.Text, PasswordTextbox.Text, 4);

                c.PhoneNumber = PhoneTextbox.Text;
                App.CustomersDB.AddCustomer(c);

                ErrorText.Text = "Customer created. Waiting to send 4.5 = 11000";

                await Task.Delay(2000);

                Transfer t = new Transfer(Configuration.InitialTopup, Configuration.InitialCost, DateTime.Now);
                await ResellerAPI.TransferEuro(c, t);

                App.CustomersDB.AddTransfer(c, t);

                ErrorText.Text = "Credits sent. Closing after a moment";

                await Task.Delay(3000);

                this.DialogResult = true;

                (this.Owner as MainWindow).SelectCustomer(c);

                this.Close();
            }
            catch (NoInternetException)
            {
                ErrorText.Text       = "No internet connection";
                ErrorText.Foreground = Brushes.Red;
            }
            catch (InvalidOperationException ex)
            {
                ErrorText.Text       = ex.Message;
                ErrorText.Foreground = Brushes.Red;
            }
            catch (Exception)
            {
                ErrorText.Text       = "Unknown error..";
                ErrorText.Foreground = Brushes.Red;
            }
            finally
            {
                AddButton.IsEnabled = true;
            }
        }
Ejemplo n.º 2
0
        async private Task transferEuro(Customer cust, Transfer trans)
        {
            switch (MessageBox.Show(
                        string.Format("Are you sure to send {0:0.00} euro (cost {1})\n     to the user : {2} ?", trans.Amount, trans.Cost, cust.Username),
                        "Confirm Transfer", MessageBoxButton.OKCancel)
                    )
            {
            case MessageBoxResult.Cancel:
                FocusManager.SetFocusedElement(this, textBox1);
                return;
            }

            try
            {
                btnTransfer.IsEnabled = false;
                closeApp.IsEnabled    = false;
                await ResellerAPI.TransferEuro(cust, trans);

                tblkResult.Text       = "Sent successfully";
                tblkResult.Foreground = Brushes.Green;
                App.CustomersDB.AddTransfer(cust, trans);
                closeApp.IsEnabled = true;
            }
            catch (InvalidOperationException)
            {
                tblkResult.Text       = "User not found!";
                tblkResult.Foreground = Brushes.Red;
            }
            catch (NoInternetException)
            {
                tblkResult.Text       = "No Internet!!";
                tblkResult.Foreground = Brushes.Red;
            }
        }