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.
143 lines
5.2 KiB
143 lines
5.2 KiB
using CommunityToolkit.Mvvm.Messaging;
|
|
using SunlightAggregationTerminal.Class;
|
|
using SunlightAggregationTerminal.Models;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
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; set; }
|
|
|
|
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();
|
|
|
|
Items = new ObservableCollection<ItemOption>();
|
|
|
|
if (userdata != null)
|
|
{
|
|
foreach (DataRow dataRow in userdata.Tables[0].Rows)
|
|
{
|
|
if (dataRow != null)
|
|
{
|
|
string _SERVER = dataRow.Field<string>("Server")!;
|
|
string _SERVERIP = dataRow.Field<string>("ServerID")! + "," + dataRow.Field<string>("ServerHTTP")!;
|
|
|
|
var dat = new ItemOption
|
|
{
|
|
SERVER = _SERVER,
|
|
SERVERIP = _SERVERIP
|
|
};
|
|
Items.Add(dat);
|
|
}
|
|
}
|
|
}
|
|
// 设置默认选中项
|
|
if (Items.Count>0)
|
|
{
|
|
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.PushModalAsync(scanPage);
|
|
}
|
|
|
|
private async void Log_Clicked(object sender, EventArgs e)//登录
|
|
{
|
|
LoadingIndicator.IsVisible = true;
|
|
|
|
string[] result = SERVERIP.Text.Split(',', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
|
|
|
App.GlobalData.ServerID = result[0]?? "";
|
|
//判断是否有http连接信息
|
|
if (result.Length ==2)
|
|
{
|
|
App.GlobalData.ServerHTTP = result[1] ?? "";
|
|
App.GlobalData.LocalAreaNetworkMode = false;
|
|
}
|
|
else
|
|
{
|
|
App.GlobalData.LocalAreaNetworkMode = true;
|
|
}
|
|
App.GlobalData.User = UsernameEntry.Text;
|
|
App.GlobalData.UserPassword = PasswordEntry.Text;
|
|
|
|
if (await AppModels.LogIn())
|
|
{
|
|
int temp_name = AppModels.Select("SELECT * FROM Users WHERE User='" + UsernameEntry.Text + "' LIMIT 1;")!.Tables[0].Rows.Count;
|
|
if (temp_name >0)
|
|
{
|
|
//存在更新账号状态
|
|
string sql = "UPDATE Users SET ServerID = '" + App.GlobalData.ServerID
|
|
+ "', ServerHTTP = '" + App.GlobalData.ServerHTTP
|
|
+ "', UserPassword = '" + PasswordEntry.Text
|
|
+"', LogNo = 1 WHERE User='" + UsernameEntry.Text + "';";
|
|
AppModels.Updata(sql);
|
|
}
|
|
else
|
|
{
|
|
//插入账号
|
|
string sql = @"INSERT INTO Users (User,UserId ,UserName ,UserPassword ,
|
|
Enterprise ,Department ,ServerID ,ServerHTTP ,Groups ,
|
|
ProxyID ,LogNo ,LocalAreaNetworkMode ,DarkMode ,
|
|
MessageNotificationMode ,GUID
|
|
)VALUES('" + UsernameEntry.Text + "','"+ App.GlobalData.UserId +
|
|
"','" + App.GlobalData.UserName + "','" + PasswordEntry.Text +
|
|
"','"+ App.GlobalData.Enterprise + "','"+ App.GlobalData.Department +
|
|
"','" + App.GlobalData.ServerID + "','" +App.GlobalData.ServerHTTP+
|
|
"','"+ App.GlobalData.Groups + "'," +
|
|
" '',1,0,0,0,'" + Models.AppModels.GetAppUniqueId() + "');";
|
|
AppModels.INSERT(sql);
|
|
}
|
|
|
|
int temp_server = AppModels.Select("SELECT * FROM Server WHERE Server='"+ App.GlobalData.Enterprise + "' LIMIT 1;")!.Tables[0].Rows.Count;
|
|
if (temp_server == 0)
|
|
{
|
|
string sql = @"INSERT INTO Server ( Server, ServerID,ServerHTTP)VALUES('" + App.GlobalData.Enterprise + "','" +
|
|
App.GlobalData.ServerID+"','"+ App.GlobalData.ServerHTTP + "');";
|
|
AppModels.INSERT(sql);
|
|
}
|
|
|
|
await Navigation.PopModalAsync();
|
|
}
|
|
else
|
|
{
|
|
await DisplayAlertAsync("未登录", "服务器不存在或拒绝访问", "是");
|
|
}
|
|
LoadingIndicator.IsVisible = false;
|
|
}
|
|
}
|