private void sb_saveOwnersDetailsToDB(DataTable dt, int cycleNumber)
        {
            if (dt == null)
            {
                return;
            }
            int i;

            Model.rwmmsVehicleOwnersDetail entry_vehicleOwnersDetail;
            bool   add;
            string meliNo;

            using (var entityLogistic = new Model.logisticEntities())
            {
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    add = false;
                    if (!Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo]))
                    {
                        meliNo = dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo].ToString();
                        entry_vehicleOwnersDetail = entityLogistic.rwmmsVehicleOwnersDetails.FirstOrDefault(o => o.wMeliNo == meliNo);
                        if (entry_vehicleOwnersDetail == null)
                        {
                            add = true;
                            entry_vehicleOwnersDetail = new Model.rwmmsVehicleOwnersDetail();
                        }
                    }
                    else
                    {
                        entry_vehicleOwnersDetail = new Model.rwmmsVehicleOwnersDetail();
                        add = true;
                    }
                    //entry_vehicleOwnersDetail.companyId = companyId;
                    entry_vehicleOwnersDetail.CycleNumber   = cycleNumber;
                    entry_vehicleOwnersDetail.FetchTime     = DateTime.Now;
                    entry_vehicleOwnersDetail.Source        = "rwmms";
                    entry_vehicleOwnersDetail.wEmail        = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_email]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_email].ToString();
                    entry_vehicleOwnersDetail.wFName        = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_fname]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_fname].ToString();
                    entry_vehicleOwnersDetail.wLName        = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_lname]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_lname].ToString();
                    entry_vehicleOwnersDetail.wMeliNo       = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo].ToString();
                    entry_vehicleOwnersDetail.wMobileNumber = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_mobileNumber]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_mobileNumber].ToString();
                    if (add)
                    {
                        entityLogistic.rwmmsVehicleOwnersDetails.Add(entry_vehicleOwnersDetail);
                    }
                    else
                    {
                        entityLogistic.Entry(entry_vehicleOwnersDetail).State = System.Data.Entity.EntityState.Modified;
                    }
                    entityLogistic.SaveChanges();
                }
            }
        }
Beispiel #2
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();
                                }
                            }
                        }
                    }
                }
            }
        }