feat: add list with db

This commit is contained in:
Azerothwav 2024-12-09 11:08:44 +01:00
parent fe0098f3db
commit 744d40b497
5 changed files with 126 additions and 2 deletions

1
.idea/gradle.xml generated
View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

View File

@ -2,6 +2,7 @@ package bdd;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.util.Log; import android.util.Log;
@ -29,4 +30,11 @@ public class ArticleDAO {
Log.d("bdd", "insert " + a); Log.d("bdd", "insert " + a);
return db.insert(CreateBdInventaire.TABLE_ARTICLE, null, values); return db.insert(CreateBdInventaire.TABLE_ARTICLE, null, values);
} }
public Cursor readArticles() {
String reqSQL = "SELECT id AS '_id', ref, des, pu, qte FROM " + CreateBdInventaire.TABLE_ARTICLE + ";";
Cursor c = db.rawQuery(reqSQL, null);
Log.d("bdd", "Le curseur contient : " + c.getCount() + " lignes");
return c;
}
} }

View File

@ -1,8 +1,13 @@
package com.example.manageinventory; package com.example.manageinventory;
import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import androidx.activity.EdgeToEdge; import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -10,6 +15,10 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsCompat;
import java.util.List;
import bdd.ArticleDAO;
public class ListeArticleActivity extends AppCompatActivity { public class ListeArticleActivity extends AppCompatActivity {
@Override @Override
@ -32,5 +41,20 @@ public class ListeArticleActivity extends AppCompatActivity {
finish(); finish();
} }
}); });
afficherLesArticles();
}
public void afficherLesArticles() {
Log.d("bdd", "Début affichage");
ArticleDAO articleDAO = new ArticleDAO(this);
Cursor c = articleDAO.readArticles();
Toast.makeText(getApplicationContext(), "Il y a " + c.getCount() + " articles", Toast.LENGTH_SHORT).show();
articleDAO.close();
String[] from = new String[] {"ref", "des", "pu", "qte"};
int[] to = new int[] {R.id.tvRef, R.id.tvDes, R.id.tvPrix, R.id.tvQte};
SimpleCursorAdapter dataAdapter = new SimpleCursorAdapter(this, R.layout.ligne_article, c, from, to, 0);
ListView lvArticle = (ListView) findViewById(R.id.lvArticle);
lvArticle.setAdapter(dataAdapter);
} }
} }

View File

@ -16,7 +16,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="160dp" android:layout_marginStart="160dp"
android:layout_marginTop="152dp" android:layout_marginTop="664dp"
android:text="@string/quit" android:text="@string/quit"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -26,9 +26,56 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="152dp" android:layout_marginStart="152dp"
android:layout_marginTop="112dp" android:layout_marginTop="32dp"
android:text="@string/list_stock" android:text="@string/list_stock"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="89dp"
android:text="Ref"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginTop="89dp"
android:text="Désignation"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="239dp"
android:layout_marginTop="89dp"
android:text="Prix"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="337dp"
android:layout_marginTop="89dp"
android:text="Qté"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="@+id/lvArticle"
android:layout_width="409dp"
android:layout_height="554dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="109dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,44 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="409dp"
android:layout_height="529dp"
android:layout_marginTop="136dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="1dp">
<TextView
android:id="@+id/tvRef"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ref" />
<TextView
android:id="@+id/tvDes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Désignation" />
<TextView
android:id="@+id/tvPrix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Prix" />
<TextView
android:id="@+id/tvQte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantité" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>