AccountManagerView.xaml.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using Aitex.Core.Account;
  4. namespace MECF.Framework.UI.Core.Accounts
  5. {
  6. /// <summary>
  7. /// Interaction logic for AccountManagement.xaml
  8. /// </summary>
  9. public partial class AccountManagerView : UserControl
  10. {
  11. public AccountManagerView()
  12. {
  13. InitializeComponent();
  14. Loaded += new RoutedEventHandler(AccountManagement_Loaded);
  15. dataGrid1.CanUserAddRows = false;
  16. }
  17. bool _hideDisabledAccounts = false;
  18. /// <summary>
  19. /// When loaded
  20. /// </summary>
  21. /// <param name="sender"></param>
  22. /// <param name="e"></param>
  23. void AccountManagement_Loaded(object sender, RoutedEventArgs e)
  24. {
  25. _hideDisabledAccounts = false;
  26. UpdateAccountList();
  27. this.IsEnabled = true;
  28. this.Name = "account";
  29. switch (this.GetPermission())
  30. {
  31. case ViewPermission.FullyControl:
  32. btnCreateAccount.Visibility = System.Windows.Visibility.Visible;
  33. btnDeleteAccount.Visibility = System.Windows.Visibility.Visible;
  34. btnUserProperty.Visibility = System.Windows.Visibility.Visible;
  35. btnUserPwd.Visibility = System.Windows.Visibility.Visible;
  36. //btnShowOnline.Visibility = System.Windows.Visibility.Visible;
  37. btnRoleEdit.Visibility = System.Windows.Visibility.Visible;
  38. //btnPermission.Visibility = System.Windows.Visibility.Visible;
  39. break;
  40. default:
  41. btnCreateAccount.Visibility = System.Windows.Visibility.Hidden;
  42. btnDeleteAccount.Visibility = System.Windows.Visibility.Hidden;
  43. btnUserProperty.Visibility = System.Windows.Visibility.Hidden;
  44. btnUserPwd.Visibility = System.Windows.Visibility.Hidden;
  45. //btnShowOnline.Visibility = System.Windows.Visibility.Hidden;
  46. btnRoleEdit.Visibility = System.Windows.Visibility.Hidden;
  47. //btnPermission.Visibility = System.Windows.Visibility.Hidden;
  48. break;
  49. }
  50. }
  51. /// <summary>
  52. /// Update account list
  53. /// </summary>
  54. private void UpdateAccountList()
  55. {
  56. DataContext = new AccountViewModel(_hideDisabledAccounts);
  57. }
  58. /// <summary>
  59. /// Toggle user list (enable only/show all)
  60. /// </summary>
  61. /// <param name="sender"></param>
  62. /// <param name="e"></param>
  63. private void checkBoxToggleAvailable_Click(object sender, RoutedEventArgs e)
  64. {
  65. _hideDisabledAccounts = !_hideDisabledAccounts;
  66. UpdateAccountList();
  67. }
  68. /// <summary>
  69. /// delete selected account
  70. /// </summary>
  71. /// <param name="sender"></param>
  72. /// <param name="e"></param>
  73. private void btnDeleteAccount_Click(object sender, RoutedEventArgs e)
  74. {
  75. var item = dataGrid1.SelectedItem as AccountViewModel.AccountInfo;
  76. if (item == null) return;
  77. if (MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableAccountViewDeleteInfo"].ToString(), item.AccountId), Application.Current.Resources["GlobalLableAccountViewMsgTitle"].ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  78. {
  79. var ret = AccountClient.Instance.Service.DeleteAccount(item.AccountId);
  80. if (ret.ActSucc)
  81. {
  82. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableAccountViewDeleteOk"].ToString(), item.AccountId), Application.Current.Resources["GlobalLableAccountViewMsgTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Information);
  83. }
  84. else
  85. {
  86. MessageBox.Show(string.Format(Application.Current.Resources["GlobalLableAccountViewDeleteFailed"].ToString(), item.AccountId, ret.Description), Application.Current.Resources["GlobalLableAccountViewMsgTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
  87. }
  88. UpdateAccountList();
  89. }
  90. }
  91. /// <summary>
  92. /// Change user's password
  93. /// </summary>
  94. /// <param name="sender"></param>
  95. /// <param name="e"></param>
  96. private void btnUserPwd_Click(object sender, RoutedEventArgs e)
  97. {
  98. var item = dataGrid1.SelectedItem as AccountViewModel.AccountInfo;
  99. if (item == null) return;
  100. UserPwdChangeView view = new UserPwdChangeView(item.AccountId) { Owner = Application.Current.MainWindow };
  101. view.ShowDialog();
  102. }
  103. /// <summary>
  104. /// Edit current selected users
  105. /// </summary>
  106. /// <param name="sender"></param>
  107. /// <param name="e"></param>
  108. private void btnRoleEdit_Click(object sender, RoutedEventArgs e)
  109. {
  110. RoleEditView view = new RoleEditView() { Owner = Application.Current.MainWindow };
  111. view.ShowDialog();
  112. }
  113. /// <summary>
  114. /// Show current online users
  115. /// </summary>
  116. /// <param name="sender"></param>
  117. /// <param name="e"></param>
  118. private void btnShowOnline_Click(object sender, RoutedEventArgs e)
  119. {
  120. CurrentLogInUsers view = new CurrentLogInUsers() { Owner = Application.Current.MainWindow };
  121. view.ShowDialog();
  122. }
  123. /// <summary>
  124. /// Edit user's profile
  125. /// </summary>
  126. /// <param name="sender"></param>
  127. /// <param name="e"></param>
  128. private void btnUserProperty_Click(object sender, RoutedEventArgs e)
  129. {
  130. var item = dataGrid1.SelectedItem as AccountViewModel.AccountInfo;
  131. if (item == null) return;
  132. var editor = new UserAccountEdit(item.Account) { Owner = Application.Current.MainWindow };
  133. var ret = editor.ShowDialog();
  134. if (ret.HasValue && ret.Value)
  135. {
  136. UpdateAccountList();
  137. }
  138. }
  139. /// <summary>
  140. /// Create account
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. private void button_CreateAccount_Click(object sender, RoutedEventArgs e)
  145. {
  146. AccountCreation view = new AccountCreation() { Owner = Application.Current.MainWindow };
  147. var ret = view.ShowDialog();
  148. if (ret.HasValue && ret.Value)
  149. UpdateAccountList();
  150. }
  151. /// <summary>
  152. /// 显示个人账号信息页面
  153. /// </summary>
  154. /// <param name="sender"></param>
  155. /// <param name="e"></param>
  156. private void button_MyAccount_Click(object sender, RoutedEventArgs e)
  157. {
  158. MyAccount view = new MyAccount() { Owner = Application.Current.MainWindow };
  159. view.ShowDialog();
  160. }
  161. private void btnPermission_Click(object sender, RoutedEventArgs e)
  162. {
  163. RolePermissionEdit view = new RolePermissionEdit() { Owner = Application.Current.MainWindow };
  164. view.ShowDialog();
  165. }
  166. }
  167. }