商品推荐模块实现java_简易商品模块实现

这是一个使用Java编写的商品管理模块,包含查找、添加、删除和修改商品功能。通过LovoTable组件展示商品信息,利用IProductService接口进行业务操作,如根据商品名、日期范围查询商品,以及对商品的增删改操作。
摘要由CSDN通过智能技术生成

packagecom.project.frame;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Date;importjava.util.List;importjavax.swing.JFrame;importjavax.swing.JOptionPane;importcom.lovo.netCRM.component.LovoButton;importcom.lovo.netCRM.component.LovoTable;importcom.lovo.netCRM.component.LovoTxt;importcom.project.bean.ProductBean;importcom.project.service.IProductService;importcom.project.service.Impl.ProductSreviceImpl;importcom.project.util.ChangeDate;public class MainFrame extendsJFrame {//第一个参数表格加入的容器//第二个参数表头列表//第三个参数表头对应实体类的属性名//第四个参数实体类中主键属性名

private LovoTable table=new LovoTable(this,new String []{"商品名","商品单价","商品产地","商品日期"}

,new String [] {"name","price","address","createDate"}, "id");/**商品名文本框*/

private LovoTxt nameTxt=new LovoTxt("商品名", 400, 50, this);/**起始日期文本框*/

private LovoTxt startTxt=new LovoTxt("起始日期", 400, 90, this);/**结束日期文本框*/

private LovoTxt endTxt=new LovoTxt("结束日期", 400, 130, this);/**商品业务组件*/

private IProductService service=newProductSreviceImpl();publicMainFrame() {this.setLayout(null);//调用业务方法得到全部商品

List list=service.findByItem("", null, null);

table.setSizeAndLocation(50, 30, 300, 200);

table.updateLovoTable(list);

LovoButton findButton=new LovoButton("查找", 500, 160, this);

findButton.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent arg0) {//得到文本框数据

String name=nameTxt.getText();//在工具类写判断日期是否正确方法

Date startDate=ChangeDate.getDate(startTxt.getText());

Date endDate=ChangeDate.getDate(endTxt.getText());//调用业务方法得到查询结果

List list=service.findByItem(name, startDate, endDate);//更新表格数据

table.updateLovoTable(list);

}

});

LovoButton addButton=new LovoButton("添加商品", 500, 200, this);

addButton.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent arg0) {

MainFrame.this.dispose();newAddFrame();

}

});

LovoButton delButton=new LovoButton("删除", 500, 240, this);

delButton.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent arg0) {//得到用户选择行的id号,如果没有选择行,返回-1

int id=table.getKey();if(id==-1)

{

JOptionPane.showMessageDialog(null, "请选择行");return;

}//调用业务方法删除

service.del(id);

List list=service.findByItem("", null, null);

table.updateLovoTable(list);

}

});

LovoButton updateButton=new LovoButton("修改", 500, 280, this);

updateButton.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent arg0) {int id=table.getKey();if(id==-1)

{

JOptionPane.showMessageDialog(null, "请选择行");return;

}

MainFrame.this.dispose();newupdateFrame(id);

}

});this.setSize(700, 400);this.setVisible(true);this.setLocationRelativeTo(null);this.setDefaultCloseOperation(3);

}public static voidmain(String[] args) {

MainFrame m=newMainFrame();

}

}packagecom.project.frame;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Date;importjavax.swing.JFrame;importcom.lovo.netCRM.component.LovoButton;importcom.lovo.netCRM.component.LovoTxt;importcom.project.bean.ProductBean;importcom.project.service.IProductService;importcom.project.service.Impl.ProductSreviceImpl;public class AddFrame extendsJFrame {/**商品名文本框*/

private LovoTxt nameTxt = new LovoTxt("商品名", 50, 50, this);/**商品价格 文本框*/

private LovoTxt priceTxt = new LovoTxt("商品价格", 50, 100, this);/**商品产地文本框*/

private LovoTxt addressTxt = new LovoTxt("商品产地", 50, 150, this);/**生产日期文本框*/

private LovoTxt dateTxt = new LovoTxt("生产日期", 50, 200, this);private IProductService service=newProductSreviceImpl();publicAddFrame() {this.setLayout(null);

LovoButton addButton= new LovoButton("添加", 100, 250, this);

addButton.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent arg0) {if(check()==false)

{return;

}//界面数据封装成实体对象

ProductBean bean=newProductBean();

System.out.println(nameTxt.getText());

bean.setName(nameTxt.getText());

bean.setPrice(Integer.parseInt(priceTxt.getText()));

bean.setAddress(addressTxt.getText());

bean.setCreateDate(Date.valueOf(dateTxt.getText()));//调用业务方法完成添加

service.add(bean);//卸载窗体

AddFrame.this.dispose();//产生新窗体

newMainFrame();

}

});this.setSize(300, 400);this.setVisible(true);this.setLocationRelativeTo(null);this.setDefaultCloseOperation(3);

}private booleancheck()

{

String info="";if(nameTxt.getText().matches("[\\w\\u4e00-\\u9fa5]{2,}")==false)

{

info+="商品为两个以上的字母、数字、汉子\n";

}if(priceTxt.getText().matches("\\d+")==false)

{

info+="单价必须为数字\n";

}if(addressTxt.getText().matches("[\\w\\u4e00-\\u9fa5]{2,}")==false)

{

info+="产地必须为两个以上的汉子\n";

}if(dateTxt.getText().matches("\\d{4}-\\d{2}-\\d{2}")==false)

{

info+="日期格式XXXX-XX-XX";

}if(info.length()!=0)

{return false;

}return true;

}

}packagecom.project.frame;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JFrame;importcom.lovo.netCRM.component.LovoButton;importcom.lovo.netCRM.component.LovoLabel;importcom.lovo.netCRM.component.LovoTxt;importcom.project.bean.ProductBean;importcom.project.service.IProductService;importcom.project.service.Impl.ProductSreviceImpl;public class updateFrame extendsJFrame {private LovoLabel nameLabel = new LovoLabel("商品名", 50, 20, this);private LovoTxt priceTxt = new LovoTxt("商品单价", 50, 70, this);private LovoLabel addressLabel = new LovoLabel("商品产地", 50, 120, this);private LovoLabel dateLabel = new LovoLabel("生产日期", 50, 170, this);private IProductService service = newProductSreviceImpl();/**需要修改商品的id*/

private intproductId;public updateFrame(intid) {this.productId =id;this.setLayout(null);this.init();

LovoButton updataButton= new LovoButton("修改", 100, 220, this);

updataButton.addActionListener(newActionListener() {

@Overridepublic voidactionPerformed(ActionEvent arg0) {

service.update(productId, Integer.parseInt(priceTxt.getText()));

updateFrame.this.dispose();newMainFrame();

}

});this.setSize(400, 300);this.setVisible(true);this.setLocationRelativeTo(null);this.setDefaultCloseOperation(3);

}/*** 初始化*/

public voidinit() {//按id得到需要修改的商品对象,将商品对象的属性值填充文本

ProductBean bean =service.findById(productId);

nameLabel.setText(bean.getName());

priceTxt.setText(bean.getPrice()+ "");

addressLabel.setText(bean.getAddress());

dateLabel.setText(bean.getCreateDate().toString());

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值