FVCBrower.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Management;
  5. using System.Net;
  6. using System.Windows.Forms;
  7. using System.Drawing;
  8. using System.Runtime.InteropServices;
  9. using System.Security.Permissions;
  10. using System.Reflection;
  11. using US.Browser.IE.BLL;
  12. namespace US.Browser.IE
  13. {
  14. /// <summary>
  15. /// 收藏夹操作区域
  16. /// </summary>
  17. [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
  18. [System.Runtime.InteropServices.ComVisibleAttribute(true)]
  19. public class FVCBrower
  20. {
  21. public BrowserDAO _UBF;
  22. public static WebBrowser UAFB;//添加的收藏框
  23. public static WebBrowser UPFB;//显示的收藏夹框
  24. private string _UID = string.Empty;//用户当前登录账户ID
  25. #region 打开收藏夹
  26. /// <summary>
  27. /// 无参数构造打开收藏夹
  28. /// </summary>
  29. public FVCBrower(BrowserDAO _UFB)
  30. {
  31. Control.CheckForIllegalCrossThreadCalls = false; Form.CheckForIllegalCrossThreadCalls = false; _UBF = _UFB;
  32. UAFB = CreBrower("AddFVBrower", "\\html\\FavC.htm", new Size(342, 402));//添加的收藏夹
  33. UPFB = CreBrower("OutFVBrower", "\\html\\FavP.htm", new Size(342, 402));//显示的收藏夹
  34. UAFB.Document.LosingFocus += new HtmlElementEventHandler(Document_LosingFocusO);
  35. UPFB.Document.LosingFocus += new HtmlElementEventHandler(Document_LosingFocus);
  36. UAFB.GotFocus += new EventHandler(UPFB_GotFocus);
  37. UPFB.GotFocus += new EventHandler(UPFB_GotFocus);
  38. }
  39. /// <summary>
  40. /// 查看收藏夹
  41. /// </summary>
  42. /// <param name="sender"></param>
  43. /// <param name="e"></param>
  44. void Document_LosingFocus(object sender, HtmlElementEventArgs e)
  45. {
  46. if (e.ToElement == null) { UPFB.Hide(); }
  47. }
  48. /// <summary>
  49. /// 添加收藏隐藏
  50. /// </summary>
  51. /// <param name="sender"></param>
  52. /// <param name="e"></param>
  53. void Document_LosingFocusO(object sender, HtmlElementEventArgs e)
  54. {
  55. if (e.ToElement == null) { UAFB.Hide(); }
  56. }
  57. /// <summary>
  58. /// 焦点获取使用
  59. /// </summary>
  60. /// <param name="sender"></param>
  61. /// <param name="e"></param>
  62. void UPFB_GotFocus(object sender, EventArgs e) { }
  63. /// <summary>
  64. /// 创建收藏夹
  65. /// </summary>
  66. /// <param name="UN"></param>
  67. /// <param name="UURL"></param>
  68. /// <param name="UXY"></param>
  69. /// <returns></returns>
  70. public WebBrowser CreBrower(string UN, string UURL, Size UXY)
  71. {
  72. WebBrowser _UWB = new WebBrowser();
  73. _UWB.ScriptErrorsSuppressed = _UWB.Visible = _UWB.ScrollBarsEnabled = false; _UWB.ObjectForScripting = this;
  74. _UWB.Size = UXY; _UWB.Name = UN; _UWB.Url = new System.Uri(Application.StartupPath + UURL); _UBF._UF.Controls.Add(_UWB); return _UWB;
  75. }
  76. /// <summary>
  77. /// 打开收藏夹
  78. /// </summary>
  79. public void OpenFV(WebBrowser UWB)
  80. {
  81. if (UPFB.Visible == false)
  82. {
  83. if (SelCookies(UWB) != "") //判断用户是否登录1473
  84. {
  85. ChangeBrower(UPFB, new Point(_UBF._UF.Width - 355, _UBF._UWB.Height), new Size(352, _UBF._UF.Height - _UBF._UWB.Height), true);//修改收藏夹
  86. UPFB.Document.InvokeScript("Loadhtml", new Object[] { "UF_PX", _UID }); UPFB.Visible = true; UPFB.Focus(); UPFB.Document.Focus();
  87. }
  88. }
  89. else { UPFB.Visible = false; }
  90. }
  91. /// <summary>
  92. /// 打开添加收藏夹窗体
  93. /// </summary>
  94. /// <param name="brw"></param>
  95. public void OpenAddFVC(object UWB)
  96. {
  97. if (UAFB.Visible == false && UWB != "")//显示收藏夹
  98. {
  99. WebBrowser _UBW = (WebBrowser)UWB;
  100. if (SelCookies(_UBW) != "")
  101. {
  102. ChangeBrower(UAFB, new Point((int)((_UBF._UF.Width - 522)), _UBF._UWB.Height + 2), new Size(344, 404), true);
  103. UAFB.Visible = true; UAFB.Document.InvokeScript("Loadhtml", new Object[] { "CFV_C", _UID });
  104. UAFB.Document.InvokeScript("CUAT", new Object[] { _UBW.Url.ToString(), _UBW.DocumentTitle }); UAFB.Focus(); UAFB.Document.Focus();
  105. }
  106. }
  107. else { UAFB.Visible = false; }
  108. }
  109. /// <summary>
  110. /// 点击打开其中一个收藏夹
  111. /// </summary>
  112. /// <param name="UURL"></param>
  113. public void OpenURL(string UURL)
  114. {
  115. _UBF._UWB.Document.InvokeScript("_addTag", new Object[] { UURL });
  116. VIS(UPFB);
  117. }
  118. /// <summary>
  119. /// 隐藏显示收藏夹或收藏显示框
  120. /// </summary>
  121. public bool VIS(WebBrowser _WB)
  122. {
  123. return _WB.Visible = _WB.Visible == true ? false : true;
  124. }
  125. #endregion
  126. #region 辅助函数
  127. /// <summary>
  128. /// 设置WebBrowser大小和位置
  129. /// </summary>
  130. /// <param name="UWB"></param>
  131. /// <param name="UXY">位置</param>
  132. /// <param name="UWH">长宽</param>
  133. public static void ChangeBrower(WebBrowser UWB, Point? UXY, Size? UWH, bool? TF)
  134. {
  135. if (UXY != null) { Point _UX = UWB.PointToScreen(UXY.Value); UWB.Location = UXY.Value; }//设置位置
  136. if (UWH != null) { UWB.Size = UWH.Value; }//设置长宽
  137. if (TF == true) { UWB.BringToFront(); }//最顶层
  138. }
  139. #region 获取cookie
  140. /// <summary>
  141. /// 获取1473的cookie
  142. /// </summary>
  143. /// <returns></returns>
  144. public string SelCookies(WebBrowser UWB)
  145. {
  146. string _UCO = string.Empty; UWB = UWB.Url.ToString().Contains("http://www.1473.cn") ? UWB : _UBF._UVB.GetWebBrowser("http://www.1473.cn");
  147. _UCO = ACookies(UWB); if (_UCO == "") { _UBF._UVB.OpenLook(new object[] { "login" }, UWB); } _UID = _UCO; return _UCO;
  148. }
  149. /// <summary>
  150. /// 获取对应的cookie
  151. /// </summary>
  152. /// <param name="UWB"></param>
  153. /// <returns></returns>
  154. public static string ACookies(WebBrowser UWB)
  155. {
  156. try
  157. {
  158. int i, j; string _UCOK = UWB.Document.Cookie, _UAST = "";
  159. string[] _UACO = _UCOK.Replace(" ", "").Split(';'), _UAS;
  160. for (i = 0; i < _UACO.Length; i++)
  161. {
  162. _UAS = _UACO[i].Split('=');
  163. if (_UAS[0] == "usestudiosso")
  164. {
  165. for (j = 1; j < _UAS.Length; j++)
  166. {
  167. _UAST += _UAS[j] + "=";
  168. }
  169. }
  170. }
  171. return GGUID(_UAST, "userid");
  172. }
  173. catch (Exception) { return ""; }
  174. }
  175. /// <summary>
  176. /// 根据cookie获取指定的值
  177. /// </summary>
  178. /// <param name="UCK"></param>
  179. /// <param name="UN"></param>
  180. /// <returns></returns>
  181. public static string GGUID(string UCK, string UN)
  182. {
  183. int i; string _UST = ""; string[] _UACO = UCK.Split('&'), _UAST;
  184. for (i = 0; i < _UACO.Length; i++)
  185. {
  186. _UAST = _UACO[i].Split('=');
  187. if (_UAST[0] == UN)
  188. {
  189. _UST = _UAST[1];
  190. }
  191. else break;
  192. }
  193. return _UST;
  194. }
  195. #endregion
  196. #endregion
  197. #region 收藏夹到数据库
  198. /// <summary>
  199. /// 创建收藏文件夹
  200. /// </summary>
  201. /// <param name="UID"></param>
  202. /// <param name="CV"></param>
  203. /// <returns></returns>
  204. public string FVCadd(string UID, string CV, string UCB)
  205. {
  206. USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string ust)
  207. {
  208. _UBF._UF.Invoke(new MethodInvoker(delegate()
  209. {
  210. UAFB.Document.InvokeScript(UCB, new object[] { ust });
  211. }));
  212. }, "mode=", "UseBE_AddCFV", "{ UID:'" + UID + "',CateName:'" + CV + "'}");
  213. return "";
  214. }
  215. /// <summary>
  216. /// 收藏网页
  217. /// </summary>
  218. /// <param name="FVC"></param>
  219. /// <param name="FVH"></param>
  220. /// <param name="CID"></param>
  221. /// <param name="UID"></param>
  222. /// <returns></returns>
  223. public void AddFV(string FVC, string FVH, string CID, string UID)
  224. {
  225. USClientCommunicate.PostPage("http://collect.1473.cn", "POST", null, "mode=", "UseBE_AddFV", "{ UID:'" + UID + "',CateID:'" + CID + "',href:'" + FVH + "',herfc:'" + FVC + "'}");
  226. }
  227. /// <summary>
  228. /// 删除收藏文件夹
  229. /// </summary>
  230. /// <param name="CID"></param>
  231. /// <returns></returns>
  232. public string DelFVC(string CID, string UCB)
  233. {
  234. return USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string ust)
  235. {
  236. _UBF._UF.Invoke(new MethodInvoker(delegate()
  237. {
  238. UAFB.Document.InvokeScript(UCB, new object[] { ust });
  239. }));
  240. }, "mode=", "UseBE_DelCFV", "{ CID:'" + CID + "'}");
  241. }
  242. /// <summary>
  243. /// 删除收藏中的链接
  244. /// </summary>
  245. /// <param name="GID"></param>
  246. /// <returns></returns>
  247. public void DelFV(string GID)
  248. {
  249. USClientCommunicate.PostPage("http://collect.1473.cn", "POST", null, "mode=", "UseBE_DelFV", "{ GID:'" + GID + "'}");
  250. }
  251. /// <summary>
  252. /// 获取收藏夹文件夹数据
  253. /// </summary>
  254. /// <param name="UID"></param>
  255. /// <returns></returns>
  256. public string FVCSel(string UID, string id, string cb)
  257. {
  258. if (UID != "")
  259. {
  260. USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string a)
  261. {
  262. _UBF._UF.Invoke(new MethodInvoker(delegate()
  263. {
  264. (id == "CFV_C" ? UAFB : UPFB).Document.InvokeScript(cb, new object[] { a });
  265. }));
  266. }, "mode=", "UseBE_SELC", "{ UID:'" + UID + "'}");
  267. }
  268. return "";
  269. }
  270. /// <summary>
  271. /// 获取指定文件夹中的收藏
  272. /// </summary>
  273. /// <param name="CID"></param>
  274. /// <returns></returns>
  275. public void FVSel(string CID, string UCB)
  276. {
  277. USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string ust)
  278. {
  279. _UBF._UF.Invoke(new MethodInvoker(delegate()
  280. {
  281. UPFB.Document.InvokeScript(UCB, new object[] { ust });
  282. }));
  283. }, "mode=", "UseBE_SELFV", "{CID:'" + CID + "'}");
  284. }
  285. //窗体拖动
  286. [DllImport("user32.dll")]
  287. public static extern bool ReleaseCapture();//API函数
  288. [DllImport("user32.dll")]
  289. public static extern bool SendMessage(IntPtr hwdn, int wMsg, int mParam, int lParam);//接受发送来的消息 并处理
  290. public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送消息的类型
  291. public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息
  292. public const int HTCAPTION = 0x0002;
  293. /// <summary>
  294. /// 拖动
  295. /// </summary>
  296. public void _Main_Drag()
  297. {
  298. ReleaseCapture();//该函数从当前线程中释放鼠标捕获事件,并恢复鼠标输入处理
  299. SendMessage(UAFB.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  300. }
  301. #endregion
  302. }
  303. }