PresetGroupSaveDialog.xaml.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Windows;
  5. namespace MECF.Framework.UI.Client.ClientViews.Dialogs
  6. {
  7. /// <summary>
  8. /// PresetGroupSaveDialog.xaml 的交互逻辑
  9. /// </summary>
  10. public partial class PresetGroupSaveDialog
  11. {
  12. #region Variables
  13. private readonly IEnumerable<string> _existFileNames;
  14. #endregion
  15. #region Constructors
  16. public PresetGroupSaveDialog(string title, IEnumerable<string> existFileNames, string defaultGroupName = "")
  17. {
  18. InitializeComponent();
  19. Title = title;
  20. _existFileNames = existFileNames;
  21. if (!string.IsNullOrEmpty(defaultGroupName))
  22. txtGroupName.Text = defaultGroupName;
  23. }
  24. #endregion
  25. #region Properties
  26. public string GroupName => txtGroupName.Text;
  27. #endregion
  28. #region Methods
  29. protected override void OnActivated(System.EventArgs e)
  30. {
  31. txtGroupName.SelectAll();
  32. txtGroupName.Focus();
  33. }
  34. #endregion
  35. #region Events
  36. private void BtnOk_OnClick(object sender, RoutedEventArgs e)
  37. {
  38. // 检查文件明是否为空
  39. if (string.IsNullOrEmpty(GroupName))
  40. {
  41. txtErrors.Text = "Group Name is Empty";
  42. txtGroupName.SelectAll();
  43. txtGroupName.Focus();
  44. return;
  45. }
  46. // 检查文件名是否包含非法字符
  47. if (GroupName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
  48. {
  49. txtErrors.Text = "illegal char(s) in Group Name";
  50. txtGroupName.SelectAll();
  51. txtGroupName.Focus();
  52. return;
  53. }
  54. if (_existFileNames != null && _existFileNames.Contains(GroupName))
  55. {
  56. txtErrors.Text = "Group Name has existed";
  57. txtGroupName.SelectAll();
  58. txtGroupName.Focus();
  59. return;
  60. }
  61. this.DialogResult = true;
  62. }
  63. private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
  64. {
  65. DialogResult = false;
  66. }
  67. #endregion
  68. }
  69. }