コード例 #1
0
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            string            choiceInstrument = "";
            List <Instrument> instruments      = new List <Instrument>();

            if (instrumentSpec is GuitarSpec)
            {
                List <Guitar> guitars = inventory.search((GuitarSpec)instrumentSpec);
                instruments      = new List <Instrument>(guitars);
                choiceInstrument = "guitar";
            }
            else if (instrumentSpec is MandolinSpec)
            {
                List <Mandolin> mandolins = inventory.search((MandolinSpec)instrumentSpec);
                instruments      = new List <Instrument>(mandolins);
                choiceInstrument = "mandolin";
            }

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these {1}s: ", name, choiceInstrument);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = null;
                        if (instrumentSpec is GuitarSpec)
                        {
                            Guitar guitar = (Guitar)instrument;
                            spec = guitar.spec;
                        }
                        else if (instrumentSpec is MandolinSpec)
                        {
                            Mandolin mandolin = (Mandolin)instrument;
                            spec = mandolin.spec;
                        }
                        if (spec == null)
                        {
                            messageFail(name);
                        }

                        msgSuccess += "\nWe have a " +
                                      Enumerations.GetEnumDescription(spec.builder) + " " + spec.model + " " +
                                      Enumerations.GetEnumDescription(spec.type) + " " + choiceInstrument + ":\n    " +
                                      Enumerations.GetEnumDescription(spec.backWood) + " back and sides,\n    " +
                                      Enumerations.GetEnumDescription(spec.topWood) + " top.\nYou can have it for only $" +
                                      instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            List <Instrument> instruments = inventory.search(instrumentSpec);

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these instruments: ", name);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = instrument.spec;
                        if (spec == null)
                        {
                            messageFail(name);
                        }

                        string instrumentType = Enumerations.GetEnumDescription((InstrumentType)spec.getProperty("instrumentType"));

                        msgSuccess += "\nWe have a " + instrumentType +
                                      " with the following properties: ";

                        foreach (string propertyName in spec.properties.Keys)
                        {
                            if (propertyName.CompareTo("instrumentType") == 0)
                            {
                                continue;
                            }
                            msgSuccess += "\n    " + propertyName + ": " + spec.getProperty(propertyName);
                        }
                        msgSuccess += "\nYou can have this " + instrumentType + " for $" +
                                      instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }
コード例 #3
0
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            List <Instrument> instruments      = inventory.search(instrumentSpec);
            string            choiceInstrument = "";

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these instruments: ", name);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = instrument.spec;
                        //choiceInstrument = guitar.ToString().ToLower();

                        if (spec == null)
                        {
                            messageFail(name);
                        }

                        msgSuccess += "\nWe have a " +
                                      Enumerations.GetEnumDescription(spec.builder) + " " + spec.model + " " +
                                      Enumerations.GetEnumDescription(spec.type) + " " + choiceInstrument + ":\n    " +
                                      Enumerations.GetEnumDescription(spec.backWood) + " back and sides,\n    " +
                                      Enumerations.GetEnumDescription(spec.topWood) + " top.\nYou can have it for only $" +
                                      instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }