Ejemplo n.º 1
0
        public List <InstrumentsSpec> Seach(InstrumentsSpec m_instrumensSpec)
        {
            List <InstrumentsSpec> myList = new List <InstrumentsSpec>();

            foreach (var item in Instruments_List)
            {
                if (!Match(item.InstrumensSpec, m_instrumensSpec))
                {
                    continue;
                }
                //首先进行类型的转换,然后判断是不是可以进行匹配

                if (m_instrumensSpec is GuitarSpec && item.InstrumensSpec is GuitarSpec)
                {
                    GuitarSpec guitarSpec   = item.InstrumensSpec as GuitarSpec;
                    GuitarSpec m_guitarSpec = m_instrumensSpec as GuitarSpec;
                    //如果说这个类型是一致的,所以对比一下二者的NumString属性
                    if (m_guitarSpec.NumString == guitarSpec.NumString)
                    {
                        myList.Add(guitarSpec);
                    }
                }
                else if (m_instrumensSpec is PianoSpec && item.InstrumensSpec is PianoSpec)
                {
                    PianoSpec pianoSpec   = item.InstrumensSpec as PianoSpec;
                    PianoSpec m_pianoSpec = m_instrumensSpec as PianoSpec;
                    if (m_pianoSpec.Style == pianoSpec.Style)
                    {
                        myList.Add(pianoSpec);
                    }
                }
            }
            return(myList);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Inventoy inventoy = new Inventoy();

            inventoy.AddInstruments(new Guitar("000001", 100.00, String_Enum.eighteen, new GuitarSpec(Model_Enum.A, Builder_Enum.ANY, Type_Enum.ACOUSTIC, Wood_Enum.ADIRONDACK, Wood_Enum.ADIRONDACK, String_Enum.eighteen)));

            inventoy.AddInstruments(new Guitar("000002", 200.00, String_Enum.eighteen, new GuitarSpec(Model_Enum.A, Builder_Enum.ANY, Type_Enum.ACOUSTIC, Wood_Enum.ADIRONDACK, Wood_Enum.ADIRONDACK, String_Enum.eighteen)));

            inventoy.AddInstruments(new Guitar("000003", 300.00, String_Enum.eighteen, new GuitarSpec(Model_Enum.A, Builder_Enum.ANY, Type_Enum.ACOUSTIC, Wood_Enum.ADIRONDACK, Wood_Enum.ADIRONDACK, String_Enum.eighteen)));

            inventoy.AddInstruments(new Guitar("000003", 300.00, String_Enum.eighteen, new GuitarSpec(Model_Enum.A, Builder_Enum.ANY, Type_Enum.ACOUSTIC, Wood_Enum.ADIRONDACK, Wood_Enum.ADIRONDACK, String_Enum.eighteen)));

            inventoy.AddInstruments(new Piano("000004", 400.00, Style_Enum.A, new PianoSpec(Model_Enum.A, Builder_Enum.ANY, Type_Enum.ACOUSTIC, Wood_Enum.ADIRONDACK, Wood_Enum.ADIRONDACK, Style_Enum.A)));

            inventoy.AddInstruments(new Piano("000005", 500.00, Style_Enum.A, new PianoSpec(Model_Enum.A, Builder_Enum.ANY, Type_Enum.ACOUSTIC, Wood_Enum.ADIRONDACK, Wood_Enum.ADIRONDACK, Style_Enum.A)));

            //inventoy.DispInstruments();

            GuitarSpec whatErinLikes = new GuitarSpec(Model_Enum.A, Builder_Enum.ANY, Type_Enum.ACOUSTIC, Wood_Enum.ADIRONDACK, Wood_Enum.ADIRONDACK, String_Enum.eighteen);

            List <InstrumentsSpec> myList = inventoy.Seach(whatErinLikes);

            foreach (var item in myList)
            {
                Console.WriteLine("Model:{0},\nType:{1},\nBackWood:{2},\nTopWood:{3},\n,Builder:{4},\nType:{5},\n", item.Model, item.Type, item.BackWood, item.TopWood, item.Builder, item.Type);
                if (item is GuitarSpec)
                {
                    GuitarSpec guitarSpec = item as GuitarSpec;
                    Console.WriteLine(guitarSpec.NumString);
                }
                else
                {
                    PianoSpec pianoSpec = item as PianoSpec;
                    Console.WriteLine(pianoSpec.Style);
                }
                Console.WriteLine("___________________");
            }
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public void DispInstruments()
        {
            foreach (var item in Instruments_List)
            {
                Console.WriteLine("The SerialNumber :{0},\nThe Price {1},\n", item.SerialNumber, item.Price);

                InstrumentsSpec instrumensSpec = item.InstrumensSpec as InstrumentsSpec;

                Console.WriteLine("Model:{0},\nType:{1},\nBackWood:{2},\nTopWood:{3},\n,Builder:{4},\nType:{5},\n", instrumensSpec.Model, instrumensSpec.Type, instrumensSpec.BackWood, instrumensSpec.TopWood, instrumensSpec.Builder, instrumensSpec.Type);

                if (item.InstrumensSpec is GuitarSpec)
                {
                    GuitarSpec guitarSpec = item.InstrumensSpec as GuitarSpec;
                    Console.WriteLine("String Number of Guitar:{0},\n", guitarSpec.NumString);
                }
                else if (item.InstrumensSpec is PianoSpec)
                {
                    PianoSpec pianoSpec = item.InstrumensSpec as PianoSpec;
                    Console.WriteLine("Style of Piano:{0},\n", pianoSpec.Style);
                }
                Console.WriteLine("__________________________________");
            }
        }