StaticClass.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Management;
  9. using US.Browser.IE.BLL;
  10. using System.Threading;
  11. using System.Runtime.InteropServices;
  12. using System.Drawing.Imaging;
  13. using System.IO;
  14. using System.Diagnostics;
  15. using System.Configuration;
  16. using System.Web.Configuration;
  17. using Shell32;
  18. namespace US.Browser.IE
  19. {
  20. /// <summary>
  21. /// 应用程序
  22. /// </summary>
  23. public partial class StaticClass : Form
  24. {
  25. #region 变量区域
  26. public static StaticClass _USE; //应用启动区域
  27. RespondWeb _UVE; //webbrower开发功能区
  28. USMain _UM;
  29. private static Popup _UPE;//广告页面
  30. public static string _UST;//启动程序的方式
  31. private Respond_setting _URE;//浏览器系统设置功能区域
  32. private static Thread th = null;//线程
  33. public static string ver = FileVersionInfo.GetVersionInfo(System.Windows.Forms.Application.ExecutablePath).FileVersion;//当前版本
  34. public static News _UNE;//消息
  35. public static string UCON = System.Configuration.ConfigurationSettings.AppSettings["type"];//Config设置
  36. static System.Windows.Forms.Timer _UDT = null; static Icon ic; static Icon[] aic; static string icoscr = string.Empty; static bool tf;
  37. public static MouseEventHandler _ume;
  38. #endregion
  39. #region 生成应用程序
  40. /// <summary>
  41. /// 应用程序初始化
  42. /// </summary>
  43. /// <param name="runstr"></param>
  44. /// <returns></returns>
  45. public static StaticClass getI(string UST)
  46. {
  47. _USE = new StaticClass(); _UST = UST;
  48. _USE.StaticClass_Load(); return _USE;
  49. }
  50. /// <summary>
  51. /// 多窗口
  52. /// </summary>
  53. /// <param name="UTP"></param>
  54. /// <returns></returns>
  55. public static StaticClass Restart(string UTP)
  56. {
  57. return StaticClass.getI(UTP);
  58. }
  59. /// <summary>
  60. /// 实例化应用程序
  61. /// </summary>
  62. /// <returns></returns>
  63. public static StaticClass getInstance()
  64. {
  65. if (BLL.USIE.isnet())
  66. {
  67. if (_USE == null) { _USE = new StaticClass(); }//生成任务托盘
  68. else { _USE.CreateMain(false); }
  69. return _USE;
  70. }
  71. return null;
  72. }
  73. /// <summary>
  74. /// 无参数构造
  75. /// </summary>
  76. public StaticClass()
  77. {
  78. InitializeComponent(); //实例化右键菜单
  79. Control.CheckForIllegalCrossThreadCalls = false;
  80. }
  81. /// <summary>
  82. /// 托盘加载完毕启动
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. private void StaticClass_Load()
  87. {
  88. bool _UTF = _UST.IndexOf("-background") != -1; _URE = new Respond_setting(); //浏览器设置区域
  89. this._UM = CreateMain(_UTF); _UPE = new Popup(_UM); UpdateCue.NewUpCF(_USE); _UNE = new News(_UM._USY);
  90. _UVE = new RespondWeb(null, _UM._USY); System.Windows.Forms.Timer _UTM = new System.Windows.Forms.Timer();
  91. _UTM.Tick += new EventHandler(delegate(object sender, EventArgs e) { _UTM.Stop(); _UTM.Dispose(); _UPE.Show(); });
  92. _UTM.Interval = 600000; _UTM.Start();
  93. }
  94. /// <summary>
  95. /// 创建主窗体
  96. /// </summary>
  97. /// <returns></returns>
  98. public USMain CreateMain(bool UTF)
  99. {
  100. USMain _UM = new USMain();
  101. System.Windows.Forms.Timer _UTM = new System.Windows.Forms.Timer(); _UTM.Tick += new EventHandler(delegate(object sender, EventArgs e) //窗体加载等待
  102. {
  103. aic = new Icon[] { new System.Drawing.Icon(Application.StartupPath + "//logo.ico"), new System.Drawing.Icon(Application.StartupPath + "//head.ico") };
  104. StaticClass.postUseBE(); _UTM.Stop(); _UTM.Dispose(); _UTM = null; if (!UTF && BLL.USIE.isnet()) { _UM.Show(); }
  105. });
  106. _UTM.Interval = 1; _UTM.Start(); return _UM;
  107. }
  108. /// <summary>
  109. /// 浏览器关闭
  110. /// </summary>
  111. /// <param name="sender"></param>
  112. /// <param name="e"></param>
  113. void StaticClass_Disposed(object sender, System.EventArgs e)
  114. {
  115. Process _UPE = System.Diagnostics.Process.GetCurrentProcess();
  116. BLL.WindowHWND.freem(); this.USIcon.Dispose(); this.IconMenu.Dispose();
  117. _UPE.Kill(); _UPE.Close(); _UPE.Dispose();
  118. }
  119. #endregion
  120. #region 托盘闪烁使用
  121. /// <summary>
  122. /// 闪烁
  123. /// </summary>
  124. public static void _twstart(string img, string tf, string ue, WebBrowser wb, RespondWeb rf)
  125. {
  126. sjxxs(tf, ue, wb, rf);
  127. if (_UDT == null) { icoscr = img; _traytwinkle(img); }
  128. else if (ic == null || icoscr != img) { if (ic != null) { ic.Dispose(); } icoscr = img; ic = geticon(img); }
  129. }
  130. /// <summary>
  131. /// 关闭闪烁
  132. /// </summary>
  133. public static void _twstop()
  134. {
  135. if (_UDT != null) { _UDT.Stop(); _UDT.Dispose(); } _UDT = null; icoscr = string.Empty;
  136. if (_USE.USIcon.Icon != aic[0]) { _USE.USIcon.Icon = aic[0]; } if (ic != null) { ic.Dispose(); ic = null; }
  137. }
  138. /// <summary>
  139. /// 闪烁开始
  140. /// </summary>
  141. /// <param name="img"></param>
  142. public static void _traytwinkle(object img)
  143. {
  144. _UDT = new System.Windows.Forms.Timer(); tf = true; string iimg = (string)img;
  145. if (ic != null) { ic.Dispose(); } ic = geticon(iimg); ic = ic == null ? aic[1] : ic; _USE.USIcon.Text = "查看消息";
  146. _UDT.Tick += new EventHandler(_UDT_Tick); _UDT.Interval = 800; _UDT.Start();
  147. }
  148. /// <summary>
  149. /// 闪烁变化
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. static void _UDT_Tick(object sender, EventArgs e)
  154. {
  155. Icon _ic = tf ? ic : aic[0];
  156. if (_ic == null) { _twstop(); }
  157. else { _USE.USIcon.Icon = _ic; tf = !tf; }
  158. }
  159. /// <summary>
  160. /// 闪烁按钮添加事件
  161. /// </summary>
  162. public static void sjxxs(string tf, string ue, WebBrowser wb, RespondWeb rf)
  163. {
  164. NotifyIcon icn = StaticClass._USE.USIcon;
  165. icn.MouseClick -= _ume; //取消相同事件
  166. _ume = new MouseEventHandler(delegate(object sender, MouseEventArgs me)
  167. {
  168. if (me.Button == MouseButtons.Left)
  169. {
  170. icn.MouseClick -= _ume; icn.Text = "云端";
  171. rf.OpenLook(new object[] { tf, ue }, wb); StaticClass._twstop();
  172. }
  173. });
  174. icn.MouseClick += _ume; //添加事件
  175. }
  176. /// <summary>
  177. /// 获取icon
  178. /// </summary>
  179. /// <param name="img"></param>
  180. /// <returns></returns>
  181. public static Icon geticon(string img)
  182. {
  183. Icon ic = null;
  184. try
  185. {
  186. System.Net.HttpWebRequest webrq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(img);
  187. System.Net.HttpWebResponse webres = (System.Net.HttpWebResponse)webrq.GetResponse();
  188. if (webres.StatusCode == System.Net.HttpStatusCode.OK && webres.ContentLength > 0)
  189. {
  190. using (Stream stream = webres.GetResponseStream())
  191. {
  192. using (Image image = Image.FromStream(stream))
  193. {
  194. using (Bitmap bmp = new Bitmap(image, new Size(16, 16)))
  195. {
  196. ic = Icon.FromHandle(bmp.GetHicon());
  197. bmp.Dispose();
  198. }
  199. image.Clone(); image.Dispose();
  200. }
  201. stream.Close(); stream.Dispose();
  202. }
  203. }
  204. webrq.Abort(); webres.Close();
  205. }
  206. catch (Exception e) { BLL.WindowHWND.freem(); }
  207. return ic;
  208. }
  209. #endregion
  210. #region 托盘点击
  211. /// <summary>
  212. /// 点击查看
  213. /// </summary>
  214. public void Show_Click()
  215. {
  216. if (BLL.USIE.isnet())
  217. {
  218. int i; List<Form> _UFL = USMain._UFL; Form _UF; this_sfb();
  219. for (i = 0; i < _UFL.Count; i++)
  220. {
  221. _UF = _UFL[i]; if (_UF.Visible == false) { _UF.Show(); } this._UVE.fouscwindow();
  222. if (_UF.WindowState == FormWindowState.Minimized) { _UF.WindowState = FormWindowState.Normal; }
  223. }
  224. }
  225. //else { MessageBox.Show("请连接网络!"); }
  226. }
  227. /// <summary>
  228. /// 窗体添加
  229. /// </summary>
  230. public void this_sfb()
  231. {
  232. if (US.Browser.IE.USMain._UFL.Count > 0)
  233. {
  234. USMain USM = (USMain)US.Browser.IE.USMain._UFL[0];
  235. List<WebBrowser> L_WB = USM._USY._UBL;
  236. if (L_WB.Count <= 0)
  237. {
  238. WebBrowser _UWB = USM._USY._UWB;
  239. _UWB.Document.InvokeScript("_addTag", new Object[] { "http://www.1473.cn" });
  240. }
  241. }
  242. }
  243. #region 右键菜单功能区域
  244. /// <summary>
  245. /// 显示窗体
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void IconMenuShow_Click(object sender, EventArgs e)
  250. {
  251. Show_Click();
  252. }
  253. /// <summary>
  254. /// 点击查看云端
  255. /// </summary>
  256. /// <param name="sender"></param>
  257. /// <param name="e"></param>
  258. private void USIcon_MouseClick(object sender, MouseEventArgs e)
  259. {
  260. if (e.Button == MouseButtons.Left) { Show_Click(); }
  261. }
  262. /// <summary>
  263. /// 查看设置
  264. /// </summary>
  265. /// <param name="sender"></param>
  266. /// <param name="e"></param>
  267. private void menuSetting_Click(object sender, EventArgs e)
  268. {
  269. _URE.SetProxy();
  270. }
  271. /// <summary>
  272. /// 关闭浏览器
  273. /// </summary>
  274. /// <param name="sender"></param>
  275. /// <param name="e"></param>
  276. public void exit_Click(object sender, EventArgs e)
  277. {
  278. StaticClass_Disposed(sender, e);
  279. }
  280. /// <summary>
  281. /// 消息提醒
  282. /// </summary>
  283. /// <param name="sender"></param>
  284. /// <param name="e"></param>
  285. void NS_Click(object sender, System.EventArgs e)
  286. {
  287. if (BLL.USIE.isnet()) { StaticClass._UNE.init(true); }
  288. }
  289. /// <summary>
  290. /// 弹出校园资讯
  291. /// </summary>
  292. /// <param name="sender"></param>
  293. /// <param name="e"></param>
  294. void zx_Click(object sender, System.EventArgs e)
  295. {
  296. if (BLL.USIE.isnet()) { _UPE.ZJTC(true); }
  297. }
  298. /// <summary>
  299. /// 更新检查
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void Newst_Click(object sender, EventArgs e)
  304. {
  305. if (BLL.USIE.isnet()) { if (!UpdateCue._UDE.showp(false)) { MessageBox.Show("版本已为最新, 感谢支持。"); }; }
  306. }
  307. /// <summary>
  308. /// 意见反馈
  309. /// </summary>
  310. /// <param name="sender"></param>
  311. /// <param name="e"></param>
  312. private void Feedback_Click(object sender, EventArgs e)
  313. {
  314. if (BLL.USIE.isnet()) { _UVE.OpenLook(new object[] { "pb", "['3c779543-bc1a-4851-af22-af9ba97a5f33']" }, null); }
  315. }
  316. #endregion
  317. #endregion
  318. #region 使用功能区域
  319. /// <summary>
  320. /// 关闭浏览器
  321. /// </summary>
  322. /// <param name="form"></param>
  323. public static void CloseSoft(Form UF)
  324. {
  325. List<Form> _UF = USMain._UFL; _UF.Remove(UF); UF.Dispose();
  326. if (_UF.Count == 0) { _USE.Close(); _USE.Dispose(); System.Environment.Exit(0); }
  327. }
  328. /// <summary>
  329. /// 隐藏图标
  330. /// </summary>
  331. /// <param name="i"></param>
  332. protected override void SetVisibleCore(bool ITF)
  333. {
  334. base.SetVisibleCore(false);
  335. }
  336. #endregion
  337. #region 获取数据
  338. /// <summary>
  339. /// 添加装机用户信息
  340. /// </summary>
  341. public static void postUseBE()
  342. {
  343. string _UOS = getUseOS(); string[] _UIP = getUseMac();
  344. try { USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string a) { if (a == "") { USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string c) { }, "mode=", "UseBE_IN", "{ UIP:'" + _UIP[1] + "',UsOS:'" + _UOS + "',UsMac:'" + _UIP[0] + "'}"); } }, "mode=", "UseBE_SEL", "{ UsMac:'" + _UIP[0] + "'}").Replace("[", "").Replace("]", ""); }
  345. catch (Exception e) { return; }
  346. }
  347. /// <summary>
  348. /// 获取用户操作系统信息
  349. /// </summary>
  350. /// <returns></returns>
  351. public static string getUseOS()
  352. {
  353. return System.Environment.OSVersion.VersionString;
  354. }
  355. /// <summary>
  356. /// 获取IP信息
  357. /// </summary>
  358. /// <returns></returns>
  359. public static string[] getUseMac()
  360. {
  361. ManagementClass _UMC = new ManagementClass("Win32_NetworkAdapterConfiguration");//获取客户端网络信息
  362. ManagementObjectCollection _UNI = _UMC.GetInstances(); string[] _UNIP = new string[2];
  363. foreach (ManagementObject i in _UNI)
  364. {
  365. if (Convert.ToBoolean(i["ipEnabled"]) == true) { _UNIP[0] = i["MacAddress"].ToString(); _UNIP[1] = (i["IPAddress"] as string[])[0]; }
  366. }
  367. return _UNIP;
  368. }
  369. #endregion
  370. }
  371. }