public TestDBFacade(IDictionary <string, IList <Item> > data) { Dictionary <string, Property> dictionary = new Dictionary <string, Property>(); emptyType = new ItemType("empty", dictionary); IPropertyTypeFactory pf = new PropertyTypeFactory(); this.data = data; }
static TestType() { IPropertyTypeFactory pf = new PropertyTypeFactory(); IDictionary <string, Property> dictionary = new Dictionary <string, Property>() { { "screenSizeInches", new Property("5.5", "screenSizeInches", pf.GetPropertyType("double")) }, { "screenResolution", new Property("123X567", "screenResolution", pf.GetPropertyType("Resolution")) } }; Type = new ItemType("test", dictionary); }
public ItemType GetItemType(string typeName) { ItemType type = null; if (connection.State == System.Data.ConnectionState.Closed) { OpenConnection(); } IDictionary <string, DBItemType> itemTypes = GetDBItemTypes(); if (itemTypes.ContainsKey(typeName)) { IDictionary <string, Property> defaultProp = new Dictionary <string, Property>(); PropertyTypeFactory propertyTypeFactory = new PropertyTypeFactory(); string query = "Select * From ItemTypeDefaultProperty,Property,PropertyType WHERE ItemTypeId = @ItemTypeId AND ItemTypeDefaultProperty.PropertyId = Property.PropertyId AND Property.PropertyTypeId = PropertyType.PropertyTypeId"; SqlCommand cmd = new SqlCommand(query, connection); cmd.Parameters.Add(new SqlParameter("ItemTypeId", itemTypes[typeName].id)); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { string value = dataReader.GetString(2); string propertyName = dataReader.GetString(4); string propertyTypeName = dataReader.GetString(7); IPropertyType propertyType = propertyTypeFactory.GetPropertyType(propertyTypeName); Property p = new Property(value, propertyName, propertyType); defaultProp.Add(propertyName, p); } cmd.Parameters.Clear(); dataReader.Close(); type = new ItemType(itemTypes[typeName].name, defaultProp); } if (connection.State == ConnectionState.Open) { CloseConnection(); } return(type); }
public IList <Item> GetItems(string producerEmail) { string itemQuery = "SELECT Item.ItemId,Item.Name,Item.ProductNumber,ItemType.Name FROM Item,ItemType WHERE ProducerEmail=@ProducerEmail AND Item.ItemTypeId=ItemType.ItemTypeId AND Item.Active = 1"; string propertiesQuery = "SELECT ItemPropertyValue.Value, Property.Name FROM ItemPropertyValue,Property WHERE ItemId=@ItemId AND Property.PropertyId = ItemPropertyValue.PropertyId"; IList <Item> items = new List <Item>(); IList <DBItem> dBItems = new List <DBItem>(); IDictionary <int, IDictionary <string, string> > itemsProperties = new Dictionary <int, IDictionary <string, string> >(); PropertyTypeFactory propertyTypeFactory = new PropertyTypeFactory(); OpenConnection(); IDictionary <string, DBItemType> itemTypes = GetDBItemTypes(); SqlCommand cmd = new SqlCommand(itemQuery, connection); cmd.Parameters.Add(new SqlParameter("ProducerEmail", producerEmail)); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { int id = dataReader.GetInt32(0); string name = dataReader.GetString(1); string productNumber = dataReader.GetString(2); string itemType = dataReader.GetString(3); dBItems.Add(new DBItem(id, name, productNumber, itemType)); } dataReader.Close(); foreach (DBItem dBItem in dBItems) { IDictionary <string, string> properties = new Dictionary <string, string>(); cmd.CommandText = propertiesQuery; cmd.Parameters.Add(new SqlParameter("ItemId", dBItem.id)); dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { string propertyName = dataReader.GetString(1); string propertyValue = dataReader.GetString(0); properties.Add(propertyName, propertyValue); } cmd.Parameters.Clear(); dataReader.Close(); itemsProperties.Add(dBItem.id, properties); } CloseConnection(); foreach (DBItem dBItem in dBItems) { Item i = new Item(dBItem.name, dBItem.productNumber, GetItemType(dBItem.itemType), itemsProperties[dBItem.id]); items.Add(i); } return(items); }