commit f1aa4e5c9047b34fd822e22951ebb53aa228f977 Author: maissane Date: Sun May 4 10:20:13 2025 +0200 projet final diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..e7d3d31 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Dépann'Tout \ No newline at end of file diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..5089976 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..639c779 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b2c751a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..9b7528e --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..d136cd4 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.dpanntout" + compileSdk = 35 + + defaultConfig { + applicationId = "com.example.dpanntout" + minSdk = 24 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} + +dependencies { + + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/dpanntout/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/dpanntout/ExampleInstrumentedTest.java new file mode 100644 index 0000000..a11f7cc --- /dev/null +++ b/app/src/androidTest/java/com/example/dpanntout/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.dpanntout; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.dpanntout", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..313ad49 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/bdd/ClientDAO.java b/app/src/main/java/bdd/ClientDAO.java new file mode 100644 index 0000000..a3c6271 --- /dev/null +++ b/app/src/main/java/bdd/ClientDAO.java @@ -0,0 +1,74 @@ +package bdd; + +import static bdd.CreateBdDepannTout.TABLE_CLIENT; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import metier.Client; +import bdd.CreateBdDepannTout; + +public class ClientDAO { + private DAO dao = null; + private SQLiteDatabase db = null; + + /** + * Constructeur + * @param context + */ + + public ClientDAO(Context context){ + dao = new DAO(context); + db = dao.open(); + } + + /** + * Fermeture de la base de données + */ + + public void close() { + dao.close(); + } + + public Cursor readLesClients() { + String reqSql = "Select id as '_id', nom, prenom, adrMail, numTel, adrPostale FROM " + TABLE_CLIENT +";"; + // Execution de la requête + Cursor c = db.rawQuery(reqSql, null); + Log.d("bdd", "le curseur contient " + c.getCount() + " lignes"); + return c; + } + + public long create(Client c) { + ContentValues values = new ContentValues(); + values.put("nom", c.getNom()); + values.put("prenom", c.getPrenom()); + values.put("adrMail", c.getAdrMail()); + values.put("numTel", c.getNumTel()); + values.put("adrPostale", c.getAdrPostale()); + Log.d("bdd", "insert, :" + c); + return db.insert(TABLE_CLIENT, null, values); + } + + public void deleteClient(int idClient){ + db.delete("client", "id = ?", new String[]{String.valueOf(idClient)}); + db.close(); + } + + + public void updateClient(int idClient, String nom, String prenom, String adrMail, String numTel, String adrPostale) { + ContentValues values = new ContentValues(); + values.put("nom", nom); + values.put("prenom", prenom); + values.put("adrMail", adrMail); + values.put("numTel", numTel); + values.put("adrPostale", adrPostale); + + db.update("client", values, "id = ?", new String[]{String.valueOf(idClient)}); + } + + +} \ No newline at end of file diff --git a/app/src/main/java/bdd/CreateBdDepannTout.java b/app/src/main/java/bdd/CreateBdDepannTout.java new file mode 100644 index 0000000..2bbeabe --- /dev/null +++ b/app/src/main/java/bdd/CreateBdDepannTout.java @@ -0,0 +1,67 @@ +package bdd; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import androidx.annotation.Nullable; + +public class CreateBdDepannTout extends SQLiteOpenHelper { + + public static final String TABLE_CLIENT = "client"; + public static final String TABLE_INTER = "intervention"; + private static final String CREATE_TABLE_CLIENT = + "CREATE TABLE " + TABLE_CLIENT + "(" + + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "nom TEXT NOT NULL, " + + "prenom TEXT NOT NULL, " + + "adrMail TEXT NOT NULL, " + + "numTel TEXT NOT NULL, " + + "adrPostale TEXT NOT NULL);"; + + private static final String CREATE_TABLE_INTER = + "CREATE TABLE " + TABLE_INTER + "(" + + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "idCli INTEGER NOT NULL, " + + "dateTime TEXT NOT NULL, " + + "observation TEXT NOT NULL);"; + + // Constructeur, à générer automatiquement + public CreateBdDepannTout(@Nullable Context context, @Nullable String name, + @Nullable SQLiteDatabase.CursorFactory factory, int version) { + super(context, name, factory, version); + } + + /** + * Création de la base de données si elle n'existe pas + * + * @param db base + */ + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(CREATE_TABLE_CLIENT); + Log.d("bdd", "table client créée"); + + db.execSQL(CREATE_TABLE_INTER); + Log.d("bdd", "table intervention créée"); + } + + /** + * Création d'une nouvelle base en cas de changement de version + * + * @param db + * @param oldVersion + * @param newVersion + */ + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("DROP TABLE IF EXISTS " + TABLE_CLIENT + ";"); + Log.d("bdd", "Table " + TABLE_CLIENT + " supprimée"); + db.execSQL("DROP TABLE IF EXISTS " + TABLE_INTER + ";"); + Log.d("bdd", "Table " + TABLE_INTER + " supprimée"); + onCreate(db); + } + + +} \ No newline at end of file diff --git a/app/src/main/java/bdd/DAO.java b/app/src/main/java/bdd/DAO.java new file mode 100644 index 0000000..0ebdba8 --- /dev/null +++ b/app/src/main/java/bdd/DAO.java @@ -0,0 +1,34 @@ +package bdd; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +public class DAO { + private static final int VERSION_BDD = 2; + private static final String NOM_BDD = "bdDepannTout"; + private CreateBdDepannTout createBd = null; + private SQLiteDatabase db = null; + + public DAO(Context context){ + createBd = new CreateBdDepannTout(context, NOM_BDD, null, VERSION_BDD); + Log.d("bdd", "Appel au constructeur de DAO ok, bdd créée"); + } + + public SQLiteDatabase open(){ + if (db == null){ + db = createBd.getWritableDatabase(); + Log.d("bdd", "Base de données ouverte"); + } else { + Log.d("bdd", "base de données accessible"); + } + return db; + } + + public void close() { + if(db != null){ + db.close(); + Log.d("bdd", "Base de données fermée"); + } + } +} diff --git a/app/src/main/java/bdd/InterventionDAO.java b/app/src/main/java/bdd/InterventionDAO.java new file mode 100644 index 0000000..fffb447 --- /dev/null +++ b/app/src/main/java/bdd/InterventionDAO.java @@ -0,0 +1,65 @@ +package bdd; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +import metier.Client; +import metier.Intervention; + +public class InterventionDAO { + + private DAO dao = null; + private SQLiteDatabase db = null; + /** + * Constructeur + * @param context + */ + + public InterventionDAO(Context context){ + dao = new DAO(context); + db = dao.open(); + } + + + /** + * Fermeture de la base de données + */ + + public void close() { + + dao.close(); + } + + + public Cursor readLesInterventions() { + String reqSql = "Select id as '_id', idCli as 'idCli', dateTime, observation FROM " + CreateBdDepannTout.TABLE_INTER +";"; + // Execution de la requête + Cursor c = db.rawQuery(reqSql, null); + Log.d("bdd", "le curseur contient " + c.getCount() + " lignes"); + return c; + } + + public long create(Intervention i ) { + ContentValues values = new ContentValues(); + values.put("idCli", i.getIdCli()); + values.put("dateTime", i.getDateTime()); + values.put("observation", i.getObservation()); + Log.d("bdd", "insert, :" + i); + return db.insert(CreateBdDepannTout.TABLE_INTER, null, values); + } + + + + + + + + + + + + +} diff --git a/app/src/main/java/com/example/dpanntout/CreerClient.java b/app/src/main/java/com/example/dpanntout/CreerClient.java new file mode 100644 index 0000000..b76348a --- /dev/null +++ b/app/src/main/java/com/example/dpanntout/CreerClient.java @@ -0,0 +1,111 @@ +package com.example.dpanntout; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import bdd.ClientDAO; +import metier.Client; + +public class CreerClient extends AppCompatActivity { + //variables de controle graphique (on les lies avec V du controle graphique du fichier xml) +private EditText nomCli; +private EditText prenomCli; +private EditText melCli; +private EditText numCli; +private EditText adCli; +private Button btnAjt; + +//variables qui vont recuperer les valeurs saisies + String saisieNomCLi; + String saisiePrenomCli; + String saisieMelCli; + String saisieNumCli; + String saisieAdCli; + + Client client ; //nv client créer avec les nvl valeur + long idClientCree; //id unique du client crée + + + private ClientDAO clientDAO = null; //pour acceder a la bd ClientDAO et avoir acces au methode, on créer un objet clientDAO + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_creer_client); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + Initialisation(); + CreationClient(); + } + + private void Initialisation() { + //gestion du bouton quitter + Button BtQuitP1 = (Button) findViewById(R.id.BtQuitP1); + //associer l'evenement quitter au boutton quitter + BtQuitP1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + clientDAO.close(); + finish(); + } + }); + } + + //methode pour créer le nouveau client avec les informations saisies +public void CreationClient(){ + // Reconnaissance des contrôles graphiques de la vue + nomCli = (EditText) findViewById(R.id.ptNomCliP1); + prenomCli = (EditText) findViewById((R.id.ptPreCliP1)); + melCli = (EditText) findViewById((R.id.ptmelCliP1)); + numCli = (EditText) findViewById((R.id.ptNumCliP1)); + adCli = (EditText) findViewById((R.id.ptAdPoCliP1)); + btnAjt = (Button) findViewById(R.id.btAjtP1); + //acces à la table client + clientDAO = new ClientDAO(this); + + // Gestion de l'événement onClick sur le boutn Ajouter + btnAjt.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //recuperation des zones de valeurs saisies + saisieNomCLi = nomCli.getText().toString(); + saisiePrenomCli = prenomCli.getText().toString(); + saisieMelCli = melCli.getText().toString(); + saisieNumCli = numCli.getText().toString(); + saisieAdCli = adCli.getText().toString(); + + //creation du nv client avec ses valeurs saisies + client = new Client(saisieNomCLi, saisiePrenomCli, saisieMelCli, saisieNumCli, saisieAdCli); + // Insertion du client dans la base de données + long idClientCree = clientDAO.create(client); + + //toast pour afficher un msg a l'ecran + Toast.makeText(getApplicationContext(), "Client ajouté + " + "no : " + idClientCree + ")", Toast.LENGTH_SHORT).show(); + + //permettre au zone de saisie de s'effacer quand on a enregistrer + nomCli.setText(""); + prenomCli.setText(""); + melCli.setText(""); + numCli.setText(""); + adCli.setText(""); + } }); + + } + +} + + + diff --git a/app/src/main/java/com/example/dpanntout/ListeClient.java b/app/src/main/java/com/example/dpanntout/ListeClient.java new file mode 100644 index 0000000..1ba99f8 --- /dev/null +++ b/app/src/main/java/com/example/dpanntout/ListeClient.java @@ -0,0 +1,201 @@ +package com.example.dpanntout; + +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ListView; +import android.widget.SimpleCursorAdapter; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import bdd.ClientDAO; +import bdd.InterventionDAO; +import metier.Client; + +public class ListeClient extends AppCompatActivity { + private int idClientSelectionne = -1; + private Client clientSelectionne; + + + private ClientDAO clientDAO; // Déclare cette variable en haut de la classe. + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_liste_client); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + Initialisation(); + + } + private void Initialisation() { + //gestion du bouton quitter + Button btQuitterP2 = (Button) findViewById(R.id.btQuitterP2); + //associer l'evenement quitter au boutton quitter + btQuitterP2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + //gestion du bouton modifier un client + Button btModifP2 = (Button)findViewById(R.id.btModifP2); + btModifP2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (verifierClientSelectionne()) { + demarrerPageModification(); + } + } + }); + + afficherLesClients(); + } + + private void demarrerPageModification () { + Intent intent = new Intent(ListeClient.this, ModifierLeClient.class); + intent.putExtra("nom", clientSelectionne.getNom()); + intent.putExtra("prenom", clientSelectionne.getPrenom()); + intent.putExtra("mail", clientSelectionne.getAdrMail()); + intent.putExtra("numero", clientSelectionne.getNumTel()); + intent.putExtra("adresse", clientSelectionne.getAdrPostale()); + startActivity(intent); + + } + + public void afficherLesClients() { + Log.d("bdd", "debut afficherLesInterventions"); + clientDAO = new ClientDAO(this); + Cursor c = clientDAO.readLesClients(); + Log.d("Database", "Nombre de client(s) : " + c.getCount()); + Toast.makeText(getApplicationContext(), "il y a " + c.getCount() + " clients ", Toast.LENGTH_SHORT).show(); + clientDAO.close(); + //nom des 4 attributs lus dans la bdd + String[] from = new String[]{"nom", "prenom", "adrMail", "numTel", "adrPostale"}; + //reference des controles graphiques qui afficheront les valeurs + int[] to = new int[]{R.id.tvNomP2_2, R.id.tvPrenomP2_2, R.id.tvMelP2_2, R.id.tvNumP2_2, R.id.tvAdP2_2}; + //adapter : lien entre les données et les controless graphiques + SimpleCursorAdapter dataAdapter = new SimpleCursorAdapter(this, R.layout.ligne_client, c, from, to, 0); + ListView lvCli = (ListView) findViewById(R.id.lvCli); + lvCli.setAdapter(dataAdapter); + + + configurerSelectionClient(); + } + +//methode pour selectionner un client dans la liste et basculer page modif avec ses do + private void configurerSelectionClient() { + ListView lvCli = findViewById(R.id.lvCli); + lvCli.setOnItemClickListener((parent, view, position, id) -> { + // Récupération du curseur correspondant à l'élément sélectionné + Cursor c = (Cursor) parent.getItemAtPosition(position); + + // On récupère les indices des colonnes + int indexNom = c.getColumnIndexOrThrow("nom"); + int indexPrenom = c.getColumnIndexOrThrow("prenom"); + int indexMail = c.getColumnIndexOrThrow("adrMail"); + int indexNumTel = c.getColumnIndexOrThrow("numTel"); + int indexAdresse = c.getColumnIndexOrThrow("adrPostale"); + + // On récupère les valeurs des colonnes + String nomClient = c.getString(indexNom); + String prenomClient = c.getString(indexPrenom); + String mailClient = c.getString(indexMail); + String numTelClient = c.getString(indexNumTel); + String adresseClient = c.getString(indexAdresse); + + // On affiche ces infos pour le débogage + Toast.makeText(getApplicationContext(), "Client sélectionné : " + nomClient + " " + prenomClient, Toast.LENGTH_SHORT).show(); + + // Passage de toutes les données à la page de modification + Intent intent = new Intent(ListeClient.this, ModifierLeClient.class); + intent.putExtra("idClient", (int) id); // Passer l'ID du client + intent.putExtra("nom", nomClient); + intent.putExtra("prenom", prenomClient); + intent.putExtra("mail", mailClient); + intent.putExtra("numTel", numTelClient); + intent.putExtra("adresse", adresseClient); + startActivity(intent); + }); + } + + + + private boolean verifierClientSelectionne() { + if (idClientSelectionne == -1) { + Toast.makeText(this, "Sélectionnez d'abord un client à modifier ", Toast.LENGTH_SHORT).show(); + return false; + } + return true; + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/dpanntout/ListeIntervention.java b/app/src/main/java/com/example/dpanntout/ListeIntervention.java new file mode 100644 index 0000000..33e48b5 --- /dev/null +++ b/app/src/main/java/com/example/dpanntout/ListeIntervention.java @@ -0,0 +1,72 @@ +package com.example.dpanntout; + +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ListView; +import android.widget.SimpleCursorAdapter; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import bdd.ClientDAO; +import bdd.InterventionDAO; + +public class ListeIntervention extends AppCompatActivity { + + private InterventionDAO interventionDAO; // Déclare cette variable en haut de la classe. + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_liste_intervention); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + Initialisation(); + } + + private void Initialisation() { + //gestion du bouton quitter + Button tvBtQuitP3 = (Button) findViewById(R.id.tvBtQuitP3); + //associer l'evenement quitter au boutton quitter + tvBtQuitP3.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + afficherLesInterventions(); + } + + + public void afficherLesInterventions(){ + Log.d("bdd", "debut afficherLesInterventions"); + interventionDAO = new InterventionDAO(this ); + Cursor c = interventionDAO.readLesInterventions(); + Log.d("Database", "Nombre d'interventions(s) : " + c.getCount()); + Toast.makeText(getApplicationContext(), "il y a " + c.getCount() + " interventions ", Toast.LENGTH_SHORT).show(); + interventionDAO.close(); + //nom des 4 attributs lus dans la bdd + String[] from = new String[]{"idCli", "dateTime", "observation"}; + //reference des controles graphiques qui afficheront les valeurs de la page ligne_intervention + int [] to = new int[] {R.id.tvIdCliInter3_3 , R.id.tvDateInter3_3, R.id.tvobsInter3_3 }; + //adapter : lien entre les données et les controless graphiques + SimpleCursorAdapter dataAdapter = new SimpleCursorAdapter(this , R.layout.ligne_intervention, c, from,to,0); + ListView lvInter = (ListView) findViewById(R.id.lvInter); + lvInter.setAdapter(dataAdapter); + } + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/dpanntout/MainActivity.java b/app/src/main/java/com/example/dpanntout/MainActivity.java new file mode 100644 index 0000000..27f8ae9 --- /dev/null +++ b/app/src/main/java/com/example/dpanntout/MainActivity.java @@ -0,0 +1,83 @@ +package com.example.dpanntout; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + Initialisation(); + } + + + private void Initialisation() { + Button tvBtMenuAdCli = (Button) findViewById(R.id.tvBtMenuAdCli); + tvBtMenuAdCli.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + demarrerPageCreerClient(); + } + }); + Button tvBtMenuListCli = (Button)findViewById(R.id.tvBtMenuListCli); + tvBtMenuListCli.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + demarrerPageListeClient(); + } + }); + Button tvBtMenuAdInter = (Button)findViewById(R.id.tvBtMenuAdInter); + tvBtMenuAdInter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + demarrerPageCreerInter(); + } + }); + + Button tvBtMenuListInter = (Button)findViewById(R.id.tvBtMenuListInter); + tvBtMenuListInter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + demarrerPageListeinter(); + } + }); + } + + //methode utilise Intent pour demarrer la page + private void demarrerPageCreerClient () { + Intent intent = new Intent(MainActivity.this, CreerClient.class); + startActivity(intent); + } + + private void demarrerPageListeClient(){ + Intent intent = new Intent(MainActivity.this, ListeClient.class); + startActivity(intent); + } + + private void demarrerPageCreerInter(){ + Intent intent = new Intent(MainActivity.this, creerIntervention.class); + startActivity(intent); + } + + private void demarrerPageListeinter(){ + Intent intent = new Intent(MainActivity.this, ListeIntervention.class); + startActivity(intent); + } + + } \ No newline at end of file diff --git a/app/src/main/java/com/example/dpanntout/ModifierLeClient.java b/app/src/main/java/com/example/dpanntout/ModifierLeClient.java new file mode 100644 index 0000000..4454481 --- /dev/null +++ b/app/src/main/java/com/example/dpanntout/ModifierLeClient.java @@ -0,0 +1,141 @@ +package com.example.dpanntout; + +import static bdd.CreateBdDepannTout.TABLE_CLIENT; + +import android.content.Intent; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import bdd.ClientDAO; +import bdd.CreateBdDepannTout; + + +public class ModifierLeClient extends AppCompatActivity { +// private CreateBdDepannTout bdDepannTout; +private int idClient; +private String nv_nom , nv_prenom, nv_mail, nv_tel, nv_adr; + + + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_modifier_le_client); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + Initialisation(); + initialiserChampsClient(); + idClient = getIntent().getIntExtra("idClient", -1); // -1 si problème + + } + + + private void Initialisation() { + //gestion du bouton quitter + Button btQuitP5 = (Button) findViewById(R.id.btQuitP5); + //associer l'evenement quitter au boutton quitter + btQuitP5.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + Button btSupCli = (Button) findViewById(R.id.btSupCli); + btSupCli.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // appel methode pour supprimer le client + supprimerClient(); + } + }); + Button btSaveModif = (Button) findViewById(R.id.btSaveModif); + btSaveModif.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // appel methode pour supprimer le client + modifierCLient(); + } + }); + } + + + //methode qui permet d'afficher dans les champs les données du cli selectionner + private void initialiserChampsClient() { + // Récupérer les données envoyées par l'intent + Intent intent = getIntent(); + if (intent != null) { + String nom = intent.getStringExtra("nom"); + String prenom = intent.getStringExtra("prenom"); + String mail = intent.getStringExtra("mail"); + String numero = intent.getStringExtra("numTel"); + String adresse = intent.getStringExtra("adresse"); + + // Relier les EditText avec fiche id fichier xml modifier client + EditText etNom = findViewById(R.id.NomCliModif); + EditText etPrenom = findViewById(R.id.preCliModif); + EditText etMail = findViewById(R.id.melCliModif); + EditText etNumero = findViewById(R.id.numCliModif); + EditText etAdresse = findViewById(R.id.addModif); + + // Remplir les EditText + etNom.setText(nom); + etPrenom.setText(prenom); + etMail.setText(mail); + etNumero.setText(numero); + etAdresse.setText(adresse); + } + } + public void supprimerClient(){ + ClientDAO client = new ClientDAO(this); + client.deleteClient(idClient); // appel de la methode presente dans ClientDAO + Toast.makeText(this, "Client supprimé", Toast.LENGTH_SHORT).show(); + + } + + public void modifierCLient(){ + // On récupère les champs de texte (les EditText) à l'écran, où l'utilisateur a tapé les infos + EditText etNom = findViewById(R.id.NomCliModif); + EditText etPrenom = findViewById(R.id.preCliModif); + EditText etMail = findViewById(R.id.melCliModif); + EditText etNumero = findViewById(R.id.numCliModif); + EditText etAdresse = findViewById(R.id.addModif); + // On transforme le texte saisi par l'utilisateur (EditText) en vraie chaîne de caractères (String) + // C’est ce qu’on va envoyer à la base de données + String nom = etNom.getText().toString(); + String prenom = etPrenom.getText().toString(); + String mail = etMail.getText().toString(); + String numero = etNumero.getText().toString(); + String adresse = etAdresse.getText().toString(); + // On crée une instance de ClientDAO pour accéder à la base de données + ClientDAO clientDAO = new ClientDAO(this); + // On appelle la méthode updateClient avec toutes les nouvelles valeurs + l'ID du client + clientDAO.updateClient(idClient, nom, prenom, mail, numero, adresse); + // On ferme la connexion à la base de données pour libérer les ressources + clientDAO.close(); + + Toast.makeText(this, "Client modifié", Toast.LENGTH_SHORT).show(); + // On ferme cette activité et on revient à l'écran précédent (ex : la liste des clients) + finish(); // retour à la liste + + } + + + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/dpanntout/creerIntervention.java b/app/src/main/java/com/example/dpanntout/creerIntervention.java new file mode 100644 index 0000000..9df704f --- /dev/null +++ b/app/src/main/java/com/example/dpanntout/creerIntervention.java @@ -0,0 +1,109 @@ +package com.example.dpanntout; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import java.sql.Date; + +import bdd.ClientDAO; +import bdd.InterventionDAO; +import metier.Client; +import metier.Intervention; + +public class creerIntervention extends AppCompatActivity { + private EditText observation; + private EditText date ; + private EditText idCliInter ; + private Button ajtInter; + + //variables qui vont recuperer les valeurs saisies + String saisieObservation; + String saisiedate; + int saisieIdCli; + + + Intervention intervention ; //nv client créer avec les nvl valeur + long IdInnterventioncree; //id unique du client crée + + private InterventionDAO interventionDAO = null; + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_creer_intervention); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + Initialisation(); + CreationIntervention(); + } + + + + private void Initialisation() { + //gestion du bouton quitter + Button tvBtQuitterInter = (Button) findViewById(R.id.tvBtQuitterInter); + //associer l'evenement quitter au boutton quitter + tvBtQuitterInter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + interventionDAO.close(); + finish(); + } + }); + } + + //methode pour créer le nouveau client avec les informations saisies + public void CreationIntervention(){ + // Reconnaissance des contrôles graphiques de la vue + observation = (EditText) findViewById(R.id.tvDateInterP3); + date = (EditText) findViewById((R.id.obsInterP3)); + idCliInter = (EditText) findViewById(R.id.idCliInter) ; + ajtInter =(Button) findViewById(R.id.btAddInter); + //acces à la table client + interventionDAO = new InterventionDAO(this); + // Gestion de l'événement onClick sur le boutn Ajouter + ajtInter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //recuperation des zones de valeurs saisies + saisieObservation = observation.getText().toString(); + saisiedate = date.getText().toString(); + saisieIdCli = Integer.parseInt(idCliInter.getText().toString()); + + intervention = new Intervention(saisieObservation, saisiedate,(int) saisieIdCli); + + long IdInnterventioncree = interventionDAO.create(intervention); + + //toast pour afficher un msg a l'ecran + Toast.makeText(getApplicationContext(), "Intervention ajouté + " + "no : " + IdInnterventioncree + ")", Toast.LENGTH_SHORT).show(); + + //permettre au zone de saisie de s'effacer quand on a enregistrer + observation.setText(""); + date.setText(""); + idCliInter.setText(""); + } }); + + } +} + + + + + + + diff --git a/app/src/main/java/metier/Client.java b/app/src/main/java/metier/Client.java new file mode 100644 index 0000000..eb0ba66 --- /dev/null +++ b/app/src/main/java/metier/Client.java @@ -0,0 +1,69 @@ +package metier; + +public class Client { + + private int id = 0; + private String nom; + private String prenom; + private String adrMail; + private String numTel; + private String adrPostale; + + + public int getId() { + + return id; + } + public String getNom() { + + return nom; + } + public String getPrenom() { + + return prenom; + } + public String getAdrMail() { + return adrMail; + } + + public String getNumTel() { + + return numTel; + } + + + public String getAdrPostale() { + return adrPostale; + } + + @Override + public String toString() { + return "Client{" + + "id=" + id + + ", nom='" + nom + '\'' + + ", prenom='" + prenom + '\'' + + ", adrMail='" + adrMail + '\'' + + ", numTel='" + numTel + '\'' + + ", adrPostale='" + adrPostale + '\'' + + '}'; + } + + //constructeur avec id client qui sera utiles pour recuperer un client depuis la bdd + public Client(int id, String nom, String prenom, String adrMail, String numTel, String adrPostale) { + this.id = id; + this.nom = nom; + this.prenom = prenom; + this.adrMail = adrMail; + this.numTel = numTel; + this.adrPostale = adrPostale; + } + + //constructeur sans idClient qui sera utile pour créer un nv client, son id sera generer dans la bdd + public Client(String nom, String prenom, String adrMail,String numTel, String adrPostale) { + this.nom = nom; + this.prenom = prenom; + this.adrMail = adrMail; + this.numTel = numTel; + this.adrPostale = adrPostale; + } +} diff --git a/app/src/main/java/metier/Intervention.java b/app/src/main/java/metier/Intervention.java new file mode 100644 index 0000000..185ccd1 --- /dev/null +++ b/app/src/main/java/metier/Intervention.java @@ -0,0 +1,56 @@ +package metier; + +public class Intervention { + private int id; + private String dateTime; + private String observation; + private int idCli; + + public Intervention(String dateTime, String observation, int idCli) { + this.dateTime = dateTime; + this.observation = observation; + this.idCli = idCli; + } + + @Override + public String toString() { + return "Intervention{" + + "id=" + id + + ", dateTime='" + dateTime + '\'' + + ", observation='" + observation + '\'' + + ", idCli=" + idCli + + '}'; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDateTime() { + return dateTime; + } + + public void setDateTime(String dateTime) { + this.dateTime = dateTime; + } + + public String getObservation() { + return observation; + } + + public void setObservation(String observation) { + this.observation = observation; + } + + public int getIdCli() { + return idCli; + } + + public void setIdCli(int idCli) { + this.idCli = idCli; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/logodepann.png b/app/src/main/res/drawable/logodepann.png new file mode 100644 index 0000000..af51276 Binary files /dev/null and b/app/src/main/res/drawable/logodepann.png differ diff --git a/app/src/main/res/layout/activity_creer_client.xml b/app/src/main/res/layout/activity_creer_client.xml new file mode 100644 index 0000000..aad0c67 --- /dev/null +++ b/app/src/main/res/layout/activity_creer_client.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + +