RecipeNameInputDlg.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.Shapes;
  13. using System.Text.RegularExpressions;
  14. namespace Aitex.UI.RecipeEditor.View
  15. {
  16. /// <summary>
  17. /// Interaction logic for RecipeNameInputDlg.xaml
  18. /// </summary>
  19. public partial class RecipeNameInputDlg : Window
  20. {
  21. public RecipeNameInputDlg(string caption)
  22. {
  23. InitializeComponent();
  24. labelCaption.Text = caption;
  25. this.buttonOK.IsEnabled = false;
  26. this.textBoxInput.Focus();
  27. }
  28. public RecipeNameInputDlg(string caption, string title)
  29. {
  30. InitializeComponent();
  31. Title = title;
  32. labelCaption.Text = caption;
  33. this.buttonOK.IsEnabled = false;
  34. this.textBoxInput.Focus();
  35. }
  36. private void buttonCancel_Click(object sender, RoutedEventArgs e)
  37. {
  38. this.DialogResult = false;
  39. }
  40. private void buttonOK_Click(object sender, RoutedEventArgs e)
  41. {
  42. this.DialogResult = true;
  43. }
  44. private void textBoxInput_TextChanged(object sender, TextChangedEventArgs e)
  45. {
  46. this.buttonOK.IsEnabled = IsValidFileName(textBoxInput.Text);
  47. }
  48. /// <summary>
  49. /// 输入文字
  50. /// </summary>
  51. public string InputText
  52. {
  53. get
  54. {
  55. return this.textBoxInput.Text;
  56. }
  57. set
  58. {
  59. this.textBoxInput.Text = value;
  60. }
  61. }
  62. /// <summary>
  63. /// 文件名校验
  64. /// </summary>
  65. /// <param name="strIn"></param>
  66. /// <returns></returns>
  67. bool IsValidFileName(string strIn)
  68. {
  69. string[] paths = strIn.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
  70. Regex regEx = new Regex(@"^[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*$");
  71. foreach (var path in paths)
  72. {
  73. if (!regEx.IsMatch(path))
  74. return false;
  75. }
  76. return true;
  77. }
  78. }
  79. }