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

📄 userserveraction.java

📁 个人网上银行系统设计该系统使用MySQL数据库。
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.perwebbank.action;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.perwebbank.DBOpertion;
import com.perwebbank.form.ServerForm;

/**
 * MyEclipse Struts Creation date: 12-12-2006
 * 
 * XDoclet definition:
 * 
 * @struts.action
 */
public class UserServerAction extends DispatchAction {
	private int tradetype;

	private ArrayList<ServerForm> array = new ArrayList<ServerForm>();

	public ActionForward deposit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws SQLException {
		ServerForm serverForm = (ServerForm) form;

		SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
		String tradedate = dateformat.format(new GregorianCalendar().getTime());

		Double sum = Double.parseDouble(serverForm.getSum());
		System.out.println(serverForm.getSum());

		serverForm = (ServerForm) request.getSession().getAttribute(
				"serverForm");
		System.out.println(serverForm.getAccount());
		String s1 = "select balance from customer where account='"
				+ serverForm.getAccount() + "'";
		DBOpertion.getStatement();
		ResultSet rs = DBOpertion.executeQuery(s1);

		if (rs.next()) {
			System.out.println("ok");
			Double balance = rs.getDouble(1);
			balance += sum;

			String s2 = "update customer set balance='" + balance
					+ "' where account='" + serverForm.getAccount() + "'";
			DBOpertion.exeuteUpdate(s2);
			tradetype = 1;
			String s3 = "Insert into trade (account,tradetype,sum,tradepass,tradedate) values ('"
					+ Integer.parseInt(serverForm.getAccount())
					+ "','"
					+ tradetype
					+ "','"
					+ sum
					+ "','"
					+ serverForm.getTradepass() + "','" + tradedate + "')";
			DBOpertion.excuteInsert(s3);
			serverForm.setBalance(String.valueOf(balance));
			request.getSession().setAttribute("serverForm", serverForm);
			DBOpertion.closeResultSet(rs);
			DBOpertion.closeStatement();
			DBOpertion.closeConnection();
			return mapping.findForward("depositSuccess");
		} else {
			DBOpertion.closeResultSet(rs);
			DBOpertion.closeStatement();
			DBOpertion.closeConnection();
			return mapping.findForward("depositerror");
		}
	}

	public ActionForward fetch(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws SQLException {
		ServerForm serverForm = (ServerForm) form;
		SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
		String tradedate = dateformat.format(new GregorianCalendar().getTime());
		Double sum = Double.parseDouble(serverForm.getSum());
		System.out.println(serverForm.getSum());
		serverForm = (ServerForm) request.getSession().getAttribute(
				"serverForm");
		System.out.println(serverForm.getAccount());
		System.out.println("balance:" + serverForm.getBalance());
		Double balance = Double.parseDouble(serverForm.getBalance());
		if (sum <= (balance - 10.0)) {
			balance -= sum;
			String s1 = "update customer set balance='" + balance
					+ "' where account='" + serverForm.getAccount()
					+ "'and loginpass='" + serverForm.getLoginpass() + "'";
			DBOpertion.getStatement();
			DBOpertion.exeuteUpdate(s1);
			tradetype = 0;
			String s2 = "Insert into trade (account,tradetype,sum,tradepass,tradedate) values ('"
					+ Integer.parseInt(serverForm.getAccount())
					+ "','"
					+ tradetype
					+ "','"
					+ sum
					+ "','"
					+ serverForm.getTradepass() + "','" + tradedate + "')";
			DBOpertion.excuteInsert(s2);
			serverForm.setBalance(String.valueOf(balance));
			request.getSession().setAttribute("serverForm", serverForm);
			DBOpertion.closeStatement();
			DBOpertion.closeConnection();
			return mapping.findForward("depositSuccess");
		} else {
			DBOpertion.closeStatement();
			DBOpertion.closeConnection();
			return mapping.findForward("fetcherror");
		}
	}

	public ActionForward tansfer(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws SQLException {
		ServerForm serverForm = (ServerForm) form;

		SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
		String tradedate = dateformat.format(new GregorianCalendar().getTime());

		Double sum = Double.parseDouble(serverForm.getSum());
		String tansferaccount = serverForm.getTansferaccount();
		serverForm = (ServerForm) request.getSession().getAttribute(
				"serverForm");
		Double balance = Double.parseDouble(serverForm.getBalance());
		ResultSet rs = null;
		if (sum < (balance - 10.0)) {
			balance -= sum;
			System.out.println("a:" + String.valueOf(balance));
			Connection con = DBOpertion.getConnection();
			try {
				con.setAutoCommit(false);
				DBOpertion.getStatement();
				String s1 = "update customer set balance='" + balance
						+ "' where account='" + serverForm.getAccount() + "'";

				String s2 = "Insert into trade (account,tradetype,sum,tradepass,tradedate) values ('"
						+ Integer.parseInt(serverForm.getAccount())
						+ "','"
						+ 0
						+ "','"
						+ sum
						+ "','"
						+ serverForm.getTradepass()
						+ "','" + tradedate + "')";
				DBOpertion.exeuteUpdate(s1);
				DBOpertion.excuteInsert(s2);

				String s3 = "select balance from customer where account='"
						+ tansferaccount + "'";
				rs = DBOpertion.executeQuery(s3);
				if (rs.next()) {
					Double tbalance = rs.getDouble(1);
					tbalance += sum;
					String s4 = "update customer set balance='" + tbalance
							+ "' where account='" + tansferaccount + "'";
					System.out.println("b:" + String.valueOf(tbalance));
					DBOpertion.exeuteUpdate(s4);

					String s5 = "Insert into trade (account,tradetype,sum,tradepass,tradedate) values ('"
							+ tansferaccount
							+ "','"
							+ 1
							+ "','"
							+ sum
							+ "','"
							+ serverForm.getTradepass()
							+ "','"
							+ tradedate
							+ "')";
					DBOpertion.excuteInsert(s5);
					serverForm.setBalance(String.valueOf(balance));
					request.getSession().setAttribute("serverForm", serverForm);
				}
				con.commit();
				con.setAutoCommit(true);
			} catch (Exception e) {
				con.rollback();
			}
			DBOpertion.closeResultSet(rs);
			DBOpertion.closeStatement();
			DBOpertion.closeConnection();
			return mapping.findForward("depositSuccess");

		} else {
			DBOpertion.closeResultSet(rs);
			DBOpertion.closeStatement();
			DBOpertion.closeConnection();
			return mapping.findForward("transfererror");
		}
	}

	public ActionForward withdraw(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws SQLException {
		ServerForm serverForm = (ServerForm) form;
		String loginpass = serverForm.getLoginpass();
		serverForm = (ServerForm) request.getSession().getAttribute(
				"serverForm");
		serverForm.setStatus(String.valueOf(2));
		String sql = "update customer set status='" + 2 + "' where account='"
				+ serverForm.getAccount() + "' and loginpass='" + loginpass
				+ "'";
		DBOpertion.getStatement();
		DBOpertion.exeuteUpdate(sql);
		request.getSession().setAttribute("serverForm", serverForm);
		DBOpertion.closeStatement();
		DBOpertion.closeConnection();
		return mapping.findForward("depositSuccess");
	}

	public ActionForward checkTrade(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws SQLException {
		ServerForm serverForm = (ServerForm) form;
		if (Integer.parseInt(serverForm.getBmonth()) < 10)
			serverForm.setBmonth("0" + serverForm.getBmonth());
		System.out.println(serverForm.getBmonth());

		if (Integer.parseInt(serverForm.getBday()) < 10)
			serverForm.setBday("0" + serverForm.getBday());
		System.out.println(serverForm.getBday());

		String begindate = serverForm.getByear() + "-" + serverForm.getBmonth()
				+ "-" + serverForm.getBday();

		if (Integer.parseInt(serverForm.getEmonth()) < 10)
			serverForm.setEmonth("0" + serverForm.getEmonth());
		System.out.println(serverForm.getEmonth());

		if (Integer.parseInt(serverForm.getEday()) < 10)
			serverForm.setEday("0" + serverForm.getEday());
		System.out.println(serverForm.getEday());

		String enddate = serverForm.getEyear() + "-" + serverForm.getEmonth()
				+ "-" + serverForm.getEday();
		System.out.println(enddate);

		serverForm = (ServerForm) request.getSession().getAttribute(
				"serverForm");
		String sql = "select * from trade where tradedate between '"
				+ begindate + "' and '" + enddate + "' and account='"
				+ serverForm.getAccount() + "'";
		/*
		 * String sql = "select * from trade where account='" +
		 * serverForm.getAccount() + "'in (select * from trade where tradedate
		 * between '" + begindate + "' and '" + enddate + "')" ;
		 */

		DBOpertion.getStatement();
		ResultSet rs = DBOpertion.executeQuery(sql);

		if (rs != null) {
			while (rs.next()) {
				ServerForm sForm = new ServerForm();
				sForm.setTradecode(String.valueOf(rs.getInt(1)));
				sForm.setTradetype(String.valueOf(rs.getInt(3)));
				sForm.setSum(String.valueOf(rs.getDouble(4)));
				sForm.setTradedate(rs.getString(6));
				array.add(sForm);
			}
			request.getSession().setAttribute("array", array);
			return mapping.findForward("depositSuccess");
		} else
			return mapping.findForward("checkTradeerror");

	}
}

⌨️ 快捷键说明

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