AccountManagerView.xaml.cs 7.8 KB

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