using System; using System.Collections.Generic; using System.Text; using System.Management; using System.Net; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; using System.Security.Permissions; using System.Reflection; using US.Browser.IE.BLL; namespace US.Browser.IE { /// /// 收藏夹操作区域 /// [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [System.Runtime.InteropServices.ComVisibleAttribute(true)] public class FVCBrower { public BrowserDAO _UBF; public static WebBrowser UAFB;//添加的收藏框 public static WebBrowser UPFB;//显示的收藏夹框 private string _UID = string.Empty;//用户当前登录账户ID #region 打开收藏夹 /// /// 无参数构造打开收藏夹 /// public FVCBrower(BrowserDAO _UFB) { Control.CheckForIllegalCrossThreadCalls = false; Form.CheckForIllegalCrossThreadCalls = false; _UBF = _UFB; UAFB = CreBrower("AddFVBrower", "\\html\\FavC.htm", new Size(342, 402));//添加的收藏夹 UPFB = CreBrower("OutFVBrower", "\\html\\FavP.htm", new Size(342, 402));//显示的收藏夹 UAFB.Document.LosingFocus += new HtmlElementEventHandler(Document_LosingFocusO); UPFB.Document.LosingFocus += new HtmlElementEventHandler(Document_LosingFocus); UAFB.GotFocus += new EventHandler(UPFB_GotFocus); UPFB.GotFocus += new EventHandler(UPFB_GotFocus); } /// /// 查看收藏夹 /// /// /// void Document_LosingFocus(object sender, HtmlElementEventArgs e) { if (e.ToElement == null) { UPFB.Hide(); } } /// /// 添加收藏隐藏 /// /// /// void Document_LosingFocusO(object sender, HtmlElementEventArgs e) { if (e.ToElement == null) { UAFB.Hide(); } } /// /// 焦点获取使用 /// /// /// void UPFB_GotFocus(object sender, EventArgs e) { } /// /// 创建收藏夹 /// /// /// /// /// public WebBrowser CreBrower(string UN, string UURL, Size UXY) { WebBrowser _UWB = new WebBrowser(); _UWB.ScriptErrorsSuppressed = _UWB.Visible = _UWB.ScrollBarsEnabled = false; _UWB.ObjectForScripting = this; _UWB.Size = UXY; _UWB.Name = UN; _UWB.Url = new System.Uri(Application.StartupPath + UURL); _UBF._UF.Controls.Add(_UWB); return _UWB; } /// /// 打开收藏夹 /// public void OpenFV(WebBrowser UWB) { if (UPFB.Visible == false) { if (SelCookies(UWB) != "") //判断用户是否登录1473 { ChangeBrower(UPFB, new Point(_UBF._UF.Width - 355, _UBF._UWB.Height), new Size(352, _UBF._UF.Height - _UBF._UWB.Height), true);//修改收藏夹 UPFB.Document.InvokeScript("Loadhtml", new Object[] { "UF_PX", _UID }); UPFB.Visible = true; UPFB.Focus(); UPFB.Document.Focus(); } } else { UPFB.Visible = false; } } /// /// 打开添加收藏夹窗体 /// /// public void OpenAddFVC(object UWB) { if (UAFB.Visible == false && UWB != "")//显示收藏夹 { WebBrowser _UBW = (WebBrowser)UWB; if (SelCookies(_UBW) != "") { ChangeBrower(UAFB, new Point((int)((_UBF._UF.Width - 522)), _UBF._UWB.Height + 2), new Size(344, 404), true); UAFB.Visible = true; UAFB.Document.InvokeScript("Loadhtml", new Object[] { "CFV_C", _UID }); UAFB.Document.InvokeScript("CUAT", new Object[] { _UBW.Url.ToString(), _UBW.DocumentTitle }); UAFB.Focus(); UAFB.Document.Focus(); } } else { UAFB.Visible = false; } } /// /// 点击打开其中一个收藏夹 /// /// public void OpenURL(string UURL) { _UBF._UWB.Document.InvokeScript("_addTag", new Object[] { UURL }); VIS(UPFB); } /// /// 隐藏显示收藏夹或收藏显示框 /// public bool VIS(WebBrowser _WB) { return _WB.Visible = _WB.Visible == true ? false : true; } #endregion #region 辅助函数 /// /// 设置WebBrowser大小和位置 /// /// /// 位置 /// 长宽 public static void ChangeBrower(WebBrowser UWB, Point? UXY, Size? UWH, bool? TF) { if (UXY != null) { Point _UX = UWB.PointToScreen(UXY.Value); UWB.Location = UXY.Value; }//设置位置 if (UWH != null) { UWB.Size = UWH.Value; }//设置长宽 if (TF == true) { UWB.BringToFront(); }//最顶层 } #region 获取cookie /// /// 获取1473的cookie /// /// public string SelCookies(WebBrowser UWB) { string _UCO = string.Empty; UWB = UWB.Url.ToString().Contains("http://www.1473.cn") ? UWB : _UBF._UVB.GetWebBrowser("http://www.1473.cn"); _UCO = ACookies(UWB); if (_UCO == "") { _UBF._UVB.OpenLook(new object[] { "login" }, UWB); } _UID = _UCO; return _UCO; } /// /// 获取对应的cookie /// /// /// public static string ACookies(WebBrowser UWB) { try { int i, j; string _UCOK = UWB.Document.Cookie, _UAST = ""; string[] _UACO = _UCOK.Replace(" ", "").Split(';'), _UAS; for (i = 0; i < _UACO.Length; i++) { _UAS = _UACO[i].Split('='); if (_UAS[0] == "usestudiosso") { for (j = 1; j < _UAS.Length; j++) { _UAST += _UAS[j] + "="; } } } return GGUID(_UAST, "userid"); } catch (Exception) { return ""; } } /// /// 根据cookie获取指定的值 /// /// /// /// public static string GGUID(string UCK, string UN) { int i; string _UST = ""; string[] _UACO = UCK.Split('&'), _UAST; for (i = 0; i < _UACO.Length; i++) { _UAST = _UACO[i].Split('='); if (_UAST[0] == UN) { _UST = _UAST[1]; } else break; } return _UST; } #endregion #endregion #region 收藏夹到数据库 /// /// 创建收藏文件夹 /// /// /// /// public string FVCadd(string UID, string CV, string UCB) { USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string ust) { _UBF._UF.Invoke(new MethodInvoker(delegate() { UAFB.Document.InvokeScript(UCB, new object[] { ust }); })); }, "mode=", "UseBE_AddCFV", "{ UID:'" + UID + "',CateName:'" + CV + "'}"); return ""; } /// /// 收藏网页 /// /// /// /// /// /// public void AddFV(string FVC, string FVH, string CID, string UID) { USClientCommunicate.PostPage("http://collect.1473.cn", "POST", null, "mode=", "UseBE_AddFV", "{ UID:'" + UID + "',CateID:'" + CID + "',href:'" + FVH + "',herfc:'" + FVC + "'}"); } /// /// 删除收藏文件夹 /// /// /// public string DelFVC(string CID, string UCB) { return USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string ust) { _UBF._UF.Invoke(new MethodInvoker(delegate() { UAFB.Document.InvokeScript(UCB, new object[] { ust }); })); }, "mode=", "UseBE_DelCFV", "{ CID:'" + CID + "'}"); } /// /// 删除收藏中的链接 /// /// /// public void DelFV(string GID) { USClientCommunicate.PostPage("http://collect.1473.cn", "POST", null, "mode=", "UseBE_DelFV", "{ GID:'" + GID + "'}"); } /// /// 获取收藏夹文件夹数据 /// /// /// public string FVCSel(string UID, string id, string cb) { if (UID != "") { USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string a) { _UBF._UF.Invoke(new MethodInvoker(delegate() { (id == "CFV_C" ? UAFB : UPFB).Document.InvokeScript(cb, new object[] { a }); })); }, "mode=", "UseBE_SELC", "{ UID:'" + UID + "'}"); } return ""; } /// /// 获取指定文件夹中的收藏 /// /// /// public void FVSel(string CID, string UCB) { USClientCommunicate.PostPage("http://collect.1473.cn", "POST", delegate(string ust) { _UBF._UF.Invoke(new MethodInvoker(delegate() { UPFB.Document.InvokeScript(UCB, new object[] { ust }); })); }, "mode=", "UseBE_SELFV", "{CID:'" + CID + "'}"); } //窗体拖动 [DllImport("user32.dll")] public static extern bool ReleaseCapture();//API函数 [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwdn, int wMsg, int mParam, int lParam);//接受发送来的消息 并处理 public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送消息的类型 public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息 public const int HTCAPTION = 0x0002; /// /// 拖动 /// public void _Main_Drag() { ReleaseCapture();//该函数从当前线程中释放鼠标捕获事件,并恢复鼠标输入处理 SendMessage(UAFB.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } #endregion } }