Home.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using ShareWifi.Utils.Net;
  5. using ShareWifi.Views.Components;
  6. using ShareWifi.Model;
  7. using ShareWifi.Utils;
  8. namespace ShareWifi.Views
  9. {
  10. public partial class HomeControl : UserControl
  11. {
  12. WifiModel wifiModel;
  13. public HomeControl()
  14. {
  15. InitializeComponent();
  16. }
  17. public static HomeControl getInstance()
  18. {
  19. return new HomeControl();
  20. }
  21. private void btnGenerate_Click(object sender, EventArgs e)
  22. {
  23. if (showWifiinfo())
  24. {
  25. //生成二维码
  26. QRModel qRModel = QRUtils.genQR(wifiModel.getWifi());
  27. picQR.Image = qRModel.QrData;
  28. }
  29. else
  30. {
  31. SimpleAlert simpleAlert = SimpleAlert.getInstance();
  32. simpleAlert.Show("请链接 WIFI!");
  33. lbPWD.Text = "null";
  34. lbSSID.Text = "null";
  35. picQR.Image = null;
  36. }
  37. }
  38. public bool showWifiinfo()
  39. {
  40. string ssid = WifiUtils.getSSID();
  41. if (ssid != "" && ssid != null)
  42. {
  43. wifiModel = new WifiModel();
  44. wifiModel.Ssid = ssid;
  45. //查找密码
  46. wifiModel.Pwd = WifiUtils.getSSDIPassword(ssid);
  47. lbPWD.Text = wifiModel.Pwd;
  48. lbSSID.Text = wifiModel.Ssid;
  49. return true;
  50. }
  51. else
  52. {
  53. SimpleAlert simpleAlert = SimpleAlert.getInstance();
  54. simpleAlert.Show("请链接 WIFI!");
  55. return false;
  56. }
  57. }
  58. private void HomeControl_Load(object sender, EventArgs e)
  59. {
  60. showWifiinfo();
  61. }
  62. }
  63. }