Esempio n. 1
0
        private void btnGetCookie_Click(object sender, EventArgs e)
        {
            string pCookie = FullWebBrowserCookie.GetCookieInternal(webBrowser1.Url, false);

            txtMsg.Text += pCookie + "\r\n";
            PostRequest("2018-08", pCookie);
        }
Esempio n. 2
0
        private void realizaDescarga()
        {
            try
            {
                for (int i = 0; i < links.Count; i++)
                {
                    Match o = regexURL.Match(links[i].OuterHtml);
                    if (o.Success)
                    {
                        Match f = regexFolio.Match(folios[i].OuterHtml);
                        if (f.Success)
                        {
                            urls.Add(f.Groups[1].Value, $"https://portalcfdi.facturaelectronica.sat.gob.mx/{o.Value}");
                        }
                    }
                }
                if (urls.Count == 0)
                {
                    MessageBox.Show("No hay ningun XML por descargar...");
                }
                else if (MessageBox.Show($"Quieres descargar {urls.Count} XML's ?", "Aviso", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    pbDownload.Minimum = 0;
                    pbDownload.Value   = 0;
                    pbDownload.Maximum = folios.Count;
                    pbDownload.Visible = true;
                    var       cookies = FullWebBrowserCookie.GetCookieInternal(webbrowser.Url, false);
                    WebClient wc      = new WebClient();
                    wc.Headers.Add("Cookie: " + cookies);
                    wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");


                    if (string.IsNullOrWhiteSpace(Properties.Settings.Default["downloadPath"].ToString()))
                    {
                        MessageBox.Show($"Primero configure una carpeta de descargas");

                        return;
                    }
                    if (!Directory.Exists(Properties.Settings.Default["downloadPath"].ToString()))
                    {
                        Directory.CreateDirectory(Properties.Settings.Default["downloadPath"].ToString());
                    }
                    foreach (var file in urls)
                    {
                        wc.DownloadFile(file.Value, $@"{Properties.Settings.Default["downloadPath"]}\{file.Key}.xml");
                        pbDownload.Value += 1;
                    }
                    MessageBox.Show($"Descarga finalizada!, se descargaron {urls.Count} archivos en {Properties.Settings.Default["downloadPath"]} ");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ocurrio un error en la descarga");
            }
            finally
            {
                pbDownload.Visible = false;
            }
        }
Esempio n. 3
0
 private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     curCookie = FullWebBrowserCookie.GetCookieInternal(e.Url, false);
     //InitialValue();
 }
Esempio n. 4
0
        private void _webBrowser_DATA_DocumentCompleted(int id, List <string> reginos)
        {
            //计算保存位置
            string text = _CurrentLabel.InnerText;
            //   HtmlElement tr = _CurrentLabel.Parent.Parent;

            //HtmlElement span = _webBrowser.Document.GetElementById("SCR001R01:kakakuTreeGroup");
            //HtmlElementCollection hc = span.GetElementsByTagName("tr");

            //foreach (HtmlElement he in hc)
            //{
            //    if (he == tr)
            //    {

            //        break;
            //    }
            //    HtmlElementCollection ls = he.GetElementsByTagName("label");



            //    if (ls.Count > 0)
            //    {
            //        HtmlElement label = ls[0];
            //        if (label.GetAttribute("onclick") == EsEkisanSite.TREE_NO_CLICK_TAG)
            //        {
            //            string text = label.InnerText;

            //            if (!string.IsNullOrEmpty(text) && text != EsEkisanSite.TREE_ROOT_TEXT)
            //            {
            //                dirPath.Append("\\");
            //                dirPath.Append(text);
            //            }
            //        }
            //        else
            //        {
            //            break;//跳出
            //        }



            //    }

            //}



            //
            //while (printBtn == null)
            //{
            //    System.Threading.Thread.Sleep(100);
            //    Application.DoEvents();
            //    printBtn = GetHtmlElementByName("SCR001R01:j_idt129");
            //}
            HtmlElement table    = GetTableObject();
            HtmlElement printBtn = GetHtmlElementByName("SCR001R01:j_idt129");

            while (printBtn == null || printBtn.OuterHtml.IndexOf("disabled") != -1)
            {
                printBtn = GetHtmlElementByName("SCR001R01:j_idt129");
                System.Threading.Thread.Sleep(100);
                Application.DoEvents();
                System.Diagnostics.Debug.WriteLine("等待打印按钮");
            }

            //System.Threading.Thread.Sleep(10000);
            printBtn.InvokeMember("click");
            //   _webBrowser.Document.InvokeScript("listHeaderPrint");
            _PrintLoadTime = 0;

            int sum = 0;

            while (_PrintLoadTime != 1)
            {
                sum += 100;
                if (sum % EsEkisanSite.MAX_TIME == 0)
                {
                    printBtn.InvokeMember("click");
                    //  _webBrowser.Document.InvokeScript("listHeaderPrint");
                }
                System.Diagnostics.Debug.WriteLine("等待激活打印窗体");
                System.Threading.Thread.Sleep(100);
                Application.DoEvents();
            }


            //多县下载
            for (int i = 0; i < reginos.Count; i++)
            {
                string regin_number = reginos[i];


                StringBuilder dirPath  = new StringBuilder(txtSavePath.Text + "\\単価リスト(一覧)");
                string        sDirPath = dirPath.ToString();
                if (!Directory.Exists(sDirPath))
                {
                    Directory.CreateDirectory(sDirPath);
                }
                dirPath.Append("\\");
                dirPath.Append(id);
                dirPath.Append("_");
                dirPath.Append(regin_number);
                dirPath.Append("_");
                dirPath.Append(text);
                dirPath.Append(EsEkisanSite.DOWNLOAD_FILE_TYPE);
                string filePath = dirPath.ToString();



                if (File.Exists(filePath) && false)
                {
                    //文件存在不下载
                    return;
                }
                else
                {
                    StringBuilder sb = new StringBuilder("処理中 <");
                    sb.Append(regin_number);
                    sb.Append(" ");
                    sb.Append(text);

                    sb.Append("> ,保存したファイルの場所は:");
                    sb.Append(filePath);
                    SetAppState(sb.ToString());


                    string http_regin_number = regin_number == "00" ? "" : regin_number;
                    string postDataStr       = GetPostDataString(http_regin_number);
                    string cookie            = Convert.ToString(FullWebBrowserCookie.GetCookieInternal(new Uri(GetCurrentUrl()), false));

                    Action action = () =>
                    {
                        DownLoadFile(filePath, postDataStr, cookie);
                    };

                    Task taks = new Task(action);
                    //最多5个线程下载
                    while (_Task.Count >= 5)
                    {
                        for (int k = _Task.Count - 1; k >= 0; k--)
                        {
                            if (_Task[k].IsCompleted)
                            {
                                _Task.RemoveAt(k);
                            }
                        }
                        System.Threading.Thread.Sleep(100);
                        Application.DoEvents();
                    }
                    _Task.Add(taks);
                    taks.Start();
                }
                Application.DoEvents();
            }


            //关闭打印窗体

            //while (_webBrowser.Document.GetElementById("GUIDANCE_SPAN") == null)
            //{
            //    System.Threading.Thread.Sleep(100);
            //    Application.DoEvents();
            //}

            HtmlElement span = _webBrowser.Document.GetElementById("GUIDANCE_SPAN");

            sum = 0;
            while (span == null)
            {
                sum += 100;
                System.Threading.Thread.Sleep(100);
                Application.DoEvents();
                span = _webBrowser.Document.GetElementById("GUIDANCE_SPAN");
                if (sum == EsEkisanSite.MAX_TIME)
                {
                    break;
                }
                System.Diagnostics.Debug.WriteLine("查找打印窗体,查找到之后关闭.");
            }
            if (span != null)
            {
                HtmlElementCollection hc = span.GetElementsByTagName("img");
                foreach (HtmlElement he in hc)
                {
                    string src = he.GetAttribute("src");

                    if (src.EndsWith(EsEkisanSite.CLOSE_BUTTON_ICON))
                    {
                        he.InvokeMember("click");
                    }
                }
            }

            table.OuterHtml = String.Empty;
            //sum = 0;
            //while (true)
            //{
            //    sum += 100;
            //    System.Threading.Thread.Sleep(100);
            //    Application.DoEvents();

            //    if (sum ==10000)
            //    {
            //        break;
            //    }
            //    System.Diagnostics.Debug.WriteLine("程序等待十秒");
            //}
            //  _webBrowser.Document.GetElementById("GUIDANCE_SPAN").OuterHtml = "";
            //  _webBrowser.Document.GetElementById("FILTER_DIV").OuterHtml = "";
        }