Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
seguinleo authored Jan 10, 2022
1 parent 19db9ba commit f0882c7
Show file tree
Hide file tree
Showing 10 changed files with 719 additions and 0 deletions.
84 changes: 84 additions & 0 deletions CVerif_CB.cpp
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;
}
}
23 changes: 23 additions & 0 deletions CVerif_CB.h
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
29 changes: 29 additions & 0 deletions CarteBancaire.pro
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
Binary file added cb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions image.qrc
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>
Binary file added logo-cb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions main.cpp
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();
}
53 changes: 53 additions & 0 deletions mainwindow.cpp
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);
}
29 changes: 29 additions & 0 deletions mainwindow.h
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
Loading

0 comments on commit f0882c7

Please sign in to comment.