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

📄 outnettingdate.java

📁 网吧管理系统JAVA代码
💻 JAVA
字号:
package netbar;

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

public class OutNettingDate {
    public OutNettingDate() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    //获得已上机的机器号
    public ArrayList getcomputerId(){
   SQLDate.sqldate();
   ArrayList array=new ArrayList();
     try{
   Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
   Statement st=con.createStatement();
   ResultSet rs=st.executeQuery("select * from Computer where OnUse='1'");
   while(rs.next()){
   array.add(rs.getString(1));
   }
   rs.close();
   st.close();
   con.close();
 //  for(int i=0;i<array.size();i++)
     //  System.out.println(array.get(i));
   }catch(SQLException ee){
   System.out.println(ee);
   }
   return array;
   }
   //获取上机的开始时间
   public String getbegintime(String computerId){
       String begintime="";
       SQLDate.sqldate();
       try{
           Connection con = DriverManager.getConnection("jdbc:odbc:netbar");
           Statement st = con.createStatement();
           ResultSet rs = st.executeQuery( "select BeginTime from Record where ComputerId='"+computerId +"' and EndTime='1900-01-01 00:00:00'");
           rs.next();
           begintime = rs.getString(1);
           rs.close();
           st.close();
           con.close();
       }catch(SQLException ee){
       System.out.println(ee);
       }
       return begintime;
   }
   //获得使用该机器的卡号
   public String getCardId(String begintime,String computerId){
       String cardId="";
       SQLDate.sqldate();
       try{
             Connection con = DriverManager.getConnection("jdbc:odbc:netbar");
             Statement st = con.createStatement();
             ResultSet rs = st.executeQuery( "select CardId from Record where BeginTime='"+begintime+"' and Endtime='1900-01-01 00:00:00' and ComputerId='"+computerId+"'");
             rs.next();
             cardId= rs.getString(1);
             rs.close();
             st.close();
             con.close();
         }catch(SQLException ee){
         System.out.println(ee);
         }
         return cardId;
     }

   //计算费用
   public int getFeeOfOutNet(String begintime,String endtime){
        //获取上机各个时间段
        int byear=Integer.parseInt(begintime.substring(0,4).trim());
        int bmonth=Integer.parseInt(begintime.substring(5,7).trim());
        int bday=Integer.parseInt(begintime.substring(8,10).trim());
        int bhour=Integer.parseInt(begintime.substring(11,13).trim());
        int bminute=Integer.parseInt(begintime.substring(14,16).trim());

        //System.out.println(byear+"\n"+bmonth+"\n"+bday+"\n"+bhour+"\n"+bminute);
        //获取下机各个时间段
        int eyear=Integer.parseInt(endtime.substring(0,4).trim());
        //System.out.println(eyear);
        int emonth=Integer.parseInt(endtime.substring(5,7).trim());
        //System.out.println(emonth);
        int eday=Integer.parseInt(endtime.substring(8,10).trim());
        //System.out.println(eday);
         //System.out.println(endtime);
        int ehour=Integer.parseInt(endtime.substring(11,14).trim());
        //System.out.println(ehour);
        int eminute=Integer.parseInt(endtime.substring(15,17).trim());
        //System.out.println(eminute);

        //System.out.println(eyear+"\n"+emonth+"\n"+eday+"\n"+ehour+"\n"+eminute);

        int donettime=0;
        int fee=2;
        //计算当前总共上机时间
        donettime=Math.abs((eyear-byear)*365*24*60+
                  (emonth-bmonth)*30*24*60+
                  (eday-bday)*24*60+
                  (ehour-bhour)*60+
                  (eminute-bminute));
         //System.out.println("时间"+donettime);
        //判断计算费用
        if(donettime>=65&&(donettime%60)<5&&(donettime%60)>0){
        fee=(donettime/60)*2;
        }
        if(donettime>65&&(donettime%60)<60&&(donettime%60)>=5){
        fee=(donettime/60+1)*2;
        }
        //System.out.println("费用"+fee);
        return fee;
    }

   //记录下机的所有信息,和更新原有记录
   public void notedateOfRecord(String endtime,int fee,String computerId,String cardId,String begintime){
       SQLDate.sqldate();
   try{
       Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
       Statement st=con.createStatement();
       st.executeUpdate("update Record set EndTime='"+endtime+"',Fee='"+fee+"' where ComputerId='"+computerId+"' and CardId='"+cardId+"' and BeginTime='"+begintime+"'");
       st.close();
       con.close();
   }catch(SQLException ee){
       System.out.println(ee);
   }
  }
  //计算当前用费与余额的差
  public int getbalance(int fee,String cardId){
      int  balance=0;
      SQLDate.sqldate();
       try{
           Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select Balance from Card where Id='"+cardId+"'");
           rs.next();
           balance=rs.getInt(1)-fee;
           rs.close();
           st.close();
           con.close();
       }catch(SQLException ee){
           System.out.println(ee);
       }
       return balance;
  }

  //计算总的用费
  public int getusefee(int fee,String cardId){
      int usefee=0;
      SQLDate.sqldate();
      try{
          Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
          Statement st=con.createStatement();
          ResultSet rs=st.executeQuery("select UseFee from Card where Id='"+cardId+"'");
          rs.next();
          usefee=rs.getInt(1)+fee;
          rs.close();
          st.close();
          con.close();
      }catch(SQLException ee){
          System.out.println(ee);
          }
          return usefee;
      }

  //更新数据
  public void reworkdateOfCard(int usefee,int balance,String cardId){
      SQLDate.sqldate();
      try{
      Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
      Statement st=con.createStatement();
      st.executeUpdate("update Card set Balance='"+balance+"',UseFee='"+usefee+"' where Id='"+cardId+"'");
      st.close();
      con.close();
      }catch(SQLException ee){
      System.out.println(ee);
      }
  }

  //改变上机状态
  public void reworkcomputercase(String computerId){
     SQLDate.sqldate();
    try{
    Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
    Statement st=con.createStatement();
    st.executeUpdate("update Computer set OnUse=0 where Id='"+computerId+"'");
    st.close();
    con.close();
    }catch(SQLException ee){
        //System.out.println("更改状态有错");
    System.out.println(ee);
    }
 }

 //记录管理员的收费情况
 public int notefee(int fee,String cardId){
     int gain=0;
 SQLDate.sqldate();
 try{
     Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
     Statement st=con.createStatement();
     //System.out.println("用费"+fee);
     ResultSet rs=st.executeQuery("select Gain from WorkOfManager where ManagerId='"+cardId+"'");
     rs.next();
     gain=rs.getInt(1);
     gain=gain+fee;
    // System.out.println("记录收费"+gain);
     rs.close();
     st.close();
     con.close();
 }catch(SQLException ee){
     System.out.println(ee);
 }
 return gain;
 }
 //更新收费情况
 public void reworkofGain(int gain,String cardId){
     SQLDate.sqldate();
    try{
        Connection con=DriverManager.getConnection("jdbc:odbc:netbar");
        Statement st=con.createStatement();
        st.executeUpdate("update WorkOfManager set Gain='"+gain+"' where ManagerId='"+cardId+"'and  EndTime='1900-01-01 00:00:00'");
        st.close();
        con.close();
    }catch(SQLException ee){
        System.out.println(ee);
    }


 }

    private void jbInit() throws Exception {
    }
}















⌨️ 快捷键说明

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