82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
using System.Net.Sockets;
|
|
using System.IO;
|
|
using log4net;
|
|
using log4net.Config;
|
|
|
|
|
|
namespace chatclient
|
|
{
|
|
/// <summary>
|
|
/// LoginWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class LoginWindow : Window,INotifyPropertyChanged
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(LoginWindow));
|
|
public LoginWindow()
|
|
{
|
|
InitializeComponent();
|
|
this.DataContext = this;
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
private void Update (string UpdateName)
|
|
{
|
|
PropertyChangedEventHandler? handler = PropertyChanged;
|
|
if (handler != null)
|
|
{
|
|
handler(this, new PropertyChangedEventArgs(UpdateName));
|
|
}
|
|
}
|
|
private string? _LoginMsg;
|
|
public string UserName { get; set; } = "";
|
|
public string UserPassword { get; set; } = "";
|
|
public string? LoginMsg
|
|
{
|
|
get { return _LoginMsg; }
|
|
set
|
|
{
|
|
_LoginMsg = value;
|
|
Update("LoginMsg");
|
|
}
|
|
}
|
|
private void Login_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (UserName == "")
|
|
{
|
|
LoginMsg = "用户名不能为空";
|
|
}
|
|
else if (UserPassword == "")
|
|
{
|
|
LoginMsg = "密码不能为空";
|
|
}
|
|
else
|
|
{
|
|
var LoginData = new
|
|
{
|
|
type = "login",
|
|
username = UserName,
|
|
password = UserPassword
|
|
};
|
|
string LoginLsonData = JsonSerializer.Serialize(LoginData);
|
|
byte[] dataBytes = Encoding.UTF8.GetBytes(LoginLsonData);
|
|
MainWindow.Client.Send(dataBytes);
|
|
}
|
|
}
|
|
}
|
|
}
|