Advertisement
Guest User

aa

a guest
Jan 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include "loginadmin.h"
  2. #include "ui_loginadmin.h"
  3. #include <QSqlDatabase>
  4. #include <QtSql/QSqlError>
  5. #include <QtSql/QSqlQuery>
  6. #include <QMessageBox>
  7.  
  8. LoginAdmin::LoginAdmin(QWidget *parent) :
  9. QMainWindow(parent),
  10. ui(new Ui::LoginAdmin)
  11. {
  12. ui->setupUi(this);
  13.  
  14. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
  15. db.setHostName("localhost");
  16. db.setDatabaseName("registroDev");
  17. db.setPort(543);
  18. db.setUserName("postgres");
  19. db.setPassword("Lb1045723");
  20.  
  21. if(!db.open()){
  22. QMessageBox::warning(this, "Error", db.lastError().text());
  23. }else{
  24. QMessageBox::information(this, "Genial", "Conexion con DB exitosa");
  25.  
  26. }
  27.  
  28.  
  29. }
  30.  
  31. LoginAdmin::~LoginAdmin()
  32. {
  33. delete ui;
  34. }
  35.  
  36. void LoginAdmin::on_pushButton_clicked()
  37. {
  38.  
  39. QString sid = ui->lineEdit_ID->text();
  40. QString sclave = ui->lineEdit_CLAVE->text();
  41.  
  42. QSqlQuery query;
  43. QString q = "SELECT username, password FROM registros WHERE username='" + sid + "';";
  44. query.exec(q);
  45.  
  46. while(query.next())
  47. {
  48. QString user = query.value(0).toString();
  49. QString passwd = query.value(1).toString();
  50.  
  51. if(sid == user && sclave == passwd){
  52. QMessageBox::information(this, "Cool", "Bienvenido");
  53. }else {
  54. QMessageBox::warning(this, "Error", "No existe esta cuenta");
  55. }
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement