Exemplo n.º 1
0
        public List <Copy> GetCheckedOutCopies(DateTime currentDate)
        {
            List <Copy> AllCheckedOutCopies = new List <Copy> {
            };

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT copies.* FROM patrons JOIN checkouts ON (patrons.id = checkouts.patron_id) JOIN copies ON (copies.id = checkouts.copy_id) WHERE patron_id = @PatronId AND checkin = 0 AND @CurrentDate > checkouts.due;", conn);

            SqlParameter patronIdParameter = new SqlParameter();

            patronIdParameter.ParameterName = "@PatronId";
            patronIdParameter.Value         = this.GetId().ToString();
            cmd.Parameters.Add(patronIdParameter);

            SqlParameter currentDateParameter = new SqlParameter();

            currentDateParameter.ParameterName = "@CurrentDate";
            currentDateParameter.Value         = currentDate;
            cmd.Parameters.Add(currentDateParameter);

            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int  copyId = rdr.GetInt32(0);
                int  bookId = rdr.GetInt32(1);
                bool copyAvailability;
                if (rdr.GetByte(2) == 1)
                {
                    copyAvailability = true;
                }
                else
                {
                    copyAvailability = false;
                }

                Copy foundCopy = new Copy(bookId, copyId);
                foundCopy.SetAvailability(copyAvailability);
                AllCheckedOutCopies.Add(foundCopy);
            }

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }

            return(AllCheckedOutCopies);
        }
Exemplo n.º 2
0
        public List <Copy> GetCopies()
        {
            List <Copy> AllCopies = new List <Copy> {
            };
            SqlConnection conn    = DB.Connection();

            conn.Open();

            SqlCommand   cmd             = new SqlCommand("SELECT * FROM copies WHERE book_id = @BookId;", conn);
            SqlParameter bookIdParameter = new SqlParameter();

            bookIdParameter.ParameterName = "@BookId";
            bookIdParameter.Value         = this.GetId();
            cmd.Parameters.Add(bookIdParameter);

            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int  id     = rdr.GetInt32(0);
                int  bookId = rdr.GetInt32(1);
                bool copyAvailability;
                if (rdr.GetByte(2) == 1)
                {
                    copyAvailability = true;
                }
                else
                {
                    copyAvailability = false;
                }

                Copy newCopy = new Copy(bookId, id);
                newCopy.SetAvailability(copyAvailability);
                AllCopies.Add(newCopy);
            }

            if (rdr != null)
            {
                rdr.Close();
            }

            if (conn != null)
            {
                conn.Close();
            }

            return(AllCopies);
        }