forked from uboger/LibraryManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReaderDelete.java
159 lines (155 loc) · 4.46 KB
/
ReaderDelete.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
//ReaderDelete.java;
import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class ReaderDelete extends Frame{
Toolkit tool= getToolkit();
String url="bookbk.png";
Image img=tool.getImage(url);
public void paint(Graphics g){
g.drawImage(img,0,0,this);
}
String[] labelsign={"读者编号","读者姓名","读者类别","读者性别","可借数量","可借天数"};
Label[] readerlb=new Label[6];
Label idlb=new Label(labelsign[0]);
TextField idtxt=new TextField();
static TextField[] readertxt=new TextField[6];
Button querybtn,closebtn,updatebtn;
static Choice readertype,readersex;
public ReaderDelete(){
setLayout(null);
setSize(500,250);setResizable(false);
setTitle("读者信息删除");
querybtn=new Button("查询");
idlb.setBounds(90,40,50,20);
idtxt.setBounds(150,40,100,20);
querybtn.setBounds(280,40,50,20);
add(idlb);add(idtxt);add(querybtn);
int lx=50,ly=80;
for(int i=0;i<readertxt.length;i++){
if(lx>240){
ly=ly+30;
lx=50;
}
readerlb[i]=new Label(labelsign[i]);
readertxt[i]=new TextField();
readerlb[i].setBounds(lx,ly,50,20);
readertxt[i].setBounds(lx+60,ly,100,20);
lx=lx+190;
add(readerlb[i]);
add(readertxt[i]);readertxt[i].setEditable(false);
}
readertxt[0].setEditable(false);
readertype=new Choice();
readertype.add("教师");
readertype.add("学生");
readertype.add("作家");
readertype.add("职工");
readertype.add("其他");
readersex=new Choice();
readersex.add("男");
readersex.add("女");
readertxt[2].setVisible(false);
readertxt[3].setVisible(false);
readertype.setBounds(110,110,100,20);
readersex.setBounds(300,110,100,20);
add(readertype);add(readersex);
closebtn=new Button("关闭");
updatebtn=new Button("删除");
updatebtn.setBounds(130,190,50,20);
closebtn.setBounds(310,190,50,20);
add(updatebtn);add(closebtn);
querybtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
queryActionPerformed(e);
}
});
updatebtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
updateActionPerformed(e);
clearAllTextField();
}
});
closebtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
DbOp.close();
dispose();
//System.exit(0);
}
});
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
DbOp.close();
dispose();
//System.exit(0);
}
});
setLocationRelativeTo(null);
setVisible(true);
}
public static void updateActionPerformed(ActionEvent e){
String id=readertxt[0].getText(),readername=readertxt[1].getText(),readetype=readertype.getSelectedItem().toString();
String sex=readersex.getSelectedItem().toString();
if(id.equals("")){
JOptionPane.showMessageDialog(null,"读者编号不为空,如已输入读者编号,请点击“查询”");
return;
}
try{
int max_num=Integer.parseInt(readertxt[4].getText()),days_num=Integer.parseInt(readertxt[5].getText());
String sql= "delete * from reader where id='"+id+"'";
int b=DbOp.executeUpdate(sql);
if(b==1){
JOptionPane.showMessageDialog(null,"删除读者信息成功");
}else{
JOptionPane.showMessageDialog(null,"读者信息删除失败");
}
}catch(NumberFormatException e2){
JOptionPane.showMessageDialog(null,"可借数量和可借天数输入错误");
}
}
public void queryActionPerformed(ActionEvent e){
String id=idtxt.getText();
if(id.equals("")){
JOptionPane.showMessageDialog(null,"读者编号不为空");
return;
}
if(IfReaderExit(id)){
Reader reader=ReaderSelect.SelectReaderByID(id);
String[] newreader=reader.getReaderInformation();
if(reader!=null){
System.out.println(reader.getReaderSex());
readersex.select(reader.getReaderSex());
readertype.select(reader.getReadertype());
for(int i=0;i<readertxt.length;i++){
readertxt[i].setText(newreader[i]);
}
}
}else{
JOptionPane.showMessageDialog(null,"不存在该读者");
}
}
public static boolean IfReaderExit(String id){
String sql="select * from reader where id='"+id+"'";
try{
ResultSet rs=DbOp.executeQuery(sql);
if(rs.next()){
return true;
}else{
return false;
}
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"查询数据错误");
}
return false;
}
public void clearAllTextField(){
for(int j=0;j<readertxt.length;j++){
readertxt[j].setText("");
}
}
public static void main(String[] args){
new ReaderDelete();
}
}