package set;
import java.awt.*;import java.awt.event.*;import java.util.*;import tools.*;import javax.swing.*;import java.awt.Rectangle;
public class fatherkindadd extends JDialog { private JLabel jLabel1 = new JLabel(); private JTextField txt_kindsID; private JTextField txt_kindsname = new JTextField(); private JLabel jLabel2 = new JLabel(); private JButton btnOK = new JButton(); private JButton btn_cancle = new JButton(); private DBConnection dcon = null;
public fatherkindadd(Frame owner, String title, boolean modal) { super(owner, title, modal); try { setDefaultCloseOperation(DISPOSE_ON_CLOSE); jbInit(); pack(); } catch (Exception exception) { exception.printStackTrace(); } }
public fatherkindadd() { this(new Frame(), "Dialog1", false); }
private void jbInit() throws Exception { txt_kindsID = new JTextField(getFatherKindsID()); this.getContentPane().setLayout(null); jLabel1.setFont(new java.awt.Font("Dialog", Font.BOLD, 13)); jLabel1.setText("科 目 ID"); jLabel1.setBounds(new Rectangle(29, 41, 61, 28)); txt_kindsname.setBounds(new Rectangle(84, 91, 71, 26)); jLabel2.setFont(new java.awt.Font("Dialog", Font.BOLD, 13)); jLabel2.setText("科目名称"); jLabel2.setBounds(new Rectangle(26, 88, 61, 28)); btnOK.setBounds(new Rectangle(19, 147, 62, 29)); btnOK.setText("确定"); this.getContentPane().add(jLabel2); btn_cancle.setBounds(new Rectangle(105, 147, 67, 30)); btn_cancle.setText("取消"); this.getContentPane().add(jLabel1); this.getContentPane().add(txt_kindsID); this.getContentPane().add(txt_kindsname); this.getContentPane().add(btnOK); this.getContentPane().add(btn_cancle); txt_kindsID.setEditable(false); txt_kindsID.setBounds(new Rectangle(84, 47, 71, 26)); btn_cancle.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closedialog(); } }); btnOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addfatherkind(); } }); }
//add private void addfatherkind() { if (txt_kindsname.getText().trim().length() == 0) { JOptionPane.showMessageDialog(this, "名称不能为空"); } else { dcon = new DBConnection(); String sql = "select * from FatherKind where fatherkind_name='" + txt_kindsname.getText().trim() + "'"; if (dcon.isNull(sql)) { JOptionPane.showMessageDialog(this, "该名称已经存在"); txt_kindsname.setText(""); } else { sql = "insert into FatherKind(fatherkind_id,fatherkind_name) values ('" + txt_kindsID.getText().trim() + "','" + txt_kindsname.getText().trim() + "')"; JOptionPane.showMessageDialog(this, dcon.update(3, sql)); this.dispose(); } } }
//close public void closedialog() { this.dispose(); }
//获取ID private String getFatherKindsID() { dcon = new DBConnection(); Vector v = dcon.select( "select fatherkind_id from FatherKind order by fatherkind_id asc"); if (v.size() == 0) { return "101"; } int autoID = 101; for (int i = 0; i < v.size(); i++) { String s = ((Vector) v.get(i)).get(0).toString(); int getID = Integer.parseInt(s); if (autoID != getID) { return String.valueOf(autoID); } autoID++; } return String.valueOf(v.size() + 1 + 100); }}