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

📄 procmemberorder.java

📁 java EJB 编程源代码。
💻 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 + -