/// <summary>
        ///  Checks whether the added address is similar to an address already in the database and if not
        ///  store this address in a session variable to be added when the order is completed.
        /// </summary>
        private AddressValid GetAddress(bool createTable)
        {
            List <AddressManager> similarAddresses = new List <AddressManager>();
            List <AddressManager> currentAddresses = AddressManager.GetAddresses();
            AddressValid          addressSuccess   = new AddressValid();
            bool   addOrder = true;
            string addressLine1, addressLine2, city, zipOrPostcode, countyStateProvince, country;

            addressLine1 = addressLine1Txt.Text;
            addressSuccess.addressLine1 = addressLine1;
            addressLine2 = addressLine2Txt.Text;
            addressSuccess.addressLine2 = addressLine2;

            city = cityTxt.Text;
            addressSuccess.city = city;

            zipOrPostcode = zipOrPostcodeTxt.Text;
            addressSuccess.zipOrPostcode = zipOrPostcode;

            countyStateProvince = countyStateProvinceTxt.Text;
            addressSuccess.countyStateProvince = countyStateProvince;

            country = Variables.GetCountryByCode(Request["countryDdl"]);
            addressSuccess.country = country;

            string addeddAddress = addressLine1 + addressLine2 + city + zipOrPostcode + countyStateProvince + country;

            foreach (AddressManager address in currentAddresses)
            {
                int diff = FuzzySearching.LD(addeddAddress, address.GetAddressStrWithoutBreaks());
                if (diff == 0)
                {
                    addressSuccess.existingAddress = address;
                    addOrder = true;
                }
                //Only get addresses that have less than 5 characters different
                else if (diff < 5)
                {
                    similarAddresses.Add(address);
                    addOrder                    = false;
                    addressesTbl.Visible        = false;
                    similarAddressesTbl.Visible = true;
                }
            }

            if (similarAddresses.Count > 0 && createTable == true)
            {
                AddSimilarHeaderRow();
                LoadAddresses(similarAddresses);
            }

            addressSuccess.addresses = similarAddresses;
            addressSuccess.addOrder  = addOrder;
            return(addressSuccess);
        }
예제 #2
0
        private void LoadCompanies()
        {
            long prevID = 0;
            int  addressCount = 0;
            List <CompanyManager> companies, filteredCompanies = new List <CompanyManager>();
            string searchText = companyNameTxt.Text;

            TableRow row = new TableRow();

            companies = CompanyManager.GetCompanies();

            if (searchText != "")
            {
                foreach (CompanyManager company in companies)
                {
                    //For if there is a small spelling mistake
                    int diff = FuzzySearching.LD(company.CompanyName, searchText);
                    if (diff < 3 || company.CompanyName.Contains(searchText, StringComparison.OrdinalIgnoreCase))
                    {
                        filteredCompanies.Add(company);
                    }
                }
                companies = filteredCompanies;
            }

            foreach (CompanyManager company in companies.OrderBy(x => x.CompanyID))
            {
                //Put all addresses for each company in the same cell
                if (company.CompanyID != prevID)
                {
                    row = new TableRow();

                    AddCell(row, company.CompanyName);
                    AddCell(row, company.CompanyDescription);
                    AddCell(row, company.PhoneNo);
                    AddCell(row, company.EmailAddress);
                    addressCount = 1;
                }
                else
                {
                    addressCount++;
                    TableCell cell = (TableCell)CompaniesTbl.FindControl(company.CompanyID.ToString());
                }
                prevID = company.CompanyID;
            }
        }