Swing/GUI企业进销存进货销售仓储管理系统-JAVA【毕业设计、快速开发、源码、开题报告】

该代码段展示了如何使用JavaSwing创建一个添加商品信息的用户界面,包括商品名称、价格、产地、库存等字段,并集成数据库查询功能,从仓库和分类表中填充下拉菜单,支持商品的保存操作。程序还包含了错误处理和界面交互逻辑。
摘要由CSDN通过智能技术生成

  

功能介绍

部分功能模块代码

package org.rancode.module.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;

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

import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;
import org.rancode.framework.util.Item;
import org.rancode.framework.util.MyFont;
import org.rancode.module.services.Impl.CategoryServiceImpl;
import org.rancode.module.services.Impl.GoodsServiceImpl;
import org.rancode.module.services.Impl.WarehouseServiceImpl;

public class AddGoodsJFrame extends JFrame implements MouseListener {

	// 定义全局组件
	JPanel backgroundPanel, labelPanel, contentPanel, buttonPanel;
	JLabel label_name, label_price, label_origin, label_stock, label_warehouse, label_category;
	JTextField name, price, origin, stock;
	JComboBox warehouse, category;
	JButton button_add;

	// 获得屏幕的大小
	final static int width = Toolkit.getDefaultToolkit().getScreenSize().width;
	final static int height = Toolkit.getDefaultToolkit().getScreenSize().height;

	// 父面板对象
	GoodsManagerJPanel parentPanel;

	public AddGoodsJFrame(GoodsManagerJPanel parentPanel) {
		this.parentPanel = parentPanel;

		initBackgroundPanel();

		this.add(backgroundPanel);

		this.setTitle("添加商品");
		this.setSize(640, 360);
		this.setVisible(true);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
	}

	// 初始化背景面板
	public void initBackgroundPanel() {
		backgroundPanel = new JPanel(new BorderLayout());

		initContentPanel();
		initButtonPanel();
		initLabelPanel();

		backgroundPanel.add(labelPanel, "North");
		backgroundPanel.add(contentPanel, "Center");
		backgroundPanel.add(buttonPanel, "South");
	}

	// 初始化label面板
	public void initLabelPanel() {

		labelPanel = new JPanel();

		JLabel title = new JLabel("商品信息");
		title.setFont(MyFont.Static);

		labelPanel.add(title);
	}

	// 初始化商品信息面板
	public void initContentPanel() {
		contentPanel = new JPanel(new GridLayout(6, 2));

		label_name = new JLabel("商品名称", JLabel.CENTER);
		label_price = new JLabel("商品价格", JLabel.CENTER);
		label_origin = new JLabel("商品产地", JLabel.CENTER);
		label_stock = new JLabel("商品库存", JLabel.CENTER);
		label_warehouse = new JLabel("所属仓库", JLabel.CENTER);
		label_category = new JLabel("所属分类", JLabel.CENTER);

		name = new JTextField("");
		price = new JTextField("");
		origin = new JTextField("");
		stock = new JTextField("");

		// 商品种类下拉框
		category = new JComboBox();
		CategoryServiceImpl categoryService = new CategoryServiceImpl();
		List<Object[]> list_category = null;
		try {
			list_category = categoryService.selectAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (list_category != null) {
			int sign = 0;
			for (int i = 0; i < list_category.size(); i++) {
				String id = (String) list_category.get(i)[0];
				String name = (String) list_category.get(i)[1];
				category.addItem(new Item(id, name));
			}
		}

		// 仓库下拉框
		warehouse = new JComboBox();
		WarehouseServiceImpl warehouseService = new WarehouseServiceImpl();
		List<Object[]> list_warehouse = null;
		try {
			list_warehouse = warehouseService.selectAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (list_warehouse != null) {
			int sign = 0;
			for (int i = 0; i < list_warehouse.size(); i++) {
				String id = (String) list_warehouse.get(i)[0];
				String name = (String) list_warehouse.get(i)[1];
				warehouse.addItem(new Item(id, name));
			}
		}

		contentPanel.add(label_name);
		contentPanel.add(name);
		contentPanel.add(label_price);
		contentPanel.add(price);
		contentPanel.add(label_origin);
		contentPanel.add(origin);
		contentPanel.add(label_stock);
		contentPanel.add(stock);
		contentPanel.add(label_category);
		contentPanel.add(category);
		contentPanel.add(label_warehouse);
		contentPanel.add(warehouse);

	}

	// 初始化按钮面板
	public void initButtonPanel() {
		buttonPanel = new JPanel();

		button_add = new JButton("保存");
		button_add.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));
		button_add.setForeground(Color.white);
		button_add.setFont(MyFont.Static);
		button_add.addMouseListener(this);

		buttonPanel.add(button_add);
	}

	// 鼠标点击事件
	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getSource() == button_add) {

			String name_String = name.getText().trim();
			String price_String = price.getText().trim();
			String origin_String = origin.getText().trim();
			String stock_String = stock.getText().trim();

			if (name_String.isEmpty()) {
				JOptionPane.showMessageDialog(null, "请输入商品名称");
			} else if (price_String.isEmpty()) {
				JOptionPane.showMessageDialog(null, "请输入商品价格");
			} else if (origin_String.isEmpty()) {
				JOptionPane.showMessageDialog(null, "请输入商品产地");
			} else if (stock_String.isEmpty()) {
				JOptionPane.showMessageDialog(null, "请输入商品库存");
			} else {
				int result = 0;
				double price_double = Double.valueOf(price_String);
				BigDecimal price_decimal = BigDecimal.valueOf(price_double);
				double stock_double = Double.valueOf(stock_String);
				String warehouse_id = ((Item) warehouse.getSelectedItem()).getKey();
				String category_id = ((Item) category.getSelectedItem()).getKey();
				String id = UUID.randomUUID().toString().replaceAll("-", "");
				Object[] params = { id, name_String, price_decimal, origin_String, stock_double, warehouse_id,
						category_id };
				GoodsServiceImpl goodsService = new GoodsServiceImpl();
				try {
					result = goodsService.insertById(params);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				if (result > 0) {
					JOptionPane.showMessageDialog(null, "添加商品成功");
					this.setVisible(false);
					parentPanel.refreshTablePanel();
				}
			}
		}

	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

}
package org.rancode.module.services.Impl;

import java.util.List;
import java.util.Vector;

import org.rancode.module.dao.Impl.BaseDaoImpl;
import org.rancode.module.services.GoodsService;

public class GoodsServiceImpl implements GoodsService {
	
	//条件查询商品
	@Override
	public Vector<Vector> selectByCondition(Object[] paraArray) throws Exception {
		Vector<Vector> rows = new Vector<Vector>();
		BaseDaoImpl dao = new BaseDaoImpl();
		StringBuilder sqlBuilder = new StringBuilder(
				"select g.id,g.name,g.price,g.origin,c.name as categoryName,w.name as warehouseName, g.stock,w.id as warehouseId,c.id as categoryId "
						+ "from goods g,warehouse w,category c "
						+ "where 1=1 and g.del_flag='0' and w.del_flag='0' and c.del_flag='0' and g.warehouse_id=w.id and g.category_id=c.id ");
		if (!"全部".equals(paraArray[0])) {
			sqlBuilder.append(" and g.category_id='" + paraArray[0] + "'");
		}
		if (!"全部".equals(paraArray[1])) {
			sqlBuilder.append(" and g.warehouse_id='" + paraArray[1] + "'");
		}
		String sql = sqlBuilder.toString();
		List<Object[]> list = dao.select(sql, 9, null);
		if (!list.isEmpty()) {
			for (Object[] object : list) {
				Vector temp = new Vector<String>();
				for (int i = 0; i < object.length; i++) {
					temp.add(object[i]);
				}
				rows.add(temp);
			}
		}

		return rows;
	}
	
	//逻辑删除商品
	@Override
	public int deleteById(Object[] paraArray) throws Exception {
		BaseDaoImpl dao = new BaseDaoImpl();
		int result = 0;
		result = dao.update("update goods set del_flag='1' where id=?", paraArray);
		return result;
	}
	
	//通过id修改销售单
	@Override
	public int updateById(Object[] paraArray) throws Exception {
		BaseDaoImpl dao = new BaseDaoImpl();
		int result = 0;
		result = dao.update("update goods set name=?,price=?,origin=?,stock=?,warehouse_id=?,category_id=? where id=?",
				paraArray);
		return result;
	}
	
	//插入销售单
	@Override
	public int insertById(Object[] paraArray) throws Exception {
		BaseDaoImpl dao = new BaseDaoImpl();
		int result = 0;
		result = dao.insert(
				"insert into goods(id,name,price,origin,stock,warehouse_id,category_id,del_flag)  values(?,?,?,?,?,?,?,'0')",
				paraArray);
		return result;
	}
	
	//查询所有销售单
	@Override
	public List selectAll() throws Exception {
		BaseDaoImpl dao = new BaseDaoImpl();
		String sql = "select id,name from goods where 1=1 and del_flag='0' ";
		List<Object[]> list = dao.select(sql, 2, null);
		return list;
	}
	
	//通过id查询销售单
	@Override
	public List selectById(Object[] paraArray) throws Exception {
		BaseDaoImpl dao = new BaseDaoImpl();
		String sql = "select c.id,c.name,w.id,w.name,g.stock " + "from goods g,category c,warehouse w "
				+ "where g.category_id=c.id and g.warehouse_id=w.id and g.del_flag='0' and c.del_flag='0' and w.del_flag='0' and g.id=?";
		List<Object[]> list = dao.select(sql, 5, paraArray);
		return list;
	}
	
	//通过id修改库存
	@Override
	public int updateStockById(Object[] paraArray) throws Exception {
		BaseDaoImpl dao = new BaseDaoImpl();
		int result = 0;
		result = dao.update("update goods set stock=stock+? where id=?", paraArray);
		return result;
	}

}

论文目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值