Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8431a24d9 | ||
|
|
0801e4875c |
No files matched your search
+2
-1
@@ -1,5 +1,6 @@
|
||||
using SunlightAggregationTerminal.Class;
|
||||
using SunlightAggregationTerminal.Models;
|
||||
using SunlightAggregationTerminal.View;
|
||||
|
||||
namespace SunlightAggregationTerminal
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace SunlightAggregationTerminal
|
||||
if (!App.GlobalData.LogNo)
|
||||
{
|
||||
var logpage = new View.LogPage();
|
||||
Navigation.PushModalAsync(logpage);
|
||||
Navigation.PushModalAsync(new NavigationPage(logpage));
|
||||
}
|
||||
else
|
||||
{//发送登录请求
|
||||
|
||||
@@ -34,6 +34,15 @@ namespace SunlightAggregationTerminal.Class
|
||||
CreateFreshUserTableNotification();
|
||||
}
|
||||
|
||||
if (SQLitedata.TableExists("Server"))
|
||||
{
|
||||
CheckAndRepairTableSchemaSERVER();
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateFreshUserTableSERVER();
|
||||
}
|
||||
|
||||
SQLitedata.Close();
|
||||
|
||||
return SQLitedata;
|
||||
@@ -203,6 +212,42 @@ namespace SunlightAggregationTerminal.Class
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void CheckAndRepairTableSchemaSERVER()
|
||||
{
|
||||
// 获取现有字段列表
|
||||
// 使用 PRAGMA table_info 获取结构
|
||||
string pragmaSql = "PRAGMA table_info('Server');";
|
||||
|
||||
// 复用现有的 ExecuteReader 方法
|
||||
// ExecuteReader 返回 null 代表出错,否则返回 DataReader
|
||||
using (var reader = SQLitedata.ExecuteReader(pragmaSql, null))
|
||||
{
|
||||
if (reader == null) return;
|
||||
|
||||
var existingColumns = new List<string>();
|
||||
while (reader.Read())
|
||||
{
|
||||
// PRAGMA table_info 返回结果的第2列(Index=1)是列名
|
||||
string colName = reader.GetString(1);
|
||||
existingColumns.Add(colName);
|
||||
}
|
||||
reader.Close(); // 记得关闭 Reader
|
||||
|
||||
// 检查并添加缺失字段 (直接拼接 SQL)
|
||||
// 检查 Enterprise
|
||||
if (!existingColumns.Contains("Enterprise"))
|
||||
{
|
||||
string sql = "ALTER TABLE Server ADD COLUMN Enterprise TEXT NULL;";
|
||||
SQLitedata.ExecuteNonQuery(sql, null);
|
||||
}
|
||||
// 检查 ServerID
|
||||
if (!existingColumns.Contains("ServerID"))
|
||||
{
|
||||
string sql = "ALTER TABLE Server ADD COLUMN ServerID TEXT;";
|
||||
SQLitedata.ExecuteNonQuery(sql, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
// --- 逻辑分支 表不存在,直接创建 ---
|
||||
private static void CreateFreshUserTable()
|
||||
{
|
||||
@@ -247,6 +292,18 @@ namespace SunlightAggregationTerminal.Class
|
||||
Type INT
|
||||
);";
|
||||
|
||||
// 复用现有的 ExecuteNonQuery 方法
|
||||
SQLitedata.ExecuteNonQuery(createSql, null);
|
||||
}
|
||||
private static void CreateFreshUserTableSERVER()
|
||||
{
|
||||
// 建表语句
|
||||
string createSql = @"
|
||||
CREATE TABLE Server (
|
||||
Enterprise TEXT,
|
||||
ServerID TEXT
|
||||
);";
|
||||
|
||||
// 复用现有的 ExecuteNonQuery 方法
|
||||
SQLitedata.ExecuteNonQuery(createSql, null);
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,3 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
|
||||
namespace SunlightAggregationTerminal;
|
||||
|
||||
public partial class QueryPage : ContentPage
|
||||
@@ -8,11 +10,10 @@ public partial class QueryPage : ContentPage
|
||||
public QueryPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
OnScanQuery = (result) =>
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
|
||||
WeakReferenceMessenger.Default.Register<string>(this, (r, scannedValue) =>
|
||||
{
|
||||
ResultEntry.Text = result;
|
||||
ResultEntry.Text = scannedValue;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
+27
-4
@@ -1,6 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using SunlightAggregationTerminal.View;
|
||||
using ZXing.Multi;
|
||||
using ZXing.Net.Maui;
|
||||
using ZXing.QrCode.Internal;
|
||||
|
||||
namespace SunlightAggregationTerminal;
|
||||
|
||||
@@ -20,10 +22,31 @@ public partial class ScanPage : ContentPage
|
||||
barcodeReader.IsDetecting = false;
|
||||
|
||||
// 触发回调
|
||||
if (mode == 0) QueryPage.OnScanQuery?.Invoke(firstResult.Value);
|
||||
if (mode == 3) LogPage.OnScanProfile?.Invoke(firstResult.Value);
|
||||
|
||||
await Navigation.PopAsync();
|
||||
if (mode == 0)
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
// 震动
|
||||
try { Vibration.Default.Vibrate(TimeSpan.FromMilliseconds(100)); } catch { }
|
||||
// 传入信息
|
||||
WeakReferenceMessenger.Default.Send(firstResult.Value);
|
||||
// 等待 1.5 秒(非阻塞,界面不会卡死)
|
||||
Task.Delay(1500);
|
||||
// 关闭页面
|
||||
Navigation.PopAsync();
|
||||
});
|
||||
}
|
||||
if (mode == 3)
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
try { Vibration.Default.Vibrate(TimeSpan.FromMilliseconds(100)); } catch { }
|
||||
WeakReferenceMessenger.Default.Send(firstResult.Value);
|
||||
Task.Delay(1500);
|
||||
// 关闭页面
|
||||
Navigation.PopModalAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -2,8 +2,7 @@
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="SunlightAggregationTerminal.View.LogPage"
|
||||
Title="LogPage">
|
||||
|
||||
Title="登录">
|
||||
<VerticalStackLayout Padding="30" Spacing="20"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
@@ -15,12 +14,13 @@
|
||||
Grid.Column="0"
|
||||
VerticalOptions="Center">
|
||||
<HorizontalStackLayout VerticalOptions="Center">
|
||||
<Label Text="服务器:" FontSize="26" TextColor="Black" />
|
||||
<Entry Text="服务器:" FontSize="26" TextColor="Black" />
|
||||
<Entry x:Name="Enterprise"
|
||||
Text="IP"
|
||||
FontSize="26"
|
||||
TextColor="Gray"
|
||||
WidthRequest="300"/>
|
||||
WidthRequest="200"
|
||||
MaximumWidthRequest="200"/>
|
||||
</HorizontalStackLayout>
|
||||
</VerticalStackLayout>
|
||||
</HorizontalStackLayout>
|
||||
@@ -36,21 +36,23 @@
|
||||
</Button>
|
||||
</Grid>
|
||||
<HorizontalStackLayout VerticalOptions="Center">
|
||||
<Label Text="用户:" FontSize="26" TextColor="Black" />
|
||||
<Entry Text="用户:" FontSize="26" TextColor="Black" />
|
||||
<!-- 用户名输入 -->
|
||||
<Entry x:Name="UsernameEntry"
|
||||
Placeholder="请输入用户名"
|
||||
FontSize="26"
|
||||
WidthRequest="380"/>
|
||||
WidthRequest="250"
|
||||
MaximumWidthRequest="250"/>
|
||||
</HorizontalStackLayout>
|
||||
<HorizontalStackLayout VerticalOptions="Center">
|
||||
<Label Text="密码:" FontSize="26" TextColor="Black"/>
|
||||
<Entry Text="密码:" FontSize="26" TextColor="Black"/>
|
||||
<!-- 密码输入 -->
|
||||
<Entry x:Name="PasswordEntry"
|
||||
Placeholder="请输入密码"
|
||||
IsPassword="True"
|
||||
FontSize="26"
|
||||
WidthRequest="380"/>
|
||||
WidthRequest="250"
|
||||
MaximumWidthRequest="250"/>
|
||||
</HorizontalStackLayout>
|
||||
<!-- 登录按钮 -->
|
||||
<Button Text="登 录"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using SunlightAggregationTerminal.Class;
|
||||
using SunlightAggregationTerminal.Models;
|
||||
using System.Data;
|
||||
@@ -10,11 +11,10 @@ public partial class LogPage : ContentPage
|
||||
public LogPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
OnScanProfile = (result) =>
|
||||
|
||||
WeakReferenceMessenger.Default.Register<string>(this, (r, scannedValue) =>
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Enterprise.Text = result;
|
||||
Enterprise.Text = scannedValue;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,4 +3,15 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="SunlightAggregationTerminal.View.LogWindow"
|
||||
Title="LogWindow">
|
||||
<ContentPage>
|
||||
|
||||
<!-- 登录按钮 -->
|
||||
<Button Text="登 录"
|
||||
BackgroundColor="#512BD4"
|
||||
TextColor="White"
|
||||
HeightRequest="50"
|
||||
WidthRequest="100"
|
||||
CornerRadius="10"
|
||||
Margin="0,10,0,0"/>
|
||||
</ContentPage>
|
||||
</Window>
|
||||
Reference in new issue
Block a user