Ejemplo n.º 1
0
        protected void borrowBtn_Click(object sender, EventArgs e)
        {
            //Get data of the current trading
            string index          = Request.Params["pointerId"].ToString();
            int    indexOfTrading = int.Parse(index);
            //Get id of trading
            Trading currentChosen = tradings[indexOfTrading];
            int     tradingId     = currentChosen.Id;

            /*Update borrower*/
            //Get id of borrower = current user in sessionId
            int borrowerId = user.Id;

            //Change tradingStatus to pending
            currentChosen.TradingStatus = 1;
            //Update borrowerId
            currentChosen.BorrowerID = borrowerId;

            //Update in database
            TradingDAO tradingDAO = new TradingDAO();

            tradingDAO.Update(tradingId, currentChosen);

            //Reload page
            Server.Transfer("BookDetail.aspx");
        }
Ejemplo n.º 2
0
        protected void uploadBtn_Click(object sender, EventArgs e)
        {
            User user      = (User)Session["currentUser"];
            int  tradingID = -1;
            int  bookID    = -1;

            if (user != null)
            {
                BookDAO bookDAO = new BookDAO();
                Book    book    = bookDAO.getByISBN(isbn.Text.Trim());
                if (book == null)
                {
                    string filename = uploadBookCover();
                    bookID = bookDAO.CreateBook(title.Value.Trim(), author.Value.Trim(), isbn.Text.Trim(), language.Value.Trim(), description.Value.Trim(), filename, user.Id, int.Parse(cate.SelectedItem.Value));
                }
                else
                {
                    bookID = book.Id;
                }
                if (bookID != -1)
                {
                    TradingDAO tradingDAO = new TradingDAO();
                    tradingID = tradingDAO.CreateNewTrading(condition.Value.Trim(), bookID, user.Id);
                    uploadTradingImage(tradingID);
                }

                Response.Redirect(string.Format("BookDetail.aspx?id={0}", bookID));
            }
        }
Ejemplo n.º 3
0
        private void FillData(string filter, int userID)
        {
            TradingDAO tradingDAO = new TradingDAO();
            BookDAO    bookDAO    = new BookDAO();
            UserDAO    userDAO    = new UserDAO();

            if (filter == "Pending")
            {
                tradings   = tradingDAO.GetPendingBorrowing(userID, page);
                totalPages = tradingDAO.getPages("PendingBR", userID);
            }
            else if (filter == "Borrowing")
            {
                tradings   = tradingDAO.GetBorrowing(userID, page);
                totalPages = tradingDAO.getPages("Borrowing", userID);
            }
            else if (filter == "Completed")
            {
                tradings   = tradingDAO.GetCompletedBorrow(userID, page);
                totalPages = tradingDAO.getPages("Borrowing", userID);
            }

            foreach (Trading t in tradings)
            {
                books.Add(bookDAO.GetById(t.BookID));
                users.Add(userDAO.GetById(t.LenderID));
            }
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // get total number of users
            UserDAO userDao = new UserDAO();

            UserNum = userDao.GetRowCount();

            // get total pending books
            BookDAO bookDao = new BookDAO();

            TotalPendings = bookDao.GetRowCountBookByStatus(Book.STATUS_PENDING);
            TotalAccepted = bookDao.GetRowCountBookByStatus(Book.STATUS_ACCEPTED);

            // get number of lastest avaible tradings
            TradingDAO tradingDao = new TradingDAO(5);

            N_LastestAvailableTradings = tradingDao.Get_N_BookNumByStatus(tradingNum, Trading.STATUS_AVAILABLE);

            // get list of Lastest Tradings
            LastestCompletedTradings = tradingDao.GetTradingByCommand("select top 5 * from Trading order by (completedTime) desc");
            foreach (Trading trading in LastestCompletedTradings)
            {
                Lenders.Add(userDao.GetById(trading.LenderID));
                Borrowers.Add(userDao.GetById(trading.BorrowerID));
                Books.Add(bookDao.GetById(trading.BookID));
            }

            // set status
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            int input = 1;


            TradingDAO tr = new TradingDAO();

            Trading a = new Trading();

            a.idOwner = 1;
            a.idBook  = 46;

            Console.WriteLine(tr.rejectTrading(3));

            Console.ReadKey();
        }
Ejemplo n.º 6
0
        public bool doActionTrading(string method, int idTrading)
        {
            TradingDAO tradingdao = new TradingDAO();

            switch (method)
            {
            case "Delete":     //Delete
                return(tradingdao.deleteTradingBook(idTrading));

            case "Accept":     //Accept
                return(tradingdao.acceptTrading(idTrading));

            case "Reject":     //Reject
                return(tradingdao.rejectTrading(idTrading));

            case "Complete":     //Complete
                return(tradingdao.completeTrading(idTrading));
            }
            return(false);
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // set title for page
            Page.Title = "Book Details - BookShare";

            if (Request.QueryString["id"] == null || Session["currentUser"] == null)
            {
                Server.Transfer("ErrorPage.aspx");
            }
            else
            {
                user   = (User)Session["currentUser"];
                idBook = int.Parse(Request.QueryString["id"]);
                BookDAO bookDAO = new BookDAO();
                //Get book by id
                book = bookDAO.GetById(idBook);

                //Get all lenders for this book
                TradingDAO tradingDAO    = new TradingDAO();
                int        tradingStatus = 0; //Get all available trading
                tradings = tradingDAO.getAllTradingOfOneBookPaging(idBook, user.Id, tradingStatus);

                //Get all lenders according to tradings
                lenders = new List <User>();
                UserDAO userDAO = new UserDAO();
                foreach (Trading t in tradings)
                {
                    User u = userDAO.GetById(t.LenderID);
                    lenders.Add(u);
                }

                //Get all traded images
                foreach (Trading t in tradings)
                {
                    tradingDAO = new TradingDAO();
                    List <string> tradedImages = new List <string>();
                    tradedImages   = tradingDAO.getAllTradedImages(t.Id);
                    t.TradedImages = tradedImages;
                }
            }
        }
Ejemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // set title for page
            Page.Title = "Borrowing - BookShare";
            User user = (User)Session["currentUser"];

            if (user == null)
            {
                Response.Redirect("Login.aspx");
            }

            listQuery.Add("Pending");
            listQuery.Add("Borrowing");
            listQuery.Add("Completed");

            filter = Request.QueryString["filter"] == null ? "Pending" : Request.QueryString["filter"];
            page   = Request.QueryString["page"] == null ? 1 : int.Parse(Request.QueryString["page"]);
            int id = Request.QueryString["id"] == null ? -1 : int.Parse(Request.QueryString["id"]);

            int point = Request.QueryString["point"] == null ? -1 : int.Parse(Request.QueryString["point"]);


            FillData(filter, user.Id);
            if (id != -1)
            {
                lenderID          = users[id].Id;
                myModal.Visible   = true;
                info.InnerHtml    = "Trading no: " + (id + 1) + "<br/>Lender: " + users[id].FullName + "<br/>";
                trading.InnerText = tradings[id].Id + "";
            }

            if (point != -1)
            {
                int        tradingID  = int.Parse(Request.QueryString["trading"]);
                TradingDAO tradingDAO = new TradingDAO();
                tradingDAO.UpdateLenderRatePoint(tradingID, point);
                Response.Redirect("Borrowing.aspx?filter=Completed");
            }
        }
Ejemplo n.º 9
0
        private void FillData(string filter, int userID)
        {
            TradingDAO tradingDAO = new TradingDAO();
            BookDAO    bookDAO    = new BookDAO();
            UserDAO    userDAO    = new UserDAO();

            if (filter == "Available")
            {
                tradings   = tradingDAO.GetAvailableLending(userID, page);
                totalPages = tradingDAO.getPages("AvailableLending", userID);
            }
            else if (filter == "Pending")
            {
                tradings   = tradingDAO.GetPendingLending(userID, page);
                totalPages = tradingDAO.getPages("PendingLending", userID);
            }
            else if (filter == "Lending")
            {
                tradings   = tradingDAO.GetLending(userID, page);
                totalPages = tradingDAO.getPages("Lending", userID);
            }
            else if (filter == "Completed")
            {
                tradings   = tradingDAO.GetCompletedLending(userID, page);
                totalPages = tradingDAO.getPages("CompletedLending", userID);
            }

            foreach (Trading t in tradings)
            {
                books.Add(bookDAO.GetById(t.BookID));
                if (filter != "Available")
                {
                    borrowers.Add(userDAO.GetById(t.BorrowerID));
                }
            }
        }
Ejemplo n.º 10
0
        public bool doBorrowBook(int idTrading, int idUser)
        {
            TradingDAO tradingdao = new TradingDAO();

            return(tradingdao.requestTrading(idTrading, idUser));
        }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // set title for page
            Page.Title = "Lending - BookShare";
            if (Session["currentUser"] == null)
            {
                Server.Transfer("ErrorPage.aspx");
            }
            else
            {
                User user = (User)Session["currentUser"];

                listQuery.Add("Available");
                listQuery.Add("Pending");
                listQuery.Add("Lending");
                listQuery.Add("Completed");

                filter = Request.QueryString["filter"] == null ? "Pending" : Request.QueryString["filter"];
                page   = Request.QueryString["page"] == null ? 1 : int.Parse(Request.QueryString["page"]);
                int id = Request.QueryString["id"] == null ? -1 : int.Parse(Request.QueryString["id"]);

                int point = Request.QueryString["point"] == null ? -1 : int.Parse(Request.QueryString["point"]);

                //Check if page is reload and there is some deletion action
                if (filter == "Delete")
                {
                    int tradingID = int.Parse(Request.QueryString["deleteID"]);
                    DeleteTrading(tradingID);
                    Response.Redirect("Lending.aspx?filter=Available");
                }
                else if (filter == "Approve")
                {
                    //Check if page is reload and there is some aprroval action
                    int tradingID = int.Parse(Request.QueryString["approveID"]);
                    ApproveTrading(tradingID);
                    Response.Redirect("Lending.aspx?filter=Pending");
                }
                else if (filter == "Complete")
                {
                    //Check if page is reload and there is some complete action
                    int tradingID = int.Parse(Request.QueryString["completeID"]);
                    CompleteTrading(tradingID);
                    Response.Redirect("Lending.aspx?filter=Completed");
                }

                FillData(filter, user.Id);

                if (id != -1)
                {
                    borrowerId        = borrowers[id].Id;
                    myModal.Visible   = true;
                    info.InnerHtml    = "Trading no: " + (id + 1) + "<br/>Borrower: " + borrowers[id].FullName + "<br/>";
                    trading.InnerText = tradings[id].Id + "";
                }

                if (point != -1)
                {
                    int        tradingID  = int.Parse(Request.QueryString["trading"]);
                    TradingDAO tradingDAO = new TradingDAO();
                    tradingDAO.UpdateBorrowerRatePoint(tradingID, point);
                    Response.Redirect("Lending.aspx?filter=Completed");
                }
            }
        }
Ejemplo n.º 12
0
        private void CompleteTrading(int tradingID)
        {
            TradingDAO tradingDAO = new TradingDAO();

            tradingDAO.CompleteLending(tradingID);
        }
Ejemplo n.º 13
0
        private void ApproveTrading(int tradingID)
        {
            TradingDAO tradingDAO = new TradingDAO();

            tradingDAO.ApproveLending(tradingID);
        }