-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSQLOperate.java
More file actions
340 lines (278 loc) · 9.14 KB
/
SQLOperate.java
File metadata and controls
340 lines (278 loc) · 9.14 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package finalServer;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import finalServer.Server;
import finalServer.Server.DoctorInfo;
public class SQLOperate {
Connection con;
// static public ResultSet rs=null;
static public Statement st = null;
public SQLOperate(Connection con) {
this.con=con;
try {
st =Server.con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void doctorReadMedicineData() {//从文件读取数据,更新到medicineData
try {
Statement st =Server.con.createStatement();
ResultSet rs=st.executeQuery("select * from medicine");
while(rs.next()){
Server.MedicineInfo mi=new Server.MedicineInfo(rs.getString(1).trim(),rs.getInt(2),rs.getInt(3));
DoctorThread.medicineData.put(rs.getString(1).trim(), mi);
}
rs.close();
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void updateDoctorRegisterIncome(String doctorAccount){
String command="update doctor set income=income+10,registerIncome=registerIncome+10 where account='"+doctorAccount+"'";
try {
st.execute(command);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void updateDoctorMedicineIncome(String doctorAccount,int price){
String command="update doctor set income=income+"+price+" ,medicineIncome=medicineIncome+"+price+" where account='"+doctorAccount+"'";
try {
st.execute(command);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void updateDepartmentRegisterIncome(String depart){
String command1="update departmentIncome set income=income+10 where department='"+depart+"'";
String command2="update departmentIncome set registerIncome=registerIncome+10 where department='"+depart+"'";
try {
st.execute(command1);
st.execute(command2);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void updateDepartmentMedicineIncome(String depart,int price){
String command1="update departmentIncome set income=income+"+price+" where department='"+depart+"'";
String command2="update departmentIncome set medicineIncome=medicineIncome+"+price+" where department='"+depart+"'";
try {
st.execute(command1);
st.execute(command2);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void declineMedicineCount(String name,int count){
String command="update medicine set count=count-"+count+" where name='"+name+"'";
try {
st.execute(command);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public boolean login(String type,String account, String password) { //登录函数
String command="select * from account where type='";
command+=(type+"' and account='");
command+=(account+"' and password='");
command+=(password+"'");
try {
ResultSet rs=st.executeQuery(command);
if(rs.next()){
rs.close();
return true;
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
//
}
static public String sendMedicineInfoToAdmin(){
//Medicine m=new MedicineInfo(name, count, price);
String message="";
String command="select * from medicine";
try {
ResultSet rs=st.executeQuery(command);
while(rs.next()){
message+=(rs.getString(1).trim()+",");
message+=(rs.getString(2).trim()+",");
message+=(rs.getString(3).trim()+"#");
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return message;
}
static public void addOnlineDoctorInfo(String string){
String command="select * from doctor where account='"+string+"'";
try {
ResultSet rs=st.executeQuery(command);
rs.next();
Server.DoctorInfo di=new Server.DoctorInfo();
di.account=rs.getString(1).trim();
di.name=rs.getString(2).trim();
di.waitCount=0;
di.department=rs.getString(5).trim();
Server.onlineDoctor.add(di);
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void addMedicineInfo(String medicine,String count,String price){
String command="insert into medicine values('"+medicine+"',"+count+","+price+")";
try {
st.execute(command);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void changeMedicineInfo(String medicine,String newName,String count,String price){
String command="update medicine set name='"+newName+"', count="+count+",price="+price+" where name='"+medicine+"'";
try {
st.execute(command);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void deleteMedicineInfo(String medicine){
String command="delete medicine where name='"+medicine+"'";
try {
st.execute(command);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public String sendDoctorInfoToAdmin(){
String message="";
String command1="select * from account";
String command2="select * from doctor";
HashMap<String,String> ps=new HashMap<String,String>();
try {
ResultSet rs1=st.executeQuery(command1);
while(rs1.next()){
ps.put(rs1.getString(1).trim(), rs1.getString(2).trim());
}
ResultSet rs2=st.executeQuery(command2);
while(rs2.next()){
String a=rs2.getString(1).trim();
message+=(a+",");
message+=(ps.get(a)+",");
message+=(rs2.getString(2).trim()+",");
message+=(rs2.getString(5).trim()+",");
message+=(rs2.getString(3).trim()+",");
message+=(rs2.getString(4).trim()+"#");
}
rs1.close();
rs2.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(message);
return message;
}
static public void addDoctorInfo(String account,String password,String name,String age,String sex,String depart){
String command1="insert into account values ('"+account+"','"+password+"','doctor')";
String command2="insert into doctor values('"+account+"','"+name+"','"+age+"','"+sex+"','"+depart+"',0,0,0)";
try {
st.execute(command1);
st.execute(command2);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void changeDoctorInfo(String account,String password,String name,String age,String sex,String depart){
String command1="update doctor set name='"+password+"' where account='"+account+"'";
String command2="update account set name='"+name+"',age='"+age+"',sex='"+sex+"',department='"+depart+"' where account='"+account+"'";
try {
st.execute(command1);
st.execute(command2);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public void deleteDoctorInfo(String account){
String command1="delete doctor where account='"+account+"'";
String command2="delete account where account='"+account+"'";
try {
st.execute(command1);
st.execute(command2);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public String sendDoctorInfoToPresident(){
String message="";
String command="select * from doctor";
try {
ResultSet rs=st.executeQuery(command);
while(rs.next()){
message+=(rs.getString(2).trim()+",");
message+=(rs.getString(5).trim()+",");
message+=((rs.getInt(7)/10)+",");
message+=(rs.getString(8).trim()+"#");
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(message);
return message;
}
static public String sendDepartmentInfoToPresident(){
String message1="";
String message2="";
String message3="";
String command="select * from departmentIncome";
try {
ResultSet rs=st.executeQuery(command);
while(rs.next()){
String depart=rs.getString(1).trim();
if(depart.equals("internal")){
message1+=((rs.getInt(2)/10)+",");
message1+=(rs.getString(4).trim());
}
else if(depart.equals("surgery")){
message2+=((rs.getInt(2)/10)+",");
message2+=(rs.getString(4).trim());
}
else if(depart.equals("paediatrics")){
message3+=((rs.getInt(2)/10)+",");
message3+=(rs.getString(4).trim());
}
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(message);
return (message1+"="+message2+"="+message3);
}
}