using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using Uchukamen.Util.ZipCodeJapan;
using System.Configuration;
namespace ZipCode
{
/// <summary>
/// Form1 の概要の説明です。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox tbZipCode;
private System.Windows.Forms.TextBox tbCity;
private System.Windows.Forms.TextBox tbTown;
private System.Windows.Forms.Button btnSearchZip;
private System.Windows.Forms.ComboBox cbKen;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button btnSearchKana;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.ErrorProvider errorProvider1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnSearchZip = new System.Windows.Forms.Button();
this.tbZipCode = new System.Windows.Forms.TextBox();
this.btnSearchKana = new System.Windows.Forms.Button();
this.tbCity = new System.Windows.Forms.TextBox();
this.tbTown = new System.Windows.Forms.TextBox();
this.cbKen = new System.Windows.Forms.ComboBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.btnClear = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.errorProvider1 = new System.Windows.Forms.ErrorProvider();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
this.SuspendLayout();
//
// btnSearchZip
//
this.btnSearchZip.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.btnSearchZip.Location = new System.Drawing.Point(296, 24);
this.btnSearchZip.Name = "btnSearchZip";
this.btnSearchZip.Size = new System.Drawing.Size(48, 23);
this.btnSearchZip.TabIndex = 2;
this.btnSearchZip.Text = "検索";
this.toolTip1.SetToolTip(this.btnSearchZip, "郵便番号より検索");
this.btnSearchZip.Click += new System.EventHandler(this.btnSearchZip_Click);
//
// tbZipCode
//
this.tbZipCode.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.tbZipCode.Location = new System.Drawing.Point(104, 24);
this.tbZipCode.Name = "tbZipCode";
this.tbZipCode.Size = new System.Drawing.Size(56, 19);
this.tbZipCode.TabIndex = 1;
this.tbZipCode.Text = "";
this.toolTip1.SetToolTip(this.tbZipCode, "例:123-4567");
//
// btnSearchKana
//
this.btnSearchKana.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.btnSearchKana.Location = new System.Drawing.Point(296, 24);
this.btnSearchKana.Name = "btnSearchKana";
this.btnSearchKana.Size = new System.Drawing.Size(48, 23);
this.btnSearchKana.TabIndex = 2;
this.btnSearchKana.Text = "検索";
this.toolTip1.SetToolTip(this.btnSearchKana, "住所の読みがなより検索");
this.btnSearchKana.Click += new System.EventHandler(this.button2_Click);
//
// tbCity
//
this.tbCity.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.tbCity.ImeMode = System.Windows.Forms.ImeMode.Katakana;
this.tbCity.Location = new System.Drawing.Point(104, 56);
this.tbCity.Name = "tbCity";
this.tbCity.Size = new System.Drawing.Size(160, 19);
this.tbCity.TabIndex = 4;
this.tbCity.Text = "";
this.toolTip1.SetToolTip(this.tbCity, "カタカナで入力");
//
// tbTown
//
this.tbTown.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.tbTown.ImeMode = System.Windows.Forms.ImeMode.Katakana;
this.tbTown.Location = new System.Drawing.Point(104, 88);
this.tbTown.Name = "tbTown";
this.tbTown.Size = new System.Drawing.Size(160, 19);
this.tbTown.TabIndex = 7;
this.tbTown.Text = "";
this.toolTip1.SetToolTip(this.tbTown, "カタカナで入力");
//
// cbKen
//
this.cbKen.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.cbKen.Items.AddRange(new object[] {
"全国",
"北海道",
"青森県",
"岩手県",
"宮城県",
"秋田県",
"山形県",
"福島県",
"茨城県",
"栃木県",
"群馬県",
"埼玉県",
"千葉県",
"東京都",
"神奈川県",
"新潟県",
"富山県",
"石川県",
"福井県",
"山梨県",
"長野県",
"岐阜県",
"静岡県",
"愛知県",
"三重県",
"滋賀県",
"京都府",
"大阪府",
"兵庫県",
"奈良県",
"和歌山県",
"鳥取県",
"島根県",
"岡山県",
"広島県",
"山口県",
"徳島県",
"香川県",
"愛媛県",
"高知県",
"福岡県",
"佐賀県",
"長崎県",
"熊本県",
"大分県",
"宮崎県",
"鹿児島県",
"沖縄県"});
this.cbKen.Location = new System.Drawing.Point(104, 24);
this.cbKen.MaxDropDownItems = 20;
this.cbKen.Name = "cbKen";
this.cbKen.Size = new System.Drawing.Size(88, 20);
this.cbKen.TabIndex = 1;
this.cbKen.Text = "全国";
this.toolTip1.SetToolTip(this.cbKen, "都道府県名を選択");
//
// listBox1
//
this.listBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.listBox1.ContextMenu = this.contextMenu1;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(8, 208);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(368, 184);
this.listBox1.TabIndex = 3;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3});
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.menuItem3.Text = "コピー(&C)";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tbZipCode,
this.btnSearchZip,
this.label4});
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(368, 56);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "郵便番号より検索";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 16);
this.label4.TabIndex = 0;
this.label4.Text = "郵便番号";
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnClear,
this.label3,
this.label2,
this.label1,
this.tbCity,
this.btnSearchKana,
this.cbKen,
this.tbTown});
this.groupBox2.Location = new System.Drawing.Point(8, 80);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(368, 120);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "住所の読みがなより検索";
//
// btnClear
//
this.btnClear.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.btnClear.Location = new System.Drawing.Point(296, 56);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(48, 23);
this.btnClear.TabIndex = 5;
this.btnClear.Text = "クリア";
this.toolTip1.SetToolTip(this.btnClear, "市町村名、町域名をクリアします。");
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 16);
this.label3.TabIndex = 6;
this.label3.Text = "町域名(カナ)";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 3;
this.label2.Text = "市町村名(カナ)";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 0;
this.label1.Text = "都道府県";
//
// toolTip1
//
this.toolTip1.AutomaticDelay = 100;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "ヘルプ(&H)";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "バージョン情報(&A)";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 392);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(384, 22);
this.statusBar1.TabIndex = 0;
//
// statusBarPanel1
//
this.statusBarPanel1.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.statusBarPanel1.ToolTipText = "Status";
this.statusBarPanel1.Width = 368;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(384, 414);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.statusBar1,
this.listBox1,
this.groupBox1,
this.groupBox2});
this.Menu = this.mainMenu1;
this.MinimumSize = new System.Drawing.Size(392, 448);
this.Name = "Form1";
this.Text = "ZipCode Searcher";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private ArrayList zipList = null;
private void btnSearchZip_Click(object sender, System.EventArgs e)
{
// エラープロバイダーをクリアする。
this.errorProvider1.SetError(this.cbKen, "");
this.errorProvider1.SetError(this.tbCity, "");
this.errorProvider1.SetError(this.btnSearchKana, "");
this.errorProvider1.SetError(this.btnSearchZip, "");
// 現在のカーソルを保存しておく。
Cursor cursor = this.Cursor;
// カーソルを WaitCursor にする。
this.Cursor = Cursors.WaitCursor;
try
{
this.errorProvider1.SetError(this.tbZipCode, "");
ZipCodeSearcher zipCodeSearcher =
new Uchukamen.Util.ZipCodeJapan.ZipCodeSearcher();
zipList = zipCodeSearcher.GetAddressFromZipCode(this.tbZipCode.Text);
this.listBox1.Items.Clear();
this.statusBarPanel1.Text = zipList.Count.ToString() + " 件見つかりました";
foreach(Uchukamen.Util.ZipCodeJapan.ZipCode zip in zipList)
{
this.listBox1.Items.Add(zip.Code+ "\t" + zip.Ken+zip.City+zip.Town);
}
}
catch (WebException exc)
{
this.listBox1.Items.Clear();
this.statusBarPanel1.Text = exc.Message;
this.errorProvider1.SetError(this.btnSearchZip, exc.Message);
}
catch (Exception exc)
{
this.listBox1.Items.Clear();
this.statusBarPanel1.Text = exc.Message;
this.errorProvider1.SetError(this.tbZipCode, exc.Message);
}
finally
{
// カーソルを元に戻す。
this.Cursor = cursor;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
// エラープロバイダーをクリアする。
this.errorProvider1.SetError(this.cbKen, "");
this.errorProvider1.SetError(this.tbCity, "");
this.errorProvider1.SetError(this.btnSearchKana, "");
this.errorProvider1.SetError(this.btnSearchZip, "");
// 現在のカーソルを保存しておく。
Cursor cursor = this.Cursor;
// カーソルを WaitCursor にする。
this.Cursor = Cursors.WaitCursor;
ZipCodeSearcher zipSearcher =
new Uchukamen.Util.ZipCodeJapan.ZipCodeSearcher();
try
{
zipList = zipSearcher.GetZipCodeFromAddress(this.cbKen.Text, this.tbCity.Text, this.tbTown.Text);
this.listBox1.Items.Clear();
this.statusBarPanel1.Text = zipList.Count.ToString() + " 件見つかりました";
foreach(Uchukamen.Util.ZipCodeJapan.ZipCode zip in zipList)
{
this.listBox1.Items.Add(zip.Code+ "\t" + zip.Ken+zip.City+zip.Town);
}
}
catch (MultipleKenException exc)
{
this.listBox1.Items.Clear();
string msg = exc.Message;
foreach(string ken in exc.KenList)
msg += "\n" + ken;
this.statusBarPanel1.Text = msg;
this.errorProvider1.SetError(this.cbKen, msg);
}
catch (WebException exc)
{
this.listBox1.Items.Clear();
this.statusBarPanel1.Text = exc.Message;
this.errorProvider1.SetError(this.btnSearchKana, exc.Message);
}
catch (Exception exc)
{
this.listBox1.Items.Clear();
this.statusBarPanel1.Text = exc.Message;
this.errorProvider1.SetError(this.tbCity, exc.Message);
}
finally
{
// カーソルを元に戻す。
this.Cursor = cursor;
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Icon = new Icon(GetType(), "App.ico");
toolTip1.SetToolTip(this.tbCity, "例:チヨダク、ケセンヌマシ、シラハマチョウなど");
toolTip1.SetToolTip(this.tbTown, "検索のヒント:町・村を省いたよみがな");
string defaultKen = ConfigurationSettings.AppSettings["ZipCode.DefaultKen"];
this.cbKen.Text = defaultKen;
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
int i = this.listBox1.SelectedIndex;
this.cbKen.Text = ((Uchukamen.Util.ZipCodeJapan.ZipCode)zipList[i]).Ken;
this.tbZipCode.Text = ((Uchukamen.Util.ZipCodeJapan.ZipCode)zipList[i]).Code;
this.tbCity.Text = ((Uchukamen.Util.ZipCodeJapan.ZipCode)zipList[i]).CityKana;
this.tbTown.Text = ((Uchukamen.Util.ZipCodeJapan.ZipCode)zipList[i]).TownKana;
}
private void btnClear_Click(object sender, System.EventArgs e)
{
this.cbKen.Text = "全国";
this.tbZipCode.Text = "";
this.tbCity.Text = "";
this.tbTown.Text = "";
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Form about = new Uchukamen.Util.AboutZipCodeSearcher.About();
about.ShowDialog();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
Clipboard.SetDataObject(this.listBox1.SelectedItem.ToString());
}
}
}
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Uchukamen.Util.AboutZipCodeSearcher
{
/// <summary>
/// About の概要の説明です。
/// </summary>
public class About : System.Windows.Forms.Form
{
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public About()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// linkLabel1
//
this.linkLabel1.Location = new System.Drawing.Point(80, 80);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(152, 23);
this.linkLabel1.TabIndex = 0;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "C# プログラミング";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.OnLinkClicked);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Arial Black", 20.25F, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.ForeColor = System.Drawing.Color.#AAAAFF;
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(312, 40);
this.label1.TabIndex = 1;
this.label1.Text = "Zip Code Searcher";
//
// button1
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button1.Location = new System.Drawing.Point(272, 72);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 2;
this.button1.Text = "OK";
//
// label2
//
this.label2.Font = new System.Drawing.Font("Arial Black", 12F, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.ForeColor = System.Drawing.Color.#AAAAFF;
this.label2.Location = new System.Drawing.Point(56, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(199, 28);
this.label2.TabIndex = 3;
this.label2.Text = "Ver.1.0 2003/5/18";
//
// About
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(338, 104);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label2,
this.button1,
this.label1,
this.linkLabel1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "About";
this.Text = "About";
this.Load += new System.EventHandler(this.About_Load);
this.ResumeLayout(false);
}
#endregion
private void About_Load(object sender, System.EventArgs e)
{
this.linkLabel1.Links.Add(0, this.linkLabel1.Text.Length,
"http://ukamen.hp.infoseek.co.jp/");
}
private void OnLinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
e.Link.Visited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
}
}
|