-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloodRecieversence.java
236 lines (193 loc) · 7.09 KB
/
bloodRecieversence.java
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package blood.management;
import DB.DBConnection;
import DB.DeleteDatabase;
import DB.DisplayDatabase;
import DB.QueryDatabase;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
/**
* FXML Controller class
*
* @author Wipro
*/
public class bloodRecieversence implements Initializable {
@FXML
private TextField rName;
@FXML
private ComboBox<String> rGroup;
@FXML
private ComboBox<String> rGender;
@FXML
private TextField rContact;
@FXML
private DatePicker rDate;
@FXML
private Button addBtn;
@FXML
private TextField rAmount;
@FXML
private TextField rQty;
/**
* Initializes the controller class.
*/
DisplayDatabase displayBloodData = new DisplayDatabase();
@FXML
private TableView<?> rTableView;
@FXML
private TextField rDoctor;
@FXML
private ComboBox<String> rEid;
String name="";
String bGroup="";
String gender="";
String contact="";
String amount="";
String qty="";
LocalDate date;
String doctor="";
String eid="";
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
ObservableList<String> eList = FXCollections.observableArrayList();
ObservableList<String> gList = FXCollections.observableArrayList();
gList.add("Male");
gList.add("Female");
gList.add("Other");
rGender.setItems(gList);
ResultSet rs = QueryDatabase.query("Select EID from EmpTable;");
if(rs!=null){
try {
while(rs.next()){
eList.add(rs.getString(1));
}
} catch (SQLException ex) {
Logger.getLogger(AddbloodSence.class.getName()).log(Level.SEVERE, null, ex);
}
}
rEid.setItems(eList);
rDate.setValue(LocalDate.now());
ObservableList<String> groupList = FXCollections.observableArrayList();
groupList.add("O +ve");
groupList.add("A +ve");
groupList.add("b +ve");
groupList.add("Ab +ve");
groupList.add("O -ve");
groupList.add("A -ve");
groupList.add("b -ve");
groupList.add("Ab -ve");
rGroup.setItems(groupList);
displayBloodData.buildData(rTableView, "Select * from recieverTable Order By(Id) desc;");
}
@FXML
private void addReciever(ActionEvent event) {
name = rName.getText();
bGroup = rGroup.getValue();
gender = rGender.getValue();
contact = rContact.getText();
date = rDate.getValue();
amount = rAmount.getText();
qty = rQty.getText();
doctor = rDoctor.getText();
eid = rEid.getValue();
if(name==null || name.isEmpty()){
rName.requestFocus();
return;
}
if(bGroup==null || bGroup.isEmpty()){
rGroup.requestFocus();
return;
}
if(contact==null || contact.isEmpty()){
rContact.requestFocus();
return;
}
if(amount==null || amount.isEmpty()){
rAmount.requestFocus();
return;
}
if(qty==null || qty.isEmpty()){
rQty.requestFocus();
return;
}
if(doctor==null || doctor.isEmpty()){
rDoctor.requestFocus();
return;
}
if(eid==null || eid.isEmpty()){
rEid.requestFocus();
return;
}
Connection c;
try{
c = DBConnection.connect();
String query = "insert into RECIEVERTable (date,Name,BloodGroup,Gender,Amount,Qty,DoctorName,Eid,Contact) values ('"+date+"','"+name+"','"+bGroup+"','"+gender+"','"+amount+"','"+qty+"','"+doctor+"','"+eid+"','"+contact+"');";
c.createStatement().execute(query);
ResultSet rs = QueryDatabase.query("Select bloodGroup from inventorytable where bloodgroup='"+bGroup+"';");
if(rs==null){
query = "insert into InventoryTable (bloodGroup,Qty) values ('"+bGroup+"','"+0+"');";
c.createStatement().execute(query);
}else{
if(!rs.next()){
query = "insert into InventoryTable (bloodGroup,Qty) values ('"+bGroup+"','"+0+"');";
c.createStatement().execute(query);
}else{
query = "Update InventoryTable set Qty=Qty-"+qty+" where bloodgroup='"+bGroup+"';";
c.createStatement().execute(query);
}
}
c.close();
rName.clear();
rGroup.setValue("");
rGender.setValue("");
rContact.clear();
rAmount.clear();
rQty.clear();
rDoctor.clear();
rEid.setValue("");
displayBloodData.buildData(rTableView, "Select * from recieverTable Order By(Id) desc;");
} catch (SQLException ex) {
Logger.getLogger(bloodRecieversence.class.getName()).log(Level.SEVERE, null, ex);
}
}
@FXML
private void mDeleteRecord(ActionEvent event) {
int index = rTableView.getSelectionModel().getSelectedIndex();
ObservableList<ObservableList> data = displayBloodData.getData();
ObservableList<String> row = data.get(index);
DeleteDatabase.deleteRecord(Integer.parseInt(row.get(0)), "recieverTable");
displayBloodData.buildData(rTableView, "Select * from recieverTable Order By(Id) desc;");
Connection c;
try{
c = DBConnection.connect();
String query = "Update InventoryTable set Qty=Qty+"+Integer.parseInt(row.get(8))+" where bloodgroup='"+row.get(3)+"';";
c.createStatement().execute(query);
c.close();
} catch (SQLException ex) {
Logger.getLogger(AddbloodSence.class.getName()).log(Level.SEVERE, null, ex);
}
}
}