📄 util.java
字号:
}
return id;
}
//获得页数多少
public static int getPageSize(String sql, Session sess) {
int pagesize = 0;
ResultSet rs = null;
PreparedStatement stat = null;
try {
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
rs.next();
pagesize = rs.getInt(1);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
stat.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return pagesize;
}
public static long getStaffId(String staffid, Session sess)
throws BwayHibernateException {
long id = 0;
ResultSet rs = null;
PreparedStatement stat = null;
String sql = "";
try {
sql = "select * from staffinfo where staffid = '" + staffid + "' ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
id = rs.getLong("id");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
stat.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return id;
}
//获得ID号
public static String getTableValueId(String tmpTableName, Session sess)
throws BwayHibernateException {
String id = "0";
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
sql = "update makerconfig set currentvalue = currentvalue +1 where tablename='"
+ tmpTableName + "' ";
sess.connection().createStatement().executeUpdate(sql);
System.out.println("the update sql : " + sql);
sql = "select * from makerconfig where tablename='" + tmpTableName
+ "' ";
System.out.println("the select sql : " + sql);
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
id = String.valueOf(rs.getInt("currentvalue"));
System.out.println("the id: " + id);
}
} catch (Exception e) {
e.printStackTrace();
}
return id;
}
//获得ID号
public static String getTableValueId(String tmpTableName, Connection conn)
throws BwayHibernateException {
String id = "0";
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
sql = "update makerconfig set currentvalue = currentvalue +1 where tablename='"
+ tmpTableName + "' ";
conn.createStatement().executeUpdate(sql);
System.out.println("the update sql : " + sql);
sql = "select * from makerconfig where tablename='" + tmpTableName
+ "' ";
System.out.println("the select sql : " + sql);
stat = conn.prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
id = String.valueOf(rs.getInt("currentvalue"));
System.out.println("the id: " + id);
}
} catch (Exception e) {
e.printStackTrace();
}
return id;
}
//求得当前序列号
public static String getCurrentId(String tmpTableName, String tmpTableFeild)
throws BwayHibernateException {
String currentId = "1000000";
Session sess = null;
ResultSet rs = null;
PreparedStatement stat = null;
Transaction tx = null;
try {
sess = HibernateSessionFactory.currentSession();
tx = sess.beginTransaction();
String sql = "select " + tmpTableFeild + " from " + tmpTableName
+ " order by id desc ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
currentId = rs.getString(tmpTableFeild);
}
currentId = String.valueOf(Integer.parseInt(currentId) + 1);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
} finally {
HibernateSessionFactory.closeSession();
}
return currentId;
}
//是否前台销售或用户不存在或密码错误
public static Staffinfo getStaffInfo(String passwd, String userName)
throws BwayHibernateException {
Staffinfo userInfo = null;
String id = "";
Session sess = null;
PreparedStatement stat = null;
ResultSet rs = null;
String sql = "";
try {
sess = HibernateSessionFactory.currentSession();
sql = "select * from staffinfo where 1= 1 and staffname = '"
+ userName + "' and " + " passward = '" + passwd + "'";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
id = rs.getString("staffid");
if (!"".equals(id) || null != id) {
userInfo = (Staffinfo) sess.get(Staffinfo.class, id);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return userInfo;
}
//员工名字等列表
public static Staffinfo getStaffinfo(HttpServletRequest request,
String staffId) throws BwayHibernateException {
Staffinfo staff = null;
Session sess = null;
try {
staff = new Staffinfo();
sess = HibernateSessionFactory.currentSession();
staff = (Staffinfo) sess.get(Staffinfo.class, staffId);
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return staff;
}
//供应商的对象
public static Merchant getMerchantObject(HttpServletRequest request,
String id) throws BwayHibernateException {
Merchant m = null;
Session sess = null;
try {
sess = HibernateSessionFactory.currentSession();
m = (Merchant) sess.get(Merchant.class, id);
} catch (Exception e) {
e.printStackTrace();
}finally {
HibernateSessionFactory.closeSession();
}
return m;
}
//所在的部门
public static Departments getDepartments(HttpServletRequest request,
String deptId) throws BwayHibernateException {
Departments dept = null;
Session sess = null;
try {
dept = new Departments();
sess = HibernateSessionFactory.currentSession();
dept = (Departments) sess.get(Departments.class, deptId);
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return dept;
}
//所在的员工列表
public static List getStaffList(HttpServletRequest request)
throws BwayHibernateException {
Staffinfo e = null;
List marketList = null;
Session sess = null;
try {
e = new Staffinfo();
sess = HibernateSessionFactory.currentSession();
Criteria criteria = sess.createCriteria(Staffinfo.class);
marketList = criteria.add(Example.create(e)).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return marketList;
}
//树栏目列表
public static List getTreeList(HttpServletRequest request,String staffid)
throws BwayHibernateException {
List marketList = null;
testtree e = new testtree();
Session sess = null;
ResultSet rs = null;
HttpSession usersession = request.getSession();
try {
e.setStaffid(staffid);
sess = HibernateSessionFactory.currentSession();
Criteria criteria = sess.createCriteria(testtree.class);
marketList = criteria.add(Example.create(e)).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return marketList;
}
//档案管理目列表
public static List getFileManagerList(HttpServletRequest request)
throws BwayHibernateException {
List marketList = null;
Filemanager e = new Filemanager();
Session sess = null;
ResultSet rs = null;
HttpSession usersession = request.getSession();
try {
sess = HibernateSessionFactory.currentSession();
Criteria criteria = sess.createCriteria(Filemanager.class);
marketList = criteria.add(Example.create(e)).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return marketList;
}
//图书目列表
public static List getBookManagerList(HttpServletRequest request)
throws BwayHibernateException {
List marketList = null;
Bookmanager e = new Bookmanager();
Session sess = null;
ResultSet rs = null;
HttpSession usersession = request.getSession();
try {
sess = HibernateSessionFactory.currentSession();
Criteria criteria = sess.createCriteria(Bookmanager.class);
marketList = criteria.add(Example.create(e)).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return marketList;
}
//个人文件夹列表
public static List getFolderList(HttpServletRequest request,String staffid)
throws BwayHibernateException {
List marketList = null;
Folders e = new Folders();
Session sess = null;
ResultSet rs = null;
HttpSession usersession = request.getSession();
try {
e.setStaffid(staffid);
sess = HibernateSessionFactory.currentSession();
Criteria criteria = sess.createCriteria(Folders.class);
marketList = criteria.add(Example.create(e)).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return marketList;
}
//部门列表
public static List getDeptTreeList(HttpServletRequest request)
throws BwayHibernateException {
List marketList = null;
Dept e = new Dept();
Session sess = null;
ResultSet rs = null;
HttpSession usersession = request.getSession();
try {
sess = HibernateSessionFactory.currentSession();
Criteria criteria = sess.createCriteria(Dept.class);
marketList = criteria.add(Example.create(e)).list();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return marketList;
}
//求得会员名字
public static String getStaffname(Session sess, String staffid)
throws BwayHibernateException {
String name = null;
ResultSet rs = null;
String sql = "";
try {
sql = "select * from staffinfo where id ='" + staffid + "' ";
rs = sess.connection().createStatement().executeQuery(sql);
if (rs.next()) {
name = rs.getString("staffcnname");
}
} catch (Exception ex) {
ex.printStackTrace();
}
return name;
}
//每个月的基本工资
public static double staffBaseAmount(Session sess, String staffid)
throws BwayHibernateException, BwayException {
double amounts = 0;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
double basewage = 0; //基本工资
double taxs = 0; //扣税
double endowment = 0; //decimal (18, 2),--养老保险
double medical = 0; //decimal (18, 2),--医疗保险
double unemployment = 0; //decimal (18, 2),--失业保险
double houseamount = 0; //decimal (18, 2),--住房工积金
double otheramount = 0; //decimal (18, 2),--其它扣除
sql = "select * from staffwage where staffid ='" + staffid + "' ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
basewage = rs.getDouble("basewage");
taxs = rs.getDouble("taxs");
endowment = rs.getDouble("endowment");
medical = rs.getDouble("medical");
unemployment = rs.getDouble("unemployment");
houseamount = rs.getDouble("houseamount");
otheramount = rs.getDouble("otheramount");
amounts = basewage - taxs - endowment - medical - unemployment
- houseamount - otheramount;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
}
return amounts;
}
//每个月的考勤
public static double staffAttendanceAmount(Session sess, String staffid,
String dates) throws BwayHibernateException, BwayException {
double attendAmounts = 0;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
double deduction = 0;
sql = "select * from staffattendance where staffid ='" + staffid
+ "' and yeathmonth='" + dates + "' ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
while (rs.next()) {
deduction = rs.getDouble("deduction");
attendAmounts = attendAmounts + deduction;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
}
return attendAmounts;
}
//每个月奖
public static double staffAwardAmount(Session sess, String staffid,
String dates) throws BwayHibernateException, BwayException {
double attendAmounts = 0;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
double deduction = 0;
sql = "select * from staffincentive where staffid ='" + staffid
+ "' " + " and yearmonth='" + dates
+ "' and types in(1,2,3,4) ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
while (rs.next()) {
deduction = rs.getDouble("deduction");
attendAmounts = attendAmounts + deduction;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
}
return attendAmounts;
}
//每个月罚
public static double staffPenaltyAmount(Session sess, String staffid,
String dates) throws BwayHibernateException, BwayException {
double attendAmounts = 0;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
double deduction = 0;
sql = "select * from staffincentive where staffid ='" + staffid
+ "' " + " and yearmonth='" + dates
+ "' and types in(5,6,7,8) ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
while (rs.next()) {
deduction = rs.getDouble("deduction");
attendAmounts = attendAmounts + deduction;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
}
return attendAmounts;
}
//每个月借
public static double staffThroughAmount(Session sess, String staffid,
String dates) throws BwayHibernateException, BwayException {
double attendAmounts = 0;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
double deduction = 0;
sql = "select * from staffcontributions where staffid ='" + staffid
+ "' " + " and yearmonth='" + dates + "' ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
while (rs.next()) {
deduction = rs.getDouble("deduction");
attendAmounts = attendAmounts + deduction;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
}
return attendAmounts;
}
//判断这个月是否已发布工资了
public static boolean checkStaffWage(Session sess, String dates)
throws BwayHibernateException, BwayException {
boolean staffwage = false;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
sql = "select * from wageaudit where yearmonth='" + dates + "' ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
staffwage = true;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
}
return staffwage;
}
//判断工资单是否已审核
public static boolean checkStaffWage(HttpServletRequest request,
String wagenumber) throws BwayHibernateException, BwayException {
boolean wages = false;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
Session sess;
try {
sql = "select * from wageaudit where wagenumber = '" + wagenumber
+ "' and auditstatus='2' ";
sess = HibernateSessionFactory.currentSession();
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
wages = true;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
} finally {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -