using System.Collections.Generic; using System.Collections.ObjectModel; using Agent.Services; using Agent.Models; using log4net; using System.Windows; using System.Windows.Controls; namespace Agent.Views { /// /// Interaction logic for SettingPage.xaml /// public partial class SettingPage : Page { private static readonly ILog log = LogManager.GetLogger(typeof(SettingPage)); private readonly UserService _userService = new UserService(); private readonly StartupService _startupService = new StartupService(); private readonly PolicyService policyService = new PolicyService(); private readonly ObservableCollection _policyList = new ObservableCollection(); public SettingPage() { InitializeComponent(); LoadSetting(); } public void LoadSetting() { StartupCheckbox.IsChecked = (bool)Application.Current.Properties["user_is_startup"]; BackupComboBox.SelectedValue = Application.Current.Properties["user_backup_type"]; RetryCheckBox.IsChecked = (bool)Application.Current.Properties["user_is_retry"]; LimitCheckBox.IsChecked = (bool)Application.Current.Properties["user_is_limit"]; HashCheckBox.IsChecked = (bool)Application.Current.Properties["user_is_hash"]; UserNameTextBox.Text = (string)Application.Current.Properties["user_name"]; UserTag1.Text = (string)Application.Current.Properties["user_tag1"]; UserTag2.Text = (string)Application.Current.Properties["user_tag2"]; UserTag3.Text = (string)Application.Current.Properties["user_tag3"]; UserTag4.Text = (string)Application.Current.Properties["user_tag4"]; UserTag5.Text = (string)Application.Current.Properties["user_tag5"]; UserTag6.Text = (string)Application.Current.Properties["user_tag6"]; UserTag7.Text = (string)Application.Current.Properties["user_tag7"]; UserTag8.Text = (string)Application.Current.Properties["user_tag8"]; UserTag9.Text = (string)Application.Current.Properties["user_tag9"]; UserTag10.Text = (string)Application.Current.Properties["user_tag10"]; } private void Button_Click(object sender, RoutedEventArgs e) { var userName = UserNameTextBox.Text; if (string.Empty == userName) { MessageBox.Show("에이전트 이름을 입력해주세요", "오류", MessageBoxButton.OK, MessageBoxImage.Error); UserNameTextBox.Focus(); return; } if (15 < userName.Length) { MessageBox.Show("에이전트 이름은 10자 이내입니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error); UserNameTextBox.Focus(); return; } var isStartup = _startupService.GetStatusWithToggle(StartupCheckbox.IsChecked.Value); var isRetry = RetryCheckBox.IsChecked.Value; var isLimit = LimitCheckBox.IsChecked.Value; var backupType = BackupComboBox.SelectedValue.ToString(); var isHash = HashCheckBox.IsChecked.Value; var userId = Application.Current.Properties["user_id"]; /* -- 설정화면 Tag값 기본설정 취소 var tag1 = UserTag1.Text == string.Empty ? "TAG1" : UserTag1.Text; var tag2 = UserTag2.Text == string.Empty ? "TAG2" : UserTag2.Text; var tag3 = UserTag3.Text == string.Empty ? "TAG3" : UserTag3.Text; var tag4 = UserTag4.Text == string.Empty ? "TAG4" : UserTag4.Text; var tag5 = UserTag5.Text == string.Empty ? "TAG5" : UserTag5.Text; var tag6 = UserTag6.Text == string.Empty ? "TAG6" : UserTag6.Text; var tag7 = UserTag7.Text == string.Empty ? "TAG7" : UserTag7.Text; var tag8 = UserTag8.Text == string.Empty ? "TAG8" : UserTag8.Text; var tag9 = UserTag9.Text == string.Empty ? "TAG9" : UserTag9.Text; var tag10 = UserTag10.Text == string.Empty ? "TAG10" : UserTag10.Text; */ var tag1 = UserTag1.Text == string.Empty ? "" : UserTag1.Text; var tag2 = UserTag2.Text == string.Empty ? "" : UserTag2.Text; var tag3 = UserTag3.Text == string.Empty ? "" : UserTag3.Text; var tag4 = UserTag4.Text == string.Empty ? "" : UserTag4.Text; var tag5 = UserTag5.Text == string.Empty ? "" : UserTag5.Text; var tag6 = UserTag6.Text == string.Empty ? "" : UserTag6.Text; var tag7 = UserTag7.Text == string.Empty ? "" : UserTag7.Text; var tag8 = UserTag8.Text == string.Empty ? "" : UserTag8.Text; var tag9 = UserTag9.Text == string.Empty ? "" : UserTag9.Text; var tag10 = UserTag10.Text == string.Empty ? "" : UserTag10.Text; var insertedUser = _userService.ModifyUser(isStartup, isRetry, isLimit, isHash, backupType, userName, tag1, tag2, tag3, tag4, tag5, tag6, tag7, tag8, tag9, tag10); if (null == insertedUser) { MessageBox.Show("실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error); return; } var result = MessageBox.Show("수정하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { return; } var frm1 = new LoginWindow(); if (frm1.ShowDialog() == true) { _userService.Insert_updateAT("수정", frm1.ReturnValue1, "설정 변경", isStartup, isRetry, isLimit, isHash, backupType, userName, tag1, tag2, tag3, tag4, tag5, tag6, tag7, tag8, tag9, tag10); log.Info($"[di_user]시작프로그램 등록={isStartup}"); log.Info($"[di_user]백업 실패 재시도={isRetry}"); log.Info($"[di_user]대용량 업로드 일일 제한={isLimit}"); log.Info($"[di_user]중복 업로드 제한={isHash}"); log.Info($"[di_user]태그 설정값 TAG1={tag1},TAG2={tag2},TAG3={tag3},TAG4={tag4},TAG5={tag5},TAG6={tag6},TAG7={tag7},TAG8={tag8},TAG9={tag9},TAG10={tag10}"); _userService.SaveUserProperties(insertedUser); if (isStartup) { _startupService.Enabled(); } else { _startupService.Disabled(); } policyService.UpdateScheduledPolicyJob(); (Window.GetWindow(this) as MainWindow).UpdateName(); MessageBox.Show("적용되었습니다.", "확인", MessageBoxButton.OK, MessageBoxImage.Information); LoadSetting(); } else { return; } } } }