⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gonghuoshang.java

📁 基于Java的仓库信息管理系统。本系统主要完成对超市仓库的库存管理
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class GonghuoShang
{
	Frame frm;
	Label labInfo;
	Label labName;
	Label labInCharge;
	Label labBelongTo;
	Label labDanwei;
	Label labDanjia;
	Label labDepict;
	TextField t1;
	TextField t2;
	TextField t3;
	TextField t4;
	TextField t5;
	TextField t6;
	Button bt1;
	Button bt2;
	Button bt3;
	Button bt4;
	Button bt5;
	Statement s;
	ResultSet rs;
	int i=0;
	public GonghuoShang()
	{
		frm=new Frame("更新供货商信息");
		frm.setSize(480,450);
		frm.setLayout(null);
		frm.setBackground(new Color(210,210,210));
		labInfo=new Label("填入供货商名称点击确定将调出单位的相关信息",	Label.LEFT);
		labInfo.setSize(480,40);
		labInfo.setLocation(10,20);
	    labName=new Label("供货单位:");
	    labName.setSize(100,20);
	    labName.setLocation(100,73);
	    labInCharge=new Label("负责人:");
	    labInCharge.setLocation(100,114);
	    labInCharge.setSize(100,40);
	    labBelongTo=new Label("单位电话:");
	    labBelongTo.setLocation(100,164);
	    labBelongTo.setSize(100,40);
	    labDanwei=new Label("单位地址:");
	    labDanwei.setLocation(100,214);
	    labDanwei.setSize(100,40);
	    labDanjia=new Label("邮编:");
	    labDanjia.setLocation(100,264);
	    labDanjia.setSize(100,40);
	    labDepict=new Label("描述:");
	    labDepict.setLocation(100,314);
	    labDepict.setSize(100,40);
	    t1=new TextField();
	    t1.setLocation(200,80);
	    t1.setSize(200,20);
	    t2=new TextField();
	    t2.setLocation(200,130);
	    t2.setSize(200,20);
	    t3=new TextField();
	    t3.setLocation(200,180);
	    t3.setSize(200,20);
	    t4=new TextField();
	    t4.setLocation(200,230);
	    t4.setSize(200,20);
	    t5=new TextField();
	    t5.setLocation(200,280);
	    t5.setSize(200,20);
	    t6=new TextField();
	    t6.setLocation(200,330);
	    t6.setSize(200,20);
	    bt1=new Button("查找");
	    bt1.setBackground(new Color(210,210,210));
	    bt1.setSize(70,30);
	    bt1.setLocation(60,390);
	    bt2=new Button("增加");
	    bt2.setBackground(new Color(210,210,210));
	    bt2.setSize(70,30);
	    bt2.setLocation(130,390);
	    bt3=new Button("更新");
	    bt3.setBackground(new Color(210,210,210));
	    bt3.setSize(70,30);
	    bt3.setLocation(200,390);
	    bt4=new Button("删除");
	    bt4.setBackground(new Color(210,210,210));
	    bt4.setSize(70,30);
	    bt4.setLocation(270,390);
	    bt5=new Button("取消");
	    bt5.setBackground(new Color(210,210,210));
	    bt5.setSize(70,30);
	    bt5.setLocation(340,390);
	    frm.add(labInfo);
	    frm.add(labName);
	    frm.add(labInCharge);
	    frm.add(labBelongTo);
	    frm.add(labDanwei);
	    frm.add(labDanjia);
	    frm.add(labDepict);
	    frm.add(t1);
	    frm.add(t2);
	    frm.add(t3);
	    frm.add(t4);
	    frm.add(t5);
	    frm.add(t6);
	    frm.add(bt1);
	    frm.add(bt2);
	    frm.add(bt3);
	    frm.add(bt4);
	    frm.add(bt5);
	    frm.setResizable(false);
	    frm.setVisible(true);
	    frm.addWindowListener(new WinLis());
	    ActLis	actlis=new ActLis();
	    bt1.addActionListener(actlis);
	    bt2.addActionListener(actlis);
	    bt3.addActionListener(actlis);
	    bt4.addActionListener(actlis);
	    bt5.addActionListener(actlis);
	    bt2.enable(false);
	    bt3.enable(false);
	    bt4.enable(false);
	    bt5.enable(false);
	    
	}
	public class ActLis implements ActionListener
	{
		 public void actionPerformed(ActionEvent e)
		 {
		 //	String url="jdbc:odbc:mydatabase";
		 	String te1=t1.getText();
		 	String te2=t2.getText();
		 	String te3=t3.getText();
		 	String te4=t4.getText();
		 	String te5=t5.getText();
		 	String te6=t6.getText();
		 	Button btn=(Button)e.getSource();
		 //	Connection con;
		 	String sqlStr;
		 	if(t1.getText().equals(""))
		 	{
		 		JOptionPane.showMessageDialog(null,"名称不能为空");
		 	}
		 	else if(!t1.getText().equals(""))
		 	{
		 	
		 	if(btn==bt1)
		 	{
		 		try
		 		{
		 			
       	    String url="jdbc:odbc:Test";
       	    	System.out.print(1);	
       	    	        Connection con=DriverManager.getConnection(url);
       	    	       
	        s=con.createStatement
		     (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
		   // String s1="select * from gonghuoshang";
		 
	      ResultSet  rs=s.executeQuery("select * from gonghuodanwei");
	      
	         rs.first();
	    do{
	    	if(rs.getString(2).equals(t1.getText()))
	    	{
	    		System.out.print(1);
	    		t2.setText(rs.getString(3));
	    		t3.setText(rs.getString(4));
	    		t4.setText(rs.getString(5));
	    		t5.setText(rs.getString(6));
	    		t6.setText(rs.getString(7));
	    		i=1;
	    		t1.setEditable(false);
	    		bt3.enable(true);
	    		bt4.enable(true);
	    		bt5.enable(true);
	    	    break;
	    	}
	    }while(rs.next());
            if(i==0)
            {
            	JOptionPane.showMessageDialog(null,"没有找到该单位,请点击添加");
            	bt2.enable(true);
            	bt5.enable(true);
            }
		 		}
		 		catch(Exception sqle)
		 		{
		 			
		 		}
		 	}
		 	if(btn==bt2)
		 	{
		 		try
		 		{
		  String url="jdbc:odbc:Test";
	      Connection con=DriverManager.getConnection(url);
		  Statement  s=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
		  System.out.print(2);
		  String  sql1="insert into gonghuodanwei "
		    +"values('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"','"+t6.getText()+"')";
		 System.out.print(2);
		   s.executeUpdate(sql1);
          JOptionPane.showMessageDialog(null,"添加成功");
          		 	   t1.setText("");
		 	   t2.setText("");
		 	   t3.setText("");
		 	   t4.setText("");
		 	   t5.setText("");
		 	   t6.setText("");
                       
		 		}
		 		catch(Exception sqle)
		 		{
		 			System.out.println("code has error!");
		 		}
		 	}
		 	if(btn==bt3)
		 	{
		 		try
		 		{
		 		
		 		 String sq="update gonghuodanwei set fzr ='"+t2.getText()+"',dwdh='"+t3.getText()+"',dwdz='"+t4.getText()+"',dwyb='"+t5.getText()+"',ms='"+t6.getText()+"' where dwmc ='"+t1.getText()+"' ";
		 		  String url="jdbc:odbc:Test";
	      Connection con=DriverManager.getConnection(url);
		  Statement  s=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
		  s.executeUpdate(sq);
		 		 JOptionPane.showMessageDialog(null,"更新成功");
		 		 		 	   t1.setText("");
		 	   t2.setText("");
		 	   t3.setText("");
		 	   t4.setText("");
		 	   t5.setText("");
		 	   t6.setText("");
		 		 }
		 		catch(Exception sqle)
		 		{
		 			System.out.println("code has error!");
		 		}	
		 	}
		 	if(btn==bt4)
		 	{
		 		try
		 		{
		 			 String url="jdbc:odbc:Test";
	      Connection con=DriverManager.getConnection(url);
		  Statement  s=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
            String sqq="delete from gonghuodanwei where dwmc='"+t1.getText()+"'";
            s.executeUpdate(sqq);
            JOptionPane.showMessageDialog(null,"删除成功");
               t1.setEditable(true);
		 	   t1.setText("");
		 	   t2.setText("");
		 	   t3.setText("");
		 	   t4.setText("");
		 	   t5.setText("");
		 	   t6.setText("");

		 		}
		 		catch(Exception sqle)
		 		{
		 			System.out.println("code has error!");
		 		}	
		 	}
		 	if(btn==bt5)
		 	{	
		 	   t1.setEditable(true);
		 	   t1.setText("");
		 	   t2.setText("");
		 	   t3.setText("");
		 	   t4.setText("");
		 	   t5.setText("");
		 	   t6.setText("");


		 	}
		 	}
		 }

	}
	//测试
//	public static void main(String[] argv)
//	{
//		new GonghuoShang();
//	}
	public class WinLis extends WindowAdapter
   	{
   		public void windowClosing(WindowEvent e)
   		{
   			frm.dispose();
   		}
   	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -