liuyuqi-dellpc 3 years ago
parent
commit
9acdf6110d
2 changed files with 31 additions and 7 deletions
  1. 2 1
      ShareWifi/Views/Home.Designer.cs
  2. 29 6
      ShareWifi/Views/Home.cs

+ 2 - 1
ShareWifi/Views/Home.Designer.cs

@@ -45,7 +45,7 @@
             this.label4.AutoSize = true;
             this.label4.Font = new System.Drawing.Font("Sitka Banner", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
             this.label4.ForeColor = System.Drawing.Color.Red;
-            this.label4.Location = new System.Drawing.Point(171, 359);
+            this.label4.Location = new System.Drawing.Point(81, 351);
             this.label4.Name = "label4";
             this.label4.Size = new System.Drawing.Size(262, 23);
             this.label4.TabIndex = 4;
@@ -134,6 +134,7 @@
             this.Controls.Add(this.btnGenerate);
             this.Name = "HomeControl";
             this.Size = new System.Drawing.Size(604, 413);
+            this.Load += new System.EventHandler(this.HomeControl_Load);
             this.panel2.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.picQR)).EndInit();
             this.ResumeLayout(false);

+ 29 - 6
ShareWifi/Views/Home.cs

@@ -10,7 +10,7 @@ namespace ShareWifi.Views
 {
     public partial class HomeControl : UserControl
     {
-        WifiModel wifiModel=new WifiModel();
+        WifiModel wifiModel;
         public HomeControl()
         {
             InitializeComponent();
@@ -23,25 +23,48 @@ namespace ShareWifi.Views
         }
 
         private void btnGenerate_Click(object sender, EventArgs e)
+        {
+            if (showWifiinfo())
+            { 
+                //生成二维码
+                QRModel qRModel = QRUtils.genQR(wifiModel.getWifi());
+                picQR.Image = qRModel.QrData;
+            }
+            else
+            {
+                SimpleAlert simpleAlert = SimpleAlert.getInstance();
+                simpleAlert.Show("请链接 WIFI!");
+                lbPWD.Text = "null";
+                lbSSID.Text = "null";
+                picQR.Image = null;
+            }
+
+        }
+
+        public bool showWifiinfo()
         {
             string ssid = WifiUtils.getSSID();
             if (ssid != "" && ssid != null)
             {
+                wifiModel = new WifiModel();
                 wifiModel.Ssid = ssid;
                 //查找密码
                 wifiModel.Pwd = WifiUtils.getSSDIPassword(ssid);
-                //生成二维码
-                QRModel qRModel = QRUtils.genQR(wifiModel.getWifi());
-                picQR.Image = qRModel.QrData;
-
                 lbPWD.Text = wifiModel.Pwd;
                 lbSSID.Text = wifiModel.Ssid;
+                return true;
             }
             else
             {
                 SimpleAlert simpleAlert = SimpleAlert.getInstance();
-                simpleAlert.Show("请链接 WIFI 后才可以分享!");
+                simpleAlert.Show("请链接 WIFI!");
+                return false;
             }
         }
+
+        private void HomeControl_Load(object sender, EventArgs e)
+        {
+            showWifiinfo();
+        }
     }
 }