现在要开发一个产品管理系统,产品种类无限分类,每类产品的参数名称和参数数量不同.比如产品种类一下的产品参数有:电源,功率,噪音....等
产品种类二下的产品参数有:温度,精度,发射率....等注:不同种类下的产品的参数数量不一定相同.怎么才能实现添加或管理种类一下的产品时,自动显示"电源,功率,噪音"等字段提供输入呢?
而添加或管理种类二下的产品时就自动显示"温度,精度,发射率"等字段.
产品种类二下的产品参数有:温度,精度,发射率....等注:不同种类下的产品的参数数量不一定相同.怎么才能实现添加或管理种类一下的产品时,自动显示"电源,功率,噪音"等字段提供输入呢?
而添加或管理种类二下的产品时就自动显示"温度,精度,发射率"等字段.
using System.Collections.Generic;
using System.Text;namespace Step5 {
// 发声类型
public enum SoundType {
Acoustic = 0,
Electric
} // 制造商
public enum Builder {
Fender = 0,
Martin,
Gibson,
Collings,
Olson
} // 木料
public enum Wood {
IndianRoseWood = 0,
BrazilianRoseWood,
Mahogany,
Maple,
Cocobolo,
Cedar,
Alder,
Sitka
} // 曼陀林琴的风格
public enum Style {
A = 0,
F
} // 乐器类型
public enum InstrumentType {
Guitar = 0,
Mandolin,
Banjo
}
}
using System.Collections.Generic;
using System.Text;namespace Step5 {
public class Instrument {
private string serialNumber; // 序列号
private double price; // 价格
private InstrumentSpec spec; // 乐器属性集
private InstrumentType type; // 乐器类型 public Instrument(string serialNumber, double price, InstrumentSpec spec, InstrumentType type) {
this.price = price;
this.serialNumber = serialNumber;
this.spec = spec;
this.type = type;
} public string SerialNumber {
get { return serialNumber; }
} public double Price {
get { return price; }
set { price = value; }
} public InstrumentType Type {
get { return type; }
} public InstrumentSpec Spec {
get { return spec; }
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace Step5 {
public abstract class InstrumentSpec : IEquatable<InstrumentSpec> {
// 用来保存所有的属性
private Hashtable properties; public InstrumentSpec(Hashtable properties) {
if (properties == null)
properties = new Hashtable();
else
this.properties = properties;
} public Hashtable Properties {
get { return properties; }
} public Object GetProperty(object propertyName) {
return properties[propertyName];
} public bool Equals(InstrumentSpec other) {
IEnumerator it = other.properties.Keys.GetEnumerator();
while (it.MoveNext()) {
if (properties[it.Current] != other.properties[it.Current])
return false;
} return true;
}
}
}
using System.Collections.Generic;
using System.Text;namespace Step5 {
public class Inventory {
private List<Instrument> instrumentList;// 维护现有的所有乐器 public Inventory() {
instrumentList = new List<Instrument>();
} // 向列表中添加 乐器
public void AddInstrument(string serialNumber, double price, InstrumentSpec spec, InstrumentType type) {
Instrument instrument = new Instrument(serialNumber, price, spec, type);
instrumentList.Add(instrument);
} // 搜索列表,寻找满足SearchSpec参数的乐器
public List<Instrument> Search(InstrumentSpec searchSpec) {
List<Instrument>.Enumerator it = instrumentList.GetEnumerator();
List<Instrument> list = new List<Instrument>(); while (it.MoveNext()) {
if (it.Current.Spec.Equals(searchSpec))
list.Add(it.Current);
}
return list;
}
}
}