├── Documentation ├── TestCases.pdf ├── projectDocument.pdf └── user-guide.pdf ├── GUI ├── bookwidget.cpp ├── bookwidget.h ├── header.h ├── imagewidget.cpp ├── imagewidget.h ├── indexs.h ├── loginwidget.cpp ├── loginwidget.h ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── publisherwidget.cpp ├── publisherwidget.h ├── signupwidget.cpp ├── signupwidget.h ├── startwidget.cpp ├── startwidget.h ├── studentwidget.cpp └── studentwidget.h ├── Library.pro ├── README.md ├── background ├── blur2.jpg └── blur5.jpg ├── book.cpp ├── book.h ├── controller.cpp ├── controller.h ├── database.cpp ├── database.h ├── icons ├── 1.png ├── 2.png ├── 3.png ├── addBook.png ├── book.png ├── book1.png ├── error.png ├── favorite.png ├── favorite1.png ├── history.png ├── laptop.jpg ├── login1.png ├── login2.png ├── login5.png ├── login6.png ├── logout.png ├── person.png ├── profile.png ├── return.png ├── save.png ├── search.jpg ├── search.png ├── search1.png ├── search_1.png ├── signup.jpg ├── signup.png └── sucess.png ├── librarian.cpp ├── librarian.h ├── main.cpp ├── publisher.cpp ├── publisher.h ├── ray2.db ├── signup.cpp ├── student.cpp ├── student.h ├── user.cpp └── user.h /Documentation/TestCases.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/Documentation/TestCases.pdf -------------------------------------------------------------------------------- /Documentation/projectDocument.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/Documentation/projectDocument.pdf -------------------------------------------------------------------------------- /Documentation/user-guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/Documentation/user-guide.pdf -------------------------------------------------------------------------------- /GUI/bookwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "bookwidget.h" 2 | 3 | extern int todayDate; 4 | BookWidget::BookWidget(Book b) 5 | { 6 | currentBook =b; 7 | } 8 | 9 | BookWidget::BookWidget(QWidget *parent) : QWidget(parent) 10 | { 11 | this->setStyleSheet("background: white;color: #00BFFF; font-size: 18px; font-weight: 400;"); 12 | this->Path = QCoreApplication::applicationDirPath(); 13 | this->grid = new QGridLayout(); 14 | 15 | this->bookName = new QLabel(); bookName->setStyleSheet("color:#00BFFF;font-weight: bold;font-size: 15px;"); 16 | this->bookType = new QLabel(); bookType->setStyleSheet("color:#00BFFF;font-weight: bold;font-size: 15px;"); 17 | this->bookPrice = new QLabel(); bookPrice->setStyleSheet("color:#00BFFF;font-weight: bold;font-size: 15px;"); 18 | this->bookPublisher = new QLabel(); bookPublisher->setStyleSheet("color:#00BFFF;font-weight: bold;font-size: 15px;"); 19 | this->bookAvailability = new QLabel(); bookAvailability->setStyleSheet("color:#00BFFF;font-weight: bold;font-size: 15px;"); 20 | 21 | this->name = new QLabel("Name :"); name->setStyleSheet("color:black;font-weight: bold;font-size: 16px;"); 22 | this->type = new QLabel("Type :"); type->setStyleSheet("color:black;font-weight: bold;font-size: 16px;"); 23 | this->price = new QLabel("Price :"); price->setStyleSheet("color:black;font-weight: bold;font-size: 16px;"); 24 | this->publisher = new QLabel("Publisher :"); publisher->setStyleSheet("color:black;font-weight: bold;font-size: 16px;"); 25 | this->availability = new QLabel("Status :"); availability->setStyleSheet("color:black;font-weight: bold;font-size: 16px;"); 26 | this->bookImage = new QLabel(); 27 | this->borrowBtn = new QPushButton("Borrow book"); 28 | this->borrowBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; width: 200px;"); 29 | this->borrowBtn->setCursor(Qt::PointingHandCursor); 30 | this->borrowed = new QMessageBox(); 31 | this->errorBox = new QMessageBox(); 32 | this->errorBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/error.png")); 33 | this->successBox = new QMessageBox(); 34 | this->successBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/sucess.png")); 35 | 36 | 37 | this->ReturnWidget = new QWidget(); 38 | this->ReturnWidget->setStyleSheet("background: white;color: #00BFFF; font-size: 18px; font-weight: 400;"); 39 | this->ReturnLayout = new QGridLayout(); 40 | this->enterBook = new QLabel("Enter expected return date :"); enterBook->setStyleSheet("color:#00BFFF;"); 41 | this->ReturnDate = new QLineEdit(); 42 | this->OkkBtn = new QPushButton("Ok"); 43 | this->OkkBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 44 | this->OkkBtn->setCursor(Qt::PointingHandCursor); 45 | 46 | this->Design(); 47 | this->Signals_Slots(); 48 | 49 | } 50 | void BookWidget::Design() 51 | { 52 | 53 | this->grid->addWidget(this->name,0,0); 54 | this->grid->addWidget(this->type,1,0); 55 | this->grid->addWidget(this->price,2,0); 56 | this->grid->addWidget(this->publisher,3,0); 57 | this->grid->addWidget(this->availability,4,0); 58 | this->grid->addWidget(this->bookName,0,1,1,-1); 59 | this->grid->addWidget(this->bookType,1,1,1,-1); 60 | this->grid->addWidget(this->bookPrice,2,1,1,-1); 61 | this->grid->addWidget(this->bookPublisher,3,1,1,-1); 62 | this->grid->addWidget(this->bookAvailability,4,1,1,-1); 63 | this->grid->addWidget(this->borrowBtn,5,0,1,-1); 64 | this->grid->addWidget(this->bookImage,0,2,5,-1); 65 | 66 | this->ReturnLayout->addWidget(enterBook,0,0,Qt::AlignLeft); 67 | this->ReturnLayout->addWidget(ReturnDate,0,1); 68 | QHBoxLayout* verticlaLayout = new QHBoxLayout; 69 | verticlaLayout->addWidget(OkkBtn); 70 | this->ReturnLayout->addLayout(verticlaLayout,2,0,1,-1); 71 | this-> ReturnWidget->setLayout(ReturnLayout); 72 | 73 | this->setMinimumWidth(400); 74 | this->setMinimumHeight(300); 75 | this->setLayout(this->grid); 76 | } 77 | 78 | 79 | void BookWidget::Signals_Slots() 80 | { 81 | // connect(this->backBtn,SIGNAL(clicked()),this,SLOT(backIsClicked())); 82 | connect(this->borrowBtn,SIGNAL(clicked()),this,SLOT(borrowIsClicked())); 83 | connect(this->OkkBtn,SIGNAL(clicked()),this,SLOT(okkkButtonClicked())); 84 | 85 | } 86 | 87 | void BookWidget::backIsClicked() 88 | { 89 | // mlhas lazma 90 | // this->hide(); 91 | } 92 | 93 | void BookWidget::borrowIsClicked() 94 | { 95 | if(!this->currentBook.getAvailability()) 96 | { 97 | this->errorBox->setText("Book is Not Available"); 98 | this->errorBox->show(); 99 | return; 100 | } 101 | ReturnWidget->show(); 102 | } 103 | 104 | void BookWidget::bookInfo(Book b) 105 | { 106 | currentBook = b; 107 | this->bookName->setText(QString::fromStdString(currentBook.getName())); 108 | this->bookType->setText(QString::fromStdString(currentBook.getType())); 109 | this->bookPrice->setText(QString::fromStdString(to_string(currentBook.getPrice()))); 110 | this->bookPublisher->setText(QString::fromStdString(currentBook.getPublisherName())); 111 | if(currentBook.getAvailability()) this->bookAvailability->setText("Available"); 112 | else this->bookAvailability->setText("Not Available"); 113 | QIcon icon(this->Path + QString::fromStdString(currentBook.getImagePath())); 114 | QPixmap image = icon.pixmap(100,100); 115 | bookImage->setPixmap(image); 116 | bookNameStr=currentBook.getName(); 117 | this->show(); 118 | } 119 | 120 | 121 | void BookWidget::error(string text) 122 | { 123 | this->errorBox->setText(QString::fromStdString(text)); 124 | this->errorBox->show(); 125 | } 126 | 127 | void BookWidget::okkkButtonClicked() 128 | { 129 | // check empty search 130 | if(this->ReturnDate->text().isEmpty()) 131 | { 132 | this->errorBox->setText("Enter Return Date"); 133 | this->errorBox->show(); 134 | return; 135 | } 136 | // return Date must be > todayDate 137 | if(this->ReturnDate->text().toInt() <= todayDate) 138 | { 139 | this->errorBox->setText("Invalid Return Data"); 140 | this->errorBox->show(); 141 | return; 142 | } 143 | 144 | this->expectedReturnDate = this->ReturnDate->text().toInt(); 145 | emit borrowBook(this->bookNameStr,this->userName ,this->expectedReturnDate); 146 | this->ReturnWidget->hide(); 147 | this->successBox->setText("Borrowed the Book Successfully !"); 148 | this->successBox->show(); 149 | 150 | } 151 | 152 | void BookWidget::setCurrentBook(Book b) 153 | { 154 | currentBook =b; 155 | this->bookName->setText(QString::fromStdString(currentBook.getName())); 156 | this->bookType->setText(QString::fromStdString(currentBook.getType())); 157 | this->bookPrice->setText(QString::fromStdString(to_string(currentBook.getPrice()))); 158 | this->bookPublisher->setText(QString::fromStdString(currentBook.getPublisherName())); 159 | if(currentBook.getAvailability()) this->bookAvailability->setText("Available"); 160 | else this->bookAvailability->setText("Not Available"); 161 | QIcon icon(this->Path + QString::fromStdString(currentBook.getImagePath())); 162 | QPixmap image = icon.pixmap(100,100); 163 | bookImage->setPixmap(image); 164 | bookNameStr=currentBook.getName(); 165 | 166 | } 167 | 168 | void BookWidget::setLoggedInUserName(string name) 169 | { 170 | this->userName = name; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /GUI/bookwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOKWIDGET_H 2 | #define BOOKWIDGET_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "book.h" 28 | #include 29 | #include 30 | #define START_WIDGET 0 31 | #define SIGNUP_WIDGET 1 32 | #define LOGIN_WIDGET 2 33 | #define PUBLISHER_WIDGET 3 34 | #define STUDENT_WIDGET 4 35 | #define BOOK_WIDGET 5 36 | 37 | class BookWidget : public QWidget 38 | { 39 | Q_OBJECT 40 | private: 41 | QGridLayout* grid; 42 | QLabel* bookName; QLabel* name; 43 | QLabel* bookType; QLabel* type; 44 | QLabel* bookPrice;QLabel* price; 45 | QLabel* bookPublisher;QLabel* publisher; 46 | QLabel* bookAvailability;QLabel* availability; 47 | QLabel* bookImage; 48 | // QPushButton* backBtn; 49 | QPushButton*borrowBtn; 50 | QMessageBox* borrowed,*errorBox,*successBox; 51 | QString Path; 52 | string bookNameStr; 53 | int expectedReturnDate; 54 | 55 | QWidget* ReturnWidget; 56 | QGridLayout* ReturnLayout; 57 | QLineEdit* ReturnDate; 58 | QPushButton *OkkBtn; 59 | 60 | string userName ; 61 | Book currentBook; 62 | 63 | QLabel* enterBook ; 64 | 65 | public: 66 | BookWidget(QWidget *parent = nullptr); 67 | BookWidget(Book b); 68 | void Design(); 69 | void Signals_Slots(); 70 | 71 | signals: 72 | void setCurrentWidget(int); 73 | void getBookInfo(string); 74 | void getBookInfo(Book); 75 | void borrowBook(string,string,int); 76 | 77 | public slots: 78 | void backIsClicked(); 79 | void borrowIsClicked(); 80 | void bookInfo(Book); 81 | void error(string); 82 | void okkkButtonClicked(); 83 | void setCurrentBook(Book b); 84 | void setLoggedInUserName(string name); 85 | 86 | }; 87 | 88 | 89 | #endif // BOOKWIDGET_H 90 | -------------------------------------------------------------------------------- /GUI/header.h: -------------------------------------------------------------------------------- 1 | #ifndef INDEXS_H 2 | #define INDEXS_H 3 | 4 | #define START_WIDGET 0 5 | #define SIGNUP_WIDGET 1 6 | #define LOGIN_WIDGET 2 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include "controller.h" 37 | #include "studentwidget.h" 38 | #include "startwidget.h" 39 | #include "signupwidget.h" 40 | #include 41 | #include "loginwidget.h" 42 | #include "bookwidget.h" 43 | 44 | #include "book.h" 45 | 46 | #include 47 | #include 48 | 49 | #endif // INDEXS_H 50 | -------------------------------------------------------------------------------- /GUI/imagewidget.cpp: -------------------------------------------------------------------------------- 1 | #include "imagewidget.h" 2 | 3 | imageWidget::imageWidget(string name , string imagePath) : QWidget() 4 | { 5 | this->layout = new QVBoxLayout(); 6 | this->label = new QLabel; 7 | this->Name = new QLabel(QString::fromStdString(name)); 8 | 9 | if(imagePath != "") 10 | this->pixMap =new QPixmap(QCoreApplication::applicationDirPath() + QString::fromStdString(imagePath)); 11 | else 12 | this->pixMap = new QPixmap(QCoreApplication::applicationDirPath() + "/../../Library-Management-System/icons/book1.png"); 13 | this->label->setPixmap(pixMap->scaled(this->width(),this->height(),Qt::KeepAspectRatio) ); 14 | this->label->setScaledContents(true); 15 | 16 | 17 | this->layout->addWidget(label); 18 | this->layout->addWidget(Name,0,Qt::AlignCenter); 19 | this->setLayout(this->layout); 20 | } 21 | 22 | void imageWidget::mousePressEvent(QMouseEvent *event) 23 | { 24 | cout << this->Name->text().toStdString() << " widget ray2 is clicked " << endl; 25 | emit bookClicked(this->Name->text().toStdString()); 26 | } 27 | -------------------------------------------------------------------------------- /GUI/imagewidget.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEWIDGET_H 2 | #define IMAGEWIDGET_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | class imageWidget : public QWidget 12 | { 13 | Q_OBJECT 14 | private: 15 | QLabel* label; 16 | QPixmap* pixMap; 17 | QLabel* Name; 18 | QVBoxLayout* layout; 19 | public: 20 | imageWidget(string name , string imagePath); 21 | protected: 22 | void mousePressEvent(QMouseEvent *event) ; 23 | signals: 24 | void bookClicked(string name); 25 | }; 26 | 27 | #endif // IMAGEWIDGET_H 28 | -------------------------------------------------------------------------------- /GUI/indexs.h: -------------------------------------------------------------------------------- 1 | #ifndef INDEXS_H 2 | #define INDEXS_H 3 | 4 | #define MIN_SIZE QSize(900,650) 5 | 6 | #define START_WIDGET 0 7 | #define SIGNUP_WIDGET 1 8 | #define LOGIN_WIDGET 2 9 | #define PUBLISHER_WIDGET 3 10 | #define STUDENT_WIDGET 4 11 | 12 | 13 | #endif // INDEXS_H 14 | -------------------------------------------------------------------------------- /GUI/loginwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "loginwidget.h" 2 | 3 | LogInWidget::LogInWidget(QWidget* parent): QWidget(parent) 4 | { 5 | this->main_grid = new QGridLayout; 6 | this->widget = new QWidget; 7 | 8 | this->image = new QLabel; 9 | this->pixMap =new QPixmap(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/laptop.jpg"); 10 | this->image->setPixmap(pixMap->scaled(this->image->width()/2,this->image->height()/2,Qt::KeepAspectRatio) ); 11 | this->image->setScaledContents(true); 12 | 13 | this->grid = new QGridLayout; 14 | this->LogInBtn = new QPushButton("Log In"); 15 | this->LogInBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 16 | this->LogInBtn->setCursor(Qt::PointingHandCursor); 17 | 18 | this->BackBtn = new QPushButton("Back"); 19 | this->BackBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 20 | this->BackBtn->setCursor(Qt::PointingHandCursor); 21 | 22 | this->Name = new QLineEdit; 23 | this->Name->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 24 | this->Password = new QLineEdit; 25 | this->Password->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 26 | 27 | this->nameLabel = new QLabel("Name"); this->nameLabel->setStyleSheet("color:black;"); 28 | this->passLabel = new QLabel("Password"); this->passLabel->setStyleSheet("color:black;"); 29 | 30 | this->publisherBtn = new QRadioButton("Publisher"); 31 | this->studentBtn = new QRadioButton("Student"); 32 | this->studentBtn->setChecked(true); 33 | 34 | this->errorBox = new QMessageBox(); 35 | this->errorBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/error.png")); 36 | 37 | this->Design(); 38 | this->outDesign(); 39 | this->Signals_Slots(); 40 | } 41 | 42 | void LogInWidget::Design() 43 | { 44 | this->widget->setStyleSheet("background-color:white;"); 45 | this->grid->addWidget(this->image,0,0,-1,1); 46 | 47 | QGridLayout* tempGrid = new QGridLayout; 48 | tempGrid->addWidget(this->nameLabel,0,0); 49 | tempGrid->addWidget(this->Name,0,1,1,-1); 50 | tempGrid->addWidget(this->passLabel,1,0); 51 | tempGrid->addWidget(this->Password,1,1,1,-1); 52 | 53 | tempGrid->addWidget(this->publisherBtn,2,0); 54 | tempGrid->addWidget(this->studentBtn,2,1); 55 | 56 | QHBoxLayout* verticalLayout = new QHBoxLayout; 57 | verticalLayout->addWidget(this->LogInBtn); 58 | verticalLayout->addWidget(this->BackBtn); 59 | tempGrid->addLayout(verticalLayout,3,0,1,-1); 60 | 61 | this->grid->addLayout(tempGrid,0,1,-1,2); 62 | this->widget->setMinimumWidth(700); 63 | this->widget->setMinimumHeight(400); 64 | 65 | this->widget->setLayout(this->grid); 66 | } 67 | 68 | void LogInWidget::outDesign() 69 | { 70 | QWidget *w1 = new QWidget; QWidget *w2 = new QWidget; 71 | this->main_grid->addWidget(w1,0,0,1,3); 72 | this->main_grid->addWidget(w2,2,0,1,3); 73 | 74 | this->main_grid->addWidget(this->widget,1,1); 75 | this->setLayout(this->main_grid); 76 | } 77 | 78 | void LogInWidget::Signals_Slots() 79 | { 80 | connect(this->LogInBtn,SIGNAL(clicked()),this,SLOT(LogInWidgetCheck())); 81 | connect(this->BackBtn,SIGNAL(clicked()),this,SLOT(buttonBack())); 82 | } 83 | 84 | void LogInWidget::LogInWidgetCheck() 85 | { 86 | cout << "ray2" << endl; 87 | if(this->Name->text().isEmpty() || this->Password->text().isEmpty()) 88 | { 89 | this->errorBox->setText("Please Fill all"); 90 | this->errorBox->show(); 91 | return; 92 | } 93 | string name,pass,email;int type=0; 94 | name=this->Name->text().toStdString(); 95 | pass=this->Password->text().toStdString(); 96 | if(this->studentBtn->isChecked())type=1; 97 | if(this->publisherBtn->isChecked())type=2; 98 | emit LogInWidgetData(name,pass,type); 99 | } 100 | 101 | void LogInWidget::error(string text) 102 | { 103 | this->errorBox->setText(QString::fromStdString(text)); 104 | this->errorBox->show(); 105 | } 106 | 107 | void LogInWidget::buttonBack() 108 | { 109 | emit setCurrentWidget(START_WIDGET); 110 | } 111 | -------------------------------------------------------------------------------- /GUI/loginwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINWIDGET_H 2 | #define LOGINWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "indexs.h" 19 | 20 | using namespace std; 21 | 22 | class LogInWidget : public QWidget 23 | { 24 | Q_OBJECT 25 | private: 26 | QGridLayout* main_grid; 27 | 28 | QWidget* widget; 29 | QGridLayout* grid; 30 | 31 | QLabel* image; 32 | QPixmap* pixMap; 33 | 34 | QPushButton* LogInBtn; 35 | QPushButton* BackBtn; 36 | QLineEdit* Name; QLabel* nameLabel; 37 | QLineEdit* Password; QLabel* passLabel; 38 | 39 | QRadioButton* publisherBtn; 40 | QRadioButton* studentBtn; 41 | 42 | QMessageBox* errorBox; 43 | 44 | public: 45 | LogInWidget(QWidget* parent = nullptr); 46 | void Design(); 47 | void outDesign(); 48 | void Signals_Slots(); 49 | 50 | signals: 51 | void LogInWidgetData(string,string,int); 52 | void setCurrentWidget(int); 53 | 54 | public slots: 55 | void LogInWidgetCheck(); 56 | void error(string); 57 | void buttonBack(); 58 | 59 | }; 60 | 61 | #endif // LOGINWIDGET_H 62 | -------------------------------------------------------------------------------- /GUI/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) 4 | { 5 | QWidget* w = new QWidget; 6 | w->setStyleSheet("background: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 #2F4F4F, stop:1 grey);"); 7 | // w->show(); 8 | 9 | this->stackWidget =new QStackedWidget(); 10 | // this->stackWidget->setStyleSheet("background-color: #F6F5E4; color: #2E2E2E; font-size: 15px; font-weight: 400;"); 11 | this->stackWidget->setStyleSheet("background: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 #00BFFF, stop:1 #F0F8FF);" 12 | "color: #2E2E2E; font-size: 15px; font-weight: 400;"); 13 | this->controller = new Controller(); 14 | this->librarian = new Librarian(); 15 | this->studentWidget = new StudentWidget(); 16 | this->startWidget = new StartWidget(); 17 | this->startWidget->setStyleSheet("background: transparent"); 18 | this->signUpWidget = new SignUp(); 19 | this->logInWidget = new LogInWidget(); 20 | this->publisherWidget = new PublisherWidget(); 21 | this->bookWidget = new BookWidget(); 22 | 23 | this->Design(); 24 | this->Signals_Slots(); 25 | 26 | this->setCentralWidget(this->stackWidget); 27 | this->stackWidget->setCurrentIndex(START_WIDGET); 28 | } 29 | 30 | void MainWindow::Design() 31 | { 32 | this->stackWidget->addWidget(this->startWidget); 33 | this->stackWidget->addWidget(this->signUpWidget); 34 | this->stackWidget->addWidget(this->logInWidget); 35 | this->stackWidget->addWidget(this->publisherWidget); 36 | this->stackWidget->addWidget(this->studentWidget); 37 | } 38 | 39 | void MainWindow::Signals_Slots() 40 | { 41 | connect(this->signUpWidget,SIGNAL(signUpData(string,string,string,int)),this->controller,SLOT(sign_up(string,string,string,int))); 42 | connect(this->controller,SIGNAL(error(string)),this->signUpWidget,SLOT(error(string))); 43 | connect(this->signUpWidget,SIGNAL(setCurrentWidget(int)),this,SLOT(changeCurrentWidget(int))); 44 | connect(this->startWidget,SIGNAL(setCurrentWidget(int)),this,SLOT(changeCurrentWidget(int))); 45 | 46 | connect(this->logInWidget,SIGNAL(LogInWidgetData(string,string,int)),this->controller,SLOT(log_in(string,string,int))); 47 | connect(this->logInWidget,SIGNAL(setCurrentWidget(int)),this,SLOT(changeCurrentWidget(int))); 48 | connect(this->controller,SIGNAL(error_login(string)),this->logInWidget,SLOT(error(string))); 49 | 50 | connect(this->controller,SIGNAL(studentLoggedin(Student)),this->studentWidget,SLOT(studentLoggedIn(Student))); 51 | connect(this->studentWidget,SIGNAL(updateStudent(string,string,string,string,int)),this->controller,SLOT(updateStudent(string,string,string,string,int))); 52 | 53 | connect(this->controller,SIGNAL(setCurrentWidget(int)),this,SLOT(changeCurrentWidget(int))); 54 | connect(this->controller,SIGNAL(publisherLoggedin(Publisher)),this->publisherWidget,SLOT(publisherLoggedIn(Publisher))); 55 | connect(this->publisherWidget,SIGNAL(setCurrentWidget(int)),this,SLOT(changeCurrentWidget(int))); 56 | connect(this->publisherWidget,SIGNAL(addBookData(string,string,string,int)),this->controller,SLOT(Upload_book(string,string,string,int))); 57 | connect(this->publisherWidget,SIGNAL(updatePublisher(string,string,string,string,int)),this->controller,SLOT(updatePublisher(string ,string,string,string,int))); 58 | 59 | // Books 60 | connect(this->controller,SIGNAL(bookInfo(Book)),this->bookWidget,SLOT(bookInfo(Book))); 61 | connect(this->bookWidget,SIGNAL(setCurrentWidget(int)),this,SLOT(changeCurrentWidget(int))); 62 | connect(this->bookWidget,SIGNAL(borrowBook(string,string,int)),this->controller,SLOT(borrowBook(string,string,int))); 63 | connect(this->controller,SIGNAL(error_noBook(string)),this->bookWidget,SLOT(error(string))); 64 | connect(this->studentWidget,SIGNAL(getBookInfo(string)),this->controller,SLOT(getBookInfo(string))); 65 | 66 | connect(this->studentWidget,SIGNAL(returnBook(string,string)),this->controller,SLOT(returnBook(string,string))); 67 | connect(this->controller,SIGNAL(error_return(string)),this->studentWidget,SLOT(error_return(string))); 68 | connect(this->controller,SIGNAL(bookReturned(int,int)),this->studentWidget,SLOT(bookReturned(int,int))); 69 | connect(this->studentWidget,SIGNAL(aa(string)),this->controller,SLOT(aa(string))); 70 | connect(this->controller,SIGNAL(borrowedBooks(vector)),this->studentWidget,SLOT(borrowedBooks(vector))); 71 | connect(this->studentWidget,SIGNAL(searchBookByName(string,string)),this->controller,SLOT(searchBookByName(string,string))); 72 | connect(this->studentWidget,SIGNAL(searchBookByType(string,string)),this->controller,SLOT(searchBookByType(string,string))); 73 | connect(this->studentWidget,SIGNAL(searchBookByPrice(int,string)),this->controller,SLOT(searchBookByPrice(int,string))); 74 | connect(this->studentWidget,SIGNAL(searchBookByPub(string,string)),this->controller,SLOT(searchBookByPub(string,string))); 75 | connect(this->controller,SIGNAL(booksFound(vector)),this->studentWidget,SLOT(booksFound(vector))); 76 | connect(this->studentWidget,SIGNAL(getSearchHistory(string)),this->controller,SLOT(getSearchHistory(string))); 77 | connect(this->controller,SIGNAL(searchedBooks(vector)),this->studentWidget,SLOT(searchedBooks(vector))); 78 | connect(this->studentWidget,SIGNAL(setCurrentWidget(int)),this,SLOT(changeCurrentWidget(int))); 79 | connect(this->studentWidget,SIGNAL(setLoggedInUserName(string)),this->bookWidget,SLOT(setLoggedInUserName(string))); 80 | 81 | connect(this->studentWidget,SIGNAL(getAllBooks()),this->controller,SLOT(getAllBooks())); 82 | 83 | //librarian 84 | 85 | //connect(this->librarian,SIGNAL(librarianWidgetOpen()),this->studentWidget,SLOT(librarianWidgetOpen())); 86 | //connect(this->studentWidget,SIGNAL(libBookState(int)),this->librarian,SLOT(libBookState(int))); 87 | 88 | } 89 | 90 | 91 | void MainWindow::changeCurrentWidget(int index) 92 | { 93 | this->stackWidget->setCurrentIndex(index); 94 | } 95 | 96 | -------------------------------------------------------------------------------- /GUI/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include "indexs.h" 5 | #include 6 | #include "controller.h" 7 | #include "librarian.h" 8 | #include "studentwidget.h" 9 | #include "startwidget.h" 10 | #include "signupwidget.h" 11 | #include "publisherwidget.h" 12 | #include 13 | #include "loginwidget.h" 14 | #include "bookwidget.h" 15 | 16 | class MainWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | private: 20 | QStackedWidget* stackWidget; 21 | Controller* controller; 22 | Librarian* librarian; 23 | StudentWidget* studentWidget; 24 | StartWidget * startWidget; 25 | SignUp* signUpWidget; 26 | LogInWidget* logInWidget; 27 | PublisherWidget* publisherWidget; 28 | BookWidget* bookWidget; 29 | public: 30 | MainWindow(QWidget *parent = nullptr); 31 | void Design(); 32 | void Signals_Slots(); 33 | 34 | public slots: 35 | void changeCurrentWidget(int); 36 | 37 | }; 38 | 39 | #endif // MAINWINDOW_H 40 | -------------------------------------------------------------------------------- /GUI/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 800 23 | 26 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /GUI/publisherwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "publisherwidget.h" 2 | 3 | PublisherWidget::PublisherWidget(QWidget *parent) : QWidget(parent) 4 | { 5 | this->main_grid = new QGridLayout; 6 | this->widget = new QWidget; 7 | // ********** header *************** 8 | this->headerWidget = new QWidget; 9 | this->headerLayout = new QHBoxLayout; 10 | 11 | this->pixMapHeader = new QPixmap(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/person.png"); 12 | this->iconHeader = new QLabel; 13 | this->Name = new QLabel; 14 | this->toolBar = new QToolBar; 15 | 16 | this->initHeader(); 17 | 18 | // book image 19 | this->image = new QLabel; 20 | this->image->setMaximumSize(QSize(200,200)); 21 | this->pixMap =new QPixmap(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/addBook.png"); 22 | this->image->setPixmap(pixMap->scaled(this->image->width(),this->image->height(),Qt::KeepAspectRatio) ); 23 | this->image->setScaledContents(true); 24 | 25 | this->setStyleSheet("font-size: 15px; font-weight: 400;"); 26 | this->grid = new QGridLayout; 27 | this->addBookBtn = new QPushButton("Add Book"); 28 | this->addBookBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; width: 200px;" 29 | "hover{background-color:white; color:#00BFFF;}"); // hover is not working 30 | this->addBookBtn->setCursor(Qt::PointingHandCursor); 31 | 32 | // this->BackBtn = new QPushButton("Logout"); 33 | // this->BackBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; width: 100px;"); 34 | // this->BackBtn->setCursor(Qt::PointingHandCursor); 35 | 36 | this->bookName = new QLineEdit; 37 | this->bookName->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 38 | this->bookPrice = new QLineEdit; 39 | this->bookPrice->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 40 | this->bookType = new QLineEdit; 41 | this->bookType->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 42 | 43 | this->pubBooksNumLabel = new QLabel("Books Published"); 44 | this->pubNameLabel = new QLabel("Publisher Name"); 45 | this->bookNameLabel = new QLabel("Book Name"); 46 | this->bookPriceLabel= new QLabel("Book Price"); 47 | this->bookTypeLabel = new QLabel("Book Type"); 48 | 49 | 50 | this->errorBox = new QMessageBox(); 51 | this->errorBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/error.png")); 52 | this->sucessBox = new QMessageBox(); 53 | this->sucessBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/sucess.png")); 54 | 55 | // this->showInfo = new QPushButton("Profile"); 56 | // this->showInfo->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; width: 100px;"); 57 | // this->showInfo->setCursor(Qt::PointingHandCursor); 58 | 59 | this->initProfileWidget(); 60 | this->Design(); 61 | this->outDesign(); 62 | this->Signals_Slots(); 63 | } 64 | 65 | void PublisherWidget::initHeader() 66 | { 67 | // ********* tool Bar ************ 68 | this->toolBar->setCursor(Qt::PointingHandCursor); 69 | QIcon logoutBtn= QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/logout.png"); 70 | QIcon profileBtn = QIcon (QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/profile.png"); 71 | QString logoutString = "Logout"; 72 | QString profileString = "Profile"; 73 | this->toolBar->addAction(logoutBtn,logoutString); 74 | this->toolBar->addAction(profileBtn,profileString); 75 | this->toolBar->setIconSize(QSize(50,50)); 76 | this->toolBar->setOrientation(Qt::Horizontal); 77 | this->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 78 | this->toolBar->setStyleSheet("QToolButton:hover{padding: 10px; background-color:white; color:#00BFFF;}" 79 | "QToolButton:select{padding: 10px;}" 80 | "QToolButton{color:white; font-weight: bold;}"); 81 | 82 | // ******** Icon ********* 83 | this->iconHeader->setMaximumSize(QSize(50,50)); 84 | this->iconHeader->setPixmap(pixMapHeader->scaled(this->iconHeader->width(),this->iconHeader->height(),Qt::KeepAspectRatio) ); 85 | this->iconHeader->setScaledContents(true); 86 | 87 | // ******** Layout Design ***************** 88 | this->headerLayout->addWidget(this->iconHeader,Qt::AlignLeft); 89 | this->headerLayout->addWidget(this->Name,Qt::AlignLeft); 90 | this->headerLayout->addItem(new QSpacerItem(300,20)); 91 | this->headerLayout->addWidget(this->toolBar,Qt::AlignRight); 92 | 93 | this->headerWidget->setLayout(this->headerLayout); 94 | this->headerWidget->setStyleSheet("background-color:#00BFFF"); 95 | 96 | // name 97 | this->Name->setText("Name"); this->Name->setStyleSheet("font-weight:bold; font-size:18px; color:white;"); 98 | 99 | this->headerWidget->setMinimumWidth(600); 100 | this->headerWidget->show(); 101 | 102 | } 103 | void PublisherWidget::outDesign() 104 | { 105 | QWidget *w1 = new QWidget; QWidget *w2 = new QWidget; 106 | this->main_grid->addWidget(w1,0,0,1,3); 107 | this->main_grid->addWidget(w2,2,0,1,3); 108 | 109 | this->main_grid->addWidget(this->widget,1,1); 110 | this->setLayout(this->main_grid); 111 | } 112 | void PublisherWidget::Design() 113 | { 114 | this->widget->setStyleSheet("background-color:white;"); 115 | 116 | this->rightLayout= new QGridLayout; 117 | this->rightLayout->addWidget(this->bookNameLabel,0,0); 118 | this->rightLayout->addWidget(this->bookName,0,1,1,-1); 119 | this->rightLayout->addWidget(this->bookPriceLabel,1,0); 120 | this->rightLayout->addWidget(this->bookPrice,1,1,1,-1); 121 | this->rightLayout->addWidget(this->bookTypeLabel,2,0); 122 | this->rightLayout->addWidget(this->bookType,2,1); 123 | this->rightLayout->addWidget(this->addBookBtn,3,0,1,-1); 124 | 125 | this->grid->addWidget(this->headerWidget,0,0,1,-1,Qt::AlignTop); 126 | this->grid->addWidget(this->image,1,0,-1,1); 127 | this->grid->addLayout(this->rightLayout,1,1,-1,2); 128 | 129 | this->grid->setVerticalSpacing(0); 130 | this->headerWidget->setMaximumHeight(100); 131 | 132 | this->widget->setMinimumWidth(700); 133 | this->widget->setMinimumHeight(400); 134 | this->widget->setLayout(this->grid); 135 | } 136 | 137 | void PublisherWidget::Signals_Slots() 138 | { 139 | connect(this->toolBar,SIGNAL(actionTriggered(QAction*)),this,SLOT(handleToolBar(QAction*))); 140 | 141 | connect(this->addBookBtn,SIGNAL(clicked()),this,SLOT(bookDataCheck())); 142 | connect(this->EditBtn,SIGNAL(clicked()),this,SLOT(editButtonClicked())); 143 | connect(this->OkBtn,SIGNAL(clicked()),this,SLOT(okButtonClicked())); 144 | } 145 | 146 | void PublisherWidget::bookDataCheck() 147 | { 148 | cout << "ray2" << endl; 149 | if(this->bookName->text().isEmpty() || this->bookType->text().isEmpty() || this->bookPrice->text().isEmpty()) 150 | { 151 | this->errorBox->setText("Please Fill all the Required Data"); 152 | this->errorBox->show(); 153 | return; 154 | } 155 | 156 | string Name; 157 | string Type; 158 | int Price; 159 | Name =this->bookName->text().toStdString(); 160 | Type =this->bookType->text().toStdString(); 161 | Price =this->bookPrice->text().toInt(); 162 | emit addBookData(this->currentPublisher.getName(),Name,Type,Price); 163 | 164 | // check box 165 | this->sucessBox->setText("Successfully Published Your Book !"); 166 | this->sucessBox->show(); 167 | } 168 | 169 | void PublisherWidget::initProfileWidget() 170 | { 171 | this->ProfileWidget = new QWidget(); 172 | this->ProfileWidget->setStyleSheet("background: #F6F5E4;color: #2E2E2E; font-size: 15px; font-weight: 400;"); 173 | 174 | this->ProfileLayout = new QGridLayout(); 175 | 176 | QLabel* name = new QLabel("Name:"); this->nameEdit = new QLineEdit(); nameEdit->setReadOnly(true); this->nameEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 177 | QLabel* password = new QLabel("Password:"); this->passEdit = new QLineEdit(); passEdit->setReadOnly(true); this->passEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 178 | QLabel* email = new QLabel("Email:"); this->emailEdit = new QLineEdit();emailEdit->setReadOnly(true);this->emailEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 179 | QLabel* cashAmount = new QLabel("Cash Amount:");this->cashEdit = new QLineEdit(); cashEdit->setReadOnly(true); this->cashEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 180 | 181 | this->EditBtn = new QPushButton("Edit"); 182 | this->EditBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 183 | this->EditBtn->setCursor(Qt::PointingHandCursor); 184 | 185 | this->OkBtn = new QPushButton("Ok"); 186 | this->OkBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 187 | this->OkBtn->setCursor(Qt::PointingHandCursor); 188 | 189 | QLabel *image; QPixmap* pixMap; 190 | image = new QLabel; 191 | pixMap =new QPixmap(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/person.png"); 192 | image->setPixmap(pixMap->scaled(image->width()/4,image->height()/4,Qt::KeepAspectRatio) ); 193 | image->setScaledContents(true); 194 | 195 | QLabel* setting =new QLabel("Profile Settings"); 196 | QFrame* line = new QFrame; line->setFrameShape(QFrame::HLine); 197 | 198 | this->ProfileLayout->addWidget(setting,0,0,1,1); 199 | this->ProfileLayout->addWidget(image,1,0,1,1); 200 | this->ProfileLayout->addWidget(line,2,0,1,-1); 201 | 202 | this->ProfileLayout->addWidget(name,3,0,Qt::AlignLeft); 203 | this->ProfileLayout->addWidget(nameEdit,3,1); 204 | 205 | this->ProfileLayout->addWidget(password,4,0,Qt::AlignLeft); 206 | this->ProfileLayout->addWidget(passEdit,4,1); 207 | 208 | this->ProfileLayout->addWidget(email,5,0,Qt::AlignLeft); 209 | this->ProfileLayout->addWidget(emailEdit,5,1); 210 | 211 | this->ProfileLayout->addWidget(cashAmount,6,0,Qt::AlignLeft); 212 | this->ProfileLayout->addWidget(cashEdit,6,1); 213 | 214 | QHBoxLayout* horizontalLayout = new QHBoxLayout; 215 | horizontalLayout->addWidget(this->EditBtn); 216 | horizontalLayout->addWidget(this->OkBtn); 217 | this->ProfileLayout->addLayout(horizontalLayout,7,0,1,-1); 218 | 219 | this->ProfileWidget->setLayout(this->ProfileLayout); 220 | this->ProfileWidget->setMinimumWidth(500); 221 | this->ProfileWidget->setMinimumHeight(400); 222 | 223 | } 224 | 225 | void PublisherWidget::error(string text) 226 | { 227 | this->errorBox->setText(QString::fromStdString(text)); 228 | this->errorBox->show(); 229 | } 230 | 231 | void PublisherWidget::buttonBack() 232 | { 233 | emit setCurrentWidget(START_WIDGET); 234 | } 235 | 236 | void PublisherWidget::publisherLoggedIn(Publisher Publisher) 237 | { 238 | this->currentPublisher = Publisher; 239 | this->nameEdit->setText(QString::fromStdString(this->currentPublisher.getName())); 240 | this->passEdit->setText(QString::fromStdString(this->currentPublisher.getPassword())); 241 | this->emailEdit->setText(QString::fromStdString(this->currentPublisher.getEmail())); 242 | this->cashEdit->setText(QString::fromStdString(to_string(this->currentPublisher.getCash()))); 243 | 244 | this->Name->setText(QString::fromStdString(this->currentPublisher.getName())); 245 | } 246 | 247 | void PublisherWidget::showInfoBtnClicked() 248 | { 249 | this->ProfileWidget->show(); 250 | } 251 | 252 | void PublisherWidget::handleToolBar(QAction * action) 253 | { 254 | QString action_name = action->text(); 255 | if(action_name == "Logout") 256 | emit setCurrentWidget(START_WIDGET); 257 | else if (action_name == "Profile") 258 | this->showInfoBtnClicked(); 259 | } 260 | 261 | void PublisherWidget::editButtonClicked() 262 | { 263 | this->nameEdit->setReadOnly(false); 264 | this->passEdit->setReadOnly(false); 265 | this->emailEdit->setReadOnly(false); 266 | this->cashEdit->setReadOnly(false); 267 | } 268 | 269 | void PublisherWidget::okButtonClicked() 270 | { 271 | // update Publisher DataBase 272 | string name = this->nameEdit->text().toStdString(); 273 | string pass = this->passEdit->text().toStdString(); 274 | string email = this->emailEdit->text().toStdString(); 275 | int cash = this->cashEdit->text().toInt(); 276 | 277 | emit updatePublisher(this->currentPublisher.getName(),name,pass,email,cash); 278 | 279 | this->currentPublisher.setName(name); 280 | this->currentPublisher.setPassword(pass); 281 | this->currentPublisher.setEmail(email); 282 | this->currentPublisher.setCash(cash); 283 | 284 | this->nameEdit->setReadOnly(true); 285 | this->passEdit->setReadOnly(true); 286 | this->emailEdit->setReadOnly(true); 287 | this->cashEdit->setReadOnly(true); 288 | 289 | this->sucessBox->setText("Edit Successfully !"); 290 | this->sucessBox->show(); 291 | this->ProfileWidget->hide(); 292 | } 293 | 294 | -------------------------------------------------------------------------------- /GUI/publisherwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef PUBLISHERWIDGET_H 2 | #define PUBLISHERWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "indexs.h" 19 | #include "publisher.h" 20 | #include 21 | 22 | using namespace std; 23 | class PublisherWidget : public QWidget 24 | { 25 | Q_OBJECT 26 | private : 27 | QGridLayout* main_grid; 28 | 29 | // ******** Header ************* 30 | QWidget* headerWidget; 31 | QHBoxLayout* headerLayout; 32 | 33 | QPixmap* pixMapHeader; 34 | QLabel* iconHeader; 35 | QLabel* Name; 36 | QToolBar* toolBar; 37 | // ******** White Widget ******** 38 | QGridLayout* grid; 39 | QWidget* widget; 40 | QLabel* image; 41 | QPixmap* pixMap; 42 | QGridLayout* rightLayout; 43 | 44 | 45 | 46 | QPushButton* addBookBtn; 47 | QPushButton* BackBtn; 48 | QLabel* pubNameLabel; 49 | QLabel* pubBooksNumLabel; 50 | 51 | QLineEdit* bookName; QLabel* bookNameLabel; 52 | QLineEdit* bookPrice; QLabel* bookPriceLabel; 53 | QLineEdit* bookType; QLabel* bookTypeLabel; 54 | QMessageBox* errorBox; 55 | QMessageBox* sucessBox; 56 | 57 | QWidget* ProfileWidget; 58 | QGridLayout* ProfileLayout; 59 | QLineEdit* nameEdit ,*passEdit , * emailEdit ,* cashEdit ; 60 | QPushButton *EditBtn , *OkBtn; 61 | Publisher currentPublisher; 62 | QPushButton* showInfo; 63 | 64 | public: 65 | PublisherWidget(QWidget *parent = nullptr); 66 | void initHeader(); 67 | void Design(); 68 | void outDesign(); 69 | void Signals_Slots(); 70 | void initProfileWidget(); 71 | 72 | 73 | signals: 74 | void addBookData(string,string,string,int); 75 | void setCurrentWidget(int); 76 | void updatePublisher(string,string,string,string,int); 77 | 78 | public slots: 79 | void bookDataCheck(); 80 | void error(string); 81 | void buttonBack(); 82 | void editButtonClicked(); 83 | void okButtonClicked(); 84 | void publisherLoggedIn(Publisher); 85 | void showInfoBtnClicked(); 86 | 87 | void handleToolBar(QAction*); 88 | 89 | }; 90 | 91 | #endif // PUBLISHERWIDGET_H 92 | -------------------------------------------------------------------------------- /GUI/signupwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "signupwidget.h" 2 | 3 | SignUp::SignUp(QWidget* parent): QWidget(parent) 4 | { 5 | this->main_grid = new QGridLayout; 6 | this->widget = new QWidget; 7 | 8 | this->image = new QLabel; 9 | this->pixMap =new QPixmap(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/signup.jpg"); 10 | this->image->setPixmap(pixMap->scaled(this->image->width()/2,this->image->height()/2,Qt::KeepAspectRatio) ); 11 | this->image->setScaledContents(true); 12 | 13 | this->grid = new QGridLayout; 14 | this->SignUpBtn = new QPushButton("Sign Up"); 15 | this->SignUpBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white;"); 16 | this->SignUpBtn->setCursor(Qt::PointingHandCursor); 17 | this->BackBtn = new QPushButton("Back"); 18 | this->BackBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 19 | this->BackBtn->setCursor(Qt::PointingHandCursor); 20 | this->Name = new QLineEdit; 21 | this->Name->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 22 | 23 | this->Email = new QLineEdit; 24 | this->Email->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 25 | 26 | this->Password = new QLineEdit; 27 | this->Password->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 28 | 29 | this->ConfirmPassword = new QLineEdit; 30 | this->ConfirmPassword->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 31 | 32 | this->nameLabel = new QLabel("Name"); 33 | this->emailLabel= new QLabel("Email"); 34 | this->passLabel = new QLabel("Password"); 35 | this->confirmLabel = new QLabel("Confirm Password"); 36 | 37 | this->publisherBtn = new QRadioButton("Publisher"); 38 | this->studentBtn = new QRadioButton("Student"); 39 | this->studentBtn->setChecked(true); 40 | 41 | this->errorBox = new QMessageBox(); 42 | this->errorBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/error.png")); 43 | 44 | this->Design(); 45 | this->outDesign(); 46 | this->Signals_Slots(); 47 | } 48 | void SignUp::outDesign() 49 | { 50 | QWidget *w1 = new QWidget; QWidget *w2 = new QWidget; 51 | this->main_grid->addWidget(w1,0,0,1,3); 52 | this->main_grid->addWidget(w2,2,0,1,3); 53 | 54 | this->main_grid->addWidget(this->widget,1,1); 55 | this->setLayout(this->main_grid); 56 | } 57 | void SignUp::Design() 58 | { 59 | this->widget->setStyleSheet("background-color:white;"); 60 | this->grid->addWidget(this->image,0,0,-1,1); 61 | 62 | QGridLayout* tempGrid = new QGridLayout; 63 | tempGrid->addWidget(this->nameLabel,0,0); 64 | tempGrid->addWidget(this->Name,0,1,1,-1); 65 | 66 | tempGrid->addWidget(this->emailLabel,1,0); 67 | tempGrid->addWidget(this->Email,1,1,1,-1); 68 | 69 | tempGrid->addWidget(this->passLabel,2,0); 70 | tempGrid->addWidget(this->Password,2,1,1,-1); 71 | 72 | tempGrid->addWidget(this->confirmLabel,3,0); 73 | tempGrid->addWidget(this->ConfirmPassword,3,1,1,-1); 74 | 75 | tempGrid->addWidget(this->publisherBtn,4,0); 76 | tempGrid->addWidget(this->studentBtn,4,1); 77 | 78 | QHBoxLayout* verticalLayout = new QHBoxLayout; 79 | verticalLayout->addWidget(this->SignUpBtn); 80 | verticalLayout->addWidget(this->BackBtn); 81 | tempGrid->addLayout(verticalLayout,5,0,1,-1); 82 | 83 | this->grid->addLayout(tempGrid,0,1,-1,2); 84 | this->widget->setMinimumWidth(700); 85 | this->widget->setMinimumHeight(400); 86 | 87 | this->widget->setLayout(this->grid); 88 | } 89 | 90 | void SignUp::Signals_Slots() 91 | { 92 | connect(this->SignUpBtn,SIGNAL(clicked()),this,SLOT(signUpCheck())); 93 | connect(this->BackBtn,SIGNAL(clicked()),this,SLOT(buttonBack())); 94 | } 95 | 96 | void SignUp::signUpCheck() 97 | { 98 | cout << "ray2" << endl; 99 | if(this->Name->text().isEmpty() || this->Email->text().isEmpty() || this->Password->text().isEmpty() 100 | || this->ConfirmPassword->text().isEmpty() ) 101 | { 102 | this->errorBox->setText("Please Fill all"); 103 | this->errorBox->show(); 104 | return; 105 | } 106 | if (this->Password->text() != this->ConfirmPassword->text()) 107 | { 108 | this->errorBox->setText("Passwords Don't Match"); 109 | this->errorBox->show(); 110 | return; 111 | } 112 | 113 | string name,pass,email;int type=0; 114 | name=this->Name->text().toStdString(); 115 | email=this->Email->text().toStdString(); 116 | pass=this->Password->text().toStdString(); 117 | if(this->studentBtn->isChecked())type=1; 118 | if(this->publisherBtn->isChecked())type=2; 119 | 120 | emit signUpData(name,email,pass,type); 121 | } 122 | 123 | void SignUp::error(string text) 124 | { 125 | this->errorBox->setText(QString::fromStdString(text)); 126 | this->errorBox->show(); 127 | } 128 | 129 | void SignUp::buttonBack() 130 | { 131 | emit setCurrentWidget(0); 132 | } 133 | -------------------------------------------------------------------------------- /GUI/signupwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SIGNUP_H 2 | #define SIGNUP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "indexs.h" 19 | 20 | using namespace std; 21 | 22 | class SignUp : public QWidget 23 | { 24 | Q_OBJECT 25 | private: 26 | QGridLayout* main_grid; 27 | 28 | QWidget* widget; 29 | 30 | QLabel* image; 31 | QPixmap* pixMap; 32 | 33 | QGridLayout* grid; 34 | QPushButton* SignUpBtn; 35 | QPushButton* BackBtn; 36 | 37 | QLineEdit* Name; QLabel* nameLabel; 38 | QLineEdit* Email; QLabel* emailLabel; 39 | QLineEdit* Password; QLabel* passLabel; 40 | QLineEdit* ConfirmPassword; QLabel* confirmLabel; 41 | 42 | QRadioButton* publisherBtn; 43 | QRadioButton* studentBtn; 44 | 45 | QMessageBox* errorBox; 46 | 47 | public: 48 | SignUp(QWidget* parent = nullptr); 49 | void Design(); 50 | void outDesign(); 51 | void Signals_Slots(); 52 | 53 | signals: 54 | void signUpData(string,string,string,int); 55 | void setCurrentWidget(int); 56 | 57 | public slots: 58 | void signUpCheck(); 59 | void error(string); 60 | void buttonBack(); 61 | 62 | }; 63 | 64 | #endif // SIGNUP_H 65 | -------------------------------------------------------------------------------- /GUI/startwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "startwidget.h" 2 | StartWidget::StartWidget(QWidget *parent) : QLabel(parent) 3 | { 4 | this->grid = new QGridLayout(); 5 | 6 | this->pixMap =new QPixmap(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/background/blur5.jpg"); 7 | this->setPixmap(pixMap->scaled(this->width(),this->height(),Qt::KeepAspectRatio) ); 8 | this->setScaledContents(true); 9 | 10 | this->initButtons(); 11 | 12 | this->grid->addWidget(this->toolBar,0,0,Qt::AlignCenter); 13 | this->setLayout(this->grid); 14 | this->setMinimumSize(MIN_SIZE); 15 | 16 | this->Signals_Slots(); 17 | 18 | } 19 | 20 | void StartWidget::initButtons() 21 | { 22 | this->toolBar =new QToolBar(""); 23 | this->toolBar->setCursor(Qt::PointingHandCursor); 24 | this->loginBtn= QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/login6.png"); 25 | this->signupBtn = QIcon (QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/signup.png"); 26 | this->loginString = "Login"; 27 | this->signupString = "Sign Up"; 28 | this->toolBar->addAction(this->loginBtn,this->loginString); 29 | this->toolBar->addAction(this->signupBtn,this->signupString); 30 | this->toolBar->setIconSize(QSize(200,200)); 31 | this->toolBar->setOrientation(Qt::Horizontal); 32 | this->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 33 | this->toolBar->setStyleSheet("QToolButton:hover{padding: 15px;}" 34 | "QToolButton:select{padding: 15px;}" 35 | "QToolButton{color:white; font-weight: bold; margin:10px;" 36 | " padding: 30px; border-radius: 50; font-size: 30px;}"); 37 | } 38 | 39 | void StartWidget::Signals_Slots() 40 | { 41 | connect(this->toolBar,SIGNAL(actionTriggered(QAction*)),this,SLOT(ButtonClicked(QAction*))); 42 | } 43 | 44 | void StartWidget::ButtonClicked(QAction *action) 45 | { 46 | if (action->text() == this->loginString ) 47 | emit setCurrentWidget(LOGIN_WIDGET); 48 | else if (action->text() == this->signupString) 49 | emit setCurrentWidget(SIGNUP_WIDGET); 50 | } 51 | -------------------------------------------------------------------------------- /GUI/startwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef STARTWIDGET_H 2 | #define STARTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "indexs.h" 15 | #include 16 | #include 17 | 18 | class StartWidget : public QLabel 19 | { 20 | Q_OBJECT 21 | private: 22 | QGridLayout* grid; 23 | QIcon loginBtn , signupBtn; 24 | QString loginString , signupString; 25 | QPixmap* pixMap; 26 | QToolBar* toolBar; 27 | public: 28 | StartWidget(QWidget *parent = nullptr); 29 | void initButtons(); 30 | void Signals_Slots(); 31 | 32 | signals: 33 | void setCurrentWidget(int); 34 | 35 | public slots: 36 | void ButtonClicked(QAction* action); 37 | }; 38 | 39 | #endif // STARTWIDGET_H 40 | -------------------------------------------------------------------------------- /GUI/studentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "studentwidget.h" 2 | 3 | extern int todayDate; 4 | Book b; 5 | 6 | StudentWidget::StudentWidget(QWidget *parent) : QWidget(parent) 7 | {b.setPrice(10); 8 | this->Path = QCoreApplication::applicationDirPath(); 9 | this->grid = new QGridLayout(); 10 | this->toolBar = new QToolBar(); 11 | this->searchLineEdit = new QLineEdit(); 12 | this->searchLineEdit->setStyleSheet("background: white;"); 13 | 14 | this->viewBooksScroll = new QScrollArea(); 15 | this->viewBooksWidget = new QWidget(); 16 | this->viewBooksWidget->setStyleSheet("background: white;"); 17 | this->viewBooksLayout = new QGridLayout(); 18 | this->lastSize.setWidth(0); 19 | this->lastSize.setHeight(0); 20 | 21 | //today to be designed 22 | this->increaseTime = new QPushButton("Add day"); 23 | this->increaseTime->setStyleSheet("background: #008080; border-radius: 10px; padding: 10px 0px; color: white;" 24 | "font-weight: bold;" 25 | "font-size: 15px;"); 26 | this->increaseTime->setCursor(Qt::PointingHandCursor); 27 | 28 | this->today = new QLabel(); 29 | this->today->setText(" Today: "+QString::fromStdString(to_string(todayDate))); 30 | this->today->setStyleSheet("color:#00BFFF;font-weight: bold;font-size: 18px; background-color:white;"); 31 | 32 | this->errorBox = new QMessageBox(); 33 | this->successBox = new QMessageBox(); 34 | this->successBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/sucess.png")); 35 | this->tabWidget = new QTabWidget(); 36 | 37 | this->initProfileWidget(); 38 | this->initReturnWidget(); 39 | this->initBorrowedWidget(); 40 | this->initSearchWidget(); 41 | this->initHistoryWidget(); 42 | this->initLibrarianWidget(); 43 | this->initToolBar(); 44 | this->Design(); 45 | this->Signals_Slots(); 46 | } 47 | void StudentWidget::initToolBar() 48 | { 49 | this->toolBar->setMovable(false); 50 | this->toolBar->setIconSize(QSize(50,50)); 51 | this->toolBar->setOrientation(Qt::Vertical); 52 | this->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 53 | 54 | QIcon Profile(this->Path + "/../../Library-Management-System/icons/profile.png"); QString ProfileText = "Profile"; 55 | QIcon Search(this->Path + "/../../Library-Management-System/icons/search.png"); QString SearchText = "Search"; 56 | QIcon favorite(this->Path + "/../../Library-Management-System/icons/book.png"); QString favoriteText = "My Books"; 57 | QIcon History(this->Path + "/../../Library-Management-System/icons/history.png"); QString HistoryText = "History"; 58 | QIcon Return(this->Path + "/../../Library-Management-System/icons/return.png"); QString ReturnText = "Return"; 59 | QIcon LogOut(this->Path + "/../../Library-Management-System/icons/logout.png"); QString LogOutText = "Log Out"; 60 | 61 | this->toolBar->addAction(Profile,ProfileText); 62 | this->toolBar->addAction(Search,SearchText); 63 | this->toolBar->addAction(favorite,favoriteText); 64 | // this->toolBar->addAction(Borrowed,BorrowedText); 65 | this->toolBar->addAction(History,HistoryText); 66 | this->toolBar->addAction(Return,ReturnText); 67 | this->toolBar->addAction(LogOut,LogOutText); 68 | this->toolBar->setStyleSheet("QToolButton:hover{padding: 5px;background-color: white; color: black;}" 69 | "QToolButton:select{padding: 5px;background-color: white; color: black;}" 70 | "QToolButton{padding: 10px; border-radius: 10px;}" 71 | "QToolBar{background-color:white;}"); 72 | } 73 | void StudentWidget::initProfileWidget() 74 | { 75 | this->ProfileWidget = new QWidget(); 76 | this->ProfileWidget->setStyleSheet("background: white;color: #2E2E2E; font-size: 15px; font-weight: 400;"); 77 | this->ProfileLayout = new QGridLayout(); 78 | 79 | QLabel* name = new QLabel("Name:"); this->nameEdit = new QLineEdit(); nameEdit->setReadOnly(true); this->nameEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 80 | QLabel* password = new QLabel("Password:"); this->passEdit = new QLineEdit(); passEdit->setReadOnly(true); this->passEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 81 | QLabel* email = new QLabel("Email:"); this->emailEdit = new QLineEdit();emailEdit->setReadOnly(true); this->emailEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 82 | QLabel* cashAmount = new QLabel("Cash Amount:");this->cashEdit = new QLineEdit(); cashEdit->setReadOnly(true); this->cashEdit->setStyleSheet("QLineEdit{ background-color:white;border: 2px solid #00BFFF;border-radius: 5px;}"); 83 | // name->setStyleSheet("background: white; color:#00BFFF;"); 84 | // password->setStyleSheet("background: white; color:#00BFFF;"); 85 | // email->setStyleSheet("background: white; color:#00BFFF;"); 86 | // cashAmount->setStyleSheet("background: white; color:#00BFFF;"); 87 | 88 | QLabel *image; QPixmap* pixMap; 89 | image = new QLabel; 90 | pixMap =new QPixmap(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/person.png"); 91 | image->setPixmap(pixMap->scaled(image->width()/4,image->height()/4,Qt::KeepAspectRatio) ); 92 | image->setScaledContents(true); 93 | 94 | this->EditBtn = new QPushButton("Edit"); 95 | this->EditBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 96 | this->EditBtn->setCursor(Qt::PointingHandCursor); 97 | 98 | this->OkBtn = new QPushButton("Ok"); 99 | this->OkBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 100 | this->OkBtn->setCursor(Qt::PointingHandCursor); 101 | 102 | QLabel* setting =new QLabel("Profile Settings"); 103 | QFrame* line = new QFrame; line->setFrameShape(QFrame::HLine); 104 | 105 | this->ProfileLayout->addWidget(setting,0,0,1,1); 106 | this->ProfileLayout->addWidget(image,1,0,1,1); 107 | this->ProfileLayout->addWidget(line,2,0,1,-1); 108 | 109 | this->ProfileLayout->addWidget(name,3,0,Qt::AlignLeft); 110 | this->ProfileLayout->addWidget(nameEdit,3,1); 111 | 112 | this->ProfileLayout->addWidget(password,4,0,Qt::AlignLeft); 113 | this->ProfileLayout->addWidget(passEdit,4,1); 114 | 115 | this->ProfileLayout->addWidget(email,5,0,Qt::AlignLeft); 116 | this->ProfileLayout->addWidget(emailEdit,5,1); 117 | 118 | this->ProfileLayout->addWidget(cashAmount,6,0,Qt::AlignLeft); 119 | this->ProfileLayout->addWidget(cashEdit,6,1); 120 | 121 | QHBoxLayout* horizontalLayout = new QHBoxLayout; 122 | horizontalLayout->addWidget(this->EditBtn); 123 | horizontalLayout->addWidget(this->OkBtn); 124 | this->ProfileLayout->addLayout(horizontalLayout,7,0,1,-1); 125 | 126 | this->ProfileWidget->setLayout(this->ProfileLayout); 127 | this->ProfileWidget->setMinimumWidth(500); 128 | this->ProfileWidget->setMinimumHeight(400); 129 | } 130 | void StudentWidget::initReturnWidget() 131 | { 132 | this->ReturnWidget = new QWidget(); 133 | this->ReturnWidget->setStyleSheet("background: white;color: #2E2E2E; font-size: 15px; font-weight: 400;"); 134 | this->ReturnLayout = new QGridLayout(); 135 | 136 | QLabel* enterBook = new QLabel("Enter return book :"); enterBook->setStyleSheet("color:#00BFFF"); 137 | this->ReturnBook = new QLineEdit(); 138 | this->ReturnBook->setStyleSheet("background: white;"); 139 | 140 | this->BackBtn = new QPushButton("Back"); 141 | this->BackBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 142 | this->BackBtn->setCursor(Qt::PointingHandCursor); 143 | 144 | this->OkkBtn = new QPushButton("Ok"); 145 | this->OkkBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 146 | this->OkkBtn->setCursor(Qt::PointingHandCursor); 147 | 148 | this->ReturnLayout->addWidget(enterBook,0,0,Qt::AlignLeft); 149 | this->ReturnLayout->addWidget(ReturnBook,0,1); 150 | 151 | QHBoxLayout* verticlaLayout = new QHBoxLayout; 152 | verticlaLayout->addWidget(this->BackBtn); 153 | verticlaLayout->addWidget(this->OkkBtn); 154 | this->ReturnLayout->addLayout(verticlaLayout,2,0,1,-1); 155 | 156 | this->ReturnWidget->setLayout(this->ReturnLayout); 157 | } 158 | void StudentWidget::initBorrowedWidget() 159 | { 160 | this->BorrowedWidget = new QWidget(); 161 | this->BorrowedWidget->setStyleSheet("color: #2E2E2E; font-size: 15px; font-weight: 400;"); 162 | this->borrowedList = new QTreeWidget(); 163 | this->borrowedList->setStyleSheet("background: white"); 164 | this->Ok1Btn = new QPushButton("Ok"); 165 | this->Ok1Btn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 166 | this->Ok1Btn->setCursor(Qt::PointingHandCursor); 167 | this->BorrowedWidget->setMinimumSize(600,150); 168 | 169 | QStringList headerLabels; 170 | headerLabels.push_back(tr("Borrowed Book")); 171 | headerLabels.push_back(tr("Borrowed Date")); 172 | headerLabels.push_back(tr("Expected Return Date")); 173 | headerLabels.push_back(tr("Expected Bill")); 174 | this->borrowedList->setColumnCount(headerLabels.count()); 175 | this->borrowedList->setHeaderLabels(headerLabels); 176 | 177 | this->borrowedList->setColumnWidth(0,150); 178 | this->borrowedList->setColumnWidth(1,150); 179 | this->borrowedList->setColumnWidth(2,150); 180 | this->borrowedList->setColumnWidth(3,100); 181 | 182 | QVBoxLayout* verticlaLayout = new QVBoxLayout; 183 | verticlaLayout->addWidget(this->borrowedList); 184 | verticlaLayout->addWidget(this->Ok1Btn); 185 | this->BorrowedWidget->setLayout(verticlaLayout); 186 | } 187 | void StudentWidget::initSearchWidget() 188 | { 189 | this->SearchWidget = new QWidget(); 190 | this->SearchWidget->setStyleSheet("background: white;color: #2E2E2E; font-size: 15px; font-weight: 400;"); 191 | this->SearchLayout = new QVBoxLayout(); 192 | this->SearchBook = new QLineEdit(); 193 | this->SearchBook->setStyleSheet("background: white;"); 194 | QLabel *lbl = new QLabel("You want to search by :"); lbl->setStyleSheet("color:#00BFFF"); 195 | 196 | this->NameBtn = new QPushButton("Name"); 197 | this->NameBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 198 | this->NameBtn->setCursor(Qt::PointingHandCursor); 199 | 200 | this->TypeBtn = new QPushButton("Type"); 201 | this->TypeBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 202 | this->TypeBtn->setCursor(Qt::PointingHandCursor); 203 | 204 | this->PriceBtn = new QPushButton("Price"); 205 | this->PriceBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 206 | this->PriceBtn->setCursor(Qt::PointingHandCursor); 207 | 208 | this->PubBtn = new QPushButton("Publisher"); 209 | this->PubBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 210 | this->PubBtn->setCursor(Qt::PointingHandCursor); 211 | 212 | this->DoneBtn = new QPushButton("Done"); 213 | this->DoneBtn->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 214 | this->DoneBtn->setCursor(Qt::PointingHandCursor); 215 | 216 | this->SearchLayout->addWidget(lbl); 217 | this->SearchLayout->addWidget(NameBtn); 218 | this->SearchLayout->addWidget(TypeBtn); 219 | this->SearchLayout->addWidget(PriceBtn); 220 | this->SearchLayout->addWidget(PubBtn); 221 | this->SearchLayout->addWidget(SearchBook); 222 | this->SearchLayout->addWidget(DoneBtn); 223 | this->SearchWidget->setLayout(this->SearchLayout); 224 | this->SearchWidget->setMinimumWidth(500); 225 | } 226 | void StudentWidget::initHistoryWidget() 227 | { 228 | this->HistoryWidget = new QWidget(); 229 | this->HistoryWidget->setStyleSheet("background: white;color: #2E2E2E; font-size: 15px; font-weight: 400;"); 230 | this->HistoryList = new QTreeWidget(); 231 | this->HistoryList->setStyleSheet("background: white"); 232 | this->OkBtnh = new QPushButton("Ok"); 233 | this->OkBtnh->setStyleSheet("background: #00BFFF; border-radius: 10px; padding: 10px 0px; color: white; "); 234 | this->OkBtnh->setCursor(Qt::PointingHandCursor); 235 | this->HistoryWidget->setMinimumSize(600,150); 236 | 237 | QStringList headerLabels; 238 | headerLabels.push_back(tr("Searched Book")); 239 | this->HistoryList->setColumnCount(headerLabels.count()); 240 | this->HistoryList->setHeaderLabels(headerLabels); 241 | 242 | QVBoxLayout* verticlaLayout = new QVBoxLayout; 243 | verticlaLayout->addWidget(this->HistoryList); 244 | verticlaLayout->addWidget(this->OkBtnh); 245 | this->HistoryWidget->setLayout(verticlaLayout); 246 | } 247 | void StudentWidget::initLibrarianWidget() 248 | { 249 | this->librarianWidget = new QWidget(); 250 | this->librarianWidget->setStyleSheet("background: #F6F5E4;color: #2E2E2E; font-size: 15px; font-weight: 400;"); 251 | this->librarianWidget->setWindowTitle("Librarian"); 252 | this->librarianWidget->move(600,0); 253 | this->librarianLayout = new QVBoxLayout(); 254 | this->libLabel = new QLabel("Enter Book State :"); 255 | this->bookState = new QLineEdit(); 256 | this->bookState->setStyleSheet("background: white;"); 257 | 258 | this->Ok2Btn = new QPushButton("Ok"); 259 | this->Ok2Btn->setStyleSheet("background: #2e2e2e; border-radius: 10px; padding: 10px 0px; color: white; "); 260 | this->Ok2Btn->setCursor(Qt::PointingHandCursor); 261 | 262 | this->librarianLayout->addWidget(libLabel); 263 | this->librarianLayout->addWidget(bookState); 264 | this->librarianLayout->addWidget(Ok2Btn); 265 | 266 | this->librarianWidget->setLayout(librarianLayout); 267 | } 268 | 269 | void StudentWidget::Design() 270 | { 271 | this->viewBooksScroll->setWidget(this->viewBooksWidget); 272 | this->viewBooksScroll->setWidgetResizable(true); 273 | this->viewBooksScroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); 274 | 275 | this->viewBooksWidget->setStyleSheet("background-color:white"); 276 | this->viewBooksWidget->setLayout(this->viewBooksLayout); 277 | 278 | this->grid->addWidget(this->toolBar,0,1,-1,1); 279 | this->grid->addWidget(this->viewBooksScroll,0,0); 280 | this->grid->addWidget(this->increaseTime,1,0); 281 | this->grid->addWidget(this->today,1,1,Qt::AlignLeft); 282 | 283 | this->setMinimumSize(MIN_SIZE); 284 | this->setLayout(this->grid); 285 | this->setStyleSheet("background-color:white;"); 286 | } 287 | 288 | void StudentWidget::Signals_Slots() 289 | { 290 | connect(this->toolBar,SIGNAL(actionTriggered(QAction*)),this,SLOT(ButtonClicked(QAction*))); 291 | connect(this->increaseTime,SIGNAL(clicked()),this,SLOT(increaseIsClicked())); 292 | connect(this->EditBtn,SIGNAL(clicked()),this,SLOT(editButtonClicked())); 293 | connect(this->OkBtn,SIGNAL(clicked()),this,SLOT(okButtonClicked())); 294 | connect(this->BackBtn,SIGNAL(clicked()),this,SLOT(backButtonClicked())); 295 | connect(this->OkkBtn,SIGNAL(clicked()),this,SLOT(okkButtonClicked())); 296 | connect(this->Ok1Btn,SIGNAL(clicked()),this,SLOT(ok1ButtonClicked())); 297 | connect(this->OkBtnh,SIGNAL(clicked()),this,SLOT(okButtonhClicked())); 298 | connect(this->NameBtn,SIGNAL(clicked()),this,SLOT(nameButtonClicked())); 299 | connect(this->TypeBtn,SIGNAL(clicked()),this,SLOT(typeButtonClicked())); 300 | connect(this->PriceBtn,SIGNAL(clicked()),this,SLOT(priceButtonClicked())); 301 | connect(this->PubBtn,SIGNAL(clicked()),this,SLOT(pubButtonClicked())); 302 | connect(this->DoneBtn,SIGNAL(clicked()),this,SLOT(doneButtonClicked())); 303 | } 304 | 305 | void StudentWidget::UpdateBooks() 306 | { 307 | // get allBooks from dataBase -> no duplicates 308 | map name_imagePath = emit getAllBooks(); 309 | // convert them into imageWidget (book interface) 310 | for (auto i = name_imagePath.begin(); i != name_imagePath.end() ;i++) 311 | { 312 | imageWidget* book_interface = new imageWidget(i->first,i->second); 313 | connect(book_interface,SIGNAL(bookClicked(string)),this,SLOT(bookClicked(string))); 314 | books.push_back(book_interface); 315 | cout << i->first << ","; 316 | } 317 | cout << " =========== books" << endl; 318 | // display it in the gridlayout 319 | uint COLOMN_SIZE = 3; 320 | uint ROW_SIZE = books.size()/COLOMN_SIZE +1; 321 | 322 | cout << ROW_SIZE << "," << COLOMN_SIZE << endl; 323 | for (uint i =0 ; i< ROW_SIZE ; i++) 324 | { 325 | for(uint j =0 ; j< COLOMN_SIZE; j++) 326 | { 327 | uint index = i * COLOMN_SIZE + j ; 328 | if(index >= books.size()) 329 | break; 330 | cout << "i=" << i << ",j=" << j << ",index=" << index << endl; 331 | // for sizing apperance 332 | books[index]->setMaximumWidth(this->viewBooksWidget->width()/3); 333 | books[index]->setMaximumHeight(this->viewBooksWidget->height()/3); 334 | 335 | this->viewBooksLayout->addWidget(books[index],i,j); 336 | } 337 | } 338 | 339 | } 340 | 341 | void StudentWidget::studentLoggedIn(Student student) 342 | { 343 | this->currentStudent = student; 344 | emit setLoggedInUserName(this->currentStudent.getName()); 345 | this->nameEdit->setText(QString::fromStdString(this->currentStudent.getName())); 346 | this->passEdit->setText(QString::fromStdString(this->currentStudent.getPassword())); 347 | this->emailEdit->setText(QString::fromStdString(this->currentStudent.getEmail())); 348 | this->cashEdit->setText(QString::fromStdString(to_string(this->currentStudent.getCash()))); 349 | this->UpdateBooks(); 350 | } 351 | void StudentWidget::ButtonClicked(QAction *action) 352 | { 353 | if (action->text() == "Profile") 354 | this->ProfileWidget->show(); 355 | else if (action->text() == "Return") 356 | this->ReturnWidget->show(); 357 | else if (action->text() == "My Books") 358 | emit aa(currentStudent.getName()); 359 | else if (action->text() == "Search") 360 | this->SearchWidget->show(); 361 | else if (action->text() == "History") 362 | emit getSearchHistory(currentStudent.getName()); 363 | else if (action->text() == "Log Out") 364 | { 365 | emit setCurrentWidget(LOGIN_WIDGET); 366 | for (int i =0 ; i< this->books.size();i++) 367 | delete this->books[i]; 368 | this->books.clear(); 369 | } 370 | } 371 | 372 | void StudentWidget::editButtonClicked() 373 | { 374 | this->nameEdit->setReadOnly(false); 375 | this->passEdit->setReadOnly(false); 376 | this->emailEdit->setReadOnly(false); 377 | this->cashEdit->setReadOnly(false); 378 | } 379 | 380 | void StudentWidget::okButtonClicked() 381 | { 382 | // update Student DataBase 383 | string name = this->nameEdit->text().toStdString(); 384 | string pass = this->passEdit->text().toStdString(); 385 | string email = this->emailEdit->text().toStdString(); 386 | int cash = this->cashEdit->text().toInt(); 387 | 388 | emit updateStudent(this->currentStudent.getName(),name,pass,email,cash); 389 | 390 | this->currentStudent.setName(name); 391 | this->currentStudent.setPassword(pass); 392 | this->currentStudent.setEmail(email); 393 | this->currentStudent.setCash(cash); 394 | 395 | this->nameEdit->setReadOnly(true); 396 | this->passEdit->setReadOnly(true); 397 | this->emailEdit->setReadOnly(true); 398 | this->cashEdit->setReadOnly(true); 399 | this->ProfileWidget->hide(); 400 | emit setLoggedInUserName(this->currentStudent.getName()); 401 | 402 | this->successBox->setText("Edit Successfully !"); 403 | this->successBox->show(); 404 | } 405 | 406 | void StudentWidget::backButtonClicked() 407 | { 408 | this->ReturnWidget->hide(); 409 | } 410 | 411 | void StudentWidget::okkButtonClicked() 412 | { 413 | if(this->ReturnBook->text().isEmpty() ) 414 | { 415 | this->errorBox->setText("Please Enter a Valid Date"); 416 | this->errorBox->show(); 417 | return; 418 | } 419 | string returnBookName = this->ReturnBook->text().toStdString(); 420 | emit returnBook(returnBookName,currentStudent.getName()); 421 | } 422 | 423 | void StudentWidget::increaseIsClicked() 424 | { 425 | todayDate++; 426 | this->today->setText(" Today: "+QString::fromStdString(to_string(todayDate))); 427 | } 428 | 429 | void StudentWidget::error_return(string text) 430 | { 431 | this->errorBox->setText(QString::fromStdString(text));//setIcon if you want 432 | this->errorBox->show(); 433 | } 434 | 435 | void StudentWidget::bookReturned(int bill , int mode) 436 | {//set icons if you want 437 | if(mode==0){ 438 | this->errorBox->setText("Thanks for returning the book sound and in time\n Here's your bill: "+QString::fromStdString(to_string(bill))); 439 | this->errorBox->show(); 440 | } 441 | else if(mode==1){ 442 | this->errorBox->setText("You've damaged the book, you will pay half of its price\n Here's your bill: "+QString::fromStdString(to_string(bill))); 443 | this->errorBox->show(); 444 | } 445 | else if(mode==2){ 446 | this->errorBox->setText("You're late, a fee will be added to the bill\n Here's your bill: "+QString::fromStdString(to_string(bill))); 447 | this->errorBox->show(); 448 | } 449 | else if(mode==3){ 450 | this->errorBox->setText("You're late and you've damaged the book!! \n Here's your bill: "+QString::fromStdString(to_string(bill))); 451 | this->errorBox->show(); 452 | } 453 | this->ReturnWidget->hide(); 454 | } 455 | 456 | void StudentWidget::borrowedBooks(vector v) 457 | { 458 | for(int i=0;iaddRoot(a,to_string(b),to_string(c),to_string(d)); 465 | } 466 | this->BorrowedWidget->show(); 467 | } 468 | 469 | void StudentWidget::searchedBooks(vector v) 470 | { 471 | 472 | for(int i=0;iaddRoot(v[i]); 474 | 475 | this->HistoryWidget->show(); 476 | } 477 | 478 | void StudentWidget::bookClicked(string name) 479 | { 480 | emit getBookInfo(name); 481 | } 482 | 483 | void StudentWidget::ok1ButtonClicked() 484 | { 485 | this->BorrowedWidget->hide(); 486 | this->borrowedList->clear(); 487 | } 488 | 489 | void StudentWidget::okButtonhClicked() 490 | { 491 | this->HistoryWidget->hide(); 492 | this->HistoryList->clear(); 493 | } 494 | 495 | void StudentWidget::nameButtonClicked() 496 | { 497 | if(SearchBook->text().isEmpty()) 498 | { 499 | this->errorBox->setText("Empty Search"); 500 | this->errorBox->show(); 501 | return; 502 | } 503 | this->tabWidget->clear(); 504 | emit searchBookByName(this->SearchBook->text().toStdString(),currentStudent.getName()); 505 | } 506 | 507 | void StudentWidget::typeButtonClicked() 508 | { 509 | if(SearchBook->text().isEmpty()) 510 | { 511 | this->errorBox->setText("Empty Search"); 512 | this->errorBox->show(); 513 | return; 514 | } 515 | 516 | this->tabWidget->clear(); 517 | emit searchBookByType(this->SearchBook->text().toStdString(),currentStudent.getName()); 518 | } 519 | 520 | void StudentWidget::priceButtonClicked() 521 | { 522 | if(SearchBook->text().isEmpty()) 523 | { 524 | this->errorBox->setText("Empty Search"); 525 | this->errorBox->show(); 526 | return; 527 | } 528 | 529 | this->tabWidget->clear(); 530 | emit searchBookByPrice(this->SearchBook->text().toInt(),currentStudent.getName()); 531 | } 532 | 533 | void StudentWidget::pubButtonClicked() 534 | { 535 | if(SearchBook->text().isEmpty()) 536 | { 537 | this->errorBox->setText("Empty Search"); 538 | this->errorBox->show(); 539 | return; 540 | } 541 | 542 | this->tabWidget->clear(); 543 | emit searchBookByPub(this->SearchBook->text().toStdString(),currentStudent.getName()); 544 | } 545 | 546 | void StudentWidget::doneButtonClicked() 547 | { 548 | this->SearchWidget->hide(); 549 | } 550 | 551 | void StudentWidget::booksFound(vector v) 552 | { 553 | if(v.size()==0) 554 | { 555 | this->errorBox->setText("Not Found"); 556 | this->errorBox->show(); 557 | return; 558 | } 559 | 560 | for(uint i=0;isetCurrentBook(v[i]); 564 | this->tabWidget->addTab(foundBookWidget,QString::fromStdString(v[i].getName())); 565 | } 566 | this->tabWidget->show(); 567 | } 568 | 569 | 570 | void StudentWidget::addRoot(string s0, string s1,string s2, string s3) 571 | { 572 | QTreeWidgetItem *i1 = new QTreeWidgetItem(this->borrowedList); 573 | i1->setText(0,QString::fromStdString(s0)); 574 | i1->setText(1,QString::fromStdString(s1)); 575 | i1->setText(2,QString::fromStdString(s2)); 576 | i1->setText(3,QString::fromStdString(s3)); 577 | borrowedList->addTopLevelItem(i1); 578 | 579 | } 580 | 581 | void StudentWidget::addRoot(string s) 582 | { 583 | QTreeWidgetItem *i1 = new QTreeWidgetItem(this->HistoryList); 584 | i1->setText(0,QString::fromStdString(s)); 585 | HistoryList->addTopLevelItem(i1); 586 | } 587 | 588 | //void StudentWidget::librarianWidgetOpen() 589 | //{ 590 | // this->librarianWidget->show(); 591 | //} 592 | 593 | //void StudentWidget::Ok2ButtonClicked() 594 | //{ 595 | // emit libBookState(stoi(this->bookState->text().toStdString())); 596 | // this->librarianWidget->hide(); 597 | //} 598 | -------------------------------------------------------------------------------- /GUI/studentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENTWIDGET_H 2 | #define STUDENTWIDGET_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "indexs.h" 19 | #include 20 | #include "student.h" 21 | #include 22 | #include 23 | #include "book.h" 24 | #include "bookwidget.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "GUI/imagewidget.h" 31 | #include 32 | #include 33 | using namespace std; 34 | 35 | class StudentWidget : public QWidget 36 | { 37 | Q_OBJECT 38 | private: 39 | QGridLayout* grid; 40 | QLineEdit* searchLineEdit; 41 | QToolBar* toolBar; 42 | QWidget* viewBooksWidget; 43 | QScrollArea* viewBooksScroll; 44 | QGridLayout* viewBooksLayout; 45 | std::vector books; 46 | uint row ; 47 | uint colomn; 48 | 49 | 50 | 51 | QWidget* ProfileWidget; 52 | QGridLayout* ProfileLayout; 53 | QLineEdit* nameEdit ,*passEdit , * emailEdit ,* cashEdit ; 54 | QPushButton *EditBtn , *OkBtn; 55 | 56 | QWidget* ReturnWidget; 57 | QGridLayout* ReturnLayout; 58 | QLineEdit* ReturnBook; 59 | QPushButton *BackBtn , *OkkBtn; 60 | 61 | QWidget* BorrowedWidget; 62 | QTreeWidget *borrowedList; 63 | QPushButton *Ok1Btn; 64 | void addRoot(string,string,string,string); 65 | 66 | QWidget* SearchWidget; 67 | QVBoxLayout* SearchLayout; 68 | QLineEdit* SearchBook; 69 | QPushButton *NameBtn,*TypeBtn,*PriceBtn,*PubBtn,*DoneBtn; 70 | 71 | QWidget* HistoryWidget; 72 | QTreeWidget *HistoryList; 73 | QPushButton *OkBtnh; 74 | void addRoot(string); 75 | 76 | Student currentStudent; 77 | QSize lastSize; 78 | vector BooksWidgets; 79 | QString Path; 80 | 81 | QPushButton* increaseTime; 82 | QLabel* today,*todayIs; 83 | QMessageBox* errorBox; 84 | QMessageBox* successBox; 85 | 86 | QTabWidget *tabWidget; 87 | 88 | QWidget* librarianWidget; 89 | QVBoxLayout* librarianLayout; 90 | QLabel* libLabel; 91 | QLineEdit* bookState; 92 | QPushButton *Ok2Btn; 93 | 94 | public: 95 | StudentWidget(QWidget* parent = nullptr); 96 | void initToolBar(); 97 | void initProfileWidget(); 98 | void initReturnWidget(); 99 | void initBorrowedWidget(); 100 | void initSearchWidget(); 101 | void initHistoryWidget(); 102 | void initLibrarianWidget(); 103 | void Design(); 104 | void Signals_Slots(); 105 | void UpdateBooks(); 106 | 107 | signals: 108 | void updateStudent(string,string,string,string,int); 109 | void getBookInfo(string); 110 | void getBookInfo(Book); 111 | void returnBook(string,string); 112 | void aa(string); 113 | void searchBookByName(string,string); 114 | void searchBookByType(string,string); 115 | void searchBookByPrice(int,string); 116 | void searchBookByPub(string,string); 117 | void getSearchHistory(string); 118 | void setCurrentWidget(int); 119 | void setLoggedInUserName(string); 120 | map getAllBooks(); 121 | // void libBookState(int); 122 | 123 | public slots: 124 | void studentLoggedIn(Student); 125 | void ButtonClicked(QAction *action); 126 | void editButtonClicked(); 127 | void okButtonClicked(); 128 | void backButtonClicked(); 129 | void okkButtonClicked(); 130 | void increaseIsClicked(); 131 | void error_return(string); 132 | void bookReturned(int,int); 133 | void borrowedBooks(vector); 134 | void ok1ButtonClicked(); 135 | void okButtonhClicked(); 136 | void nameButtonClicked(); 137 | void typeButtonClicked(); 138 | void priceButtonClicked(); 139 | void pubButtonClicked(); 140 | void doneButtonClicked(); 141 | void booksFound(vector); 142 | void searchedBooks(vector); 143 | void bookClicked(string name); 144 | // void librarianWidgetOpen(); 145 | // void Ok2ButtonClicked(); 146 | 147 | }; 148 | 149 | #endif // STUDENTWIDGET_H 150 | -------------------------------------------------------------------------------- /Library.pro: -------------------------------------------------------------------------------- 1 | QT += core gui sql 2 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 3 | 4 | CONFIG += c++11 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | GUI/bookwidget.cpp \ 19 | GUI/imagewidget.cpp \ 20 | GUI/loginwidget.cpp \ 21 | GUI/mainwindow.cpp \ 22 | GUI/publisherwidget.cpp \ 23 | GUI/signupwidget.cpp \ 24 | GUI/startwidget.cpp \ 25 | GUI/studentwidget.cpp \ 26 | book.cpp \ 27 | controller.cpp \ 28 | database.cpp \ 29 | librarian.cpp \ 30 | main.cpp \ 31 | publisher.cpp \ 32 | student.cpp \ 33 | user.cpp 34 | 35 | HEADERS += \ 36 | GUI/bookwidget.h \ 37 | GUI/header.h \ 38 | GUI/imagewidget.h \ 39 | GUI/indexs.h \ 40 | GUI/loginwidget.h \ 41 | GUI/mainwindow.h \ 42 | GUI/publisherwidget.h \ 43 | GUI/signupwidget.h \ 44 | GUI/startwidget.h \ 45 | GUI/studentwidget.h \ 46 | book.h \ 47 | controller.h \ 48 | database.h \ 49 | indexs.h \ 50 | librarian.h \ 51 | publisher.h \ 52 | student.h \ 53 | user.h 54 | 55 | FORMS += \ 56 | GUI/mainwindow.ui \ 57 | 58 | # Default rules for deployment. 59 | qnx: target.path = /tmp/$${TARGET}/bin 60 | else: unix:!android: target.path = /opt/$${TARGET}/bin 61 | !isEmpty(target.path): INSTALLS += target 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Table of contents 2 | * [Introduction](#general-info) 3 | * [Technologies](#technologies) 4 | * [Prerequisites](#Prerequisites) 5 | * [Setup](#setup) 6 | * [Deployment](#Deployment) 7 | 8 | ## Introduction 9 | The Library-Management-System is a software system with a Graphical User Interface to provide the libraries with a helpfull software system that has features like: registration system, publishing books system, borrowing system and searching and payment methods. 10 | 11 | ## Technologies 12 | Project is created with: 13 | * C++ 14 | * QT Framework 15 | * CSS3 16 | * SQLite 17 | 18 | ## User Guide 19 | Check the User Guide located in "Doucmentation/user_guide.pdf" 20 | 21 | -------------------------------------------------------------------------------- /background/blur2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/background/blur2.jpg -------------------------------------------------------------------------------- /background/blur5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/background/blur5.jpg -------------------------------------------------------------------------------- /book.cpp: -------------------------------------------------------------------------------- 1 | #include "book.h" 2 | #include "publisher.h" 3 | 4 | Book::Book(string name, string Type, Publisher* author, string Rowid, int price, bool State , bool Availability) 5 | { 6 | Name = name; 7 | type = Type; 8 | publisher = author ; 9 | Price = price ; 10 | state = State; 11 | availability = 1; 12 | rowid=Rowid; 13 | } 14 | 15 | Book::Book() 16 | { 17 | 18 | } 19 | 20 | void Book::setName(string name) 21 | { 22 | this->Name = name; 23 | } 24 | 25 | void Book::setPrice(int price) 26 | { 27 | this->Price = price; 28 | } 29 | 30 | void Book::setType(string Type) 31 | { 32 | this->type = Type; 33 | } 34 | 35 | void Book::setPublisher(Publisher* myPublisher) 36 | { 37 | this->publisher = myPublisher; 38 | } 39 | 40 | void Book::setPublisherName(string name) 41 | { 42 | this->publisher_name = name; 43 | } 44 | 45 | void Book::setImagePath(string path) 46 | { 47 | this->imagePath = path; 48 | } 49 | 50 | void Book::setState(bool State) 51 | { 52 | this->state = State; 53 | } 54 | 55 | void Book::setAvailability(bool Availability) 56 | { 57 | this->availability = Availability; 58 | } 59 | 60 | void Book::setBorrowedDate(int date) 61 | { 62 | this->borrowedDate = date; 63 | } 64 | 65 | void Book::setExpectedReturnDate(int date) 66 | { 67 | this->expectedReturnDate = date; 68 | } 69 | 70 | void Book::setActualReturnDate(int date) 71 | { 72 | this->actualReturnDate = date ; 73 | } 74 | 75 | void Book::setRowId(string Rowid) 76 | { 77 | this->rowid = Rowid; 78 | } 79 | 80 | string Book::getRowId() 81 | { 82 | return this->rowid; 83 | } 84 | 85 | string Book::getName() 86 | { 87 | return this->Name; 88 | } 89 | 90 | int Book::getPrice() 91 | { 92 | return this->Price; 93 | } 94 | 95 | string Book::getType() 96 | { 97 | return this->type; 98 | } 99 | 100 | Publisher* Book::getPublisher() 101 | { 102 | return publisher; 103 | } 104 | 105 | string Book::getPublisherName() 106 | { 107 | return this->publisher_name; 108 | } 109 | 110 | string Book::getImagePath() 111 | { 112 | return this->imagePath; 113 | } 114 | 115 | bool Book::getState() 116 | { 117 | return this->state; 118 | } 119 | 120 | bool Book::getAvailability() 121 | { 122 | return this->availability; 123 | } 124 | 125 | int Book::getBorrowedDate() 126 | { 127 | return this->borrowedDate; 128 | } 129 | 130 | int Book::getExpectedReturnDate() 131 | { 132 | return this->expectedReturnDate; 133 | } 134 | 135 | int Book::getActualReturnDate() 136 | { 137 | return this->actualReturnDate; 138 | } 139 | 140 | void Book::showInfo() 141 | { 142 | cout << "Name:" << this->Name ; 143 | cout << endl; 144 | cout << "Price:" << this->Price; 145 | cout << endl; 146 | cout << "State:" << this->state; 147 | cout << endl; 148 | cout << "Type:" << this->type ; 149 | cout << endl; 150 | cout << "Publisher_name: " << this->publisher_name << endl; 151 | } 152 | 153 | bool Book::operator ==(Book &) 154 | { 155 | 156 | } 157 | -------------------------------------------------------------------------------- /book.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOK_H 2 | #define BOOK_H 3 | 4 | #include 5 | #include 6 | class Publisher; 7 | 8 | using namespace std; 9 | 10 | class Book 11 | { 12 | private: 13 | string rowid; 14 | string Name; 15 | int Price; 16 | bool state; 17 | string type; 18 | string imagePath; 19 | Publisher* publisher; 20 | bool availability; 21 | string publisher_name; 22 | 23 | int borrowedDate=0, expectedReturnDate=0, actualReturnDate=0 ; 24 | 25 | public: 26 | Book(); 27 | Book(string name , string type , Publisher* author , string Rowid ,int price = 0 , bool State = true, bool Availability = true); 28 | // ========= Setters =========== 29 | void setName(string); 30 | void setPrice(int); 31 | void setType(string); 32 | void setPublisher(Publisher*); 33 | void setPublisherName(string); 34 | void setImagePath(string); 35 | void setState(bool); 36 | void setAvailability(bool); 37 | void setBorrowedDate(int); 38 | void setExpectedReturnDate(int); 39 | void setActualReturnDate(int); 40 | void setRowId(string); 41 | // ========== Getters =========== 42 | string getRowId(); 43 | string getName(); 44 | int getPrice(); 45 | string getType(); 46 | Publisher* getPublisher(); 47 | string getPublisherName(); 48 | string getImagePath(); 49 | bool getState(); 50 | bool getAvailability(); 51 | int getBorrowedDate(); 52 | int getExpectedReturnDate(); 53 | int getActualReturnDate(); 54 | 55 | void showInfo(); 56 | bool operator == (Book&); 57 | }; 58 | 59 | #endif // BOOK_H 60 | -------------------------------------------------------------------------------- /controller.cpp: -------------------------------------------------------------------------------- 1 | #include "controller.h" 2 | extern int todayDate; 3 | Controller::Controller() : QObject() 4 | { 5 | QString path = QCoreApplication::applicationDirPath(); 6 | this->db.init(path); 7 | } 8 | void Controller::start() 9 | { 10 | } 11 | 12 | void Controller::sign_up(string name ,string email , string password , int choice) 13 | { 14 | Student student1; 15 | Publisher publisher1; 16 | if (choice == 1) // user is student 17 | { 18 | student1.setName(name); 19 | student1.setPassword(password); 20 | student1.setEmail(email); 21 | if(!db.saveStudent(student1)) 22 | { 23 | emit error("Student Name already Exist ! Enter another name"); 24 | cout << "Student Name already Exist ! Enter another name" << endl; 25 | return; 26 | } 27 | cout<<"You signed up successfully"<log_in(name,password,choice); 44 | } 45 | void Controller::log_in(string name , string password , int choice) 46 | { 47 | if(choice==1) 48 | { 49 | Student s; 50 | int mode = db.checkStudent(name,password); 51 | if (mode==1) 52 | { 53 | emit error_login("No name matches the name you entered"); 54 | } 55 | else if(mode==2) 56 | { 57 | emit error_login("Wrong Password"); 58 | } 59 | else if(mode==0) 60 | { 61 | s = db.loadStudent(name); 62 | cout<<"You've logged in successfully"<>choice; 103 | if(choice==1) 104 | { 105 | string name,type; 106 | int price; 107 | cout<<"Enter Book Name : "; 108 | cin>>name; 109 | cout<<"Enter Book Type : "; 110 | cin>>type; 111 | cout<<"Enter Book Price : "; 112 | cin>>price; 113 | this->Upload_book(pubName,name,type,price); 114 | } 115 | else if(choice==2) 116 | { 117 | Book book1; 118 | string nameInitial,type,name; 119 | int price,x; 120 | cout<<"Which book you want to update? :"; 121 | cin>>nameInitial; 122 | book1=db.loadBook(nameInitial); 123 | cout<<"What do you want to edit in this book ?"<>x; 128 | if(x==1){cout<<"Enter Book Name : ";cin>>name;book1.setName(name);} 129 | if(x==2){cout<<"Enter Book Type : ";cin>>type;book1.setType(type);} 130 | if(x==3){cout<<"Enter Book Price : ";cin>>price;book1.setPrice(price);} 131 | db.updateBook(book1,nameInitial); 132 | } 133 | else if(choice==3) 134 | { 135 | vector s = db.loadPublisher(pubName).viewMyBooks(); 136 | cout<<"Your books are : "; 137 | for (int i =0 ; i < s.size() ; i++) 138 | cout << s[i] << " "; 139 | cout << endl; 140 | } 141 | else if(choice==4) cout<<"You Have : "<< db.loadPublisher(pubName).getCash() << " L.E.\n" ; 142 | else if(choice==5) db.loadPublisher(pubName).showInfo(); 143 | else if(choice==6) 144 | { 145 | Publisher pub; 146 | string email,name,pass; 147 | int cashAmount,x; 148 | pub=db.loadPublisher(pubName); 149 | cout<<"What do you want to edit in the profile ?"<>x; 155 | if(x==1){cout<<"Enter new Name : ";cin>>name;pub.setName(name);} 156 | if(x==2){cout<<"Enter new Password : ";cin>>pass;pub.setPassword(pass);} 157 | if(x==3){cout<<"Enter new Email : ";cin>>pass;pub.setPassword(pass);} 158 | if(x==4){cout<<"Enter new Cash amount : ";cin>>cashAmount;pub.setCash(cashAmount);} 159 | db.updatePublisher(pub,pubName); 160 | break; 161 | } 162 | else if(choice==7) return; 163 | else cout<<"Wrong Choice. "< get any un available book to just show it to user and know that there is no available books 194 | if(b.getName().empty()) 195 | b= db.loadBookForce(BookNameOrID); 196 | if(b.getName().empty()) 197 | { 198 | emit error_noBook("Not Found Book"); 199 | return; 200 | } 201 | emit bookInfo(b); 202 | Student s =db.loadStudent(stuName); 203 | db.addSearchHistory(b,stuName); 204 | db.updateStudent(s,stuName); 205 | } 206 | 207 | void Controller::searchBookByType(string type , string stuName) 208 | { 209 | vector v = db.searchBookByType(type); 210 | Student s =db.loadStudent(stuName); 211 | for(int i=0;i v = db.searchBookByPrice(price); 223 | emit booksFound(v); 224 | Student s =db.loadStudent(stuName); 225 | for(int i=0;i v = db.searchBookByPubName(pub); 235 | emit booksFound(v); 236 | Student s =db.loadStudent(stuName); 237 | for(int i=0;i v;Book b; 276 | Student s=db.loadStudent(stuName); 277 | v= split_string(s.getCurrentBookName(),","); 278 | for(int i=0;iexpectedBorrowedPeriod) 297 | { 298 | int fee; 299 | fee=5*ceil((actualBorrowedPeriod-expectedBorrowedPeriod)/7.0); 300 | bill+=fee; 301 | flag=1;flag3=1; 302 | } 303 | //int state = l.checkState(&b); 304 | if(1) 305 | { 306 | int fee; 307 | fee=b.getPrice()/2; 308 | bill+=fee; 309 | flag=1;flag4=1; 310 | } 311 | if(!flag3&&flag4)mode=1; //late 312 | else if(flag3&&!flag4)mode=2; //damaged 313 | else if(flag3&&flag4)mode=3; //late and damaged (7ayawan ya3ni) 314 | else mode=0; //wa7ed mo7taram <3 315 | emit bookReturned(bill,mode); 316 | s.addCash(-1*bill); 317 | string str=s.getCurrentBookName(); 318 | int x; 319 | for(int i=0;i v = db.loadStudent(stuName).getCurrentBookVector(&db); 335 | emit borrowedBooks(v); 336 | } 337 | 338 | void Controller::getBookInfo(string BookNameOrID) 339 | { 340 | //Book b = db.loadBookByRowId(BookNameOrID); 341 | Book b; 342 | b= db.loadBook(BookNameOrID); 343 | if(b.getName().empty()) 344 | b= db.loadBookForce(BookNameOrID); 345 | if(b.getName().empty()) 346 | { 347 | emit error_noBook("Not Found Book"); 348 | return; 349 | } 350 | emit bookInfo(b); 351 | } 352 | 353 | void Controller::getSearchHistory(string stuName) 354 | { 355 | Student s = db.loadStudent(stuName); 356 | vector v = s.getSearchHistory(); 357 | //could load books instead of bookNames 358 | emit searchedBooks(v); 359 | } 360 | 361 | map Controller::getAllBooks() 362 | { 363 | return this->db.getAllBooks(); 364 | } 365 | 366 | void Controller::updatePublisher(string pubName, string name, string pass, string email, int cashAmount) 367 | { 368 | Publisher p; 369 | p=db.loadPublisher(pubName); 370 | p.setName(name); 371 | p.setPassword(pass); 372 | p.setEmail(email); 373 | p.setCash(cashAmount); 374 | db.updatePublisher(p,pubName); 375 | } 376 | 377 | void Controller::updateStudent(string stuName, string name, string pass, string email, int cashAmount) 378 | { 379 | Student s; 380 | s=db.loadStudent(stuName); 381 | s.setName(name); 382 | s.setPassword(pass); 383 | s.setEmail(email); 384 | s.setCash(cashAmount); 385 | db.updateStudent(s,stuName); 386 | } 387 | void Controller::studentLoggedIn(string stuName) 388 | { 389 | int choice; 390 | while(1) 391 | { 392 | cout<<"what do yo want to do ? "<>choice; 404 | if(choice==1) 405 | { 406 | int choice1; 407 | while(1){ 408 | cout<<"Do you wanna search books by :"<>choice1; 415 | if(choice1==1) 416 | { 417 | string name; 418 | cout<<"Enter book's name : "; 419 | cin>>name; 420 | if(db.loadBook(name).getName().empty()) cout<<"Your book is not available :( "<>type; 433 | vector v = db.searchBookByType(type); 434 | cout<<"We've found "<>publisherName; 445 | vector v = db.searchBookByPubName(publisherName); 446 | cout<<"We've found "<>price; 458 | vector v = db.searchBookByPrice(price); 459 | cout<<"We've found "<>name; 476 | if(db.loadBook(name).getName().empty()) 477 | { 478 | Book b;int x; 479 | cout<<"This book is not available 😞 "<>x; 482 | if(x) b=l.supplyRequestedBook(stuName,&db); 483 | } 484 | else 485 | { 486 | cout<<"Enter today's date : ";//el 7etta dih el mafrod ne3melha men barra bas for now 5aliha keda 487 | cin>>borrowDate; 488 | cout<<"Enter return date : "; 489 | cin>>expectedReturnDate; 490 | Student s = db.loadStudent(stuName); 491 | Book b = db.loadBook(name); 492 | s.setCurrentBook(db.loadBook(name).getRowId()); 493 | b.setBorrowedDate(borrowDate); 494 | b.setExpectedReturnDate(expectedReturnDate); 495 | db.addBorrowedBooks(b,stuName); 496 | b.setAvailability(0); 497 | db.updateStudent(s,stuName); 498 | db.updateBookByRowId(b,db.loadBook(name).getRowId()); 499 | Publisher pub = db.loadPublisher(db.loadBook(b.getName()).getPublisherName()); 500 | pub.addCash(db.loadBook(b.getName()).getPrice()/2); 501 | db.updatePublisher(pub,pub.getName()); 502 | cout<<"You borrowed the book successfully, your book's ID is : "<>rowid; 514 | Book b=db.loadBookByRowId(rowid); 515 | Student s=db.loadStudent(stuName); 516 | if(b.getRowId()!=s.getCurrentBookName()) 517 | cout<<"This is not the book you borrowed!"<>actualReturnDate; 522 | b.setActualReturnDate(actualReturnDate); 523 | actualBorrowedPeriod = b.getActualReturnDate() - b.getBorrowedDate(); 524 | expectedBorrowedPeriod=b.getExpectedReturnDate()-b.getBorrowedDate(); 525 | bill=ceil(actualBorrowedPeriod/7.0)*b.getPrice(); 526 | if(actualBorrowedPeriod>expectedBorrowedPeriod) 527 | { 528 | int fee; 529 | fee=5*ceil((actualBorrowedPeriod-expectedBorrowedPeriod)/7.0); 530 | bill+=fee; 531 | flag=1; 532 | } 533 | int state = l.checkState(&b); 534 | if(state) 535 | { 536 | int fee; 537 | fee=b.getPrice()/2; 538 | bill+=fee; 539 | flag=1; 540 | } 541 | if(!flag) 542 | cout<<"You're a good boy, you returned the book sound and in the right time, here's your bill : "<>x; 580 | if(x==1){cout<<"Enter new Name : ";cin>>name;s.setName(name);} 581 | if(x==2){cout<<"Enter new Password : ";cin>>pass;s.setPassword(pass);} 582 | if(x==3){cout<<"Enter new Email : ";cin>>pass;s.setPassword(pass);} 583 | if(x==4){cout<<"Enter new Cash amount : ";cin>>cashAmount;s.setCash(cashAmount);} 584 | db.updateStudent(s,stuName); 585 | break; 586 | } 587 | else if(choice==10) 588 | break; 589 | else 590 | cout<<"Enter correct choice"< Controller :: split_string(string s,string splitter) 595 | { 596 | vector splitted; 597 | uint n = s.length(); 598 | int pos = 0; 599 | int start = pos; 600 | while (pos != string::npos) 601 | { 602 | pos = s.find_first_of(splitter,pos+1); 603 | string splitted_string = s.substr(start,pos-start); 604 | splitted.push_back(splitted_string); 605 | start = pos+1; 606 | } 607 | 608 | return splitted; 609 | } 610 | -------------------------------------------------------------------------------- /controller.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTROLLER_H 2 | #define CONTROLLER_H 3 | 4 | #include 5 | #include "book.h" 6 | #include 7 | #include "publisher.h" 8 | #include "student.h" 9 | #include "user.h" 10 | #include "database.h" 11 | #include "librarian.h" 12 | #include 13 | #include "GUI/indexs.h" 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | class Controller : public QObject 19 | { 20 | Q_OBJECT 21 | private: 22 | DataBase db; 23 | vector split_string(string,string); 24 | 25 | public : 26 | Controller(); 27 | void start(); 28 | 29 | void studentLoggedIn(string); 30 | void publisherLoggedIn(string); 31 | 32 | public slots: 33 | 34 | void log_in(string name , string password , int choice); 35 | void sign_up(string ,string ,string,int); 36 | // publisher 37 | void Upload_book(string ,string,string,int); 38 | void updatePublisher(string ,string,string,string,int); 39 | void updateStudent(string,string,string,string,int); 40 | 41 | // books 42 | void searchBookByName(string,string); 43 | void searchBookByType(string,string); 44 | void searchBookByPrice(int,string); 45 | void searchBookByPub(string,string); 46 | void borrowBook(string,string,int); 47 | void returnBook(string,string); 48 | void aa(string); 49 | void getBookInfo(string); 50 | void getSearchHistory(string); 51 | map getAllBooks(); 52 | 53 | 54 | signals: 55 | void error(string); 56 | void error_login(string); 57 | void studentLoggedin(Student); 58 | void publisherLoggedin(Publisher); 59 | void setCurrentWidget(int index); 60 | 61 | // books 62 | void error_noBook(string); 63 | void bookInfo(Book); 64 | void error_return(string); 65 | void bookReturned(int,int); 66 | void borrowedBooks(vector); 67 | void booksFound(vector); 68 | void searchedBooks(vector); 69 | 70 | }; 71 | 72 | #endif // CONTROLLER_H 73 | -------------------------------------------------------------------------------- /database.cpp: -------------------------------------------------------------------------------- 1 | #include "database.h" 2 | #include "book.h" 3 | #include "publisher.h" 4 | #include "student.h" 5 | 6 | DataBase::DataBase() 7 | { 8 | 9 | } 10 | 11 | void DataBase::init(QString path) 12 | { 13 | this->db = QSqlDatabase ::addDatabase("QSQLITE"); 14 | QString Path = path + "/../../Library-Management-System/ray2.db"; 15 | Path.toStdString(); 16 | 17 | this->db.setDatabaseName(Path); 18 | this->db.open(); 19 | 20 | if (!this->db.isOpen()) 21 | cout << "db doesn't open and you are not ray2" << endl; 22 | } 23 | 24 | bool DataBase::saveBook(Book book) 25 | { 26 | QSqlQuery check(this->db); 27 | check.prepare("SELECT * FROM Books WHERE Name=?;"); 28 | check.bindValue(0,QString::fromStdString(book.getName())); 29 | check.exec(); 30 | // if(check.next()) 31 | // return false; 32 | QSqlQuery query(this->db); 33 | query.prepare("INSERT INTO Books(Name,Type,Price,Publisher,borrowedDate,expectedReturnDate,actualReturnDate,State,Availability,imagePath) VALUES(?,?,?,?,?,?,?,?,?,?);"); 34 | query.bindValue(0,QString::fromStdString(book.getName())); 35 | query.bindValue(1,QString::fromStdString(book.getType())); 36 | query.bindValue(2,book.getPrice()); 37 | query.bindValue(3,QString::fromStdString(book.getPublisherName())); 38 | query.bindValue(4,book.getBorrowedDate()); 39 | query.bindValue(5,book.getExpectedReturnDate()); 40 | query.bindValue(6,book.getActualReturnDate()); 41 | query.bindValue(7,book.getState()); 42 | query.bindValue(8,book.getAvailability()); 43 | query.bindValue(9,QString::fromStdString(book.getImagePath())); 44 | query.exec(); 45 | return true; 46 | } 47 | 48 | bool DataBase::saveStudent(Student student) 49 | { 50 | QSqlQuery check(this->db); 51 | check.prepare("SELECT * FROM Students WHERE Name=?;"); 52 | check.bindValue(0,QString::fromStdString(student.getName())); 53 | check.exec(); 54 | if(check.next()) 55 | return false; 56 | QSqlQuery query(this->db); 57 | query.prepare("INSERT INTO Students(Name,Email,Password,cashAmount) VALUES(?,?,?,?);"); 58 | query.bindValue(0,QString::fromStdString(student.getName())); 59 | query.bindValue(1,QString::fromStdString(student.getEmail())); 60 | query.bindValue(2,QString::fromStdString(student.getPassword())); 61 | query.bindValue(3,student.getCash()); 62 | query.exec(); 63 | return true; 64 | } 65 | bool DataBase::savePublisher(Publisher publisher) 66 | { 67 | QSqlQuery check(this->db); 68 | check.prepare("SELECT * FROM Publishers WHERE Name=?;"); 69 | check.bindValue(0,QString::fromStdString(publisher.getName())); 70 | check.exec(); 71 | if(check.next()) 72 | return false; 73 | QSqlQuery query(this->db); 74 | query.prepare("INSERT INTO Publishers(Name,Email,Password,cashAmount) VALUES(?,?,?,?);"); 75 | query.bindValue(0,QString::fromStdString(publisher.getName())); 76 | query.bindValue(1,QString::fromStdString(publisher.getEmail())); 77 | query.bindValue(2,QString::fromStdString(publisher.getPassword())); 78 | query.bindValue(3,publisher.getCash()); 79 | query.exec(); 80 | return true; 81 | } 82 | void DataBase::updateStudent(Student student , string oldStuName) 83 | { 84 | int x = student.getCash(); 85 | 86 | QSqlQuery query(this->db); 87 | query.prepare("UPDATE Students SET Name=?,Email=?,Password=?,cashAmount=?,currentBook=?,requestedBook=? WHERE Name = ? ;"); 88 | query.bindValue(0,QString::fromStdString(student.getName())); 89 | query.bindValue(1,QString::fromStdString(student.getEmail())); 90 | query.bindValue(2,QString::fromStdString(student.getPassword())); 91 | query.bindValue(3,student.getCash()); 92 | query.bindValue(4,QString::fromStdString(student.getCurrentBookName())); 93 | query.bindValue(5,QString::fromStdString(student.getRequestedBookName())); 94 | query.bindValue(6,QString::fromStdString(oldStuName)); 95 | query.exec(); 96 | 97 | } 98 | void DataBase::updatePublisher(Publisher publisher, string old_name) 99 | { 100 | QSqlQuery query(this->db); 101 | query.prepare("UPDATE Publishers SET Name=?,Email=?,Password=?,cashAmount=? WHERE Name = ? ;"); 102 | query.bindValue(0,QString::fromStdString(publisher.getName())); 103 | query.bindValue(1,QString::fromStdString(publisher.getEmail())); 104 | query.bindValue(2,QString::fromStdString(publisher.getPassword())); 105 | query.bindValue(3,publisher.getCash()); 106 | query.bindValue(4,QString::fromStdString(old_name)); 107 | query.exec(); 108 | } 109 | void DataBase::updateBook(Book book , string oldBookName) 110 | { 111 | QSqlQuery query(this->db); 112 | query.prepare("UPDATE Books SET Name=?,Type=?,Price=?,Publisher=?,borrowedDate=?,expectedReturnDate=?,actualReturnDate=?,State=?,Availability=?,imagePath=? WHERE Name = ? ;"); 113 | query.bindValue(0,QString::fromStdString(book.getName())); 114 | query.bindValue(1,QString::fromStdString(book.getType())); 115 | query.bindValue(2,book.getPrice()); 116 | query.bindValue(3,QString::fromStdString(book.getPublisherName())); 117 | query.bindValue(4,book.getBorrowedDate()); 118 | query.bindValue(5,book.getExpectedReturnDate()); 119 | query.bindValue(6,book.getActualReturnDate()); 120 | query.bindValue(7,book.getState()); 121 | query.bindValue(8,book.getAvailability()); 122 | query.bindValue(9,QString::fromStdString(book.getImagePath())); 123 | query.bindValue(10,QString::fromStdString(oldBookName)); 124 | query.exec(); 125 | } 126 | 127 | void DataBase::updateBookByRowId(Book book, string rowid) 128 | { 129 | QSqlQuery query(this->db); 130 | query.prepare("UPDATE Books SET Name=?,Type=?,Price=?,Publisher=?,borrowedDate=?,expectedReturnDate=?,actualReturnDate=?,State=?,Availability=?,imagePath=? WHERE rowid = ? ;"); 131 | query.bindValue(0,QString::fromStdString(book.getName())); 132 | query.bindValue(1,QString::fromStdString(book.getType())); 133 | query.bindValue(2,book.getPrice()); 134 | query.bindValue(3,QString::fromStdString(book.getPublisherName())); 135 | query.bindValue(4,book.getBorrowedDate()); 136 | query.bindValue(5,book.getExpectedReturnDate()); 137 | query.bindValue(6,book.getActualReturnDate()); 138 | query.bindValue(7,book.getState()); 139 | query.bindValue(8,book.getAvailability()); 140 | query.bindValue(9,QString::fromStdString(book.getImagePath())); 141 | query.bindValue(10,QString::fromStdString(rowid)); 142 | query.exec(); 143 | } 144 | 145 | Book DataBase::loadBook(string name) 146 | { 147 | QSqlQuery query(this->db); 148 | query.prepare("SELECT Name,Type,Price,Publisher,borrowedDate,expectedReturnDate,actualReturnDate,State,Availability,imagePath,rowid FROM " 149 | "Books WHERE Name=?;"); 150 | query.bindValue(0,QString::fromStdString(name)); 151 | query.exec(); 152 | Book book; 153 | while(query.next()) 154 | { 155 | int available = query.value(8).toInt(); 156 | if (!available) 157 | continue; 158 | book.setAvailability(available); 159 | book.setName(query.value(0).toString().toStdString()); 160 | book.setType(query.value(1).toString().toStdString()); 161 | book.setPrice(stoi(query.value(2).toString().toStdString())); 162 | book.setPublisherName(query.value(3).toString().toStdString()); 163 | book.setBorrowedDate(query.value(4).toInt()); 164 | book.setExpectedReturnDate(query.value(5).toInt()); 165 | book.setActualReturnDate(query.value(6).toInt()); 166 | book.setState(query.value(7).toInt()); 167 | book.setImagePath(query.value(9).toString().toStdString()); 168 | book.setRowId(query.value(10).toString().toStdString()); 169 | break; 170 | } 171 | return book; 172 | } 173 | Book DataBase::loadBookByRowId(string rowid) 174 | { 175 | QSqlQuery query(this->db); 176 | query.prepare("SELECT Name,Type,Price,Publisher,borrowedDate,expectedReturnDate,actualReturnDate,State,Availability,imagePath,rowid FROM " 177 | "Books WHERE rowid=?;"); 178 | query.bindValue(0,QString::fromStdString(rowid)); 179 | query.exec(); 180 | Book book; 181 | while(query.next()) 182 | { 183 | book.setName(query.value(0).toString().toStdString()); 184 | book.setType(query.value(1).toString().toStdString()); 185 | book.setPrice(stoi(query.value(2).toString().toStdString())); 186 | book.setPublisherName(query.value(3).toString().toStdString()); 187 | book.setBorrowedDate(query.value(4).toInt()); 188 | book.setExpectedReturnDate(query.value(5).toInt()); 189 | book.setActualReturnDate(query.value(6).toInt()); 190 | book.setState(query.value(7).toInt()); 191 | book.setAvailability(query.value(8).toInt()); 192 | book.setImagePath(query.value(9).toString().toStdString()); 193 | book.setRowId(query.value(10).toString().toStdString()); 194 | } 195 | return book; 196 | } 197 | Book DataBase::loadBookForce(string name) 198 | { 199 | QSqlQuery query(this->db); 200 | query.prepare("SELECT Name,Type,Price,Publisher,borrowedDate,expectedReturnDate,actualReturnDate,State,Availability,imagePath,rowid FROM " 201 | "Books WHERE Name=?;"); 202 | query.bindValue(0,QString::fromStdString(name)); 203 | query.exec(); 204 | Book book; 205 | while(query.next()) 206 | { 207 | book.setName(query.value(0).toString().toStdString()); 208 | book.setType(query.value(1).toString().toStdString()); 209 | book.setPrice(stoi(query.value(2).toString().toStdString())); 210 | book.setPublisherName(query.value(3).toString().toStdString()); 211 | book.setBorrowedDate(query.value(4).toInt()); 212 | book.setExpectedReturnDate(query.value(5).toInt()); 213 | book.setActualReturnDate(query.value(6).toInt()); 214 | book.setState(query.value(7).toInt()); 215 | book.setAvailability(query.value(8).toInt()); 216 | book.setImagePath(query.value(9).toString().toStdString()); 217 | book.setRowId(query.value(10).toString().toStdString()); 218 | break; 219 | } 220 | return book; 221 | } 222 | Student DataBase::loadStudent(string name) 223 | { 224 | QSqlQuery query(this->db); 225 | query.prepare("SELECT Name,Email,Password,cashAmount,currentBook,requestedBook,borrowedBooks,searchHistory,favoriteBooks FROM Students WHERE Name=?;"); 226 | query.bindValue(0,QString::fromStdString(name)); 227 | query.exec(); 228 | Student student; 229 | while(query.next()) 230 | { 231 | student.setName(query.value(0).toString().toStdString()); 232 | student.setEmail(query.value(1).toString().toStdString()); 233 | student.setPassword(query.value(2).toString().toStdString()); 234 | student.setCash(stoi(query.value(3).toString().toStdString())); 235 | student.setCurrentBook(query.value(4).toString().toStdString()); 236 | student.setRequestedBook(query.value(5).toString().toStdString()); 237 | student.addBorrowedBooks(split_string(query.value(6).toString().toStdString(),",")); 238 | student.addSearchHistory(split_string(query.value(7).toString().toStdString(),",")); 239 | student.addFavoriteBooks(split_string(query.value(8).toString().toStdString(),",")); 240 | } 241 | return student; 242 | } 243 | Publisher DataBase::loadPublisher(string name) 244 | { 245 | QSqlQuery query(this->db); 246 | query.prepare("SELECT Name,Email,Password,cashAmount,my_books FROM Publishers WHERE Name=?;"); 247 | query.bindValue(0,QString::fromStdString(name)); 248 | query.exec(); 249 | Publisher publisher; 250 | while(query.next()) 251 | { 252 | publisher.setName(query.value(0).toString().toStdString()); 253 | publisher.setEmail(query.value(1).toString().toStdString()); 254 | publisher.setPassword(query.value(2).toString().toStdString()); 255 | publisher.setCash(stoi(query.value(3).toString().toStdString())); 256 | // my_books 257 | vector BooksNames = split_string(query.value(4).toString().toStdString(),","); 258 | for (int i =0 ; i< BooksNames.size(); i++) 259 | publisher.addBook(BooksNames[i]); 260 | } 261 | return publisher; 262 | } 263 | 264 | int DataBase::checkStudent(string name, string password)// 0:name,password are correct | 1:name wrong | 2:name correct & password wrong 265 | { 266 | int mode=0; 267 | QSqlQuery query(this->db); 268 | query.prepare("SELECT Name,Password FROM Students where Name = ? ;"); 269 | query.bindValue(0,QString::fromStdString(name)); 270 | query.exec(); 271 | string namee,pass; 272 | while(query.next()) 273 | { 274 | namee = query.value(0).toString().toStdString(); 275 | pass = query.value(1).toString().toStdString(); 276 | } 277 | if(namee.empty())mode=1; 278 | else {if(pass!=password)mode=2;} 279 | return mode; 280 | } 281 | int DataBase::checkPublisher(string name, string password) 282 | { 283 | int mode=0; 284 | QSqlQuery query(this->db); 285 | query.prepare("SELECT Name,Password FROM Publishers where Name = ? ;"); 286 | query.bindValue(0,QString::fromStdString(name)); 287 | query.exec(); 288 | string namee,pass; 289 | while(query.next()) 290 | { 291 | namee = query.value(0).toString().toStdString(); 292 | pass = query.value(1).toString().toStdString(); 293 | } 294 | if(namee.empty())mode=1; 295 | else {if(pass!=password)mode=2;} 296 | return mode; 297 | } 298 | 299 | void DataBase::addPublisherBooks(Book book,string pubName) 300 | { 301 | QSqlQuery query(this->db); 302 | query.prepare("SELECT my_books FROM Publishers WHERE Name=?;"); 303 | query.bindValue(0,QString::fromStdString(pubName)); 304 | query.exec(); 305 | string pubBooks; 306 | while(query.next()) 307 | pubBooks = query.value(0).toString().toStdString(); 308 | pubBooks += "," + book.getName(); 309 | query.prepare("UPDATE Publishers SET my_books=? WHERE Name=?;"); 310 | query.bindValue(0,QString::fromStdString(pubBooks)); 311 | query.bindValue(1,QString::fromStdString(pubName)); 312 | query.exec(); 313 | } 314 | void DataBase::addPublisherCash(int price , string pubName) 315 | { 316 | QSqlQuery query(this->db); 317 | query.prepare("SELECT cashAmount FROM Publishers WHERE Name=?;"); 318 | query.bindValue(0,QString::fromStdString(pubName)); 319 | query.exec(); 320 | int cashAmount=0; 321 | while(query.next()) 322 | cashAmount = query.value(0).toInt(); 323 | cashAmount += price; 324 | query.prepare("UPDATE Publishers SET cashAmount=? WHERE Name=?;"); 325 | query.bindValue(0,cashAmount); 326 | query.bindValue(1,QString::fromStdString(pubName)); 327 | query.exec(); 328 | } 329 | void DataBase::addCurrentBooks(Book book, string stuName) 330 | { 331 | QSqlQuery query(this->db); 332 | query.prepare("SELECT currentBook FROM Students WHERE Name=?;"); 333 | query.bindValue(0,QString::fromStdString(stuName)); 334 | query.exec(); 335 | string currentBooks,currentBooksUnique=""; 336 | while(query.next()) 337 | currentBooks = query.value(0).toString().toStdString(); 338 | currentBooks += "," + book.getRowId(); 339 | vector vec = split_string(currentBooks,","); 340 | sort( vec.begin(), vec.end() ); 341 | vec.erase( unique( vec.begin(),vec.end() ), vec.end() ); 342 | for(int i=0;idb); 355 | query.prepare("SELECT searchHistory FROM Students WHERE Name=?;"); 356 | query.bindValue(0,QString::fromStdString(stuName)); 357 | query.exec(); 358 | string searchBooks,searchBooksUnique=""; 359 | while(query.next()) 360 | searchBooks = query.value(0).toString().toStdString(); 361 | searchBooks += "," + book.getName(); 362 | vector vec = split_string(searchBooks,","); 363 | sort( vec.begin(), vec.end() ); 364 | vec.erase( unique( vec.begin(),vec.end() ), vec.end() ); 365 | for(int i=0;idb); 377 | query.prepare("SELECT borrowedBooks FROM Students WHERE Name=?;"); 378 | query.bindValue(0,QString::fromStdString(stuName)); 379 | query.exec(); 380 | string borrowedBooks,borrowedBooksUnique=""; 381 | while(query.next()) 382 | borrowedBooks = query.value(0).toString().toStdString(); 383 | borrowedBooks += "," + book.getName(); 384 | vector vec = split_string(borrowedBooks,","); 385 | sort( vec.begin(), vec.end() ); 386 | vec.erase( unique( vec.begin(),vec.end() ), vec.end() ); 387 | for(int i=0;idb); 399 | query.prepare("SELECT favoriteBooks FROM Students WHERE Name=?;"); 400 | query.bindValue(0,QString::fromStdString(stuName)); 401 | query.exec(); 402 | string favoriteBooks,favoriteBooksUnique=""; 403 | while(query.next()) 404 | favoriteBooks = query.value(0).toString().toStdString(); 405 | favoriteBooks += "," + book.getName(); 406 | vector vec = split_string(favoriteBooks,","); 407 | sort( vec.begin(), vec.end() ); 408 | vec.erase( unique( vec.begin(),vec.end() ), vec.end() ); 409 | for(int i=0;i DataBase::searchBookByType(string type) 421 | { 422 | QSqlQuery query(this->db); 423 | query.prepare("SELECT Name FROM Books where Type = ? ;"); 424 | query.bindValue(0,QString::fromStdString(type)); 425 | query.exec(); 426 | vector v; 427 | vector ss; 428 | while(query.next()) 429 | ss.push_back(query.value(0).toString().toStdString()); 430 | for(int i=0 ; iloadBookForce(ss[i])); 432 | return v; 433 | } 434 | vector DataBase::searchBookByPrice(int price) 435 | { 436 | QSqlQuery query(this->db); 437 | query.prepare("SELECT Name FROM Books where Price <= ? ;"); 438 | query.bindValue(0,price); 439 | query.exec(); 440 | vector v; 441 | vector ss; 442 | while(query.next()) 443 | ss.push_back(query.value(0).toString().toStdString()); 444 | for(int i=0 ; iloadBookForce(ss[i])); 446 | return v; 447 | } 448 | vector DataBase::searchBookByPubName(string pubName) 449 | { 450 | QSqlQuery query(this->db); 451 | query.prepare("SELECT Name FROM Books where Publisher = ? ;"); 452 | query.bindValue(0,QString::fromStdString(pubName)); 453 | query.exec(); 454 | vector v; 455 | vector ss; 456 | while(query.next()) 457 | ss.push_back(query.value(0).toString().toStdString()); 458 | for(int i=0 ; iloadBookForce(ss[i])); 460 | return v; 461 | } 462 | 463 | map DataBase::getAllBooks() 464 | { 465 | QSqlQuery query(this->db); 466 | query.prepare("SELECT Name,imagePath FROM Books;"); 467 | query.exec(); 468 | map name_imagePath ; 469 | while(query.next()) 470 | { 471 | string name = query.value(0).toString().toStdString() ; 472 | string imagePath = query.value(1).toString().toStdString(); 473 | name_imagePath[name] = imagePath; 474 | } 475 | return name_imagePath; 476 | 477 | } 478 | 479 | 480 | vector DataBase :: split_string(string s,string splitter) 481 | { 482 | vector splitted; 483 | uint n = s.length(); 484 | int pos = 0; 485 | int start = pos; 486 | while (pos != string::npos) 487 | { 488 | pos = s.find_first_of(splitter,pos+1); 489 | string splitted_string = s.substr(start,pos-start); 490 | splitted.push_back(splitted_string); 491 | start = pos+1; 492 | } 493 | 494 | return splitted; 495 | } 496 | -------------------------------------------------------------------------------- /database.h: -------------------------------------------------------------------------------- 1 | #ifndef DataBase_H 2 | #define DataBase_H 3 | 4 | #include 5 | #include 6 | #include "user.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | class Student; 19 | class Publisher; 20 | class Book; 21 | 22 | class DataBase 23 | { 24 | private: 25 | QSqlDatabase db; 26 | vector split_string(string s,string splitter); 27 | public: 28 | 29 | DataBase(); 30 | void init(QString); 31 | // savers 32 | bool saveBook(Book); 33 | bool saveStudent(Student); 34 | bool savePublisher(Publisher); 35 | // update1 36 | void updateBook(Book,string); 37 | void updateBookByRowId(Book,string); 38 | void updateStudent(Student,string); 39 | void updatePublisher(Publisher,string); 40 | void addPublisherBooks(Book,string); 41 | void addPublisherCash(int,string); 42 | void addCurrentBooks(Book,string); 43 | void addSearchHistory(Book,string); 44 | void addBorrowedBooks(Book,string); 45 | void addFavoriteBooks(Book,string); 46 | // system search 47 | Book loadBookByRowId(string); 48 | Book loadBook(string); 49 | Book loadBookForce(string); 50 | Student loadStudent(string); 51 | Publisher loadPublisher(string); 52 | //checkers 53 | int checkStudent(string,string); 54 | int checkPublisher(string,string); 55 | // user search 56 | vector searchBookByType(string); 57 | vector searchBookByPrice(int); 58 | vector searchBookByPubName(string); 59 | 60 | map getAllBooks(); 61 | 62 | // void saveLibrarian(Librarian); 63 | // Book loadLibirian(); 64 | }; 65 | #endif // DataBase_H 66 | -------------------------------------------------------------------------------- /icons/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/1.png -------------------------------------------------------------------------------- /icons/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/2.png -------------------------------------------------------------------------------- /icons/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/3.png -------------------------------------------------------------------------------- /icons/addBook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/addBook.png -------------------------------------------------------------------------------- /icons/book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/book.png -------------------------------------------------------------------------------- /icons/book1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/book1.png -------------------------------------------------------------------------------- /icons/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/error.png -------------------------------------------------------------------------------- /icons/favorite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/favorite.png -------------------------------------------------------------------------------- /icons/favorite1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/favorite1.png -------------------------------------------------------------------------------- /icons/history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/history.png -------------------------------------------------------------------------------- /icons/laptop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/laptop.jpg -------------------------------------------------------------------------------- /icons/login1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/login1.png -------------------------------------------------------------------------------- /icons/login2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/login2.png -------------------------------------------------------------------------------- /icons/login5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/login5.png -------------------------------------------------------------------------------- /icons/login6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/login6.png -------------------------------------------------------------------------------- /icons/logout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/logout.png -------------------------------------------------------------------------------- /icons/person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/person.png -------------------------------------------------------------------------------- /icons/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/profile.png -------------------------------------------------------------------------------- /icons/return.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/return.png -------------------------------------------------------------------------------- /icons/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/save.png -------------------------------------------------------------------------------- /icons/search.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/search.jpg -------------------------------------------------------------------------------- /icons/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/search.png -------------------------------------------------------------------------------- /icons/search1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/search1.png -------------------------------------------------------------------------------- /icons/search_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/search_1.png -------------------------------------------------------------------------------- /icons/signup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/signup.jpg -------------------------------------------------------------------------------- /icons/signup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/signup.png -------------------------------------------------------------------------------- /icons/sucess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/icons/sucess.png -------------------------------------------------------------------------------- /librarian.cpp: -------------------------------------------------------------------------------- 1 | #ifndef LIBRARIAN 2 | #define LIBRARIAN 3 | 4 | #include "librarian.h" 5 | 6 | Librarian::Librarian() //: public QObject 7 | { 8 | 9 | } 10 | 11 | Librarian::Librarian(string name, string password, string email) 12 | { 13 | 14 | } 15 | 16 | bool Librarian::checkState(Book *b) 17 | { 18 | cout<<"Ya librarian, enter the book state elly enta shayefha: 1 for bad , 0 for good"<setState(bookState); 22 | //return bookState; 23 | return 1; 24 | } 25 | 26 | Book Librarian::supplyRequestedBook(string stuName, DataBase* db) 27 | { 28 | Book b;string type;int price; 29 | Student s= db->loadStudent(stuName); 30 | string bookName = s.getRequestedBookName(); 31 | b.setName(bookName); 32 | cout<<"Ya librarian bsha, enter book's type : "<>type;b.setType(type); 34 | cout<<"w ma3lesh kman, enter book's price : "<>price;b.setPrice(price); 36 | b.setPublisherName("OUTSIDE"); 37 | db->saveBook(b); 38 | s.setRequestedBook(""); 39 | db->updateStudent(s,s.getName()); 40 | } 41 | 42 | void Librarian::libBookState(int libBookState) 43 | { 44 | flag=1; 45 | bookState = libBookState; 46 | } 47 | 48 | 49 | #endif LIBRARIAN 50 | -------------------------------------------------------------------------------- /librarian.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBRARIAN_H 2 | #define LIBRARIAN_H 3 | 4 | #include 5 | #include "user.h" 6 | #include "book.h" 7 | #include "database.h" 8 | #include "student.h" 9 | //#include 10 | 11 | using namespace std; 12 | 13 | class Librarian//: public QObject 14 | { 15 | // Q_OBJECT 16 | private: 17 | int flag,bookState; 18 | signals: 19 | void librarianWidgetOpen(); 20 | public: 21 | Librarian(); 22 | Librarian(string name , string password,string email); 23 | bool checkState(Book*); 24 | Book supplyRequestedBook(string,DataBase*); 25 | 26 | public slots: 27 | void libBookState(int); 28 | }; 29 | 30 | 31 | #endif // LIBRARIAN_H 32 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "GUI/mainwindow.h" 2 | 3 | #include 4 | int todayDate=1; 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | MainWindow w; 10 | w.show(); 11 | 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /publisher.cpp: -------------------------------------------------------------------------------- 1 | #include "publisher.h" 2 | #include "book.h" 3 | 4 | Publisher::Publisher() : User() 5 | { 6 | 7 | } 8 | 9 | Publisher::Publisher(string name, string password, string email) : User(name,email,password) 10 | { 11 | 12 | } 13 | 14 | void Publisher::showInfo() 15 | { 16 | cout <<"User's info : "<Name << endl << "E-mail : " << Email << endl << "Cash Amount : "<< cash_amount << endl; 18 | cout << "myBooks:" << endl; 19 | for (int i =0 ; i < this->my_books_names.size() ; i++) 20 | cout << this->my_books_names[i] << " "; 21 | cout << endl; 22 | } 23 | 24 | void Publisher::addBook(Book *Published_Book) 25 | { 26 | this->my_books.push_back(Published_Book); 27 | } 28 | void Publisher::RemoveBook(Book *Removed_Book) 29 | { 30 | for(unsigned int i = 0; i < my_books.size(); i++) 31 | { 32 | if(Removed_Book == my_books[i]) 33 | my_books.erase(my_books.begin()+i); 34 | } 35 | } 36 | 37 | void Publisher::addBook(string Published_Book) 38 | { 39 | this->my_books_names.push_back(Published_Book); 40 | } 41 | 42 | void Publisher::RemoveBook(string Removed_Book) 43 | { 44 | for(unsigned int i = 0; i < my_books_names.size(); i++) 45 | { 46 | if(Removed_Book == my_books_names[i]) 47 | my_books_names.erase(my_books_names.begin()+i); 48 | } 49 | } 50 | Book Publisher::getMyBook(int i) 51 | { 52 | return *(my_books[i]); 53 | } 54 | int Publisher::pubBooksNum() 55 | { 56 | return my_books.size(); 57 | } 58 | 59 | vector Publisher::viewMyBooks() 60 | { 61 | vector s; 62 | for (int i =0 ; i < this->my_books_names.size() ; i++) 63 | s.push_back(this->my_books_names[i]); 64 | return s; 65 | } 66 | -------------------------------------------------------------------------------- /publisher.h: -------------------------------------------------------------------------------- 1 | #ifndef PUBLISHER_H 2 | #define PUBLISHER_H 3 | 4 | #include "user.h" 5 | class Book; 6 | class Publisher : public User 7 | { 8 | private: 9 | vector my_books; 10 | vector my_books_names; 11 | public: 12 | Publisher(); 13 | Publisher(string name , string password,string email); 14 | void showInfo(); 15 | void addBook(Book* Published_Book); 16 | void RemoveBook(Book* Removed_Book); 17 | void addBook(string Published_Book); 18 | void RemoveBook(string Removed_Book); 19 | Book getMyBook(int i); 20 | int pubBooksNum(); 21 | vector viewMyBooks(); 22 | }; 23 | 24 | #endif // PUBLISHER_H 25 | -------------------------------------------------------------------------------- /ray2.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AmrElsersy/Library-Management-System/a8eeff866f404d587a5efdc6837b95e3e04424bf/ray2.db -------------------------------------------------------------------------------- /signup.cpp: -------------------------------------------------------------------------------- 1 | #include "signupwidget.h" 2 | 3 | SignUp::SignUp(QWidget* parent): QWidget(parent) 4 | { 5 | this->grid = new QGridLayout; 6 | this->SignUpBtn = new QPushButton("Sign Up"); 7 | this->BackBtn = new QPushButton("Back"); 8 | 9 | this->Name = new QLineEdit; 10 | this->Email = new QLineEdit; 11 | this->Password = new QLineEdit; 12 | this->ConfirmPassword = new QLineEdit; 13 | 14 | this->nameLabel = new QLabel("Name"); 15 | this->emailLabel= new QLabel("Email"); 16 | this->passLabel = new QLabel("Password"); 17 | this->confirmLabel = new QLabel("Confirm Password"); 18 | 19 | this->publisherBtn = new QRadioButton("Publisher"); 20 | this->studentBtn = new QRadioButton("Student"); 21 | this->studentBtn->setChecked(true); 22 | 23 | this->errorBox = new QMessageBox(); 24 | this->errorBox->setWindowIcon(QIcon(QCoreApplication::applicationDirPath()+"/../../Library-Management-System/icons/error.png")); 25 | 26 | this->Design(); 27 | this->Signals_Slots(); 28 | this->setLayout(this->grid); 29 | } 30 | 31 | void SignUp::Design() 32 | { 33 | this->grid->addWidget(this->nameLabel,0,0); 34 | this->grid->addWidget(this->Name,0,1,1,-1); 35 | 36 | this->grid->addWidget(this->emailLabel,1,0); 37 | this->grid->addWidget(this->Email,1,1,1,-1); 38 | 39 | this->grid->addWidget(this->passLabel,2,0); 40 | this->grid->addWidget(this->Password,2,1,1,-1); 41 | 42 | this->grid->addWidget(this->confirmLabel,3,0); 43 | this->grid->addWidget(this->ConfirmPassword,3,1,1,-1); 44 | 45 | this->grid->addWidget(this->publisherBtn,4,0); 46 | this->grid->addWidget(this->studentBtn,4,1); 47 | 48 | QHBoxLayout* verticalLayout = new QHBoxLayout; 49 | verticalLayout->addWidget(this->SignUpBtn); 50 | verticalLayout->addWidget(this->BackBtn); 51 | this->grid->addLayout(verticalLayout,5,0,1,-1); 52 | } 53 | 54 | void SignUp::Signals_Slots() 55 | { 56 | connect(this->SignUpBtn,SIGNAL(clicked()),this,SLOT(signUpCheck())); 57 | connect(this->BackBtn,SIGNAL(clicked()),this,SLOT(buttonBack())); 58 | } 59 | 60 | void SignUp::signUpCheck() 61 | { 62 | cout << "ray2" << endl; 63 | if(this->Name->text().isEmpty() || this->Email->text().isEmpty() || this->Password->text().isEmpty() 64 | || this->ConfirmPassword->text().isEmpty() ) 65 | { 66 | this->errorBox->setText("Please Fill all"); 67 | this->errorBox->show(); 68 | return; 69 | } 70 | if (this->Password->text() != this->ConfirmPassword->text()) 71 | { 72 | this->errorBox->setText("Passwords Don't Match"); 73 | this->errorBox->show(); 74 | return; 75 | } 76 | 77 | string name,pass,email;int type=0; 78 | name=this->Name->text().toStdString(); 79 | email=this->Email->text().toStdString(); 80 | pass=this->Password->text().toStdString(); 81 | if(this->studentBtn->isChecked())type=1; 82 | if(this->publisherBtn->isChecked())type=2; 83 | emit signUpData(name,email,pass,type); 84 | } 85 | 86 | void SignUp::error(string text) 87 | { 88 | this->errorBox->setText(QString::fromStdString(text)); 89 | this->errorBox->show(); 90 | } 91 | 92 | void SignUp::buttonBack() 93 | { 94 | emit setCurrentWidget(START_WIDGET); 95 | } 96 | -------------------------------------------------------------------------------- /student.cpp: -------------------------------------------------------------------------------- 1 | #ifndef STUDENT 2 | #define STUDENT 3 | 4 | #include "student.h" 5 | 6 | Student::Student(): User() 7 | { 8 | } 9 | 10 | Student::Student(string name, string password, string email) : User(name,email,password) 11 | { 12 | 13 | } 14 | 15 | void Student::addSearchHistory(vector x) 16 | { 17 | for(int i =0; isearchHistory_names.push_back(x[i]); 19 | } 20 | 21 | void Student::addFavoriteBooks(vector x) 22 | { 23 | for(int i =0; ifavoriteBooks_names.push_back(x[i]); 25 | } 26 | 27 | void Student::showInfo() 28 | { 29 | cout <<"User's info : "<borrowedBooks_names[i] << " "; 34 | cout << endl; 35 | cout << "searchHisory:"; 36 | for (int i =0 ; isearchHistory_names[i] << " "; 38 | cout << endl; 39 | cout << "favoriteBooks:"; 40 | for (int i =0 ; ifavoriteBooks_names[i] << " "; 42 | cout << endl; 43 | cout << "current:" << currentBook_name << " ,requested:" << requestedBook_name << endl; 44 | } 45 | 46 | void Student::setCurrentBook(string name) 47 | { 48 | this->currentBook_name = name; 49 | } 50 | 51 | void Student::setRequestedBook(string name) 52 | { 53 | this->requestedBook_name = name; 54 | } 55 | 56 | void Student::addBorrowedBooks(vector x) 57 | { 58 | for(int i =0; iborrowedBooks_names.push_back(x[i]); 60 | } 61 | 62 | string Student::getCurrentBookName() 63 | { 64 | return this->currentBook_name; 65 | } 66 | 67 | vector Student::getCurrentBookVector(DataBase *db) 68 | { 69 | vector v= this->split_string(currentBook_name,","); 70 | vector vb; 71 | for(int i=0;iloadBookByRowId(v[i])); 73 | return vb; 74 | } 75 | 76 | string Student::getRequestedBookName() 77 | { 78 | return this->requestedBook_name; 79 | } 80 | 81 | vector Student::getSearchHistory() 82 | { 83 | return this->searchHistory_names; 84 | } 85 | 86 | vector Student :: split_string(string s,string splitter) 87 | { 88 | vector splitted; 89 | int n = s.length(); 90 | int pos = 0; 91 | int start = pos; 92 | while (pos != string::npos) 93 | { 94 | pos = s.find_first_of(splitter,pos+1); 95 | string splitted_string = s.substr(start,pos-start); 96 | splitted.push_back(splitted_string); 97 | start = pos+1; 98 | } 99 | 100 | return splitted; 101 | } 102 | 103 | #endif STUDENT 104 | -------------------------------------------------------------------------------- /student.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENT_H 2 | #define STUDENT_H 3 | 4 | #include 5 | #include "user.h" 6 | #include "book.h" 7 | #include "database.h" 8 | 9 | using namespace std; 10 | 11 | class Student : public User 12 | { 13 | private: 14 | vector currentBooks; 15 | string currentBook_name; 16 | string requestedBook_name; 17 | vector borrowedBooks_names; 18 | vector searchHistory_names; 19 | vector favoriteBooks_names; 20 | vector split_string(string,string); 21 | 22 | public: 23 | Student(); 24 | Student(string name , string password,string email); 25 | // setters and adders 26 | //overloaded functions 27 | void setCurrentBook(string); 28 | void setRequestedBook(string); 29 | void addBorrowedBooks(vector); 30 | void addSearchHistory(vector); 31 | void addFavoriteBooks(vector); 32 | void showInfo(); 33 | 34 | // getters 35 | string getCurrentBookName(); 36 | vector getCurrentBookVector(DataBase*); 37 | string getRequestedBookName(); 38 | vector getSearchHistory(); 39 | 40 | }; 41 | 42 | #endif // STUDENT_H 43 | -------------------------------------------------------------------------------- /user.cpp: -------------------------------------------------------------------------------- 1 | #include "user.h" 2 | 3 | User::User() 4 | { 5 | 6 | } 7 | 8 | User::User(string name , string email , string password) 9 | { 10 | Name = name ; 11 | Email = email ; 12 | Password = password ; 13 | } 14 | 15 | void User::setName(string name) 16 | { 17 | Name = name ; 18 | } 19 | void User::setEmail(string email) 20 | { 21 | Email = email ; 22 | } 23 | void User::setPassword(string password) 24 | { 25 | Password = password ; 26 | } 27 | 28 | void User::addCash(int cash) 29 | { 30 | cash_amount += cash ; 31 | } 32 | 33 | void User::setCash(int cash) 34 | { 35 | this->cash_amount = cash; 36 | } 37 | string User::getName() 38 | { 39 | return this->Name ; 40 | } 41 | string User::getEmail() 42 | { 43 | return this->Email ; 44 | } 45 | string User::getPassword() 46 | { 47 | return Password ; 48 | } 49 | 50 | int User::getCash() 51 | { 52 | return cash_amount ; 53 | } 54 | 55 | void User::showInfo() 56 | { 57 | cout <<"Your info : "< 4 | #include 5 | using namespace std; 6 | 7 | class User 8 | { 9 | protected: 10 | string Name; 11 | string Email; 12 | string Password; 13 | int cash_amount=0; 14 | public: 15 | User(string name , string email , string password); 16 | User(); 17 | // ========== Setters ========== 18 | void setName(string name); 19 | void setEmail(string email); 20 | void setPassword(string password); 21 | void addCash(int cash); 22 | void setCash(int cash); 23 | // ========== Getters ========== 24 | string getName(); 25 | string getEmail(); 26 | string getPassword(); 27 | int getCash(); 28 | // ============================= 29 | void showInfo(); 30 | bool operator == (User&); // in searching compare name(or id) and passwords 31 | 32 | }; 33 | 34 | #endif // PERSON_H 35 | --------------------------------------------------------------------------------