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

📄 frmxiaoshou.java~39~

📁 在学校时做的第一个项目
💻 JAVA~39~
字号:
package vegtable;

import java.awt.*;

import javax.swing.*;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.BorderFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.util.Calendar;

/**
 * <p>Title: vegtable</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Frmxiaoshou extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    JLabel lblname = new JLabel();
    JTextField txtname = new JTextField();
    JLabel lblprice = new JLabel();
    JTextField txtprice = new JTextField();
    JLabel lblnum = new JLabel();
    JTextField txtnum = new JTextField();
    JLabel lbldw = new JLabel();
    JComboBox cbodw = new JComboBox();
    JButton tbnadd = new JButton();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    JOptionPane jOptionPane1 = new JOptionPane();
    JPanel jPanel1 = new JPanel();
    JButton btndelete = new JButton();
    JButton btnjianshao = new JButton();
    JLabel lbljg = new JLabel();
    public Frmxiaoshou() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        this.setSize(500,500);
        this.setLocation(200,20);
        this.setTitle("销售信息管理界面");
        lblname.setFont(new java.awt.Font("宋体", Font.BOLD, 14));
        lblname.setText("商品名称");
        lblname.setBounds(new Rectangle(28, 60, 90, 38));
        txtprice.setBounds(new Rectangle(106, 112, 118, 38));
        txtprice.addMouseListener(new Frmxiaoshou_txtprice_mouseAdapter(this));
        lblprice.setFont(new java.awt.Font("宋体", Font.BOLD, 14));
        lblprice.setText("价格");
        lblprice.setBounds(new Rectangle(28, 109, 75, 39));
        tbnadd.setBounds(new Rectangle(46, 246, 153, 39));
        tbnadd.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        tbnadd.setText("录入已销售的商品");
        tbnadd.addActionListener(new Frmxiaoshou_tbnadd_actionAdapter(this));
        cbodw.setBackground(Color.orange);
        cbodw.setBounds(new Rectangle(350, 115, 120, 34));
        lbldw.setFont(new java.awt.Font("宋体", Font.BOLD, 14));
        lbldw.setText("单位");
        lbldw.setBounds(new Rectangle(278, 113, 75, 37));
        txtnum.setBounds(new Rectangle(350, 57, 120, 38));
        lblnum.setFont(new java.awt.Font("宋体", Font.BOLD, 14));
        lblnum.setText("数量");
        lblnum.setBounds(new Rectangle(278, 61, 63, 34));
        jButton3.setBounds(new Rectangle(338, 246, 155, 39));
        jButton3.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        jButton3.setText("录入下一个商品");
        jButton3.addActionListener(new Frmxiaoshou_jButton3_actionAdapter(this));
        jButton4.setBounds(new Rectangle(298, 338, 118, 36));
        jButton4.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        jButton4.setText("返回主窗口");
        jButton4.addActionListener(new Frmxiaoshou_jButton4_actionAdapter(this));
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBounds(new Rectangle(11, 16, 489, 388));
        btndelete.setBounds(new Rectangle(124, 340, 123, 35));
        btndelete.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        btndelete.setText("删除旧记录");
        btndelete.addActionListener(new Frmxiaoshou_btndelete_actionAdapter(this));
        jOptionPane1.setBounds(new Rectangle(49, 200, 15, 21));
        btnjianshao.setBounds(new Rectangle(208, 246, 119, 39));
        btnjianshao.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        btnjianshao.setText("剩余库存商品");
        btnjianshao.addActionListener(new Frmxiaoshou_btnjianshao_actionAdapter(this));
        lbljg.setFont(new java.awt.Font("宋体", Font.BOLD, 14));
        lbljg.setText("元/斤");
        lbljg.setBounds(new Rectangle(222, 113, 67, 38));
        this.getContentPane().add(lblname);
        this.getContentPane().add(txtname);
        this.cbodw.addItem("--请选择单位--");
        this.cbodw.addItem("筐");
        this.cbodw.addItem("公斤");
        this.cbodw.addItem("斤");
        this.getContentPane().add(txtprice);
        this.getContentPane().add(lblprice);
        this.getContentPane().add(jOptionPane1);
        this.getContentPane().add(txtnum);
        this.getContentPane().add(lblnum);
        this.getContentPane().add(cbodw);
        this.getContentPane().add(lbldw);
        this.getContentPane().add(lbljg);
        this.getContentPane().add(tbnadd);
        this.getContentPane().add(btnjianshao);
        this.getContentPane().add(jButton3);
        this.getContentPane().add(jButton4);
        this.getContentPane().add(btndelete);
        this.getContentPane().add(jPanel1);
        txtname.setBounds(new Rectangle(106, 61, 121, 38));
    }

    public static void main(String[] args) {
        Frmxiaoshou frmxiaoshou = new Frmxiaoshou();
        frmxiaoshou.setVisible(true);
    }

    public void tbnadd_actionPerformed(ActionEvent e) {
        String i=null;
        if(this.cbodw.getSelectedItem().equals("筐"))
        {
            i="筐";
        }
        else if(this.cbodw.getSelectedItem().equals("公斤"))
        {
            i="公斤";
        }
        else
        {
            i="斤";
        }
        if(this.txtname.getText().equals(""))
        {
            this.jOptionPane1.showMessageDialog(this,"商品名称不能为空!");
        }else{
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (ClassNotFoundException ex) {
        }
        try {
            Connection con = java.sql.DriverManager.getConnection(
                    "jdbc:odbc:veg");
            Statement s=con.createStatement();
            int num=s.executeUpdate("insert into 销售表 values('"+this.txtname.getText()+"','"+this.txtprice.getText()+"','"+this.txtnum.getText()+"','"+i+"')");
            if(num>0)
            {
                this.jOptionPane1.showMessageDialog(this,"销售成功,请及时更新库存信息!");
            }
            con.close();
            s.close();
        } catch (SQLException ex1) {
        }
      }
    }

    public void jButton3_actionPerformed(ActionEvent e) {
        this.txtname.setText("");
        this.txtnum.setText("");
        this.txtprice.setText("");
    }

    public void jButton4_actionPerformed(ActionEvent e) {
        Frmveg frmveg=new Frmveg();
        frmveg.setVisible(true);
        this.setVisible(false);
    }

    public void btncheck_actionPerformed(ActionEvent e) {


    }

    public void btndelete_actionPerformed(ActionEvent e) {
        if(this.txtname.getText().equals(""))
        {
            this.jOptionPane1.showMessageDialog(this,"商品名不能为空!");
        }else
        {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (ClassNotFoundException ex) {
        }
        try {
            Connection con = java.sql.DriverManager.getConnection(
                    "jdbc:odbc:veg");
            Statement s=con.createStatement();
            int num=s.executeUpdate("delete from 销售表 where 商品名称='"+this.txtname.getText()+"'");
            if(num>0)
            {
                this.jOptionPane1.showMessageDialog(this,"删除记录成功!");
            }
        } catch (SQLException ex1) {
        }
       }
    }

    public void btnjianshao_actionPerformed(ActionEvent e) {
        String i=null;
        if(this.cbodw.getSelectedItem().equals("筐"))
        {
            i="筐";
        }
        else if(this.cbodw.getSelectedItem().equals("公斤"))
        {
            i="公斤";
        }
        else
        {
            i="斤";
        }
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (ClassNotFoundException ex) {
        }
        try {
            Connection con = java.sql.DriverManager.getConnection(
                    "jdbc:odbc:veg");
            Statement s=con.createStatement();
            int num=s.executeUpdate("update 入库表 set 价格='"+this.txtprice.getText()+"', 数量=数量-'"+this.txtnum.getText()+"',单位='"+i+"' where 商品名称='"+this.txtname.getText()+"'");
            if(num>0)
            {
                this.jOptionPane1.showMessageDialog(this,"已经更新了库存!");
            }
            con.close();
            s.close();
        } catch (SQLException ex1) {
        }
    }

    public void txtprice_mouseClicked(MouseEvent e) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (ClassNotFoundException ex) {
        }

            try {
                Connection con = java.sql.DriverManager.getConnection(
                        "jdbc:odbc:veg");
                Statement s=con.createStatement();
                ResultSet rs=s.executeQuery("select 价格 from 入库表 where 商品名称='"+this.txtname.getText()+"'");
                if(rs.next())
                {
                 String  u= rs.getString(1);
                 this.txtprice.setText(u);
                }
            } catch (SQLException ex1) {
            }
    }

    public void lbltime1_mouseClicked(MouseEvent e) {
        Calendar cal;
        cal=Calendar.getInstance();
    }
}


class Frmxiaoshou_txtprice_mouseAdapter extends MouseAdapter {
    private Frmxiaoshou adaptee;
    Frmxiaoshou_txtprice_mouseAdapter(Frmxiaoshou adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.txtprice_mouseClicked(e);
    }
}


class Frmxiaoshou_btnjianshao_actionAdapter implements ActionListener {
    private Frmxiaoshou adaptee;
    Frmxiaoshou_btnjianshao_actionAdapter(Frmxiaoshou adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnjianshao_actionPerformed(e);
    }
}


class Frmxiaoshou_btndelete_actionAdapter implements ActionListener {
    private Frmxiaoshou adaptee;
    Frmxiaoshou_btndelete_actionAdapter(Frmxiaoshou adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btndelete_actionPerformed(e);
    }
}


class Frmxiaoshou_jButton4_actionAdapter implements ActionListener {
    private Frmxiaoshou adaptee;
    Frmxiaoshou_jButton4_actionAdapter(Frmxiaoshou adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton4_actionPerformed(e);
    }
}


class Frmxiaoshou_jButton3_actionAdapter implements ActionListener {
    private Frmxiaoshou adaptee;
    Frmxiaoshou_jButton3_actionAdapter(Frmxiaoshou adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton3_actionPerformed(e);
    }
}


class Frmxiaoshou_tbnadd_actionAdapter implements ActionListener {
    private Frmxiaoshou adaptee;
    Frmxiaoshou_tbnadd_actionAdapter(Frmxiaoshou adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.tbnadd_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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