📄 buybean.java
字号:
/*
* Created on 2007-5-16
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package course.ejb.buy;
import course.sys.Param;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.ejb.SessionBean;
import course.data.buy.Buy;
import course.data.buy.UserInf;
import course.sys.Param;
import course.sys.buy.ParamBuy;
import course.sys.login.ParamLogin;
import course.sys.register.ParamRegister;
import course.sys.zjgp1.ParamZjgp1;
/**
*
* <!-- begin-user-doc --> A generated session bean <!-- end-user-doc --> * <!--
* lomboz.beginDefinition --> <?xml version="1.0" encoding="UTF-8"?> <lomboz:EJB
* xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
* xmlns:lomboz="http://lomboz.objectlearn.com/xml/lomboz"> <lomboz:session>
* <lomboz:sessionEjb><j2ee:display-name>Buy </j2ee:display-name>
* <j2ee:ejb-name>Buy </j2ee:ejb-name> <j2ee:ejb-class>course.ejb.buy.BuyBean
* </j2ee:ejb-class> <j2ee:session-type>Stateless </j2ee:session-type>
* <j2ee:transaction-type>Container </j2ee:transaction-type>
* </lomboz:sessionEjb> </lomboz:session> </lomboz:EJB> <!--
* lomboz.endDefinition -->
*
* <!-- begin-xdoclet-definition -->
*
* @ejb.bean name="Buy" jndi-name="Buy" type="Stateless"
* transaction-type="Container" -- This is needed for JOnAS. If you
* are not using JOnAS you can safely remove the tags below.
* @jonas.bean ejb-name="Buy" jndi-name="Buy" -- <!-- end-xdoclet-definition -->
* @generated
*/
public abstract class BuyBean implements javax.ejb.SessionBean {
/**
* @ejb.interface-method view-type="remote"
*/
public ArrayList getStkInf(String stkID) {
ArrayList list = new ArrayList();
try {
Class.forName(Param.JDBCDriver).newInstance();
Connection conn = DriverManager.getConnection(Param.JDBCUrl);
PreparedStatement pstmt = conn
.prepareStatement(ParamBuy.SQLGetStkInf);
pstmt.setString(1, stkID);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
list.add(rs.getString("pri"));
list.add(rs.getString("priStpDwn"));
list.add(rs.getString("priStpUp"));
}
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* *
*
* @ejb.interface-method * view-type="remote" *
*/
public String getCashCanUsed(String userName) {
String cashCanUsed = null;
try {
Class.forName(Param.JDBCDriver).newInstance();
Connection conn = DriverManager.getConnection(Param.JDBCUrl);
PreparedStatement pstmt = conn
.prepareStatement(ParamBuy.SQLGetCashCanUsed);
pstmt.setString(1, userName);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
cashCanUsed = rs.getString("cashCanUsed");
}
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return cashCanUsed;
}
/**
* *
*
* @ejb.interface-method * view-type="remote" *
*/
public void InsertStkOwnInf(Buy buy) {
boolean b = true;
if (b) {
Buy tempBuy = getStockOwner_info(buy.getUserName(), buy.getStkID());
try {
Connection conn1 = DriverManager.getConnection(Param.JDBCUrl);
PreparedStatement pstmt = conn1
.prepareStatement(ParamBuy.SQLUpDateStkOwnInf);
if (tempBuy.getStkSumNum().equals("")
|| tempBuy.getStkSumNum().toString() == null) {
tempBuy.setStkSumNum("0");
}
if (buy.getStkSumNum().equals("") || buy.getStkSumNum() == null) {
buy.setStkSumNum("0");
}
//stkSumNum
int stkSumNum = Integer.parseInt(tempBuy.getStkSumNum())
+ Integer.parseInt(buy.getStkSumNum());
pstmt.setString(1, Integer.toString(stkSumNum));
if (tempBuy.getStkCanUsed().equals("")
|| tempBuy.getStkCanUsed().toString() == null) {
tempBuy.setStkCanUsed("0");
}
if (buy.getStkCanUsed().equals("")
|| buy.getStkCanUsed().toString() == null) {
buy.setStkCanUsed("0");
}
//stkCanUsed
int stkCanUsed = Integer.parseInt(tempBuy.getStkCanUsed())
+ Integer.parseInt(buy.getStkCanUsed());
pstmt.setString(2, Integer.toString(stkCanUsed));
pstmt.setString(3, buy.getPriBuyIn());
pstmt.setString(4, tempBuy.getPriSelNow());
if (tempBuy.getPriSelNow().equals("")
|| tempBuy.getPriSelNow().toString() == null) {
tempBuy.setPriSelNow("0");
}
if (buy.getPriBuyIn().equals("")
|| buy.getPriBuyIn().toString() == null) {
buy.setPriBuyIn("0");
}
//numGetLos
// int numGetLos = Integer.parseInt(tempBuy.getPriSelNow())
// / Integer.parseInt(buy.getPriBuyIn()) - 1;
int numGetLos = 0;
pstmt.setString(5, Integer.toString(numGetLos));
//priStpLos=priBuyIn*(1+numGetLos)
int priStpLos = Integer.parseInt(buy.getPriBuyIn())
* (1 + numGetLos);
pstmt.setString(6, Integer.toString(priStpLos));
if (stkCanUsed > 0) {
buy.setStkState("canSell");
} else {
buy.setStkState("CanNotSell");
}
pstmt.setString(7, buy.getStkState());
pstmt.setString(8, tempBuy.getReason() + buy.getReason());
pstmt.setString(9, buy.getUserName());
pstmt.setString(10, buy.getStkID());
pstmt.executeUpdate();
pstmt.close();
conn1.close();
} catch (Exception e1) {
b = false;
}
}
if (!b) {
Buy tempBuy = new Buy();
try {
Class.forName(Param.JDBCDriver).newInstance();
Connection conn = DriverManager.getConnection(Param.JDBCUrl);
PreparedStatement pstmt = conn
.prepareStatement(ParamBuy.SQLInsertStkOwnInf);
pstmt.setString(1, buy.getUserName());
pstmt.setString(2, buy.getStkID());
pstmt.setString(3, buy.getStkSumNum());
pstmt.setString(4, buy.getStkCanUsed());
pstmt.setString(5, buy.getPriBuyIn());
buy.setPriSelNow(buy.getPriBuyIn());
pstmt.setString(6, buy.getPriSelNow());
tempBuy.setPriSelNow("0");
if (tempBuy.getPriSelNow().equals("")
|| tempBuy.getPriSelNow().toString() == null) {
tempBuy.setPriSelNow("0");
}
if (buy.getPriBuyIn().equals("")
|| buy.getPriBuyIn().toString() == null) {
buy.setPriBuyIn("0");
}
//numGetLos
int numGetLos = Integer.parseInt(tempBuy.getPriSelNow())
/ Integer.parseInt(buy.getPriBuyIn()) - 1;
pstmt.setString(7, Integer.toString(numGetLos));
//priStpLos=priBuyIn*(1+numGetLos)
int priStpLos = Integer.parseInt(buy.getPriBuyIn())
* (1 + numGetLos);
pstmt.setString(8, Integer.toString(priStpLos));
buy.setStkState("canSell");
pstmt.setString(9, buy.getStkState());
pstmt.setString(10, buy.getReason());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e2) {
}
}
}
/**
* *
*
* @ejb.interface-method * view-type="remote" *
*/
public void UpdateUserInf(UserInf userInf) {
UserInf tempUserInf = getCustomer_info(userInf.getUserName());
try {
Class.forName(Param.JDBCDriver).newInstance();
Connection conn1 = DriverManager.getConnection(Param.JDBCUrl);
PreparedStatement pstmt = conn1
.prepareStatement(ParamBuy.SQLUpdateUserInf);
if (tempUserInf.getCashCanUsed().equals("")
|| tempUserInf.getCashCanUsed().toString() == null) {
tempUserInf.setCashCanUsed("0");
}
if (userInf.getCashCanUsed().equals("")
|| userInf.getCashCanUsed().toString() == null) {
userInf.setCashCanUsed("0");
}
//cashCanUsed
int cashCanUsed = Integer.parseInt(tempUserInf.getCashCanUsed())
- Integer.parseInt(userInf.getCashCanUsed());
pstmt.setString(1, Integer.toString(cashCanUsed));
if (tempUserInf.getNumOfDone().equals("")
|| tempUserInf.getNumOfDone().toString() == null) {
tempUserInf.setNumOfDone("0");
}
if (userInf.getNumOfDone().equals("")
|| userInf.getNumOfDone().toString() == null) {
userInf.setNumOfDone("0");
}
//numOfDone
int numOfDone = Integer.parseInt(tempUserInf.getNumOfDone())
+ Integer.parseInt(userInf.getNumOfDone());
//pstmt.setString(3, Integer.toString(numOfDone));
// sumOfWth
int sumOfWth = cashCanUsed + numOfDone;
pstmt.setString(2, Integer.toString(sumOfWth));
pstmt.setString(3, Integer.toString(numOfDone));
int dayOfReg = Integer.parseInt(tempUserInf.getDayOfReg());
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
String today = sf.format(new Date());
if (today.equals("") || today == null) {
userInf.setNumOfDone("0");
}
int dayOfNow = Integer.parseInt(today);
int year = (int) ((dayOfNow / 10000) - (dayOfReg / 10000));
int mon = (int) (((dayOfNow % 10000) / 100) - ((dayOfReg % 10000) / 100));
int date = (int) ((dayOfNow % 1000000) - (dayOfReg % 1000000));
int day = year * 365 + mon * 30 + date;
if (day <= 1) {
day = 1;
}
//incOfDay
int incOfDay = (int) ((sumOfWth - Param.MoneyOfReg) / day);
pstmt.setString(4, Integer.toString(incOfDay));
//incOfWeek
int incOfWeek = (int) (incOfDay / 7);
pstmt.setString(5, Integer.toString(incOfWeek));
// inc
int inc = sumOfWth - Param.MoneyOfReg;
pstmt.setString(6, Integer.toString(inc));
pstmt.setString(7, userInf.getUserName());
pstmt.executeUpdate();
pstmt.close();
conn1.close();
} catch (Exception e) {
}
}
/**
* @ejb.interface-method view-type="remote"
*/
public UserInf getCustomer_info(String userName) {
UserInf userInf = new UserInf();
try {
Class.forName(Param.JDBCDriver).newInstance();
Connection conn = DriverManager.getConnection(Param.JDBCUrl);
PreparedStatement pstmt = conn
.prepareStatement(ParamBuy.SQLGetCustomer_info);
pstmt.setString(1, userName);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
userInf.setCashCanUsed(rs.getString("cashCanUsed"));
userInf.setSumOfWth(rs.getString("sumOfWth"));
userInf.setNumOfDone(rs.getString("numOfDone"));
userInf.setIncOfDay(rs.getString("incOfDay"));
userInf.setIncOfWeek(rs.getString("incOfWeek"));
userInf.setInc(rs.getString("inc"));
userInf.setDayOfReg(rs.getString("dayOfReg"));
}
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return userInf;
}
/**
* @ejb.interface-method view-type="remote"
*/
public Buy getStockOwner_info(String userName, String stkID) {
Buy buy = new Buy();
try {
Class.forName(Param.JDBCDriver).newInstance();
Connection conn = DriverManager.getConnection(Param.JDBCUrl);
PreparedStatement pstmt = conn
.prepareStatement(ParamBuy.SQLGetStockOwner_info);
pstmt.setString(1, userName);
pstmt.setString(2, stkID);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
buy.setStkSumNum(rs.getString("stkSumNum"));
buy.setStkCanUsed(rs.getString("stkCanUsed"));
buy.setPriBuyIn(rs.getString("priBuyIn"));
buy.setPriSelNow(rs.getString("priSelNow"));
buy.setNumGetLos(rs.getString("numGetLos"));
buy.setPriStpLos(rs.getString("priStpLos"));
buy.setStkState(rs.getString("stkState"));
buy.setReason(rs.getString("reason"));
}
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return buy;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -