/*
 * ZipLook (C#)
 * 뾛뺇붥뜂땤덙궖렖밫
 */

using System.Windows.Forms;

namespace ZipLook {

  public partial class ZipLookForm : Form {

    public ZipLookForm() {
      InitializeComponent();
    }

    private Oblaat.SQLite3.Database db_;

    private void ZipLookForm_Shown(object sender, System.EventArgs e) {
      db_ = new Oblaat.SQLite3.Database();
      db_.open("zip.db");
      toolStripStatusLabel1.Text = db_.errmsg();
    }

    private void textBox1_TextChanged(object sender, System.EventArgs e) {
      string sql = "SELECT zip, pref, city, town FROM zip_table WHERE zip = ?";
      Oblaat.SQLite3.Statement statement = null;
      db_.prepare(sql, out statement );
      statement.bind_text(1, textBox1.Text);
      if ( statement.step() == Oblaat.SQLite3.Result.ROW ) {
        string[] item = { statement.column_text(0), statement.column_text(1),statement.column_text(2),statement.column_text(3)};
        listView1.Items.Add(new ListViewItem(item));
      }
      statement.finalize();
      toolStripStatusLabel1.Text = db_.errmsg();
    }
  }
}
