加入登录和修改密码

This commit is contained in:
xu 2020-02-26 02:02:12 +08:00
parent 2f26de2196
commit 3362a1b47c
6 changed files with 453 additions and 0 deletions

View File

@ -0,0 +1,150 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Practices.ServiceLocation;
using Plane.FormationCreator.Formation;
using Plane.FormationCreator.Util;
using Plane.FormationCreator.Views;
using Plane.Util;
using Plane.Windows.Messages;
using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interactivity;
namespace Plane.FormationCreator.ViewModels
{
/// <summary>
/// This class contains properties that a View can data bind to.
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class ChangePasswordViewModel : ViewModelBase
{
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private MainViewModel _MainViewModel=ServiceLocator.Current.GetInstance<MainViewModel>();
/// <summary>
/// Initializes a new instance of the LoginViewModel class.
/// </summary>
public ChangePasswordViewModel()
{
NewPassword = "";
OldPassword = "";
NewPassword1 = "";
Username = "";
}
private string _Username="";
public string Username
{
get { return _Username; }
set
{
Set(nameof(Username), ref _Username, value);
}
}
private string _OldPassword = "";
public string OldPassword
{
get { return _OldPassword; }
set
{
Set(nameof(OldPassword), ref _OldPassword, value);
}
}
private string _NewPassword = "";
public string NewPassword
{
get { return _NewPassword; }
set
{
Set(nameof(NewPassword), ref _NewPassword, value);
}
}
private string _NewPassword1 = "";
public string NewPassword1
{
get { return _NewPassword1; }
set
{
Set(nameof(NewPassword1), ref _NewPassword1, value);
}
}
private ICommand _ExitCommand;
public ICommand ExitCommand
{
get
{
return _ExitCommand ?? (_ExitCommand = new RelayCommand<ChangePasswordView>(wd =>
{
if (wd != null)
{
NewPassword = "";
OldPassword = "";
NewPassword1 = "";
Username = "";
wd.Close();
}
}));
}
}
private ICommand _ChangePasswordCommand;
public ICommand ChangePasswordCommand
{
get
{
return _ChangePasswordCommand ?? (_ChangePasswordCommand = new RelayCommand<ChangePasswordView>(wd =>
{
if (Username.Trim() == "")
{
Alert.Show("请输入账号!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (OldPassword=="")
{
Alert.Show("请输入原密码!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (NewPassword.Length<6)
{
Alert.Show("新密码长度不能低于6位", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (NewPassword != NewPassword1)
{
Alert.Show("两次新密码不相同!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
_copterManager.NetChangePassword(Username.Trim(), OldPassword, NewPassword);
//wd.Close();
}));
}
}
}
}

View File

@ -0,0 +1,123 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Practices.ServiceLocation;
using Plane.FormationCreator.Formation;
using Plane.FormationCreator.Util;
using Plane.FormationCreator.Views;
using Plane.Util;
using Plane.Windows.Messages;
using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interactivity;
namespace Plane.FormationCreator.ViewModels
{
/// <summary>
/// This class contains properties that a View can data bind to.
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class LoginViewModel : ViewModelBase
{
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private MainViewModel _MainViewModel=ServiceLocator.Current.GetInstance<MainViewModel>();
/// <summary>
/// Initializes a new instance of the LoginViewModel class.
/// </summary>
public LoginViewModel()
{
Username = VersionControl.Username;
SavePassword = VersionControl.IssavePassword;
if (SavePassword)
Password = VersionControl.Password;
}
private string _Username="";
public string Username
{
get { return _Username; }
set
{
Set(nameof(Username), ref _Username, value);
}
}
private string _Password = "";
public string Password
{
get { return _Password; }
set
{
Set(nameof(Password), ref _Password, value);
}
}
private bool _SavePassword = false;
public bool SavePassword
{
get { return _SavePassword; }
set
{
Set(nameof(SavePassword), ref _SavePassword, value);
}
}
private ICommand _ExitCommand;
public ICommand ExitCommand
{
get
{
return _ExitCommand ?? (_ExitCommand = new RelayCommand<LoginView>(wd =>
{
if (wd != null)
{
wd.Close();
}
}));
}
}
private ICommand _LoginCommand;
public ICommand LoginCommand
{
get
{
return _LoginCommand ?? (_LoginCommand = new RelayCommand<LoginView>(wd =>
{
if (Username.Trim() == "")
{
Alert.Show("请输入账号!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (Password == "")
{
Alert.Show("请输入密码!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
_copterManager.NetLogoin(Username.Trim(), Password, SavePassword);
if (!SavePassword) Password = "";
wd.Close();
}));
}
}
}
}

View File

@ -0,0 +1,77 @@
<Window x:Class="Plane.FormationCreator.Views.ChangePasswordView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ignore="http://www.galasoft.ch/ignore"
xmlns:Helper="clr-namespace:Plane.Util"
mc:Ignorable="d ignore" Height="316.504" Width="490.433" Title="更改登录密码" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Content="账号:" Margin="10" FontWeight="Bold" FontSize="14" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" />
<TextBox
Margin="10"
Width="120" VerticalContentAlignment="Center"
Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left"
Grid.Row="0" Grid.Column="1"/>
<Label Content="原密码:" Margin="10" FontWeight="Bold" FontSize="14" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" />
<PasswordBox
x:Name="passwordBox"
Margin="10"
Width="120"
HorizontalAlignment="Left" VerticalContentAlignment="Center" Grid.Row="1" Grid.Column="1"
PasswordChar="*"
MaxLength="20"
Helper:PasswordBoxHelper.Attach="True"
Helper:PasswordBoxHelper.Password="{Binding Path=OldPassword ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<Label Content="新密码:" Margin="10" FontWeight="Bold" FontSize="14" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" />
<PasswordBox
x:Name="newpasswordBox"
Margin="10"
Width="120"
HorizontalAlignment="Left" VerticalContentAlignment="Center" Grid.Row="2" Grid.Column="1"
PasswordChar="*"
MaxLength="20"
Helper:PasswordBoxHelper.Attach="True"
Helper:PasswordBoxHelper.Password="{Binding Path=NewPassword ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<Label Content="再次输入新密码:" Margin="10" FontWeight="Bold" FontSize="14" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" />
<PasswordBox
x:Name="newpasswordBox1"
Margin="10"
Width="120"
HorizontalAlignment="Left" VerticalContentAlignment="Center" Grid.Row="3" Grid.Column="1"
PasswordChar="*"
MaxLength="20"
Helper:PasswordBoxHelper.Attach="True"
Helper:PasswordBoxHelper.Password="{Binding Path=NewPassword1 ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<Button Content="取消" Grid.Row="4" Grid.Column="0" Margin="10,5,10,5" Height="40" Width="80" IsCancel="True"
Command="{Binding ExitCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" />
<Button Content="更改" Grid.Row="4" Grid.Column="1" Margin="50,5,10,5" Height="40" Width="80" IsDefault="True"
Command="{Binding ChangePasswordCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" />
</Grid>
</Window>

View File

@ -0,0 +1,24 @@
using Microsoft.Practices.ServiceLocation;
using Plane.FormationCreator.ViewModels;
using System.Windows;
using System.Windows.Controls;
namespace Plane.FormationCreator.Views
{
/// <summary>
/// Description for ChangePasswordView.
/// </summary>
public partial class ChangePasswordView : Window
{
/// <summary>
/// Initializes a new instance of the ChangePasswordView class.
/// </summary>
public ChangePasswordView()
{
InitializeComponent();
ChangePasswordViewModel loginViewModel = ServiceLocator.Current.GetInstance<ChangePasswordViewModel>();
this.DataContext = loginViewModel;
}
}
}

View File

@ -0,0 +1,55 @@
<Window x:Class="Plane.FormationCreator.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ignore="http://www.galasoft.ch/ignore"
xmlns:Helper="clr-namespace:Plane.Util"
mc:Ignorable="d ignore" Height="253.421" Width="463.894" Title="登录系统" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Content="账号:" Margin="10" FontWeight="Bold" FontSize="14" Grid.Row="0" Grid.Column="0" />
<TextBox
Margin="10"
Width="120" VerticalContentAlignment="Center"
Text="{Binding Username, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left"
Grid.Row="0" Grid.Column="1"/>
<Label Content="密码:" Margin="10" FontWeight="Bold" FontSize="14" Grid.Row="1" Grid.Column="0" />
<PasswordBox
x:Name="passwordBox"
Margin="10"
Width="120"
HorizontalAlignment="Left" VerticalContentAlignment="Center" Grid.Row="1" Grid.Column="1"
PasswordChar="*"
MaxLength="20"
Helper:PasswordBoxHelper.Attach="True"
Helper:PasswordBoxHelper.Password="{Binding Path=Password ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<Button Content="取消" Grid.Row="2" Grid.Column="0" Margin="10,5,10,5" Height="40" Width="80" IsCancel="True"
Command="{Binding ExitCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" />
<Button Content="登录" Grid.Row="2" Grid.Column="1" Margin="50,5,10,5" Height="40" Width="80" IsDefault="True"
Command="{Binding LoginCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" />
<CheckBox x:Name="checkBox" Content="保存密码" Grid.Column="1" HorizontalAlignment="Right" Margin="0,18.033,-85.353,12.168" Grid.Row="1" Width="75.353"
IsChecked="{Binding SavePassword}"/>
</Grid>
</Window>

View File

@ -0,0 +1,24 @@
using Microsoft.Practices.ServiceLocation;
using Plane.FormationCreator.ViewModels;
using System.Windows;
using System.Windows.Controls;
namespace Plane.FormationCreator.Views
{
/// <summary>
/// Description for LoginView.
/// </summary>
public partial class LoginView : Window
{
/// <summary>
/// Initializes a new instance of the LoginView class.
/// </summary>
public LoginView()
{
InitializeComponent();
LoginViewModel loginViewModel = ServiceLocator.Current.GetInstance<LoginViewModel>();
this.DataContext = loginViewModel;
}
}
}