⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectnet.java

📁 网吧管理系统. 实现了网吧收费的管理.每小时设置2元,不足1小时扣除2元,1小时5分内扣除2元,以后扣除两小时的4元.
💻 JAVA
字号:
package com.liu.Cortrol;


import java.sql.*;
import java.util.ArrayList;

import Bean.*;

public class SelectNet {
	Statement sm;
	ResultSet rs;
	Card card;
	Record record = new Record();
	
	Conncetion conn = new Conncetion();
	//传入帐号密码查询卡的信息
	public Card getCard(int id,int password){
		try{
		conn.Conncentionsql();
		rs = conn.s.executeQuery("select * from Card where card_id ="+ id +"and password ="+ password);
			while(rs.next())
			{
				card = new Card();
				card.setCard_id(id);
				System.out.println("1111");	
				card.setPassword(rs.getString("password"));
				card.setMoney(rs.getInt("money"));
				card.setName(rs.getString("name"));
					
			}	
		}
		catch(SQLException sqle){
			sqle.printStackTrace();
		}finally{
		conn.close();
		return card;
		}
	}
	
	public int getCard2(int card_id){
		int i =0;
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Card where card_id ="+ card_id );
				while(rs.next())
				{
					i = rs.getInt("money");
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return i;
			}	
	}
	
	
	
	//查询记录表里面的时间
	public float getRecord(int computer_id){
		float f =0;
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Record where computer_id ="+ computer_id );
				while(rs.next())
				{
					Record record = new Record();
					System.out.println("1111");	
					float f1 =rs.getFloat("begintime");
					float f2 =rs.getFloat("endtime");
					f = f2 - f1;
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return f;
			}
	}
	
	public int getRecord2(int computer_id){
		int i =0;
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Record where computer_id ="+ computer_id );
				while(rs.next())
				{
					i = rs.getInt("card_id");
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return i;
			}	
	}
	
	public int getcost(int computer_id){
		int i =0;
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Record where computer_id ="+ computer_id );
				while(rs.next())
				{
					i = rs.getInt("cost");
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return i;
			}	
	}
	public String getbegintime(int computer_id){
		String s = "";
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Record where computer_id ="+ computer_id );
				while(rs.next())
				{
					s = rs.getString("begint");
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return s;
			}	
	}
	public String getendtime(int computer_id){
		String s ="";
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Record where computer_id ="+ computer_id );
				while(rs.next())
				{
					s = rs.getString("endt");
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return s;
			}	
	}
	
	//查询空闲电脑。
	public ArrayList getComputer(){
		ArrayList al = new ArrayList();
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Computer where useing ='"+ "0'");
				while(rs.next())
				{
					Computer computer = new Computer();	
					computer.setComputer_id(rs.getInt("Computer_id"));
					computer.setUseing(rs.getInt("useing"));
					computer.setRemark(rs.getString("remark"));
					al.add(computer);
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return al;
			}
	}
	//查询使用中电脑
	public ArrayList getComputer2(){
		ArrayList al = new ArrayList();
		try{
			conn.Conncentionsql();
			rs = conn.s.executeQuery("select * from Computer where useing ='"+ "1'");
				while(rs.next())
				{
					Computer computer = new Computer();	
					computer.setComputer_id(rs.getInt("Computer_id"));
					computer.setUseing(rs.getInt("useing"));
					computer.setRemark(rs.getString("remark"));
					al.add(computer);
				}	
			}
			catch(SQLException sqle){
				sqle.printStackTrace();
			}finally{
			conn.close();
			return al;
			}
	}
	//创建使用电脑于卡的联系。
	public int setRecord(Record record){
		try{
			System.out.println("正在插入数据");
			String sql = "insert into Record(Card_id,Computer_id,begintime,begint) values ("
				+record.getCard_id()+","+record.getComputer_id()+","+record.getBegintime()+",'"
				+record.getBegint()+"')";
			conn.Conncentionsql();
			int i = conn.s.executeUpdate(sql);
			System.out.println("插入数据成功");
			return i;
			
		}
		catch(SQLException sqle){
			sqle.printStackTrace();
			return 0;
		}
		finally{
			conn.close();
		}
	}
	//更新结束时间。
	public int setRecord2(Record record){
		try{
			System.out.println("正在更新结束时间");
			String sql = "update Record set endtime ="+record.getEndtime()
			+",endt='"+record.getEndt()+"'"+" where computer_id =("+record.getComputer_id()+")";
			conn.Conncentionsql();
			int i = conn.s.executeUpdate(sql);
			System.out.println("更新结束时间成功");
			return i;
			
		}
		catch(SQLException sqle){
			sqle.printStackTrace();
			return 0;
		}
		finally{
			conn.close();
		}
	}
	
	// 更新扣除时间。
	public int setCost(Record record){
		try{
			System.out.println("正在扣钱");
			String sql = "update Record set cost ="+record.getCost()+" where computer_id =("
				+record.getComputer_id()+")";
			conn.Conncentionsql();
			int i = conn.s.executeUpdate(sql);
			System.out.println("更新扣钱成功");
			return i;	
		}
		catch(SQLException sqle){
			sqle.printStackTrace();
			return 0;
		}
		finally{
			conn.close();
		}
	}
	//将电脑更新为使用状态
	public int updateComputer(int computer_id){
		try{
			conn.Conncentionsql();
			System.out.println("222222");
			String sql = "update Computer set useing =1 where computer_id="+computer_id+"";
			int i = conn.s.executeUpdate(sql);
			System.out.println(sql);
			
				return i;
		}
		catch(Exception e){
			e.printStackTrace();
			return -1;
		}finally{
			conn.close();
		}	
	}
	//将电脑更新为空闲状态
	public int updateComputer2(int computer_id){
		try{
			conn.Conncentionsql();
			System.out.println("222222");
			String sql = "update Computer set useing =0 where computer_id="+computer_id+"";
			int i = conn.s.executeUpdate(sql);
			System.out.println(sql);
			
				return i;
		}
		catch(Exception e){
			e.printStackTrace();
			return -1;
		}finally{
			conn.close();
		}	
	}
	
	public int updateCard(int money,int card_id){
		try{	
			String sql = "update Card set money ="+money+"where card_id ="+card_id;
			conn.Conncentionsql();
			int i = conn.s.executeUpdate(sql);
			return i;
		}
		catch(SQLException sqle){
			sqle.printStackTrace();
			return 0;
		}
		finally{
			conn.close();
		}
	}
	
	//删除Record表内容
	public int deleteRecord(int computer_id){
		int i=0;
		try{
			conn.Conncentionsql();
			 i = conn.s.executeUpdate("delete from Record where computer_id="+ computer_id );
		}catch(SQLException sqle){
			sqle.printStackTrace();
		}
		finally{
			conn.close();
			return i;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -