您的位置:首页 > 数据库

数据库课程设计_实验室管理系统_设备入库

2013-07-30 11:30 627 查看
package labor;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class EquIn_Labor  extends JFrame{
    private JLabel equType=new JLabel("类别:");
    private JTextField typeEqu=new  JTextField(10);
    private JLabel equName=new JLabel("设备名:");
    private JTextField nameEqu=new  JTextField(10);
    private JLabel equModel=new JLabel("型号:");
    private JTextField modelEqu=new  JTextField(10);
    private JLabel equSpec=new JLabel("规格:");
    private JTextField specEqu=new  JTextField(10);
    private JLabel equMoney=new JLabel("单价:");
    private JTextField moneyEqu=new  JTextField(10);
    private JLabel equAmount=new JLabel("数量:");
    private JTextField amountEqu=new  JTextField(10);
    private JLabel equCondition=new JLabel("运行状况:");
    private JTextField conditionEqu=new  JTextField(10);
    private JLabel equManufacturer=new JLabel("生产厂家:");
    private JTextField manufacturerEqu=new  JTextField(10);
    private JLabel equBuyer=new JLabel("购买人:");
    private JTextField buyerEqu=new  JTextField(10);
    private JLabel equBuydate=new JLabel("购买日期:");
    private JTextField buydateEqu=new  JTextField(10);
    private JLabel equTime=new JLabel("购买批次:");
    private JTextField timeEqu=new  JTextField(10);
    private JLabel equRname=new JLabel("机房名:");
    private JTextField rnameEqu=new  JTextField(10);
	private JButton insert=new JButton("入库 ");
	private JButton back=new JButton("返回");
	private JTextArea jta_In=new JTextArea(" ",200,50);
	private Container c=this.getContentPane();
    public EquIn_Labor() {
		super("设备入库管理");
		init();
	}

	private void init(){
		JPanel jp=new JPanel();
		JPanel jp1=new JPanel();
		jp1.setLayout(new GridLayout(12,2));
		jp1.add(equType);jp1.add(typeEqu);
		jp1.add(equName);jp1.add(nameEqu);
		jp1.add(equModel);jp1.add(modelEqu);
		jp1.add(equSpec);jp1.add(specEqu);
		jp1.add(equMoney);jp1.add(moneyEqu);
		jp1.add(equAmount);jp1.add(amountEqu);
		jp1.add(equCondition);jp1.add(conditionEqu);
		jp1.add(equManufacturer);jp1.add(manufacturerEqu);
		jp1.add(equBuyer);jp1.add(buyerEqu);
		jp1.add(equBuydate);jp1.add(buydateEqu);
		jp1.add(equTime);jp1.add(timeEqu);
		jp1.add(equRname);jp1.add(rnameEqu);
		
		JPanel jp2=new JPanel();
		jp2.add(insert);jp2.add(back);
		jp.add(jp1);jp.add(jp2);    
		c.add(jp,BorderLayout.NORTH);
		c.add(jta_In,BorderLayout.CENTER);
		insert.addActionListener(new ActionListener(){
			
			public void actionPerformed(ActionEvent e) {
				String aa[]={"类别"," 设备名"," 型号"," 规格"," 单价"," 数量"," 运行状况"," 生产厂家"," 购买人"," 购买日期"," 购买批次"," 机房名"};
				for(int i=0;i<6;i++){
					jta_In.append(aa[i]+"\t");
				}
				jta_In.append("\n");
				
				DBConnection db=new DBConnection();
				String sqlInsert="insert into equCondition(Etype,Ename,Emodel,Espec,Echarge, Eamount,Econdition, Emanufacturer,Ebuyer,Ebuydate,Etime,Rname ) values(?,?,?,?,?,?,?,?,?,?,?,?) ";
				try {
					PreparedStatement pst=db.conn.prepareStatement(sqlInsert,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);							
					jta_In.append(typeEqu.getText()+"\t");
					jta_In.append(nameEqu.getText()+"\t");
					jta_In.append(modelEqu.getText()+"\t");
					jta_In.append(specEqu.getText()+"\t");
					jta_In.append(moneyEqu.getText()+"\t");	
					jta_In.append(amountEqu.getText()+"\t");
					jta_In.append("\n");
					for(int i=6;i<aa.length;i++){
						jta_In.append(aa[i]+"\t");
					}
					jta_In.append("\n");
					jta_In.append(conditionEqu.getText()+"\t");	
					jta_In.append(manufacturerEqu.getText()+"\t");	
					jta_In.append(buyerEqu.getText()+"\t");
					jta_In.append(buydateEqu.getText()+"\t");
					jta_In.append(timeEqu.getText()+"\t");
					jta_In.append(rnameEqu.getText()+"\n");
					pst.setString(1, typeEqu.getText());
					pst.setString(2, nameEqu.getText());
					pst.setString(3, modelEqu.getText());
					pst.setString(4, specEqu.getText());
					pst.setString(5, moneyEqu.getText());
					pst.setString(6, amountEqu.getText());
					pst.setString(7, conditionEqu.getText());
					pst.setString(8, manufacturerEqu.getText());
					pst.setString(9, buyerEqu.getText());
					pst.setString(10, buydateEqu.getText());
					pst.setString(11, timeEqu.getText());
					pst.setString(12, rnameEqu.getText());
					
					pst.executeUpdate();
					JOptionPane.showMessageDialog(null, "操作成功!");
					typeEqu.setText(null);nameEqu.setText(null);modelEqu.setText(null);
					specEqu.setText(null);moneyEqu.setText(null);amountEqu.setText(null);
					manufacturerEqu.setText(null);buyerEqu.setText(null);conditionEqu.setText(null);
					buydateEqu.setText(null);timeEqu.setText(null);rnameEqu.setText(null);
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
			
		});
        back.addActionListener(new ActionListener(){
			
			public void actionPerformed(ActionEvent e) {
				hide_me();
				Mana_Labor ul=new Mana_Labor();
	
			}
			
		});
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setSize(500,400);
		this.setVisible(true);
	}
	public void hide_me(){
		   this.setVisible(false);
	}
	/*public static void main(String args[]){
		EquIn_Labor sl=new EquIn_Labor();
	}*/

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: