📄 dosp.java
字号:
package cn.aiqinzhe;
import java.sql.*;
import java.util.*;
import java.util.Date;
public class DoSp extends ExeDB{
private ResultSet rs ;
private String strSql;
private PreparedStatement pstmt;
public DoSp()
{
this.strSql="";
rs=null;
pstmt=null;
}
//取得所有商品
public Collection getSps()throws SQLException{
ArrayList<SpDX> splist = null;
try{
splist = new ArrayList<SpDX>();
this.strSql="select * from sp order by id desc";
rs= super.exeSqlQuery(this.strSql);
while (rs.next()){
SpDX sp= new SpDX(rs.getInt(1),
rs.getString(2),
rs.getFloat(3),
rs.getInt(4),
rs.getDate(5),
rs.getString(6),
rs.getString(7),
rs.getString(8));
splist.add(sp);
}
return splist;
}catch(Exception ex)
{
System.out.println(ex.toString());
return splist;
}
}
//取得商品
public SpDX getSp(int id) throws SQLException
{
try
{
this.strSql="select * from sp";
this.strSql=this.strSql + " where id='" + id + "'";
rs= super.exeSqlQuery(this.strSql);
if(rs.next())
{
SpDX sp= new SpDX(rs.getInt(1),
rs.getString(2),
rs.getFloat(3),
rs.getInt(4),
rs.getDate(5),
rs.getString(6),
rs.getString(7),
rs.getString(8));
return sp;
}
else return new SpDX();
}catch(Exception ex)
{
System.out.println(ex.toString());
return new SpDX();
}
}
//分类显示商品
public Collection getSpFl(String fl)throws SQLException{
String fl2="";
if(fl.equals("tushu")) fl2="图书";
if(fl.equals("shouji")) fl2="手机";
if(fl.equals("bijiben")) fl2="笔记本电脑";
if(fl.equals("qita")) fl2="其他";
if(fl.equals("shenghuo")) fl2="生活用品";
ArrayList<SpDX> spfl = null;
try{
spfl = new ArrayList<SpDX>();
this.strSql="select * from sp";
this.strSql=this.strSql + " where fl='" + fl2 + "'";
rs= super.exeSqlQuery(this.strSql);
while (rs.next()){
SpDX sp= new SpDX(rs.getInt(1),
rs.getString(2),
rs.getFloat(3),
rs.getInt(4),
rs.getDate(5),
rs.getString(6),
rs.getString(7),
rs.getString(8));
spfl.add(sp);
}
return spfl;
}catch(Exception ex)
{
System.out.println(ex.toString());
return spfl;
}
}
//查找商品
public Collection getCha(String key)throws SQLException{
ArrayList<SpDX> spcha = null;
try{
spcha = new ArrayList<SpDX>();
this.strSql="select * from sp";
this.strSql=this.strSql + " where name like '%" + key + "%'";
rs= super.exeSqlQuery(this.strSql);
while (rs.next()){
SpDX sp= new SpDX(rs.getInt(1),
rs.getString(2),
rs.getFloat(3),
rs.getInt(4),
rs.getDate(5),
rs.getString(6),
rs.getString(7),
rs.getString(8));
spcha.add(sp);
}
return spcha;
}catch(Exception ex)
{
System.out.println(ex.toString());
return spcha;
}
}
//库存足够不
public boolean isSl(int id,int sm)throws SQLException{
boolean bo = false;
try{
this.strSql="select sl from sp";
this.strSql=this.strSql + " where id='" + id + "'";
rs= super.exeSqlQuery(this.strSql);
if(rs.next()){
int sl= rs.getInt(1);
if(sl >= sm) bo = true;
}
return bo;
}catch(Exception ex)
{
System.out.println(ex.toString());
return bo;
}
}
//购买
public synchronized void buySp(Gouwuche gwc)throws SQLException{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -