You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
4.1 KiB
123 lines
4.1 KiB
using CommunityToolkit.Mvvm.Messaging;
|
|
using SunlightAggregationTerminal.Class;
|
|
using SunlightAggregationTerminal.Models;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
|
|
namespace SunlightAggregationTerminal.View;
|
|
|
|
public class ItemOption
|
|
{
|
|
public required string? SERVER { get; set; }
|
|
public required string? SERVERIP { get; set; }
|
|
}
|
|
|
|
public partial class LogPage : ContentPage
|
|
{
|
|
public ObservableCollection<ItemOption>? Items { get; }
|
|
|
|
public LogPage()
|
|
{
|
|
InitializeComponent();
|
|
|
|
WeakReferenceMessenger.Default.Register<string>(this, (r, scannedValue) =>
|
|
{
|
|
SERVERIP.Text = scannedValue;
|
|
});
|
|
|
|
//可用服务器列表
|
|
AppModels.sqliteHelper.Open();
|
|
var userdata = AppModels.sqliteHelper.ExecuteDataSet("select * from Server", null);
|
|
AppModels.sqliteHelper.Close();
|
|
|
|
if (userdata != null)
|
|
{
|
|
foreach (DataRow dataRow in userdata.Tables[0].Rows)
|
|
{
|
|
if (dataRow != null)
|
|
{
|
|
Items?.Add(new ItemOption {
|
|
SERVER = dataRow.Field<string>("UserName") ?? "",
|
|
SERVERIP = dataRow.Field<string>("UserName") ?? ""
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// 可选:设置默认选中项
|
|
if (Items != null)
|
|
{
|
|
SERVER.ItemsSource = Items;
|
|
SERVER.SelectedItem = Items[0];
|
|
}
|
|
}
|
|
|
|
private void SERVER_SelectedIndexChanged(object sender, EventArgs e)//服务器列表选择
|
|
{
|
|
var dat = SERVER.SelectedItem as ItemOption;
|
|
if (dat != null)
|
|
{
|
|
SERVERIP.Text = dat.SERVERIP?.ToString();
|
|
}
|
|
}
|
|
|
|
private void OnScanButtonClicked(object sender, EventArgs e)//扫码按钮
|
|
{
|
|
// 跳转到扫码页面
|
|
var scanPage = new ScanPage(3);
|
|
Navigation.PushAsync(scanPage);
|
|
}
|
|
|
|
private async void Log_Clicked(object sender, EventArgs e)//登录
|
|
{
|
|
TcpServer.Configuration(SERVERIP.Text, UsernameEntry.Text, PasswordEntry.Text,
|
|
Models.AppModels.GetAppUniqueId());
|
|
|
|
TcpServer.TcpTransmit("Log");
|
|
|
|
LoadingIndicator.IsVisible = true;
|
|
|
|
if (await AppModels.LogIn())
|
|
{
|
|
var temp_name = AppModels.Select("SELECT * FROM Users WHERE User='" + UsernameEntry.Text + "' LIMIT 1;")!.Tables[0];
|
|
if (temp_name != null)
|
|
{
|
|
//存在更新账号状态
|
|
string sql = @"UPDATE Users SET ServerID = '" + SERVERIP.Text
|
|
+ "', UserPassword = '" + PasswordEntry.Text +
|
|
"', LogNo = true WHERE User='" + UsernameEntry.Text + "';";
|
|
AppModels.Updata(sql);
|
|
}
|
|
else
|
|
{
|
|
//插入账号
|
|
string sql = @"INSERT INTO Users (User,UserId ,UserName ,UserPassword ,
|
|
Enterprise ,Department ,ServerID ,Groups ,
|
|
ProxyID ,LogNo ,LocalAreaNetworkMode ,DarkMode ,
|
|
MessageNotificationMode ,GUID
|
|
)VALUES('" + UsernameEntry.Text + "','SUNLIGHT','SUNLIGHT','" + PasswordEntry.Text +
|
|
"','SUNLIGHT','ENGINEER','" + SERVERIP.Text + "','ENGINEER'," +
|
|
" '',0,0,0,0,'" + Models.AppModels.GetAppUniqueId() + "');";
|
|
AppModels.INSERT(sql);
|
|
}
|
|
|
|
var temp_server = AppModels.Select("SELECT * FROM Server WHERE ServerID='" + SERVERIP.Text + "' LIMIT 1;")!.Tables[0];
|
|
if (temp_server == null)
|
|
{
|
|
string sql = @"INSERT INTO Server ( Server, ServerID)VALUES('" + App.GlobalData.Enterprise + "','" +
|
|
App.GlobalData.ServerID + "');";
|
|
AppModels.INSERT(sql);
|
|
}
|
|
|
|
await Navigation.PopModalAsync();
|
|
}
|
|
else
|
|
{
|
|
await DisplayAlertAsync("未登录", "服务器不存在或拒绝访问", "是");
|
|
}
|
|
LoadingIndicator.IsVisible = false;
|
|
}
|
|
|
|
|
|
}
|