示例#1
0
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (cbNetList.SelectedIndex == -1)
            {
                await new MessageDialog("请选择一个WIFI信号").ShowAsync();
                return;
            }
            var selWifi = cbNetList.SelectedItem as Windows.Devices.WiFi.WiFiAvailableNetwork;

            if (wifi.BjutWifiList.Contains(selWifi.Ssid) == false)
            {
                await new MessageDialog("请选择一个工大官方wifi信号").ShowAsync();
                return;
            }

            if (string.IsNullOrEmpty(tbUserName.Text))
            {
                tbUserName.Focus(FocusState.Keyboard);
                return;
            }
            if (string.IsNullOrEmpty(tbPassword.Password))
            {
                tbPassword.Focus(FocusState.Keyboard);
                return;
            }

            if (user.UserInfo == null)
            {
                user.UserInfo = new UserAuthEntity();
            }
            user.UserInfo.UserName = tbUserName.Text.Trim();
            user.UserInfo.Password = tbPassword.Password.Trim();

            //显示进度环
            ProgressView.ProgressIndicator progress = new ProgressView.ProgressIndicator();

            progress.Show();


            try
            {
                //if (cbSave.IsChecked == true)
                //{
                //    user.SaveUserInfo();
                //}
                user.SaveUserInfo();//保存密码

                var connProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();

                bool re = true;
                if (connProfile == null || connProfile.ProfileName != selWifi.Ssid)
                {
                    re = await Task.Run <bool>(() => wifi.ConnectWifi(selWifi));
                }

                if (re == true)
                {
                    wifi.ConStatus = "已连接到:" + selWifi.Ssid;

                    await Authenticate();
                }
                else
                {
                    wifi.ConStatus = "WIFI连接异常,请重试";
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message).ShowAsync();
            }
            finally
            {
                //隐藏进度环
                //progressRing.IsActive = false;
                //SetControlStatus(grid, true);
                progress.Hide();
                //btnAuthentication.Focus(FocusState.Keyboard);
            }
        }