PowerTools InputMan for Windows Forms 8.0J
GetTown メソッド
使用例 

市区町村の全国地方公共団体コードを示す 5 桁の数字文字列。
指定した市区町村にあるすべての町域の情報を取得します。
構文

パラメータ

cityJISCode
市区町村の全国地方公共団体コードを示す 5 桁の数字文字列。

戻り値の型

指定した市区町村にあるすべての町域の情報を含む RegionInfo コレクション。
解説
返された RegionInfo レコード内の RegionInfo.Code プロパティの値は、町域に詳細な丁目情報がない場合には、町域の郵便番号になります。それ以外の場合、RegionInfo.Code プロパティは空の文字列になります。検索が失敗した場合は空のコレクションが返されます。
使用例
//  Please use the following namespace
//  using System.Windows.Forms;
//  using GrapeCity.Win.Editors;

public void HierarchicalAddressSearching()
{
    // Creates instance of GcAddress component.
    GcAddress gcAddress1 = new GcAddress();

    RegionInfo selectedPrefecture = null;
    RegionInfo selectedCity = null;
    RegionInfo selectedTown = null;

    // Get all prefectures.
    IEnumerable<RegionInfo> prefectures = gcAddress1.GetPrefecture();
    foreach (var prefecture in prefectures)
    {
        // Choose 宮城県 form the returned prefectures.
        if (string.Compare("宮城県", prefecture.Name) == 0)
        {
            System.Console.WriteLine("Searched prefecture: {0}", prefecture);
            selectedPrefecture = prefecture;
            break;
        }
    }

    if (selectedPrefecture == null)
    {
        return;
    }
    IEnumerable<RegionInfo> cities = gcAddress1.GetCity(selectedPrefecture.Code);
    foreach (var city in cities)
    {
        // Choose "仙台市青葉区" from the returned city list.
        if (string.Compare("仙台市青葉区", city.Name) == 0)
        {
            System.Console.WriteLine("Searched city: {0}", city);
            selectedCity = city;
            break;
        }
    }

    if (selectedCity == null)
    {
        return;
    }
    IEnumerable<RegionInfo> towns = gcAddress1.GetTown(selectedCity.Code);
    foreach (var town in towns)
    {
        // Choose "中央" from the returned town list.
        if (string.Compare("中央", town.Name) == 0)
        {
            System.Console.WriteLine("Searched town: {0}", town);
            selectedTown = town;
            break;
        }
    }

    if (selectedTown == null)
    {
        return;
    }
    else if (!string.IsNullOrEmpty(selectedTown.Code))
    {
        // To this step, we've already got the ZipCode in the town level.
        // Then query area information will not get result.
        System.Console.WriteLine("ZipCode is: {0}", selectedTown.Code);
        return;
    }

    // Town has area information, continue with searching.
    IEnumerable<RegionInfo> areas = gcAddress1.GetTownArea(selectedCity.Code, selectedTown.Name);
    int counter = 0;
    foreach (var area in areas)
    {
        System.Console.WriteLine("Searched ZipCode {0}: {1}", counter++, area.Code);
    }
}
'  Please use the following namespace
'  using System.Windows.Forms;
'  using GrapeCity.Win.Editors;

Public Sub HierarchicalAddressSearching()
    ' Creates instance of GcAddress component.
    Dim gcAddress1 As New GcAddress()

    Dim selectedPrefecture As RegionInfo = Nothing
    Dim selectedCity As RegionInfo = Nothing
    Dim selectedTown As RegionInfo = Nothing

    ' Get all prefectures.
    Dim prefectures As IEnumerable(Of RegionInfo) = gcAddress1.GetPrefecture()
    For Each prefecture As RegionInfo In prefectures
        ' Choose 宮城県 form the returned prefectures.
        If String.Compare("宮城県", prefecture.Name) = 0 Then
            System.Console.WriteLine("Searched prefecture: {0}", prefecture)
            selectedPrefecture = prefecture
            Exit For
        End If
    Next

    If selectedPrefecture Is Nothing Then
        Return
    End If
    Dim cities As IEnumerable(Of RegionInfo) = gcAddress1.GetCity(selectedPrefecture.Code)
    For Each city As RegionInfo In cities
        ' Choose "仙台市青葉区" from the returned city list.
        If String.Compare("仙台市青葉区", city.Name) = 0 Then
            System.Console.WriteLine("Searched city: {0}", city)
            selectedCity = city
            Exit For
        End If
    Next

    If selectedCity Is Nothing Then
        Return
    End If
    Dim towns As IEnumerable(Of RegionInfo) = gcAddress1.GetTown(selectedCity.Code)
    For Each town As RegionInfo In towns
        ' Choose "中央" from the returned town list.
        If String.Compare("中央", town.Name) = 0 Then
            System.Console.WriteLine("Searched town: {0}", town)
            selectedTown = town
            Exit For
        End If
    Next

    If selectedTown Is Nothing Then
        Return
    ElseIf Not String.IsNullOrEmpty(selectedTown.Code) Then
        ' To this step, we've already got the ZipCode in the town level.
        ' Then query area information will not get result.
        System.Console.WriteLine("ZipCode is: {0}", selectedTown.Code)
        Return
    End If

    ' Town has area information, continue with searching.
    Dim areas As IEnumerable(Of RegionInfo) = gcAddress1.GetTownArea(selectedCity.Code, selectedTown.Name)
    Dim counter As Integer = 0
    For Each area As RegionInfo In areas
        System.Console.WriteLine("Searched ZipCode {0}: {1}", System.Math.Max(System.Threading.Interlocked.Increment(counter), counter - 1), area.Code)
    Next
End Sub
参照

GcAddress クラス
GcAddress メンバ

 

 


© 2004-2015 GrapeCity inc. All rights reserved.