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.
93 lines
2.8 KiB
93 lines
2.8 KiB
using SunlightAggregationTerminal.Models;
|
|
using System.Data;
|
|
using System.Linq;
|
|
|
|
namespace SunlightAggregationTerminal;
|
|
|
|
public partial class NotificationPage : ContentPage
|
|
{
|
|
public NotificationItem NoticeItem { get; set; } = new NotificationItem();
|
|
public NotificationItem MessageItem { get; set; } = new NotificationItem();
|
|
public NotificationItem SystemItem { get; set; } = new NotificationItem();
|
|
|
|
public NotificationPage()
|
|
{
|
|
InitializeComponent();
|
|
this.BindingContext = this;
|
|
}
|
|
|
|
private void ContentPage_Loaded(object sender, EventArgs e)
|
|
{
|
|
LoadSummaryData();
|
|
}
|
|
|
|
private void LoadSummaryData()
|
|
{
|
|
var allItems = DataService.GetAllItems();
|
|
|
|
// 筛选出 Type 为 Notice 的数据,并取第一条
|
|
// 对应 DataTable 的 Select("Type = ...").First()
|
|
var noticeItem = allItems.FirstOrDefault(x => x.Type == MsgType.Notice);
|
|
|
|
// 读取数据 (注意判空,防止找不到数据时报错)
|
|
if (noticeItem != null)
|
|
{
|
|
NoticeItemTitle.Text = noticeItem.Title;
|
|
NoticeItemContent.Text = noticeItem.Content;
|
|
}
|
|
else
|
|
{
|
|
// 处理没有找到数据的情况
|
|
NoticeItemTitle.Text = "暂无通知";
|
|
NoticeItemContent.Text = "通知";
|
|
}
|
|
|
|
var messageItem = allItems.FirstOrDefault(x => x.Type == MsgType.Message);
|
|
|
|
// 读取数据 (注意判空,防止找不到数据时报错)
|
|
if (messageItem != null)
|
|
{
|
|
MessageItemTitle.Text = messageItem.Title;
|
|
MessageItemContent.Text = messageItem.Content;
|
|
}
|
|
else
|
|
{
|
|
// 处理没有找到数据的情况
|
|
MessageItemTitle.Text = "暂无通知";
|
|
MessageItemContent.Text = "信息";
|
|
}
|
|
var systemItem = allItems.FirstOrDefault(x => x.Type == MsgType.System);
|
|
|
|
// 读取数据 (注意判空,防止找不到数据时报错)
|
|
if (systemItem != null)
|
|
{
|
|
SystemItemTitle.Text = systemItem.Title;
|
|
SystemItemContent.Text = systemItem.Content;
|
|
}
|
|
else
|
|
{
|
|
// 处理没有找到数据的情况
|
|
SystemItemTitle.Text = "暂无通知";
|
|
SystemItemContent.Text = "系统信息";
|
|
}
|
|
|
|
}
|
|
|
|
// 点击跳转到独立页面
|
|
private async void OnNoticeTapped(object sender, TappedEventArgs e)
|
|
{
|
|
await Navigation.PushAsync(new NotificationView.NoticePage());
|
|
}
|
|
|
|
private async void OnMessageTapped(object sender, TappedEventArgs e)
|
|
{
|
|
await Navigation.PushAsync(new NotificationView.MessagePage());
|
|
}
|
|
|
|
private async void OnSystemTapped(object sender, TappedEventArgs e)
|
|
{
|
|
await Navigation.PushAsync(new NotificationView.SystemPage());
|
|
}
|
|
|
|
|
|
}
|