Example #1
0
        /// <summary>
        /// Get a list of postcodes that match the search criteria
        /// </summary>
        /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
        /// <param name="criteria">Postcode Lookup search criteria</param>
        /// <returns></returns>
        public PostcodeLookupReturnValue PostcodeLookupSearch(HostSecurityToken oHostSecurityToken, PostcodeLookupSearchCriteria criteria)
        {
            PostcodeLookupReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oContactService = new ContactService();
                returnValue     = oContactService.PostcodeLookupSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), criteria);
            }
            else
            {
                returnValue         = new PostcodeLookupReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
        protected void PostcodeLookup(string AmbiguityId, string SearchStatus)
        {
            try
            {
                ContactServiceClient      contactService    = new ContactServiceClient();
                PostcodeLookupReturnValue returnValue       = new PostcodeLookupReturnValue();
                CollectionRequest         collectionRequest = new CollectionRequest();
                collectionRequest.StartRow = 0;
                PostcodeLookupSearchCriteria criteria = new PostcodeLookupSearchCriteria();

                criteria.Address = new Address();
                criteria.Address.OrganisationName  = _txtOrganisation.Text;
                criteria.Address.PostBox           = _txtPOBox.Text;
                criteria.Address.SubBuilding       = _txtSubBuildingName.Text;
                criteria.Address.HouseName         = _txtHouseName.Text;
                criteria.Address.StreetNumber      = _txtHouseNumber.Text;
                criteria.Address.Line1             = _txtAddress1.Text;
                criteria.Address.Line2             = _txtAddress2.Text;
                criteria.Address.Line3             = _txtAddress3.Text;
                criteria.Address.DependantLocality = _txtDeptLoc.Text;
                criteria.Address.Town     = _txtTown.Text;
                criteria.Address.County   = _txtCounty.Text;
                criteria.Address.PostCode = _txtPostcode.Text;
                criteria.Address.Country  = _txtCountry.Text;
                criteria.Address.DXNumber = _txtDXAddress1.Text;
                criteria.Address.DXTown   = _txtDXAddress2.Text;
                criteria.AmbiguityId      = AmbiguityId;
                criteria.SearchStatus     = SearchStatus;
                returnValue = contactService.PostcodeLookupSearch(_logonId, criteria);

                if (returnValue != null)
                {
                    //Add each address
                    if (returnValue.PostcodeLookup != null)
                    {
                        _trServiceError.Style["display"]      = "none";
                        _trServiceErrorSpace.Style["display"] = "none";
                        _listAddress.Style["display"]         = "";

                        _listAddress.Items.Clear();

                        foreach (PostcodeLookupSearchItem cAddress in returnValue.PostcodeLookup)
                        {
                            this._listAddress.Items.Add(CreateListViewItem(cAddress));
                        }
                    }
                    else
                    {
                        string msg = string.Empty;

                        if (string.IsNullOrEmpty(returnValue.Message))
                        {
                            msg = "No matching or ambiguous addresses could be found for these details.";
                        }
                        else
                        {
                            msg = returnValue.Message;
                        }

                        _trServiceError.Style["display"]      = "";
                        _trServiceErrorSpace.Style["display"] = "";
                        _listAddress.Style["display"]         = "none";
                        _lblServiceError.Text = msg;
                    }
                }
                else
                {
                    _trServiceError.Style["display"]      = "";
                    _trServiceErrorSpace.Style["display"] = "";
                    _listAddress.Style["display"]         = "none";
                    _lblServiceError.Text = "No matching or ambiguous addresses could be found for these details.";
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                _trServiceError.Style["display"]      = "";
                _trServiceErrorSpace.Style["display"] = "";
                _listAddress.Style["display"]         = "none";
                _lblServiceError.Text = ex.Message;
            }
            _mpePostcodeLookup.Show();
        }
        /// <summary>
        /// Get a list of postcodes that match the search criteria
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service.</param>
        /// <param name="criteria">Postcode Lookup search criteria</param>
        /// <returns></returns>
        public PostcodeLookupReturnValue PostcodeLookupSearch(Guid logonId, PostcodeLookupSearchCriteria criteria)
        {
            IrisLogManager _logError = new IrisLogManager(LogType.ERROR);

            PostcodeLookupReturnValue returnValue = new PostcodeLookupReturnValue();
            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            // Can do everything
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    StringBuilder sbQuery = new StringBuilder();

                    if (criteria.SearchStatus == string.Empty)
                    {

                        if (criteria.Address.HouseName != string.Empty)
                            sbQuery.Append(criteria.Address.HouseName + ", ");

                        if (criteria.Address.StreetNumber != string.Empty)
                            sbQuery.Append(criteria.Address.StreetNumber + ", ");

                        if (criteria.Address.Line1 != string.Empty)
                            sbQuery.Append(criteria.Address.Line1 + ", ");

                        if (criteria.Address.Line2 != string.Empty)
                            sbQuery.Append(criteria.Address.Line2 + ", ");

                        if (criteria.Address.DependantLocality != string.Empty)
                            sbQuery.Append(criteria.Address.DependantLocality + ", ");

                        if (criteria.Address.Line3 != string.Empty)
                            sbQuery.Append(criteria.Address.Line3 + ", ");

                        if (criteria.Address.Town != string.Empty)
                            sbQuery.Append(criteria.Address.Town + ", ");

                        if (criteria.Address.County != string.Empty)
                            sbQuery.Append(criteria.Address.County + ", ");

                        if (criteria.Address.PostCode != string.Empty)
                            sbQuery.Append(criteria.Address.PostCode + ", ");

                        while (sbQuery.Length > 0 && (sbQuery[sbQuery.Length - 1] == ' ' || sbQuery[sbQuery.Length - 1] == ','))
                        {
                            sbQuery.Length--;
                        }
                    }
                    else
                    {
                        sbQuery.Append(criteria.SearchStatus);
                    }

                    _logError.TraceMessage(" Query = " + sbQuery.ToString());

                    SrvPostcodeLookup postcodeLookup = new SrvPostcodeLookup();
                    List<CapscanAddress> results = postcodeLookup.CapscanQuery(sbQuery.ToString(), criteria.AmbiguityId);

                    _logError.TraceMessage(" CapscanQuery Results Count = " + results.Count);

                    List<PostcodeLookupSearchItem> postcodeItemList = new List<PostcodeLookupSearchItem>();

                    if (results.Count == 0)
                    {
                        returnValue = null;
                    }
                    else
                    {
                        //Add each address
                        foreach (CapscanAddress cAddress in results)
                        {
                            PostcodeLookupSearchItem postcodeItem = new PostcodeLookupSearchItem();
                            postcodeItem.AdminCounty = cAddress.admincounty;
                            postcodeItem.AmbiguityId = cAddress.ambiguityid;
                            postcodeItem.AmbiguityText = cAddress.ambiguitytext;
                            postcodeItem.Buildingname = cAddress.buildingname;
                            postcodeItem.BuildingNumber = cAddress.buildingnumber;
                            postcodeItem.Country = cAddress.country;
                            postcodeItem.County = cAddress.county;
                            postcodeItem.DepLocality = cAddress.deplocality;
                            postcodeItem.DepStreet = cAddress.depstreet;
                            postcodeItem.Locality = cAddress.locality;
                            postcodeItem.Organisation = cAddress.organisation;
                            postcodeItem.Postcode = cAddress.postcode;
                            postcodeItem.PostTown = cAddress.posttown;
                            postcodeItem.Resolved = cAddress.resolved;
                            postcodeItem.SearchStatus = cAddress.searchstatus;
                            postcodeItem.Street = cAddress.street;
                            postcodeItem.SubBuilding = cAddress.subbuilding;

                            postcodeItemList.Add(postcodeItem);
                        }

                        if (postcodeItemList != null)
                        {
                            returnValue.PostcodeLookup = postcodeItemList;
                        }
                    }

                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = "Could not load postcode lookup for the current user. <br>Exception: " + Ex.Message;
            }

            return returnValue;
        }
        protected void PostcodeLookup(string AmbiguityId, string SearchStatus)
        {
            try
            {
                ContactServiceClient contactService = new ContactServiceClient();
                PostcodeLookupReturnValue returnValue = new PostcodeLookupReturnValue();
                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.StartRow = 0;
                PostcodeLookupSearchCriteria criteria = new PostcodeLookupSearchCriteria();

                criteria.Address = new Address();
                criteria.Address.OrganisationName = _txtOrganisation.Text;
                criteria.Address.PostBox = _txtPOBox.Text;
                criteria.Address.SubBuilding = _txtSubBuildingName.Text;
                criteria.Address.HouseName = _txtHouseName.Text;
                criteria.Address.StreetNumber = _txtHouseNumber.Text;
                criteria.Address.Line1 = _txtAddress1.Text;
                criteria.Address.Line2 = _txtAddress2.Text;
                criteria.Address.Line3 = _txtAddress3.Text;
                criteria.Address.DependantLocality = _txtDeptLoc.Text;
                criteria.Address.Town = _txtTown.Text;
                criteria.Address.County = _txtCounty.Text;
                criteria.Address.PostCode = _txtPostcode.Text;
                criteria.Address.Country = _txtCountry.Text;
                criteria.Address.DXNumber = _txtDXAddress1.Text;
                criteria.Address.DXTown = _txtDXAddress2.Text;
                criteria.AmbiguityId = AmbiguityId;
                criteria.SearchStatus = SearchStatus;
                returnValue = contactService.PostcodeLookupSearch(_logonId, criteria);

                if (returnValue != null)
                {
                    //Add each address
                    if (returnValue.PostcodeLookup != null)
                    {
                        _trServiceError.Style["display"] = "none";
                        _trServiceErrorSpace.Style["display"] = "none";
                        _listAddress.Style["display"] = "";

                        _listAddress.Items.Clear();

                        foreach (PostcodeLookupSearchItem cAddress in returnValue.PostcodeLookup)
                        {
                            this._listAddress.Items.Add(CreateListViewItem(cAddress));

                        }
                    }
                    else
                    {
                        string msg = string.Empty;

                        if (string.IsNullOrEmpty(returnValue.Message))
                            msg = "No matching or ambiguous addresses could be found for these details.";
                        else
                            msg = returnValue.Message;

                        _trServiceError.Style["display"] = "";
                        _trServiceErrorSpace.Style["display"] = "";
                        _listAddress.Style["display"] = "none";
                        _lblServiceError.Text = msg;
                    }
                }
                else
                {
                    _trServiceError.Style["display"] = "";
                    _trServiceErrorSpace.Style["display"] = "";
                    _listAddress.Style["display"] = "none";
                    _lblServiceError.Text = "No matching or ambiguous addresses could be found for these details.";
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                _trServiceError.Style["display"] = "";
                _trServiceErrorSpace.Style["display"] = "";
                _listAddress.Style["display"] = "none";
                _lblServiceError.Text = ex.Message;
            }
            _mpePostcodeLookup.Show();
        }
 /// <summary>
 /// Get a list of postcodes that match the search criteria
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="criteria">Postcode Lookup search criteria</param>
 /// <returns></returns>
 public PostcodeLookupReturnValue PostcodeLookupSearch(HostSecurityToken oHostSecurityToken, PostcodeLookupSearchCriteria criteria)
 {
     PostcodeLookupReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oContactService = new ContactService();
         returnValue = oContactService.PostcodeLookupSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), criteria);
     }
     else
     {
         returnValue = new PostcodeLookupReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }