Пример #1
0
        public void InsertTests()
        {
            addOneOfEach();

            int countBefore = _list.Count;

            _list.Insert(0, new A());

            int countAfter = _list.Count;

            Assert.That(countAfter, Is.EqualTo(countBefore + 1));

            Assert.That(_list[0], Is.TypeOf <A>());
            Assert.That(_list[1], Is.TypeOf <A>());
            Assert.That(_list[2], Is.TypeOf <B>());
        }
            public void LibStatus(string updateFile)
        {
            /*
             *Purpose: updates database
             *Pre: needs to be called and a database to manage
             *Post: an updated database, along with lists of returned, loaned
             * nonChanged and overdue books
             */
            // variables
            StreamReader sr; // reader
            StreamWriter sw; // writer
            string info, let, fName, lName; // string variables
            int spcLoc,changes=0, pos = 0; // int variables
            byte errorLine = 1, ODs = 0, numDays; // byte variables
            decimal price; // decimal variable
            bool PraiseBe = true; // bool variable
            ItemRec BookRec = new ItemRec(); // creates new record to store
            //intialize lists plus one parallel array
     ListClass returnList = new ListClass(), loanedList = new ListClass(),
            nonLRList = new ListClass(), ODBook = new ListClass();
            decimal[] ODPrice = new decimal[numBooks];

            sr = new StreamReader(updateFile); // opens file
            info = sr.ReadLine(); // read next line of file     
            // while not end of file and no errors
            while (info != EOF && PraiseBe == true) 
            {
                if (ErrorChecker(info, errorLine) == !PraiseBe) // if not errors
                {
                    spcLoc = info.IndexOf(SPACE); // finds space location
                    BookRec.ISBN = info.Substring(pos, spcLoc); // sets ID
                    this.Find(BookRec.ISBN); // gets record and sets currPos

                    info = info.Remove(pos, spcLoc + ONE); // wittleing info
                    spcLoc = info.IndexOf(SPACE); // finds space location
                    if (spcLoc == -1) // if no more data
                        let = info; // set whats left
                    else
                        let = info.Substring(ZERO, ONE); // grab needed let

                    changes++;
                    if (let == "L" || let == "l") // if loaned
                    {// adds one to loaned if loaned out
                        this.listArr[currPos].numOnLoan =
                            (byte)(this.listArr[currPos].numOnLoan + OREO);
                       // this.Insert(BookRec); // adds it back to main list
                        // if not in list already add it
                        if (loanedList.Find(this.listArr[currPos].ISBN)==false)
                            loanedList.Insert(this.listArr[currPos]);
                    } // end if

                    else if (let == "R" || let == "r") // if returned
                    {// subtracts one from loaned if returned
                        this.listArr[currPos].numOnLoan =
                            (byte)(this.listArr[currPos].numOnLoan - OREO);
                       // this.Insert(BookRec); // adds it back to main list
                        // if not in list already add it
                        if (returnList.Find(this.listArr[currPos].ISBN)==false)
                            returnList.Insert(this.listArr[currPos]);
                    } // end else if

                    spcLoc = info.IndexOf(SPACE);// finds space location
                    if (spcLoc == -1) // if end
                        numDays = ZERO; // add whats left
                    else
                    { // whittle info and grab days its been loaned
                        info = info.Remove(pos, spcLoc + ONE);
                        numDays = Convert.ToByte(info.Substring(pos));

                        if (numDays > WEEK) // if numdays is overdue
                        {
                            price = numDays * OD; // multiply price by days
                            // if not on list already add it
                            if (ODBook.Find(this.listArr[currPos].ISBN)==false)
                            {
                                ODBook.Insert(this.listArr[currPos]);
                                ODPrice[ODs] = price; // adds price
                                ODs++; // price postion to keep parallel
                            }
                        } // end 

                    } // end else   
                   
                } // end checker
               
                 errorLine++; // count line
                info = sr.ReadLine(); // read next line of file     
            } // end while
            sr.Close(); // closes reader
            sw = new StreamWriter(REPORTS); // open output file

            //~~~~~~~~~~~~~~~~~

            // 1st report runs through returned list and prints each
            sw.WriteLine("1st Report: Returned");
            sw.WriteLine(" ISBN: " +
           String.Format("   {0,-20}", "Lastname, Firstname")
             + SPACE + "# in Library");
            returnList.FirstPos(); // sets first position
            for (int book = 0; book < returnList.GetLength(); book++)
            {
                BookRec = returnList.Retrieve(); // gets record
                spcLoc = BookRec.authorName.IndexOf(SPACE);// gets space loc
            // gets first name then last name and prints need information
                fName = BookRec.authorName.Substring(pos, spcLoc); 
                lName = BookRec.authorName.Substring(spcLoc + ONE) + COMMA;
                sw.WriteLine(BookRec.ISBN + 
              String.Format("   {0,-20}", (lName + SPACE + fName))
              + SPACE + (BookRec.numOwned - BookRec.numOnLoan).ToString());
                returnList.NextPos(); // next position
            } // end returned list
            sw.WriteLine(); // space

            //~~~~~~~~~~~~~~~~~

            // 2nd report runs through loaned list and prints each
            sw.WriteLine("2nd Report: Loaned");
sw.WriteLine(" ISBN: " + String.Format("   {0,-20}", "Lastname, Firstname")
             + SPACE + "# in Library");
            loanedList.FirstPos(); // sets first position
            for (int book = 0; book < loanedList.GetLength(); book++)
            {
                BookRec = loanedList.Retrieve();// gets record
                spcLoc = BookRec.authorName.IndexOf(SPACE);// gets space loc
                // gets first name then last name and prints need information
                fName = BookRec.authorName.Substring(pos, spcLoc);
                lName = BookRec.authorName.Substring(spcLoc + ONE) + COMMA;
                sw.WriteLine(BookRec.ISBN +
              String.Format("   {0,-20}", (lName + SPACE + fName))
              + SPACE + (BookRec.numOwned - BookRec.numOnLoan).ToString());
                loanedList.NextPos(); // goes to next position
            } // end loaned list
            sw.WriteLine(); // space

            //~~~~~~~~~~~~~~~~~

            // 3rd report runs through unchanged list and prints each
            sw.WriteLine("3rd Report: Unchanged");
            nonLRList = this - loanedList; // subtracts l list elements
            nonLRList = nonLRList - returnList; // subtracts r list elements
            sw.WriteLine(" ISBN: " + 
          String.Format("   {0,-20}", "Lastname, Firstname")
             + SPACE + "# in Library");
            nonLRList.FirstPos(); // sets first position
            for (int book = 0; book < nonLRList.GetLength(); book++)
            {
                BookRec = nonLRList.Retrieve();// gets record
                spcLoc = BookRec.authorName.IndexOf(SPACE);// gets space loc
                // gets first name then last name and prints need information
                fName = BookRec.authorName.Substring(pos, spcLoc);
                lName = BookRec.authorName.Substring(spcLoc + ONE) + COMMA;
                sw.WriteLine(BookRec.ISBN + 
              String.Format("   {0,-20}", (lName + SPACE + fName))
              + SPACE + (BookRec.numOwned - BookRec.numOnLoan).ToString());
                nonLRList.NextPos(); // goes to next position
            } // ends unchanged list
            sw.WriteLine(); // space

            //~~~~~~~~~~~~~~~~~

            // 4th report runs through OD list and array and prints each
            sw.WriteLine("4th Report: Overdue");
            sw.WriteLine(" ISBN: " +
           String.Format("   {0,-20}", "Lastname, Firstname")
             + SPACE + "# in Library" + " Money Owed:");
            ODBook.FirstPos(); // sets first position
            for (int book = 0; book < ODBook.GetLength(); book++)
            {
                BookRec = ODBook.Retrieve();// gets record
                spcLoc = BookRec.authorName.IndexOf(SPACE);// gets space loc
              // gets first name then last name and prints need information
                fName = BookRec.authorName.Substring(pos, spcLoc);
                lName = BookRec.authorName.Substring(spcLoc + ONE) + COMMA;
                sw.WriteLine(BookRec.ISBN + 
               String.Format("   {0,-20}", (lName + SPACE + fName))
              + SPACE + (BookRec.numOwned - BookRec.numOnLoan).ToString() + 
              String.Format("{0,17}", (ODPrice[book].ToString("c"))));
                ODBook.NextPos(); // goes to next position
            } // end overdue list report

            sw.Close(); // close file writer
            PrintCurrentData(changes); // prints updated database

        } // end lib status