您的位置:首页 > 职场人生

黑马程序员---10、超市商品管理之商品信息管理模块

2013-07-28 10:49 344 查看
超市商品管理之商品信息管理模块
 

超市商品管理之商品信息管理

1. 项目描述

       超市库存管理在欧美等国已实行多年,如今,在像中国这样的发展中国家也迅速地得到了推广。它最主要的特点是能够实时和准确地反映店内的销售情况,以便为超市管理者提供决策信息支持。超市库存管理的内容就是商品的入库、出库和库存管理,它是商品管理的中间环节。用数据描叙货物的收入、发出和储存的状态,实际反映了商品在超市内流动的客观过程,库存管理和商品管理的其他环节都有直接联系。可以说它在商品配送管理中起着枢纽和基础的重要作用。

        有效的库存管理,可降低运营成本,进而提高商品周转率,这样才能减少因风险造成的损失,从而使利润达到最高点。一个超市的库存,也就代表了这个超市的大部分资产总额。如何将这些静态的资产以最快的速度流转,这就是库存管理的目的。一个好的超市,并不是只有畅销的商品就行了。因为畅销的可能都是固定的某些商品,而有些商品可能进了超市后,就无人问津,这样不仅使这些商品占据了库房空间,而且也积了大量的资金,使得资金运转相当的困难。要改善库存周转率不高的状况,就必须先从了解超市目前的库存情况开始,而要了解库存的情况,就可以利用信息系统来进行管理,从而进一步的提高库存管理的效率。通过信息系统的查询可以方便的找出目前最畅销和滞销的商品,然后再利用各种行销方法,将滞销的商品销售出去,这样就可以避免超市因为滞销而造成的损坏、过期和资金积压等问题。

        超市库存管理系统由库存商品信息模块、库存商品供货商模块、管理员模块和库存管理模块,库存盘点信息模块组成,它们分别实现商品信息管理,商品供货商管理,商品进出库管理,库存盘点管理功能。几个模块之间的关系是密切联系的,商品信息管理模块是本系统最基础也是最重要的模块,因为它是其他模块执行操作的依据,进货、盘点已经库存的数据更新都围绕商品信息模块而展开。

      这次仅对商品信息管理模块进行粗浅的部分设计,对商品信息进行增加、删除功能。

ProductService :

package control;

import java.util.ArrayList;

import java.util.Iterator;

import model.SimpleProduct;;

public class ProductService {

ArrayList<SimpleProduct> products=new java.util.ArrayList<SimpleProduct>();

Object[][] productShow=new Object[20][3];

public ProductService(){

init();

}

/*数据初始化*/

public void init(){

/*从文件、数据库里调出已有信息*/

products.add(new SimpleProduct(1,"apple",1));

products.add(new SimpleProduct(2,"apple",1));

products.add(new SimpleProduct(3,"apple",1));

products.add(new SimpleProduct(4,"apple",1));

productShow=this.listToArray();

}

/*将新得到的数据存储到ArrayList*/

public void addNewProduct(SimpleProduct product){

/*跳过检测:如编号不允许重复*/

products.add(product);

}

/*删除指定编号的商品*/

public void deleteProductByNo(int no){

Iterator it=products.iterator();

while(it.hasNext()){

SimpleProduct sp=(SimpleProduct)it.next();

if(sp.getNo()==no){

products.remove(sp);

break;

}

}

}

public Object[][] listToArray(){

int i=0;

Iterator it=products.iterator();

while(it.hasNext()){

SimpleProduct sp=(SimpleProduct)it.next();

System.out.println(sp.toString());

productShow[i][0]=sp.getNo();

productShow[i][1]=sp.getName();

productShow[i][2]=sp.getPrice();

i++;

}

return productShow;

}

public Object[][] setLastNull(){

int size=products.size();

productShow[size][0]=null;

productShow[size][1]=null;

productShow[size][2]=null;

return productShow;

}

public ArrayList<SimpleProduct> getProducts() {

return products;

}

public void setProducts(ArrayList<SimpleProduct> products) {

this.products = products;

}

public Object[][] getProductShow() {

return productShow;

}

public void setProductShow(Object[][] productShow) {

this.productShow = productShow;

}

}

package form;

MainForm  :

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class MainForm  extends JFrame implements ActionListener{

JMenuBar menubar;

    JMenu menu;

    JMenuItem  item1,item2;

    JPanel center=new JPanel();

    CardLayout card;

    ProductFrame product;

public MainForm(){

super();

init();

setTitle("商品库存管理系统");

Toolkit tool=getToolkit(); 

Dimension dim=tool.getScreenSize();

setBounds(0,0,dim.width/2,dim.height/2);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true); 

  }

public void init(){

menubar=new JMenuBar(); 

    menu=new JMenu("基本信息管理");   

    item1=new JMenuItem("商品资料管理");

    item2=new JMenuItem("销售员管理");          

    menu.add(item1);

    item1.addActionListener(this);

    menu.add(item2);

    menubar.add(menu);

    setJMenuBar(menubar);

    card = new CardLayout();

    center.setLayout(card);

    

    ProductFrame product = new ProductFrame();

    center.add("product",product);

    

    add(center,BorderLayout.CENTER);

    }

@Override

public void actionPerformed(ActionEvent e) {

JMenuItem item =  (JMenuItem)e.getSource();

if(item == item1){

card.show(center,"product");  //切换到商品管理界面

     }

}

}

ProductFrame:

package form;

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

import javax.swing.*;

import control.ProductService;

import model.SimpleProduct;

public class ProductFrame extends JPanel implements ActionListener{

Box baseBox,inputBox;

JTable show;

JLabel pno,pname,pprice;

JTextField tfno,tfname,tfprice;

JButton badd,bdelete,bseek,blist;

Object productshow[][]=new Object[20][3];

Object[] tableTitle={"商品编号","商品名称","商品价格"};

JScrollPane showInfor;

ProductService ps=new ProductService();

public ProductFrame(){

init();

setSize(200,200);

setVisible(true);

}

public void init(){

this.setLayout(new BorderLayout());

productshow=ps.getProductShow();

show=new JTable(productshow,tableTitle);

showInfor=new JScrollPane(show);

pno=new JLabel("商品编号");

pname=new JLabel("商品名称");

pprice=new JLabel("商品价格");

tfno=new JTextField(10);

tfname=new JTextField(10);

tfprice=new JTextField(10);

Box inputBox1=Box.createHorizontalBox();

inputBox1.add(pno);

inputBox1.add(tfno);

Box inputBox2=Box.createHorizontalBox();

inputBox2.add(pname);

inputBox2.add(tfname);

Box inputBox3=Box.createHorizontalBox();

inputBox3.add(pprice);

inputBox3.add(tfprice);

Box tfBox=Box.createVerticalBox();

tfBox.add(inputBox1);

tfBox.add(inputBox2);

tfBox.add(inputBox3);

Box buttonBox=Box.createHorizontalBox();

badd=new JButton("新增");

badd.addActionListener(this);

bdelete=new JButton("删除");

bdelete.addActionListener(this);

buttonBox.add(badd);

buttonBox.add(bdelete);

tfBox.add(buttonBox);

baseBox=Box.createHorizontalBox();

baseBox.add(tfBox);

baseBox.add(showInfor);

add(baseBox,BorderLayout.CENTER);

}

@Override

public void actionPerformed(ActionEvent e) {

if(e.getSource()==badd){

SimpleProduct sp=new SimpleProduct();

sp.setNo(Integer.parseInt(tfno.getText()));

sp.setName(tfname.getText());

sp.setPrice(Float.parseFloat(tfprice.getText()));

ps.addNewProduct(sp);

ps.setProductShow(productshow);

productshow=ps.listToArray();

show.repaint();

}

if(e.getSource()==bdelete){

int no=Integer.parseInt(tfno.getText());

ps.deleteProductByNo(no);

ps.setProductShow(productshow);

productshow=ps.listToArray();

productshow=ps.setLastNull();

show.repaint();

}

}

}

Product:

package model;

import java.math.BigDecimal;

public class Product {

/**商品编号*/

private String productID;

/**商品名称*/

private String productName;

/**安全存量*/

private BigDecimal safeStock;

/**最后进货日期*/

private String lastPurchaseDate;

/**最后销售日期*/

private String lastDeliverDate;

/**当前数量*/

private BigDecimal quantity;

/**建议购买价格*/

private BigDecimal suggestBuyPrice;

/**建议销售价格*/

private BigDecimal suggestSalePrice;

public String getProductID() {

return productID;

}

public void setProductI
cd65
D(String productID) {

this.productID = productID;

}

public String getProductName() {

return productName;

}

public void setProductName(String productName) {

this.productName = productName;

}

public BigDecimal getSafeStock() {

return safeStock;

}

public void setSafeStock(BigDecimal safeStock) {

this.safeStock = safeStock;

}

public String getLastPurchaseDate() {

return lastPurchaseDate;

}

public void setLastPurchaseDate(String lastPurchaseDate) {

this.lastPurchaseDate = lastPurchaseDate;

}

public String getLastDeliverDate() {

return lastDeliverDate;

}

public void setLastDeliverDate(String lastDeliverDate) {

this.lastDeliverDate = lastDeliverDate;

}

public BigDecimal getQuantity() {

return quantity;

}

public void setQuantity(BigDecimal quantity) {

this.quantity = quantity;

}

public BigDecimal getSuggestBuyPrice() {

return suggestBuyPrice;

}

public void setSuggestBuyPrice(BigDecimal suggestBuyPrice) {

this.suggestBuyPrice = suggestBuyPrice;

}

public BigDecimal getSuggestSalePrice() {

return suggestSalePrice;

}

public void setSuggestSalePrice(BigDecimal suggestSalePrice) {

this.suggestSalePrice = suggestSalePrice;

}

public  static void ShowTitle(){

System.out.println( "|商品名称|"+"商品安全存量|"+"最后进货日期|"+"最后销售日期|"+"当前数量|"+"建议购买价格|"+"建议销售价格|");

}

@Override

public String toString() {

return( "   "+productName+"      "+safeStock

+"      "+lastPurchaseDate+"       "+lastDeliverDate

+"     "+quantity+"      "+suggestBuyPrice

+"       "+suggestSalePrice);

}

}

SimpleProduct:

package model;

import java.io.Serializable;

public class SimpleProduct{

int no;

String name;

float price;

public SimpleProduct() {

super();

}

public SimpleProduct(int no, String name, float price) {

super();

this.no = no;

this.name = name;

this.price = price;

}

public int getNo() {

return no;

}

public void setNo(int no) {

this.no = no;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public float getPrice() {

return price;

}

public void setPrice(float price) {

this.price = price;

}

@Override

public String toString() {

return no+"\t"+name+"\t"+price;

}

}

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: