123 lines
3.2 KiB
C#
123 lines
3.2 KiB
C#
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();
|
|
|
|
}));
|
|
}
|
|
}
|
|
|
|
}
|
|
} |