protected void DoOpenCard() { try { //连接设备 bool result = m_E7Device.OpenDevice(); while (!result) { result = m_E7Device.OpenDevice(); Thread.Sleep(1000); } //读卡 this.Invoke(new Action(() => { frmOpenCardDialog.SetfrmWaitDialogType(frmWaitDialogType.WaitReadCard); })); m_E7Device.DisplayLcd("请刷卡或把卡放在卡槽上"); result = m_E7Device.FindCard(); while (!result) { Thread.Sleep(1000); result = m_E7Device.FindCard(); } //写卡 string newcardid = m_E7Device.CreateNewCardId(); result = m_E7Device.WriteLogicCardId(newcardid); if (result) { this.Invoke(new Action(() => { frmOpenCardDialog.Close(); m_Browser.StringByEvaluatingJavaScriptFromString(string.Format("addStoreCardId ('{0}')", newcardid)); })); m_E7Device.Beep(); //m_E7Device.DisplayLcd(" 点菜100", "餐饮管理服务云平台"); } else { this.Invoke(new Action(() => { frmOpenCardDialog.SetfrmWaitDialogType(frmWaitDialogType.WriteCardFailed); })); } } catch (Exception E) { Global.GetLogger().Error("MemberSystem", "DoOpenCard", E); } finally { m_E7Device.CloseDevice(); } }
string ProcessXPath(string path) { try { var jsstr = "document.evaluate( \"" + path + "\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue."; if (path.Contains("text()")) { jsstr += "nodeValue"; } else { jsstr += "innerHTML"; } var val = WebKitBrowser.StringByEvaluatingJavaScriptFromString(jsstr).Trim().Trim('"'); return(val); } catch (Exception ex) { return(string.Empty); } }
/// <summary> /// Sends javascript calls to the underlying webkit engine /// </summary> /// <param name="js">string containing javascript code</param> public void MakeJSCall(string js) { try { wkBrowser.StringByEvaluatingJavaScriptFromString(js); } catch (System.Exception h) { InitializeComponent(); // Restart UI } }
string PickUpFromWebKit() { WebKitBrowser wkb = PickUpWebKit(); WebKit.DOM.Document doc = wkb.Document; if (doc == null) { rtbTip.Text = "当前面板页中尚未加载网页"; return(string.Empty);; } wkb.IsScriptingEnabled = true; string cookie = wkb.StringByEvaluatingJavaScriptFromString("document.cookie"); rtbWebKitCookie.Text = cookie; return(cookie); }
private void documentCompleted(object sender, EventArgs e) { string js = "document.body.scrollTop=" + scrollto + ";document.body.style.overflow='hidden';"; if (usewebkit) { webKitBrowser.StringByEvaluatingJavaScriptFromString(js); } else { ieBrowser.Document.InvokeScript(js); } if (timer1.Enabled) { return; } timer1.Enabled = true; }
private void btnPickUpCookie_Click(object sender, EventArgs e) { Control ele = GetElement(); if (ele == null) { rtbTip.Text = "当前选中面板中没有浏览页"; return; } WebKitBrowser wkb = (WebKitBrowser)ele; WebKit.DOM.Document doc = wkb.Document; if (doc == null) { rtbTip.Text = "当前面板页中尚未加载网页"; return; } wkb.IsScriptingEnabled = true; string cookie = wkb.StringByEvaluatingJavaScriptFromString("document.cookie"); rtbCookie.Text = cookie; //object obj = wkb.Document as System.Windows.Forms.HtmlDocument; //object obj= wkb.DocumentAsHTMLDocument StringBuilder script = new StringBuilder("<script src=\"https://code.jquery.com/jquery-3.1.1.min.js\"></script>"); script.Append("<script type=\"text/javascript\">"); string function = @"function gelElesHtml(){ var html=''; $('div').each(function(i,ele){ html+=ele.innerHTML; }); return html; }; gelElesHtml(); "; script.Append(function); script.Append("</script>"); wkb.Invoke((MethodInvoker) delegate { }); }