Ejemplo n.º 1
0
        private void sb_readAndSaveSubGroupsToDB(int groupIdParent, bool getAttach, string attachmentDirPath)
        {
            wagonPartsGroupsDataTable dt = new wagonPartsGroupsDataTable(1, 0, false);
            string html;
            int    rowIndex;


            this.v_webBrowser.FindElement(By.Id("__tab_ContentPlaceHolder1_TabContainer1_SetPanel")).Click();
            html = this.v_webBrowser.PageSource;

            if (!string.IsNullOrEmpty(html))
            {
                dt.Rows.Clear();
                Functions.sb_fillDatatableWithHtmlTableId(html, v_tableIdSub, dt);
                this.sb_fillDatatablePSID(html, v_tableIdSub, 1, dt);
                if (dt.Rows.Count > 0)
                {
                    this.sb_saveGroupsToDB(dt, groupIdParent);
                }

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

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

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

                        this.sb_readAndSavePartsToDB(groupId, dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_groupName].ToString()
                                                     , getAttach, attachmentDirPath);
                        this.sb_readAndSaveSubGroupsToDB(groupId, getAttach, attachmentDirPath + (attachmentDirPath.EndsWith("\\") ? "" : "\\") + 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);
                            this.v_webBrowser.FindElement(By.Id("__tab_ContentPlaceHolder1_TabContainer1_SetPanel")).Click();
                            SharedFunctions.sb_waitForReady(this.v_webBrowser);
                        }
                    }
                }
                catch (Exception ex2)
                {
                }
            }
        }
Ejemplo n.º 2
0
        private void sb_saveGroupsToDB(wagonPartsGroupsDataTable dt, int?idGroupParent)
        {
            if (dt == null)
            {
                return;
            }
            int    i;
            bool   add;
            string groupName;

            Model.rwmmsWagonPartsGroup entry_wagonPartsGroup;
            using (var entityLogistic = new Model.logisticEntities())
            {
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    add = false;
                    if (Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName]))
                    {
                        continue;
                    }
                    groupName             = dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName].ToString();
                    entry_wagonPartsGroup = entityLogistic.rwmmsWagonPartsGroups.FirstOrDefault(o => o.IdGroupParent == idGroupParent &&
                                                                                                o.wGroupName == groupName);
                    if (entry_wagonPartsGroup == null)
                    {
                        add = true;
                        entry_wagonPartsGroup = new Model.rwmmsWagonPartsGroup();
                    }

                    entry_wagonPartsGroup.FetchTime     = DateTime.Now;
                    entry_wagonPartsGroup.IdGroupParent = idGroupParent;
                    entry_wagonPartsGroup.wGroupName    = Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName]) ? null : dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName].ToString();
                    entry_wagonPartsGroup.wPSID         = Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_psid]) ? null : dt.Rows[i][wagonPartsGroupsDataTable.fld_psid].ToString();
                    entry_wagonPartsGroup.wSerialNo     = Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_serialNo]) ? null : dt.Rows[i][wagonPartsGroupsDataTable.fld_serialNo].ToString().Replace(" ", "").Replace("\r\n", "");

                    if (add)
                    {
                        entityLogistic.rwmmsWagonPartsGroups.Add(entry_wagonPartsGroup);
                    }
                    else
                    {
                        entityLogistic.Entry(entry_wagonPartsGroup).State = System.Data.Entity.EntityState.Modified;
                    }
                    try
                    {
                        entityLogistic.SaveChanges();
                        dt.Rows[i][wagonPartsGroupsDataTable.fld_id] = entry_wagonPartsGroup.Id;
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //string v_buttonSearchId = "ContentPlaceHolder1_cmdSearch";
        //string v_spanPageRowCountId = "ContentPlaceHolder1_lblRecordCount";
        public wagonPartsGroups()
        {
            this.v_downloadPath = Environment.CurrentDirectory + "\\Files\\rwmms\\wagonParts\\";
            this.v_dt           = new wagonPartsGroupsDataTable(1, 1, true);

            this.v_webBrowserService = ChromeDriverService.CreateDefaultService();
            this.v_webBrowserService.HideCommandPromptWindow = true;

            this.v_webBrowserOptions = new ChromeOptions();
            //this.v_webBrowserOptions.AddArgument("--headless");
            this.v_webBrowserOptions.AddUserProfilePreference("download.default_directory", this.v_downloadPath);
            this.v_webBrowser = new ChromeDriver(this.v_webBrowserService, this.v_webBrowserOptions);

            this.v_pageCount = seleniumDownloader.fnc_getPageCount(this.v_webBrowser, this.v_url, this.v_tableId, true);
        }