📄 common.java
字号:
package restaurant;
import java.io.*;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Calendar;
import java.util.Vector;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Common{
private DBCon con;
private Read read;
private Write write;
private Exit exit;
public boolean check(String id,String password){
ResultSet rs=null;
id=toChinese(id);
password=toChinese(password);
if(userExist(id)){
String sql="select * from operator where id='"+id+"' AND password='"+password+"'";
con = new DBCon();
read = new Read(con.getConnection());
rs=read.executeQuery(sql);
try{
if(rs.next()){
exit = new Exit(con.getConnection());
exit.Close();
return true;
}
else
return false;
}catch(SQLException e){
System.err.println(e.getMessage());
}
}
else{
return false;
}
return false;
}
public boolean userExist(String userID){
String sql="select * from operator where id='"+userID+"'";
ResultSet rs=null;
con = new DBCon();
read = new Read(con.getConnection());
rs=read.executeQuery(sql);
try{
if(rs.next()){
exit = new Exit(con.getConnection());
exit.Close();
return true;
}
}catch(SQLException e){
System.err.println(e.getMessage());
}
return false;
}
public boolean isManager(String userID){
userID=toChinese(userID);
String sql="select * from operator where id='"+userID+"'";
ResultSet rs=null;
boolean flag=false;
con = new DBCon();
read = new Read(con.getConnection());
rs=read.executeQuery(sql);
try{
if(rs.next()){
if(rs.getString("type").equals("manager"))
flag=true;
else
flag=false;
exit = new Exit(con.getConnection());
exit.Close();
return flag;
}
}catch(SQLException e){
System.err.println(e.getMessage());
}
return false;
}
public boolean roomOccupied(String roomNo){
String sql="select bookNo from roomBook where roomNo='"+roomNo+"'";
ResultSet rs=null;
con = new DBCon();
read = new Read(con.getConnection());
rs=read.executeQuery(sql);
try{
if(rs.next()){
exit = new Exit(con.getConnection());
exit.Close();
return true;
}
}catch(SQLException e){
System.err.println(e.getMessage());
}
return false;
}
public void WriteSystemLog(String message){
String sql="insert into system values('"+message+"')";
con = new DBCon();
write = new Write(con.getConnection());
write.executeUpdate(sql);
exit = new Exit(con.getConnection());
exit.Close();
}
public boolean haveFood(String foodName){
String sql="select * from food where name='"+foodName+"'";
ResultSet rs=null;
con = new DBCon();
read = new Read(con.getConnection());
rs=read.executeQuery(sql);
try{
if(rs.next()){
exit = new Exit(con.getConnection());
exit.Close();
return true;
}
}catch(SQLException e){
System.err.println(e.getMessage());
}
return false;
}
public boolean roomExist(String removeID){
String sql="select * from roomBook where roomNo='"+removeID+"'";
ResultSet rs=null;
con = new DBCon();
read = new Read(con.getConnection());
rs=read.executeQuery(sql);
try{
if(rs.next()){
exit = new Exit(con.getConnection());
exit.Close();
return true;
}
}catch(SQLException e){
System.err.println(e.getMessage());
}
return false;
}
public String getNowTime(){
Calendar t=Calendar.getInstance();
String str=t.get(Calendar.YEAR)+"-"+t.get(Calendar.MONTH)+"-"+t.get(Calendar.DATE);
return str;
}
public int getNowPage(Vector vec,int rowsCols,String Page,String go,String goPage){
int totalPage;
int nowPage=1;
if(vec.size()%rowsCols==0)
totalPage=vec.size()/rowsCols;
else
totalPage=vec.size()/rowsCols+1;
if(!Page.equals("no"))
{
nowPage=Integer.parseInt(Page);
}
if(!go.equals("no"))
{
if(!goPage.equals("no"))
{
nowPage=Integer.parseInt(goPage);
if(nowPage>totalPage) nowPage=totalPage;
if(nowPage<1) nowPage=1;
}
}
if(nowPage<1) nowPage=1;
if(nowPage>totalPage) nowPage=totalPage;
return nowPage;
}
public int getTotalPage(Vector vec,int rowsCols){
if(vec.size()%rowsCols==0)
return vec.size()/rowsCols;
else
return vec.size()/rowsCols+1;
}
public String toChinese(String str)
{
try{
byte[] temp;
temp=str.getBytes("ISO-8859-1");
str=new String(temp);
}catch(Exception e)
{
e.toString();
}
return str;
}
public boolean isNumber(String str)
{
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() )
{
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -