// GetElement public mshtml.IHTMLElement GetElement(mshtml.HTMLWindow2 fra, string tagName, string keyName, string keyTxt) { mshtml.IHTMLElementCollection eles = default(mshtml.IHTMLElementCollection); mshtml.HTMLDocument Doc = default(mshtml.HTMLDocument); Doc = (mshtml.HTMLDocument)fra.document; eles = Doc.getElementsByTagName(tagName); foreach (mshtml.IHTMLElement ele in eles) { try { if (keyName == "innertext") { if (ele.innerText == keyTxt) { return(ele); } } else { if (ele.getAttribute(keyName).ToString() == keyTxt) { return(ele); } } } catch (Exception) { } } return(null); }
public IEElement(Browser browser, mshtml.IHTMLElement Element) { Browser = browser; RawElement = Element; className = Element.className; id = Element.id; tagName = Element.tagName.ToLower(); if (tagName == "input") { mshtml.IHTMLInputElement inputelement = Element as mshtml.IHTMLInputElement; type = inputelement.type.ToLower(); } try { mshtml.IHTMLUniqueName id = RawElement as mshtml.IHTMLUniqueName; uniqueID = id.uniqueID; } catch (Exception) { } IndexInParent = -1; if (Element.parentElement != null && !string.IsNullOrEmpty(uniqueID)) { mshtml.IHTMLElementCollection children = Element.parentElement.children; for (int i = 0; i < children.length; i++) { mshtml.IHTMLUniqueName id = children.item(i) as mshtml.IHTMLUniqueName; if (id != null && id.uniqueID == uniqueID) { IndexInParent = i; break; } } } }
static public bool findPoster(mshtml.HTMLDocument doc, MovieDB db) { if (db == null || doc == null) { return(false); } mshtml.IHTMLElementCollection item = doc.getElementsByTagName("img"); string posterUrl = ""; int cnt = 0; foreach (mshtml.IHTMLElement elem in item) { if (elem.getAttribute("alt") == db.title && cnt == 0) { posterUrl = elem.getAttribute("src"); break; } } if (posterUrl.Length <= 0) { return(false); } db.posterUrl = posterUrl.Split('?')[0]; return(true); }
public override void AddSubElements() { mshtml.IHTMLElementCollection children = IEElement.RawElement.children; foreach (mshtml.IHTMLElement elementNode in children) { var ele = new IEElement(IEElement.Browser, elementNode); var exists = Children.Where(x => ((IEElement)x.Element).uniqueID == ele.uniqueID).FirstOrDefault(); if (exists == null) { Interfaces.Log.Debug("Adding " + ele.ToString()); Children.Add(new IETreeElement(this, false, ele)); } } int frameoffsetx = 0; int frameoffsety = 0; if (IESelector.frameTags.Contains(IEElement.tagName.ToUpper())) { frameoffsetx += IEElement.RawElement.offsetLeft; frameoffsety += IEElement.RawElement.offsetTop; var web = IEElement.RawElement as SHDocVw.IWebBrowser2; var _doc = (mshtml.HTMLDocument)web.Document; Children.Add(new IETreeElement(this, false, new IEElement(IEElement.Browser, _doc.documentElement))); } }
public mshtml.IHTMLElement[] matches(mshtml.IHTMLElement element) { int counter = 0; do { try { var matchs = new List <mshtml.IHTMLElement>(); mshtml.IHTMLElementCollection elements = element.children; foreach (mshtml.IHTMLElement elementNode in elements) { if (Match(elementNode)) { matchs.Add(elementNode); } } Log.Selector("match count: " + matchs.Count); return(matchs.ToArray()); } catch (Exception) { ++counter; if (counter == 2) { throw; } } } while (counter < 2); return(new mshtml.IHTMLElement[] { }); }
public static List <mshtml.IHTMLElement> ToList(this mshtml.IHTMLElementCollection elements) { var results = new List <mshtml.IHTMLElement>(); foreach (mshtml.IHTMLElement element in elements) { results.Add(element); } return(results); }
private void frmBrowser_Navigated(object sender, NavigationEventArgs e) { SetStatusRight("RSS completely loaded."); WebBrowser Browser = sender as WebBrowser; mshtml.HTMLDocument HTMLDoc = Browser.Document as mshtml.HTMLDocument; mshtml.IHTMLScriptElement HTMLScript = (mshtml.IHTMLScriptElement)HTMLDoc.createElement("SCRIPT"); HTMLScript.type = "text/javascript"; HTMLScript.text = @"function noError() { return true; } window.onerror = noError;"; mshtml.IHTMLElementCollection Nodes = HTMLDoc.getElementsByTagName("HEAD"); foreach (mshtml.HTMLHeadElement HTMLElementItem in Nodes) { HTMLElementItem.appendChild((mshtml.IHTMLDOMNode)HTMLScript); } }
//Get element and do soming public mshtml.IHTMLElement GetElementByDo(ref SHDocVw.InternetExplorerMedium webApp, string fraName, string tagName, string keyName, string keyTxt) { if (ReferenceEquals(webApp, null)) { return(null); } SleepAndWaitComplete(webApp); mshtml.HTMLDocument Doc = (mshtml.HTMLDocument)webApp.Document; mshtml.IHTMLElementCollection eles = default(mshtml.IHTMLElementCollection); if (fraName == "") { eles = Doc.getElementsByTagName(tagName); } else { mshtml.HTMLWindow2 fra = GetFrameWait(ref webApp, fraName); Doc = (mshtml.HTMLDocument)fra.document; eles = Doc.getElementsByTagName(tagName); } SleepAndWaitComplete(webApp); foreach (mshtml.IHTMLElement ele in eles) { try { if (keyName == "innertext") { if (ele.innerText == keyTxt) { return(ele); } } else { String myKey; myKey = Convert.ToString(ele.getAttribute(keyName)); if (myKey.ToString() == keyTxt) { return(ele); } } } catch (Exception) { } } return(null); }
public ReplicaPage(string html) { Raw = html; Supplier = new Dictionary <string, string>(); var parser = new FMWW.Http.HTMLParser(html); mshtml.HTMLDocument document = parser.Document; mshtml.IHTMLElementCollection inputs = document.getElementsByTagName("input"); foreach (mshtml.IHTMLElement elm in inputs) { string title = elm.getAttribute("title") ?? ""; var id = elm.id ?? ""; if ((title.Length == 0) || (id.Length == 0)) { continue; } string value = elm.getAttribute("value"); Supplier.Add(title, value); Trace.WriteLine(String.Format("{0} {1} {2}", elm.id, title, value)); try { var input = elm as mshtml.IHTMLInputElement; var suffix = ":select"; var t = title + suffix; var v = ""; mshtml.IHTMLElementCollection spans = document.getElementById(elm.id + suffix).children; foreach (mshtml.IHTMLElement span in spans) { if (span.getAttribute("value") == input.value) { v = span.getAttribute("text"); continue; } } Supplier.Add(t, v); Trace.WriteLine(String.Format("{0} {1} {2}", elm.id + suffix, t, v)); } catch (Exception e) { Trace.WriteLine(e.Message); } } mshtml.IHTMLElement remark = document.getElementById("remark"); Supplier.Add("備考", remark.innerText); }
static public void GetRecommendMovies(mshtml.HTMLDocument doc, MovieDB db) { mshtml.IHTMLElementCollection item = doc.getElementsByTagName("ul"); foreach (mshtml.IHTMLElement elem in item) { if (elem.getAttribute("className") == "thumb_link_mv") { string text = elem.innerText; text = text.Replace("\r\n", ","); text = text.Replace(",,, ,", string.Empty); text = text.Substring(4); string[] movies = text.Split(','); db.recommendMovies.AddRange(movies); break; } } }
public List <CrmWebService.CompanyCmsData> GenerateCCDList(string html, out int totalCount) { List <CrmWebService.CompanyCmsData> ccdList = new List <CompanyCmsData>(); mshtml.HTMLDocumentClass doc = new mshtml.HTMLDocumentClass(); doc.designMode = "on"; doc.IHTMLDocument2_write(html); mshtml.IHTMLElement divcnt = doc.getElementById("cnt"); mshtml.IHTMLElementCollection childrens = (mshtml.IHTMLElementCollection)divcnt.children; mshtml.IHTMLTable table = (mshtml.IHTMLTable)childrens.item(2); for (int i = 1; i < table.rows.length; i++) { CompanyCmsData item = new CompanyCmsData(); mshtml.IHTMLTableRow row = (mshtml.IHTMLTableRow)table.rows.item(i); mshtml.IHTMLElement cell = (mshtml.IHTMLElement)row.cells.item(0); item.CmsId = int.Parse(cell.innerText.Trim()); cell = (mshtml.IHTMLElement)row.cells.item(1); item.CompanyName = string.IsNullOrEmpty(cell.innerText) ? "" : cell.innerText.Trim(); cell = (mshtml.IHTMLElement)row.cells.item(2); item.TTSStatusDesp = string.IsNullOrEmpty(cell.innerText) ? "" : cell.innerText.Trim(); cell = (mshtml.IHTMLElement)row.cells.item(3); item.ContactPhone = string.IsNullOrEmpty(cell.innerText) ? "" : cell.innerText.Trim(); cell = (mshtml.IHTMLElement)row.cells.item(5); item.SalesName = string.IsNullOrEmpty(cell.innerText) ? "" : cell.innerText.Trim(); ccdList.Add(item); } totalCount = 0; mshtml.IHTMLElementCollection eles = doc.getElementsByName("totalCount"); if (eles != null && eles.length > 0) { totalCount = int.Parse(((mshtml.IHTMLElement)eles.item(0)).getAttribute("value").ToString()); } return(ccdList); }
static public void GetRatings(mshtml.HTMLDocument doc, MovieDB db) { mshtml.IHTMLElementCollection item = doc.getElementsByTagName("div"); int lineIndex = 0; foreach (mshtml.IHTMLElement elem in item) { var score = elem.getAttribute("className"); if (score == "star_score" || score == "star_score ") { string text = elem.innerText; text = text.Replace("\r\n", ""); if (lineIndex == 0) { text = text.Replace("관람객 평점 ", ""); text = text.Replace("점", ","); db.audRating = text.Split(',')[0]; } else if (lineIndex == 1) { db.expRating = text; } else if (lineIndex == 2) { db.netRating = text; } lineIndex++; if (lineIndex >= 3) { break; } } } }
void startParsing() { mshtml.IHTMLDocument2 htmlDocument = web.Document as mshtml.IHTMLDocument2; mshtml.IHTMLElementCollection hec = (mshtml.IHTMLElementCollection)htmlDocument.all; cnt = 0; try { foreach (mshtml.IHTMLElement element in hec) { if (element.tagName.Equals("SPAN")) { cnt++; if (cnt > 2) { sol[cnt - 3] = element.outerHTML; } } } cnt -= 2; for (int i = 0; i < cnt; i++) { sol[i] = sol[i].Substring(sol[i].LastIndexOf("<") - 2, 2); if (sol[i].IndexOf(">") == 0) { sol[i] = sol[i].Substring(1); } } } catch (WebException) { sol[0] = "Error Found"; } catch (Exception) { } }
public CompanyCmsData GenerateCCD(string html) { CompanyCmsData item = new CompanyCmsData(); mshtml.HTMLDocumentClass doc = new mshtml.HTMLDocumentClass(); doc.designMode = "on"; doc.IHTMLDocument2_write(html); mshtml.IHTMLElement noteEle = doc.getElementById("note"); //公司简介 if (noteEle != null) { item.CompanyDesp = string.IsNullOrEmpty(noteEle.innerText) ? "" : noteEle.innerText.Trim(); } else { return(null); } mshtml.IHTMLElement ele = doc.getElementById("registeredAddress"); //注册地址 if (ele.getAttribute("value") != null) { item.RegisterAddress = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("address"); //地址 if (ele.getAttribute("value") != null) { item.RealAddress = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("businessLicense"); //营业执照号 if (ele.getAttribute("value") != null) { item.CompanyIdNo = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("email"); //营业执照号 if (ele.getAttribute("value") != null) { item.CompanyEmail = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("legalRepresentative"); //法人 if (ele.getAttribute("value") != null) { item.LegalPerson = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("contact"); //联系人 if (ele.getAttribute("value") != null) { item.ContactPerson = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("phone"); //电话 if (ele.getAttribute("value") != null) { item.ContactPhone = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } ele = doc.getElementById("accountName"); //tts的admin账号 if (ele.getAttribute("value") != null) { item.TTSAdminAccount = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } mshtml.IHTMLElementCollection eles = doc.getElementsByName("promotionNameDomestic"); if (eles != null && eles.length > 0) { ele = (mshtml.IHTMLElement)eles.item(0); if (ele.getAttribute("value") != null) { item.GuoneiWebName = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } } eles = doc.getElementsByName("promotionNameInternational"); if (eles != null && eles.length > 0) { ele = (mshtml.IHTMLElement)eles.item(0); if (ele.getAttribute("value") != null) { item.GuojiWebName = string.IsNullOrEmpty(ele.getAttribute("value").ToString()) ? "" : ele.getAttribute("value").ToString(); } } ele = doc.getElementById("bossBackgrouds"); //公司简介 item.BossBackground = string.IsNullOrEmpty(ele.innerText) ? "" : ele.innerText.Trim(); return(item); }
public bool Get(ref mshtml.IHTMLTable table, bool tableCreated) { if (table == null) { return(false); } // define the table border, width, cell padding and spacing object bgColor, borderColor; base.Get(out bgColor, out borderColor); table.bgColor = bgColor; table.borderColor = borderColor; if (this.TableWidth > 0) { table.width = (this.TableWidthMeasurement == MeasurementOption.Pixel) ? string.Format("{0}", this.TableWidth) : string.Format("{0}%", this.TableWidth); } else { table.width = string.Empty; } if (this.TableAlignment != HorizontalAlignOption.Default) { table.align = this.TableAlignment.ToString().ToLower(); } else { table.align = string.Empty; } table.border = this.BorderSize; table.cellPadding = this.CellPadding.ToString(); table.cellSpacing = this.CellSpacing.ToString(); // define the given table caption and alignment string caption = this.CaptionText; mshtml.IHTMLTableCaption tableCaption = table.caption; if (caption != null && caption != string.Empty) { // ensure table caption correctly defined if (tableCaption == null) { tableCaption = table.createCaption(); } ((mshtml.IHTMLElement)tableCaption).innerText = caption; if (this.CaptionAlignment != HorizontalAlignOption.Default) { tableCaption.align = this.CaptionAlignment.ToString().ToLower(); } if (this.CaptionLocation != VerticalAlignOption.Default) { tableCaption.vAlign = this.CaptionLocation.ToString().ToLower(); } } else { // if no caption specified remove the existing one if (tableCaption != null) { // prior to deleting the caption the contents must be cleared ((mshtml.IHTMLElement)tableCaption).innerText = null; table.deleteCaption(); } } // determine the number of rows one has to insert int numberRows, numberCols; if (tableCreated) { numberRows = Math.Max((int)this.TableRows, 1); } else { numberRows = Math.Max((int)this.TableRows, 1) - (int)table.rows.length; } // layout the table structure in terms of rows and columns table.cols = (int)this.TableColumns; if (tableCreated) { // this section is an optimization based on creating a new table // the section below works but not as efficiently numberCols = Math.Max((int)this.TableColumns, 1); // insert the appropriate number of rows mshtml.IHTMLTableRow tableRow; for (int idxRow = 0; idxRow < numberRows; idxRow++) { tableRow = (mshtml.IHTMLTableRow)table.insertRow(-1); // add the new columns to the end of each row for (int idxCol = 0; idxCol < numberCols; idxCol++) { tableRow.insertCell(-1); } } } else { // if the number of rows is increasing insert the decrepency if (numberRows > 0) { // insert the appropriate number of rows for (int idxRow = 0; idxRow < numberRows; idxRow++) { table.insertRow(-1); } } else { // remove the extra rows from the table for (int idxRow = numberRows; idxRow < 0; idxRow++) { table.deleteRow(table.rows.length - 1); } } // have the rows constructed // now ensure the columns are correctly defined for each row mshtml.IHTMLElementCollection rows = table.rows; foreach (mshtml.IHTMLTableRow tableRow in rows) { numberCols = Math.Max((int)this.TableColumns, 1) - (int)tableRow.cells.length; if (numberCols > 0) { // add the new column to the end of each row for (int idxCol = 0; idxCol < numberCols; idxCol++) { tableRow.insertCell(-1); } } else { // reduce the number of cells in the given row // remove the extra rows from the table for (int idxCol = numberCols; idxCol < 0; idxCol++) { tableRow.deleteCell(tableRow.cells.length - 1); } } } } return(true); }
// function to insert a basic table // will honour the existing table if passed in private void ProcessTable(HtmlTable table, HtmlTableProperty tableProperties) { try { using (new UndoUnit(Document, "Table add/modify")) { // obtain a reference to the body node and indicate table present HtmlDomNode bodyNode = (HtmlDomNode)Document.body; bool tableCreated = false; MsHtmlWrap.MarkupRange targetMarkupRange = null; // ensure a table node has been defined to work with if (table == null) { // create the table and indicate it was created table = (HtmlTable)Document.createElement("TABLE"); tableCreated = true; //markup range for selecting first cell after table creation targetMarkupRange = GetMarkupRange(); } // define the table border, width, cell padding and spacing table.border = tableProperties.BorderSize; if (tableProperties.TableWidth > 0) { table.width = (tableProperties.TableWidthMeasurement == MeasurementOption.Pixel) ? string.Format("{0}", tableProperties.TableWidth) : string.Format("{0}%", tableProperties.TableWidth); } else { table.width = string.Empty; } if (tableProperties.TableAlignment != HorizontalAlignOption.Default) { table.align = tableProperties.TableAlignment.ToString().ToLower(); } else { table.align = string.Empty; } table.cellPadding = tableProperties.CellPadding.ToString(); table.cellSpacing = tableProperties.CellSpacing.ToString(); // define the given table caption and alignment string caption = tableProperties.CaptionText; HtmlTableCaption tableCaption = table.caption; if (caption != null && caption != string.Empty) { // ensure table caption correctly defined if (tableCaption == null) { tableCaption = table.createCaption(); } ((HtmlElement)tableCaption).innerText = caption; if (tableProperties.CaptionAlignment != HorizontalAlignOption.Default) { tableCaption.align = tableProperties.CaptionAlignment.ToString().ToLower(); } if (tableProperties.CaptionLocation != VerticalAlignOption.Default) { tableCaption.vAlign = tableProperties.CaptionLocation.ToString().ToLower(); } } else { // if no caption specified remove the existing one if (tableCaption != null) { // prior to deleting the caption the contents must be cleared ((HtmlElement)tableCaption).innerText = null; table.deleteCaption(); } } // determine the number of rows one has to insert int numberRows, numberCols; if (tableCreated) { numberRows = Math.Max((int)tableProperties.TableRows, 1); } else { numberRows = Math.Max((int)tableProperties.TableRows, 1) - (int)table.rows.length; } // layout the table structure in terms of rows and columns table.cols = (int)tableProperties.TableColumns; if (tableCreated) { // this section is an optimization based on creating a new table // the section below works but not as efficiently numberCols = Math.Max((int)tableProperties.TableColumns, 1); // insert the appropriate number of rows HtmlTableRow tableRow; for (int idxRow = 0; idxRow < numberRows; idxRow++) { tableRow = table.insertRow(-1) as HtmlTableRow; // add the new columns to the end of each row for (int idxCol = 0; idxCol < numberCols; idxCol++) { tableRow.insertCell(-1); } } } else { // if the number of rows is increasing insert the decrepency if (numberRows > 0) { // insert the appropriate number of rows for (int idxRow = 0; idxRow < numberRows; idxRow++) { table.insertRow(-1); } } else { // remove the extra rows from the table for (int idxRow = numberRows; idxRow < 0; idxRow++) { table.deleteRow(table.rows.length - 1); } } // have the rows constructed // now ensure the columns are correctly defined for each row HtmlElementCollection rows = table.rows; foreach (HtmlTableRow tableRow in rows) { numberCols = Math.Max((int)tableProperties.TableColumns, 1) - (int)tableRow.cells.length; if (numberCols > 0) { // add the new column to the end of each row for (int idxCol = 0; idxCol < numberCols; idxCol++) { tableRow.insertCell(-1); } } else { // reduce the number of cells in the given row // remove the extra rows from the table for (int idxCol = numberCols; idxCol < 0; idxCol++) { tableRow.deleteCell(tableRow.cells.length - 1); } } } } // if the table was created then it requires insertion into the DOM // otherwise property changes are sufficient if (tableCreated) { // table processing all complete so insert into the DOM HtmlDomNode tableNode = (HtmlDomNode)table; HtmlElement tableElement = (HtmlElement)table; HtmlSelection selection = Document.selection; HtmlTextRange textRange = SelectionHelper.GetTextRange(Document); // final insert dependant on what user has selected if (textRange != null) { // text range selected so overwrite with a table try { string selectedText = textRange.text; if (selectedText != null) { // place selected text into first cell HtmlTableRow tableRow = table.rows.item(0, null) as HtmlTableRow; (tableRow.cells.item(0, null) as HtmlElement).innerText = selectedText; } textRange.pasteHTML(tableElement.outerHTML); } catch (Exception ex) { throw new HtmlEditorException("Invalid Text selection for the Insertion of a Table.", "ProcessTable", ex); } } else { HtmlControlRange controlRange = SelectionHelper.GetAllControls(Document); if (controlRange != null) { // overwrite any controls the user has selected try { // clear the selection and insert the table // only valid if multiple selection is enabled for (int idx = 1; idx < controlRange.length; idx++) { controlRange.remove(idx); } controlRange.item(0).outerHTML = tableElement.outerHTML; // this should work with initial count set to zero // controlRange.add((HtmlControlElement)table); } catch (Exception ex) { throw new HtmlEditorException("Cannot Delete all previously Controls selected.", "ProcessTable", ex); } } else { // insert the table at the end of the HTML bodyNode.appendChild(tableNode); } } } else { // table has been correctly defined as being the first selected item // need to remove other selected items HtmlControlRange controlRange = SelectionHelper.GetAllControls(Document); if (controlRange != null) { // clear the controls selected other than than the first table // only valid if multiple selection is enabled for (int idx = 1; idx < controlRange.length; idx++) { controlRange.remove(idx); } } } //if table created, then focus the first cell if (tableCreated) { try { HtmlElement cell = targetMarkupRange.GetFirstElement(e => e is HtmlTableCell, true); if (cell != null) { SelectCell(cell as HtmlTableCell); } } catch (Exception e) { Log.Write(e); } } } } catch (Exception ex) { // throw an exception indicating table structure change error throw new HtmlEditorException("Unable to modify Html Table properties.", "ProcessTable", ex); } } //ProcessTable
private void enumElements(Browser browser, mshtml.IHTMLElement baseelement, IESelector anchor, bool doEnum, int X, int Y) { mshtml.IHTMLElement element = baseelement; mshtml.HTMLDocument document = browser.Document; var pathToRoot = new List <mshtml.IHTMLElement>(); while (element != null) { if (pathToRoot.Contains(element)) { break; } try { pathToRoot.Add(element); } catch (Exception) { } try { element = element.parentElement; } catch (Exception ex) { Log.Error(ex, ""); return; } } // Log.Selector(string.Format("IEselector::create pathToRoot::end {0:mm\\:ss\\.fff}", sw.Elapsed)); pathToRoot.Reverse(); if (anchor != null) { var anchorlist = anchor.Where(x => x.Enabled && x.Selector == null).ToList(); for (var i = 0; i < anchorlist.Count(); i++) { //if (((IESelectorItem)anchorlist[i]).Match(pathToRoot[0])) if (IESelectorItem.Match(anchorlist[i], pathToRoot[0])) { pathToRoot.Remove(pathToRoot[0]); } else { Log.Selector("Element does not match the anchor path"); return; } } } if (pathToRoot.Count == 0) { Log.Error("Element is same as annchor"); return; } element = pathToRoot.Last(); // // Log.Selector(string.Format("IEselector::remove anchor if needed::end {0:mm\\:ss\\.fff}", sw.Elapsed)); IESelectorItem item; if (anchor == null && Items.Count == 0) { item = new IESelectorItem(browser.Document); item.Enabled = true; //item.canDisable = false; Items.Add(item); } for (var i = 0; i < pathToRoot.Count(); i++) { var o = pathToRoot[i]; item = new IESelectorItem(browser, o); if (i == 0 || i == (pathToRoot.Count() - 1)) { item.canDisable = false; } foreach (var p in item.Properties) { int idx = p.Value.IndexOf("."); if (p.Name == "className" && idx > -1) { int idx2 = p.Value.IndexOf(".", idx + 1); if (idx2 > idx) { p.Value = p.Value.Substring(0, idx2 + 1) + "*"; } } } if (doEnum) { item.EnumNeededProperties(o, o.parentElement); } Items.Add(item); } if (frameTags.Contains(baseelement.tagName.ToUpper())) { //var ele2 = baseelement as mshtml.IHTMLElement2; //var col2 = ele2.getClientRects(); //var rect2 = col2.item(0); //X -= rect2.left; //Y -= rect2.top; var frame = baseelement as mshtml.HTMLFrameElement; var fffff = frame.contentWindow; mshtml.IHTMLWindow2 window = frame.contentWindow; mshtml.IHTMLElement el2 = null; foreach (string frameTag in frameTags) { mshtml.IHTMLElementCollection framesCollection = document.getElementsByTagName(frameTag); foreach (mshtml.IHTMLElement _frame in framesCollection) { // var _f = _frame as mshtml.HTMLFrameElement; el2 = browser.ElementFromPoint(_frame, X, Y); //var _wb = _f as SHDocVw.IWebBrowser2; //document = _wb.Document as mshtml.HTMLDocument; //el2 = document.elementFromPoint(X, Y); if (el2 != null) { var tag = el2.tagName; // var html = el2.innerHTML; Log.Selector("tag: " + tag); //browser.elementx += _frame.offsetLeft; //browser.elementy += _frame.offsetTop; //browser.frameoffsetx += _frame.offsetLeft; //browser.frameoffsety += _frame.offsetTop; enumElements(browser, el2, anchor, doEnum, X, Y); return; } } } } }
public static IEElement[] GetElementsWithuiSelector(IESelector selector, IElement fromElement = null, int maxresults = 1) { IEElement iefromElement = fromElement as IEElement; Browser browser; if (iefromElement != null) { browser = iefromElement.Browser; } else { browser = Browser.GetBrowser(); } if (browser == null) { Log.Warning("Failed locating an Internet Explore instance"); return(new IEElement[] { }); } var sw = new System.Diagnostics.Stopwatch(); sw.Start(); IEElement _fromElement = fromElement as IEElement; var selectors = selector.Where(x => x.Enabled == true && x.Selector == null).ToList(); var current = new List <IEElement>(); IEElement[] result = null; int startIndex = 1; if (iefromElement != null) { startIndex = 0; current.Add(iefromElement); } else { mshtml.IHTMLElement startfrom = null; startfrom = browser.Document.documentElement; current.Add(new IEElement(browser, startfrom)); } for (var i = startIndex; i < selectors.Count; i++) { var s = new IESelectorItem(selectors[i]); var elements = new List <IEElement>(); elements.AddRange(current); current.Clear(); int failcounter = 0; do { foreach (var _element in elements) { mshtml.IHTMLElement[] matches; if (frameTags.Contains(_element.tagName.ToUpper())) { if (s.tagName.ToUpper() == "HTML") { i++; s = new IESelectorItem(selectors[i]); } var _f = _element.RawElement as mshtml.HTMLFrameElement; mshtml.DispHTMLDocument doc = (mshtml.DispHTMLDocument)((SHDocVw.IWebBrowser2)_f).Document; var _doc = doc.documentElement as mshtml.IHTMLElement; matches = ((IESelectorItem)s).matches(_doc); browser.elementx += _f.offsetLeft; browser.elementy += _f.offsetTop; browser.frameoffsetx += _f.offsetLeft; browser.frameoffsety += _f.offsetTop; } else { matches = ((IESelectorItem)s).matches(_element.RawElement); } var uimatches = new List <IEElement>(); foreach (var m in matches) { var ui = new IEElement(browser, m); uimatches.Add(ui); } current.AddRange(uimatches.ToArray()); Log.Selector("add " + uimatches.Count + " matches to current"); } if (current.Count == 0) { ++failcounter; string message = string.Format("Failer # " + failcounter + " finding any hits for selector # " + i + " {0:mm\\:ss\\.fff}", sw.Elapsed) + "\n"; message += "lookin for \n" + s.ToString() + "\n"; foreach (var _element in elements) { mshtml.IHTMLElementCollection children = _element.RawElement.children; foreach (mshtml.IHTMLElement elementNode in children) { var ui = new IEElement(browser, elementNode); message += ui.ToString() + "\n"; } var matches = ((IESelectorItem)s).matches(_element.RawElement); } Log.Selector(message); } else { Log.Selector(string.Format("Found " + current.Count + " hits for selector # " + i + " {0:mm\\:ss\\.fff}", sw.Elapsed)); } } while (failcounter < 2 && current.Count == 0); if (i == (selectors.Count - 1)) { result = current.ToArray(); } if (current.Count == 0) { var message = "needed to find " + Environment.NewLine + selectors[i].ToString() + Environment.NewLine + "but found only: " + Environment.NewLine; foreach (var element in elements) { mshtml.IHTMLElementCollection children = element.RawElement.children; foreach (mshtml.IHTMLElement c in children) { try { // message += automationutil.getSelector(c, (i == selectors.Count - 1)) + Environment.NewLine; } catch (Exception) { } } } Log.Selector(message); return(new IEElement[] { }); } } if (result == null) { return new IEElement[] { } } ; Log.Selector(string.Format("GetElementsWithuiSelector::end {0:mm\\:ss\\.fff}", sw.Elapsed)); return(result); } }
//Step 2 (WHILE) public bool DoStep2_Set(int startIdx = 0) { mshtml.HTMLDocument Doc = default(mshtml.HTMLDocument); mshtml.IHTMLElementCollection eles = default(mshtml.IHTMLElementCollection); Doc = (mshtml.HTMLDocument)Ie.Document; mshtml.HTMLWindow2 fra = Pub_Com.GetFrameWait(ref Ie, "fraHyou"); while (ReferenceEquals(fra, null)) { Com.Sleep5(1000); fra = Pub_Com.GetFrameWait(ref Ie, "fraHyou"); } Pub_Com.SleepAndWaitComplete(Ie); Doc = (mshtml.HTMLDocument)fra.document; eles = Doc.getElementsByTagName("input"); Pub_Com.SleepAndWaitComplete(Ie); Com.Sleep5(1000); if (eles.length == 0) { MessageBox.Show("明細がありません、多分発注した件数多いです"); Ie.Visible = true; System.Environment.Exit(0); return(false); } for (int i = startIdx; i <= eles.length - 1; i++) { mshtml.IHTMLElement ele = (mshtml.IHTMLElement)(eles.item(i)); if (ReferenceEquals(ele, null)) { continue; } try { if (ele.getAttribute("name").ToString() == "strMitKbnHen") { mshtml.IHTMLTableRow tr = (mshtml.IHTMLTableRow)ele.parentElement.parentElement; mshtml.HTMLTableCell td = (mshtml.HTMLTableCell)(tr.cells.item(4)); if (td.innerText == "作成中") { ele.click(); Pub_Com.GetElementBy(ref Ie, "fraHead", "input", "value", "発注納期非表示").click(); Pub_Com.SleepAndWaitComplete(Ie); mshtml.HTMLDocument Doc1 = (mshtml.HTMLDocument)Ie.Document; mshtml.HTMLWindow2 fra1 = Pub_Com.GetFrameWait(ref Ie, "fraMitBody"); Doc1 = (mshtml.HTMLDocument)fra1.document; if (Doc1.body.innerText.IndexOf("発注可能な見積ではありません") > 0) { Ie.GoBack(); Pub_Com.SleepAndWaitComplete(Ie); return(DoStep2_Set(i + 1)); } else { return(true); } } } } catch (Exception) { } } return(false); }
private void browser_LoadCompleted(object sender, NavigationEventArgs e) { if (browser.Document != null) { try { mshtml.HTMLDocument dom = (mshtml.HTMLDocument)browser.Document; //mshtml.IHTMLElement temper=null; switch (model.ToUpper()) { case "ALPHA": //读取温度 Scanner Block Temperature [°C] Alpha仪器 mshtml.IHTMLElement temper = dom.getElementById("SCRTMPCORR"); if (temper != null) { if (!double.TryParse(temper.innerHTML, out Temperature)) { Temperature = -1; } } break; case "MATRIX-I": //读取温度 Scanner Block Temperature [°C] Matrix仪器 mshtml.IHTMLElementCollection temperM = dom.getElementsByTagName("TD"); if (temperM != null) { bool IsFindOut = false; foreach (mshtml.IHTMLElement p in temperM) { if (IsFindOut) { string temp = p.innerHTML; if (!double.TryParse(p.innerHTML, out Temperature)) { Temperature = -1; } break; } if (p.innerHTML.Contains("Scannerblock Temperature")) { //已经找到 IsFindOut = true; } } } break; case "TANGO": mshtml.IHTMLElementCollection temperT = dom.getElementsByTagName("TD"); if (temperT != null) { bool IsFindOut = false; foreach (mshtml.IHTMLElement p in temperT) { if (IsFindOut) { string temp = p.innerHTML; if (!double.TryParse(p.innerHTML, out Temperature)) { Temperature = -1; } break; } if (p.innerHTML != null) { if (p.innerHTML.Contains("Scanner Block Temperature")) { //已经找到 IsFindOut = true; } } } } break; default: break; } //读取激光波数 mshtml.IHTMLElementCollection textArea = dom.getElementsByTagName("B"); foreach (mshtml.IHTMLElement p in textArea) { if (p.parentElement.parentElement.innerHTML != null && p.parentElement.parentElement.innerHTML.Contains("Current NvRAM Data"))//NvRamDataPrev")) { string htmlText = p.parentElement.parentElement.innerHTML; int fx = htmlText.IndexOf("CLWN"); int lx = htmlText.LastIndexOf("CLWN"); string result = htmlText.Substring(fx, lx - fx); result = result.Replace("CLWN>", string.Empty).Replace("</", string.Empty); //string temp1=""; ////result = Regex.Replace(result, @"[\d+.]*", ""); double temp = -1; if (double.TryParse(result, out temp)) { laserWave = temp; } else { laserWave = -1; } // break; //string tempString = p.innerHTML;// lwn.parentElement.innerHTML; //string[] result = tempString.Replace("<TD id=LWN>LWN\r\n<TD>Laser Wavenumber</TD>\r\n<TD>", string.Empty).Split('\r'); ////string[] res=result.s //if (result != null && result.Count() > 0) //{ // if (!double.TryParse(result[0], out laserWave)) // { // laserWave = -1; // } //} } } //int i = 0; //foreach(mshtml.IHTMLElement p in lwn.parentElement.children) //{ // if (i == 0) // { // i++; // continue; // } // if (!double.TryParse(p.innerHTML, out laserWave)) // { // laserWave = -1; // } //} //} //mshtml.IHTMLElementCollection laser = dom.getElementsByTagName("TEXTAREA"); //mshtml.IHTMLElementCollection node = dom.getElementsByTagName("B"); //mshtml.IHTMLElement element=null; //foreach (mshtml.IHTMLElement html in node) //{ // if (html.innerHTML == "Previous Start-Up NvRAM Data") // { // element=html; // } //} //foreach(mshtml.IHTMLElement html in laser) //{ // if(html.parentElement.parentElement.parentElement.parentElement.parentElement==element.parentElement.parentElement) // { // XmlDocument doc = new XmlDocument(); // doc.LoadXml(html.parentElement.parentElement.innerHTML); //加载Xml文件 // XmlElement rootElem = doc.DocumentElement; //获取根节点 // XmlNodeList personNodes = rootElem.GetElementsByTagName("TABLE"); //获取person子节点集合 // foreach (XmlElement node1 in personNodes) // { // foreach (XmlElement child in node1.ChildNodes) // { // //读取IP地址 // if (string.Equals(child.Name, "URL")) // { // } // } // } // } //} //foreach (mshtml.IHTMLElement html in node) //{ // if (html.innerHTML == "Previous Start-Up NvRAM Data") // { // string htmlText = html.parentElement.parentElement.innerHTML; // int fx = htmlText.IndexOf("CLWN"); // int lx = htmlText.LastIndexOf("CLWN"); // string result = htmlText.Substring(fx, lx - fx); // result = result.Replace("CLWN>", string.Empty).Replace("</", string.Empty); // //string temp1=""; // ////result = Regex.Replace(result, @"[\d+.]*", ""); // double temp = -1; // if (double.TryParse(result, out temp)) // { // laserWave = temp; // } // else // { // laserWave = -1; // } // break; // } //} } catch { } this.Hide(); } else { Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDelgate(Refresh)); } }
private void VideoLoaded(object sender, NavigationEventArgs e) { mshtml.HTMLDocument document = VideoPlayer.Document as mshtml.HTMLDocument; mshtml.IHTMLElementCollection divCol; new Thread(() => { while (true) { /* * Check if a video ad was loaded, if so: reload */ divCol = document.getElementsByTagName("div"); foreach (mshtml.IHTMLElement element in divCol) { if (element.className != null) { //Console.WriteLine(element.className); if (element.className.Equals("ytp-ad-player-overlay")) { Console.WriteLine("Contains video ads, reloading"); this.Dispatcher.Invoke(() => { VideoPlayer.Navigate(VideoPlayer.Source); }); return; } } } /* * Check if video slider's scale is 1, if so: load next video */ //Thread.Sleep(0); mshtml.HTMLDocument tdocument; this.Dispatcher.Invoke(() => { tdocument = VideoPlayer.Document as mshtml.HTMLDocument; }); mshtml.IHTMLElementCollection tcol = document.getElementsByTagName("div"); foreach (mshtml.IHTMLElement el in tcol) { try { String classname = el.getAttribute("className"); if (classname.Equals("ytp-play-progress ytp-swatch-background-color")) { String scale = el.style.getAttribute("transform"); if (scale.StartsWith("scaleX(1")) { this.Dispatcher.Invoke(() => { PlayYoutubeVideo(); }); return; } break; } } catch { } } } }).Start(); }
public static bool Match(SelectorItem item, mshtml.IHTMLElement m) { foreach (var p in item.Properties.Where(x => x.Enabled == true && x.Value != null)) { if (p.Name == "tagName") { if (!string.IsNullOrEmpty(m.tagName)) { var v = m.tagName; if (!PatternMatcher.FitsMask(v, p.Value)) { Log.Selector(p.Name + " mismatch '" + v + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "className") { var v = m.className; if (!string.IsNullOrEmpty(m.className)) { if (v.Contains(" ") && !p.Value.Contains(" ")) { var arr = v.Split(' '); var found = false; foreach (var s in arr) { if (PatternMatcher.FitsMask(s, p.Value)) { found = true; } } if (!found) { Log.Selector(p.Name + " mismatch '" + m.className + "' expected '" + p.Value + "'"); return(false); } } else if (!PatternMatcher.FitsMask(v, p.Value)) { Log.Selector(p.Name + " mismatch '" + m.className + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "type" && m.tagName.ToLower() == "input") { mshtml.HTMLInputElement ele = (mshtml.HTMLInputElement)m; if (!string.IsNullOrEmpty(ele.type)) { var v = ele.type; if (!PatternMatcher.FitsMask(ele.type, p.Value)) { Log.Selector(p.Name + " mismatch '" + v + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "Id") { if (!string.IsNullOrEmpty(m.id)) { var v = m.id; if (!PatternMatcher.FitsMask(m.id, p.Value)) { Log.Selector(p.Name + " mismatch '" + v + "' expected '" + p.Value + "'"); return(false); } } else { Log.Selector(p.Name + " does not exists, but needed value '" + p.Value + "'"); return(false); } } if (p.Name == "IndexInParent") { mshtml.IHTMLUniqueName id = m as mshtml.IHTMLUniqueName; var uniqueID = id.uniqueID; var IndexInParent = -1; if (m.parentElement != null && !string.IsNullOrEmpty(uniqueID)) { mshtml.IHTMLElementCollection children = m.parentElement.children; for (int i = 0; i < children.length; i++) { mshtml.IHTMLUniqueName id2 = children.item(i) as mshtml.IHTMLUniqueName; if (id2.uniqueID == uniqueID) { IndexInParent = i; break; } } } if (IndexInParent != int.Parse(p.Value)) { Log.Selector(p.Name + " mismatch '" + IndexInParent + "' expected '" + p.Value + "'"); return(false); } } } return(true); }
public void EnumNeededProperties(mshtml.IHTMLElement element, mshtml.IHTMLElement parent) { string name = null; if (!string.IsNullOrEmpty(element.tagName)) { name = element.tagName; } if (!string.IsNullOrEmpty(element.className)) { name = element.className; } if (!string.IsNullOrEmpty(element.id)) { name = element.id; } var props = GetProperties(); int i = 1; int matchcounter = 0; foreach (var p in Properties) { p.Enabled = false; } do { Log.Selector("#*******************************#"); Log.Selector("# " + i); var selectedProps = props.Take(i).ToArray(); foreach (var p in Properties) { p.Enabled = selectedProps.Contains(p.Name); } mshtml.IHTMLElementCollection children = null; if (element.parentElement != null) { children = element.parentElement.children; } matchcounter = 0; if (children != null) { foreach (mshtml.IHTMLElement elementNode in children) { if (Match(elementNode)) { matchcounter++; } if (matchcounter > 1) { break; } } if (matchcounter != 1) { Log.Selector("EnumNeededProperties match with " + i + " gave more than 1 result"); ++i; if (i >= props.Count()) { break; } } } else { ++i; } } while (matchcounter != 1 && i < props.Count()); Log.Selector("EnumNeededProperties match with " + i + " gave " + matchcounter + " result"); Properties.ForEach((e) => e.Enabled = false); foreach (var p in props.Take(i).ToArray()) { Properties.Where(x => x.Name == p).First().Enabled = true; } }
static public bool UpdateMovieDB(mshtml.HTMLDocument doc, MovieDB db) { if (db == null || doc == null) { return(false); } mshtml.IHTMLElementCollection item = doc.getElementsByTagName("dd"); int lineIndex = 0; foreach (mshtml.IHTMLElement elem in item) { string text = elem.innerText; if (lineIndex == 0) { // 감독 text = text.Replace(", ", ","); string[] director = text.Split(','); db.director.AddRange(director); } else if (lineIndex == 1) { // 배우 text = text.Replace(", ", ","); string[] actor = text.Split(','); db.actor.AddRange(actor); } else if (lineIndex == 2) { // 장르, 국가, 상영시간, 개봉일 text = text.Replace(", ", ","); text = text.Replace(" ", "+"); text = text.Replace(" ", string.Empty); string[] tmp = text.Split('+'); string[] genre = tmp[0].Split(','); db.genre.AddRange(genre); string[] nation = tmp[1].Split(','); db.nation.AddRange(nation); db.runningTime = tmp[2]; db.releaseDate = tmp[3]; } else if (lineIndex == 5) { // 관람 등급 text = text.Replace("\r\n", ""); text = text.Replace("도움말", ""); db.movieRating = text; break; } lineIndex++; } // 유사한 영화들 GetRecommendMovies(doc, db); // 관람객, 전문가, 네티즌 평점 GetRatings(doc, db); return(db.Is()); }
//実行 MAIN public void DoAll() { //SavePdf("aaaa.csv") Pub_Com = new Com("納期指定発注" + DateTime.Now.ToString("yyyyMMddHHmmss")); if (Pub_Com.file_list_Nouki.Count == 0) { ProBar = 100; return; } lv1 = System.Convert.ToDecimal(90 / Pub_Com.file_list_Nouki.Count); lv2 = lv1 / 15; //一回目 bool firsOpenKbn = true; object authHeader = "Authorization: Basic " + Convert.ToBase64String(System.Text.UnicodeEncoding.UTF8.GetBytes(string.Format("{0}:{1}", Pub_Com.user, Pub_Com.password))) + "\\r\\n"; //*** OnSiteパスワード入力画面 Ie.Navigate(Pub_Com.url, null, null, null, authHeader); Ie.Silent = true; Ie.Visible = IeVisible; ProBar = 5; //***ログイン DoStep1_Login(); //CSV ファイルs 取込 ProBar = 10; for (int fileIdx = 0; fileIdx <= Pub_Com.file_list_Nouki.Count - 1; fileIdx++) { string csvFileName = System.Convert.ToString(Pub_Com.file_list_Nouki[fileIdx].ToString().Trim()); string[] csvNameSplitor = csvFileName.Split('-'); string 事業所 = csvNameSplitor[0]; string 得意先 = csvNameSplitor[1]; string 店 = csvNameSplitor[2]; string 現場名 = csvNameSplitor[3]; string 備考 = csvNameSplitor[4]; string 日付連番 = csvNameSplitor[5]; //一回目ではなく 実行 if (firsOpenKbn == false) { Pub_Com.GetElementBy(ref Ie, "fraHead", "input", "value", "絞込検索").click(); Pub_Com.SleepAndWaitComplete(Ie); } firsOpenKbn = false; AddProBar(lv2); //1 Pub_Com.AddMsg("取込:" + Pub_Com.file_list_Nouki[fileIdx].ToString().Trim()); //見積検索 Pub_Com.AddMsg("見積検索"); DoStep1_PoupuSentaku(事業所, 得意先, 店, 現場名, 備考, 日付連番, csvFileName); Pub_Com.SleepAndWaitComplete(Ie); AddProBar(lv2); //2 //納期日設定 if (!DoStep2_Set()) { continue; } Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); //該当データがありません NEXT mshtml.HTMLWindow2 fraTmp = Pub_Com.GetFrameByName(ref Ie, "fraHyou"); if (fraTmp != null) { if (fraTmp.document.body.innerText.IndexOf("該当データがありません") >= 0) { continue; } } //CSVファイル内容取込 string[] csvDataLines = System.IO.File.ReadAllLines(Pub_Com.folder_Nouki + csvFileName); string code = ""; string nouki = ""; AddProBar(lv2); //3 mshtml.HTMLWindow2 fra = Pub_Com.GetFrameWait(ref Ie, "fraMitBody"); mshtml.HTMLDocument Doc = (mshtml.HTMLDocument)fra.document; mshtml.IHTMLElementCollection eles = Doc.getElementsByTagName("input"); //Radio 明細Key mshtml.IHTMLElementCollection cbEles = Doc.getElementsByName("strMeisaiKey"); //指定納期 mshtml.IHTMLElementCollection nouhinDateEles = Doc.getElementsByName("strSiteiNouhinDate"); int csvIdx = 0; int sameCdSuu = 0; int gamenSameCdSuu = 0; //CSV LINES for (int csvLinesIdx = 0; csvLinesIdx <= csvDataLines.Length - 1; csvLinesIdx++) { if (!string.IsNullOrEmpty(csvDataLines[csvLinesIdx].Trim())) { //コード 納期 code = System.Convert.ToString(csvDataLines[csvLinesIdx].Split(',')[1].Trim()); nouki = System.Convert.ToString((System.Convert.ToDateTime(csvDataLines[csvLinesIdx].Split(',')[2].Trim())).ToString("yyyy/MM/dd")); sameCdSuu = 0; gamenSameCdSuu = 0; for (csvIdx = 0; csvIdx <= csvLinesIdx; csvIdx++) { if (csvDataLines[csvIdx].Split(',')[1].Trim() == code) { sameCdSuu++; } } for (int i = 0; i <= cbEles.length - 1; i++) { mshtml.IHTMLElement cb = (mshtml.IHTMLElement)(cbEles.item(i)); mshtml.IHTMLTableRow tr = (mshtml.IHTMLTableRow)cb.parentElement.parentElement; mshtml.HTMLTableCell td = (mshtml.HTMLTableCell)(tr.cells.item(1)); mshtml.IHTMLTable table = (mshtml.IHTMLTable)cb.parentElement.parentElement.parentElement.parentElement; bool isHaveDate = false; if (td.innerText == code) { gamenSameCdSuu++; if (sameCdSuu == gamenSameCdSuu) { mshtml.IHTMLSelectElement sel = (mshtml.IHTMLSelectElement)(nouhinDateEles.item(i)); for (int j = 0; j <= sel.length - 1; j++) { mshtml.IHTMLOptionElement opEle = (mshtml.IHTMLOptionElement)(sel.item(j)); if (opEle.value.IndexOf(nouki) > 0) { opEle.selected = true; isHaveDate = true; break; } } } else { continue; } if (!isHaveDate) { MessageBox.Show("コード:[" + code + "] 納品希望日:[" + nouki + "]がありません"); return; } } } } } AddProBar(lv2); //4 Pub_Com.GetElementBy(ref Ie, "fraMitBody", "select", "name", "strBukkenKbn").setAttribute("value", "01"); Pub_Com.GetElementBy(ref Ie, "fraMitBody", "input", "value", "発 注").click(); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); AddProBar(lv2); //5 Pub_Com.GetElementBy(ref Ie, "fraMitBody", "input", "value", "発注結果照会へ").click(); Pub_Com.SleepAndWaitComplete(Ie); AddProBar(lv2); //6 //PDF 印刷 if (insatu) { SHDocVw.InternetExplorerMedium childIe = default(SHDocVw.InternetExplorerMedium); int RebackKaisu = -1; Reback: RebackKaisu++; Com.Sleep5(1000); //前回印刷画面 Close ClosePrintPage(); Pub_Com.GetElementBy(ref Ie, "fraMitBody", "input", "value", "結果印刷").click(); int wait_print; wait_print = int.Parse(Com.GetAppSetting("wait_print")); AutoResetEvent myEvent = new AutoResetEvent(false); myEvent.WaitOne(wait_print * 1000); myEvent.Close(); try { //印刷画面取得する childIe = GetPrintPage(); } catch (Exception) { } Com.Sleep5(1000); //IE エラー判定する if (GetErrCon() == false) { Com.Sleep5(1000); if (RebackKaisu <= 1) { goto Reback; } else { if (MessageBox.Show("帳票Download エラーしました、終了ですか?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { System.Environment.Exit(0); } } } string flName = Pub_Com.pdfPath + csvFileName; try { bool rtv = GetFcwInfo(childIe, flName); ClosePrintPage(); if (rtv == false) { if (RebackKaisu <= 1) { goto Reback; } else { if (MessageBox.Show("帳票Download エラーしました、終了ですか?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { System.Environment.Exit(0); } } } } catch (Exception) { ClosePrintPage(); if (RebackKaisu <= 1) { goto Reback; } else { if (MessageBox.Show("帳票Download エラーしました、終了ですか?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { System.Environment.Exit(0); } } } } AddProBar(lv2); //10 Pub_Com.AddMsg("移動CSV:" + csvFileName + "→" + Pub_Com.folder_Nouki_kanryou); Com.MoveFile(Pub_Com.folder_Nouki + csvFileName, Pub_Com.folder_Nouki_kanryou + csvFileName); AddProBar(lv2); //11 Pub_Com.GetElementBy(ref Ie, "fraMitMenu", "a", "innertext", "[見積一覧を再表示]").click(); Pub_Com.SleepAndWaitComplete(Ie); } ProBar = 100; }
private void webBrowserEx1_NavigateComplete(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e) { _doc = (mshtml.IHTMLDocument2)this.webBrowserEx1.CurrentDocument; ps = (mshtml.IHTMLElementCollection)((mshtml.IHTMLElementCollection) _doc.body.all).tags("p"); _mouseover = new MouseOverHandler(_doc); _mousemove = new MouseMoveHandler(_doc); _keydown = new KeyDownHandler(_doc); _keyup = new KeyUpHandler(_doc); _doc.onmouseover = new DispatchWrapper(_mouseover); _doc.onmousemove = new DispatchWrapper(_mousemove); _doc.onkeydown = new DispatchWrapper(_keydown); _doc.onkeyup = new DispatchWrapper(_keyup); _mouseover.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnMouseOver); _mousemove.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnMouseMove); _keydown.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnKeyDown); _keyup.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnKeyUp); if(paragraphTarget > 0) JumpToParagraph(paragraphTarget); //either we move directly to a destination paragraph //or we want to highlight all findings, bookmark them, and move to the first one if(searchItemTarget != null && searchItemTarget.Length > 0) { if (jumpToKeyword) JumpToParagraph(searchItemTarget); else Highlight(searchItemTarget, "Yellow", ""); } //TODO ExamineBookContents(); }
//Step 1 新規見積もり public void DoStep1_PoupuSentaku(string 事業所, string 得意先, string 店, string 現場名, string 備考, string 日付連番, string fl) { try { Pub_Com.AddMsg("見積検索 POPUP"); SHDocVw.InternetExplorerMedium cIe = GetPopupWindow("OnSite", "mitSearch.asp"); while (ReferenceEquals(cIe, null)) { Com.Sleep5(100); cIe = GetPopupWindow("OnSite", "mitSearch.asp"); } Pub_Com.SleepAndWaitComplete(cIe); Pub_Com.GetElementBy(ref cIe, "", "input", "name", "strGenbaMei").innerText = 現場名; Pub_Com.GetElementBy(ref cIe, "", "input", "name", "strUriJgy").click(); Pub_Com.SleepAndWaitComplete(cIe); AddProBar(lv2); //12 Pub_Com.AddMsg("事業所検索 POPUP"); SHDocVw.InternetExplorerMedium cIe2 = GetPopupWindow("OnSite", "jgyKensaku.asp"); while (ReferenceEquals(cIe2, null)) { Com.Sleep5(100); cIe2 = GetPopupWindow("OnSite", "jgyKensaku.asp"); } Pub_Com.SleepAndWaitComplete(cIe2); Pub_Com.GetElementBy(ref cIe2, "", "input", "name", "strJgyCd").innerText = 事業所; Pub_Com.GetElementBy(ref cIe2, "", "input", "value", "検 索").click(); Com.Sleep5(1000); AddProBar(lv2); //13 Pub_Com.SleepAndWaitComplete(cIe); Pub_Com.GetElementBy(ref cIe, "", "input", "value", "検 索").click(); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); Pub_Com.SleepAndWaitComplete(Ie); Com.Sleep5(1000); AddProBar(lv2); //14 //50件以上の場合 try { Com.Sleep5(1000); mshtml.HTMLDocument Doc = default(mshtml.HTMLDocument); mshtml.IHTMLElementCollection eles = default(mshtml.IHTMLElementCollection); Doc = (mshtml.HTMLDocument)Ie.Document; mshtml.HTMLWindow2 fra = Pub_Com.GetFrameWait(ref Ie, "fraHyou"); Doc = (mshtml.HTMLDocument)fra.document; eles = Doc.getElementsByTagName("input"); foreach (mshtml.IHTMLElement ele in eles) { try { if (ele.getAttribute("value").ToString() == "継 続") { ele.click(); Pub_Com.SleepAndWaitComplete(Ie); goto endOfForLoop; } } catch (Exception) { } } endOfForLoop: 1.GetHashCode(); //VBConversions note: C# requires an executable line here, so a dummy line was added. } catch (Exception) { } AddProBar(lv2); //15 return; } catch (Exception) { //DoStep1_SinkiMitumori(事業所, 得意先, 下店, 現場名, 備考, 日付連番, fl) return; } }