📄 updatescoreinfo.java
字号:
package com.Update;
import com.MainFrame;
import com.component.MyFrame;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
/**
* @author Laiger
*/
public class UpdateScoreInfo extends MyFrame implements ActionListener {
private JLabel jLabel1 = null;
private JComboBox jComboBox1 = null;
private JTextField t1 = null;
private JLabel jLabel2 = null;
private JComboBox jComboBox2 = null;
private JLabel jLabel3 = null;
private JTextField t2 = null;
private JLabel jLabel4 = null;
private JTextField t3 = null;
private JButton ok = null;
private JButton cancel = null;
/**
* This method initializes
*
*/
public UpdateScoreInfo(MainFrame m) {
super(m);
initialize();
}
public UpdateScoreInfo() {
super();
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(16, 175, 72, 33));
jLabel4.setText("得 分");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(18, 127, 71, 32));
jLabel3.setText("成 绩");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(19, 80, 67, 29));
jLabel2.setText("项 目 号");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(19, 38, 66, 29));
jLabel1.setText("运动员代号");
this.setSize(new Dimension(415, 269));
this.setTitle("成绩录入");
this.add(jLabel1, null);
this.add(getT1(), null);
this.add(getJComboBox1(), null);
this.add(jLabel2, null);
this.add(getJComboBox2(), null);
this.add(jLabel3, null);
this.add(getT2(), null);
this.add(jLabel4, null);
this.add(getT3(), null);
this.add(getOk(), null);
this.add(getCancel(), null);
}
/**
* @return the jComboBox1
* @uml.property name="jComboBox1"
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox();
jComboBox1.setBounds(new Rectangle(101, 40, 133, 27));
String sql="select * from athlete";
ResultSet rs=db.executeQuery(sql);
try {
if(rs.next()){
jComboBox1.addItem(rs.getString("Id").trim());
//t1.setText(rs.getString("name"));
}
while(rs.next()){
jComboBox1.addItem(rs.getString("Id").trim());
}
} catch (SQLException e) {
e.printStackTrace();
}
jComboBox1.setSelectedIndex(-1);
jComboBox1.addActionListener(this);
}
return jComboBox1;
}
/**
* @return the t1
* @uml.property name="t1"
*/
private JTextField getT1() {
if (t1 == null) {
t1 = new JTextField();
t1.setBounds(new Rectangle(268, 40, 127, 26));
t1.setEditable(false);
}
return t1;
}
/**
* @return the jComboBox2
* @uml.property name="jComboBox2"
*/
private JComboBox getJComboBox2() {
if (jComboBox2 == null) {
jComboBox2 = new JComboBox();
jComboBox2.setBounds(new Rectangle(100, 80, 132, 30));
String sql="select * from project";
ResultSet rs=db.executeQuery(sql);
try {
while(rs.next()){
jComboBox2.addItem(rs.getString("id").trim());
}
} catch (SQLException e) {
e.printStackTrace();
}
}
jComboBox2.setSelectedIndex(-1);
jComboBox2.addActionListener(this);
return jComboBox2;
}
/**
* This method initializes t2
* @return javax.swing.JTextField
* @uml.property name="t2"
*/
private JTextField getT2() {
if (t2 == null) {
t2 = new JTextField();
t2.setBounds(new Rectangle(101, 128, 184, 32));
}
return t2;
}
/**
* This method initializes t3
* @return javax.swing.JTextField
* @uml.property name="t3"
*/
private JTextField getT3() {
if (t3 == null) {
t3 = new JTextField();
t3.setBounds(new Rectangle(102, 176, 182, 33));
}
return t3;
}
/**
* This method initializes ok
* @return javax.swing.JButton
* @uml.property name="ok"
*/
private JButton getOk() {
if (ok == null) {
ok = new JButton();
ok.setBounds(new Rectangle(49, 233, 107, 31));
ok.setText("确定");
ok.addActionListener(this);
}
return ok;
}
/**
* This method initializes cancel
* @return javax.swing.JButton
* @uml.property name="cancel"
*/
private JButton getCancel() {
if (cancel == null) {
cancel = new JButton();
cancel.setBounds(new Rectangle(283, 232, 103, 31));
cancel.setText("退出");
cancel.addActionListener(this);
}
return cancel;
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jComboBox1){
String sql="select * from athlete where id='"+jComboBox1.getSelectedItem().toString().trim()+"'";
ResultSet rs=db.executeQuery(sql);
try {
if(rs.next()){
t1.setText(rs.getString("name"));
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
else if(e.getSource()==ok){
String s2=t2.getText().toString().trim();
String s3=t3.getText().toString().trim();
if(s2.equals("")||s3.equals("")){
JOptionPane.showMessageDialog(this,"成绩或得分不能为空!");
return;
}
String sql="select * from project where id='"+jComboBox2.getSelectedItem().toString().trim()+"'";
ResultSet rs=db.executeQuery(sql);
String proID="";
float record=0.0f;
String athleteID=jComboBox1.getSelectedItem().toString().trim();
try {
if(rs.next()){
proID=rs.getString("id");
record=rs.getFloat("record");
sql="select * from achievement where athleteID='"+athleteID+"' and ProjectId='"+proID+"'";
rs=db.executeQuery(sql);
if(!rs.next()){
JOptionPane.showMessageDialog(this,"该运动员的成绩还没有录入录入!");
}
else{
sql="update achievement set achievement="+s2+",score="+s3+" where athleteId="+athleteID+" and projectid='"+proID+"'";
if(db.executeUpdate(sql)){
if(Float.parseFloat(s2)>record){
sql="update project set record="+s2+",recorder='"+t1.getText()+"' where id='"+proID+"'";
if(db.executeUpdate(sql))
JOptionPane.showMessageDialog(this,"成绩录入成功,恭喜!已经打破一项新的记录!");
}
else
JOptionPane.showMessageDialog(this,"成绩录入成功!");
}
else{
JOptionPane.showMessageDialog(this,"录入失败,请检查数据的格式!");
}
}
}
} catch (SQLException e1) {
}
}
else if(e.getSource()==cancel){
db.close();
if(m!=null)
m.setVisible(true);
dispose();
}
else{
String athleteID=jComboBox1.getSelectedItem().toString().trim();
String proID=jComboBox2.getSelectedItem().toString().trim();
String sql="select * from achievement where athleteID='"+athleteID+"' and ProjectId='"+proID+"'";
ResultSet rs=db.executeQuery(sql);
try {
if(rs.next()){
t2.setText(rs.getString("achievement"));
t3.setText(rs.getString("score"));
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
} // @jve:decl-index=0:visual-constraint="247,14"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -