using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace JJServiceManager { /// 한 줄 입력 (글자 또는 비밀번호) public sealed class TextPrompt : Window { private readonly TextBox _text; private readonly PasswordBox _pw; private readonly bool _password; private TextPrompt(string title, string message, string initial, bool password, bool upper) { _password = password; Title = title + AppInstance.TitleTag; Width = 460; SizeToContent = SizeToContent.Height; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.CenterOwner; ShowInTaskbar = false; FontFamily = new FontFamily("Malgun Gothic"); FontSize = 13; AppIcon.Apply(this); var root = new StackPanel { Margin = new Thickness(18) }; root.Children.Add(new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 0, 0, 10) }); if (password) { _pw = new PasswordBox { Height = 30, VerticalContentAlignment = VerticalAlignment.Center }; root.Children.Add(_pw); } else { _text = new TextBox { Height = 30, VerticalContentAlignment = VerticalAlignment.Center, Text = initial ?? "", CharacterCasing = upper ? CharacterCasing.Upper : CharacterCasing.Normal, FontFamily = upper ? new FontFamily("Consolas") : FontFamily, FontWeight = upper ? FontWeights.Bold : FontWeights.Normal }; root.Children.Add(_text); } var buttons = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 14, 0, 0) }; var ok = new Button { Content = "확인", MinWidth = 80, IsDefault = true, FontWeight = FontWeights.Bold }; var cancel = new Button { Content = "취소", MinWidth = 80, IsCancel = true, Margin = new Thickness(6, 0, 0, 0) }; ok.Click += (s, e) => DialogResult = true; buttons.Children.Add(ok); buttons.Children.Add(cancel); root.Children.Add(buttons); Content = root; Loaded += (s, e) => { if (_pw != null) _pw.Focus(); else { _text.Focus(); _text.SelectAll(); } }; } private string Value => _password ? _pw.Password : _text.Text.Trim(); /// 입력값 (취소하면 null) public static string Ask(Window owner, string title, string message, string initial = "", bool password = false, bool upper = false) { var w = new TextPrompt(title, message, initial, password, upper); if (owner != null && owner.IsVisible) w.Owner = owner; return w.ShowDialog() == true ? w.Value : null; } } /// 중계 서버 비밀번호 변경 (지금 비밀번호 + 새 비밀번호 두 번) public sealed class ChangePasswordWindow : Window { private readonly PasswordBox _old, _new1, _new2; private readonly TextBlock _msg; public string OldPassword => _old.Password; public string NewPassword => _new1.Password; private ChangePasswordWindow(string message, bool askOld) { Title = "중계 서버 비밀번호 변경" + AppInstance.TitleTag; Width = 440; SizeToContent = SizeToContent.Height; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.CenterOwner; ShowInTaskbar = false; FontFamily = new FontFamily("Malgun Gothic"); FontSize = 13; AppIcon.Apply(this); var root = new StackPanel { Margin = new Thickness(18) }; root.Children.Add(new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 0, 0, 10) }); var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(120) }); grid.ColumnDefinitions.Add(new ColumnDefinition()); _old = new PasswordBox { Height = 28, Margin = new Thickness(0, 3, 0, 3) }; _new1 = new PasswordBox { Height = 28, Margin = new Thickness(0, 3, 0, 3) }; _new2 = new PasswordBox { Height = 28, Margin = new Thickness(0, 3, 0, 3) }; int row = 0; void Add(string label, Control c) { grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); var t = new TextBlock { Text = label, VerticalAlignment = VerticalAlignment.Center }; Grid.SetRow(t, row); Grid.SetRow(c, row); Grid.SetColumn(c, 1); grid.Children.Add(t); grid.Children.Add(c); row++; } if (askOld) Add("지금 비밀번호", _old); Add("새 비밀번호", _new1); Add("새 비밀번호 확인", _new2); root.Children.Add(grid); _msg = new TextBlock { Foreground = Brushes2.Stopped, Margin = new Thickness(0, 8, 0, 0), TextWrapping = TextWrapping.Wrap, Text = "8자 이상" }; root.Children.Add(_msg); var buttons = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 12, 0, 0) }; var ok = new Button { Content = "변경", MinWidth = 80, IsDefault = true, FontWeight = FontWeights.Bold }; var cancel = new Button { Content = "취소", MinWidth = 80, IsCancel = true, Margin = new Thickness(6, 0, 0, 0) }; ok.Click += (s, e) => { if (askOld && _old.Password.Length == 0) { _msg.Text = "지금 비밀번호를 입력하세요."; return; } if (_new1.Password.Length < 8) { _msg.Text = "새 비밀번호는 8자 이상이어야 합니다."; return; } if (_new1.Password != _new2.Password) { _msg.Text = "새 비밀번호와 확인이 다릅니다."; return; } if (askOld && _new1.Password == _old.Password) { _msg.Text = "지금과 다른 비밀번호를 입력하세요."; return; } DialogResult = true; }; buttons.Children.Add(ok); buttons.Children.Add(cancel); root.Children.Add(buttons); Content = root; Loaded += (s, e) => (askOld ? _old : _new1).Focus(); } /// (지금 비밀번호, 새 비밀번호) 또는 취소하면 null. askOld=false면 지금 비밀번호는 빈 값 public static (string oldPw, string newPw)? Ask(Window owner, string message, bool askOld = true) { var w = new ChangePasswordWindow(message, askOld); if (owner != null && owner.IsVisible) w.Owner = owner; return w.ShowDialog() == true ? (w.OldPassword, w.NewPassword) : null; } } }