RecipeNameInputDlg.xaml.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. if (textBoxInput.Text == "")
  47. {
  48. this.buttonOK.IsEnabled=false;
  49. }
  50. else
  51. {
  52. this.buttonOK.IsEnabled = IsValidFileName(textBoxInput.Text);
  53. }
  54. }
  55. /// <summary>
  56. /// 输入文字
  57. /// </summary>
  58. public string InputText
  59. {
  60. get
  61. {
  62. return this.textBoxInput.Text;
  63. }
  64. set
  65. {
  66. this.textBoxInput.Text = value;
  67. }
  68. }
  69. public string SelectedType { get; set; }
  70. /// <summary>
  71. /// 文件名校验
  72. /// </summary>
  73. /// <param name="strIn"></param>
  74. /// <returns></returns>
  75. bool IsValidFileName(string strIn)
  76. {
  77. string[] paths = strIn.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
  78. Regex regEx = new Regex(@"^[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*$");
  79. foreach (var path in paths)
  80. {
  81. if (!regEx.IsMatch(path))
  82. return false;
  83. }
  84. return true;
  85. }
  86. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  87. {
  88. SelectedType = (sender as RadioButton).Content.ToString();
  89. }
  90. }
  91. }