feat: push project
This commit is contained in:
parent
803b318bda
commit
fe0098f3db
32
app/src/main/java/bdd/ArticleDAO.java
Normal file
32
app/src/main/java/bdd/ArticleDAO.java
Normal file
@ -0,0 +1,32 @@
|
||||
package bdd;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.util.Log;
|
||||
|
||||
import com.example.manageinventory.Article;
|
||||
|
||||
public class ArticleDAO {
|
||||
private DAO dao = null;
|
||||
private SQLiteDatabase db = null;
|
||||
|
||||
public ArticleDAO(Context context) {
|
||||
dao = new DAO(context);
|
||||
db = dao.open();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
dao.close();
|
||||
}
|
||||
|
||||
public long create(Article a) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("ref", a.getReference());
|
||||
values.put("des", a.getDesignation());
|
||||
values.put("pu", a.getPrix());
|
||||
values.put("qte", a.getQte());
|
||||
Log.d("bdd", "insert " + a);
|
||||
return db.insert(CreateBdInventaire.TABLE_ARTICLE, null, values);
|
||||
}
|
||||
}
|
36
app/src/main/java/bdd/CreateBdInventaire.java
Normal file
36
app/src/main/java/bdd/CreateBdInventaire.java
Normal file
@ -0,0 +1,36 @@
|
||||
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 CreateBdInventaire extends SQLiteOpenHelper {
|
||||
public static final String TABLE_ARTICLE = "article";
|
||||
private static final String CREATE_TABLE_ARTICLE =
|
||||
"CREATE TABLE " + TABLE_ARTICLE + "(" +
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
"ref TEXT NOT NULL, " +
|
||||
"des TEXT NOT NULL, " +
|
||||
"pu REAL," +
|
||||
"qte INTEGER);";
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(CREATE_TABLE_ARTICLE);
|
||||
Log.d("bdd", "Base créée");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
|
||||
db.execSQL("DROP TABLE " + TABLE_ARTICLE + ";");
|
||||
Log.d("bdd", "Table " + TABLE_ARTICLE + " supprimée");
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
public CreateBdInventaire(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
|
||||
super(context, name, factory, version);
|
||||
}
|
||||
}
|
34
app/src/main/java/bdd/DAO.java
Normal file
34
app/src/main/java/bdd/DAO.java
Normal file
@ -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 = 1;
|
||||
private static final String NOM_BDD = "inventaire.db";
|
||||
private CreateBdInventaire createBD = null;
|
||||
private SQLiteDatabase db = null;
|
||||
|
||||
public DAO(Context context) {
|
||||
createBD = new CreateBdInventaire(context, NOM_BDD, null, VERSION_BDD);
|
||||
Log.d("bdd", "Appel au constructeur de la DAO ok");
|
||||
}
|
||||
|
||||
public SQLiteDatabase open() {
|
||||
if (db == null) {
|
||||
db = createBD.getWritableDatabase();
|
||||
Log.d("bdd", "Base de donnée ouverte");
|
||||
} else {
|
||||
Log.d("bdd", "Base de donnée accessible");
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
Log.d("bdd", "Base de donnée fermer");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package com.example.manageinventory;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
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;
|
||||
@ -10,7 +13,25 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import bdd.ArticleDAO;
|
||||
|
||||
public class AjoutArticleActivity extends AppCompatActivity {
|
||||
Article art = null;
|
||||
private ArticleDAO articleDAO = null;
|
||||
private EditText etRef;
|
||||
private EditText etDes;
|
||||
private EditText etPrix;
|
||||
private EditText etQte;
|
||||
private Button btAjout;
|
||||
|
||||
String ref;
|
||||
String des;
|
||||
String prix;
|
||||
double prixN;
|
||||
String qte;
|
||||
int qteN;
|
||||
long idArticleCree;
|
||||
ArticleDAO artDAO;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -22,6 +43,7 @@ public class AjoutArticleActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
articleDAO = new ArticleDAO(this);
|
||||
initialisation();
|
||||
}
|
||||
|
||||
@ -29,6 +51,7 @@ public class AjoutArticleActivity extends AppCompatActivity {
|
||||
Button btQuitter = (Button) findViewById(R.id.btQuit);
|
||||
btQuitter.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View arg0) {
|
||||
articleDAO.close();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@ -36,8 +59,38 @@ public class AjoutArticleActivity extends AppCompatActivity {
|
||||
Button btAjoutArticle = (Button) findViewById(R.id.btAdd);
|
||||
btAjoutArticle.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View arg0) {
|
||||
System.out.println("test");
|
||||
creationArticle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void creationArticle() {
|
||||
// Reconnaissance des contrôles graphiques de la vue
|
||||
etRef = (EditText) findViewById(R.id.plRef);
|
||||
etDes = (EditText) findViewById(R.id.plDes);
|
||||
etPrix = (EditText) findViewById(R.id.plPrice);
|
||||
etQte = (EditText) findViewById(R.id.plQuant);
|
||||
btAjout = (Button) findViewById(R.id.btAdd);
|
||||
|
||||
// Récupération des zones saisies
|
||||
ref = etRef.getText().toString();
|
||||
des = etDes.getText().toString();
|
||||
prix = etPrix.getText().toString();
|
||||
prixN = (float) Float.parseFloat(prix);
|
||||
qte = etQte.getText().toString();
|
||||
qteN = Integer.parseInt(qte);
|
||||
// Création de l'article correspondant
|
||||
art = new Article(ref, des, (float) prixN, qteN);
|
||||
// Insertion de l'article dans la base de données
|
||||
long idArticleCree = articleDAO.create(art);
|
||||
// Message à l'écran
|
||||
Toast.makeText(getApplicationContext(), "Produit ajouté + " +
|
||||
"(no : " + idArticleCree + " )",Toast.LENGTH_SHORT).show();
|
||||
// Zones de saisies effacées
|
||||
etRef.setText("");
|
||||
etRef.requestFocus();
|
||||
etDes.setText("");
|
||||
etPrix.setText("");
|
||||
etQte.setText("");
|
||||
}
|
||||
}
|
59
app/src/main/java/com/example/manageinventory/Article.java
Normal file
59
app/src/main/java/com/example/manageinventory/Article.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.example.manageinventory;
|
||||
|
||||
public class Article {
|
||||
public int id = 0;
|
||||
public String reference;
|
||||
public String designation;
|
||||
public float prix;
|
||||
public int qte;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public String getDesignation() {
|
||||
return designation;
|
||||
}
|
||||
|
||||
public float getPrix() {
|
||||
return prix;
|
||||
}
|
||||
|
||||
public int getQte() {
|
||||
return qte;
|
||||
}
|
||||
|
||||
public void setQte(int qte) {
|
||||
this.qte = qte;
|
||||
}
|
||||
|
||||
public void setPrix(float prix) {
|
||||
this.prix = prix;
|
||||
}
|
||||
|
||||
public void setDesignation(String designation) {
|
||||
this.designation = designation;
|
||||
}
|
||||
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Article() {
|
||||
}
|
||||
|
||||
public Article(String reference, String designation, float prix, int qte) {
|
||||
this.reference = reference;
|
||||
this.designation = designation;
|
||||
this.prix = prix;
|
||||
this.qte = qte;
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/plRef"
|
||||
android:id="@+id/plDes"
|
||||
android:layout_width="282dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_marginStart="50dp"
|
||||
@ -26,6 +26,21 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/plRef"
|
||||
android:layout_width="282dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_marginStart="50dp"
|
||||
android:layout_marginTop="132dp"
|
||||
android:layout_marginEnd="50dp"
|
||||
android:ems="10"
|
||||
android:hint="@string/put_reference"
|
||||
android:inputType="text"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.517"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/plPrice"
|
||||
android:layout_width="282dp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user