添加项目文件。

This commit is contained in:
sc committed 2026-05-01 14:44:49 +08:00
1 parent 6c0af56ea9
commit 54eaa8a836
64 files changed
+3176

No files matched your search

+89
View File
@@ -0,0 +1,89 @@
using CommunityToolkit.Mvvm.ComponentModel;
using SunlightAggregationTerminal.Class;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace SunlightAggregationTerminal.Models
{
public class AppModels : ObservableObject
{
public static SqliteHelper sqliteHelper = SQLiteConfig.Config(Path.Combine(FileSystem.AppDataDirectory, "MyAppData.db"))!; //数据库连接路径(获取各平台的应用数据目录)
public AppModels()
{
if(sqliteHelper != null)
{//获取配置信息
sqliteHelper.Open();
var userdata= sqliteHelper.ExecuteDataSet("select * from Users Where LogNo = 1", null);
sqliteHelper.Close();
if (userdata != null)
{
var dat = userdata.Tables[0].AsEnumerable().FirstOrDefault();
if (dat != null)
{
App.GlobalData.UserName = dat.Field<string>("UserName") ?? "";
App.GlobalData.UserId = dat.Field<string>("UserId") ?? "";
App.GlobalData.User = dat.Field<string>("User") ?? "";
App.GlobalData.UserPassword = dat.Field<string>("UserPassword") ?? "";
App.GlobalData.Enterprise = dat.Field<string>("Enterprise") ?? "";
App.GlobalData.Department = dat.Field<string>("Department") ?? "";
App.GlobalData.Groups = dat.Field<string>("Groups") ?? "";
App.GlobalData.ServerID = dat.Field<string>("ServerID") ?? "";
App.GlobalData.ProxyID = dat.Field<string>("ProxyID") ?? "";
App.GlobalData.LogNo = Convert.ToBoolean(dat.Field<object>("LogNo"));
App.GlobalData.LocalAreaNetworkMode = Convert.ToBoolean(dat.Field<object>("LocalAreaNetworkMode"));
App.GlobalData.DarkMode = Convert.ToBoolean(dat.Field<object>("DarkMode"));
App.GlobalData.MessageNotificationMode = Convert.ToBoolean(dat.Field<object>("MessageNotificationMode"));
TcpServer.Configuration(App.GlobalData.ServerID, App.GlobalData.User, App.GlobalData.UserPassword, dat.Field<string>("GUID") ?? "Not");
}
}
}
}
public static void Updata(string sql)
{
sqliteHelper.Open();
sqliteHelper.ExecuteNonQuery(sql, null);
sqliteHelper.Close();
}
public static void INSERT(string sql)
{
sqliteHelper.Open();
sqliteHelper.ExecuteNonQuery(sql, null);
sqliteHelper.Close();
}
public static DataSet? Select(string sql)
{
sqliteHelper.Open();
var userdata = sqliteHelper.ExecuteDataSet(sql, null);
sqliteHelper.Close();
return userdata;
}
public static string GetAppUniqueId()
{
const string key = "sunlight_app_unique_id";
// 尝试从安全存储中读取
string? id = SecureStorage.GetAsync(key).Result;
if (string.IsNullOrEmpty(id))
{
// 如果不存在,生成一个新的 GUID
id = Guid.NewGuid().ToString();
// 保存到安全存储
SecureStorage.SetAsync(key, id).Wait();
}
return id;
}
}
}
+40
View File
@@ -0,0 +1,40 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Text;
namespace SunlightAggregationTerminal.Models
{
#pragma warning disable CA1416
public partial class DataModel : ObservableObject
{
[ObservableProperty]
public partial string User { get; set; }
[ObservableProperty]
public partial string UserId { get; set; }
[ObservableProperty]
public partial string UserName { get; set; }
[ObservableProperty]
public partial string UserPassword { get; set; }
[ObservableProperty]
public partial string Enterprise { get; set; }
[ObservableProperty]
public partial string Department { get; set; }
[ObservableProperty]
public partial string ServerID { get; set; }
[ObservableProperty]
public partial string Groups { get; set; }
[ObservableProperty]
public partial string ProxyID { get; set; }
[ObservableProperty]
public partial bool LogNo { get; set; }
public bool IsNotLogNo => !LogNo;
[ObservableProperty]
public partial bool LocalAreaNetworkMode { get; set; }
[ObservableProperty]
public partial bool DarkMode { get; set; }
[ObservableProperty]
public partial bool MessageNotificationMode { get; set; }
}
}
+58
View File
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Linq;
namespace SunlightAggregationTerminal.Models
{
// 定义枚举
public enum MsgType
{
Notice, // 通知
Message, // 信息
System // 系统
}
// 定义显示用的模型
public class NotificationItem
{
public Int64 Id { get; set; }
public string? Title { get; set; }
public string? Content { get; set; }
public DateTime Time { get; set; }
public MsgType Type { get; set; }
}
public static class DataService
{
public static DataSet? data = AppModels.Select("select * from Notification Where Time > '" + DateTime.Now.AddDays(-30) + "'");
// 直接返回 List
public static List<NotificationItem> _NotificationData = new List<NotificationItem>();
public static List<NotificationItem> GetAllItems()
{
_NotificationData.Clear();
if (data != null)
{
foreach (DataRow dr in data.Tables[0].Rows)
{
_NotificationData.Add(new NotificationItem
{
Id = dr.Field<Int64>("Id"),
Title = dr.Field<string>("Title") ,
Content = dr.Field<string>("Content"),
Time = DateTime.Parse(dr.Field<string>("Time")!),
Type = (MsgType)dr.Field<Int64>("Type")
});
}
}
// 倒序返回
return _NotificationData.OrderByDescending(x => x.Time).ToList();
}
}
}