/// Called when we want to administrate our list of users void App::adminUsers() { // Check if we have the rights dbo::ptr<User> user = userSession()->user(); if (!user) { go(urls::home); setStatusText(WString::tr("access-denied")); } }
int LoginData::userSession(QString user_name) { for (int i = 0; i < numberOfUsers(); i++) { if (userName(i) == user_name) { return userSession(i); } } return -1; }
bool Peminjaman::pinjamBuku(QString peminjam, QString kdbuku){ QString tanggalPinjam = QDate().currentDate().toString("yyyy-MM-dd"); QString tanggalTempo = QDate().currentDate().addDays(7).toString("yyyy-MM-dd"); QSqlQuery querypinjam, querybuku; QSettings userSession("Chip-Project","Libska-User"); QString idPetugas = userSession.value("USERID").toString(); bool ret=false; querybuku.exec("SELECT * FROM tbl_buku WHERE kd_buku = \""+kdbuku+"\" "); querybuku.next(); //qDebug()<<querybuku.lastQuery(); QString countTersedia = "0"; if(querybuku.size() != 0){ countTersedia = querybuku.value(querybuku.record().indexOf("tersedia")).toString(); }else{ //messagePinjam = "Buku tersedia"; } if( countTersedia.toInt() >= 1){ QString sql = "INSERT INTO tbl_peminjaman SET siswa=\""+peminjam+"\", buku=\""+kdbuku+"\", tgl_tempo=\""+tanggalTempo+"\", tgl_pinjam=\""+tanggalPinjam+"\", id_petugas=\""+idPetugas+"\" "; if(!querypinjam.exec(sql)){ qDebug() << "Peminjaman::pinjamBuku : Error Query insert"; qDebug() << sql; ret = false; }else{ //Query Buku querybuku.clear(); if(querybuku.exec("SELECT * FROM tbl_buku WHERE kd_buku = \""+kdbuku+"\" ")){ querybuku.next(); QString tersedia = querybuku.value(querybuku.record().indexOf("tersedia")).toString(); int newTersedia = tersedia.toInt() - 1; int newCount = querybuku.value(querybuku.record().indexOf("count")).toInt() + 1; if(querybuku.size() == 1){ querybuku.clear(); if(querybuku.exec("UPDATE tbl_buku SET tersedia = \""+QString::number(newTersedia)+"\", count = \""+QString::number(newCount)+"\" WHERE kd_buku = \""+kdbuku+"\" ")){ QSqlQuery querySiswa; querySiswa.exec("SELECT * FROM tbl_anggota WHERE no_induk = \""+peminjam+"\" "); querySiswa.next(); int newCountSiswa = querySiswa.value(querybuku.record().indexOf("tersedia")).toInt() + 1; querybuku.clear(); if(querybuku.exec("UPDATE tbl_anggota SET count = \""+QString::number(newCountSiswa)+"\" WHERE no_induk = \""+peminjam+"\" ")){ }else{ qDebug()<<"Error udpate tbl anggota : "+querybuku.lastQuery(); } ret = true; }else{ qDebug()<<"pinjamBuku : Error update stock"; ret = false; } } }else{ qDebug()<<"pinjamBuku : Error count stock"; ret = false; } } }else{ ret = false; } return ret; }