SettingPage.xaml.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System.Collections.Generic;
  2. using System.Collections.ObjectModel;
  3. using Agent.Services;
  4. using Agent.Models;
  5. using log4net;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace Agent.Views
  9. {
  10. /// <summary>
  11. /// Interaction logic for SettingPage.xaml
  12. /// </summary>
  13. public partial class SettingPage : Page
  14. {
  15. private static readonly ILog log = LogManager.GetLogger(typeof(SettingPage));
  16. private readonly UserService _userService = new UserService();
  17. private readonly StartupService _startupService = new StartupService();
  18. private readonly PolicyService policyService = new PolicyService();
  19. private readonly ObservableCollection<PolicyListItem> _policyList = new ObservableCollection<PolicyListItem>();
  20. public SettingPage()
  21. {
  22. InitializeComponent();
  23. LoadSetting();
  24. }
  25. public void LoadSetting()
  26. {
  27. StartupCheckbox.IsChecked = (bool)Application.Current.Properties["user_is_startup"];
  28. BackupComboBox.SelectedValue = Application.Current.Properties["user_backup_type"];
  29. RetryCheckBox.IsChecked = (bool)Application.Current.Properties["user_is_retry"];
  30. LimitCheckBox.IsChecked = (bool)Application.Current.Properties["user_is_limit"];
  31. HashCheckBox.IsChecked = (bool)Application.Current.Properties["user_is_hash"];
  32. UserNameTextBox.Text = (string)Application.Current.Properties["user_name"];
  33. UserTag1.Text = (string)Application.Current.Properties["user_tag1"];
  34. UserTag2.Text = (string)Application.Current.Properties["user_tag2"];
  35. UserTag3.Text = (string)Application.Current.Properties["user_tag3"];
  36. UserTag4.Text = (string)Application.Current.Properties["user_tag4"];
  37. UserTag5.Text = (string)Application.Current.Properties["user_tag5"];
  38. UserTag6.Text = (string)Application.Current.Properties["user_tag6"];
  39. UserTag7.Text = (string)Application.Current.Properties["user_tag7"];
  40. UserTag8.Text = (string)Application.Current.Properties["user_tag8"];
  41. UserTag9.Text = (string)Application.Current.Properties["user_tag9"];
  42. UserTag10.Text = (string)Application.Current.Properties["user_tag10"];
  43. }
  44. private void Button_Click(object sender, RoutedEventArgs e)
  45. {
  46. var userName = UserNameTextBox.Text;
  47. if (string.Empty == userName)
  48. {
  49. MessageBox.Show("에이전트 이름을 입력해주세요", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  50. UserNameTextBox.Focus();
  51. return;
  52. }
  53. if (15 < userName.Length)
  54. {
  55. MessageBox.Show("에이전트 이름은 10자 이내입니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  56. UserNameTextBox.Focus();
  57. return;
  58. }
  59. var isStartup = _startupService.GetStatusWithToggle(StartupCheckbox.IsChecked.Value);
  60. var isRetry = RetryCheckBox.IsChecked.Value;
  61. var isLimit = LimitCheckBox.IsChecked.Value;
  62. var backupType = BackupComboBox.SelectedValue.ToString();
  63. var isHash = HashCheckBox.IsChecked.Value;
  64. var userId = Application.Current.Properties["user_id"];
  65. /* -- 설정화면 Tag값 기본설정 취소
  66. var tag1 = UserTag1.Text == string.Empty ? "TAG1" : UserTag1.Text;
  67. var tag2 = UserTag2.Text == string.Empty ? "TAG2" : UserTag2.Text;
  68. var tag3 = UserTag3.Text == string.Empty ? "TAG3" : UserTag3.Text;
  69. var tag4 = UserTag4.Text == string.Empty ? "TAG4" : UserTag4.Text;
  70. var tag5 = UserTag5.Text == string.Empty ? "TAG5" : UserTag5.Text;
  71. var tag6 = UserTag6.Text == string.Empty ? "TAG6" : UserTag6.Text;
  72. var tag7 = UserTag7.Text == string.Empty ? "TAG7" : UserTag7.Text;
  73. var tag8 = UserTag8.Text == string.Empty ? "TAG8" : UserTag8.Text;
  74. var tag9 = UserTag9.Text == string.Empty ? "TAG9" : UserTag9.Text;
  75. var tag10 = UserTag10.Text == string.Empty ? "TAG10" : UserTag10.Text;
  76. */
  77. var tag1 = UserTag1.Text == string.Empty ? "" : UserTag1.Text;
  78. var tag2 = UserTag2.Text == string.Empty ? "" : UserTag2.Text;
  79. var tag3 = UserTag3.Text == string.Empty ? "" : UserTag3.Text;
  80. var tag4 = UserTag4.Text == string.Empty ? "" : UserTag4.Text;
  81. var tag5 = UserTag5.Text == string.Empty ? "" : UserTag5.Text;
  82. var tag6 = UserTag6.Text == string.Empty ? "" : UserTag6.Text;
  83. var tag7 = UserTag7.Text == string.Empty ? "" : UserTag7.Text;
  84. var tag8 = UserTag8.Text == string.Empty ? "" : UserTag8.Text;
  85. var tag9 = UserTag9.Text == string.Empty ? "" : UserTag9.Text;
  86. var tag10 = UserTag10.Text == string.Empty ? "" : UserTag10.Text;
  87. var insertedUser = _userService.ModifyUser(isStartup, isRetry, isLimit, isHash, backupType, userName,
  88. tag1, tag2, tag3, tag4, tag5, tag6, tag7, tag8, tag9, tag10);
  89. if (null == insertedUser)
  90. {
  91. MessageBox.Show("실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  92. return;
  93. }
  94. var result = MessageBox.Show("수정하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
  95. if (result == MessageBoxResult.No)
  96. {
  97. return;
  98. }
  99. var frm1 = new LoginWindow();
  100. if (frm1.ShowDialog() == true)
  101. {
  102. _userService.Insert_updateAT("수정", frm1.ReturnValue1, "설정 변경",
  103. isStartup, isRetry, isLimit, isHash, backupType, userName,
  104. tag1, tag2, tag3, tag4, tag5, tag6, tag7, tag8, tag9, tag10);
  105. log.Info($"[di_user]시작프로그램 등록={isStartup}");
  106. log.Info($"[di_user]백업 실패 재시도={isRetry}");
  107. log.Info($"[di_user]대용량 업로드 일일 제한={isLimit}");
  108. log.Info($"[di_user]중복 업로드 제한={isHash}");
  109. log.Info($"[di_user]태그 설정값 TAG1={tag1},TAG2={tag2},TAG3={tag3},TAG4={tag4},TAG5={tag5},TAG6={tag6},TAG7={tag7},TAG8={tag8},TAG9={tag9},TAG10={tag10}");
  110. _userService.SaveUserProperties(insertedUser);
  111. if (isStartup)
  112. {
  113. _startupService.Enabled();
  114. }
  115. else
  116. {
  117. _startupService.Disabled();
  118. }
  119. policyService.UpdateScheduledPolicyJob();
  120. (Window.GetWindow(this) as MainWindow).UpdateName();
  121. MessageBox.Show("적용되었습니다.", "확인", MessageBoxButton.OK, MessageBoxImage.Information);
  122. LoadSetting();
  123. }
  124. else
  125. {
  126. return;
  127. }
  128. }
  129. }
  130. }