예제 #1
0
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            var ItemInWiFiControl = WiFiControl.ContainerFromItem(WiFiControl.SelectedItem) as ListViewItem;

            WiFiList[WiFiControl.SelectedIndex].HideMessage();
            ItemInWiFiControl.ContentTemplate = WiFiPressState;
        }
예제 #2
0
        private void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            var ItemInWiFiControl = WiFiControl.ContainerFromItem(WiFiControl.SelectedItem) as ListViewItem;

            foreach (var WiFiInfo in from WiFiInfo in StoragedWiFiInfoCollection
                     where WiFiInfo.SSID == WiFiList[WiFiControl.SelectedIndex].Name
                     select WiFiInfo)
            {
                WiFiList[WiFiControl.SelectedIndex].Password = WiFiInfo.Password;
                break;
            }

            if (WiFiList[WiFiControl.SelectedIndex].Password != "")
            {
                ItemInWiFiControl.ContentTemplate = WiFiConnectingState;
                ConfirmButton_Click(null, null);
            }
            else
            {
                ItemInWiFiControl.ContentTemplate = WiFiPasswordState;
            }

            //连接WiFi期间需要暂时停止搜索,因为此时搜索将导致WiFi列表位移
            WiFiScanTimer.Tick -= WiFiScanTimer_Tick;
            WiFiScanTimer.Stop();
            Progressing.Visibility = Visibility.Collapsed;
        }
예제 #3
0
        private async void DisconnectButton_Click(object sender, RoutedEventArgs e)
        {
            WiFi.Disconnect();
            var item = WiFiList[WiFiControl.SelectedIndex];

            item.AutoConnect = false;
            await SQLite.GetInstance().UpdateWiFiDataAsync(item.Name, false);

            WiFiList[WiFiControl.SelectedIndex].ChangeConnectionStateAsync(false);
            (WiFiControl.ContainerFromItem(WiFiControl.SelectedItem) as ListViewItem).ContentTemplate = WiFiPressState;
        }
예제 #4
0
        private void WiFiControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (var ItemInWiFiControl in from RemovedItem in e.RemovedItems
                     let ItemInWiFiControl = WiFiControl.ContainerFromItem(RemovedItem) as ListViewItem
                                             where ItemInWiFiControl.ContentTemplate != WiFiNormalState
                                             select ItemInWiFiControl)
            {
                ItemInWiFiControl.ContentTemplate = WiFiNormalState;
            }

            foreach (var WiFi in WiFiList)
            {
                WiFi.HideMessage();
            }
        }
예제 #5
0
        private void WiFiControl_ItemClick(object sender, ItemClickEventArgs e)
        {
            var ItemInWiFiControl = WiFiControl.ContainerFromItem(e.ClickedItem) as ListViewItem;
            var ClickedItem       = e.ClickedItem as WiFiInfo;

            if (ClickedItem.IsConnected)
            {
                ItemInWiFiControl.ContentTemplate = WiFiConnectedState;
                return;
            }

            if (ItemInWiFiControl.ContentTemplate == WiFiNormalState)
            {
                foreach (var WiFiInfo in from WiFiInfo in StoragedWiFiInfoCollection
                         where WiFiInfo.SSID == ClickedItem.Name
                         select WiFiInfo)
                {
                    ClickedItem.AutoConnect = WiFiInfo.AutoConnect;
                    break;
                }
                ItemInWiFiControl.ContentTemplate = WiFiPressState;
            }
        }
예제 #6
0
        private async void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            string Pass = WiFiList[WiFiControl.SelectedIndex].Password;

            if (Pass != "" && Pass.Length >= 8)
            {
                WiFiList[WiFiControl.SelectedIndex].HideMessage();
                (WiFiControl.ContainerFromItem(WiFiControl.SelectedItem) as ListViewItem).ContentTemplate = WiFiConnectingState;

                WiFiInfo           Info       = WiFiList[WiFiControl.SelectedIndex];
                PasswordCredential Credential = new PasswordCredential
                {
                    Password = Info.Password
                };

                var ConnectResult = await WiFi.ConnectAsync(Info.GetWiFiAvailableNetwork(), Info.AutoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual, Credential);

                if (ConnectResult.ConnectionStatus == WiFiConnectionStatus.Success)
                {
                    foreach (var WiFiInfo in from WiFiInfo in WiFiList
                             where WiFiInfo.IsConnected == true
                             select WiFiInfo)
                    {
                        WiFiInfo.ChangeConnectionStateAsync(false);
                    }

                    Info.HideMessage();
                    Info.ChangeConnectionStateAsync(true, true);

                    (WiFiControl.ContainerFromItem(WiFiControl.SelectedItem) as ListViewItem).ContentTemplate = WiFiConnectedState;

                    bool IsExist = false;

                    foreach (var WiFiInfo in from WiFiInfo in StoragedWiFiInfoCollection
                             where WiFiInfo.SSID == Info.Name
                             select WiFiInfo)
                    {
                        if (WiFiInfo.Password != Info.Password)
                        {
                            await SQLite.GetInstance().UpdateWiFiDataAsync(Info.Name, Info.Password);
                        }
                        else if (WiFiInfo.Password == Info.Password)
                        {
                            IsExist = true;
                        }

                        if (WiFiInfo.AutoConnect != Info.AutoConnect)
                        {
                            await SQLite.GetInstance().UpdateWiFiDataAsync(Info.Name, Info.AutoConnect);
                        }

                        break;
                    }

                    if (!IsExist)
                    {
                        IsExist = false;
                        StoragedWiFiInfoCollection.Add(new WiFiInDataBase(Info.Name, Info.Password, Info.AutoConnect ? "True" : "False"));
                        await SQLite.GetInstance().SetWiFiDataAsync(Info.Name, Info.Password, Info.AutoConnect);
                    }
                }
                else
                {
                    WiFi.Disconnect();
                    (WiFiControl.ContainerFromItem(WiFiControl.SelectedItem) as ListViewItem).ContentTemplate = WiFiErrorState;
                    Info.ShowMessage("连接失败");
                }

                //连接完成后重新开始搜索
                WiFiScanTimer.Tick += WiFiScanTimer_Tick;
                WiFiScanTimer.Start();
            }
            else
            {
                WiFiList[WiFiControl.SelectedIndex].ShowMessage("密码必须非空且大于8位");
            }
        }