Example #1
0
        private void LoadCustomer(WebBrowser webBrowser1)
        {
            try
            {
                HtmlWindowCollection coll = webBrowser1.Document.Window.Frames;
                foreach (HtmlWindow win in coll)
                {
                    HtmlElement ele = win.Document.GetElementById("tMemCardID");
                    if (ele != null)
                    {
                        TicketOrder ticketOrder = new TicketOrder();
                        if (ticketOrder.LoadTicketOrder(txtOrderId.Text.Trim()))
                        {
                            win.Document.GetElementById("tPNR").SetAttribute("value", ticketOrder.PNR);

                            System.Web.Caching.Cache cache = System.Web.HttpRuntime.Cache;
                            cache.Add("TicketOrderInfo", ticketOrder, null, DateTime.MaxValue, new TimeSpan(0, 5, 0), System.Web.Caching.CacheItemPriority.Normal, null);
                        }

                        ele.SetAttribute("value", ticketOrder.CardNum);
                        win.Document.GetElementById("tMemName").SetAttribute("value", ticketOrder.MemberName);

                        ele = win.Document.GetElementById("bMemInfo");
                        ele.InvokeMember("Click");
                        fillData = BLL.FillData.填写PNR;
                        break;
                    }
                }
            }
            catch { }
        }
Example #2
0
    public void PrintStatus(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        HtmlWindow           currWin = wb.Document.Window;
        HtmlWindowCollection frames  = currWin.Frames;

        System.Console.WriteLine("Frame count: " + frames.Count);
    }
Example #3
0
 private void ChildMenu(WebBrowser browser)
 {
     try
     {
         HtmlWindowCollection coll = browser.Document.Window.Frames;
         foreach (HtmlWindow win in coll)
         {
             HtmlElement ele = win.Document.GetElementById("LeftMenuTable");
             if (ele != null)
             {
                 HtmlElementCollection eleCollection = ele.All;
                 foreach (HtmlElement el in eleCollection)
                 {
                     if (el.InnerText == "机票预订")
                     {
                         el.Parent.Parent.InvokeMember("Click");
                         process = BLL.ProcessControl.打开菜单;
                         break;
                     }
                 }
             }
         }
     }
     catch { }
 }
Example #4
0
 private void Navigate(WebBrowser browser)
 {
     try
     {
         HtmlWindowCollection coll = browser.Document.Window.Frames;
         foreach (HtmlWindow win in coll)
         {
             HtmlElement ele = win.Document.GetElementById("LeftMenuTable");
             if (ele != null)
             {
                 HtmlElementCollection eleCollection = ele.All;
                 foreach (HtmlElement el in eleCollection)
                 {
                     if (el.InnerText == "订单导入")
                     {
                         el.GetElementsByTagName("a")[0].InvokeMember("Click");
                         process  = BLL.ProcessControl.填充数据;
                         fillData = BLL.FillData.填写会员卡号;
                         break;
                     }
                 }
             }
         }
     }
     catch { }
 }
Example #5
0
        private void FillData(WebBrowser browser)
        {
            try
            {
                HtmlWindowCollection coll = browser.Document.Window.Frames;
                foreach (HtmlWindow win in coll)
                {
                    HtmlDocument doc     = win.Document;
                    HtmlElement  element = doc.GetElementById("tSendContactName");
                    if (element != null)
                    {
                        System.Web.Caching.Cache cache = System.Web.HttpRuntime.Cache;
                        object      obj         = cache.Get("TicketOrderInfo");
                        TicketOrder ticketOrder = null;
                        if (obj == null)
                        {
                            ticketOrder = new TicketOrder();
                            ticketOrder.LoadTicketOrder(txtOrderId.Text.Trim());
                        }
                        else
                        {
                            ticketOrder = obj as TicketOrder;
                        }

                        ChangeData(doc, ticketOrder);
                        ChangeTicket(doc, ticketOrder);
                    }
                }
            }
            catch { }
        }
Example #6
0
 public void FillInForm(string Expression)
 {
     this.mainfrm.DisplayProgress("Filling Forms...");
     Expression = Expression.Replace("&", "&");
     Expression = HttpUtility.UrlDecode(Expression, this.mainfrm.CurrentSite.WebEncoding);
     string[] array = Expression.Split(new char[]
     {
         '&'
     });
     for (int j = 0; j < array.Length; j++)
     {
         string   str           = array[j];
         string[] paraNameValue = WebSite.GetParaNameValue(str, '=');
         try
         {
             this.WCRBrowser.Document.All[paraNameValue[0]].SetAttribute("value", GlobalObject.unescape(paraNameValue[1]));
         }
         catch
         {
         }
         HtmlWindowCollection frames = this.WCRBrowser.Document.Window.Frames;
         for (int i = 0; i < frames.Count; i++)
         {
             try
             {
                 this.WCRBrowser.Document.Window.Frames[i].Document.All[paraNameValue[0]].SetAttribute("value", GlobalObject.unescape(paraNameValue[1]));
             }
             catch
             {
             }
         }
     }
     this.mainfrm.DisplayProgress("Done");
 }
Example #7
0
 /// <summary>
 /// Obtener el string HTML de un IFrame. Se busca recursivamente dentro de child frames o sub-frames
 /// </summary>
 /// <param name="pHtmlDoc">HtmlDocument donde se va a buscar</param>
 /// <param name="pFrameIdentifier">Identificador del IFrame HTML</param>
 /// <returns>String del HTML del IFrame, si no se encuentra se obtiene string.Empty</returns>
 public static string GetHtmlFromFrameByIdentifier(HtmlDocument pHtmlDoc, string pFrameIdentifier = null)
 {
     try
     {
         if (pHtmlDoc == null)
         {
             return(string.Empty);
         }
         string vHtml = string.Empty;
         // Evaluar si el HtmlDocument tiene frames
         HtmlWindowCollection vParentFrames = GetFramesFromDocument(pHtmlDoc);
         if (vParentFrames != null)
         {
             // Recorrer los frames del HtmlDocument
             foreach (HtmlWindow vParentFrame in vParentFrames)
             {
                 if (FrameIsNotNull(vParentFrame))
                 {
                     // Si se conoce el Id del frame, entonces se busca por Id, de lo contrario se busca para todos los frames
                     bool vByIdentifier = !string.IsNullOrWhiteSpace(pFrameIdentifier) ? vParentFrame.WindowFrameElement.Id.Equals(pFrameIdentifier) : true;
                     if (vByIdentifier)
                     {
                         // Obtener el HTML del frame
                         vHtml = BodyHasHtmlFromDocument(vParentFrame.Document) ? vParentFrame.Document.Body.InnerHtml : vHtml;
                         break;
                     }
                     // Evaluar si el HtmlDocument del frame tiene frames (child frames o sub-frames)
                     else if (GetFramesFromDocument(vParentFrame.Document) != null)
                     {
                         // Buscar recursivamente el HTML dentro de los child frames
                         vHtml = GetHtmlFromFrameByIdentifier(vParentFrame.Document, pFrameIdentifier);
                     }
                     else
                     {
                         vHtml = string.Empty;
                     }
                 }
                 else
                 {
                     vHtml = string.Empty;
                 }
             }
         }
         else
         {
             vHtml = string.Empty;
         }
         return(vHtml);
     }
     catch (NullReferenceException vE)
     {
         return(string.Empty);
     }
     catch (Exception vE)
     {
         throw vE;
     }
 }
        void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser.Document.MouseOver  += new HtmlElementEventHandler(Document_MouseOver);
            webBrowser.Document.MouseLeave += new HtmlElementEventHandler(Document_MouseLeave);
            HtmlWindowCollection frames = webBrowser.Document.Window.Frames;

            foreach (HtmlWindow frame in frames)
            {
                frame.Document.MouseOver  += new HtmlElementEventHandler(Document_MouseOver);
                frame.Document.MouseLeave += new HtmlElementEventHandler(Document_MouseLeave);
            }
        }
Example #9
0
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            HtmlWindowCollection coll = (sender as WebBrowser).Document.Window.Frames;
            string       s            = "function alert(){}; function confirm(){ return true;};";//function open(){};function window.showModalDialog(){};";
            IHTMLWindow2 win1         = null;

            foreach (HtmlWindow win in coll)
            {
                win1 = (IHTMLWindow2)win.DomWindow;
                win1.execScript(s, "javascript");
            }
        }
Example #10
0
        /// <summary>
        /// Obtener un HtmlElement de HtmlDocument.Window.Frames
        /// </summary>
        /// <param name="pHtmlDoc">HtmlDocument donde se va a buscar</param>
        /// <param name="pIdentifier">Identificador del elemento que se está buscando (id o name o attribute)</param>
        /// <returns>HtmlElement encontrado o nulo si no se encontró</returns>
        public static HtmlElement GetHtmlElementFromFrames(HtmlDocument pHtmlDoc, string pIdentifier)
        {
            try
            {
                if (pHtmlDoc == null)
                {
                    return(null);
                }
                HtmlElement          vHtmlElement  = null;
                HtmlWindowCollection vParentFrames = GetFramesFromDocument(pHtmlDoc);
                if (vParentFrames != null)
                {
                    foreach (HtmlWindow vParentFrame in vParentFrames)
                    {
                        if (vHtmlElement == null)
                        {
                            try
                            {
                                if (FrameIsNotNull(vParentFrame))
                                {
                                    vHtmlElement = vParentFrame.Document.GetElementById(pIdentifier) != null
                                    ? vParentFrame.Document.GetElementById(pIdentifier)
                                    : (vParentFrame.Document.All[pIdentifier] != null ? vParentFrame.Document.All[pIdentifier] : null);

                                    if (vHtmlElement == null)
                                    {
                                        if (GetFramesFromDocument(vParentFrame.Document) != null)
                                        {
                                            vHtmlElement = GetHtmlElementFromFrames(vParentFrame.Document, pIdentifier);
                                        }
                                    }
                                }
                            }
                            catch (Exception vE)
                            {
                                // Continuar si falla
                                continue;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                return(vHtmlElement);
            }
            catch (Exception vE)
            {
                throw vE;
            }
        }
Example #11
0
 /// <summary>
 /// Obtener listado de HtmlElement de HtmlDocument.Window.Frames por nombre de etiqueta
 /// </summary>
 /// <param name="pHtmlDoc">HtmlDocument donde se va a buscar</param>
 /// <param name="pTag">Nombre de la etiqueta para hacer la búsqueda</param>
 /// <returns>HtmlElementCollection listado de HtmlElement</returns>
 public static HtmlElementCollection GetHtmlElementsFromFramesByTagName(HtmlDocument pHtmlDoc, string pTag)
 {
     try
     {
         HtmlElementCollection vHtmlElements = null;
         HtmlWindowCollection  vParentFrames = GetFramesFromDocument(pHtmlDoc);
         if (vParentFrames != null)
         {
             foreach (HtmlWindow vParentFrame in vParentFrames)
             {
                 if (vHtmlElements == null)
                 {
                     try
                     {
                         if (FrameIsNotNull(vParentFrame))
                         {
                             vHtmlElements = vParentFrame.Document.GetElementsByTagName(pTag).Count > 0
                                 ? vParentFrame.Document.GetElementsByTagName(pTag) : null;
                             if (vHtmlElements == null)
                             {
                                 if (GetFramesFromDocument(vParentFrame.Document) != null)
                                 {
                                     vHtmlElements = GetHtmlElementsFromFramesByTagName(vParentFrame.Document, pTag);
                                 }
                             }
                         }
                     }
                     catch (Exception vE)
                     {
                         // Continuar si falla
                         continue;
                     }
                 }
                 else
                 {
                     break;
                 }
             }
         }
         return(vHtmlElements);
     }
     catch (Exception vE)
     {
         throw vE;
     }
 }
Example #12
0
 string getSpecificFrameByUrl(string url, HtmlWindowCollection frames, bool textOnly)
 {
     foreach (HtmlWindow frame in frames)
     {
         if (frame.Url.ToString().Contains(url))
         {
             if (frame.Document.Body == null)
             {
                 return("");
             }
             else
             {
                 return((textOnly) ? frame.Document.Body.InnerText : frame.Document.Body.InnerHtml);
             }
         }
     }
     return(null);
 }
Example #13
0
 private void SubmitOrder(WebBrowser browser)
 {
     try
     {
         HtmlWindowCollection coll = browser.Document.Window.Frames;
         foreach (HtmlWindow win in coll)
         {
             HtmlElement element = win.Document.GetElementById("bOrderSave");
             if (element != null)
             {
                 element.InvokeMember("Click");
                 isTrue = true;
                 break;
             }
         }
     }
     catch { }
 }
Example #14
0
        }// end of OnTimer

        //获取网页源代码
        public void fetch()
        {
            WebBrowser web = this.webBrowser1;

            if (timer_state == 1)
            {
                web.Refresh();
                flag = 1;
            }

            if (flag == 1) //确定已打开正确网页
            {
                /*检测table中是否有元素来检测js是否执行完成*/
                File.Delete("html.txt");

                HtmlWindowCollection htmlwc = web.Document.Window.Frames; //获取所有iframe框架
                foreach (HtmlWindow win in htmlwc)
                {
                    if (win.Document.Body != null) //记录第一层iframe框架
                    {
                        HtmlDocument hdc = win.Document;
                        foreach (HtmlElement element in hdc.Body.All)
                        {
                            if (element.TagName.ToLower().Equals("table")) //find table
                            {
                                foreach (HtmlElement child in element.All) //find the special element
                                {
                                    string id = child.GetAttribute("id").ToLower();
                                    if (id == "datagrid-row-r1-2-0") //第一行的id存在说明js已执行
                                    {
                                        string htmlStr = win.Document.Body.InnerHtml;
                                        htmlStr = htmlStr.Replace("\r\n", "");
                                        File.AppendAllText("html.txt", htmlStr);
                                        flag = 2;
                                        process(htmlStr);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #15
0
        public void menuWirelessStatistics()
        {
            try
            {
                //Buscar el frame correspondiente donde se encuentra los botones a partir del name
                HtmlWindowCollection frame = _web.Document.Window.Frames;

                //Buscar el botón Wireless por ID y ejecutar el click
                frame[1].Document.GetElementById("a12").InvokeMember("click");

                //Luego de completarse la carga de la página terminar ciclo de ejecución
                accionWeb = FuenteMacs.FPrincipal.AccionWeb.ninguna;
            }
            catch (Exception ex)
            {
                //Evitar un posible bucle infinito
                accionWeb = FuenteMacs.FPrincipal.AccionWeb.ninguna;

                ControlLog.EscribirLog(ControlLog.TipoGravedad.WARNING, "ControlWeb.cs", "menuWirelessStatistics", "Error al intentar acceder a la vista de WirelessStatistics: " + ex.Message);
            }
        }
Example #16
0
        private void LoadPNR(WebBrowser webBrowser1)
        {
            try
            {
                HtmlWindowCollection coll = webBrowser1.Document.Window.Frames;
                foreach (HtmlWindow win in coll)
                {
                    HtmlElement ele = win.Document.GetElementById("tPNR");
                    if (ele != null)
                    {
                        win.Document.GetElementById("bA").InvokeMember("Click");

                        process  = BLL.ProcessControl.提交;
                        fillData = BLL.FillData.初始化;

                        break;
                    }
                }
            }
            catch { }
        }
Example #17
0
        private bool FindChildFrames(HtmlWindow n)
        {
            HtmlWindowCollection x = n.Document.Window.Frames;

            if (x.Count < 1)
            {
                richTextBox1.Text += "IN THE ROOT\n";
                return(false);
            }
            else
            {
                richTextBox1.Text += "---->Diving\n";
                foreach (HtmlWindow w in x)
                {
                    if (FindChildFrames(w) == false)
                    {
                        PrintAllElements(w);
                    }
                }
                return(true);
            }
        }
Example #18
0
        /// <summary>
        /// This method iterates recursively through the <see cref="HtmlWindowCollection"/>
        ///   of a webbrowser document get the maximal scroll size of the containing frames.
        /// </summary>
        /// <param name="htmlWindows">
        /// The first <see cref="HtmlWindowCollection"/>
        ///   to start parsing. You get it from browser.Document.Window.Frames
        /// </param>
        /// <param name="currentScrollsize">
        /// Ref. A <see cref="Size"/> to be updated with
        ///   maximal scroll size values.
        /// </param>
        private static void GetLargestScrollSizeOfAllFrames(HtmlWindowCollection htmlWindows, ref Size currentScrollsize)
        {
            foreach (HtmlWindow window in htmlWindows)
            {
                try
                {
                    HtmlDocument document = window.Document;
                    if (document == null)
                    {
                        continue;
                    }

                    GetMaxScrollSizeOfDocument(document, ref currentScrollsize);
                    if (document.Window != null)
                    {
                        GetLargestScrollSizeOfAllFrames(document.Window.Frames, ref currentScrollsize);
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    ExceptionMethods.HandleExceptionSilent(ex);
                }
            }
        }
Example #19
0
        //Intenta obtener la lista de MACs
        public List <String> obtenerListaMac()
        {
            try
            {
                List <String> lsMac = new List <string>();

                //Buscar el frame correspondiente donde se encuentra los botones a partir del name
                HtmlWindowCollection frame = _web.Document.Window.Frames;

                //Buscar la tabla que contiene los datos de las estadísticas
                HtmlElement tabla = frame[2].Document.GetElementsByTagName("TBODY")[1];

                //Obtener las filas
                HtmlElementCollection filas = tabla.GetElementsByTagName("tr");

                //Verificar que la tabla es correcta, verificando el título de la misma
                if (filas[0].GetElementsByTagName("td")[1].InnerText == "MAC Address")
                {
                    //Recorrer las filas, excepto el primero q son los títulos, y obtener cada una de las MACs
                    for (int i = 1; i < filas.Count; i++)
                    {
                        //Obtener la segunda columna, que es donde esta la MAC y añadir a la lista
                        lsMac.Add(filas[i].GetElementsByTagName("td")[1].InnerText);
                    }

                    //Reiniciar contador
                    reintentos = Datos.cantidadReintentosAnteFallo;

                    return(lsMac);
                }
                else
                {
                    //La vista no es la correcta, muy probablemente

                    //Reducir el número de reintentos
                    reintentos--;
                    if (reintentos == 0)
                    {
                        //Volver a navegar desde el inicio, reiniciar contador
                        reintentos = Datos.cantidadReintentosAnteFallo;
                        iniciarNavegacion();
                    }

                    ControlLog.EscribirLog(ControlLog.TipoGravedad.WARNING, "ControlWeb.cs", "obtenerListaMac", "Error al intentar leer las direcciones Macs de la web, la tabla leida no es la correcta, título leido: " + filas[0].GetElementsByTagName("td")[1].InnerText);

                    return(null);
                }
            }
            catch (Exception ex)
            {
                //Reducir el número de reintentos
                reintentos--;
                if (reintentos == 0)
                {
                    //Volver a navegar desde el inicio, reiniciar contador
                    reintentos = Datos.cantidadReintentosAnteFallo;
                    iniciarNavegacion();
                }

                ControlLog.EscribirLog(ControlLog.TipoGravedad.WARNING, "ControlWeb.cs", "obtenerListaMac", "Error al intentar leer las direcciones Macs de la web: " + ex.Message);
                return(null);
            }
        }