Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1.  
  2. public partial class App : Application
  3.     {
  4.         protected override void OnStartup(StartupEventArgs e)
  5.         {
  6.             base.OnStartup(e);
  7.  
  8.             var connectionViewModel = new ConnectionDBViewModel();
  9.             var authorizationForm = new AuthorizationForm(connectionViewModel);
  10.  
  11.             EventHandler onSuccessfulСonnection = null;
  12.  
  13.             onSuccessfulСonnection = async (obj, ev) =>
  14.             {
  15.                 connectionViewModel.SuccessfulСonnection -= onSuccessfulСonnection;
  16.  
  17.                 Current.MainWindow = new MainWindow(await SpreadsheetsViewModel.NewAsync(connectionViewModel));
  18.                 authorizationForm.Close();
  19.                 Current.MainWindow.Show();
  20.             };
  21.            
  22.             connectionViewModel.SuccessfulСonnection += onSuccessfulСonnection;
  23.            
  24.             authorizationForm.Show();
  25.         }
  26.     }
  27.  
  28.  
  29.  
  30. public event EventHandler SuccessfulСonnection = null;
  31.  
  32. public ICommand LogInCommand
  33.         {
  34.             get
  35.             {
  36.                 return Get(() => LogInCommand, new RelayCommand((sender) =>
  37.                 {
  38.                     if (IsValidOnClick())
  39.                     {
  40.                         if ((sender as Storyboard) != null)
  41.                         {
  42.                             EventHandler onCompleted = null;
  43.  
  44.                             onCompleted = async (obj, e) =>
  45.                             {
  46.                                 (sender as Storyboard).Completed -= onCompleted;
  47.  
  48.                                 try
  49.                                 {                                    
  50.                                     using (var sqlConnection = LinqHelpers.NewConnection(SrvName, DbName, UsrName, PasName, SSPI))
  51.                                     {
  52.                                         await sqlConnection.OpenAsync();
  53.                                         SchemaDatabase = await LinqHelpers.GetSchemaAsync(sqlConnection, "Databases", new string[] { DbName });                                
  54.                                     }
  55.  
  56.                                     SuccessfulСonnection?.Invoke(this, EventArgs.Empty);                                                                                          
  57.                                 }
  58.                                 catch (Exception ex)
  59.                                 {
  60.                                     errorCallback.ErrorInfo = ex.Message;
  61.                                 }
  62.                             };
  63.                            
  64.                             (sender as Storyboard).Completed += onCompleted;
  65.                             (sender as Storyboard).Begin();
  66.                         }
  67.                     }
  68.                 }));
  69.             }
  70.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement