projet android depanntout fini

This commit is contained in:
maissane 2025-05-12 10:35:42 +02:00
parent 169ada12e2
commit e9fab30f78
16 changed files with 370 additions and 70 deletions

1
.idea/vcs.xml generated
View File

@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/DepannTout" vcs="Git" />
</component>
</project>

View File

@ -12,6 +12,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.DépannTout"
tools:targetApi="31">
<activity
android:name=".ModifierLintervention"
android:exported="false" />
<activity
android:name=".ModifierLeClient"
android:exported="false" />

View File

@ -29,7 +29,6 @@ public class ClientDAO {
/**
* Fermeture de la base de données
*/
public void close() {
dao.close();
}

View File

@ -27,7 +27,7 @@ public class CreateBdDepannTout extends SQLiteOpenHelper {
"dateTime TEXT NOT NULL, " +
"observation TEXT NOT NULL);";
// Constructeur, à générer automatiquement
// Constructeur (généré automatiquement)
public CreateBdDepannTout(@Nullable Context context, @Nullable String name,
@Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);

View File

@ -14,7 +14,6 @@ public class DAO {
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();
@ -24,7 +23,6 @@ public class DAO {
}
return db;
}
public void close() {
if(db != null){
db.close();

View File

@ -5,6 +5,9 @@ import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.Toast;
import org.w3c.dom.Text;
import metier.Client;
import metier.Intervention;
@ -35,7 +38,8 @@ public class InterventionDAO {
public Cursor readLesInterventions() {
String reqSql = "Select id as '_id', idCli as 'idCli', dateTime, observation FROM " + CreateBdDepannTout.TABLE_INTER +";";
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");
@ -50,8 +54,25 @@ public class InterventionDAO {
Log.d("bdd", "insert, :" + i);
return db.insert(CreateBdDepannTout.TABLE_INTER, null, values);
}
public void deleteIntervention(int id ){
// int ligneSuppr = db.delete("intervention", "id = ?", new String[]{String.valueOf(id)});
//// db.close();
// Log.d("DEBUG", "Nombre de lignes supprimées : " + ligneSuppr );
Log.d("DEBUG", "Tentative de suppression de l'intervention avec l'ID : " + id);
int ligneSuppr = db.delete("intervention", "id = ?", new String[]{String.valueOf(id)});
Log.d("DEBUG", "Nombre de lignes supprimées : " + ligneSuppr); // Affiche le nombre de lignes supprimées
db.close();
}
public void updateIntervention(int idInter, int idCli, String dateTime, String observation) {
ContentValues values = new ContentValues();
// values.put("idInter", idInter);
values.put("idCli", idCli);
values.put("dateTime", dateTime);
values.put("observation", observation);
db.update("intervention", values, "id = ?", new String[]{String.valueOf(idInter)});
}

View File

@ -50,30 +50,30 @@ public class ListeClient extends AppCompatActivity {
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();
}
}
});
// //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);
}
// 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");
@ -133,13 +133,14 @@ public class ListeClient extends AppCompatActivity {
private boolean verifierClientSelectionne() {
if (idClientSelectionne == -1) {
Toast.makeText(this, "Sélectionnez d'abord un client à modifier ", Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
//ct une condition pour le bouton genre qd on clic sur le bouton modif sans selec un cli
// private boolean verifierClientSelectionne() {
// if (idClientSelectionne == -1) {
// Toast.makeText(this, "Sélectionnez d'abord un client à modifier ", Toast.LENGTH_SHORT).show();
// return false;
// }
// return true;
// }

View File

@ -56,7 +56,7 @@ public class ListeIntervention extends AppCompatActivity {
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();
// 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
@ -65,8 +65,43 @@ public class ListeIntervention extends AppCompatActivity {
SimpleCursorAdapter dataAdapter = new SimpleCursorAdapter(this , R.layout.ligne_intervention, c, from,to,0);
ListView lvInter = (ListView) findViewById(R.id.lvInter);
lvInter.setAdapter(dataAdapter);
configurerSelectioninter();
}
private void configurerSelectioninter() {
ListView lvInter = findViewById(R.id.lvInter);
lvInter.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 l'ID de l'intervention depuis le curseur
int indexId = c.getColumnIndexOrThrow("_id"); // Assurez-vous que le nom de la colonne est "id"
int interventionId = c.getInt(indexId);
// On récupère les indices des colonnes
int indexIdCli = c.getColumnIndexOrThrow("idCli");
int indexDate = c.getColumnIndexOrThrow("dateTime");
int indexObservation = c.getColumnIndexOrThrow("observation");
// On récupère les valeurs des colonnes
String idClient = c.getString(indexIdCli);
String date = c.getString(indexDate);
String obs = c.getString(indexObservation);
// On affiche ces infos pour le débogage
Toast.makeText(getApplicationContext(), "Intervention sélectionné : " + idClient + " " , Toast.LENGTH_SHORT).show();
// Passage de toutes les données à la page de modification
Intent intent = new Intent(ListeIntervention.this, ModifierLintervention.class);
intent.putExtra("_id", interventionId); // Passer l'ID de l'intervention
intent.putExtra("id", (int) id); // Passer l'ID de l'inter
intent.putExtra("idCli", idClient);
intent.putExtra("dateTime", date);
intent.putExtra("observation", obs);
startActivity(intent);
});
}
}

View File

@ -0,0 +1,130 @@
package com.example.dpanntout;
import android.content.Intent;
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.InterventionDAO;
public class ModifierLintervention extends AppCompatActivity {
private int idInter ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_modifier_lintervention);
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();
initialiserChampsIntervention();
idInter = getIntent().getIntExtra("id", -1); // -1 si problème
}
private void Initialisation() {
//gestion du bouton quitter
Button btQuitModifInter = (Button) findViewById(R.id.btQuitModifInter);
//associer l'evenement quitter au boutton quitter
btQuitModifInter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Button btDeleteInter = (Button) findViewById(R.id.btDeleteInter);
btDeleteInter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
supprimerIntervention();
}
});
Button saveModifInter = (Button) findViewById(R.id.saveModifInter);
saveModifInter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
modifierIntervention();
}
});
}
//methode qui permet d'afficher dans les champs les données d'une inter selectionner
private void initialiserChampsIntervention() {
// Récupérer les données envoyées par l'intent
Intent intent = getIntent();
if (intent != null) {
String numCLient = intent.getStringExtra("idCli");
String date = intent.getStringExtra("dateTime");
String observation = intent.getStringExtra("observation");
// Relier les EditText avec fiche id fichier xml modifier client
EditText etNumCli = findViewById(R.id.tvNumcliModif);
EditText etDateTime = findViewById(R.id.tvDateModif);
EditText etObservation = findViewById(R.id.tvObsModif);
// Remplir les EditText
etNumCli.setText(numCLient);
etDateTime.setText(date);
etObservation.setText(observation);
}
}
public void supprimerIntervention(){
InterventionDAO intervention = new InterventionDAO(this);
intervention.deleteIntervention(idInter); // appel de la methode presente dans ClientDAO
intervention.close(); //fermer la classe
Toast.makeText(this, "Intervention supprimé", Toast.LENGTH_SHORT).show();
}
public void modifierIntervention(){
// On récupère les champs de texte (les EditText) à l'écran, l'utilisateur a tapé les infos
EditText etNumCli = findViewById(R.id.tvNumcliModif);
EditText etDateTime = findViewById(R.id.tvDateModif);
EditText etObservation = findViewById(R.id.tvObsModif);
// On transforme le texte saisi par l'utilisateur (EditText) en vraie chaîne de caractères (String)
// Cest ce quon va envoyer à la base de données
String idClient = etNumCli.getText().toString();
String date = etDateTime.getText().toString();
String observation = etObservation.getText().toString();
// On crée une instance de ClientDAO pour accéder à la base de données
InterventionDAO interventionDAO = new InterventionDAO(this);
// On appelle la méthode updateClient avec toutes les nouvelles valeurs + l'ID du client
interventionDAO.updateIntervention( idInter, Integer.parseInt(idClient), date, observation );
// On ferme la connexion à la base de données pour libérer les ressources
interventionDAO.close();
Toast.makeText(this, "intervention modifiée", 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
}
}

View File

@ -99,6 +99,14 @@ public class creerIntervention extends AppCompatActivity {
} });
}
}

View File

@ -31,6 +31,14 @@
android:textAlignment="center"
android:textSize="24sp" />
<EditText
android:id="@+id/idCliInter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/idCliInter" />
<EditText
android:id="@+id/tvDateInterP3"
android:layout_width="match_parent"
@ -49,14 +57,6 @@
android:inputType="text"
android:text="@string/ObsInter" />
<EditText
android:id="@+id/idCliInter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/idCliInter" />
<Button
android:id="@+id/btAddInter"
android:layout_width="match_parent"

View File

@ -9,9 +9,18 @@
tools:context=".ListeIntervention">
<LinearLayout
android:id="@+id/tvListeP3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="729dp"-->
<!-- android:orientation="vertical"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<TextView
android:id="@+id/textView5"
@ -25,7 +34,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/titreP3"
android:text="@string/tvTitreListeInter"
android:textAlignment="center"
android:textSize="24sp" />
@ -35,6 +44,13 @@
android:layout_margin="9dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvIdCliP3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/idCliInter" />
<TextView
android:id="@+id/tvDateP3"
android:layout_width="wrap_content"
@ -51,19 +67,20 @@
android:text="@string/ObsInter"
android:textSize="16sp" />
<TextView
android:id="@+id/tvIdCliP3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/idCliInter" />
</LinearLayout>
<!-- <ListView-->
<!-- android:id="@+id/lvInter"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="544dp" />-->
<ListView
android:id="@+id/lvInter"
android:layout_width="match_parent"
android:layout_height="544dp" />
android:layout_height="0dp"
android:layout_weight="1"
android:paddingStart="8dp"
android:paddingEnd="8dp"/>
<Button
android:id="@+id/tvBtQuitP3"

View File

@ -72,19 +72,19 @@
<Button
android:id="@+id/btSaveModif"
android:layout_width="match_parent"
android:layout_width="392dp"
android:layout_height="wrap_content"
android:text="@string/btEnrModif" />
<Button
android:id="@+id/btQuitP5"
android:layout_width="match_parent"
android:layout_width="392dp"
android:layout_height="wrap_content"
android:text="@string/btQuitModif" />
<Button
android:id="@+id/btSupCli"
android:layout_width="match_parent"
android:layout_width="392dp"
android:layout_height="wrap_content"
android:soundEffectsEnabled="true"
android:text="@string/SupprCliModif"

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ModifierLintervention">
<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
android:orientation="vertical"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">
<TextView
android:id="@+id/tvApNamP6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="@string/app_name" />
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="@string/titreModifInter"
android:textAlignment="center"
android:textSize="24sp" />
<EditText
android:id="@+id/tvNumcliModif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/tvNumCliModif" />
<EditText
android:id="@+id/tvDateModif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/tvDateModif" />
<EditText
android:id="@+id/tvObsModif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="@string/tvObsModif" />
<Button
android:id="@+id/saveModifInter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btsaveModifInter" />
<Button
android:id="@+id/btQuitModifInter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btQuitModifInter" />
<Button
android:id="@+id/btDeleteInter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btSupprInter" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,15 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<!-- xmlns:tools="http://schemas.android.com/tools"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent">-->
<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
<!-- <LinearLayout-->
<!-- android:layout_width="409dp"-->
<!-- android:layout_height="729dp"-->
<!-- android:orientation="horizontal"-->
<!-- tools:layout_editor_absoluteX="1dp"-->
<!-- tools:layout_editor_absoluteY="1dp">-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">
android:padding="4dp">
<TextView
android:id="@+id/tvIdCliInter3.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/idCliInter" />
<TextView
android:id="@+id/tvDateInter3.3"
@ -25,11 +37,5 @@
android:layout_weight="1"
android:text="@string/ObsInter" />
<TextView
android:id="@+id/tvIdCliInter3.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/idCliInter" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<!--</androidx.constraintlayout.widget.ConstraintLayout>-->

View File

@ -31,4 +31,12 @@
<string name="btQuitModif">Quitter l\'edition</string>
<string name="btEnrModif">Enregistrer les modifications</string>
<string name="SupprCliModif">Supprimer le client</string>
<string name="titreModifInter">Modifier une intervention</string>
<string name="btsaveModifInter">Enregistrer les modifications</string>
<string name="btQuitModifInter">Quitter l\'edition</string>
<string name="btSupprInter">Supprimer l\'intervention</string>
<string name="tvDateModif">Date de l\'intervention</string>
<string name="tvObsModif">Observation</string>
<string name="tvNumCliModif">NumClient</string>
<string name="tvTitreListeInter">Listes des interventions</string>
</resources>