Ejemplo n.º 1
0
        } // end rewindFiles

        // checks for duplicate ISBN when attempting to add
        public Boolean checkForDuplicateRecordAdd(string enteredISBN)
        {
            string  nextRecord;
            Boolean isEndOfFile = true;
            Boolean success;
            int     countProcessedRecords = 0;

            nextRecord = currentBookFile.getNextRecord(ref isEndOfFile);
            while (!isEndOfFile)
            {
                countProcessedRecords++;
                BookClass book = new BookClass();
                success = book.createBookObject(nextRecord);
                if (success != true)
                {
                    MessageBox.Show
                        ("Unable to create Book Object. Book not created.",
                        "Book creation failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                } // end if statement
                if (book.bookMatch(enteredISBN) == false)
                {
                    writeOneRecord(nextRecord);
                }
                else
                {
                    MessageBox.Show
                        ("Book with ISBN: " + enteredISBN + " already exists in our library.", "ISBN error",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return(true);
                }

                nextRecord = currentBookFile.getNextRecord(ref isEndOfFile);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public Boolean createBookObject(string s) // IN: string from the Book Text File
        {
            BookClass thisBook = this;

            string[] bookString = s.Split('*');

            bookString[0] = bookString[0].Trim();

            // Convert ISBN
            hiddenISBN = bookString[0];
            if (hiddenISBN == "" || hiddenISBN == " ")
            {
                MessageBox.Show(hiddenISBN +
                                ": ISBN cannot be blank. Book File Corrupt. Execution Terminated.",
                                "ISBN in Book File Invalid", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            // title string to string (no conversion)
            // Checks for blank title

            hiddenTitle = bookString[1].Trim();
            if (hiddenTitle == " " || hiddenTitle == "")
            {
                MessageBox.Show(hiddenTitle +
                                ": Title string is empty or Blank. Book File Corrupt. Execution Terminated.",
                                "Title in Book File Invalid", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            hiddenAuthor = bookString[2].Trim();
            // Convert author to string
            // Checks for blank author
            if (hiddenAuthor == " " || hiddenAuthor == "")
            {
                MessageBox.Show(hiddenAuthor +
                                ": Author cannot be blank. Book File Corrupt. Execution Terminated.",
                                "Author in Book File Invalid", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            // Convert price to hiddenPrice
            hiddenPrice = bookString[3].Trim();
            if (hiddenPrice == " " || hiddenPrice == "")
            {
                MessageBox.Show(hiddenPrice +
                                ": Price cannot be blank. Book File Corrupt. Execution Terminated.",
                                "Price in Book File Invalid", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            // Convert quantity to hiddenQuantity
            hiddenQuantity = bookString[4].Trim();
            if (hiddenQuantity == " " || hiddenQuantity == "")
            {
                MessageBox.Show(hiddenQuantity +
                                ": Quantity cannot be blank. Book File Corrupt. Execution Terminated.",
                                "Quantity in Book File Invalid", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            // Convert Last Date of Access to a Date
            hiddenDateLastTransaction = bookString[5].Trim();
            if (hiddenDateLastTransaction == " " || hiddenDateLastTransaction == "")
            {
                MessageBox.Show(hiddenDateLastTransaction +
                                ": Date of Last Transaction cannot be blank. Book File Corrupt. Execution Terminated.",
                                "Date in Book File Invalid", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            //if all data is valid
            return(true);
        }