www.pudn.com > RFID_98798798698698.rar > RFIDSearchAction.java


package com.rfid.struts.action; 
 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession; 
import java.util.List; 
 
import org.apache.struts.action.Action; 
import org.apache.struts.action.ActionForm; 
import org.apache.struts.action.ActionForward; 
import org.apache.struts.action.ActionMapping; 
import org.apache.struts.action.ActionMessages; 
 
import com.rfid.struts.form.RFIDSearchForm; 
import com.rfid.model.*; 
import com.rfid.dao.*; 
 
public class RFIDSearchAction extends Action{ 
 
	public ActionForward execute(ActionMapping mapping, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response) { 
		RFIDSearchForm rfidSearchForm = (RFIDSearchForm) form; 
 
		HttpSession session = request.getSession(); 
		ActionForward forward = new ActionForward(); 
        ActionMessages msgs = new ActionMessages(); 
         
        if(rfidSearchForm == null){ 
			request.setAttribute("error", "非法输入"); 
			forward = new  ActionForward("","/pages/error.jsp",true); 
			return forward; 
		} 
         
        String todo = rfidSearchForm.getTodo(); 
    	if(todo == null ){ 
    		request.setAttribute("error", "非法输入"); 
    		forward = new  ActionForward("","/pages/error.jsp",true); 
    		return forward; 
    	} 
    	else if(todo.equals("RFIDSearch")){ 
    		String rfid = rfidSearchForm.getRfid_id(); 
    		TProductDAO dao1 = new TProductDAO(); 
    		TInStoreDAO dao2 = new TInStoreDAO(); 
    		TOutStoreDAO dao3 = new TOutStoreDAO(); 
            TOrderDAO dao4 = new TOrderDAO(); 
            List list1,list2,list3,list4; 
            TProduct product ; 
    		TInStore instore ; 
    		TOutStore outstore ; 
    		TOrder order; 
    		TRFIDSearchResult rfidSearchResult = new TRFIDSearchResult(); 
    		 
    		list1 = dao1.searchByRFID(rfid); 
    		 
    		try{ 
    			product = (TProduct)list1.get(0); 
    			rfidSearchResult.setRfid_id(rfid); 
    		    rfidSearchResult.setName(product.getName()); 
    		    rfidSearchResult.setInstore_id(product.getInStore_id()); 
    		    rfidSearchResult.setOrder_id(product.getOrder_id()); 
    		    rfidSearchResult.setOutstore_id(product.getOutStore_id()); 
    		    rfidSearchResult.setProduct_time(product.getProduct_time()); 
    		     
    		    list2 = dao2.searchByID(product.getInStore_id()); 
    		    list3 = dao3.searchByID(product.getOutStore_id()); 
    		    list4 = dao4.searchByIDForHistory(product.getOrder_id()); 
    				 
    		    try{ 
    			    instore = (TInStore)list2.get(0); 
    			    rfidSearchResult.setInstore_time(instore.getInput_time()); 
    		    }catch(Exception e){ 
    		    	e.printStackTrace(); 
    		    } 
    		 
    		    try{ 
    			    outstore = (TOutStore)list3.get(0); 
    			    rfidSearchResult.setOutstore_time(outstore.getInputtime()); 
    		    }catch(Exception e){ 
    		    	e.printStackTrace(); 
    		    } 
    		 
    		    try{ 
    			     order = (TOrder)list4.get(0); 
    			     rfidSearchResult.setOrder_time(order.getInput_time()); 
    		    }catch(Exception e){ 
    		    	e.printStackTrace(); 
    		    }   		    		       		        		        		  
    		}  	 
    	    catch(Exception e) 
    	    { 
    		    e.printStackTrace();  
    		    rfidSearchResult =null; 
    	    } 
    		 
    		session.setAttribute("rfidSearchResult", rfidSearchResult); 
    		forward = new  ActionForward("","/pages/sales/sell_security.jsp",true); 
    		return forward; 
    	} 
    	 
    	 
    	request.setAttribute("error", "非法输入"); 
		forward = new  ActionForward("","/pages/error.jsp",true); 
        saveMessages(request, msgs); 
        return forward; 
	} 
}