订单管理系统代码 是课程设计的数据库的import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.sql.*; public class addO extends JInternalFrame { private JButton butCancel,butOk; private JLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5; private JTextField jtf1,jtf4,jtf5; private JComboBox jcb2,jcb3; public addO() {//空构造 super("添加订单"); initComponents(); this.setVisible(true); this.setClosable(true); this.setSize(260,310); } private void initComponents() { //实例化并添加控件 jLabel1 = new JLabel(); jLabel2 = new JLabel(); jLabel2 = new JLabel(); jLabel3 = new JLabel(); jLabel4 = new JLabel(); jLabel5 = new JLabel(); jtf1=new JTextField(); jcb2= new JComboBox(); jcb3= new JComboBox(); jtf4=new JTextField(); jtf5=new JTextField(); butOk = new JButton(); butCancel = new JButton(); //实例化并添加控件完成 getContentPane().setLayout(null);//设置布局 //为空间放置具体位置 jLabel1.setText("订单号"); getContentPane().add(jLabel1); jLabel1.setBounds(30, 30, 70, 20); jLabel2.setText("商品"); getContentPane().add(jLabel2); jLabel2.setBounds(30, 60, 70, 20); jLabel3.setText("客户"); getContentPane().add(jLabel3); jLabel3.setBounds(30, 90, 60, 20); jLabel4.setText("数量"); getContentPane().add(jLabel4); jLabel4.setBounds(30, 120, 70, 20); jLabel5.setText("总金额"); getContentPane().add(jLabel5); jLabel5.setBounds(30, 150, 70, 20); getContentPane().add(jtf1); jtf1.setBounds(100, 30, 130, 24); getContentPane().add(jcb2); jcb2.setBounds(100, 60, 130, 24); getContentPane().add(jcb3); jcb3.setBounds(100, 90, 130, 24); getContentPane().add(jtf4); jtf4.setBounds(100, 120, 130, 24); getContentPane().add(jtf5); jtf5.setBounds(100, 150, 130, 24); butOk.setText("添加"); getContentPane().add(butOk); butOk.setBounds(80, 240, 70, 27); butCancel.setText("取消"); getContentPane().add(butCancel); butCancel.setBounds(160, 240, 70, 27); //为空间放置具体位置结束 //将所有商品号和客户代号读出来 database.joinDB(); String sql="select 商品号 from goods"; String sql2="select 客户代号 from client"; try{ if(database.query(sql)){ while(database.rs.next()){ String name=database.rs.getString("商品号"); jcb2.addItem(name); } } if(database.query(sql2)){ while(database.rs.next()){ String name=database.rs.getString("客户代号"); jcb3.addItem(name); } } } catch(Exception ea){} //为添加和取消按钮加事件 butOk.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String name2="" + jcb2.getSelectedItem(); String name3="" + jcb3.getSelectedItem(); if(jtf1.getText().equals("")){ new JOptionPane().showMessageDialog(null,"订单号不能为空"); } else if(name2.equals("")){ new JOptionPane().showMessageDialog(null,"商品不能为空"); } else if(name3.equals("")){ new JOptionPane().showMessageDialog(null,"客户不能为空"); } else { String sql="insert into orders values('"+ jtf1.getText()+"','"+name2+"','"+name3+"','"+ jtf4.getText()+"','"+ jtf5.getText()+"')"; try{ if(database.executeSQL(sql)){ new JOptionPane().showMessageDialog(null,"添加成功!"); } } catch(Exception ea){} } } }); butCancel.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ } }); } } {//空构造 super("添加订单"); initComponents(); this.setVisible(true); this.setClosable(true); this.setSize(260,310); } private void initComponents() { //实例化并添加控件 jLabel1 = new JLabel(); jLabel2 = new JLabel(); jLabel2 = new JLabel(); jLabel3 = new JLabel(); jLabel4 = new JLabel(); jLabel5 = new JLabel(); jtf1=new JTextField(); jcb2= new JComboBox(); jcb3= new JComboBox(); jtf4=new JTextField(); jtf5=new JTextField(); butOk = new JButton(); butCancel = new JButton(); //实例化并添加控件完成 getContentPane().setLayout(null);//设置布局 //为空间放置具体位置 jLabel1.setText("订单号"); getContentPane().add(jLabel1); jLabel1.setBounds(30, 30, 70, 20); jLabel2.setText("商品"); getContentPane().add(jLabel2); jLabel2.setBounds(30, 60, 70, 20); jLabel3.setText("客户"); getContentPane().add(jLabel3); jLabel3.setBounds(30, 90, 60, 20); jLabel4.setText("数量"); getContentPane().add(jLabel4); jLabel4.setBounds(30, 120, 70, 20); jLabel5.setText("总金额"); getContentPane().add(jLabel5); jLabel5.setBounds(30, 150, 70, 20); getContentPane().add(jtf1); jtf1.setBounds(100, 30, 130, 24); getContentPane().add(jcb2); jcb2.setBounds(100, 60, 130, 24); getContentPane().add(jcb3); jcb3.setBounds(100, 90, 130, 24); getContentPane().add(jtf4); jtf4.setBounds(100, 120, 130, 24); getContentPane().add(jtf5); jtf5.setBounds(100, 150, 130, 24); butOk.setText("添加"); getContentPane().add(butOk); butOk.setBounds(80, 240, 70, 27); butCancel.setText("取消"); getContentPane().add(butCancel); butCancel.setBounds(160, 240, 70, 27); //为空间放置具体位置结束 //将所有商品号和客户代号读出来 database.joinDB(); String sql="select 商品号 from goods"; String sql2="select 客户代号 from client"; try{ if(database.query(sql)){ while(database.rs.next()){ String name=database.rs.getString("商品号"); jcb2.addItem(name); } } if(database.query(sql2)){ while(database.rs.next()){ String name=database.rs.getString("客户代号"); jcb3.addItem(name); } } } catch(Exception ea){} //为添加和取消按钮加事件 butOk.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String name2="" + jcb2.getSelectedItem(); String name3="" + jcb3.getSelectedItem(); if(jtf1.getText().equals("")){ new JOptionPane().showMessageDialog(null,"订单号不能为空"); } else if(name2.equals("")){ new JOptionPane().showMessageDialog(null,"商品不能为空"); } else if(name3.equals("")){ new JOptionPane().showMessageDialog(null,"客户不能为空"); } else { String sql="insert into orders values('"+ jtf1.getText()+"','"+name2+"','"+name3+"','"+ jtf4.getText()+"','"+ jtf5.getText()+"')"; try{ if(database.executeSQL(sql)){ new JOptionPane().showMessageDialog(null,"添加成功!"); } } catch(Exception ea){} } } }); butCancel.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ } }); } }