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; } }
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; } }
async private void Window_Loaded(object sender, RoutedEventArgs e) { TransfersList.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("TransferDate", System.ComponentModel.ListSortDirection.Descending)); cust = this.DataContext as Customer; try { CreditsText.Text = "getting balance...."; await Task.Delay(500); CreditsText.Text = (await ResellerAPI.GetCustomerInfo(cust)).ToString(); } catch (Exception) { CreditsText.Text = "NA"; } }
async private void AddButton_Click(object sender, RoutedEventArgs e) { AddButton.IsEnabled = false; ErrorLabel.Text = ""; string name = ResellerNameTextBox.Text.ToLowerInvariant(); string pass = ResellerPassTextBox.Text; if (!name.Contains("ahkvoip")) { ErrorLabel.Text = "Reseller not working with this program."; return; } try { bool resellerCreated = await ResellerAPI.CheckReseller(name, pass); if (resellerCreated) { ResellerXml.AddReseller(name, pass); ResellerNameTextBox.Text = ""; ResellerPassTextBox.Text = ""; App.CustomersDB.AddReseller(new Reseller(name, pass)); } else { ErrorLabel.Text = "Wrong password,try again later"; AddButton.IsEnabled = true; } } catch (NoInternetException) { ErrorLabel.Text = "No Internet Connection!"; AddButton.IsEnabled = true; } catch (Exception ex) { ErrorLabel.Text = ex.Message; } }
async private void TextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TextBlock tb = sender as TextBlock; try { if (PasswordTextbox.Text.Length > 5) { tb.Cursor = Cursors.Wait; if (tb.Text.StartsWith("reset")) { tb.Text = "Resetting"; await ResellerAPI.ResetPassword(cust, PasswordTextbox.Text); } else { bool b = await ResellerAPI.CheckPassword(cust, PasswordTextbox.Text); if (!b) { PasswordTextbox.Text = ""; tb.Cursor = Cursors.Hand; return; } } cust.Password = PasswordTextbox.Text; tb.Text = "check password"; tb.Cursor = Cursors.Hand; App.CustomersDB.UpdateCustomer(cust); } else if (PasswordTextbox.Text.Length == 0) { cust.Password = ""; App.CustomersDB.UpdateCustomer(cust); } } catch (Exception) { } }