dbdco.java
来自「海鲜超市管理系统是不个错的超市管理系统」· Java 代码 · 共 1,111 行 · 第 1/2 页
JAVA
1,111 行
/*
* 创建日期 2006-10-27
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package dco;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import conn.DBConn;
import dto.IncoAndDept;
import util.PageControl;
import dto.VendorDto;
import dto.BillDto;
import dto.BillitemDto;
/**
* @author www
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class DBDco
{
// 用户权限管理表查询
public int check(String userName, String passWord)
{
Connection co = null;
PreparedStatement ps = null;
ResultSet rs = null;
int flg = 0;
String sql = " SELECT USERNAME,PASSWORD,FLAG FROM SHOP_USER WHERE USERNAME = ? AND PASSWORD = ? ";
try
{
co = DBConn.getConn();
ps = co.prepareStatement(sql);
ps.setString(1,userName);
ps.setString(2,passWord);
rs = ps.executeQuery();
if (rs.next())
{
flg = rs.getInt("FLAG");
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
ps.close();
co.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
return flg;
}
// 用于提取部门和部门收入信息表的相关信息
public int sumNote = 0;
public List sele(String str,String curpage)
{
PageControl pageControl = new PageControl();
Connection co = null;
PreparedStatement ps = null;
ResultSet rs = null;
List list = new ArrayList();
String sql = " SELECT I.DAILY_INCOME,I.DAILY_INCOME||'$' A,TO_CHAR(I.BUSINESS_DATE,'MM/DD/YYYY') B,TO_CHAR(I.LST_MOD_TIMESTEMP,'MM/DD/YYYY') C,D.DEPT_NAME D,I.INCOME_ID E " +
" FROM TABLE_INCOME I,TABLE_DEPT D WHERE I.DEPT_ID = D.DEPT_ID(+) " + str;
try
{
co = DBConn.getConn();
ps = co.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = ps.executeQuery();
rs.absolute(-1);
sumNote = rs.getRow();
pageControl.init(Integer.parseInt(curpage),sumNote);
if (sumNote > 0)
{
if (pageControl.getStart() == 0)
{
rs.absolute(1);
}
else
{
rs.absolute(pageControl.getStart());
}
}
do
{
IncoAndDept ia = new IncoAndDept();
ia.setDaily_income(rs.getString("A"));
ia.setBusiness_date(rs.getString("B"));
ia.setLst_mod_timestemp(rs.getString("C"));
ia.setDept_name(rs.getString("D"));
ia.setIncome_ID(Integer.toString(rs.getInt("E")));
list.add(ia);
if (!rs.next())
{
break;
}
}while (rs.getRow() < pageControl.getEnd()+1);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
ps.close();
co.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
return list;
}
// 部门表中部门名称提取,带分页
public List seleD(String curpage)
{
sumNote = 0;
PageControl pageControl = new PageControl();
Connection co = null;
PreparedStatement ps = null;
ResultSet rs = null;
List list = new ArrayList();
String sql = " SELECT D.Dept_ID I,D.DEPT_NAME D,D.DEPT_DESCREPTION E FROM TABLE_DEPT D ORDER BY D ";
try
{
co = DBConn.getConn();
ps = co.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = ps.executeQuery();
rs.absolute(-1);
sumNote = rs.getRow();
pageControl.init(Integer.parseInt(curpage),sumNote);
if (sumNote > 0)
{
if (pageControl.getStart() == 0)
{
rs.absolute(1);
}
else
{
rs.absolute(pageControl.getStart());
}
}
do
{
IncoAndDept ia = new IncoAndDept();
ia.setDept_ID(rs.getString("i"));
ia.setDept_name(rs.getString("D"));
ia.setDept_descreption(rs.getString("E"));
list.add(ia);
if (!rs.next())
{
break;
}
}while (rs.getRow() < pageControl.getEnd()+1);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
ps.close();
co.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
return list;
}
// 部门表中部门名称提取,不带分页
public List seleD()
{
Connection co = null;
PreparedStatement ps = null;
ResultSet rs = null;
List list = new ArrayList();
String sql = " SELECT D.Dept_ID I,D.DEPT_NAME D,D.DEPT_DESCREPTION E FROM TABLE_DEPT D ORDER BY D ";
try
{
co = DBConn.getConn();
ps = co.prepareStatement(sql);
rs = ps.executeQuery();
IncoAndDept ia = null;
while (rs.next())
{
ia = new IncoAndDept();
ia.setDept_ID(rs.getString("i"));
ia.setDept_name(rs.getString("D"));
list.add(ia);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
ps.close();
co.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
return list;
}
// 往Table_dept表中插入获取的信息
public int inseD(String dept_Id,String daliy_Income)
{
Connection co = null;
PreparedStatement ps = null;
int flg = 0;
String sql = " INSERT INTO TABLE_INCOME VALUES(INCOME_SEQ.NEXTVAL,?,?,SYSDATE,SYSDATE) ";
try
{
co = DBConn.getConn();
co.setAutoCommit(false);
ps = co.prepareStatement(sql);
ps.setInt(1,Integer.parseInt(dept_Id));
ps.setDouble(2,Double.parseDouble(daliy_Income));
flg = ps.executeUpdate();
co.commit();
}
catch (Exception e)
{
try
{
co.rollback();
}
catch (Exception e1)
{
e1.printStackTrace();
}
e.printStackTrace();
}
finally
{
try
{
ps.close();
co.close();
}
catch (Exception e2)
{
e2.printStackTrace();
}
}
return flg;
}
// 跟据所补获信息,修改Table_Income表中的信息值
public int updaD(String income_ID,String dept_Id,String daliy_Income)
{
Connection co = null;
PreparedStatement ps = null;
int flg = 0;
String sql = " UPDATE TABLE_INCOME SET DEPT_ID=?,DAILY_INCOME=?,LST_MOD_TIMESTEMP=SYSDATE WHERE INCOME_ID=? ";
try
{
co = DBConn.getConn();
co.setAutoCommit(false);
ps = co.prepareStatement(sql);
ps.setInt(1,Integer.parseInt(dept_Id));
ps.setDouble(2,Double.parseDouble(daliy_Income));
ps.setInt(3,Integer.parseInt(income_ID));
flg = ps.executeUpdate();
co.commit();
}
catch (Exception e)
{
try
{
co.rollback();
}
catch (Exception e1)
{
e1.printStackTrace();
}
e.printStackTrace();
}
finally
{
try
{
ps.close();
co.close();
}
catch (Exception e2)
{
e2.printStackTrace();
}
}
return flg;
}
// 插入部门表信息
public int inseDe(String dept_Name,String dept_Descreption)
{
Connection co = null;
PreparedStatement ps = null;
int flg = 0;
String sql = " INSERT INTO TABLE_DEPT VALUES(DEPT_SEQ.NEXTVAL,?,?) ";
try
{
co = DBConn.getConn();
co.setAutoCommit(false);
ps = co.prepareStatement(sql);
ps.setString(1,dept_Name);
ps.setString(2,dept_Descreption);
flg = ps.executeUpdate();
co.commit();
}
catch (Exception e)
{
try
{
co.rollback();
}
catch (Exception e1)
{
e1.printStackTrace();
}
e.printStackTrace();
}
finally
{
try
{
ps.close();
co.close();
}
catch (Exception e2)
{
e2.printStackTrace();
}
}
return flg;
}
// 修改部门表
public int updaDe(String Dept_ID,String Dept_name,String Dept_desc)
{
Connection co = null;
PreparedStatement ps = null;
int flg = 0;
String sql = " UPDATE TABLE_DEPT SET Dept_name=?,Dept_descreption=? WHERE Dept_ID=? ";
try
{
co = DBConn.getConn();
co.setAutoCommit(false);
ps = co.prepareStatement(sql);
ps.setString(1,Dept_name);
ps.setString(2,Dept_desc);
ps.setInt(3,Integer.parseInt(Dept_ID));
flg = ps.executeUpdate();
co.commit();
}
catch (Exception e)
{
try
{
co.rollback();
}
catch (Exception e1)
{
e1.printStackTrace();
}
e.printStackTrace();
}
finally
{
try
{
ps.close();
co.close();
}
catch (Exception e2)
{
e2.printStackTrace();
}
}
return flg;
}
// 供应商信息提取,带分页
public List seleV(String curpage)
{
sumNote = 0;
PageControl pageControl = new PageControl();
Connection co = null;
PreparedStatement ps = null;
ResultSet rs = null;
List list = new ArrayList();
String sql = " SELECT VENDOR_ID ID,VENDOR_NAME NAME,VENDOR_ADDRESS ADDRESS,VENDOR_PHONE PHONE,VENDOR_FAS FAS,VENDOR_CONTACT_PERSON PERSON "+
" FROM TABLE_VENDOR ORDER BY NAME ";
try
{
co = DBConn.getConn();
ps = co.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = ps.executeQuery();
rs.absolute(-1);
sumNote = rs.getRow();
pageControl.init(Integer.parseInt(curpage),sumNote);
if (sumNote > 0)
{
if (pageControl.getStart() == 0)
{
rs.absolute(1);
}
else
{
rs.absolute(pageControl.getStart());
}
}
do
{
VendorDto ia = new VendorDto();
ia.setVendor_Id(Integer.toString(rs.getInt("ID")));
ia.setVendor_Name(rs.getString("NAME"));
ia.setVendor_Person(rs.getString("PERSON"));
ia.setVendor_Address(rs.getString("ADDRESS"));
ia.setVendor_Phone(rs.getString("PHONE"));
ia.setVendor_Fas(rs.getString("FAS"));
list.add(ia);
if (!rs.next())
{
break;
}
}while (rs.getRow() < pageControl.getEnd()+1);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
ps.close();
co.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
return list;
}
// 查询供应商信息
public List seleV()
{
Connection co = null;
PreparedStatement ps = null;
ResultSet rs = null;
List list = new ArrayList();
String sql = " SELECT VENDOR_ID ID,VENDOR_NAME NAME,VENDOR_ADDRESS ADDRESS,VENDOR_PHONE PHONE,VENDOR_FAS FAS,VENDOR_CONTACT_PERSON PERSON "+
" FROM TABLE_VENDOR ORDER BY NAME ";
try
{
co = DBConn.getConn();
ps = co.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next())
{
VendorDto ia = new VendorDto();
ia.setVendor_Id(Integer.toString(rs.getInt("ID")));
ia.setVendor_Name(rs.getString("NAME"));
list.add(ia);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
ps.close();
co.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
return list;
}
// 根据供应商ID,查询供应商名称
public String seleV(long vendor_ID)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?