Browse Source

finish v1

liuyuqi-dellpc 3 years ago
parent
commit
4844998858

+ 4 - 4
ShareWifi/MainForm.Designer.cs

@@ -58,7 +58,7 @@
             this.btnAboutMe.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.btnAboutMe.Image = global::ShareWifi.Properties.Resources.icons8_about;
             this.btnAboutMe.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
-            this.btnAboutMe.Location = new System.Drawing.Point(0, 57);
+            this.btnAboutMe.Location = new System.Drawing.Point(0, 95);
             this.btnAboutMe.Name = "btnAboutMe";
             this.btnAboutMe.Size = new System.Drawing.Size(196, 46);
             this.btnAboutMe.TabIndex = 1;
@@ -73,7 +73,7 @@
             this.btnHome.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.btnHome.Image = global::ShareWifi.Properties.Resources.icons8_home_1;
             this.btnHome.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
-            this.btnHome.Location = new System.Drawing.Point(0, 8);
+            this.btnHome.Location = new System.Drawing.Point(0, 46);
             this.btnHome.Name = "btnHome";
             this.btnHome.Size = new System.Drawing.Size(196, 46);
             this.btnHome.TabIndex = 1;
@@ -124,9 +124,9 @@
             this.label1.Font = new System.Drawing.Font("Sitka Banner", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
             this.label1.Location = new System.Drawing.Point(31, 3);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(93, 30);
+            this.label1.Size = new System.Drawing.Size(117, 30);
             this.label1.TabIndex = 0;
-            this.label1.Text = "WifiShare";
+            this.label1.Text = "Wifi QRCode";
             // 
             // plContent
             // 

+ 11 - 2
ShareWifi/MainForm.cs

@@ -13,6 +13,9 @@ namespace ShareWifi
 {
     public partial class MainForm : Form
     {
+        HomeControl home;
+        AboutMe aboutMe;
+
         public MainForm()
         {
             InitializeComponent();
@@ -35,14 +38,20 @@ namespace ShareWifi
 
         public void interHome()
         {
-            Home home = Home.getInstance();
+            if (home == null)
+            {
+                home = HomeControl.getInstance();
+            }
             plContent.Controls.Clear();
             plContent.Controls.Add(home);
         }
 
         private void btnAboutMe_Click(object sender, EventArgs e)
         {
-            AboutMe aboutMe = AboutMe.getInstance();
+            if (aboutMe == null)
+            {
+                aboutMe = AboutMe.getInstance();
+            }
             plContent.Controls.Clear();
             plContent.Controls.Add(aboutMe);
         }

+ 5 - 3
ShareWifi/Model/WifiModel.cs

@@ -8,13 +8,15 @@ namespace ShareWifi.Model
 {
     class WifiModel
     {
-        private string ssid;
+         string ssid;
         string pwd;
-        string mac;
+
+        public string Ssid { get => ssid; set => ssid = value; }
+        public string Pwd { get => pwd; set => pwd = value; }
 
         public string getWifi()
         {
-            return "WIFI:T:WPA;p:\"" + pwd + "\";S:" + ssid + ";";
+            return "WIFI:T:WPA;p:\"" + Pwd + "\";S:" + Ssid + ";";
         }
     }
 }

+ 1 - 1
ShareWifi/Utils/QRUtils.cs

@@ -27,7 +27,7 @@ namespace ShareWifi.Utils
 
             string fileName = System.DateTime.Now.ToString("yyyy-MM-dd-HH_mm_ss") + ".jpg";
             string filePath = System.Environment.CurrentDirectory;
-            bitmap.Save(filePath + "/" + fileName, ImageFormat.Jpeg);
+            //bitmap.Save(filePath + "/" + fileName, ImageFormat.Jpeg);
             return new QRModel(filePath, fileName, bitmap);
         }
     }

+ 2 - 2
ShareWifi/Views/Components/SimpleAlert.Designer.cs

@@ -46,7 +46,7 @@
             this.lbMessage.AutoSize = true;
             this.lbMessage.Font = new System.Drawing.Font("SimSun", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.lbMessage.ForeColor = System.Drawing.Color.White;
-            this.lbMessage.Location = new System.Drawing.Point(72, 9);
+            this.lbMessage.Location = new System.Drawing.Point(12, 13);
             this.lbMessage.Name = "lbMessage";
             this.lbMessage.Size = new System.Drawing.Size(34, 15);
             this.lbMessage.TabIndex = 1;
@@ -54,7 +54,7 @@
             // 
             // timer1
             // 
-            this.timer1.Interval = 5000;
+            this.timer1.Interval = 3000;
             this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
             // 
             // SimpleAlert

+ 2 - 1
ShareWifi/Views/Components/SimpleAlert.cs

@@ -33,7 +33,7 @@ namespace ShareWifi.Views.Components
 
         private void SimpleAlert_Load(object sender, EventArgs e)
         {
-
+            timer1.Start();
         }
 
         /// <summary>
@@ -43,6 +43,7 @@ namespace ShareWifi.Views.Components
         /// <param name="e"></param>
         private void timer1_Tick(object sender, EventArgs e)
         {
+            timer1.Stop();
             Close();
         }
     }

+ 71 - 17
ShareWifi/Views/Home.Designer.cs

@@ -1,6 +1,6 @@
 namespace ShareWifi.Views
 {
-    partial class Home
+    partial class HomeControl
     {
         /// <summary> 
         /// Required designer variable.
@@ -30,16 +30,21 @@
         {
             this.label4 = new System.Windows.Forms.Label();
             this.panel2 = new System.Windows.Forms.Panel();
-            this.pictureBox3 = new System.Windows.Forms.PictureBox();
+            this.picQR = new System.Windows.Forms.PictureBox();
             this.btnGenerate = new System.Windows.Forms.Button();
+            this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.lbPWD = new System.Windows.Forms.Label();
+            this.lbSSID = new System.Windows.Forms.Label();
             this.panel2.SuspendLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.picQR)).BeginInit();
             this.SuspendLayout();
             // 
             // label4
             // 
             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.Name = "label4";
             this.label4.Size = new System.Drawing.Size(262, 23);
@@ -49,25 +54,26 @@
             // panel2
             // 
             this.panel2.BackColor = System.Drawing.Color.White;
-            this.panel2.Controls.Add(this.pictureBox3);
-            this.panel2.Location = new System.Drawing.Point(175, 30);
+            this.panel2.Controls.Add(this.picQR);
+            this.panel2.Location = new System.Drawing.Point(85, 23);
             this.panel2.Name = "panel2";
-            this.panel2.Size = new System.Drawing.Size(256, 249);
+            this.panel2.Size = new System.Drawing.Size(228, 228);
             this.panel2.TabIndex = 3;
             // 
-            // pictureBox3
+            // picQR
             // 
-            this.pictureBox3.Location = new System.Drawing.Point(9, 9);
-            this.pictureBox3.Name = "pictureBox3";
-            this.pictureBox3.Size = new System.Drawing.Size(238, 228);
-            this.pictureBox3.TabIndex = 0;
-            this.pictureBox3.TabStop = false;
+            this.picQR.Location = new System.Drawing.Point(0, 0);
+            this.picQR.Name = "picQR";
+            this.picQR.Size = new System.Drawing.Size(228, 228);
+            this.picQR.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
+            this.picQR.TabIndex = 0;
+            this.picQR.TabStop = false;
             // 
             // btnGenerate
             // 
             this.btnGenerate.FlatAppearance.BorderSize = 0;
             this.btnGenerate.ForeColor = System.Drawing.Color.Black;
-            this.btnGenerate.Location = new System.Drawing.Point(219, 300);
+            this.btnGenerate.Location = new System.Drawing.Point(109, 289);
             this.btnGenerate.Name = "btnGenerate";
             this.btnGenerate.Size = new System.Drawing.Size(174, 38);
             this.btnGenerate.TabIndex = 2;
@@ -75,17 +81,61 @@
             this.btnGenerate.UseVisualStyleBackColor = true;
             this.btnGenerate.Click += new System.EventHandler(this.btnGenerate_Click);
             // 
-            // Home
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.label1.Location = new System.Drawing.Point(398, 108);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(46, 21);
+            this.label1.TabIndex = 5;
+            this.label1.Text = "SSID:";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.label2.Location = new System.Drawing.Point(347, 138);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(97, 21);
+            this.label2.TabIndex = 5;
+            this.label2.Text = "PASSWORD:";
+            // 
+            // lbPWD
+            // 
+            this.lbPWD.AutoSize = true;
+            this.lbPWD.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.lbPWD.Location = new System.Drawing.Point(460, 138);
+            this.lbPWD.Name = "lbPWD";
+            this.lbPWD.Size = new System.Drawing.Size(40, 21);
+            this.lbPWD.TabIndex = 5;
+            this.lbPWD.Text = "null";
+            // 
+            // lbSSID
+            // 
+            this.lbSSID.AutoSize = true;
+            this.lbSSID.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.lbSSID.Location = new System.Drawing.Point(460, 108);
+            this.lbSSID.Name = "lbSSID";
+            this.lbSSID.Size = new System.Drawing.Size(40, 21);
+            this.lbSSID.TabIndex = 5;
+            this.lbSSID.Text = "null";
+            // 
+            // HomeControl
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.Controls.Add(this.lbSSID);
+            this.Controls.Add(this.lbPWD);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
             this.Controls.Add(this.label4);
             this.Controls.Add(this.panel2);
             this.Controls.Add(this.btnGenerate);
-            this.Name = "Home";
+            this.Name = "HomeControl";
             this.Size = new System.Drawing.Size(604, 413);
             this.panel2.ResumeLayout(false);
-            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.picQR)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -95,7 +145,11 @@
 
         private System.Windows.Forms.Label label4;
         private System.Windows.Forms.Panel panel2;
-        private System.Windows.Forms.PictureBox pictureBox3;
+        private System.Windows.Forms.PictureBox picQR;
         private System.Windows.Forms.Button btnGenerate;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label lbPWD;
+        private System.Windows.Forms.Label lbSSID;
     }
 }

+ 14 - 21
ShareWifi/Views/Home.cs

@@ -1,53 +1,46 @@
 using System;
 using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.Data;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Forms;
 using ShareWifi.Utils.Net;
 using ShareWifi.Views.Components;
 using ShareWifi.Model;
+using ShareWifi.Utils;
 
 namespace ShareWifi.Views
 {
-    public partial class Home : UserControl
+    public partial class HomeControl : UserControl
     {
-        WifiModel wifiModel;
-        public Home()
+        WifiModel wifiModel=new WifiModel();
+        public HomeControl()
         {
             InitializeComponent();
         }
 
-        public static Home getInstance()
+        public static HomeControl getInstance()
         {
-            return new Home();
+            return new HomeControl();
 
         }
 
-        public override bool Equals(object obj)
-        {
-            return obj is Home home &&
-                   EqualityComparer<WifiModel>.Default.Equals(wifiModel, home.wifiModel);
-        }
-
         private void btnGenerate_Click(object sender, EventArgs e)
         {
             string ssid = WifiUtils.getSSID();
-            if (ssid != "" || ssid != null)
+            if (ssid != "" && ssid != null)
             {
+                wifiModel.Ssid = ssid;
                 //查找密码
-                string v = WifiUtils.getSSDIPassword(ssid);
+                wifiModel.Pwd = WifiUtils.getSSDIPassword(ssid);
                 //生成二维码
-                btnGenerate.Text = v;
+                QRModel qRModel = QRUtils.genQR(wifiModel.getWifi());
+                picQR.Image = qRModel.QrData;
+
+                lbPWD.Text = wifiModel.Pwd;
+                lbSSID.Text = wifiModel.Ssid;
             }
             else
             {
                 SimpleAlert simpleAlert = SimpleAlert.getInstance();
                 simpleAlert.Show("请链接 WIFI 后才可以分享!");
-
             }
         }
     }