Compare commits

...
2 Commits
Author SHA1 Message Date
sc c1a497205d 添加输入限制 2024-03-29 22:18:11 +08:00
sc 05f0384875 添加项目文件。 2024-03-29 21:08:29 +08:00
2 changed files with 113 additions and 2 deletions

No files matched your search

+27 -2
View File
@@ -5,8 +5,33 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SUNLIGHT_CDKEY"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
Title="MainWindow" Height="400" Width="600">
<Grid>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="20,10,0,0" TextWrapping="Wrap" Text="SN:" VerticalAlignment="Top" Width="170" FontSize="24"/>
<TextBox x:Name="sn_id" HorizontalAlignment="Left" Height="40" Margin="170,10,0,0" VerticalAlignment="Top" Width="340" FontSize="24"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="20,55,0,0" TextWrapping="Wrap" Text="DURATION:" VerticalAlignment="Top" Width="170" FontSize="24"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="400,55,0,0" TextWrapping="Wrap" Text="MONTHS" VerticalAlignment="Top" Width="170" FontSize="24"/>
<ComboBox x:Name="DURATION" HorizontalAlignment="Left" Height="40" Margin="170,55,0,0" VerticalAlignment="Top" Width="220" DropDownClosed="DURATION_DropDownClosed" FontSize="24">
<ComboBoxItem Content=""></ComboBoxItem>
<ComboBoxItem Content="1"></ComboBoxItem>
<ComboBoxItem Content="2"></ComboBoxItem>
<ComboBoxItem Content="3"></ComboBoxItem>
<ComboBoxItem Content="6"></ComboBoxItem>
<ComboBoxItem Content="12"></ComboBoxItem>
<ComboBoxItem Content="FOREVER"></ComboBoxItem>
</ComboBox>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="20,100,0,0" TextWrapping="Wrap" Text="TIME:" VerticalAlignment="Top" Width="88" FontSize="24"/>
<TextBox x:Name="T_Y" Text="0" HorizontalAlignment="Left" Height="40" Margin="170,100,0,0" VerticalAlignment="Top" Width="220" FontSize="24" InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Tb_KeyFloating_Y" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="400,100,0,0" TextWrapping="Wrap" Text="YEAR" VerticalAlignment="Top" Width="170" FontSize="24"/>
<TextBox x:Name="T_M" Text="0" HorizontalAlignment="Left" Height="40" Margin="170,145,0,0" VerticalAlignment="Top" Width="220" FontSize="24" InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Tb_KeyFloating_M" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="400,145,0,0" TextWrapping="Wrap" Text="MONTHS" VerticalAlignment="Top" Width="170" FontSize="24"/>
<TextBox x:Name="T_D" Text="0" HorizontalAlignment="Left" Height="40" Margin="170,190,0,0" VerticalAlignment="Top" Width="220" FontSize="24" InputMethod.IsInputMethodEnabled="False" PreviewTextInput="Tb_KeyFloating_D" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="400,190,0,0" TextWrapping="Wrap" Text="DAY" VerticalAlignment="Top" Width="170" FontSize="24"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="20,235,0,0" TextWrapping="Wrap" Text="CDKEY:" VerticalAlignment="Top" Width="88" FontSize="24"/>
<TextBox x:Name="cdk" HorizontalAlignment="Left" Height="40" Margin="170,235,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="342" FontSize="24"/>
<Button Content="OK" HorizontalAlignment="Left" Height="40" Margin="170,280,0,0" VerticalAlignment="Top" Width="85" Background="#FFE6E6E6" Click="Button_Click"/>
</Grid>
</Window>
+86
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@@ -19,9 +20,94 @@ namespace SUNLIGHT_CDKEY
/// </summary>
public partial class MainWindow : Window
{
int d, y, m;
public MainWindow()
{
InitializeComponent();
T_Y.Text = DateTime.Now.ToString("yyyy");
T_M.Text = DateTime.Now.ToString("MM");
T_D.Text = DateTime.Now.ToString("dd");
}
private void Tb_KeyFloating_D(object sender, TextCompositionEventArgs e)//输入事件
{
d = int.Parse(T_D.Text);
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
if(d>30)T_D.Text = "30";
}
private void Tb_KeyFloating_Y(object sender, TextCompositionEventArgs e)//输入事件
{
y = int.Parse(T_Y.Text);
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
if (y > 2099) T_Y.Text = "2099";
}
private void Tb_KeyFloating_M(object sender, TextCompositionEventArgs e)//输入事件
{
m = int.Parse(T_M.Text);
//Regex re = new Regex("[^0-9.-]+");
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
e.Handled = !re.IsMatch(e.Text);
if (m > 12) T_M.Text = "12";
}
private void DURATION_DropDownClosed(object sender, EventArgs e)
{
T_Y.Text = DateTime.Now.ToString("yyyy");
T_M.Text = DateTime.Now.ToString("MM");
T_D.Text = DateTime.Now.ToString("dd");
d = int.Parse(T_D.Text);
y = int.Parse(T_Y.Text);
m = int.Parse(T_M.Text);
if (DURATION.Text == "1")
{
m += 1;
}
else if (DURATION.Text == "2")
{
m += 2;
}
else if (DURATION.Text == "3")
{
m += 3;
}
else if (DURATION.Text == "6")
{
m += 6;
}
else if (DURATION.Text == "12")
{
y += 1;
}
else if (DURATION.Text == "FOREVER")
{
y = 2099;
}
if (m > 12)
{
m = m-12;
y += 1;
}
T_Y.Text=y.ToString();
T_M.Text=m.ToString();
T_D.Text=d.ToString();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string t;
t = sn_id.Text.Substring(0, 6);
}
}
}