feat: 登录页、注册表工具类

master
Tongg 7 months ago
parent 8f3af6c231
commit c71aa5fea8
  1. 10
      Language/zh_CN.xaml
  2. 146
      LoginWindow.xaml
  3. 31
      LoginWindow.xaml.cs
  4. 6
      MainWindow.xaml.cs
  5. 81
      Model/Helper/RegistryHelper.cs
  6. BIN
      Resource/Images/UIResource/08-2.png
  7. BIN
      Resource/Images/UIResource/08-3.png
  8. BIN
      Resource/Images/UIResource/08-4.png
  9. BIN
      Resource/Images/UIResource/08-5.jpg
  10. 8
      SparkClient.csproj

@ -162,4 +162,14 @@
<sys:String x:Key="ViewportSaveSucceed">保存成功</sys:String>
<sys:String x:Key="ViewportSaveFail">保存失败</sys:String>
<sys:String x:Key="ViewportSelectPath">选择路径</sys:String>
<!-- 登录页 -->
<sys:String x:Key="LoginWindowTitle">星辉钻石检测系统</sys:String>
<sys:String x:Key="LoginWindowAccount">账号</sys:String>
<sys:String x:Key="LoginWindowPassword">密码</sys:String>
<sys:String x:Key="LoginWindowRemember">记住密码</sys:String>
<sys:String x:Key="LoginWindowLogin">登 录</sys:String>
<sys:String x:Key="LoginWindowExit">退 出 系 统</sys:String>
<sys:String x:Key="LoginWindowForgot">如果忘记密码,请联系我们</sys:String>
</ResourceDictionary>

@ -0,0 +1,146 @@
<Window x:Class="SparkClient.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SparkClient"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
ResizeMode="NoResize"
Title="LoginWindow" Height="450" Width="450">
<Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
<Border CornerRadius="20"
BorderThickness="1"
BorderBrush="LightGray"
Background="White">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="80"/>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 标题 -->
<Grid Grid.Row="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="/Resource/Images/icon_200.png" Width="70"/>
<TextBlock Grid.Column="1" Text="{StaticResource LoginWindowTitle}"
FontSize="32" FontWeight="Bold" VerticalAlignment="Center">
<TextBlock.Foreground>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#58b9e3" Offset="0"/>
<GradientStop Color="#349ad0" Offset="1"/>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
</Grid>
</Grid>
<!-- 账号输入 -->
<Grid Grid.Row="3" >
<Border Height="40" CornerRadius="20" BorderBrush="#ebeef5"
BorderThickness="1" Background="#ebeef5"
Margin="40 10" Padding="20 0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Width="25" Height="25" Source="Resource/Images/UIResource/08-2.png" />
<hc:TextBox Grid.Column="1" Grid.ColumnSpan="2" BorderThickness="0" FontSize="18" HorizontalAlignment="Stretch"
Background="Transparent" Padding="5 0" hc:InfoElement.ShowClearButton="True"
VerticalAlignment="Stretch" TextAlignment="Left" x:Name="AccountTextBox"
hc:InfoElement.Placeholder="{StaticResource LoginWindowAccount}"
/>
<!-- <Image Grid.Column="2" Width="25" Height="25" Source="Resource/Images/UIResource/08-4.png" MouseLeftButtonDown="UIElement_OnMouseLeftButtonDown" /> -->
</Grid>
</Border>
</Grid>
<!-- 密码输入 -->
<Grid Grid.Row="4" >
<Border Height="40" CornerRadius="20" BorderBrush="#ebeef5"
BorderThickness="1" Background="#ebeef5"
Margin="40 10" Padding="20 0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Width="25" Height="25" Source="Resource/Images/UIResource/08-3.png" />
<hc:PasswordBox Grid.Column="1" Grid.ColumnSpan="2" ShowEyeButton="True" BorderThickness="0"
FontSize="18" HorizontalAlignment="Stretch" hc:InfoElement.Necessary="True" Background="Transparent"
hc:InfoElement.Placeholder="{StaticResource LoginWindowPassword}"/>
</Grid>
</Border>
</Grid>
<!-- 记住密码 -->
<CheckBox Grid.Row="5" Content="{StaticResource LoginWindowRemember}"
Background="#8ea4c9" IsChecked="True" Foreground="#8c8c8c" FontSize="16"
Margin="45 5"/>
<!-- 登录按钮 -->
<Button x:Name="ConfirmButton" Grid.Row="6" Padding="0" Margin="0 10 0 10" Height="50"
Width="360 "
BorderThickness="0" Background="Transparent" FocusVisualStyle="{x:Null}">
<Border
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0 0 0 0"
Padding="10, 10"
Width="360"
BorderThickness="0"
CornerRadius="20">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#61bde2" Offset="0"/>
<GradientStop Color="#53abd9" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<TextBlock FontSize="18" Text="{StaticResource LoginWindowLogin}" TextAlignment="Center" Foreground="#ffffff"></TextBlock>
</Border>
</Button>
<Button x:Name="CloseButton" Grid.Row="7" Padding="0" Margin="0 0 0 20" Height="50"
Width="360 " Click="CloseButton_OnClick"
BorderThickness="0" Background="Transparent" FocusVisualStyle="{x:Null}">
<Border
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0 0 0 0"
Padding="10, 10"
Width="360"
BorderThickness="0"
CornerRadius="20">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#e3687d" Offset="0"/>
<GradientStop Color="#d95464" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<TextBlock FontSize="18" Text="{StaticResource LoginWindowExit}" TextAlignment="Center" Foreground="#ffffff"></TextBlock>
</Border>
</Button>
<!-- 联系我们 -->
<TextBlock Grid.Row="8" Text="{StaticResource LoginWindowForgot}" TextAlignment="Center"
Margin="20,0" FontSize="14" Foreground="#8e8e8e" Padding="0 10 0 0" VerticalAlignment="Bottom"/>
</Grid>
</Border>
</Grid>
</Window>

@ -0,0 +1,31 @@
using System.Windows;
using System.Windows.Input;
namespace SparkClient;
public partial class LoginWindow : Window
{
public LoginWindow()
{
InitializeComponent();
WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
this.DragMove();
}
}
private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
AccountTextBox.Text = string.Empty;
}
private void CloseButton_OnClick(object sender, RoutedEventArgs e)
{
this.Close();
Environment.Exit(0);
}
}

@ -13,6 +13,7 @@ using SparkClient.Model.Helper;
using SparkClient.ViewModel;
using SparkClient.ViewModel.BaseWindow;
using SparkClient.Views.BaseWindow;
using MessageBox = SparkClient.Views.Dialog.MessageBox;
using Window = System.Windows.Window;
namespace SparkClient;
@ -138,9 +139,10 @@ public partial class MainWindow
var message = MultilingualHelper.getString("ExitAsk");
var title = MultilingualHelper.getString("ExitAskTitle");
MessageBoxResult result = HandyControl.Controls.MessageBox.Show( message, title, MessageBoxButton.YesNo, MessageBoxImage.Question );
// MessageBoxResult result = HandyControl.Controls.MessageBox.Show( message, title, MessageBoxButton.YesNo, MessageBoxImage.Question );
MessageBoxResult result = new MessageBox().ShowAsk(message);
if (result == MessageBoxResult.Yes)
if (result == MessageBoxResult.OK)
{
DataBaseHelper.CloseConnection();
// this.Close();

@ -0,0 +1,81 @@
using Microsoft.Win32;
namespace SparkClient.Model.Helper;
public static class RegistryHelper
{
private const string BaseRegistryKey = @"SOFTWARE\Dayu\Spark";
/// <summary>
/// 向注册表写入字符串类型值
/// </summary>
/// <param name="keyName">存储的键名</param>
/// <param name="value">要写入的字符串值</param>
public static void WriteString(string keyName, string value)
{
using (var key = Registry.CurrentUser.CreateSubKey(BaseRegistryKey))
{
key?.SetValue(keyName, value, RegistryValueKind.String);
}
}
/// <summary>
/// 从注册表读取字符串类型值
/// </summary>
/// <param name="keyName">存储的键名</param>
/// <returns>读取到的字符串值,若不存在则返回 null</returns>
public static string ReadString(string keyName)
{
using (var key = Registry.CurrentUser.OpenSubKey(BaseRegistryKey))
{
if (key == null) return null;
return key.GetValue(keyName) as string;
}
}
/// <summary>
/// 向注册表写入布尔类型值(以 0/1 方式)
/// </summary>
public static void WriteBool(string keyName, bool value)
{
using (var key = Registry.CurrentUser.CreateSubKey(BaseRegistryKey))
{
key?.SetValue(keyName, value ? 1 : 0, RegistryValueKind.DWord);
}
}
/// <summary>
/// 从注册表读取布尔类型值(从 0/1 转换)
/// </summary>
public static bool ReadBool(string keyName, bool defaultValue = false)
{
using (var key = Registry.CurrentUser.OpenSubKey(BaseRegistryKey))
{
if (key == null) return defaultValue;
object regValue = key.GetValue(keyName);
if (regValue == null) return defaultValue;
int intVal;
if (int.TryParse(regValue.ToString(), out intVal))
{
return intVal != 0; // 1->true, 0->false
}
return defaultValue;
}
}
/// <summary>
/// 删除某个键值
/// </summary>
/// <param name="keyName">要删除的键名</param>
public static void DeleteKey(string keyName)
{
using (var key = Registry.CurrentUser.OpenSubKey(BaseRegistryKey, writable: true))
{
if (key != null)
{
key.DeleteValue(keyName, throwOnMissingValue: false);
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

@ -154,6 +154,14 @@
<Resource Include="Resource\Images\UserControl\03-8-2.png" />
<None Remove="Resource\Images\UserControl\03-14-1.png" />
<Resource Include="Resource\Images\UserControl\03-14-1.png" />
<None Remove="Resource\Images\UIResource\08-2.png" />
<Resource Include="Resource\Images\UIResource\08-2.png" />
<None Remove="Resource\Images\UIResource\08-3.png" />
<Resource Include="Resource\Images\UIResource\08-3.png" />
<None Remove="Resource\Images\UIResource\08-4.png" />
<Resource Include="Resource\Images\UIResource\08-4.png" />
<None Remove="Resource\Images\UIResource\08-5.jpg" />
<Resource Include="Resource\Images\UIResource\08-5.jpg" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save