@TOC
本系统为了解决销售常规工作的管理,基于普通用户、管理员两种角色,实现了销售单管理、入库单管理、库存管理、数据可视化管理、个人信息等功能。
登录
个人信息
管理员首页
销售单管理
入库单管理
库存管理
目标可视化
本销售管理系统实现了以下功能:
1、普通用户、管理员登录
2、入库单管理
3、销售单管理
4、库存管理管理
5、目标可视化展示
6、个人信息
数据库:mysql
开发工具:Eclipse(Myeclispe、Idea也可以)
知识点:Swing
Dao
GoodsDaoImpl.java
package DAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import MySQL.Goods;
import DBConn.DBConn;
public class GoodsDaoImpl implements GoodsDao{
//增加
public void add(Goods g) {
String ssql = "insert into goods values(?,?,?,?)";
Connection conn = DBConn.open();
try {
PreparedStatement pstmt = conn.prepareStatement(ssql);
pstmt.setString(1,g.getId());
pstmt.setString(2,g.getName());
pstmt.setInt(3,g.getPrice());
pstmt.setString(4,g.getSize());
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBConn.close(conn);
}
}
//修改
public void update(Goods g) {
String ssql = "update goods set name=?,price=?,size=? where id=?";
Connection conn = DBConn.open();
try {
PreparedStatement pstmt = conn.prepareStatement(ssql);
pstmt.setString(1,g.getName());
pstmt.setInt(2,g.getPrice());
pstmt.setString(3,g.getSize());
pstmt.setString(4,g.getId());
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBConn.close(conn);
}
}
//删除
public void delete(String id) {
String ssql = "delete from goods where id=?";
Connection conn = DBConn.open();
try {
PreparedStatement pstmt = conn.prepareStatement(ssql);
pstmt.setString(1,id);
pstmt.executeUpdate();
} catch (SQLException e){
e.printStackTrace();
}finally{
DBConn.close(conn);
}
}
//通过id得到商品
public Goods getGoodsById(String id) {
String ssql = "select * from goods where id=?";
Connection conn = DBConn.open();
try {
PreparedStatement pstmt = conn.prepareStatement(ssql);
pstmt.setString(1, id);
ResultSet rs = pstmt.executeQuery();
if(rs.next()){
String name = rs.getString(2);
int price = rs.getInt(3);
String size = rs.getString(4);
Goods g = new Goods();
g.setId(id);
g.setName(name);
g.setPrice(price);
g.setSize(size);
return g;
}
} catch (SQLException e){
e.printStackTrace();
}finally{
DBConn.close(conn);
}
return null;
}
//查询
public String query() {
String ssql = "select * from goods";
Connection conn = DBConn.open();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(ssql);
String s ="";
while(rs.next()){
String id = rs.getString(1);
String name = rs.getString(2);
int price = rs.getInt(3);
String size = rs.getString(4);
s = s+id+" "+name+" "+price+" "+size+"\n";
}
return s;
}catch (SQLException e1){
e1.printStackTrace();
}finally{
DBConn.close(conn);
}
return null;
}
}
PurchaseImpl.java
package DAO;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import DBConn.DBConn;
import MySQL.Purchase;
public class PurchaseImpl implements PurchaseDao{
//增加
public void add(Purchase p) {
String ssql = "insert into purchase values(?,?,?,?)";
Connection conn = DBConn.open();
try {
PreparedStatement pstmt = conn.prepareStatement(ssql);
pstmt.setString(1,p.getId());
pstmt.setInt(2,p.getNumber());
pstmt.setInt(3,p.getPrice());
pstmt.setDate(4,p.getDate());
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBConn.close(conn);
}
}
//删除
public void delete(String id) {
String ssql = "delete from purchase where id=?";
Connection conn = DBConn.open();
try {
PreparedStatement pstmt = conn.prepareStatement(ssql);
pstmt.setString(1,id);
pstmt.executeUpdate();
} catch (SQLException e){
e.printStackTrace();
}finally{
DBConn.close(conn);
}
}
//通过id得到商品
public Purchase getPurchaseById(String id) {
String ssql = "select * from purchase where id=?";
Connection conn = DBConn.open();
try {
PreparedStatement pstmt = conn.prepareStatement(ssql);
pstmt.setString(1, id);
ResultSet rs = pstmt.executeQuery();
if(rs.next()){
int number = rs.getInt(2);
int price = rs.getInt(3);
Date date = rs.getDate(4);
Purchase p = new Purchase();
p.setId(id);
p.setNumber(number);
p.setPrice(price);
p.setDate(date);
return p;
}
} catch (SQLException e){
e.printStackTrace();
}finally{
DBConn.close(conn);
}
return null;
}
//查询
public String query() {
String ssql = "select * from purchase";
Connection conn = DBConn.open();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(ssql);
String s ="";
while(rs.next()){
String id = rs.getString(1);
int number = rs.getInt(2);
int price = rs.getInt(3);
Date date = rs.getDate(4);
s = s+id+" "+number+" "+price+" "+date+"\n";
}
return s;
}catch (SQLException e1){
e1.printStackTrace();
}finally{
DBConn.close(conn);
}
return null;
}
}
可视化
CircleProgressBar.java
package JFrame;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JPanel;
/**
* 圆形进度条。
*/
public class CircleProgressBar extends JPanel {
private static final long serialVersionUID = 1L;
private int minimumProgress; //最小进度值。
private int maximumProgress; //最大进度值。
private int progress; //当前进度值。
private Color backgroundColor; //背景颜色。
private Color foregroundColor; //前景颜色。
private Color digitalColor; //数字颜色。
//构造函数△△ △
public CircleProgressBar() {
setMinimumProgress(0);
setMaximumProgress(100);
setProgress(0);
setBackgroundColor(new Color(209, 206, 200));
setForegroundColor(new Color(172, 168, 163));
setDigitalColor(Color.BLACK);
}
/**
*△△ △ 绘制圆形进度条。
*/
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D graphics2d = (Graphics2D) g;
// 开启抗锯齿
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
int x = 0;
int y = 0;
int width = 0;
int height = 0;
int fontSize = 0;
if (getWidth() >= getHeight()) {
x = (getWidth() - getHeight()) / 2 + 25;
y = 25;
width = getHeight() - 50;
height = getHeight() - 50;
fontSize = getWidth() / 8;
} else {
x = 25;
y = (getHeight() - getWidth()) / 2 + 25;
width = getWidth() - 50;
height = getWidth() - 50;
fontSize = getHeight() / 8;
}
graphics2d.setStroke(new BasicStroke(20.0f));
graphics2d.setColor(backgroundColor);
graphics2d.drawArc(x, y, width, height, 0, 360);
graphics2d.setColor(foregroundColor);
graphics2d.drawArc(x, y, width, height, 90, -(int) (360 * ((progress * 1.0) / (getMaximumProgress() - getMinimumProgress()))));
graphics2d.setFont(new Font("黑体", Font.BOLD, fontSize));
FontMetrics fontMetrics = graphics2d.getFontMetrics();
int digitalWidth = fontMetrics.stringWidth(progress + "%");
int digitalAscent = fontMetrics.getAscent();
graphics2d.setColor(digitalColor);
graphics2d.drawString(progress + "%", getWidth() / 2 - digitalWidth / 2, getHeight() / 2 + digitalAscent / 2);
}
/**
* 返回最小进度值。
*/
public int getMinimumProgress() {
return minimumProgress;
}
/**
* 设置最小进度值。
*/
public void setMinimumProgress(int minimumProgress) {
if (minimumProgress <= getMaximumProgress()) {
this.minimumProgress = minimumProgress;
}
}
/**
* 返回最大进度值。
*/
public int getMaximumProgress() {
return maximumProgress;
}
/**
* 设置最大进度值。
*/
public void setMaximumProgress(int maximumProgress) {
if (maximumProgress >= getMinimumProgress()) {
this.maximumProgress = maximumProgress;
}
}
/**
* 返回当前进度值。
*/
public int getProgress() {
return progress;
}
/**
* 设置当前进度值。
*/
public void setProgress(int progress) {
if (progress >= getMinimumProgress() && progress <= getMaximumProgress()) {
this.progress = progress;
this.repaint();
}
}
/**
* 返回背景颜色。
*/
public Color getBackgroundColor() {
return backgroundColor;
}
/**
* 设置背景颜色。
*/
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
this.repaint();
}
/**
* 返回前景颜色。
*/
public Color getForegroundColor() {
return foregroundColor;
}
/**
* 设置前景颜色。
*/
public void setForegroundColor(Color foregroundColor) {
this.foregroundColor = foregroundColor;
this.repaint();
}
/**
* 返回数字颜色。
*/
public Color getDigitalColor() {
return digitalColor;
}
/**
* 设置数字颜色。
*/
public void setDigitalColor(Color digitalColor) {
this.digitalColor = digitalColor;
this.repaint();
}
}
商品
goodsUpdate.java
package JFrame;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import DAO.GoodsDaoImpl;
import DBConn.DBConn;
import MySQL.Goods;
public class goodsUpdate extends JFrame{
private static final long serialVersionUID = -866582087055034098L;
JLabel e1,e2,e3,e4,msg;
JTextField t1,t2,t3,t4;
JButton b1,b2,reset;
Connection conn;
public goodsUpdate(){
conn = DBConn.open();
e1 = new JLabel("商品代码:");
t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(10);
t4 = new JTextField(10);
reset= new JButton("刷新");
t1.setText(""); b1 = new JButton("查询");
e2 = new JLabel("商品名称:"); t2.setText("");
e3 = new JLabel("价格:"); t3.setText("");
e4 = new JLabel("规格:"); t4.setText("");
msg = new JLabel(""); b2 = new JButton("修改");
//字体设置
Font f = new Font("隶书",Font.BOLD,23);
e1.setFont(f);t1.setFont(f);
e2.setFont(f);t2.setFont(f);
e3.setFont(f);t3.setFont(f);
e4.setFont(f);t4.setFont(f);
b2.setFont(f); b2.setForeground(Color.blue);
msg.setFont(f); msg.setForeground(Color.lightGray);
b1.setFont(f);b1.setForeground(Color.blue);
reset.setFont(f);
//位置
e1.setBounds(30, 20,110,30); t1.setBounds(145, 20,200, 30);
b1.setBounds(150, 80,90, 40); reset.setBounds(265, 80, 90, 40);
e2.setBounds(30, 140,110,30); t2.setBounds(145, 140,200, 30);
e3.setBounds(50, 200,110,30); t3.setBounds(145, 200,200, 30);
e4.setBounds(50, 260,110,30); t4.setBounds(145, 260,200, 30);
b2.setBounds(150,320,90,40); msg.setBounds(140, 400,240,30);
this.add(e1);this.add(t1);
this.add(b1);this.add(reset);
this.add(e2);this.add(t2);
this.add(e3);this.add(t3);
this.add(e4);this.add(t4);
this.add(msg);
//按钮监听
b1.addActionListener(new B1());
reset.addActionListener(new reSet());
b2.addActionListener(new B2());
this.setBounds(440,190,395,480);
setTitle("修改信息");
this.setLayout(null); // 绝对布局
setVisible(true);
}
//内部类:按id查询
class B1 implements ActionListener{
Goods g = new Goods(); //new很关键
GoodsDaoImpl gdi = new GoodsDaoImpl();
public void actionPerformed(ActionEvent e)
{
try{
g.setId(t1.getText());
g = gdi.getGoodsById(g.getId());
t2.setText(g.getName());
t3.setText(String.valueOf(g.getPrice()));
t4.setText(g.getSize());
add(b2);
}catch (Exception e1) {
msg.setText("不存在此商品!");
t1.requestFocus();
}finally{
DBConn.close(conn); //关闭数据库连接
}
}
}
//内部类:b2修改
class B2 implements ActionListener
{
Goods g = new Goods(); //new很关键
GoodsDaoImpl gdi = new GoodsDaoImpl();
public void actionPerformed(ActionEvent e)
{
g.setName(t2.getText());
g.setPrice(Integer.parseInt(t3.getText()));
g.setSize(t4.getText());
g.setId(t1.getText());
gdi.update(g);
msg.setText("修改成功!");
}
}
class reSet implements ActionListener{
Goods g = new Goods(); //new很关键
GoodsDaoImpl gdi = new GoodsDaoImpl();
public void actionPerformed(ActionEvent e)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
msg.setText("");
}
}
}
销售
Sales.java
package JFrame;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import DAO.SalesDaoImpl;;
public class Sales extends JPanel{
private static final long serialVersionUID = 6603958499502362577L;
JButton bt1,bt3,bt4,home;
JLabel lb1,bg;
JTextArea ta;
public Sales() {
ImageIcon img1 = new ImageIcon(HomePage.class.getResource("add.png"));
//ImageIcon img2 = new ImageIcon(HomePage.class.getResource("modify.png"));
ImageIcon img3 = new ImageIcon(HomePage.class.getResource("delete.png"));
ImageIcon img4 = new ImageIcon(HomePage.class.getResource("update.png"));
ImageIcon img5 = new ImageIcon(HomePage.class.getResource("3.png"));
ImageIcon home1 = new ImageIcon(HomePage.class.getResource("back.png"));
ImageIcon bg1 = new ImageIcon(HomePage.class.getResource("userbg.jpg"));
bg = new JLabel(bg1);
bt1 = new JButton(img1);
//bt2 = new JButton(img2);
bt3 = new JButton(img3);
bt4 = new JButton(img4);
lb1= new JLabel(img5);
ta = new JTextArea();
home = new JButton(home1);
this.setLayout(null); // 绝对布局
home.setBounds(1, 1, 64, 64);
bt1.setBounds(320, 50, 30, 30);
//bt2.setBounds(360, 50, 30, 30);
bt3.setBounds(360, 50, 30, 30);
bt4.setBounds(400, 50, 30, 30);
lb1.setBounds(150, 90, 500,300);
ta.setBounds(220, 220, 400, 400);
bg.setBounds(0, 0, 800, 600);
//字体
Font font = new Font("幼圆", Font.BOLD, 20); // 字体
ta.setForeground(Color.black);
ta.setFont(font);
ta.setText(queryAll());//显示所有商品信息
ta.setBackground(null);//隐藏边框
this.add(bt1);
//this.add(bt2);
this.add(bt3);
this.add(bt4);
this.add(lb1);
this.add(ta);
this.add(home);
this.add(bg);
home.setOpaque(false);//按钮透明
home.setBorderPainted(false); // 按钮无边框
//按钮监听
bt1.addActionListener(new B1());
//bt2.addActionListener(new B2());
bt3.addActionListener(new B3());
bt4.addActionListener(new B4());
}
public String queryAll(){
SalesDaoImpl sdi = new SalesDaoImpl();
String s;
s = sdi.query();
return s;
}
//内部类
class B1 implements ActionListener
{
public void actionPerformed(ActionEvent e){
new salesAdd();
}
}
class B3 implements ActionListener
{
public void actionPerformed(ActionEvent e){
new salesDelete();
}
}
class B4 implements ActionListener
{
public void actionPerformed(ActionEvent e){
ta.setText(queryAll());
}
}
}
【源码下载声明】
—1、源码的下载链接一般在在文章底部,直接下载获取即可。
【公众号介绍】
—码农一枚,专注于用代码改变生活。非技术大牛,热衷于学习,通过分享自己的一些经验、知识点、成品等干活,与大家共勉。
【联系方式】
—
联
系
方
式
公众号: 程序猿矛盾体
【公众号二维码, 扫一扫吧】
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。