登录功能,自动登录实现
This commit is contained in:
commit
bb8dfca7a1
5 files changed
+49
-51
No files matched your search
+21
-27
@@ -9,13 +9,13 @@ namespace SunlightAggregationTerminal.View;
|
||||
|
||||
public class ItemOption
|
||||
{
|
||||
public required string? SERVER { get; set; }
|
||||
public required string? SERVERIP { get; set; }
|
||||
public required string SERVER { get; set; }
|
||||
public required string SERVERIP { get; set; }
|
||||
}
|
||||
|
||||
public partial class LogPage : ContentPage
|
||||
{
|
||||
public ObservableCollection<ItemOption>? Items { get; }
|
||||
public ObservableCollection<ItemOption>? Items { get; set; }
|
||||
|
||||
public LogPage()
|
||||
{
|
||||
@@ -31,22 +31,25 @@ public partial class LogPage : ContentPage
|
||||
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)
|
||||
{
|
||||
Items?.Add(new ItemOption {
|
||||
SERVER = dataRow.Field<string>("UserName") ?? "",
|
||||
SERVERIP = dataRow.Field<string>("UserName") ?? ""
|
||||
});
|
||||
var dat = new ItemOption
|
||||
{
|
||||
SERVER = dataRow.Field<string>("Server") ?? "",
|
||||
SERVERIP = dataRow.Field<string>("ServerID") ?? ""
|
||||
};
|
||||
Items.Add(dat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:设置默认选中项
|
||||
if (Items != null)
|
||||
// 设置默认选中项
|
||||
if (Items.Count>0)
|
||||
{
|
||||
SERVER.ItemsSource = Items;
|
||||
SERVER.SelectedItem = Items[0];
|
||||
@@ -74,19 +77,17 @@ public partial class LogPage : ContentPage
|
||||
TcpServer.Configuration(SERVERIP.Text, UsernameEntry.Text, PasswordEntry.Text,
|
||||
Models.AppModels.GetAppUniqueId());
|
||||
|
||||
|
||||
LoadingIndicator.IsVisible = true;
|
||||
|
||||
//TcpServer.TcpTransmit("Log");
|
||||
|
||||
|
||||
if (await AppModels.LogIn())
|
||||
{
|
||||
var temp_name = AppModels.Select("SELECT * FROM Users WHERE User='" + UsernameEntry.Text + "' LIMIT 1;")!.Tables[0];
|
||||
if (temp_name != null)
|
||||
App.GlobalData.ServerID = SERVERIP.Text;
|
||||
|
||||
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 = '" + SERVERIP.Text
|
||||
string sql = "UPDATE Users SET ServerID = '" + SERVERIP.Text
|
||||
+ "', UserPassword = '" + PasswordEntry.Text +
|
||||
"', LogNo = 1 WHERE User='" + UsernameEntry.Text + "';";
|
||||
AppModels.Updata(sql);
|
||||
@@ -104,8 +105,8 @@ public partial class LogPage : ContentPage
|
||||
AppModels.INSERT(sql);
|
||||
}
|
||||
|
||||
var temp_server = AppModels.Select("SELECT * FROM Server WHERE ServerID='" + SERVERIP.Text + "' LIMIT 1;")!.Tables[0];
|
||||
if (temp_server == null)
|
||||
int temp_server = AppModels.Select("SELECT * FROM Server WHERE ServerID='" + SERVERIP.Text + "' LIMIT 1;")!.Tables[0].Rows.Count;
|
||||
if (temp_server == 0)
|
||||
{
|
||||
string sql = @"INSERT INTO Server ( Server, ServerID)VALUES('" + App.GlobalData.Enterprise + "','" +
|
||||
App.GlobalData.ServerID + "');";
|
||||
@@ -119,12 +120,5 @@ public partial class LogPage : ContentPage
|
||||
await DisplayAlertAsync("未登录", "服务器不存在或拒绝访问", "是");
|
||||
}
|
||||
LoadingIndicator.IsVisible = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//await Navigation.PopModalAsync();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user