AjoutMedocActivity.java
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.example.martin.projetv5;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Toast;
import java.util.ArrayList;
/**
* Created by martin on 28/02/2017.
*/
public class AjoutMedocActivity extends AppCompatActivity {
StringBDD eventBDD = null;
ArrayList<String> arrayList = new ArrayList<>();
AutoCompleteTextView editNom = null;
public void onClickAjout(View view){
editNom = (AutoCompleteTextView) findViewById(R.id.textNom);
String s1 = editNom.getText().toString();
// on regarde si le nom rentré existe
boolean existe = false;
int w=1;
while(w <= eventBDD.getIndiceMaxMedoc() && !existe) {
Medicament m = eventBDD.getMedocWithId(w);
if (m.getNom1().equals(s1)) existe = true;
w++;
}
if(existe) {
Medicament m = eventBDD.getMedocWithNom1(s1);
// s'il existe on regarde ensuite si ce medicament n'est pas déjà en train d'être pris
boolean ok = true;
int x=1;
while(x <= eventBDD.getIndiceMaxPrise() && ok){
Prise2 p = eventBDD.getPriseWithId(x);
if(p.getIdMedoc().equals(m.getIdM()))ok = false;
x++;
}
if(ok) {
// si tout est bon, on poursuit
Intent i = new Intent(this, ModifMedocActivity.class);
boolean nouveau = true;
i.putExtra("id", m.getIdM());
i.putExtra("new", nouveau);
startActivity(i);
}
else Toast.makeText(this,R.string.ajout3,Toast.LENGTH_LONG).show();
}
else Toast.makeText(this,R.string.ajout2,Toast.LENGTH_LONG).show();
}
void recupNom1Medoc(ArrayList<String> aList){
for(int w=0; w<eventBDD.getIndiceMaxMedoc(); w++){
String s = eventBDD.getMedocWithId(w+1).getNom1();
aList.add(w,s);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ajout_layout);
eventBDD = new StringBDD(this);
eventBDD.open();
}
@Override
protected void onResume() {
eventBDD.open();
super.onResume();
editNom = (AutoCompleteTextView) findViewById(R.id.textNom);
recupNom1Medoc(arrayList);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, arrayList);
editNom.setAdapter(adapter);
editNom.setThreshold(0);
}
@Override
protected void onPause() {
eventBDD.close();
super.onPause();
arrayList.clear();
}
}