示例#1
0
        private void logIn_Click(object sender, RoutedEventArgs e)
        {
            var context       = DataEntitiesProvider.Provide();
            var minVersionStr = context.GlobalSettings.FirstOrDefault(x => x.Name == "MinimumSupportedVersion");

            if (minVersionStr != null)
            {
                var minVersion  = Version.Parse(minVersionStr.Value);
                var thisVersion = Assembly.GetExecutingAssembly().GetName().Version;
                if (thisVersion < minVersion)
                {
                    MessageBox.Show("This version is not supported any more because of database changes. Please get an update");
                    return;
                }
            }


            var lastLoggedIn = GetLastLoggedInUser();

            var loginBox = new LoginWindow(lastLoggedIn);

            loginBox.Owner = this;
            loginBox.ShowDialog();
            if (loginBox.UserId == 0)
            {
                MessageBox.Show("Invalid user/password");
                return;
            }

            WriteLoggedInUserToRegistry(loginBox.UserName);

            _databaseCheckTimer.Start();

            GlobalSettings.LoggedInUser = loginBox.UserName;
            LoggedInUserId = loginBox.UserId;
            UserLoginId    = loginBox.UserLoginId;
            this.Title    += " --- logged in as " + loginBox.UserName
                             + " --- " + DataEntitiesProvider.Description();

            ViewModel.IsLoggedIn = true;
            UserLoggedIn(this, new EventArgs());
        }