2
2
using DofGMTool . Contracts . Services ;
3
3
using DofGMTool . Core . Contracts . Services ;
4
4
using DofGMTool . Core . Services ;
5
+ using DofGMTool . Helpers ;
5
6
using DofGMTool . Models ;
6
7
using DofGMTool . Services ;
7
8
using DofGMTool . ViewModels ;
11
12
using Microsoft . Extensions . Hosting ;
12
13
using Microsoft . UI . Xaml ;
13
14
using Microsoft . UI . Xaml . Controls ;
14
- using MySqlConnector ;
15
15
using System . Diagnostics ;
16
16
using Windows . Storage ;
17
17
@@ -90,42 +90,7 @@ public App()
90
90
services . AddTransient < MainPage > ( ) ;
91
91
services . AddTransient < ShellPage > ( ) ;
92
92
services . AddTransient < ShellViewModel > ( ) ;
93
- services . AddSingleton < IFreeSql < MySqlFlag > > ( provider =>
94
- {
95
- return new FreeSqlBuilder ( )
96
- . UseConnectionFactory ( DataType . MySql , ( ) =>
97
- {
98
- var conn = new MySqlConnection ( "data source=192.168.200.131;port=3306;user id=game;password=uu5!^%jg;initial catalog=taiwan_cain;sslmode=none;max pool size=50;Charset=latin1;ConvertZeroDateTime=True;" ) ;
99
- conn . Open ( ) ;
100
- MySqlCommand cmd = conn . CreateCommand ( ) ;
101
- cmd . CommandText = "SET Charset latin1;" ;
102
- cmd . ExecuteNonQuery ( ) ;
103
- return conn ;
104
- } )
105
- . UseMonitorCommand ( cmd => Debug . WriteLine ( $ "Sql:{ cmd . CommandText } ") )
106
- . Build < MySqlFlag > ( ) ;
107
- } ) ;
108
- //Func<IServiceProvider, IFreeSql<MySqlFlag>> fsqlMysql = r =>
109
- //{
110
- // IFreeSql<MySqlFlag> fsql1 = new FreeSqlBuilder().UseConnectionFactory(DataType.MySql, () =>
111
- // {
112
-
113
-
114
-
115
- // var conn = new MySqlConnection("data source=192.168.200.131;port=3306;user id=game;password=uu5!^%jg;initial catalog=taiwan_cain;sslmode=none;max pool size=12;Charset=latin1;");
116
- // conn.Open();
117
- // MySqlCommand cmd = conn.CreateCommand();
118
- // cmd.CommandText = "SET Charset latin1;";
119
- // cmd.ExecuteNonQuery();
120
- // //conn.Close();
121
- // return conn;
122
- // })
123
- // .UseMonitorCommand(cmd => Debug.WriteLine($"Sql:{cmd.CommandText}"))
124
- // .Build<MySqlFlag>();
125
-
126
- // return fsql1;
127
- //};
128
-
93
+ services . AddTransient < LoginWindowViewModel > ( ) ;
129
94
130
95
Func < IServiceProvider , IFreeSql < SqliteFlag > > fsqlSqlite = r =>
131
96
{
@@ -139,9 +104,7 @@ public App()
139
104
return fsql2 ;
140
105
} ;
141
106
142
- //services.AddSingleton<IFreeSql<MySqlFlag>>(fsqlMysql);
143
107
services . AddSingleton < IFreeSql < SqliteFlag > > ( fsqlSqlite ) ;
144
- services . AddSingleton < IDatabaseService , DatabaseService > ( ) ; // 注册动态数据库服务
145
108
// Configuration
146
109
services . Configure < LocalSettingsOptions > ( context . Configuration . GetSection ( nameof ( LocalSettingsOptions ) ) ) ;
147
110
} ) .
@@ -161,20 +124,29 @@ private async void App_UnhandledException(object sender, Microsoft.UI.Xaml.Unhan
161
124
162
125
var dialog = new ContentDialog
163
126
{
164
- Title = "Unhandled Exception " ,
165
- Content = $ "An unhandled exception occurred: { e . Exception . Message } ",
127
+ Title = "错误! " ,
128
+ Content = $ " { e . Exception . Message } ",
166
129
CloseButtonText = "我知道了" ,
167
- XamlRoot = MainWindow . Content . XamlRoot
130
+ XamlRoot = App . CurrentWindow . Content . XamlRoot // MainWindow.Content.XamlRoot
168
131
} ;
169
132
170
133
await dialog . ShowAsync ( ) ;
171
134
}
172
135
136
+ public static Window CurrentWindow = Window . Current ;
173
137
174
- protected override async void OnLaunched ( LaunchActivatedEventArgs args )
138
+ protected override void OnLaunched ( LaunchActivatedEventArgs args )
175
139
{
140
+ CurrentWindow = new LoginWindow ( ) ;
141
+
142
+ App . MainWindow . Closed += CurrentWindow_Closed ;
143
+ CurrentWindow . Activate ( ) ;
176
144
base . OnLaunched ( args ) ;
177
145
178
- await App . GetService < IActivationService > ( ) . ActivateAsync ( args ) ;
146
+ //await App.GetService<IActivationService>().ActivateAsync(args);
147
+ }
148
+ private void CurrentWindow_Closed ( object sender , WindowEventArgs e )
149
+ {
150
+ DatabaseHelper . Instance . Dispose ( ) ;
179
151
}
180
152
}
0 commit comments