123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using System.Text.RegularExpressions;
- namespace Aitex.UI.RecipeEditor.View
- {
- /// <summary>
- /// Interaction logic for RecipeNameInputDlg.xaml
- /// </summary>
- public partial class RecipeNameInputDlg : Window
- {
- public RecipeNameInputDlg(string caption)
- {
- InitializeComponent();
- labelCaption.Text = caption;
- this.buttonOK.IsEnabled = false;
- this.textBoxInput.Focus();
- }
- public RecipeNameInputDlg(string caption, string title)
- {
- InitializeComponent();
- Title = title;
- labelCaption.Text = caption;
- this.buttonOK.IsEnabled = false;
- this.textBoxInput.Focus();
- }
- private void buttonCancel_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- }
- private void buttonOK_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = true;
- }
- private void textBoxInput_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (textBoxInput.Text == "")
- {
- this.buttonOK.IsEnabled=false;
- }
- else
- {
- this.buttonOK.IsEnabled = IsValidFileName(textBoxInput.Text);
- }
- }
- /// <summary>
- /// 输入文字
- /// </summary>
- public string InputText
- {
- get
- {
- return this.textBoxInput.Text;
- }
- set
- {
- this.textBoxInput.Text = value;
- }
- }
- public string SelectedType { get; set; }
- /// <summary>
- /// 文件名校验
- /// </summary>
- /// <param name="strIn"></param>
- /// <returns></returns>
- bool IsValidFileName(string strIn)
- {
- string[] paths = strIn.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
- Regex regEx = new Regex(@"^[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*$");
- foreach (var path in paths)
- {
- if (!regEx.IsMatch(path))
- return false;
- }
- return true;
- }
- private void RadioButton_Checked(object sender, RoutedEventArgs e)
- {
- SelectedType = (sender as RadioButton).Content.ToString();
- }
- }
- }
|