Exemplo n.º 1
0
 /// <summary>
 /// Searches for a given hardware in the store. If there is a matching hardware ,returns it from the store, else it returns null.
 /// </summary>
 /// <param name="store"></param>
 /// <param name="hardware"></param>
 /// <returns></returns>
 public Hardware.Hardware PartInStore(CsvReader store, Hardware.Hardware hardware)
 {
     if (hardware is Hardware.Deck)
     {
         Hardware.Deck deckHardware = hardware as Hardware.Deck;
         foreach (Hardware.Deck deck in store.Decks)
         {
             if (deck.brand.ToLower().Equals(deckHardware.brand.ToLower()) && deck.length.Equals(deckHardware.length) && deck.width.Equals(deckHardware.width))
             {
                 return(deck);
             }
         }
     }
     else if (hardware is Hardware.Truck)
     {
         Hardware.Truck truckHardware = hardware as Hardware.Truck;
         foreach (Hardware.Truck truck in store.Trucks)
         {
             if (truck.brand.ToLower().Equals(truckHardware.brand.ToLower()) && truck.size.Equals(truckHardware.size))
             {
                 return(truck);
             }
         }
     }
     else if (hardware is Hardware.Wheels)
     {
         Hardware.Wheels wheelsHardware = hardware as Hardware.Wheels;
         foreach (Hardware.Wheels wheels in store.Wheels)
         {
             if (wheels.brand.ToLower().Equals(wheelsHardware.brand.ToLower()) && wheels.size.Equals(wheelsHardware.size) && wheels.hardness.ToLower().Equals(wheelsHardware.hardness.ToLower()))
             {
                 return(wheels);
             }
         }
     }
     else if (hardware is Hardware.Griptape)
     {
         Hardware.Griptape griptapeHardware = hardware as Hardware.Griptape;
         foreach (Hardware.Griptape griptape in store.Griptapes)
         {
             if (griptape.brand.ToLower().Equals(griptapeHardware.brand.ToLower()))
             {
                 return(griptape);
             }
         }
     }
     else if (hardware is Hardware.Bearings)
     {
         Hardware.Bearings bearingsHardware = hardware as Hardware.Bearings;
         foreach (Hardware.Bearings bearings in store.Bearings)
         {
             if (bearings.brand.ToLower().Equals(bearingsHardware.brand.ToLower()) && bearings.type.ToLower().Equals(bearingsHardware.type.ToLower()))
             {
                 return(bearings);
             }
         }
     }
     return(null);
 }
Exemplo n.º 2
0
 public CsvReader()
 {
     Griptapes = new Hardware.Griptape[ArraySizer("Griptape")];
     Bearings  = new Hardware.Bearings[ArraySizer("Bearings")];
     Decks     = new Hardware.Deck[ArraySizer("Deck")];
     Trucks    = new Hardware.Truck[ArraySizer("Truck")];
     Wheels    = new Hardware.Wheels[ArraySizer("Wheels")];
 }
Exemplo n.º 3
0
 public Skateboard(string name, Hardware.Wheels wheel, Hardware.Truck truck, Hardware.Griptape griptape, Hardware.Deck deck, Hardware.Bearings bearings)
 {
     this.name     = name;
     this.wheel    = wheel;
     this.truck    = truck;
     this.griptape = griptape;
     this.deck     = deck;
     this.bearings = bearings;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Reads trucks out of the CSV file and store them in CsvReader Trucks array.
 /// </summary>
 private void LoadTruck()
 {
     using (var reader = new StreamReader(@"Storage.csv"))
     {
         int index = 0;
         while (!reader.EndOfStream)
         {
             var line   = reader.ReadLine();
             var values = line.Split(",");
             if (values[0] == "Truck")
             {
                 Hardware.Truck truck = new Hardware.Truck(values[1], float.Parse(values[2], System.Globalization.CultureInfo.InvariantCulture));
                 Trucks[index] = truck;
                 index++;
             }
         }
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Prints out the store and asks for every attribute of a truck from the user, returns a Truck with the user given attributes.
 /// </summary>
 /// <param name="store"></param>
 /// <returns></returns>
 public Hardware.Truck TruckForAssembly(CsvReader store)
 {
     Hardware.Truck truck = new Hardware.Truck();
     while (true)
     {
         UI.PrintAllParts(store, "Trucks");
         try
         {
             truck.brand = UI.AskForHardware("brand", "truck");
             truck.size  = float.Parse(UI.AskForHardware("size", "truck"), CultureInfo.InvariantCulture.NumberFormat);
             return(truck);
         }
         catch (FormatException)
         {
             UI.PrintErrorMessage("Invalid format!");
             Console.Clear();
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Loads the user created skateboards from an xml.
        /// </summary>
        /// <param name="fileName"></param>
        public void LoadXML(string fileName = "inventory.xml")
        {
            XElement element   = XElement.Load(fileName);
            var      partNodes = element.Elements("Skateboard");

            foreach (var node in partNodes)
            {
                var skateboard = new Skateboard();
                var wheel      = new Hardware.Wheels();
                var truck      = new Hardware.Truck();
                var griptape   = new Hardware.Griptape();
                var deck       = new Hardware.Deck();
                var bearings   = new Hardware.Bearings();
                skateboard.name = node.Element("name").Value;
                var wheelNode = new XElement(node.Element("wheel"));
                wheel.brand    = wheelNode.Element("brand").Value;
                wheel.size     = Convert.ToInt32(wheelNode.Element("size").Value);
                wheel.hardness = wheelNode.Element("hardness").Value;
                var truckNode = new XElement(node.Element("truck"));
                truck.brand = truckNode.Element("brand").Value;
                truck.size  = float.Parse(truckNode.Element("size").Value, CultureInfo.InvariantCulture.NumberFormat);
                var griptapeNode = new XElement(node.Element("griptape"));
                griptape.brand = griptapeNode.Element("brand").Value;
                var deckNode = new XElement(node.Element("deck"));
                deck.brand  = deckNode.Element("brand").Value;
                deck.width  = float.Parse(deckNode.Element("width").Value, CultureInfo.InvariantCulture.NumberFormat);
                deck.length = float.Parse(deckNode.Element("length").Value, CultureInfo.InvariantCulture.NumberFormat);
                var bearingsNode = new XElement(node.Element("bearings"));
                bearings.brand      = bearingsNode.Element("brand").Value;
                bearings.type       = bearingsNode.Element("type").Value;
                skateboard.wheel    = wheel;
                skateboard.truck    = truck;
                skateboard.griptape = griptape;
                skateboard.deck     = deck;
                skateboard.bearings = bearings;
                Skateboards.Add(skateboard);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Updates part of a skateboard that the user can pick .
        /// </summary>
        public void SkateboardUpdate()
        {
            CsvReader store = new CsvReader();

            //Loads the parts from the csv file.
            store.LoadEverything();
            UI.Printer("Type in the name of the skateboard you want to update ");
            string name = UI.Scanner();

            //Check if there is a board with the name that the user gave
            GetSkateboardByName(name);
            for (int i = 0; i < Skateboards.Count; i++)
            {
                //Iterates through the storage and searches for the matching name
                if (Skateboards[i].name.ToLower().Equals(name.ToLower()))
                {
                    UI.Printer("Which hardware do you want to change?(Deck,Truck,Wheels,Griptape,Bearings)");
                    string hardwareType = UI.Scanner();
                    switch (hardwareType.ToLower())
                    {
                    case "deck":
                    {
                        while (true)
                        {
                            Console.Clear();
                            Hardware.Deck deck = DeckForAssembly(store);
                            try
                            {
                                Hardware.Deck deckReturnable = (Hardware.Deck)Skateboards[i].PartInStore(store, deck);
                                if (!deckReturnable.Equals(null))
                                {
                                    Skateboards[i].deck = deckReturnable;
                                    break;
                                }
                            }
                            catch (NullReferenceException)
                            {
                                UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                            }
                        }
                        break;
                    }

                    case "truck":
                    {
                        while (true)
                        {
                            Console.Clear();
                            Hardware.Truck truck = TruckForAssembly(store);
                            try
                            {
                                Hardware.Truck truckReturnable = (Hardware.Truck)Skateboards[i].PartInStore(store, truck);
                                if (!truckReturnable.Equals(null))
                                {
                                    Skateboards[i].truck = truckReturnable;
                                    break;
                                }
                            }
                            catch (NullReferenceException)
                            {
                                UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                            }
                        }
                        break;
                    }

                    case "wheels":
                    {
                        while (true)
                        {
                            Console.Clear();
                            Hardware.Wheels wheels = WheelsForAssembly(store);
                            try
                            {
                                Hardware.Wheels wheelsReturnable = (Hardware.Wheels)Skateboards[i].PartInStore(store, wheels);
                                if (!wheelsReturnable.Equals(null))
                                {
                                    Skateboards[i].wheel = wheelsReturnable;
                                    break;
                                }
                            }
                            catch (NullReferenceException)
                            {
                                UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                            }
                        }
                        break;
                    }

                    case "bearings":
                    {
                        while (true)
                        {
                            Console.Clear();
                            Hardware.Bearings bearings = BearingsForAssembly(store);
                            try
                            {
                                Hardware.Bearings bearingsReturnable = (Hardware.Bearings)Skateboards[i].PartInStore(store, bearings);
                                if (!bearingsReturnable.Equals(null))
                                {
                                    Skateboards[i].bearings = bearingsReturnable;
                                    break;
                                }
                            }
                            catch (NullReferenceException)
                            {
                                UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                            }
                        }
                        break;
                    }

                    case "griptape":
                    {
                        while (true)
                        {
                            Console.Clear();
                            Hardware.Griptape griptape = GriptapeForAssembly(store);
                            try
                            {
                                Hardware.Griptape griptapeReturnable = (Hardware.Griptape)Skateboards[i].PartInStore(store, griptape);
                                if (!griptapeReturnable.Equals(null))
                                {
                                    Skateboards[i].griptape = griptapeReturnable;
                                    break;
                                }
                            }
                            catch (NullReferenceException)
                            {
                                UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                            }
                        }
                        break;
                    }

                    default:
                    {
                        UI.PrintErrorMessage("That's not a valid hardware!");
                        break;
                    }
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new skateboard instance, with parts chosen by the user
        /// </summary>
        /// <returns></returns>
        public Skateboard SkateboardAssembly()
        {
            Console.Clear();
            CsvReader store = new CsvReader();

            //Loads hardware from the csv file
            store.LoadEverything();
            Skateboard skateboard = new Skateboard();
            //Checks if the given name already exists in the storage. Throws exception if it does.
            string name;

            while (true)
            {
                try
                {
                    name = CheckIfBoardNameExists(UI.GetNameOfBoard());
                    break;
                }
                catch (Exceptions.NameExistsException)
                {
                    UI.PrintErrorMessage("This name already exists.");
                }
            }
            skateboard.name = name;
            while (true)
            {
                Console.Clear();
                Hardware.Deck deck = DeckForAssembly(store);
                try
                {
                    //Gets the chosen deck from the store and puts it in deckReturnable .
                    Hardware.Deck deckReturnable = (Hardware.Deck)skateboard.PartInStore(store, deck);
                    if (!deckReturnable.Equals(null))
                    {
                        skateboard.deck = deckReturnable;
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                }
            }
            while (true)
            {
                Console.Clear();
                Hardware.Griptape griptape = GriptapeForAssembly(store);
                try
                {
                    Hardware.Griptape griptapeReturnable = (Hardware.Griptape)skateboard.PartInStore(store, griptape);
                    if (!griptapeReturnable.Equals(null))
                    {
                        skateboard.griptape = griptapeReturnable;
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                }
            }
            while (true)
            {
                Console.Clear();
                Hardware.Truck truck = TruckForAssembly(store);
                try
                {
                    Hardware.Truck truckReturnable = (Hardware.Truck)skateboard.PartInStore(store, truck);
                    if (!truckReturnable.Equals(null))
                    {
                        skateboard.truck = truckReturnable;
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                }
            }
            while (true)
            {
                Console.Clear();
                Hardware.Wheels wheels = WheelsForAssembly(store);
                try
                {
                    Hardware.Wheels wheelsReturnable = (Hardware.Wheels)skateboard.PartInStore(store, wheels);
                    if (!wheelsReturnable.Equals(null))
                    {
                        skateboard.wheel = wheelsReturnable;
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                }
            }
            while (true)
            {
                Console.Clear();
                Hardware.Bearings bearings = BearingsForAssembly(store);
                try
                {
                    Hardware.Bearings bearingsReturnable = (Hardware.Bearings)skateboard.PartInStore(store, bearings);
                    if (!bearingsReturnable.Equals(null))
                    {
                        skateboard.bearings = bearingsReturnable;
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!");
                }
            }
            return(skateboard);
        }