コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loginAndLogout">for those pages which have bugs in access controls</param>
        public void sb_readAllControlsAndSaveToDB(bool loginAndLogout)
        {
            login lg = new login();

            if (loginAndLogout)
            {
                lg = new login();
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
            }
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.prp_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
                this.v_webBrowser.Navigate().GoToUrl(this.prp_url);
            }

            this.sb_readCombosAndSaveToDB();
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cycleNumber"></param>
        /// <param name="getExtraDetail">getExtraDetail like fathername and ....</param>
        public void sb_readAllAndSaveToDB(int cycleNumber, bool getExtraDetail)
        {
            login lg = new login();

            lg.fnc_logoutWithSelenium(this.v_webBrowser);
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
            }


            int    pageIndex = 0;
            string html;
            bool   logoutAndLogin = getExtraDetail;

            for (pageIndex = 0; pageIndex <= this.v_pageCount - 1; pageIndex++)
            {
                //if we should get extraDetail we should logout and then login again
                pageIndex = this.fnc_gotoPage(pageIndex, logoutAndLogin);
                if (pageIndex == -1)
                {
                    return;
                }

                html = this.v_webBrowser.PageSource;

                if (!string.IsNullOrEmpty(html))
                {
                    this.v_dtOwners.Rows.Clear();
                    Functions.sb_fillDatatableWithHtmlTableId(html, v_tableId, 1, 1, 0, 0, this.v_dtOwners);
                    if (this.v_dtOwners.Rows.Count > 0)
                    {
                        this.sb_saveOwnersDetailsToDB(this.v_dtOwners, cycleNumber);
                    }
                    if (getExtraDetail)
                    {
                        this.sb_readExtraDetailAndSaveToDB(cycleNumber, pageIndex);
                    }
                }
                else
                {
                    break;
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logoutAndLogin">logout current webDriver and login again to see all owners</param>
        /// <returns></returns>
        public int fnc_getPageCount(bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
            }
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
            }

            this.v_webBrowser.Navigate().GoToUrl(this.v_url);
            SharedFunctions.sb_waitForReady(this.v_webBrowser);
            string html          = this.v_webBrowser.PageSource;
            int    lastPageIndex = 0;
            var    table         = Functions.fnc_getElementById(html, this.v_tableId);

            if (table != null)
            {
                var tbody = table.SelectSingleNode("tbody");
                var rows  = tbody.SelectNodes("tr");
                if (rows != null && rows.Count > 0)
                {
                    var lastRow        = rows[rows.Count - 1];
                    var td             = lastRow.SelectSingleNode("td");
                    var hrefCollection = td.SelectNodes("a");
                    if (hrefCollection != null && hrefCollection.Count > 0)
                    {
                        var pageIndexStr = hrefCollection[hrefCollection.Count - 1].InnerText;
                        int temp;
                        if (int.TryParse(pageIndexStr, out temp))
                        {
                            lastPageIndex = temp;
                        }
                    }
                }
            }
            return(lastPageIndex);
        }
コード例 #4
0
        public static int fnc_getPageCountWithRowCount(IWebDriver webBrowser, string url, string controlIdRowCount, string controlIdToClick, bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }

            if (!string.IsNullOrEmpty(controlIdToClick))
            {
                sb_click(webBrowser, url, controlIdToClick, false);
            }
            int lastPageIndex = -1;
            var elRowCount    = webBrowser.FindElement(By.Id(controlIdRowCount));

            //int paginationGroup = 0;
            if (elRowCount != null)
            {
                if (int.TryParse(elRowCount.Text, out lastPageIndex))
                {
                    return(lastPageIndex / v_paginationSize + (lastPageIndex % v_paginationSize > 0 ? 1 : 0));
                }
            }
            return(lastPageIndex);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="logoutAndLogin">logout current webDriver and login again to see all owners</param>
        public int fnc_gotoPage(int pageIndex, bool logoutAndLogin, bool waitTillReady = true)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
            }
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
            }

            if (this.v_pageCount == -1)
            {
                this.v_pageCount = this.fnc_getPageCount(false);
            }
            if (pageIndex > this.v_pageCount)
            {
                return(-1);
            }

            if (pageIndex == 0)
            {
                this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                if (waitTillReady)
                {
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                }
                return(pageIndex);
            }
            else
            {
                this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                SharedFunctions.sb_waitForReady(this.v_webBrowser);
                var table = this.v_webBrowser.FindElementById(v_tableId);
                if (table != null)
                {
                    var rows = table.FindElements(By.TagName("tr"));
                    if (rows != null && rows.Count > 0)
                    {
                        var lastRow = rows[rows.Count - 1];
                        var td      = lastRow.FindElement(By.TagName("td"));
                        if (td != null)
                        {
                            var hrefCollection = td.FindElements(By.TagName("a"));
                            if (pageIndex <= hrefCollection.Count)
                            {
                                hrefCollection[pageIndex - 1].Click();
                                if (waitTillReady)
                                {
                                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                                }
                                return(pageIndex);
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
        }
コード例 #6
0
        public void sb_readAndSaveToDB(bool loginAndLogout, bool getAttach)
        {
            if (loginAndLogout)
            {
                login lg = new login();
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
                if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
                {
                    lg.fnc_loginWithSelenium(this.v_webBrowser);
                    this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                }
            }

            int    pageIndex = 1;
            int    rowIndex;
            string html;

            using (var entityLogistic = new Model.logisticEntities())
            {
                for (pageIndex = 1; pageIndex <= this.v_pageCount; pageIndex++)
                {
                    Program.logs.Info("Start of :" + pageIndex);
                    //if we should get extraDetail we should logout and then login again
                    if (pageIndex > 1)
                    {
                        pageIndex = seleniumDownloader.fnc_gotoPage(this.v_webBrowser, this.v_url, this.v_tableId, pageIndex, this.v_pageCount, false);
                        if (pageIndex == -1)
                        {
                            return;
                        }
                    }

                    html = this.v_webBrowser.PageSource;

                    if (!string.IsNullOrEmpty(html))
                    {
                        this.v_dt.Rows.Clear();
                        Functions.sb_fillDatatableWithHtmlTableId(html, v_tableId, this.v_dt);
                        this.sb_fillDatatablePSID(html, v_tableId, 2, this.v_dt);
                        if (this.v_dt.Rows.Count > 0)
                        {
                            this.sb_saveGroupsToDB(this.v_dt, null);
                        }
                    }
                    else
                    {
                        break;
                    }

                    try
                    {
                        int groupId;
                        for (rowIndex = 0; rowIndex <= this.v_dt.Rows.Count - 1; rowIndex++)
                        {
                            if (Functions.IsNull(this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_id]))
                            {
                                continue;
                            }

                            groupId = int.Parse(this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_id].ToString());

                            var el    = this.v_webBrowser.FindElement(By.Id(this.v_tableId));
                            var rows  = el.FindElements(By.TagName("tr"));
                            var cells = rows[rowIndex + this.v_dt.prp_skipRowTop].FindElements(By.TagName("td"));
                            cells[2].Click();
                            SharedFunctions.sb_waitForReady(this.v_webBrowser);

                            var queryString = HttpUtility.ParseQueryString(this.v_webBrowser.Url);
                            if (!Functions.IsNull(queryString["psid"]))
                            {
                                var entryPartGroup = entityLogistic.rwmmsWagonPartsGroups.FirstOrDefault(o => o.Id == groupId);
                                if (entryPartGroup != null)
                                {
                                    entryPartGroup.wPSID = queryString["psid"];
                                    entityLogistic.SaveChanges();
                                }
                            }
                            this.sb_readAndSavePartsToDB(groupId, this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_groupName].ToString(), getAttach
                                                         , this.v_downloadPath);
                            this.sb_readAndSaveSubGroupsToDB(groupId, getAttach, this.v_downloadPath + (this.v_downloadPath.EndsWith("\\") ? "" : "\\") + this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_groupName].ToString());

                            var elPath         = this.v_webBrowser.FindElement(By.Id(this.v_pathElementId));
                            var hrefCollection = elPath.FindElements(By.TagName("a"));
                            if (hrefCollection != null && hrefCollection.Count > 0)
                            {
                                hrefCollection[hrefCollection.Count - 1].Click();
                                SharedFunctions.sb_waitForReady(this.v_webBrowser);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    Program.logs.Info("End of :" + pageIndex);
                }
            }
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="webBrowser"></param>
        /// <param name="url"></param>
        /// <param name="tableId"></param>
        /// <param name="controlIdToClick">to get pagecount in some pages we need to click a control if this parameter is specified
        /// this function click the control</param>
        /// <param name="logoutAndLogin">for some pages to get all rows we need logoutAndLogin set to true</param>
        /// <returns></returns>
        public static int fnc_getPageCount(IWebDriver webBrowser, string url, By tableBy, string controlIdToClick, bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }
            if (!string.IsNullOrEmpty(controlIdToClick))
            {
                sb_click(webBrowser, url, controlIdToClick, false);
            }
            int lastPageIndex = -1;
            int temp, i;

            getPageSource : string html = webBrowser.PageSource;
            var table = webBrowser.FindElement(tableBy);

            //int paginationGroup = 0;
            if (table != null)
            {
                List <IWebElement> rows;
                try
                {
                    var tbody = table.FindElement(By.TagName("tbody"));
                    if (tbody != null)
                    {
                        rows = tbody.FindElements(By.TagName("tr")).ToList();
                    }
                    else
                    {
                        rows = table.FindElements(By.TagName("tr")).ToList();
                    }
                }
                catch
                {
                    rows = table.FindElements(By.TagName("tr")).ToList();
                }

                if (rows != null && rows.Count > 0)
                {
                    //we have atleast one page
                    lastPageIndex = 1;
                    var lastRow        = rows[rows.Count - 1];
                    var td             = lastRow.FindElement(By.TagName("td"));
                    var hrefCollection = td.FindElements(By.TagName("a"));
                    if (hrefCollection != null && hrefCollection.Count > 0)
                    {
                        if (/*v_nextPaginationGroupPos <= hrefCollection.Count
                             * &&*/hrefCollection[hrefCollection.Count - 1].Text == v_nextPaginationText)
                        {
                            //we have next page so we should have next paginationgroup
                            hrefCollection[hrefCollection.Count - 1].Click();
                            SharedFunctions.sb_waitForReady(webBrowser);
                            goto getPageSource;
                            //paginationGroup++;
                        }
                        else
                        {
                            //we do not have nextPaginationGroup
                            for (i = 0; i <= hrefCollection.Count - 1; i++)
                            {
                                if (int.TryParse(hrefCollection[i].Text, out temp))
                                {
                                    if (temp > lastPageIndex)
                                    {
                                        lastPageIndex = temp;
                                    }
                                }
                            }
                            return(lastPageIndex);
                        }
                        //if (hrefCollection.Count < v_paginationSize)
                        //{
                        //    //we do not have next paginiation for example we have only 3 pages and paginzationsize is 10
                        //    var pageIndexStr = hrefCollection[hrefCollection.Count - 1].Text;
                        //    int temp;
                        //    if (int.TryParse(pageIndexStr, out temp))
                        //    {
                        //        lastPageIndex = temp + (paginationGroup * v_paginationSize);
                        //    }
                        //}
                        //else if (hrefCollection.Count > v_paginationSize)
                        //{
                        //    //we have more pages than paginzationsize. e.g. we have 12 pages while paginationsize is 10
                        //    hrefCollection[v_nextPaginationGroupPos].Click();
                        //    SharedFunctions.sb_waitForReady(webBrowser);
                        //    paginationGroup++;

                        //}
                        //else if (hrefCollection.Count == v_paginationSize)
                        //{
                        //    //there are three possibilities paginationsize = 10 and we have 10 pages
                        //    //or we have 19 pages in second group we will have 9 pages and previous button
                        //    //or we have 9 pages  + nextPagination we have 10 hrefCollection
                        //    //so => hrefCollection.Count == v_paginationSize
                        //    if (hrefCollection[v_nextPaginationGroupPos].Text == v_nextPaginationText)
                        //    {
                        //        hrefCollection[v_nextPaginationGroupPos].Click();
                        //        SharedFunctions.sb_waitForReady(webBrowser);
                        //        paginationGroup++;
                        //    }
                        //    else
                        //    {
                        //        var pageIndexStr = hrefCollection[hrefCollection.Count - 1].Text;
                        //        int temp;
                        //        if (int.TryParse(pageIndexStr, out temp))
                        //        {
                        //            lastPageIndex = temp + (paginationGroup * v_paginationSize);
                        //        }
                        //    }
                        //}
                    }
                }
            }
            return(lastPageIndex);
        }
コード例 #8
0
        public static int fnc_gotoPage(IWebDriver webBrowser, string url, By tableBy, int pageIndex, int pageCount, bool logoutAndLogin
                                       , bool waitTillReady = true)
        {
            int i, temp, max, min;

            min = int.MaxValue;
            max = int.MinValue;
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }

            if (pageCount == -1)
            {
                pageCount = fnc_getPageCount(webBrowser, url, tableBy, false);
            }
            if (pageIndex > pageCount)
            {
                return(-1);
            }

            if (pageIndex == 1)
            {
                webBrowser.Navigate().GoToUrl(url);
                if (waitTillReady)
                {
                    SharedFunctions.sb_waitForReady(webBrowser);
                }
                return(pageIndex);
            }
            else
            {
                //webBrowser.Navigate().GoToUrl(url);
                //SharedFunctions.sb_waitForReady(webBrowser);
                var table = webBrowser.FindElement(tableBy);
                if (table != null)
                {
                    var rows = table.FindElements(By.TagName("tr"));
                    if (rows != null && rows.Count > 0)
                    {
                        var lastRow = rows[rows.Count - 1];
                        var td      = lastRow.FindElement(By.TagName("td"));
                        if (td != null)
                        {
                            var hrefCollection = td.FindElements(By.TagName("a")).ToList();
                            var hrefCollectionAndCurrentPage = hrefCollection.ToList();
                            hrefCollectionAndCurrentPage.AddRange(td.FindElements(By.TagName("span")).ToList());

                            var hrefPage = hrefCollectionAndCurrentPage.FirstOrDefault(o => o.Text == pageIndex.ToString());
                            if (hrefPage != null)
                            {
                                hrefPage.Click();
                                if (waitTillReady)
                                {
                                    SharedFunctions.sb_waitForReady(webBrowser);
                                }
                                return(pageIndex);
                            }
                            else
                            {
                                for (i = 0; i <= hrefCollectionAndCurrentPage.Count - 1; i++)
                                {
                                    if (int.TryParse(hrefCollectionAndCurrentPage[i].Text, out temp))
                                    {
                                        if (temp < min)
                                        {
                                            min = temp;
                                        }
                                        if (temp > max)
                                        {
                                            max = temp;
                                        }
                                    }
                                }
                                if (min == int.MaxValue || max == int.MinValue)
                                {
                                    //we cannot find any href with integer text
                                    return(-1);
                                }
                                if (min <= pageIndex && pageIndex <= max)
                                {
                                    //page index is between min and max but we could find the page in previous step so there is a problem
                                    return(-1);
                                }
                                if (pageIndex < min)
                                {
                                    //go to previous page
                                    if (hrefCollection.Count >= v_previousPaginationGroupPos &&
                                        hrefCollection[v_previousPaginationGroupPos].Text == v_previousPaginationText)
                                    {
                                        hrefCollection[v_previousPaginationGroupPos].Click();
                                        if (waitTillReady)
                                        {
                                            SharedFunctions.sb_waitForReady(webBrowser);
                                        }

                                        return(fnc_gotoPage(webBrowser, url, tableBy, pageIndex, pageCount, logoutAndLogin));
                                    }
                                }
                                else if (pageIndex > max)
                                {
                                    //go to next page
                                    if (/*hrefCollection.Count >= v_nextPaginationGroupPos
                                         * &&*/hrefCollection[hrefCollection.Count - 1].Text == v_nextPaginationText)
                                    {
                                        hrefCollection[hrefCollection.Count - 1].Click();
                                        if (waitTillReady)
                                        {
                                            SharedFunctions.sb_waitForReady(webBrowser);
                                        }

                                        return(fnc_gotoPage(webBrowser, url, tableBy, pageIndex, pageCount, logoutAndLogin));
                                    }
                                }

                                return(-1);
                            }
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
        }
コード例 #9
0
        public void sb_readAndSaveToDB(bool getOwners, bool getIntroductionFiles, int cycleNumber)
        {
            try
            {
                int   i;
                login lg = new login();
start:
                if (login.v_cookieCollection == null)
                {
                    if (!lg.fnc_login())
                    {
                        //cannot login
                        return;
                    }
                }
                Uri uri;
                Model.rwmmsVehicleOwner entry_company;
                uri = new Uri(this.v_url);
                string postData;
                string introductionFilePath;

                HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

                //webRequest.Headers.Add("Accept-Language", "en-US,en;q=0.8");
                webRequest.Proxy  = null;
                webRequest.Method = "POST";

                //webRequest.Headers.Add("Cache-Control", "no-cache");
                webRequest.ContentType = "application/x-www-form-urlencoded";

                webRequest.CookieContainer = new CookieContainer();
                foreach (System.Net.Cookie cookie in login.v_cookieCollection)
                {
                    webRequest.CookieContainer.Add(cookie);
                }

                postData = "__EVENTTARGET="
                           + "&__EVENTARGUMENT="
                           + "&__VIEWSTATE=19gB2KPXunfoY1KhdzKAuxbd%2FOoFmZ3EhsltmoK2s2VkBDy6lwwZr7rC25jXm%2BQIJEpBZnx2gjOlf8C0mpGh%2FkEaSfPTf9k%2BqaLrna5Oyeq%2BPbp9AU6oxxViHFeoRwvzEz%2FawXFACHm5L3aqOHniXVtwr%2FH5EgML96nGzzM6ycEhi56B%2B56Lt2045a%2Fy%2F0fOAXo3c2qy%2F6Wb4tWlH3WHViqY2XkJT12CIxTRoupHoPcVNeYbLMPR1Y99a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ri5RU5PgqtmZg0HV8%2Bulislnd2mGZrlJ6BTAszhnFQRBXCNlZCLY9HKqBdabUAxRsELjO7W%2F2UDg0Ja2%2BSklAOZb5Oy6kSrW24PICP1PLHrtdq6wxmRVAAwhWnp7ZSHTkPW1fEJ3%2FY9Bzidn8%2FQ1Cb%2Baj4BV%2FF6OLZ%2FK3p7qngg6zuJ3OhcrX5P73vJ33QD0bgcLo%2FZcV5CN6AexEsLbaO%2FXQVLZGTnQPwmtTNRD1mbqp60ipL%2Fke%2FUP2sX1eTMR1dzRNHlm4R%2Bh0YESHqSucqMECXIuwpKiaaH5kcvYriqIQXFXf7IuiWG0f2LuoJmx9jRNUR33gqnaHha749ki6jCJ4shYGiZ0Ell6wQctVCM0qPRIrCy8zdBhkEdKzKBaEuK88yQQ%3D%3D"
                           + "&__VIEWSTATEGENERATOR=FB6C6F2C"
                           + "&__VIEWSTATEENCRYPTED="
                           + "&__EVENTVALIDATION=CKs99QiiMJ2E9XqMrGTdqJtDalYRrpoJ1Ty8fuaFf8MEYdyFhb%2B2UnhIQ%2FeF4I7Xork8TUH7TPKn7LxdAlD93Inzzu5FFypSQacV45UIx%2BUmf2r4SRUCYHACHx27AL4Msa%2BfUbhd6zqoR2y6unlVfAGu8Pri9%2BHV1rNG2BhpF2o4cvbKC1eVjT9PwdmfS4qqHhUyM2ukCLM3LTnpKyoEcUV1aaKde5DcdFYwA4cdDaXH8emhnCNdujHMDutHAU1esPtPuplPYDv7PoTyMZtLRgcr8Zbk7Pe6%2FpEnynfBB7eGMrz5cNGJwlW8qWpzOxQmv1OroRLQwiCGO%2FoyJijp6tZICRvXMEPyur2Kbt3mdfB%2B4DGXZulYWcy84KKOL1k1LuIXwSMD3Kr6HSyChodoReYuNsfmiM%2BRbh32rsQ3WHnBgYAQnZTKuthxBVnD9EPzNZtLe1VGgA2ol%2FYF1o8DnGuyzAejQ6%2B7HJJ4GdezJrM2FpcLNmdvZSn5m3UCMbx6tLKE1mx7MzarMM%2B7bGh3xZ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1RHrvXXoxIfkXn7lsvW3QdvxdCBnnYWMN%2FE3GOcLnEoirJt%2BS31cn0uRPIpApDODga1Jig2%2B8lx7GdUlucWMxmOrXFzU1pBBLn8QKYIDxgn7UgSySyyfWVNthiZokkEsWsZyONzDg%2Fr9OD563xqw9hkHuLb1ba4y4eL9XzcnguO2XAZgNteGjDB62iXHdaO8evAuHazGDGcqbdhz2H1dMen1n%2B31%2B57NXNLGSsOZoQf3aI14g3nA9%2FZ6ch2UDu2yD8vURW7HnihCH6XfzWwgz89z4W0bvdyW0AipjMV%2BbZYvHjsRXo8ewuRvvnPeTKaupWsPFJXZsZs7H2Qi92pFFkr%2BGeFDWaHnQ50Vm3KAHn2Fl7HX6Ch9sgw57SUz4jDowNyaSYZBx3vKB%2BLmy1DY%2B8iueprOqM0mbn9Zpgfh23%2BvFR3%2FBaqrDUx9xk34l4Bt7RJPvAzvmLsesA8aGrwT7npF2N0bTN4y5uOQpQWX3BpbhNJi1VuM%2F7PlN5apaEXnSQUVUrwnZKd3bw5h4eF0BLUYlli1XmK%2BdCj3MwSsWF%2Fl9YS03wCvKvU2oeWyv%2Fyd49t7BJupZWp1YyXb6OpUb9HQxeHb7xg6YNHDuiMkJYmsLQB0IZMp%2FUYM%2BoBpl2wbq1AvK4c0Q1KEaMK"
                           + "&ctl00%24ContentPlaceHolder1%24txtRegisterDate="
                           + "&ctl00%24ContentPlaceHolder1%24txtRegisterNumber="
                           + "&ctl00%24ContentPlaceHolder1%24txtNationalCode="
                           + "&ctl00%24ContentPlaceHolder1%24txtRegisterLocation="
                           + "&ctl00%24ContentPlaceHolder1%24btnSearch=%D8%AC%D8%B3%D8%AA%D8%AC%D9%88";
                byte[] formData = Encoding.ASCII.GetBytes(postData);

                webRequest.ContentLength = formData.Length;
                Stream streamRequest = webRequest.GetRequestStream();
                streamRequest.Write(formData, 0, formData.Length);
                streamRequest.Flush();
                streamRequest.Close();

                HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
                if (webResponse != null)
                {
                    if (webResponse.ResponseUri == null || string.IsNullOrEmpty(webResponse.ResponseUri.AbsoluteUri))
                    {
                        webResponse.Close();
                        return;
                    }
                    if (login.fnc_isLoginPage(webResponse, this.v_url))
                    {
                        //we haven't loginned yet
                        if (lg.fnc_login())
                        {
                            goto start;
                        }
                        else
                        {
                            //cannot login inform or log !!!!!
                            webResponse.Close();
                            return;
                        }
                    }
                    string result;
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("utf-8")))
                    {
                        result = rd.ReadToEnd();
                    }
                    webResponse.Close();
                    if (!string.IsNullOrEmpty(result))
                    {
                        this.v_dt.Rows.Clear();
                        Functions.sb_fillDatatableWithHtmlTableId(result, "ContentPlaceHolder1_dgVehicleOwners", 1, 1, 0, 0, this.v_dt);
                        for (i = 0; i <= this.v_dt.Rows.Count - 1; i++)
                        {
                            introductionFilePath = null;

                            this.sb_saveToDB(this.v_dt, cycleNumber, introductionFilePath, out entry_company);
                            if (getIntroductionFiles && entry_company != null)
                            {
                                introductionFilePath            = this.fnc_getIntroductionFile(entry_company.Id, entry_company.wCompanyName, i);
                                entry_company.wIntroductionFile = introductionFilePath;
                                using (var entityLogistic = new Model.logisticEntities())
                                {
                                    entityLogistic.Entry(entry_company).State = System.Data.Entity.EntityState.Modified;
                                    entityLogistic.SaveChanges();
                                }
                            }

                            if (getOwners && entry_company != null)
                            {
                                this.sb_readOwnerDetail(entry_company.Id, cycleNumber);
                                //this.readAndSaveOwnerDetailToDB(entry_company.Id, cycleNumber);
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
            }
        }
コード例 #10
0
        private void sb_readOwnerDetail(int companyId, int cycleNumber)
        {
            login lg = new login();

            lg.fnc_loginWithSelenium(this.v_webBrowser);

            bool   add;
            string tableId = "ContentPlaceHolder1_dgVehicleOwners";

            this.v_webBrowser.Navigate().GoToUrl(this.v_url);
            SharedFunctions.sb_waitForReady(this.v_webBrowser);
            var btnSearch = this.v_webBrowser.FindElement(By.Id("ContentPlaceHolder1_btnSearch"));

            if (btnSearch == null)
            {
                return;
            }
            btnSearch.Click();
            SharedFunctions.sb_waitForReady(this.v_webBrowser);
            var table = this.v_webBrowser.FindElement(By.Id(tableId));

            if (table == null)
            {
                return;
            }
            var rows = table.FindElements(By.TagName("tr"));

            if (rows == null || rows.Count < 3)
            {
                return;
            }
            var columns = rows[1].FindElements(By.TagName("td"));

            if (columns.Count >= 6)
            {
                var href = columns[6].FindElement(By.TagName("a"));
                if (href != null)
                {
                    href.Click();
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                    table = this.v_webBrowser.FindElement(By.Id("ContentPlaceHolder1_dgVehicleOwnerDetails"));
                    if (table == null)
                    {
                        return;
                    }
                    rows = table.FindElements(By.TagName("tr"));
                    if (rows == null || rows.Count < 3)
                    {
                        return;
                    }
                    columns = rows[1].FindElements(By.TagName("td"));
                    if (columns.Count >= 6)
                    {
                        href = columns[6].FindElement(By.TagName("a"));
                        if (href != null)
                        {
                            href.Click();
                            //SharedFunctions.sb_waitForReady(this.v_webBrowser);
                            SharedFunctions.sb_waitForReady(this.v_webBrowser);
                            string htmlEditPage = this.v_webBrowser.PageSource;
                            string firstName    = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtFirstName");
                            string lastName     = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtLastName");
                            string fatherName   = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtFatherName");
                            string certNo       = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtIdentityNumber");
                            string registerCity = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtIdentityRegisterLocation");
                            string meliNo       = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtNationalCode");

                            string postalCode   = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtAgentPostCode");
                            string email        = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtAgentEmail");
                            string mobileNumber = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtMobileNumber");
                            string birthDate    = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtBirthDate");
                            string address      = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtAgentAddress");
                            using (var entityLogistic = new Model.logisticEntities())
                            {
                                if (!string.IsNullOrEmpty(meliNo))
                                {
                                    add = false;
                                    var entryOwnerExtraDetail = entityLogistic.rwmmsVehicleOwnersDetails.FirstOrDefault(o => o.wMeliNo == meliNo);
                                    if (entryOwnerExtraDetail == null)
                                    {
                                        entryOwnerExtraDetail = new Model.rwmmsVehicleOwnersDetail();
                                        add = true;
                                    }

                                    entryOwnerExtraDetail.CycleNumber    = cycleNumber;
                                    entryOwnerExtraDetail.FetchTime      = DateTime.Now;
                                    entryOwnerExtraDetail.Source         = this.v_url;
                                    entryOwnerExtraDetail.vehicleOwnerId = companyId;
                                    entryOwnerExtraDetail.wAddress       = (Functions.IsNull(address) ? null : address);
                                    entryOwnerExtraDetail.wBirthDate     = (Functions.IsNull(birthDate) ? null : birthDate);
                                    entryOwnerExtraDetail.wCertNo        = (Functions.IsNull(certNo) ? null : certNo);
                                    entryOwnerExtraDetail.wEmail         = (Functions.IsNull(email) ? null : email);
                                    entryOwnerExtraDetail.wFatherName    = (Functions.IsNull(fatherName) ? null : fatherName);
                                    entryOwnerExtraDetail.wFName         = (Functions.IsNull(firstName) ? null : firstName);
                                    entryOwnerExtraDetail.wLName         = (Functions.IsNull(lastName) ? null : lastName);
                                    entryOwnerExtraDetail.wMeliNo        = (Functions.IsNull(meliNo) ? null : meliNo);
                                    entryOwnerExtraDetail.wMobileNumber  = (Functions.IsNull(mobileNumber) ? null : mobileNumber);
                                    entryOwnerExtraDetail.wPostalCode    = (Functions.IsNull(postalCode) ? null : postalCode);
                                    entryOwnerExtraDetail.wRegisterCity  = (Functions.IsNull(registerCity) ? null : registerCity);
                                    if (add)
                                    {
                                        entityLogistic.rwmmsVehicleOwnersDetails.Add(entryOwnerExtraDetail);
                                    }
                                    else
                                    {
                                        entityLogistic.Entry(entryOwnerExtraDetail).State = System.Data.Entity.EntityState.Modified;
                                    }
                                    entityLogistic.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #11
0
        public void sb_readAndSaveToDB(int cycleNumber, string ownerName, string typeName, bool getLastItems, bool getDetail, bool getAttach, bool loginAndLogout)
        {
            if (loginAndLogout)
            {
                login lg = new login();
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
                if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
                {
                    lg.fnc_loginWithSelenium(this.v_webBrowser);
                    this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                    seleniumDownloader.sb_click(this.v_webBrowser, this.v_url, this.v_buttonSearchId, false);
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                }
            }

            int    pageIndex = 1;
            string html;
            int    pageIndexStart = 1;

            if (getLastItems)
            {
                using (var entityLogistic = new Model.logisticEntities())
                {
                    int?maxPageNo = entityLogistic.rwmmsDeclerationLists.Where(o => o.wOwnerName == ownerName && o.wTypeName == typeName).Max(o => o.PageIndex);
                    if (maxPageNo.HasValue)
                    {
                        pageIndexStart = maxPageNo.Value;
                    }
                    else
                    {
                        pageIndexStart = 1;
                    }
                }
            }
            for (pageIndex = pageIndexStart; pageIndex <= this.v_pageCount; pageIndex++)
            {
                Program.logs.Info("Start of :" + pageIndex);
                //if we should get extraDetail we should logout and then login again
                if (pageIndex > 1)
                {
                    pageIndex = seleniumDownloader.fnc_gotoPage(this.v_webBrowser, this.v_url, this.v_tableId, pageIndex, this.v_pageCount, false);
                    if (pageIndex == -1)
                    {
                        return;
                    }
                }

                html = this.v_webBrowser.PageSource;

                if (!string.IsNullOrEmpty(html))
                {
                    this.v_dt.Rows.Clear();
                    Functions.sb_fillDatatableWithHtmlTableId(html, v_tableId, this.v_dt);
                    if (this.v_dt.Rows.Count > 0)
                    {
                        if (getDetail)
                        {
                            System.Collections.ObjectModel.ReadOnlyCollection <IWebElement> rows;
                            int i = this.v_dt.prp_skipRowTop;
                            do
                            //for (int i = this.v_dt.prp_skipRowTop; i <= rows.Count - this.v_dt.prp_skipRowBottom; i++)
                            {
                                rows = Functions.fnc_getSeleniumTableRows(this.v_webBrowser, this.v_tableId);
                                var cells = rows[i].FindElements(By.TagName("td"));
                                if (cells.Count >= 8)
                                {
                                    cells[8].Click();
                                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                                    Functions.sb_fillDataRowWithHtmlControls(this.v_webBrowser.PageSource, this.v_dt, this.v_dt.Rows[i - this.v_dt.prp_skipRowTop]);
                                    try
                                    {
                                        var btnCancel = this.v_webBrowser.FindElement(By.Id("ContentPlaceHolder1_cmdCancel"));
                                        btnCancel.Click();
                                        SharedFunctions.sb_waitForReady(this.v_webBrowser);
                                    }
                                    catch
                                    {
                                        return;
                                    }
                                }
                                i++;
                            } while (i < rows.Count - this.v_dt.prp_skipRowBottom);
                        }

                        if (getAttach)
                        {
                            this.sb_getAttach();
                        }
                        this.sb_saveToDB(this.v_dt, cycleNumber, pageIndex, ownerName, typeName, getDetail, getAttach);
                    }
                }
                else
                {
                    break;
                }
                Program.logs.Info("End of :" + pageIndex);
            }
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="webBrowser"></param>
        /// <param name="url"></param>
        /// <param name="grid"></param>
        /// <param name="controlIdToClick">to get pagecount in some pages we need to click a control if this parameter is specified
        /// this function click the control</param>
        /// <param name="logoutAndLogin">for some pages to get all rows we need logoutAndLogin set to true</param>
        /// <returns></returns>
        public static int fnc_getPageCount(IWebDriver webBrowser, string url, IWebElement grid
                                           , IWebElement rowCountElement, string rowCountLabelRegexPattern, int pageRowCount, bool logoutAndLogin)
        {
            if (rowCountElement != null)
            {
                var rowCountStr = rowCountElement.Text;
                int rowCount;
                if (!int.TryParse(rowCountStr, out rowCount))
                {
                    if (!string.IsNullOrEmpty(rowCountLabelRegexPattern))
                    {
                        rowCountStr = System.Text.RegularExpressions.Regex.Replace(rowCountStr, rowCountLabelRegexPattern, "");
                    }
                    rowCountStr = rowCountStr.Replace("&nbsp;", "");
                    rowCountStr = rowCountStr.Replace(" ", "");
                    rowCountStr = rowCountStr.Replace(",", "");
                    rowCountStr = rowCountStr.Replace("تعدادرکورد", "");
                    rowCountStr = rowCountStr.Replace("تعدادركورد", "");
                    rowCountStr = rowCountStr.TrimStart().TrimEnd();
                    rowCount    = int.Parse(rowCountStr);
                }
                return(rowCount / pageRowCount + (rowCount % pageRowCount > 0 ? 1 : 0));
            }
            else
            {
                login lg = new login();
                if (logoutAndLogin)
                {
                    lg.fnc_logoutWithSelenium(webBrowser);
                }
                if (login.fnc_isLoginPage(webBrowser.Url, url))
                {
                    lg.fnc_loginWithSelenium(webBrowser);
                    webBrowser.Navigate().GoToUrl(url);
                }

                if (webBrowser.Url.ToLower() != url.ToLower())
                {
                    webBrowser.Navigate().GoToUrl(url);
                    SharedFunctions.sb_waitForReady(webBrowser);
                }

                int lastPageIndex = -1;
                int temp, i;
                getPageSource : string html = webBrowser.PageSource;

                //int paginationGroup = 0;
                if (grid != null)
                {
                    List <IWebElement> rows;
                    try
                    {
                        var tbody = grid.FindElement(By.TagName("tbody"));
                        if (tbody != null)
                        {
                            rows = tbody.FindElements(By.TagName("tr")).ToList();
                        }
                        else
                        {
                            rows = grid.FindElements(By.TagName("tr")).ToList();
                        }
                    }
                    catch
                    {
                        rows = grid.FindElements(By.TagName("tr")).ToList();
                    }

                    if (rows != null && rows.Count > 0)
                    {
                        //we have atleast one page
                        lastPageIndex = 1;
                        var lastRow        = rows[rows.Count - 1];
                        var td             = lastRow.FindElement(By.TagName("td"));
                        var hrefCollection = td.FindElements(By.TagName("a"));
                        if (hrefCollection != null && hrefCollection.Count > 0)
                        {
                            if (/*v_nextPaginationGroupPos <= hrefCollection.Count
                                 * &&*/hrefCollection[hrefCollection.Count - 1].Text == v_nextPaginationText)
                            {
                                //we have next page so we should have next paginationgroup
                                hrefCollection[hrefCollection.Count - 1].Click();
                                SharedFunctions.sb_waitForReady(webBrowser);
                                goto getPageSource;
                                //paginationGroup++;
                            }
                            else
                            {
                                //we do not have nextPaginationGroup
                                for (i = 0; i <= hrefCollection.Count - 1; i++)
                                {
                                    if (int.TryParse(hrefCollection[i].Text, out temp))
                                    {
                                        if (temp > lastPageIndex)
                                        {
                                            lastPageIndex = temp;
                                        }
                                    }
                                }
                                return(lastPageIndex);
                            }
                        }
                    }
                }
                return(lastPageIndex);
            }
        }