Skip to content

Commit

Permalink
Upgrade to v2.1
Browse files Browse the repository at this point in the history
Upgrade to v2.1
Support some experimental features
Add install key mode (without activate)
Add manual enter key mode
  • Loading branch information
TGSAN committed May 31, 2018
1 parent 824f03b commit f51df4a
Show file tree
Hide file tree
Showing 22 changed files with 2,032 additions and 152 deletions.
Binary file modified .vs/CMWTAT_DIGITAL/v15/.suo
Binary file not shown.
Binary file modified .vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed CMWTAT_DIGITAL/CMWTAT.ico
Binary file not shown.
Binary file removed CMWTAT_DIGITAL/CMWTAT.png
Binary file not shown.
3 changes: 3 additions & 0 deletions CMWTAT_DIGITAL/CMWTAT_DIGITAL.csproj
Expand Up @@ -82,6 +82,9 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Domain\IsSN.cs" />
<Compile Include="Domain\NotifyPropertyChangedExtension.cs" />
<Compile Include="Domain\ViewModel.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
82 changes: 82 additions & 0 deletions CMWTAT_DIGITAL/Domain/IsSN.cs
@@ -0,0 +1,82 @@
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Controls;

namespace CMWTAT_DIGITAL.Domain
{
class IsSN : ValidationRule
{
#region 匹配方法

/// <summary>
/// 验证字符串是否匹配正则表达式描述的规则
/// </summary>
/// <param name="inputStr">待验证的字符串</param>
/// <param name="patternStr">正则表达式字符串</param>
/// <returns>是否匹配</returns>
public static bool IsMatch(string inputStr, string patternStr)
{
return IsMatch(inputStr, patternStr, false, false);
}

/// <summary>
/// 验证字符串是否匹配正则表达式描述的规则
/// </summary>
/// <param name="inputStr">待验证的字符串</param>
/// <param name="patternStr">正则表达式字符串</param>
/// <param name="ifIgnoreCase">匹配时是否不区分大小写</param>
/// <returns>是否匹配</returns>
public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase)
{
return IsMatch(inputStr, patternStr, ifIgnoreCase, false);
}

/// <summary>
/// 验证字符串是否匹配正则表达式描述的规则
/// </summary>
/// <param name="inputStr">待验证的字符串</param>
/// <param name="patternStr">正则表达式字符串</param>
/// <param name="ifIgnoreCase">匹配时是否不区分大小写</param>
/// <param name="ifValidateWhiteSpace">是否验证空白字符串</param>
/// <returns>是否匹配</returns>
public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase, bool ifValidateWhiteSpace)
{
if (!ifValidateWhiteSpace && string.IsNullOrEmpty(inputStr))
return false;//如果不要求验证空白字符串而此时传入的待验证字符串为空白字符串,则不匹配
Regex regex = null;
if (ifIgnoreCase)
regex = new Regex(patternStr, RegexOptions.IgnoreCase);//指定不区分大小写的匹配
else
regex = new Regex(patternStr);
return regex.IsMatch(inputStr);
}

#endregion

public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
//Console.WriteLine("\""+value+"\"");
//return string.IsNullOrWhiteSpace((value ?? "").ToString())
// ? new ValidationResult(false, "Key is required.")
// : ValidationResult.ValidResult;

string pattern = @"^[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}$";

if (IsMatch((value ?? "").ToString(), pattern))
{
return ValidationResult.ValidResult;

}
else if (string.IsNullOrWhiteSpace((value ?? "").ToString()))
{
return new ValidationResult(false, "Please enter the key for the current edition.");
}
else
{
return new ValidationResult(false, "Invalid format.");
}

}
}
}
20 changes: 20 additions & 0 deletions CMWTAT_DIGITAL/Domain/NotifyPropertyChangedExtension.cs
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace CMWTAT_DIGITAL.Domain
{
public static class NotifyPropertyChangedExtension
{
public static void MutateVerbose<TField>(this INotifyPropertyChanged instance, ref TField field, TField newValue, Action<PropertyChangedEventArgs> raise, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<TField>.Default.Equals(field, newValue)) return;
field = newValue;
raise?.Invoke(new PropertyChangedEventArgs(propertyName));
}
}
}
37 changes: 37 additions & 0 deletions CMWTAT_DIGITAL/Domain/ViewModel.cs
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CMWTAT_DIGITAL.Domain
{
class ViewModel : INotifyPropertyChanged
{
private string _sn;

public ViewModel()
{
LongListToTestComboVirtualization = new List<int>(Enumerable.Range(0, 1000));
}

public string SN
{
get { return _sn; }
set
{
this.MutateVerbose(ref _sn, value, RaisePropertyChanged());
}
}

public IList<int> LongListToTestComboVirtualization { get; }

public event PropertyChangedEventHandler PropertyChanged;

private Action<PropertyChangedEventArgs> RaisePropertyChanged()
{
return args => PropertyChanged?.Invoke(this, args);
}
}
}

0 comments on commit f51df4a

Please sign in to comment.