Skip to content

Commit f51df4a

Browse files
committed
Upgrade to v2.1
Upgrade to v2.1 Support some experimental features Add install key mode (without activate) Add manual enter key mode
1 parent 824f03b commit f51df4a

22 files changed

+2032
-152
lines changed

.vs/CMWTAT_DIGITAL/v15/.suo

32.5 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

CMWTAT_DIGITAL/CMWTAT.ico

-394 KB
Binary file not shown.

CMWTAT_DIGITAL/CMWTAT.png

-153 KB
Binary file not shown.

CMWTAT_DIGITAL/CMWTAT_DIGITAL.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
<DependentUpon>App.xaml</DependentUpon>
8383
<SubType>Code</SubType>
8484
</Compile>
85+
<Compile Include="Domain\IsSN.cs" />
86+
<Compile Include="Domain\NotifyPropertyChangedExtension.cs" />
87+
<Compile Include="Domain\ViewModel.cs" />
8588
<Compile Include="MainWindow.xaml.cs">
8689
<DependentUpon>MainWindow.xaml</DependentUpon>
8790
<SubType>Code</SubType>

CMWTAT_DIGITAL/Domain/IsSN.cs

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Text.RegularExpressions;
4+
using System.Windows.Controls;
5+
6+
namespace CMWTAT_DIGITAL.Domain
7+
{
8+
class IsSN : ValidationRule
9+
{
10+
#region 匹配方法
11+
12+
/// <summary>
13+
/// 验证字符串是否匹配正则表达式描述的规则
14+
/// </summary>
15+
/// <param name="inputStr">待验证的字符串</param>
16+
/// <param name="patternStr">正则表达式字符串</param>
17+
/// <returns>是否匹配</returns>
18+
public static bool IsMatch(string inputStr, string patternStr)
19+
{
20+
return IsMatch(inputStr, patternStr, false, false);
21+
}
22+
23+
/// <summary>
24+
/// 验证字符串是否匹配正则表达式描述的规则
25+
/// </summary>
26+
/// <param name="inputStr">待验证的字符串</param>
27+
/// <param name="patternStr">正则表达式字符串</param>
28+
/// <param name="ifIgnoreCase">匹配时是否不区分大小写</param>
29+
/// <returns>是否匹配</returns>
30+
public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase)
31+
{
32+
return IsMatch(inputStr, patternStr, ifIgnoreCase, false);
33+
}
34+
35+
/// <summary>
36+
/// 验证字符串是否匹配正则表达式描述的规则
37+
/// </summary>
38+
/// <param name="inputStr">待验证的字符串</param>
39+
/// <param name="patternStr">正则表达式字符串</param>
40+
/// <param name="ifIgnoreCase">匹配时是否不区分大小写</param>
41+
/// <param name="ifValidateWhiteSpace">是否验证空白字符串</param>
42+
/// <returns>是否匹配</returns>
43+
public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase, bool ifValidateWhiteSpace)
44+
{
45+
if (!ifValidateWhiteSpace && string.IsNullOrEmpty(inputStr))
46+
return false;//如果不要求验证空白字符串而此时传入的待验证字符串为空白字符串,则不匹配
47+
Regex regex = null;
48+
if (ifIgnoreCase)
49+
regex = new Regex(patternStr, RegexOptions.IgnoreCase);//指定不区分大小写的匹配
50+
else
51+
regex = new Regex(patternStr);
52+
return regex.IsMatch(inputStr);
53+
}
54+
55+
#endregion
56+
57+
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
58+
{
59+
//Console.WriteLine("\""+value+"\"");
60+
//return string.IsNullOrWhiteSpace((value ?? "").ToString())
61+
// ? new ValidationResult(false, "Key is required.")
62+
// : ValidationResult.ValidResult;
63+
64+
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}$";
65+
66+
if (IsMatch((value ?? "").ToString(), pattern))
67+
{
68+
return ValidationResult.ValidResult;
69+
70+
}
71+
else if (string.IsNullOrWhiteSpace((value ?? "").ToString()))
72+
{
73+
return new ValidationResult(false, "Please enter the key for the current edition.");
74+
}
75+
else
76+
{
77+
return new ValidationResult(false, "Invalid format.");
78+
}
79+
80+
}
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace CMWTAT_DIGITAL.Domain
10+
{
11+
public static class NotifyPropertyChangedExtension
12+
{
13+
public static void MutateVerbose<TField>(this INotifyPropertyChanged instance, ref TField field, TField newValue, Action<PropertyChangedEventArgs> raise, [CallerMemberName] string propertyName = null)
14+
{
15+
if (EqualityComparer<TField>.Default.Equals(field, newValue)) return;
16+
field = newValue;
17+
raise?.Invoke(new PropertyChangedEventArgs(propertyName));
18+
}
19+
}
20+
}

CMWTAT_DIGITAL/Domain/ViewModel.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CMWTAT_DIGITAL.Domain
9+
{
10+
class ViewModel : INotifyPropertyChanged
11+
{
12+
private string _sn;
13+
14+
public ViewModel()
15+
{
16+
LongListToTestComboVirtualization = new List<int>(Enumerable.Range(0, 1000));
17+
}
18+
19+
public string SN
20+
{
21+
get { return _sn; }
22+
set
23+
{
24+
this.MutateVerbose(ref _sn, value, RaisePropertyChanged());
25+
}
26+
}
27+
28+
public IList<int> LongListToTestComboVirtualization { get; }
29+
30+
public event PropertyChangedEventHandler PropertyChanged;
31+
32+
private Action<PropertyChangedEventArgs> RaisePropertyChanged()
33+
{
34+
return args => PropertyChanged?.Invoke(this, args);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)