Click here to Skip to main content
15,921,382 members
Home / Discussions / C#
   

C#

 
GeneralRe: Generic event, or raise event based on generic type. [modified] Pin
DaveyM6915-Jan-09 23:08
professionalDaveyM6915-Jan-09 23:08 
GeneralRe: Generic event, or raise event based on generic type. Pin
Wendelius15-Jan-09 23:25
mentorWendelius15-Jan-09 23:25 
QuestionKeep current view centered on Zoom Pin
Richard Blythe12-Jan-09 7:16
Richard Blythe12-Jan-09 7:16 
AnswerRe: Keep current view centered on Zoom [modified] Pin
Luc Pattyn12-Jan-09 8:01
sitebuilderLuc Pattyn12-Jan-09 8:01 
GeneralRe: Keep current view centered on Zoom Pin
Richard Blythe12-Jan-09 9:10
Richard Blythe12-Jan-09 9:10 
QuestionAddress Pin
boiDev12-Jan-09 6:56
boiDev12-Jan-09 6:56 
AnswerRe: Address Pin
EliottA12-Jan-09 7:21
EliottA12-Jan-09 7:21 
GeneralRe: Address Pin
boiDev12-Jan-09 11:25
boiDev12-Jan-09 11:25 
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AddressFinder
{
public partial class AddressSelecter : Form
{
private static readonly object EventClose = new object();

public event EventHandler OnClose
{
add
{
Events.AddHandler(EventClose,value);
}
remove
{
Events.RemoveHandler(EventClose,value);
}
}

public virtual void OnCloseEvent(EventArgs e)
{
EventHandler handler = (EventHandler) Events[EventClose];
if(handler!=null)
{
handler(this, e);
}
}

public AddressSelecter()
{
InitializeComponent();
}

private string buildingNo;

public string BuildingNo
{
get { return buildingNo; }
set { buildingNo = value; }
}

private string street;

public string Street
{
get { return street; }
set { street = value; }
}

private string city;

public string City
{
get { return city; }
set { city = value; }
}

private string country;

public string Country
{
get { return country; }
set { country = value; }
}

public string PostCode
{
get { return txtPostCode.Text; }
set { txtPostCode.Text = value; }
}

private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(@"select
b.buildingId,
b.buildingname,
s.streetname,
c.cityname
from
zipcode z
inner join city c on z.CityID = c.CityID
inner join building b on z.zipcodeid = b.zipcodeid
inner join street s on z.zipcodeid = s.zipcodeid
where z.zipcode = @postcode;");
cmd.Parameters.AddWithValue("postcode", txtPostCode.Text);

SqlDataReader reader = Read(cmd);

if (reader.HasRows)
{
while (reader.Read())
{
ItemObject item = new ItemObject();
item.Key =
string.Format("{0}, {1}, {2}", reader.GetString(1), reader.GetString(2), reader.GetString(3));
item.ValueOfKey = reader.GetInt64(0).ToString();

listBox1.Items.Add(item);
}
}
}

private void button2_Click(object sender, EventArgs e)
{
ItemObject selectedObject = (ItemObject)listBox1.SelectedItem;
lblBuilding.Text = selectedObject.ToString();

SqlCommand cmd = new SqlCommand(@"select
b.buildingname,
s.streetname,
c.cityname,
cntry.countryname
from
zipcode z
inner join city c on z.CityID = c.CityID
inner join building b on z.zipcodeid = b.zipcodeid
inner join street s on z.zipcodeid = s.zipcodeid
inner join country cntry on z.countryid = cntry.countryid
where z.zipcode = @postcode and b.buildingId = @buildingId");

cmd.Parameters.AddWithValue("postcode", txtPostCode.Text);
cmd.Parameters.AddWithValue("buildingId", selectedObject.ValueOfKey);

SqlDataReader reader = Read(cmd);

if (reader.HasRows)
{
reader.Read();

BuildingNo = reader.GetString(0);
Street = reader.GetString(1);
City = reader.GetString(2);
Country = reader.GetString(3);
}

lblBuilding.Text = BuildingNo + " " + Street;
lblCity.Text = City;
lblCountry.Text = Country;
}

private static SqlDataReader Read(SqlCommand cmd)
{
SqlConnection connection = new SqlConnection("Data Source=localhost;Database=Geo;Integrated Security=SSPI");

connection.Open();
cmd.Connection = connection;

SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

return reader;
}

private void btnOk_Click(object sender, EventArgs e)
{
this.Hide();
OnCloseEvent(e);
}
}

public class ItemObject
{
private string key;
private object valueOfKey;

/// <summary>
/// Overloaded constructor.
/// </summary>
/// <param name="key">Key of object.</param>
/// <param name="valueOfKey">Value of object.</param>
public ItemObject(string key, object valueOfKey)
{
this.key = key;
this.valueOfKey = valueOfKey;
}

/// <summary>
/// Default constructor
/// </summary>
public ItemObject()
{
key = string.Empty;
valueOfKey = string.Empty;
}

///<summary>
///Returns a <see cref="T:System.String"></see> that represents the current
///<see cref="T:System.Object">
/// </see>.
///</summary>
///
///<returns>
///A <see cref="T:System.String"></see> that represents the current
///<see cref="T:System.Object">
/// </see>.
///</returns>
public override string ToString()
{
return key;
}

///<summary>
///Serves as a hash function for a particular type.
///</summary>
///
///<returns>
///A hash code for the current <see cref="T:System.Object"></see>.
///</returns>
public override int GetHashCode()
{
return ToString().GetHashCode();
}

/// <summary>
/// Gets or sets Key of object.
/// </summary>
public string Key
{
get { return key; }
set { key = value; }
}

/// <summary>
/// Gets or sets Value of object.
/// </summary>
public object ValueOfKey
{
get { return valueOfKey; }
set { valueOfKey = value; }
}
}
}

I have created the database an every thing. At the moment you have to type in the full post code for it to populate. i want so that you do not have to type in the full post code E.G if the full post code is IG6 6AF you should be able to type any part of it and still be able to search and find the address..

i hope you can help


Thank You
GeneralRe: Address Pin
EliottA12-Jan-09 11:29
EliottA12-Jan-09 11:29 
GeneralRe: Address Pin
boiDev12-Jan-09 11:43
boiDev12-Jan-09 11:43 
GeneralRe: Address Pin
EliottA12-Jan-09 12:28
EliottA12-Jan-09 12:28 
Questionincreasing panel size Pin
jananiSreedhar12-Jan-09 6:11
jananiSreedhar12-Jan-09 6:11 
AnswerRe: increasing panel size Pin
User 665812-Jan-09 6:18
User 665812-Jan-09 6:18 
AnswerRe: increasing panel size Pin
EliottA12-Jan-09 6:23
EliottA12-Jan-09 6:23 
QuestionString in UTF-8 format was inserted to DB Pin
Miro7712-Jan-09 5:44
Miro7712-Jan-09 5:44 
AnswerRe: String in UTF-8 format was inserted to DB Pin
Ben Fair12-Jan-09 8:06
Ben Fair12-Jan-09 8:06 
GeneralRe: String in UTF-8 format was inserted to DB Pin
Miro7712-Jan-09 20:23
Miro7712-Jan-09 20:23 
AnswerRe: String in UTF-8 format was inserted to DB Pin
Guffa12-Jan-09 13:34
Guffa12-Jan-09 13:34 
QuestionHow to create a class that can be used like a DataTable? Pin
Michael Sync12-Jan-09 4:57
Michael Sync12-Jan-09 4:57 
AnswerRe: How to create a class that can be used like a DataTable? Pin
Moim Hossain12-Jan-09 4:59
Moim Hossain12-Jan-09 4:59 
GeneralRe: How to create a class that can be used like a DataTable? Pin
Michael Sync12-Jan-09 5:03
Michael Sync12-Jan-09 5:03 
GeneralRe: How to create a class that can be used like a DataTable? Pin
Moim Hossain12-Jan-09 5:11
Moim Hossain12-Jan-09 5:11 
GeneralRe: How to create a class that can be used like a DataTable? Pin
Michael Sync12-Jan-09 5:47
Michael Sync12-Jan-09 5:47 
GeneralRe: How to create a class that can be used like a DataTable? Pin
Not Active12-Jan-09 5:52
mentorNot Active12-Jan-09 5:52 
GeneralRe: How to create a class that can be used like a DataTable? Pin
Michael Sync12-Jan-09 6:03
Michael Sync12-Jan-09 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.