LoadingViewModel.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace ProximaAnalizer.ViewModels;
  2. internal partial class LoadingViewModel : ObservableObject
  3. {
  4. public LoadingViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,SqlSugarCustom sqlSugarCustom)
  5. {
  6. this._regionManager = regionManager;
  7. this._eventAggregator = eventAggregator;
  8. this._sqlSugarCustom = sqlSugarCustom;
  9. Task.Factory.StartNew(Initialize);
  10. }
  11. private readonly IEventAggregator _eventAggregator;
  12. private readonly IRegionManager _regionManager;
  13. private readonly SqlSugarCustom _sqlSugarCustom;
  14. private void Initialize()
  15. {
  16. //Thread.Sleep(2000);
  17. string dbString = "Database=TINReal;Password=123456;Host=10.4.6.89;Username=postgres;Persist Security Info=True";
  18. this._sqlSugarCustom.Initialize();
  19. if(!this._sqlSugarCustom.Open(dbString, DbType.PostgreSQL,true))
  20. {
  21. MessageBox.Show("Connect to db 10.4.6.89 Failed");
  22. App.Current.Shutdown();
  23. }
  24. App.Current.Dispatcher.Invoke(() =>
  25. {
  26. _eventAggregator.GetEvent<WindowSwitch>().Page = Pages.RecipeStepNavi;
  27. _eventAggregator.GetEvent<WindowSwitch>().Publish();
  28. });
  29. }
  30. }