QAS Pro。某些地址的问题

时间:2013-08-15 15:28:58

标签: c# vba search postal-code

我为一家使用QAS Pro近2年的呼叫中心工作。我们使用访问数据库中的资源DLL与内部托管的QAS服务器进行通信。它唯一的用途是根据邮政编码收集地址详细信息。因此,第一个函数从该邮政编码中获取一个地址列表,将它们插入到访问中的组合框中。操作员可以选择适当的地址后将其插入正确的字段。

这是由不再和我们在一起的开发人员编写的。我的工作是修复代码。通过一些测试,我已经能够验证它是我们使用的c#代码而不是地址。由于测试工具工作正常。

资源DLL使用QAS中的c#测试代码和一些额外的文件来实现一些功能。我是c#的新手,之前从未做过类似的事情。任何帮助表示赞赏。

这是一位老同事写的代码。

  namespace MangoQAS
{
    using com.qas.proweb;
    using System;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;

    [ComVisible(true)]
    public class QAS
    {
        public QAS()
        {
            QuickAddress address = new QuickAddress("http://10.10.15.7:2021") {
                Engine = QuickAddress.EngineTypes.Singleline,
                Flatten = true
            };
            this.searchService = address;
        }

        private string GetMoniker(string p)
        {
            return this.searchService.Search("GBR", p, PromptSet.Types.Default, "Database layout").Picklist.Items[0].Moniker;
        }

        public string[] RefinePostcode(string p)
        {
            string moniker = this.GetMoniker(p);
            FormattedAddress formattedAddress = this.searchService.GetFormattedAddress(moniker, "Database Layout");
            return new string[] { formattedAddress.AddressLines[0].Line, formattedAddress.AddressLines[1].Line, formattedAddress.AddressLines[2].Line, formattedAddress.AddressLines[3].Line, formattedAddress.AddressLines[4].Line, formattedAddress.AddressLines[5].Line, formattedAddress.AddressLines[6].Line };
        }

        public string[] SearchPostcodes(string postCode)
        {
            SearchResult result = this.searchService.Search("GBR", postCode, PromptSet.Types.OneLine, "Database layout");
            string[] strArray = new string[result.Picklist.Length];
            for (int i = 0; i < result.Picklist.Length; i++)
            {
                strArray[i] = result.Picklist.Items[i].Text;
            }
            return strArray;
        }

        private QuickAddress searchService { get; set; }
    }
}

SearchPostcodes - 根据邮政编码返回地址列表。 RefinePostcode - 获取地址行并发回格式化的地址。

问题似乎与RefinePostcode有关。我已经尝试格式化地址字符串,因为我的第一个想法是它不喜欢正斜杠。这没用。

例如,使用邮政编码:PA169AE 这让我:0/1 15 Brachelston Street,GREENOCK,Renfrewshire,位于组合框的顶部。
如果我点击这个地址,它将发回:1 Crossgates,Greenock Road,PA7 5JU 更改所有内容,包括我输入的邮政编码。

我认为问题出在RefinePostcode或GetMoniker上。下面的2个区块来自示例代码并且未更改,但可能需要进行诊断。

    public FormattedAddress GetFormattedAddress(string sMoniker, string sLayout)
    {
        Debug.Assert((sMoniker != null) && (sLayout != null));
        QAGetAddress qAGetAddress = new QAGetAddress {
            Layout = sLayout,
            Moniker = sMoniker,
            QAConfig = this.m_Config,
            Language = this.m_LanguageString
        };
        FormattedAddress address2 = null;
        try
        {
            address2 = new FormattedAddress(this.SearchService.DoGetAddress(qAGetAddress).QAAddress);
        }
        catch (Exception exception)
        {
            this.MapException(exception);
        }
        return address2;
    }


    public SearchResult Search(string sDataID, string sSearch, PromptSet.Types tPromptSet, string sLayout)
    {
        Debug.Assert(sDataID != null);
        Debug.Assert(sSearch != null);
        QASearch qASearch = new QASearch {
            Country = sDataID,
            Engine = this.m_Engine
        };
        qASearch.Engine.PromptSet = (PromptSetType) tPromptSet;
        qASearch.Engine.PromptSetSpecified = true;
        qASearch.Layout = sLayout;
        qASearch.QAConfig = this.m_Config;
        qASearch.Search = sSearch;
        qASearch.Language = this.m_LanguageString;
        SearchResult result = null;
        try
        {
            result = new SearchResult(this.SearchService.DoSearch(qASearch));
        }
        catch (Exception exception)
        {
            this.MapException(exception);
        }
        return result;
    }

我彻底搜查了谷歌,似乎无法找到任何理由。如果需要,我可以发布更多代码示例。

2 个答案:

答案 0 :(得分:2)

你知道这个吗?

从它的外观来看,我认为你在这里遇到的问题是搜索的背景。 QAS服务器和QuickAddress类都是无状态的 - 它们没有先前搜索的历史记录。

因为目前没有任何内容可以链接您的第一次搜索邮政编码,以及您在地址行上的第二次搜索。所以,当你打电话给RefinePostcode时,你根本就没有精炼。相反,你正在英国广泛的“0/1 15 Brachelston Street,GREENOCK,Renfrewshire”进行全新的搜索。虽然QAS专业版可以处理这个问题,但是这个搜索会产生一些可能性,因此你所追求的结果不是第一个返回的结果。

这里有一些改进工作流程的可能性。为了避免对您的VBA代码进行任何更改并仅限制对上面示例的更改,您可以向此类引入状态并更改工作流,以便您使用搜索传递邮政编码。类似于以下内容:

public class QAS
{
    public QAS()
    {       
        // Create a new soap proxy that can talk to QAS Pro Web   
        QuickAddress address = new QuickAddress("http://10.10.15.7:2021") 
        {
            Engine = QuickAddress.EngineTypes.Singleline,
            Flatten = true
        };

        this.searchService = address;
    }

    /// <summary>
    /// For the supplied search, get the moniker which can then be used to format the address.
    /// </summary>
    private string GetMoniker(string p)
    {
        return this.searchService.Search("GBR", p, PromptSet.Types.Default, "Database layout").Picklist.Items[0].Moniker;
    }

    /// <summary>
    /// Return a formatted address from the supplied search. 
    /// </summary>
    public string[] RefinePostcode(string p)
    {
        // Append the postcode to our address to speed up and improve searches.
        string search = p + "," + Postcode;

        SearchResult result = this.searchService.Search("GBR", 
                                                        postCode,
                                                        PromptSet.Types.OneLine,
                                                        "Database layout");
        if ( result.Picklist.Items.Length > 0 )
        {

        }
        else
        {
            // What is your workflow if an address is not found?
        }
        string moniker = this.GetMoniker(search);
        FormattedAddress formattedAddress = this.searchService.GetFormattedAddress(moniker, "Database Layout");
        return new string[] { formattedAddress.AddressLines[0].Line, formattedAddress.AddressLines[1].Line, formattedAddress.AddressLines[2].Line, formattedAddress.AddressLines[3].Line, formattedAddress.AddressLines[4].Line, formattedAddress.AddressLines[5].Line, formattedAddress.AddressLines[6].Line };
    }

    /// <summary>
    /// Once a postcode is captured by the operator, return a list of potential addresses. 
    /// </summary>
    public string[] SearchPostcodes(string postCode)
    {
        Postcode = postcode;
        SearchResult result = this.searchService.Search("GBR", 
                                                        postCode,
                                                        PromptSet.Types.OneLine,
                                                        "Database layout");

        string[] strArray = new string[result.Picklist.Length];
        for (int i = 0; i < result.Picklist.Length; i++)
        {
            strArray[i] = result.Picklist.Items[i].Text;
        }
        return strArray;
    }

    private QuickAddress searchService { get; set; }

    /// <summary>
    /// Gets or sets the postcode from the initial search.
    /// </summary>
    private string Postcode
    {
        get;
        set;
    }

}

如果你有时间,最好再进一步并正确修复你的工作流程。 QAS Pro Web中的搜索之间的上下文是通过标记处理的。这些是Pro Web在与服务器进行所有交互后提供的令牌,您可以使用这些令牌获取格式化地址或执行进一步搜索。在提供的文档中有更多详细信息。

在对邮政编码进行初步搜索后,您将获得一个地址列表,每个地址都有一个与之关联的名字对象。如果您能够存储这些标记并将这些与您放入组合框的列表相关联,那么当操作员选择一个时,您可以将该名字直接传递到GetFormatted地址,并且您应该能够更快,更准确地捕获地址并且更少代码!

希望有所帮助! 人。

答案 1 :(得分:0)

这是代码访问使用。

Private Sub cmdSelect_Click()

    Dim thisOne As String
    thisOne = Me.lkupAddressList.Value

    Dim objQAS As MangoQAS.QAS
    Set objQAS = New MangoQAS.QAS
    Dim finalAddress As Variant

    finalAddress = objQAS.RefinePostcode(thisOne)

    Form_Script.txtAddress1 = finalAddress(0)
    Form_Script.txtAddress2 = finalAddress(1)
    Form_Script.txtAddress3 = finalAddress(2)
    Form_Script.txtTown = finalAddress(3)
    Form_Script.txtCounty = finalAddress(4)
    Form_Script.txtPostcode = finalAddress(5)

    Set objQAS = Nothing

    DoCmd.Close acForm, "frmSelectAddress_qas"

End Sub

Private Sub Form_Load()

    Dim postcodeToSearch As String

    postcodeToSearch = Form_Script.txtPostcode

    Dim objQAS As MangoQAS.QAS
    Set objQAS = New MangoQAS.QAS
    Dim results As Variant

    results = objQAS.SearchPostcodes(postcodeToSearch)

    Dim howMany As Integer
    howMany = UBound(results)

    For i = 0 To howMany
        Me.lkupAddressList.AddItem ("'" & results(i) & "'")
    Next

    Set objQAS = Nothing

End Sub