@ -19,73 +19,73 @@ public class productionImpl implements productionService {
public Vector < Production > findAllproduction ( ) {
Vector < Production > productions = new Vector < Production > ( ) ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
String SQL = "select * from production where delmark = 1" ;
String SQL = "select * from production where delmark = 1" ; // SQL查询语句, 只查询未被删除的商品
PreparedStatement preparedStatement = null ;
ResultSet resultSet = null ;
try {
preparedStatement = conn . prepareStatement ( SQL ) ;
preparedStatement = conn . prepareStatement ( SQL ) ; // 创建PreparedStatement对象
resultSet = preparedStatement . executeQuery ( ) ;
resultSet = preparedStatement . executeQuery ( ) ; // 执行查询,获取结果集
while ( resultSet . next ( ) ) {
while ( resultSet . next ( ) ) { // 遍历结果集
Production production = new Production ( ) ;
production . setId ( resultSet . getString ( "id" ) ) ;
production . setName ( resultSet . getString ( "name" ) ) ;
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ;
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ;
production . setLife ( resultSet . getInt ( "life" ) ) ;
production . setSum ( resultSet . getInt ( "sum" ) ) ;
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ;
production . setId2 ( resultSet . getString ( "id2" ) ) ;
production . setName2 ( resultSet . getString ( "name2" ) ) ;
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ;
productions . add ( production ) ;
production . setId ( resultSet . getString ( "id" ) ) ; // 设置商品ID
production . setName ( resultSet . getString ( "name" ) ) ; // 设置商品名称
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ; // 设置进价
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ; // 设置售价
production . setLife ( resultSet . getInt ( "life" ) ) ; // 设置保质期
production . setSum ( resultSet . getInt ( "sum" ) ) ; // 设置库存数量
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ; // 设置供应商ID
production . setId2 ( resultSet . getString ( "id2" ) ) ; // 设置商品类别ID
production . setName2 ( resultSet . getString ( "name2" ) ) ; // 设置商品类别名称
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ; // 设置删除标记
productions . add ( production ) ; // 将商品信息添加到Vector中
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( resultSet , preparedStatement , conn ) ;
JDBCUtil . close ( resultSet , preparedStatement , conn ) ; // 关闭数据库资源
}
return productions ;
return productions ; // 返回所有商品信息
}
/* 用于收银系统, 通过商品id返回所有信息 */
public Production findByIdProduction ( String id ) {
Production production = new Production ( ) ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
ResultSet resultSet = null ;
try {
preparedStatement = conn
. prepareStatement ( "select * from production where id=? and delmark = 1" ) ;
preparedStatement . setString ( 1 , id ) ;
resultSet = preparedStatement . executeQuery ( ) ;
if ( resultSet . next ( ) ) {
production . setId ( resultSet . getString ( "id" ) ) ;
production . setName ( resultSet . getString ( "name" ) ) ;
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ;
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ;
production . setLife ( resultSet . getInt ( "life" ) ) ;
production . setSum ( resultSet . getInt ( "sum" ) ) ;
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ;
production . setId2 ( resultSet . getString ( "id2" ) ) ;
production . setName2 ( resultSet . getString ( "name2" ) ) ;
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ;
. prepareStatement ( "select * from production where id=? and delmark = 1" ) ; // 查询指定ID且未被删除的商品
preparedStatement . setString ( 1 , id ) ; // 设置查询参数
resultSet = preparedStatement . executeQuery ( ) ; // 执行查询
if ( resultSet . next ( ) ) { // 如果找到商品
production . setId ( resultSet . getString ( "id" ) ) ; // 设置商品ID
production . setName ( resultSet . getString ( "name" ) ) ; // 设置商品名称
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ; // 设置进价
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ; // 设置售价
production . setLife ( resultSet . getInt ( "life" ) ) ; // 设置保质期
production . setSum ( resultSet . getInt ( "sum" ) ) ; // 设置库存数量
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ; // 设置供应商ID
production . setId2 ( resultSet . getString ( "id2" ) ) ; // 设置商品类别ID
production . setName2 ( resultSet . getString ( "name2" ) ) ; // 设置商品类别名称
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ; // 设置删除标记
} else {
System . out . println ( "未找到" ) ;
return null ;
return null ; // 如果未找到商品, 返回null
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( resultSet , preparedStatement , conn ) ;
JDBCUtil . close ( resultSet , preparedStatement , conn ) ; // 关闭数据库资源
}
return production ;
return production ; // 返回商品信息
}
@Override
@ -94,35 +94,35 @@ public class productionImpl implements productionService {
* 由 一 个 商 品 名 查 找 并 输 出 全 部 商 品 信 息
* /
Vector < Production > productions = new Vector < Production > ( ) ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
ResultSet resultSet = null ;
try {
preparedStatement = conn . prepareStatement ( "select * from production where name like ? and delmark = 1" ) ;
String s = '%' + name + '%' ;
preparedStatement . setString ( 1 , s ) ;
resultSet = preparedStatement . executeQuery ( ) ;
preparedStatement = conn . prepareStatement ( "select * from production where name like ? and delmark = 1" ) ; // 模糊查询商品名称
String s = '%' + name + '%' ; // 构造模糊查询字符串
preparedStatement . setString ( 1 , s ) ; // 设置查询参数
resultSet = preparedStatement . executeQuery ( ) ; // 执行查询
while ( resultSet . next ( ) ) {
while ( resultSet . next ( ) ) { // 遍历结果集
Production production = new Production ( ) ;
production . setId ( resultSet . getString ( "id" ) ) ;
production . setName ( resultSet . getString ( "name" ) ) ;
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ;
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ;
production . setLife ( resultSet . getInt ( "life" ) ) ;
production . setSum ( resultSet . getInt ( "sum" ) ) ;
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ;
production . setId2 ( resultSet . getString ( "id2" ) ) ;
production . setName2 ( resultSet . getString ( "name2" ) ) ;
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ;
productions . add ( production ) ;
production . setId ( resultSet . getString ( "id" ) ) ; // 设置商品ID
production . setName ( resultSet . getString ( "name" ) ) ; // 设置商品名称
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ; // 设置进价
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ; // 设置售价
production . setLife ( resultSet . getInt ( "life" ) ) ; // 设置保质期
production . setSum ( resultSet . getInt ( "sum" ) ) ; // 设置库存数量
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ; // 设置供应商ID
production . setId2 ( resultSet . getString ( "id2" ) ) ; // 设置商品类别ID
production . setName2 ( resultSet . getString ( "name2" ) ) ; // 设置商品类别名称
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ; // 设置删除标记
productions . add ( production ) ; // 将商品信息添加到Vector中
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( resultSet , preparedStatement , conn ) ;
JDBCUtil . close ( resultSet , preparedStatement , conn ) ; // 关闭数据库资源
}
return productions ;
return productions ; // 返回所有匹配的商品信息
}
@Override
@ -131,34 +131,34 @@ public class productionImpl implements productionService {
* /
public Production findByNameProduction ( String name ) {
Production production = new Production ( ) ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
ResultSet resultSet = null ;
try {
preparedStatement = conn
. prepareStatement ( "select * from production where name=?" ) ;
preparedStatement . setString ( 1 , name ) ;
resultSet = preparedStatement . executeQuery ( ) ;
if ( resultSet . next ( ) ) {
production . setId ( resultSet . getString ( "id" ) ) ;
production . setName ( resultSet . getString ( "name" ) ) ;
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ;
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ;
production . setLife ( resultSet . getInt ( "life" ) ) ;
production . setSum ( resultSet . getInt ( "sum" ) ) ;
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ;
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ;
. prepareStatement ( "select * from production where name=?" ) ; // 精确查询商品名称
preparedStatement . setString ( 1 , name ) ; // 设置查询参数
resultSet = preparedStatement . executeQuery ( ) ; // 执行查询
if ( resultSet . next ( ) ) { // 如果找到商品
production . setId ( resultSet . getString ( "id" ) ) ; // 设置商品ID
production . setName ( resultSet . getString ( "name" ) ) ; // 设置商品名称
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ; // 设置进价
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ; // 设置售价
production . setLife ( resultSet . getInt ( "life" ) ) ; // 设置保质期
production . setSum ( resultSet . getInt ( "sum" ) ) ; // 设置库存数量
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ; // 设置供应商ID
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ; // 设置删除标记
} else {
return null ;
return null ; // 如果未找到商品, 返回null
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( resultSet , preparedStatement , conn ) ;
JDBCUtil . close ( resultSet , preparedStatement , conn ) ; // 关闭数据库资源
}
return production ;
return production ; // 返回商品信息
}
@Override
@ -167,39 +167,39 @@ public class productionImpl implements productionService {
* /
public int addProduction ( Production p ) {
int flag = 0 ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
PreparedStatement preparedStatement1 = null ;
ResultSet resultSet1 = null ;
ResultSet resultSet1 = null ;
// 假设商品不存在
try {
preparedStatement1 = conn . prepareStatement ( "select * from production where id=?" ) ;
preparedStatement1 . setString ( 1 , p . getId ( ) ) ;
resultSet1 = preparedStatement1 . executeQuery ( ) ;
if ( resultSet1 . next ( ) ) {
return flag = 2 ;
preparedStatement1 = conn . prepareStatement ( "select * from production where id=?" ) ; // 检查商品是否已存在
preparedStatement1 . setString ( 1 , p . getId ( ) ) ; // 设置查询参数
resultSet1 = preparedStatement1 . executeQuery ( ) ; // 执行查询
if ( resultSet1 . next ( ) ) {
return flag = 2 ; // 如果商品已存在, 返回2
}
preparedStatement = conn . prepareStatement ( "insert into production values(?,?,?,?,?,?,?,?,?,?,?)" ) ;
preparedStatement . setString ( 1 , p . getId ( ) ) ;
preparedStatement . setString ( 2 , p . getName ( ) ) ;
preparedStatement . setFloat ( 3 , p . getInPrice ( ) ) ;
preparedStatement . setFloat ( 4 , p . getOutPrice ( ) ) ;
preparedStatement . setInt ( 5 , p . getLife ( ) ) ;
preparedStatement . setInt ( 6 , p . getSum ( ) ) ;
preparedStatement . setInt ( 7 , p . getSupplyId ( ) ) ;
preparedStatement . setString ( 8 , p . getId2 ( ) ) ;
preparedStatement . setString ( 9 , p . getName2 ( ) ) ;
preparedStatement . setFloat ( 10 , 0 ) ;
preparedStatement . setInt ( 11 , 1 ) ;
preparedStatement . executeUpdate ( ) ;
flag = 1 ;
preparedStatement = conn . prepareStatement ( "insert into production values(?,?,?,?,?,?,?,?,?,?,?)" ) ; // 插入新商品
preparedStatement . setString ( 1 , p . getId ( ) ) ; // 设置商品ID
preparedStatement . setString ( 2 , p . getName ( ) ) ; // 设置商品名称
preparedStatement . setFloat ( 3 , p . getInPrice ( ) ) ; // 设置进价
preparedStatement . setFloat ( 4 , p . getOutPrice ( ) ) ; // 设置售价
preparedStatement . setInt ( 5 , p . getLife ( ) ) ; // 设置保质期
preparedStatement . setInt ( 6 , p . getSum ( ) ) ; // 设置库存数量
preparedStatement . setInt ( 7 , p . getSupplyId ( ) ) ; // 设置供应商ID
preparedStatement . setString ( 8 , p . getId2 ( ) ) ; // 设置商品类别ID
preparedStatement . setString ( 9 , p . getName2 ( ) ) ; // 设置商品类别名称
preparedStatement . setFloat ( 10 , 0 ) ; // 设置未知字段
preparedStatement . setInt ( 11 , 1 ) ; // 设置删除标记为1( 未删除)
preparedStatement . executeUpdate ( ) ; // 执行插入
flag = 1 ; // 插入成功, 返回1
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( null , preparedStatement , conn ) ;
JDBCUtil . close ( null , preparedStatement , conn ) ; // 关闭数据库资源
}
return flag ;
return flag ; // 返回操作结果
}
@Override
@ -208,22 +208,21 @@ public class productionImpl implements productionService {
* /
public int deleteProduction ( String id ) {
int flag = 0 ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
try {
preparedStatement = conn
. prepareStatement ( "delete from production where id = ?" ) ;
preparedStatement . setString ( 1 , id ) ;
preparedStatement . executeUpdate ( ) ;
flag = 1 ;
. prepareStatement ( "delete from production where id = ?" ) ; // 删除指定ID的商品
preparedStatement . setString ( 1 , id ) ; // 设置查询参数
preparedStatement . executeUpdate ( ) ; // 执行删除
flag = 1 ; // 删除成功, 返回1
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( null , preparedStatement , conn ) ;
JDBCUtil . close ( null , preparedStatement , conn ) ; // 关闭数据库资源
}
return flag ;
return flag ; // 返回操作结果
}
@Override
@ -232,98 +231,99 @@ public class productionImpl implements productionService {
* /
public int updateProduction ( Production p ) {
int flag = 0 ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
try {
preparedStatement = conn
. prepareStatement ( "update production set name=?,inPrice=?,OutPrice=?,life=?,sum=?,delmark=? where id = ? and supplyId=?" ) ;
. prepareStatement ( "update production set name=?,inPrice=?,OutPrice=?,life=?,sum=?,delmark=? where id = ? and supplyId=?" ) ; // 更新商品信息
preparedStatement . setString ( 1 , p . getName ( ) ) ;
preparedStatement . setFloat ( 2 , p . getInPrice ( ) ) ;
preparedStatement . setFloat ( 3 , p . getOutPrice ( ) ) ;
preparedStatement . setInt ( 4 , p . getLife ( ) ) ;
preparedStatement . setInt ( 5 , p . getSum ( ) ) ;
preparedStatement . setInt ( 6 , p . getDelmark ( ) ) ;
preparedStatement . setString ( 7 , p . getId ( ) ) ;
preparedStatement . setInt ( 8 , p . getSupplyId ( ) ) ;
preparedStatement . setString ( 1 , p . getName ( ) ) ; // 设置商品名称
preparedStatement . setFloat ( 2 , p . getInPrice ( ) ) ; // 设置进价
preparedStatement . setFloat ( 3 , p . getOutPrice ( ) ) ; // 设置售价
preparedStatement . setInt ( 4 , p . getLife ( ) ) ; // 设置保质期
preparedStatement . setInt ( 5 , p . getSum ( ) ) ; // 设置库存数量
preparedStatement . setInt ( 6 , p . getDelmark ( ) ) ; // 设置删除标记
preparedStatement . setString ( 7 , p . getId ( ) ) ; // 设置商品ID
preparedStatement . setInt ( 8 , p . getSupplyId ( ) ) ; // 设置供应商ID
preparedStatement . executeUpdate ( ) ;
flag = 1 ;
preparedStatement . executeUpdate ( ) ; // 执行更新
flag = 1 ; // 更新成功, 返回1
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( null , preparedStatement , conn ) ;
JDBCUtil . close ( null , preparedStatement , conn ) ; // 关闭数据库资源
}
return flag ;
return flag ; // 返回操作结果
}
@Override
public Vector < Production > findProductionById2 ( String id ) {
/ * *
* 由 一 个 商 品 类 别 id2 查 找 并 输 出 全 部 商 品
* 由 一 个 商 品 类 别 id2 查 找 并 输 出 全 部 商 品
* /
Vector < Production > productions = new Vector < Production > ( ) ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
ResultSet resultSet = null ;
try {
if ( id . equals ( "0" ) )
preparedStatement = conn . prepareStatement ( "select * from production where delmark = 1" ) ;
else
{ preparedStatement = conn . prepareStatement ( "select * from production where id2= ? and delmark = 1" ) ;
preparedStatement . setString ( 1 , id ) ; }
resultSet = preparedStatement . executeQuery ( ) ;
while ( resultSet . next ( ) ) {
if ( id . equals ( "0" ) )
preparedStatement = conn . prepareStatement ( "select * from production where delmark = 1" ) ; // 查询所有未删除的商品
else {
preparedStatement = conn . prepareStatement ( "select * from production where id2= ? and delmark = 1" ) ; // 查询指定类别ID且未删除的商品
preparedStatement . setString ( 1 , id ) ; // 设置查询参数
}
resultSet = preparedStatement . executeQuery ( ) ; // 执行查询
while ( resultSet . next ( ) ) { // 遍历结果集
Production production = new Production ( ) ;
production . setId ( resultSet . getString ( "id" ) ) ;
production . setName ( resultSet . getString ( "name" ) ) ;
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ;
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ;
production . setLife ( resultSet . getInt ( "life" ) ) ;
production . setSum ( resultSet . getInt ( "sum" ) ) ;
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ;
production . setId2 ( resultSet . getString ( "id2" ) ) ;
production . setName2 ( resultSet . getString ( "name2" ) ) ;
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ;
productions . add ( production ) ;
production . setId ( resultSet . getString ( "id" ) ) ; // 设置商品ID
production . setName ( resultSet . getString ( "name" ) ) ; // 设置商品名称
production . setInPrice ( resultSet . getFloat ( "inPrice" ) ) ; // 设置进价
production . setOutPrice ( resultSet . getFloat ( "OutPrice" ) ) ; // 设置售价
production . setLife ( resultSet . getInt ( "life" ) ) ; // 设置保质期
production . setSum ( resultSet . getInt ( "sum" ) ) ; // 设置库存数量
production . setSupplyId ( resultSet . getInt ( "supplyId" ) ) ; // 设置供应商ID
production . setId2 ( resultSet . getString ( "id2" ) ) ; // 设置商品类别ID
production . setName2 ( resultSet . getString ( "name2" ) ) ; // 设置商品类别名称
production . setDelmark ( resultSet . getInt ( "delmark" ) ) ; // 设置删除标记
productions . add ( production ) ; // 将商品信息添加到Vector中
}
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( resultSet , preparedStatement , conn ) ;
JDBCUtil . close ( resultSet , preparedStatement , conn ) ; // 关闭数据库资源
}
return productions ;
return productions ; // 返回所有匹配的商品信息
}
@Override
/ * *
* 更 新 商 品 数 量 和 价 格
* /
public boolean updateProductionSum ( String prodId , int sum ) {
public boolean updateProductionSum ( String prodId , int sum ) {
boolean flag = false ;
Connection conn = JDBCUtil . getConn ( ) ;
Connection conn = JDBCUtil . getConn ( ) ; // 获取数据库连接
PreparedStatement preparedStatement = null ;
try {
preparedStatement = conn
. prepareStatement ( "update production set sum=?+(select sum from(select sum from production where id = ? and delmark=1 ) p) where id = ? and delmark=1;" ) ;
. prepareStatement ( "update production set sum=?+(select sum from(select sum from production where id = ? and delmark=1 ) p) where id = ? and delmark=1;" ) ; // 更新商品库存数量
preparedStatement . setInt ( 1 , sum ) ;
preparedStatement . setString ( 2 , prodId ) ;
preparedStatement . setString ( 3 , prodId ) ;
preparedStatement . setInt ( 1 , sum ) ; // 设置新增库存数量
preparedStatement . setString ( 2 , prodId ) ; // 设置商品ID
preparedStatement . setString ( 3 , prodId ) ; // 设置商品ID
if ( preparedStatement . executeUpdate ( ) = = 1 ) ;
flag = true ;
if ( preparedStatement . executeUpdate ( ) = = 1 )
flag = true ; // 更新成功, 返回true
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
} finally {
JDBCUtil . close ( null , preparedStatement , conn ) ;
JDBCUtil . close ( null , preparedStatement , conn ) ; // 关闭数据库资源
}
return flag ;
return flag ; // 返回操作结果
}
}
}