public static void deleteRecord(int number, RecordList list)         // removes a record from the list and displays the boats that have to be moved in the holding bay
        {
            int count    = list.Count();
            int movments = count - number - 1;
            IEnumerable <RecordNode> movList = list.Where(record => (record.getPosition() > number));

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("DELETE A RECORD" + Environment.NewLine);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("The record has been succesfully deleted." + Environment.NewLine);

            if (movList.Count() != 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("In order to leave access out to that boat, you have to move in the holding bay the following " + movments + " boat/s:" + Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(String.Join(Environment.NewLine, movList));
            }
            else
            {
                Console.WriteLine("There is no need to move any other boat to leave access out to this one.");
            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(Environment.NewLine + "Press enter to go back to the main menu.");

            list.removeRecordAt(number);

            if (list.EmptyCheck() != 0)             // check if the list is empty
            {
                MarinaTools.writeList(list);
            }
            else
            {
                MarinaTools.writeEmptyList();                   //if the last record has been removed, clear all the text in the file. Using the binary formatter in this case, leaves some strings in the file that interfer with the creation of new records.
            }


            MarinaTools.goBackMainMenu();
        }
Ejemplo n.º 2
0
        public static void newRecord()         // here is where the user input the information for the new object and where I create the record objects and the list
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.Clear();

            // user inputs info for his booking record
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("In order to complete the booking you have to to input some information: " + Environment.NewLine);
            Console.ForegroundColor = ConsoleColor.White;
            bool   repeat;
            string oName, bName;
            char   bType;



            do
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Name of the owner > ");
                oName  = (Console.ReadLine()).Trim();
                repeat = MarinaTools.checkStringInput(oName);
            } while (repeat == true);

            do
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Name of the boat > ");
                bName  = (Console.ReadLine()).Trim();
                repeat = MarinaTools.checkStringInput(bName);
            } while (repeat == true);


            string inputType;

            do
            {
                Console.WriteLine("input the type of the boat: N for narrow, S for sailing, M for motor > ");
                inputType = Console.ReadLine();
                repeat    = MarinaTools.checkBoatType(inputType);               //method that validates the user input for the boat type
            } while (repeat == true);

            string lowInputType = inputType.ToLower(new CultureInfo("en-US", false));

            bType = lowInputType[0];


            //reads the list from the file or creates a new one
            RecordList recordsList = MarinaTools.readList();

            //counts the number of records in the list in order to assign a position to the current object
            int bPosition = recordsList.Count();

            //Creates an object containing all the customer information
            RecordNode record = new RecordNode(oName, bName, bType, bPosition);

            //adds the current object at the end of the list
            recordsList.addRecordAtEnd(record);


            //Serializes and rewrite the list in the file of booking
            MarinaTools.writeList(recordsList);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Your booking is confirmed. Press enter to go back to the main menu.");
            MarinaTools.goBackMainMenu();
        }