AccountCreation.xaml.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Windows;
  2. using Aitex.Core.Account;
  3. namespace MECF.Framework.UI.Core.Accounts
  4. {
  5. /// <summary>
  6. /// Interaction logic for AccountCreation.xaml
  7. /// </summary>
  8. public partial class AccountCreation : Window
  9. {
  10. Account _account = new Account();
  11. public AccountCreation()
  12. {
  13. InitializeComponent();
  14. DataContext = _account;
  15. var roles = AccountClient.Instance.Service.GetAllRoles();
  16. foreach (var item in roles)
  17. {
  18. comboBoxGroup.Items.Add(item);
  19. }
  20. comboBoxGroup.SelectedItem = _account.Role;
  21. }
  22. /// <summary>
  23. /// Save current configuration
  24. /// </summary>
  25. /// <param name="sender"></param>
  26. /// <param name="e"></param>
  27. private void button_Save_Click(object sender, RoutedEventArgs e)
  28. {
  29. Account account = DataContext as Account;
  30. if (string.IsNullOrEmpty((string)comboBoxGroup.SelectedValue))
  31. {
  32. MessageBox.Show("Please select role", "Account", MessageBoxButton.OK, MessageBoxImage.Warning);
  33. return;
  34. }
  35. account.Role = (string)comboBoxGroup.SelectedValue;
  36. var ret = AccountClient.Instance.Service.CreateAccount(account);
  37. if (ret.ActSucc)
  38. {
  39. DialogResult = true;
  40. Close();
  41. MessageBox.Show(string.Format("\" {0} \" created!", _account.AccountId), "Account", MessageBoxButton.OK, MessageBoxImage.Information);
  42. }
  43. else
  44. {
  45. MessageBox.Show(string.Format("\" {0} \" create failed,\r\n{1}", _account.AccountId, ret.Description), "Account", MessageBoxButton.OK, MessageBoxImage.Warning);
  46. }
  47. }
  48. }
  49. }