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

📄 denglu.java

📁 商品销售界面的实现,包括商品和员工等 用ODBC连接SQL数据库实现,
💻 JAVA
字号:
import java.io.*;
import java.sql.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
class ConnectDataBase extends Frame implements ActionListener
{
	Button b1,b2,b3,b4,b5,b6,b7;
	TextArea t1;
	Dialog	my;
	TextField T1,T2,T3,T4,T5,T6,T7,T8;
	Label L1,L2,L3,L4,L5,L6,L7;
	/*public static void driver()
	{
		try
	    {
		  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	    }
        catch(java.lang.ClassNotFoundException a)
        {
    	  System.out.println(a.getMessage());  
        }
	}*/
	public ConnectDataBase()
	{
		super("商品销售管理系统");
		b1=new Button("商品管理");
		b2=new Button("商品销售登记");
		b3=new Button("商品订货计划");
		b4=new Button("商品入库管理");
		b5=new Button("商品出库管理");
		b6=new Button("员工管理");
		b7 = new Button("退出");
		t1=new TextArea("查询结果为:",10,50);
		setLayout(new FlowLayout());
		add(t1);
	    add(b1);
	    b1.addActionListener(this);
	    add(b2);
	    b2.addActionListener(this);
        addWindowListener(new closeWin());
    }
     public void actionPerformed(ActionEvent e)
        {	
         b1.addActionListener(new ActionListener()
         {
         	public void actionPerformed(ActionEvent e)
         	{
         	try
	        {
		      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	        }
            catch(java.lang.ClassNotFoundException a)
            {
    	       t1.append(a.getMessage());  
            }
		 	String url="jdbc:odbc:goods";
		    String sql="SELECT * FROM Spname WHERE Shno!=0";
            try
             {
    	        Connection con=DriverManager.getConnection(url,"u1","123456");
    	        Statement stmt=con.createStatement();	
                ResultSet rs=stmt.executeQuery(sql);
    	        while(rs.next())
    	         {
    	  	        String s1=rs.getString("Shno");//货号
    	  	        String s2=rs.getString("Spname");//品名
					String s3= rs.getString("Stype");//规格
					String s4 = rs.getString("Sprice");//单价
					int p=rs.getInt("Rjprice");//进价
    	 	        int s=rs.getInt("Rcprice");//售价
    	  	        t1.append("货号:"+s1+"\n");
    	  	        t1.append("品名"+s2+"\n");
					t1.append("规格" + s3 + "\n");
					t1.append("品名" + s4+ "\n");
					t1.append("进价:"+p+"\n");
    	  	        t1.append("售价:"+s+"\n");
    	  	    }
                stmt.close();
                con.close();
             }
             catch(SQLException ex)
              { 
                t1.append(ex.getMessage());
              }
              }
         });
          b2.addActionListener(new ActionListener()
         {
         	public void actionPerformed(ActionEvent e)
         	{
          	L1=new Label("编号");
   		    L2=new Label("货号");
    		L3=new Label("工号");
			L4=new Label("数量");
			L5=new Label("销售日期");
			L6=new Label("客户名");
			T1=new TextField(20);
			T2=new TextField(20);
			T3=new TextField(20);
			T4=new TextField(20);
			T5=new TextField(20);
			T6=new TextField(15);
		    my=new Dialog(ConnectDataBase.this,"商品销售登记",true);
     		my.setLayout(new FlowLayout());
     		my.add(L1);my.add(T1);
     		my.add(L2);my.add(T2);
     		my.add(L3);my.add(T3);
     		my.add(L4);my.add(T4);
     		my.add(L5);my.add(T5);
     		my.add(L6);my.add(T6);
     		my.add(b2);my.add(b7);
     		my.setSize(250,300);
     		my.setVisible(true);
          }
          });
		  b3.addActionListener(new ActionListener()
         {
         	public void actionPerformed(ActionEvent e)
         	{
          	L1=new Label("货号");
   		    L2=new Label("品名");
    		L3=new Label("规格");
			L4=new Label("单价");
			L5=new Label("数量");
			T1=new TextField(20);
			T2=new TextField(20);
			T3=new TextField(20);
			T4=new TextField(20);
			T5=new TextField(20);
		    my=new Dialog(ConnectDataBase.this,"商品订货计划",true);
     		my.setLayout(new FlowLayout());
     		my.add(L1);my.add(T1);
     		my.add(L2);my.add(T2);
     		my.add(L3);my.add(T3);
     		my.add(L4);my.add(T4);
     		my.add(L5);my.add(T5);
     		my.setSize(250,300);
     		my.setVisible(true);
          }
          });
		  b4.addActionListener(new ActionListener()
         {
         	public void actionPerformed(ActionEvent e)
         	{
          	L1=new Label("货号");
   		    L2=new Label("进价");
    		L3=new Label("售价");
			L4=new Label("库存量");
			L5=new Label("最低库存");
			L6=new Label("订货量");
			T1=new TextField(20);
			T2=new TextField(20);
			T3=new TextField(20);
			T4=new TextField(20);
			T5=new TextField(20);
			T6=new TextField(15);
		    my=new Dialog(ConnectDataBase.this,"商品库存",true);
     		my.setLayout(new FlowLayout());
     		my.add(L1);my.add(T1);
     		my.add(L2);my.add(T2);
     		my.add(L3);my.add(T3);
     		my.add(L4);my.add(T4);
     		my.add(L5);my.add(T5);
     		my.add(L6);my.add(T6);
     		my.setSize(250,300);
     		my.setVisible(true);
          }
          });
		  b5.addActionListener(new ActionListener()
         {
         	public void actionPerformed(ActionEvent e)
         	{
          	L1=new Label("编号");
   		    L2=new Label("货号");
			L3=new Label("数量");
			T1=new TextField(20);
			T2=new TextField(20);
			T3=new TextField(20);
		    my=new Dialog(ConnectDataBase.this,"商品出库",true);
     		my.setLayout(new FlowLayout());
     		my.add(L1);my.add(T1);
     		my.add(L2);my.add(T2);
     		my.add(L3);my.add(T3);
     		my.setSize(250,300);
     		my.setVisible(true);
          }
          });
		  b6.addActionListener(new ActionListener()
         {
         	public void actionPerformed(ActionEvent e)
         	{
          	L1=new Label("工号");
   		    L2=new Label("姓名");
    		L3=new Label("地址");
			L4=new Label("电话");
			L5=new Label("出生日期");
			L6=new Label("起聘日期");
			L7=new Label("基本工资");
			T1=new TextField(20);
			T2=new TextField(20);
			T3=new TextField(20);
			T4=new TextField(20);
			T5=new TextField(20);
			T6=new TextField(15);
            T7=new TextField(15);
		    my=new Dialog(ConnectDataBase.this,"员工管理",true);
     		my.setLayout(new FlowLayout());
     		my.add(L1);my.add(T1);
     		my.add(L2);my.add(T2);
     		my.add(L3);my.add(T3);
     		my.add(L4);my.add(T4);
     		my.add(L5);my.add(T5);
     		my.add(L6);my.add(T6);
			my.add(L7);my.add(T7);
     		my.setSize(250,300);
     		my.setVisible(true);
          }
          });
           b2.addActionListener(new ActionListener()
         {
         	public void actionPerformed(ActionEvent e)
         	{
     			try
	            {
		          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	            }
                catch(java.lang.ClassNotFoundException a)
                {
    	          System.out.println(a.getMessage());  
                }
     			String url="jdbc:odbc:liu";
		        String sql1="INSERT INTO goods VALUES('"+T1.getText()+"','"+T2.getText()+"','"+T3.getText()+"','"+T4.getText()+"',"+Integer.parseInt(T5.getText())+")";
		  	    String sql2="INSERT INTO goods VALUES('"+T1.getText()+"','"+T6.getText()+"',"+T7.getText()+","+null+")";
		  	    try
                {
                  
    	          Connection con=DriverManager.getConnection(url,"u1","123456");
    	          Statement stmt=con.createStatement();	
                  stmt.executeUpdate(sql1);
                  stmt.executeUpdate(sql2);
                  stmt.close();
                  con.close();
                }
                catch(SQLException ex)
                { 
                  t1.append(ex.getMessage()+"\n");
                }
     			}
     		});
     	 b7.addActionListener(new ActionListener()
          {
         	public void actionPerformed(ActionEvent e)
         	{
     	    	my.dispose();
     	    }
     	 });
	  }
	
}

class closeWin extends WindowAdapter
{
	public void windowClosing(WindowEvent e)
	{
		Window w=e.getWindow();
		w.dispose();
	}
}

public class denglu extends Frame implements ActionListener
{
	Label L1,L2,L3;
	TextField T1,T2;
	Button b1,b2;
	boolean f=false;
	Dialog errorDialog;
	public denglu()
	{
		super("登录对话框");
		L1=new Label("用户名:");
		L2=new Label("密码");
		L3=new Label("该用户不存在!您没有授权!");
        b2=new Button("确定");
		T1=new TextField(20);
		T2=new TextField(20);
		T2.setEchoChar('*');
		b1=new Button("登录");
		setLayout(new FlowLayout());
		add(L1);add(T1);
		add(L2);add(T2);
		add(b1);
		b1.addActionListener(this);
        addWindowListener(new closeWin());
     }
   public void actionPerformed(ActionEvent e)
    {
	  b1.addActionListener(new ActionListener()
	  {
		public void actionPerformed(ActionEvent e)
		{
			String t1,t2;
			t1=T1.getText();
			t2=T2.getText();
			 try
	            {
		          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	            }
                catch(java.lang.ClassNotFoundException a)
                {
    	          System.out.println(a.getMessage());  
                }
             String url="jdbc:odbc:goods";
             String sql="SELECT * FROM SQLUser";
             try
             {
    	        Connection con=DriverManager.getConnection(url,t1,t2);
    	        Statement stmt=con.createStatement();
    	        f=true;
    	     }
    	     catch(SQLException ex)
              { 
                f=false;
                System.out.println(ex.getMessage());
              }
             if(f)
             {
             	ConnectDataBase c=new ConnectDataBase();
                c.setSize(400,350);
                c.setVisible(true);
             }
             else
             {
             	errorDialog=new Dialog(denglu.this,"用户不存在",true);
             	errorDialog.setLayout(new FlowLayout());
             	errorDialog.add(L3);
             	errorDialog.add(b2);
             	errorDialog.setSize(200,200);
             	errorDialog.setVisible(true);
             }
		}
	});
	b2.addActionListener(new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			errorDialog.dispose();
		}
    });	
	}
	public static void main(String args[])
	{
	    denglu d=new denglu();
	    d.setSize(200,200);
		d.setVisible(true);
	}
	
}

⌨️ 快捷键说明

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