Windowsクライアント版 検索アプリケーション
C# postanMain.cs
C# postanList.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Postan.jp.co.est.webservice;
namespace Postan
{
///
/// 郵便番号検索 Windowsアプリ版
/// 郵便番号から住所、住所から郵便番号を検索する。
///
public class PostanMain : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBoxPostCode; //郵便番号
private System.Windows.Forms.Button buttonSearchAdd; //住所検索ボタン
private System.Windows.Forms.TextBox textBoxAdd; //住所
private System.Windows.Forms.Button buttonSerachPostcode; //郵便番号検索ボタン
private System.Windows.Forms.Button btnClear; //クリアボタン
private System.Windows.Forms.Label lblPostcode;
private System.Windows.Forms.Label lblAddress;
private System.Windows.Forms.Label lblFindCountMsg;
private System.Windows.Forms.PictureBox pictureBox1;
///
/// 必要なデザイナ変数です。
///
private System.ComponentModel.Container components = null;
public PostanMain()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
///
/// 使用されているリソースに後処理を実行します。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PostanMain));
this.textBoxPostCode = new System.Windows.Forms.TextBox();
this.textBoxAdd = new System.Windows.Forms.TextBox();
this.buttonSearchAdd = new System.Windows.Forms.Button();
this.buttonSerachPostcode = new System.Windows.Forms.Button();
this.lblPostcode = new System.Windows.Forms.Label();
this.lblAddress = new System.Windows.Forms.Label();
this.lblFindCountMsg = new System.Windows.Forms.Label();
this.btnClear = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// textBoxPostCode
//
this.textBoxPostCode.ImeMode = System.Windows.Forms.ImeMode.Disable;
this.textBoxPostCode.Location = new System.Drawing.Point(72, 144);
this.textBoxPostCode.Name = "textBoxPostCode";
this.textBoxPostCode.Size = new System.Drawing.Size(96, 19);
this.textBoxPostCode.TabIndex = 0;
this.textBoxPostCode.Text = "";
this.textBoxPostCode.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxPostCode_KeyPress);
//
// textBoxAdd
//
this.textBoxAdd.Location = new System.Drawing.Point(56, 176);
this.textBoxAdd.Name = "textBoxAdd";
this.textBoxAdd.Size = new System.Drawing.Size(256, 19);
this.textBoxAdd.TabIndex = 2;
this.textBoxAdd.Text = "";
this.textBoxAdd.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxAdd_KeyPress);
//
// buttonSearchAdd
//
this.buttonSearchAdd.BackColor = System.Drawing.SystemColors.Control;
this.buttonSearchAdd.Location = new System.Drawing.Point(328, 144);
this.buttonSearchAdd.Name = "buttonSearchAdd";
this.buttonSearchAdd.Size = new System.Drawing.Size(96, 23);
this.buttonSearchAdd.TabIndex = 1;
this.buttonSearchAdd.Text = "住所検索";
this.buttonSearchAdd.Click += new System.EventHandler(this.buttonSearchAdd_Click);
//
// buttonSerachPostcode
//
this.buttonSerachPostcode.BackColor = System.Drawing.SystemColors.Control;
this.buttonSerachPostcode.Location = new System.Drawing.Point(328, 176);
this.buttonSerachPostcode.Name = "buttonSerachPostcode";
this.buttonSerachPostcode.Size = new System.Drawing.Size(96, 23);
this.buttonSerachPostcode.TabIndex = 3;
this.buttonSerachPostcode.Text = "郵便番号検索";
this.buttonSerachPostcode.Click += new System.EventHandler(this.buttonSerachPostcode_Click);
//
// lblPostcode
//
this.lblPostcode.Location = new System.Drawing.Point(8, 152);
this.lblPostcode.Name = "lblPostcode";
this.lblPostcode.Size = new System.Drawing.Size(64, 16);
this.lblPostcode.TabIndex = 5;
this.lblPostcode.Text = "郵便番号";
//
// lblAddress
//
this.lblAddress.ForeColor = System.Drawing.SystemColors.ControlText;
this.lblAddress.Location = new System.Drawing.Point(16, 184);
this.lblAddress.Name = "lblAddress";
this.lblAddress.Size = new System.Drawing.Size(40, 16);
this.lblAddress.TabIndex = 6;
this.lblAddress.Text = "住所";
//
// lblFindCountMsg
//
this.lblFindCountMsg.Location = new System.Drawing.Point(16, 216);
this.lblFindCountMsg.Name = "lblFindCountMsg";
this.lblFindCountMsg.Size = new System.Drawing.Size(304, 23);
this.lblFindCountMsg.TabIndex = 99;
//
// btnClear
//
this.btnClear.BackColor = System.Drawing.SystemColors.Control;
this.btnClear.Location = new System.Drawing.Point(328, 216);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(96, 24);
this.btnClear.TabIndex = 6;
this.btnClear.Text = "クリア";
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(416, 128);
this.pictureBox1.TabIndex = 107;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// PostanMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(247)), ((System.Byte)(150)));
this.ClientSize = new System.Drawing.Size(432, 261);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.pictureBox1,
this.btnClear,
this.lblFindCountMsg,
this.lblAddress,
this.lblPostcode,
this.buttonSerachPostcode,
this.buttonSearchAdd,
this.textBoxAdd,
this.textBoxPostCode});
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "PostanMain";
this.Text = "ぽすたん−住所←→郵便番号検索−";
this.ResumeLayout(false);
}
#endregion
///
/// アプリケーションのメイン エントリ ポイントです。
///
[STAThread]
static void Main()
{
Application.Run(new PostanMain());
}
private void buttonSearchAdd_Click(object sender, System.EventArgs e)
{//郵便番号から住所検索
//ラベルメッセージの初期化&カーソルを砂時計にする
lblFindCountMsg.Text = "";
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
ShowResult(textBoxPostCode.Text, false);
//カーソルを元に戻す
this.Cursor = Cursors.Default;
}
private void buttonSerachPostcode_Click(object sender, System.EventArgs e)
{//住所から郵便番号検索
//ラベルメッセージの初期化&カーソルを砂時計にする
lblFindCountMsg.Text = "";
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
ShowResult(textBoxAdd.Text, true); //検索チェック
//カーソルを元に戻す
this.Cursor = Cursors.Default;
}
///
/// 検索チェックの結果を見てラベルメッセージを表示
///
///
///
private void ShowResult(string Value, bool IsAddress)
{
SearchEngine seService = new SearchEngine();
FindList flResult = null;
PostanList plForm;
//入力データにより呼び出すseServieを使い分ける
if ( IsAddress == true )
{
flResult = seService.FromAddress2( Value );
}
else
{
if(Value.Length == 3 || Value.Length == 5)
{
flResult = seService.FromOldZipCode2(Value);
}
else if(Value.Length == 7)
{
flResult = seService.FromZipCode2(Value);
}
else
{
lblFindCountMsg.Text = "郵便番号は3桁、5桁、7桁で入力してください。";
flResult = seService.FromZipCode2(Value);
}
}
//検索チェックの結果をみる
if( flResult.IsSuccess == false )
{
MessageBox.Show(this, flResult.ErrorMessage);
}
else
{//検索に使える値を得、検索一覧を表示し、その中から1つ選択
if( flResult.FindCount > 0 )
{
plForm = new PostanList(); //検索結果一覧を表示し、1つ選択
FindItem fiSelect = plForm.SelectItems( flResult.Item ); //選択されたもの
lblFindCountMsg.Text = "";
}
else
{
lblFindCountMsg.Text = "見つかりませんでした。";
}
}
}
private void textBoxPostCode_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//郵便番号での、入力制御
//数値文字とコントロール文字のみ反応し、それ以外は無視。
if ( char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar) )
{
e.Handled = false;
}
else
{
e.Handled = true;
}
if ( e.KeyChar == '\r' && 0 < textBoxPostCode.Text.Trim().Length )
{
buttonSearchAdd_Click(textBoxPostCode, EventArgs.Empty);
}
}
private void btnClear_Click(object sender, System.EventArgs e)
{
//クリアボタンが押されたらテキストフレームを空にする
textBoxPostCode.Clear();
textBoxAdd.Clear();
lblFindCountMsg.Text = "";
}
private void textBoxAdd_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ( e.KeyChar == '\r' && 0 < textBoxAdd.Text.Trim().Length )
{
buttonSerachPostcode_Click(textBoxAdd, EventArgs.Empty);
}
}
private void pictureBox1_Click(object sender, System.EventArgs e)
{
}
}
}