-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
719 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "CVerif_CB.h" | ||
#include <QDate> | ||
|
||
CVerif_CB::CVerif_CB() { | ||
} | ||
|
||
CVerif_CB::~CVerif_CB() { | ||
} | ||
|
||
bool CVerif_CB::getDateCB_OK() { | ||
return dateCB_OK; | ||
} | ||
|
||
bool CVerif_CB::getNumeroCB_OK() { | ||
return numeroCB_OK; | ||
} | ||
|
||
bool CVerif_CB::getCarteValide() { | ||
return carteValide; | ||
} | ||
|
||
void CVerif_CB::setCarteValide() { | ||
if((getNumeroCB_OK() == true) && (getDateCB_OK() == true)) { | ||
carteValide = true; | ||
} | ||
else { | ||
carteValide = false; | ||
} | ||
} | ||
|
||
void CVerif_CB::VerifierNumeroCB(unsigned char *numerocb) { | ||
for(int i=0; i<16; i++) { | ||
numeroCB[i] = numerocb[i] - 0x30; | ||
} | ||
int somme = 0, reste = 0, index = 0, N1 = 0; | ||
index = 1; | ||
while(index <= 15) { | ||
N1 = numeroCB[index]; | ||
somme = somme + N1; | ||
index = index + 2; | ||
} | ||
index = 0; | ||
while(index <= 15) { | ||
N1 = numeroCB[index]; | ||
N1 = N1 * 2; | ||
if(N1 > 9) { | ||
N1 = N1 - 9; | ||
} | ||
somme = somme + N1; | ||
index = index + 2; | ||
} | ||
reste = somme%10; | ||
if(reste == 0) { | ||
numeroCB_OK = true; | ||
} | ||
else { | ||
numeroCB_OK = false; | ||
} | ||
} | ||
|
||
void CVerif_CB::VerifierDateCB(unsigned char moiscb, int anneecb) { | ||
QDate DateJour = QDate::currentDate(); | ||
if(moiscb < 13) { | ||
if(DateJour.year() < anneecb) { | ||
dateCB_OK = true; | ||
} | ||
else { | ||
if(DateJour.year() <= anneecb) { | ||
if(DateJour.month() <= moiscb) { | ||
dateCB_OK = true; | ||
} | ||
else { | ||
dateCB_OK = false; | ||
} | ||
} | ||
else { | ||
dateCB_OK = false; | ||
} | ||
} | ||
} | ||
else { | ||
dateCB_OK = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef CVERIF_CB_H | ||
#define CVERIF_CB_H | ||
|
||
class CVerif_CB | ||
{ | ||
private: | ||
unsigned char numeroCB[16]; | ||
bool numeroCB_OK; | ||
bool carteValide; | ||
bool dateCB_OK; | ||
|
||
public: | ||
CVerif_CB(); | ||
~CVerif_CB(); | ||
void VerifierNumeroCB(unsigned char *numerocb); | ||
void VerifierDateCB(unsigned char moiscb, int anneecb); | ||
bool getNumeroCB_OK(); | ||
bool getDateCB_OK(); | ||
bool getCarteValide(); | ||
void setCarteValide(); | ||
}; | ||
|
||
#endif // CVERIF_CB_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
QT += core gui | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
CONFIG += c++11 | ||
|
||
# You can make your code fail to compile if it uses deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
SOURCES += \ | ||
CVerif_CB.cpp \ | ||
main.cpp \ | ||
mainwindow.cpp | ||
|
||
HEADERS += \ | ||
CVerif_CB.h \ | ||
mainwindow.h | ||
|
||
FORMS += \ | ||
mainwindow.ui | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target | ||
|
||
RESOURCES += \ | ||
image.qrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<RCC> | ||
<qresource prefix="/"> | ||
<file>cb.png</file> | ||
<file>logo-cb.jpg</file> | ||
</qresource> | ||
</RCC> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "mainwindow.h" | ||
|
||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "mainwindow.h" | ||
#include "ui_mainwindow.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
MainWindow::MainWindow(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::MainWindow) | ||
{ | ||
carteCB = new CVerif_CB(); | ||
ui->setupUi(this); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void MainWindow::on_PB_Verifier_clicked() { | ||
CVerif_CB verif; | ||
int annee; | ||
unsigned char mois; | ||
unsigned char *numerocb = new unsigned char[16]; | ||
char *numerocb2 = new char[16]; | ||
strcpy(numerocb2, ui->LE_Numero->text().toLatin1()); | ||
|
||
for(int i=0; i<16; i++) { | ||
numerocb[i] = numerocb2[i]; | ||
} | ||
|
||
verif.VerifierNumeroCB(numerocb); | ||
annee = ui->LE_Annee->text().toInt(); | ||
mois = (unsigned char)ui->LE_Mois->text().toInt(); | ||
verif.VerifierDateCB(mois,annee); | ||
verif.setCarteValide(); | ||
|
||
if(verif.getCarteValide() == true) { | ||
ui->label_Verification->setText("Valid card !"); | ||
} | ||
else { | ||
if(verif.getNumeroCB_OK() == true) { | ||
ui->label_Verification->setText("Invalid date"); | ||
} | ||
else { | ||
ui->label_Verification->setText("Invalid number"); | ||
} | ||
} | ||
} | ||
|
||
void MainWindow::on_PB_Quitter_clicked() { | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | ||
|
||
#include <QMainWindow> | ||
#include "CVerif_CB.h" | ||
|
||
namespace Ui { | ||
class MainWindow; | ||
} | ||
|
||
class MainWindow : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit MainWindow(QWidget *parent = 0); | ||
~MainWindow(); | ||
|
||
private slots: | ||
void on_PB_Verifier_clicked(); | ||
void on_PB_Quitter_clicked(); | ||
|
||
private: | ||
Ui::MainWindow *ui; | ||
|
||
CVerif_CB *carteCB; | ||
}; | ||
|
||
#endif // MAINWINDOW_H |
Oops, something went wrong.