Main.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using CefSharp;
  2. using CefSharp.WinForms;
  3. using efunbox_xyyf_windows.baseMvp;
  4. using efunbox_xyyf_windows.bean;
  5. using efunbox_xyyf_windows.contract;
  6. using efunbox_xyyf_windows.cusview;
  7. using efunbox_xyyf_windows.presenter;
  8. using efunbox_xyyf_windows.util;
  9. using Newtonsoft.Json;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Diagnostics;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Net;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows.Forms;
  21. namespace efunbox_xyyf_windows
  22. {
  23. public delegate void ChangeWebUrl(string url);
  24. public delegate void WebViewReload();
  25. public delegate string getWebUrl();
  26. public partial class Main : BaseForm<MainPresenter>, MainContract.IView
  27. {
  28. /*
  29. * debug使用到的方法
  30. * **/
  31. public static ChangeWebUrl changeWebUrl;
  32. public static WebViewReload webviewReload;
  33. public static getWebUrl getWebNowUrl;
  34. //webview
  35. ChromiumWebBrowser webview;
  36. public Main()
  37. {
  38. InitializeComponent();
  39. this.FormClosing += Form1_FormClosing;
  40. }
  41. //窗体加载
  42. private void Form1_Load(object sender, EventArgs e)
  43. {
  44. mPresenter = new MainPresenter();
  45. mPresenter.attachView(this);
  46. changeWebUrl = ChangeWebUrl;
  47. webviewReload = WebViewReload;
  48. getWebNowUrl = getWebUrl;
  49. }
  50. //窗体第一次显示
  51. private void Form1_Shown(object sender, EventArgs e)
  52. {
  53. loadingProgress.Value = 20;
  54. mPresenter.LenvAutoLogin();
  55. }
  56. /*
  57. * 窗体关闭
  58. * **/
  59. private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
  60. {
  61. //阻止关闭
  62. //e.Cancel = true;
  63. //调用js方法通知网页用户想关闭应用
  64. //webview.GetBrowser().MainFrame.EvaluateScriptAsync("FormClosing()");
  65. //JS会回调JsInterface里面的exitApp()方法进行退出
  66. Cef.Shutdown();
  67. if (webview != null)
  68. {
  69. webview.Dispose();
  70. }
  71. }
  72. public string getWebUrl()
  73. {
  74. return mPresenter.getWebUrl();
  75. }
  76. public ChromiumWebBrowser getWebView()
  77. {
  78. try
  79. {
  80. return webview;
  81. }
  82. catch (Exception ex)
  83. {
  84. Console.WriteLine(ex.Message);
  85. return null;
  86. }
  87. }
  88. public void getLenvIdSuccess()
  89. {
  90. loadingProgress.Value = 100;
  91. loadingProgress.Visible = false;
  92. //都获取到信息了,初始化webview
  93. webview = new ChromiumWebBrowser();
  94. mPresenter.initWebView(webview);
  95. this.Controls.Add(webview);
  96. showDialog();
  97. }
  98. public ProgressBar getLoadingBar()
  99. {
  100. return loadingProgress;
  101. }
  102. /*
  103. *
  104. * 以下是测试方法,DebugUtilForm窗口调用
  105. *
  106. * **/
  107. public void showDialog()
  108. {
  109. //测试用
  110. DialogResult MsgBoxResult;//设置对话框的返回值
  111. MsgBoxResult = System.Windows.Forms.MessageBox.Show("打开debug操作窗?", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);//定义对话框的按钮式样
  112. if (MsgBoxResult.ToString() == "Yes")//如果对话框的返回值是YES(按"Y"按钮)
  113. {
  114. DebugUtilForm debugUtilForm = new DebugUtilForm();
  115. debugUtilForm.Show(this);
  116. }
  117. if (MsgBoxResult.ToString() == "No")//如果对话框的返回值是NO(按"N"按钮)
  118. {
  119. //选择了No,继续
  120. }
  121. }
  122. public void ChangeWebUrl(string url)
  123. {
  124. webview.LoadUrl(url);
  125. }
  126. public void WebViewReload()
  127. {
  128. webview.Reload();
  129. }
  130. }
  131. }