Am trying to adapt a pice of sample code in a proof of concept project
and can not seem to fugure out how to load the required values from a
database vs the static values in the sample.
Here is the Sample Class...
public class ModeItem : INotifyPropertyChanged
{
#region Creation
public static ModeItem[] GetModeItems()
{
// In a real app this would probably call into a data
access layer to get records from a database.
return new ModeItem[]
{
new ModeItem(1, "Item 1", "0"),
new ModeItem(2, "Item 2", "1"),
new ModeItem(3, "Item 3", "0"),
new ModeItem(4, "Item 4", "1"),
new ModeItem(5, "Item 5", "0"),
new ModeItem(6, "Item 6", "1"),
new ModeItem(7, "Item 7", "0"),
new ModeItem(8, "Item 8", "1"),
new ModeItem(9, "Item 9", "0"),
new ModeItem(10, "Item 10", "1"),
};
}
private ModeItem(int iItemID, string sItemName, string
sItemIcon)
{
this.ItemID = iItemID;
this.ItemName = sItemName;
this.ItemIcon = sItemIcon;
}
#endregion // Creation
#region Properties
public int ItemID { get; private set; }
string itemName;
public string ItemName
{
get { return itemName; }
set
{
if (value == itemName)
return;
itemName = value;
this.OnPropertyChanged("ItemName");
}
}
public string ItemIcon { get; private set; }
#endregion // Properties
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler =
this.PropertyChanged;
if (handler != null)
handler(this, new
PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
And here is what I want to do,
public class CategoryItem : INotifyPropertyChanged
{
private int itemID;
private string itemDescription;
private int itemIcon;
#region Public Properties
public int ItemID
{
get { return this.itemID; }
set { this.itemID = value; }
}
public string ItemDescription
{
get { return this.itemDescription; }
set
{
if (value == this.itemDescription)
return;
this.itemDescription = value;
this.OnPropertyChanged("ItemDescription");
}
}
public int ItemIcon
{
get { return this.itemIcon; }
set { this.itemIcon = value; }
}
#endregion // Public Properties
#region Creation
/// <summary>
///
/// </summary>
/// <returns>Categories</returns>
public static CategoryItem[] GetCategoryItems(string
sqlConnectionString)
{
OleDbConnection sqlConnection = new
OleDbConnection(sqlConnectionString.ToString());
string sqlQueryString = String.Format(@"SELECT [recID],
[catName], [catIcon] " +
"FROM [categories] " +
"WHERE [catActive] = 'True'");
sqlConnection.Open();
OleDbCommand oleDbCommand = new
OleDbCommand(sqlQueryString.ToString(), sqlConnection);
OleDbDataReader oleDbDataReader =
oleDbCommand.ExecuteReader();
while (oleDbDataReader.Read())
{
new CategoryItem(
oleDbDataReader.GetInt32(0),
oleDbDataReader.GetString(1).ToString(),
oleDbDataReader.GetInt32(2));
}
if (sqlConnection != null) sqlConnection.Close();
return TheCategory;
}
private CategoryItem(int iItemID, string sItemDescription, int
iItemIcon)
{
this.ItemID = iItemID;
this.ItemDescription = sItemDescription;
this.ItemIcon = iItemIcon;
}
#endregion // Creation
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler =
this.PropertyChanged;
if (handler != null)
handler(this, new
PropertyChangedEventArgs(propertyName));
}
#endregion
}
Any help you can provide would be greatly appreciated.