Ejemplo n.º 1
0
 @Override
 public BankAccountPO getBankAccount(String bankID) throws RemoteException {
   String select =
       MySql.select(
           TableEnum.BANK_ACCOUNT,
           new HashMap<String, String>() {
             {
               put("formID", bankID);
             }
           });
   ResultSet rs = null;
   BankAccountPO result = null;
   try {
     statement = conn.prepareStatement(select);
     rs = statement.executeQuery(select);
     rs.next();
     result =
         new BankAccountPO(
             rs.getString("bankID"), rs.getString("accountName"), rs.getString("balance"));
   } catch (SQLException e) {
     System.err.println("查找数据库时出错:");
     e.printStackTrace();
     return null;
   }
   return result;
 }
Ejemplo n.º 2
0
  @Override
  public OperationMessage checkIsNameUsed(String name) throws RemoteException {
    String select =
        MySql.select(
            TableEnum.BANK_ACCOUNT,
            new HashMap<String, String>() {
              {
                put("accountName", name);
              }
            });
    ResultSet rs = null;
    OperationMessage result = new OperationMessage(false, "没有被使用");
    try {
      statement = conn.prepareStatement(select);
      rs = statement.executeQuery(select);
      while (rs.next()) {
        return new OperationMessage(true, "已经被使用");
      }
    } catch (SQLException e) {
      System.err.println("查找数据库时出错:");
      e.printStackTrace();
    }

    return result;
  }
Ejemplo n.º 3
0
  @Override
  public OperationMessage modifyBalance(String ID, double money) throws RemoteException {
    OperationMessage result = new OperationMessage();
    double balance = 0;
    if (ID == null) {
      ID = CompanyAccount;
    }
    final String accID = ID;
    String select =
        MySql.select(
            TableEnum.BANK_ACCOUNT,
            new HashMap<String, String>() {
              {
                put("bankID", accID);
              }
            });

    ResultSet rs = null;
    try {
      statement = conn.prepareStatement(select);
      rs = statement.executeQuery(select);
      rs.next();
      balance = Double.parseDouble(rs.getString("balance")) + money;
      String operation =
          MySql.update(
              TableEnum.BANK_ACCOUNT,
              "balance",
              balance + "",
              new HashMap<String, String>() {
                {
                  put("bankID", accID);
                }
              });
      statement = conn.prepareStatement(operation);
      statement.executeUpdate();
    } catch (SQLException e) {
      System.err.println("没有对应账户");
      e.printStackTrace();
      result = new OperationMessage(false, "调整账户余额出错");
    }

    return result;
  }
Ejemplo n.º 4
0
 @Override
 public OperationMessage clear() throws RemoteException {
   OperationMessage result = new OperationMessage();
   String clear = MySql.delete(TableEnum.BANK_ACCOUNT, null);
   try {
     statement = conn.prepareStatement(clear);
     statement.executeUpdate();
   } catch (SQLException e) {
     result = new OperationMessage(false, "清空数据库时出错:");
     System.err.println("清空数据库时出错:");
     e.printStackTrace();
   }
   return result;
 }
Ejemplo n.º 5
0
  @Override
  public ArrayList<FormPO> getByAccID(String accID) throws RemoteException {
    String select_pay =
        MySql.select(
            TableEnum.PAYMENT,
            new HashMap<String, String>() {
              {
                put("payerAccID", accID);
              }
            });
    // String select_rev = "select * from `revenue` where `payerAccID` = '"
    // + accID + "'";//这地方不知道怎么搞
    ResultSet rs = null;
    PaymentPO pay = null;
    RevenuePO rev = null;
    ArrayList<FormPO> result = new ArrayList<FormPO>();
    try {
      statement = conn.prepareStatement(select_pay);
      rs = statement.executeQuery(select_pay);
      while (rs.next()) {
        pay =
            new PaymentPO(
                rs.getString("formID"),
                rs.getTimestamp("date"),
                rs.getString("amount"),
                rs.getString("payerAccID"),
                rs.getString("payerName"),
                rs.getString("payerAccount"),
                rs.getString("receiverAccID"),
                rs.getString("receiverName"),
                rs.getString("receiverAccount"),
                rs.getString("item"),
                rs.getString("note"),
                rs.getString("creatorID"));
        pay.setFormState(rs.getString("formState"));
        result.add(pay);
      }
    } catch (SQLException e) {
      System.err.println("查找数据库时出错:");
      e.printStackTrace();
    }

    return result;
  }
Ejemplo n.º 6
0
  @Override
  public String getNewBankID() throws RemoteException {
    String selectAll = MySql.select(TableEnum.BANK_ACCOUNT, null);
    ResultSet rs = null;
    try {
      statement = conn.prepareStatement(selectAll);
      rs = statement.executeQuery(selectAll);
      while (rs.next()) {
        ID_MAX = Math.max(ID_MAX, Integer.parseInt(rs.getString("bankID"))); // 3位编号
      }
    } catch (SQLException e) {
      System.err.println("访问数据库时出错:");
      e.printStackTrace();
    }

    ID_MAX++; // 将该数字加一
    if (ID_MAX > 999) return null;
    String added = String.format("%03d", ID_MAX);

    return added;
  }
Ejemplo n.º 7
0
 @Override
 public String getBankIDByName(String name) throws RemoteException {
   String select =
       MySql.select(
           TableEnum.BANK_ACCOUNT,
           new HashMap<String, String>() {
             {
               put("accountName", name);
             }
           });
   ResultSet rs = null;
   try {
     statement = conn.prepareStatement(select);
     rs = statement.executeQuery(select);
     rs.next();
     return rs.getString("bankID");
   } catch (SQLException e) {
     System.err.println("查找数据库时出错:");
     e.printStackTrace();
     return null;
   }
 }
Ejemplo n.º 8
0
  @Override
  public ArrayList<BankAccountPO> getAll() throws RemoteException {
    String selectAll = MySql.select(TableEnum.BANK_ACCOUNT, null);
    ResultSet rs = null;
    BankAccountPO temp = null;
    ArrayList<BankAccountPO> result = new ArrayList<BankAccountPO>();
    try {
      statement = conn.prepareStatement(selectAll);
      rs = statement.executeQuery(selectAll);
      while (rs.next()) {
        temp =
            new BankAccountPO(
                rs.getString("bankID"), rs.getString("accountName"), rs.getString("balance"));
        result.add(temp);
      }
    } catch (SQLException e) {
      System.err.println("查找数据库时出错:");
      e.printStackTrace();
    }

    return result;
  }
Ejemplo n.º 9
0
  @Override
  public OperationMessage delete(String id) throws RemoteException {
    OperationMessage result = new OperationMessage();
    String delete =
        MySql.delete(
            TableEnum.BANK_ACCOUNT,
            new HashMap<String, String>() {
              {
                put("bankID", id);
              }
            });
    try {
      statement = conn.prepareStatement(delete);
      statement.executeUpdate();
    } catch (SQLException e) {
      result = new OperationMessage(false, "删除时出错:");
      System.err.println("删除时出错:");
      e.printStackTrace();
    }

    return result;
  }
Ejemplo n.º 10
0
  @Override
  public OperationMessage insert(BankAccountPO po) throws RemoteException {
    OperationMessage result = new OperationMessage();
    String insert =
        MySql.insert(
            TableEnum.BANK_ACCOUNT,
            new HashMap<String, String>() {
              {
                put("bankID", po.getBankID());
                put("accountName", po.getAccountName());
                put("balance", po.getBalance());
              }
            });
    try {
      statement = conn.prepareStatement(insert);
      statement.executeUpdate();
    } catch (SQLException e) {
      result = new OperationMessage(false, "新建时出错:");
      System.err.println("新建时出错:");
      e.printStackTrace();
    }

    return result;
  }