WpfApp/MainWindow.xaml.cs

53 lines
1.5 KiB
C#

using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using guoke;
using SqlSugar;
namespace WpfApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly LogService log;
private readonly DatabaseService db;
private readonly EventService<GeneralEventArgs> even;
public MainWindow(LogService logService, DatabaseService databaseService, EventService<GeneralEventArgs> eventService)
{
InitializeComponent();
log = logService;
db = databaseService;
even = eventService;
// 记录窗口初始化日志
log.Info("MainWindow", "主窗口已通过依赖注入初始化");
log.Info("窗体启动");
even.AddEventHandler("GeneralEvent", (m, d) =>
{
log.Info($"接收到事件:{d.Data}");
});
}
private void Button_Click(object sender, RoutedEventArgs e)
{
SqlSugarScope scope = db.GetScope("LocalData");
scope.guokeCheckToCreate<aaa>();//检查并创建表
even.TriggerEvent("GeneralEvent", this, new GeneralEventArgs("测试", 1));
}
public class aaa : BaseTableModel
{
}
}
}