コード例 #1
0
        public static void deleteByDisplay()
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("DELETE A RECORD" + Environment.NewLine);

            //Call a method to read from the list of all records
            RecordList recordsList = MarinaTools.readList();

            Console.ForegroundColor = ConsoleColor.White;
            //Print all the records
            Console.WriteLine(String.Join(Environment.NewLine + Environment.NewLine, recordsList));

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(Environment.NewLine + "Insert the position number that you want to delete >");
            Console.ForegroundColor = ConsoleColor.White;

            string inputNumber;
            bool   repeat;

            do
            {
                inputNumber = Console.ReadLine();
                repeat      = MarinaTools.checkIntInput(inputNumber);
            } while (repeat == true);

            int delNumber = int.Parse(inputNumber);

            finalDelCheck(delNumber, recordsList);
        }
コード例 #2
0
        public static void DisRec()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("ALL RECORDS AND AVAILABLE SPACE" + Environment.NewLine);
            Console.ForegroundColor = ConsoleColor.White;

            //check the available space in the berth
            double spaceAvailable = MarinaTools.spaceAvailable();

            Console.WriteLine("The current available space in the berth is " + spaceAvailable + "m" + Environment.NewLine);

            Console.WriteLine("All the bookings:" + Environment.NewLine);

            Console.ForegroundColor = ConsoleColor.Yellow;

            //Call a method to read from the list of all records
            RecordList recordsList = MarinaTools.readList();

            //Print all the records
            foreach (var item in recordsList)
            {
                Console.WriteLine(item + Environment.NewLine);
            }


            Console.WriteLine(Environment.NewLine + "Press enter to go back to the main menu");
            Console.ResetColor();
            MarinaTools.goBackMainMenu();
        }
コード例 #3
0
        public static void deleteByNames()
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("DELETE A RECORD" + Environment.NewLine);

            //Call a method to read from the list of all records
            RecordList recordsList = MarinaTools.readList();


            Console.WriteLine("In order to delete your booking we need you to input some information: " + Environment.NewLine);
            Console.ForegroundColor = ConsoleColor.White;

            bool   repeat;
            string oName, bName;


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

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

            //find the records that contain the inserted owner name and owner boat
            IEnumerable <RecordNode> delList = recordsList.Where(record => (record.getName() == oName) && (record.getBoat() == bName));

            if (delList.Count() != 0)
            {
                Console.WriteLine(String.Join(Environment.NewLine, delList));


                Console.WriteLine("Insert the position number that you want to delete >");

                string inputNumber;

                do
                {
                    inputNumber = Console.ReadLine();
                }while (repeat == true);

                int delNumber = int.Parse(inputNumber);

                finalDelCheck(delNumber, recordsList);
            }
            else
            {
                Console.WriteLine("The entered details have 0 matches. Press enter to go back to the main menu.");
                MarinaTools.goBackMainMenu();
            }
        }
コード例 #4
0
        public static void writeList(RecordList list)         // Write a list in the file
        {
            string path = "Marina Berth Records.bin";

            using (Stream stream = File.Open(path, FileMode.Create))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                list.reorderList();                 //reorder the list, in case a record has been deleted

                bformatter.Serialize(stream, list);
            }
        }
コード例 #5
0
        public static RecordList readList()         // Read a list from a file or create a new one
        {
            string path = "Marina Berth Records.bin";

            try
            {
                using (Stream stream = File.Open(path, FileMode.Open))
                {
                    var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                    RecordList recordsList = (RecordList)bformatter.Deserialize(stream);
                    return(recordsList);
                }
            }
            catch
            {
                RecordList recordsList = new RecordList();
                return(recordsList);
            }
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        public static void finalDelCheck(int number, RecordList list)          // the user is asked to confirm the deleting
        {
            bool repeat = false;

            do
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Are you sure to delete record number " + number + " ? Typet Y to confirm or N to go back to the main menu.");
                Console.ForegroundColor = ConsoleColor.White;
                string inputDecision = Console.ReadLine();
                //converting every input to low case to avoid errors due to input format
                string lowDecision = inputDecision.ToLower(new CultureInfo("en-US", false));
                char   decision    = lowDecision[0];

                switch (decision)
                {
                case 'n':
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("No record has been deleted. Press enter to go back to the main menu. Thank you");
                    MarinaTools.goBackMainMenu();
                    break;

                case 'y':

                    DeleteRecords.deleteRecord(number, list);

                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("You did not insert a valid option. Try again");
                    Console.ForegroundColor = ConsoleColor.White;
                    repeat = true;
                    break;
                }
            }while (repeat == true);
        }
コード例 #8
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();
        }