?? procmemberorder.java
字號:
package NetCommodityOrder.javabean;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import NetCommodityOrder.moejb.*;
import NetCommodityOrder.scejb.*;
import NetCommodityOrder.ejbtools.*;
public class ProcMemberOrder
{
String memberid = null;
String orderid = "";
int totalprice = 0;
String[] commodityid;
String[] quantity;
String[] commodityname;
int[] commoditynumber;
int[] unitprice;
HashMap hashmap = new HashMap();
ArrayList arraylist = null;
Context initcontext = null;
Object obj = null;
MemberOrderProcHomeint memberorderprochomeint = null;
ShopCommodityProcHomeint shopcommodityprochomeint = null;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//取得兩個EntityBean(MemberOrderProcHomeint
//和ShopCommodityProcHomeint)的home接口對象
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public ProcMemberOrder() throws Exception
{
initcontext = new InitialContext();
obj = initcontext.lookup("ejb/ShopCommodityProcEJB");
shopcommodityprochomeint = (ShopCommodityProcHomeint)PortableRemoteObject.narrow(obj,ShopCommodityProcHomeint.class);
obj = initcontext.lookup("ejb/MemberOrderProcEJB");
memberorderprochomeint = (MemberOrderProcHomeint)PortableRemoteObject.narrow(obj,MemberOrderProcHomeint.class);
setCommodityhashmap();
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//定義一些屬性方法,用來設定和獲取變量的值
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public void setOrderid(String orderid)
{
this.orderid = orderid;
}
public void setMemberid(String memberid)
{
this.memberid = memberid;
}
public void setCommoditynumber(int[] commoditynumber)
{
this.commoditynumber = commoditynumber;
}
public void setCommodityid(String[] commodityid)
{
this.commodityid = commodityid;
}
public void setCommodityname(String[] commodityname)
{
this.commodityname = commodityname;
}
public void setUnitprice(int[] unitprice)
{
this.unitprice = unitprice;
}
public void setQuantity(String[] quantity)
{
this.quantity = quantity;
}
public String getOrderid()
{
return this.orderid;
}
public String getMemberid()
{
return this.memberid;
}
public int[] getCommoditynumber()
{
return this.commoditynumber;
}
public String[] getCommodityid()
{
return this.commodityid;
}
public String[] getCommodityname()
{
return this.commodityname;
}
public int[] getUnitprice()
{
return this.unitprice;
}
public String[] getQuantity()
{
return this.quantity;
}
public int getTotalprice()
{
return this.totalprice;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//定義一個HashMap對象,存放訂購商品的編號和ShopCommodity的類別
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
private void setCommodityhashmap()
{
try
{
Collection collection = shopcommodityprochomeint.findAll();
Iterator iter = collection.iterator();
while (iter.hasNext())
{
ShopCommodity shopcommodity = ((ShopCommodityProcRemoteint)iter.next()).getCommodityInfomation();
hashmap.put(shopcommodity.getCommodityid(),shopcommodity);
}
}
catch(Exception e)
{}
}
public String getCommodityname1(String commodityid)
{
return ((ShopCommodity)hashmap.get(commodityid)).getCommodityname();
}
public int getUnitprice1(String commodityid)
{
return ((ShopCommodity)hashmap.get(commodityid)).getUnitprice();
}
public Hashtable getOrdersHash() throws Exception
{
Hashtable hashtable = null;
Iterator iter = null;
try
{
hashtable = new Hashtable();
iter = memberorderprochomeint.findByMemberid(memberid).iterator();
while(iter.hasNext())
{
MemberOrderProcRemoteint memberorderprocremoteint = (MemberOrderProcRemoteint)iter.next();
arraylist = memberorderprocremoteint.getCommodityOrder();
hashtable.put(memberorderprocremoteint.getOrderid(),arraylist);
}
}
catch(Exception e)
{
throw new Exception("訂單記錄不存在,請重新查詢!");
}
return hashtable;
}
public Vector getCommodityVector() throws Exception
{
Vector v = new Vector();
try
{
Collection collection = shopcommodityprochomeint.findAll();
Iterator iter = collection.iterator();
while (iter.hasNext())
{
ShopCommodityProcRemoteint shopcommodityprocremoteint = (ShopCommodityProcRemoteint)iter.next();
v.add(shopcommodityprocremoteint.getCommodityInfomation());
}
}
catch(Exception e)
{
throw new Exception(e.toString());
}
return v;
}
public void setCommodityArrayList()
{
arraylist = new ArrayList();
this.totalprice = 0;
int index = 0;
int tmpquantity = 0;
int tmptotalprice = 0;
for(int j = 0; j < commoditynumber.length;j++)
{
index = commoditynumber[j];
tmpquantity = 0;
try
{
tmpquantity = Integer.parseInt("0" + quantity[index].trim());
}
catch(Exception e)
{}
if(tmpquantity != 0)
{
tmptotalprice = tmpquantity * unitprice[index];
arraylist.add(new CommodityOrder(orderid,commodityid[index],tmpquantity,commodityname[index],unitprice[index],tmptotalprice));
this.totalprice = this.totalprice + tmptotalprice;
}
}
}
public ArrayList getCommodityArraylist()
{
return arraylist;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//調用create()方法,將定單記錄加入到數據庫中
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public void ConfMemberOrder()
{
try
{
MemberOrderProcRemoteint memberorderprocremoteint = memberorderprochomeint.create(memberid,totalprice,arraylist);
orderid = memberorderprocremoteint.getOrderid();
}
catch(Exception e)
{}
}
public void cancelMemberOrder() throws Exception
{
if(orderid != null && orderid != "" && orderid.length() > 1)
{
try
{
memberorderprochomeint.remove(orderid);
}
catch(Exception e)
{
throw new Exception("無法取消訂單!");
}
}
else
{
throw new Exception("無法取消訂單!");
}
}
public void updateMemberOrder() throws Exception
{
if(orderid != "" && orderid != null && orderid.length() > 1)
{
try
{
MemberOrderProcRemoteint memberorderprocremoteint = memberorderprochomeint.findByPrimaryKey(orderid);
memberorderprocremoteint.setCommodityOrder(arraylist);
memberorderprocremoteint.setTotalprice(totalprice);
}
catch(Exception e)
{
throw new Exception("無法更新定單");
}
}
else
{
throw new Exception("無法更新定單");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -