示例#1
0
        async private void balanceTextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            TextBlock balanceTB = sender as TextBlock;

            if (balanceTB.Cursor != Cursors.Wait)
            {
                var bin = balanceTB.GetBindingExpression(TextBlock.TextProperty).ParentBinding;
                balanceTB.Text = "wait";
                FanytelUser user = balanceTB.Tag as FanytelUser;

                balanceTB.Cursor = Cursors.Wait;
                try
                {
                    TextError.Visibility = Visibility.Collapsed;
                    await user.GetBalance();
                }
                catch (Exception)
                {
                    TextError.Visibility = Visibility.Visible;
                }

                balanceTB.Cursor = Cursors.Hand;
                balanceTB.SetBinding(TextBlock.TextProperty, bin);
            }
        }
示例#2
0
        public static void GetUsers()
        {
            if (File.Exists(usersPath))
            {
                Users.Clear();
                string[] usersData = File.ReadAllLines(usersPath);
                foreach (string s in usersData)
                {
                    string[]    data = s.Split(new char[] { ',' });
                    FanytelUser u    = new FanytelUser();
                    u.PhoneNumber  = data[0];
                    u.Password     = data[1];
                    u.Balance      = double.Parse(data[2]);
                    u.ResellerRate = int.Parse(data[3]);

                    Users.Add(u);
                }
            }
            else
            {
                File.Create(usersPath);
            }
        }
示例#3
0
        private void buttonPinOk_Click(object sender, RoutedEventArgs e)
        {
            listBox.Visibility = Visibility.Visible;
            gridPin.Visibility = Visibility.Collapsed;

            FanytelUser addedUser = new FanytelUser()
            {
                PhoneNumber = queryTextBox.Text,
                Password    = textBoxPin.Text
            };

            App.GetUsers();
            App.Users.Insert(0, addedUser);
            App.SaveUsers();
            TBUsersCount.Text = App.Users.Count.ToString();
            queryTextBox.Clear();
            textBoxPin.Clear();

            listBox.ScrollIntoView(addedUser);
            listBox.SelectedItem = addedUser;

            amountTextBox.SelectAll();
            amountTextBox.Focus();
        }
示例#4
0
        async private void transferButton_Click(object sender, RoutedEventArgs e)
        {
            transferButton.IsEnabled = false;
            closeApp.IsEnabled       = false;

            transferButton.Content = "waiting...";
            while (App.Reseller.Balance == 0)
            {
                await Task.Delay(500);
            }
            transferButton.Content = "Send";

            FanytelUser user = listBox.SelectedItem as FanytelUser;

            amount = Math.Round(amount * 100) / 100;
            if (user.PhoneNumber.EndsWith("*"))
            {
                MessageBox.Show("This number is blacklisted.\n\rCan't Transfer balance from us.", "BlackList", MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }
            if (MessageBox.Show(string.Format("Are you sure you want to send {0} $ \r\n    to the number {1}", amount, user.PhoneNumber), "Transfer Credit", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                int resultCode = await App.Reseller.TransferBalance(user.PhoneNumber, amount);

                switch (resultCode)
                {
                case 0:
                    MessageBox.Show("Internet Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    break;

                case 1:
                    Transfer trans = new Transfer();
                    trans.Amount      = amount;
                    trans.PhoneNumber = user.PhoneNumber;
                    trans.Date        = DateTime.Now.AddSeconds(-3);
                    trans.Price       = price;
                    App.GetTransfers();
                    App.Transfers.Insert(0, trans);
                    App.SaveTransfers();
                    await user.GetBalance();

                    todayLabel.Content = string.Format("Today: {0:0.00} , {1}", Transfer.GetTotalAmount(DateTime.Now), Transfer.GetTotalPrice(DateTime.Now));

                    amountTextBox.Text = "0";

                    queryTextBox.Focus();
                    queryTextBox.SelectAll();
                    MessageBox.Show("Transferred Successfully");
                    break;

                case 2:
                    MessageBox.Show(string.Format("This number ({0}) is not a user yet", user.PhoneNumber), "Not found",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                    break;
                }
            }
            else
            {
                transferButton.IsEnabled = true;
            }

            closeApp.IsEnabled = true;
        }