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

📄 gbs_rfpattachmentsubaction.java

📁 对日软件外包 为东芝做的一个全球商业管理系统
💻 JAVA
字号:
/*
 * Created on 2004/07/30
 *
 */
package ACTION;

import java.util.ArrayList;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import COMMON.BaseCommonCheck;
import COMMON.BaseDispatchAction;
import COMMON.MessageList;
import COMMON.ReturnValue;
import COMMON.SystemConstants;
import DataBean.GBS_RfpAttachList_stBean;
import LOGIC.GBS_RequestActionLogic;

/**
 * <p>Title: Service Information </p>
 * <p>Description: process page action<br>
 * </p>
 * <p> Copyright (c) 2004</p>
 * @author mxx
 * @version  1.0
 */
public class GBS_RfpAttachmentSubAction extends BaseDispatchAction implements SystemConstants {

	/**
	 * init page 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward init(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws Exception {
		GBS_RfpAttachmentSubForm thisform = (GBS_RfpAttachmentSubForm) form;

		//get login user info from session
		this.setUserInfoFromSession(request, thisform);
		GBS_RequestActionLogic logic = new GBS_RequestActionLogic(this.getDataSource(request));
		thisform.setMethod("insert");
		if (!thisform.getLineNo().equals("") || !thisform.getSeqNo().equals("")) {
			thisform.setMethod("update");

			ArrayList rfpAttachList = (ArrayList) this.getFromSession(request, RFPATTACHLIST);

			//ReturnValue returnValue = (ReturnValue)logic.getRfpAttachment(thisform.getCustomerID(),thisform.getRfpNo(),thisform.getLineNo());
			for (int i = 0; rfpAttachList != null && i < rfpAttachList.size(); i++) {
				GBS_RfpAttachList_stBean rfpAttachListBean = (GBS_RfpAttachList_stBean) rfpAttachList.get(i);
				if (rfpAttachListBean.getLineNo().equals(thisform.getLineNo())) {
					thisform.setTitle(rfpAttachListBean.getTitle());
					thisform.setAttachmentfilename(rfpAttachListBean.getAttachmentFileName());
				}
			}
		}
		return (mapping.findForward(nextview));
	}

	public ActionForward update(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws Exception {

		GBS_RfpAttachmentSubForm thisform = (GBS_RfpAttachmentSubForm) form;
		//get login user info from session
		this.setUserInfoFromSession(request, thisform);
		//
		GBS_RequestActionLogic logic = new GBS_RequestActionLogic(this.getDataSource(request));
		//乮侾乯丂夋柺丏揧晅僼傽僀儖偑偁傞応崌
		String seqNo = "";

		//input check
		MessageList errorMsg = new MessageList();
		errorMsg = inputCheck(thisform, request);
		if (errorMsg.size() > 0) {
			//save error to request
			this.setMessage(errorMsg);
			return (mapping.findForward(nextview));
		}

		if (thisform.getAttachmentFile() != null && !thisform.getAttachmentFile().getFileName().equals("")) {
			//RfpAttachList_stBean.setAttachmentFileName(thisform.getAttachmentFile().getFileName());
			HttpSession session = request.getSession();
			ReturnValue returnValue =
				logic.addAttachmentFileIntoTempTable(
					session.getId(),
					thisform.getLoginUserId(),
					thisform.getAttachmentFile());
			if (returnValue.isError()) {
				if (returnValue.isBussinessError()) {
					this.setMessage(returnValue.getMessageList());
				}
				//getErrorCode getErrorMessage proc
				return (mapping.findForward(nextview));
			} else {
				int iSeqNo = ((Integer) returnValue.getDataValue()).intValue();
				seqNo = String.valueOf(iSeqNo);
				thisform.setAttachmentfilename(thisform.getAttachmentFile().getFileName());
				//thisform.setSeqNo(iSeqNo + "");

			}

		}

		//乮俀乯丂RFP揧晅帒椏傪僙僢僔儑儞偵曐懚偡傞
		ArrayList RfpAttachList = (ArrayList) this.getFromSession(request, RFPATTACHLIST);
		if (RfpAttachList == null) {
			RfpAttachList = new ArrayList();
		}
		for (int i = 0; i < RfpAttachList.size(); i++) {
			GBS_RfpAttachList_stBean st = (GBS_RfpAttachList_stBean) RfpAttachList.get(i);
			if (st.getLineNo().equals(thisform.getLineNo()) && st.getSeqNo().equals(thisform.getSeqNo())) {
				if (thisform.getAttachmentFile() != null && !thisform.getAttachmentFile().getFileName().equals("")) {
					st.setSeqNo(seqNo);
					st.setAttachmentFileName(thisform.getAttachmentfilename());

					//String fileType = "";
					//String fileName = thisform.getAttachmentfilename();
					//if (fileName != null) {
					//	fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
					//	if (!(fileType.equals("doc") || fileType.equals("xls") || fileType.equals("pdf")))
					//		fileType = "other";
					//}
					st.setFiletype(BaseCommonCheck.getFileType(st.getAttachmentFileName()));
				}
				if (thisform.getFdelflag().equals("on")) {
					//file delete = on 
					st.setFiletype("");
					st.setAttachmentFileName("");
					st.setFileDeleteFlg(true);
				} else {
					st.setFileDeleteFlg(false);
				}
//				if (!st.getLineNo().startsWith("A")) {
					st.setUpdateUser(thisform.getLoginUserId());
					st.setUpdateUserName(thisform.getLoginMemberNameFirst() + " " + thisform.getLoginMemberNameLast());
					st.setUpdateDate(BaseCommonCheck.convertDateToYYYYMonDD());
//				}
				st.setRecordDeleteFlg(false);
				st.setRowUpdateFlg(true);
				st.setTitle(thisform.getTitle());
				break;
			}
		}
		thisform.setMethod("close");
		return (mapping.findForward(nextview));
	}

	public ActionForward insert(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws Exception {
		GBS_RfpAttachmentSubForm thisform = (GBS_RfpAttachmentSubForm) form;
		//get login user info from session
		this.setUserInfoFromSession(request, thisform);
		//
		GBS_RequestActionLogic logic = new GBS_RequestActionLogic(this.getDataSource(request));
		//乮侾乯丂夋柺丏揧晅僼傽僀儖偑偁傞応崌
		String seqNo = "";

		//input check
		MessageList errorMsg = new MessageList();
		errorMsg = inputCheck(thisform, request);
		if (errorMsg.size() > 0) {
			//save error to request
			this.setMessage(errorMsg);
			return (mapping.findForward(nextview));
		}

		//YM
		if (thisform.getAttachmentFile() != null && !thisform.getAttachmentFile().getFileName().equals("")) {
			//RfpAttachList_stBean.setAttachmentFileName(thisform.getAttachmentFile().getFileName());
			HttpSession session = request.getSession();
			ReturnValue returnValue =
				logic.addAttachmentFileIntoTempTable(
					session.getId(),
					thisform.getLoginUserId(),
					thisform.getAttachmentFile());
			if (returnValue.isError()) {
				if (returnValue.isBussinessError()) {
					this.setMessage(returnValue.getMessageList());
				}
				//getErrorCode getErrorMessage proc
				return (mapping.findForward(nextview));
			} else {
				int iSeqNo = ((Integer) returnValue.getDataValue()).intValue();
				thisform.setAttachmentfilename(thisform.getAttachmentFile().getFileName());
				thisform.setSeqNo(iSeqNo + "");

			}

		}

		//乮俀乯丂RFP揧晅帒椏傪僙僢僔儑儞偵曐懚偡傞
		ArrayList RfpAttachList = (ArrayList) this.getFromSession(request, RFPATTACHLIST);
		if (RfpAttachList == null) {
			RfpAttachList = new ArrayList();
		}

		GBS_RfpAttachList_stBean st = new GBS_RfpAttachList_stBean();
		st.setCustomerID(thisform.getCustomerID());
		st.setRfpNo(thisform.getRfpNo());
		st.setLineNo("ADD" + RfpAttachList.size());
		st.setSeqNo(thisform.getSeqNo());
		st.setAttachmentFileName(thisform.getAttachmentfilename());
		//String fileType = "";
		st.setFiletype(BaseCommonCheck.getFileType(thisform.getAttachmentfilename()));
		//		String fileName = thisform.getAttachmentfilename();
		//		if (fileName != null) {
		//			st.setFiletype(BaseCommonCheck.getFileType(st.getAttachmentFileName()));
		//			fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
		//			if (!(fileType.equals("doc") || fileType.equals("xls") || fileType.equals("pdf")))
		//				fileType = "other";
		//		}
		//		st.setFiletype(fileType);
		st.setUpdateUser(thisform.getLoginUserId());
		st.setCreateUserName(thisform.getLoginMemberNameFirst() + " " + thisform.getLoginMemberNameLast());
		st.setCreateUser(thisform.getLoginUserId());
		//Edit by Gxk 2004/08/27:add update user and date
		st.setUpdateDate(BaseCommonCheck.convertDateToYYYYMonDD());
		st.setUpdateUserName(thisform.getLoginMemberNameFirst() + " " + thisform.getLoginMemberNameLast());
		//Edit by Gxk 2004/08/27 End
		st.setCreateDate(BaseCommonCheck.convertDateToYYYYMonDD());
		st.setRecordDeleteFlg(false);
		st.setRowUpdateFlg(true);
		st.setTitle(thisform.getTitle());
		RfpAttachList.add(st);
		request.getSession();
		this.saveToSession(request, RFPATTACHLIST, RfpAttachList);
		thisform.setMethod("close");
		return (mapping.findForward(nextview));
	}

	public ActionForward delete(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws Exception {
		GBS_RfpAttachmentSubForm thisform = (GBS_RfpAttachmentSubForm) form;
		//get login user info from session
		this.setUserInfoFromSession(request, thisform);
		//
		//乮俀乯丂RFP揧晅帒椏傪僙僢僔儑儞偵曐懚偡傞
		ArrayList RfpAttachList = (ArrayList) this.getFromSession(request, RFPATTACHLIST);
		if (RfpAttachList == null) {
			RfpAttachList = new ArrayList();
		}
		for (int i = 0; i < RfpAttachList.size(); i++) {
			GBS_RfpAttachList_stBean st = (GBS_RfpAttachList_stBean) RfpAttachList.get(i);
			if (st.getLineNo().equals(thisform.getLineNo()) && st.getSeqNo().equals(thisform.getSeqNo())) {
				st.setRecordDeleteFlg(true);
				st.setRowUpdateFlg(true);
				break;
			}
		}
		thisform.setMethod("close");
		return (mapping.findForward(nextview));
	}

	public ActionForward download(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws Exception {

		log.info("[location info]GBS_RequestAction.download method!");
		GBS_RfpAttachmentSubForm thisForm = (GBS_RfpAttachmentSubForm) form;
		this.setUserInfoFromSession(request, thisForm);

		// read data 
		GBS_RequestActionLogic logic = new GBS_RequestActionLogic(this.getDataSource(request));

		GBS_RfpAttachList_stBean st = new GBS_RfpAttachList_stBean();
		if (thisForm.getLineNo() != null && !thisForm.getLineNo().equals("")) {
			//read data from session;
			ArrayList RfpAttachList = (ArrayList) this.getFromSession(request, RFPATTACHLIST);
			for (int i = 0; RfpAttachList != null && i < RfpAttachList.size(); i++) {

				st = (GBS_RfpAttachList_stBean) RfpAttachList.get(i);
				if (String.valueOf(st.getLineNo()).equals(thisForm.getLineNo())) {
					break;
				}
			}
		}

		// read data 
		ReturnValue returnValue = logic.getAttachmentFile(st, response);

		return (null);
	}
	/**
	 * method inputCheck
	 * @param requestForm GBS_RfpAttachmentSubForm
	 * @param request HttpServletRequest
	 * @throws Exception
	 * @return ErrorMessages
	 */
	private MessageList inputCheck(GBS_RfpAttachmentSubForm requestForm, HttpServletRequest request) throws Exception {
		//create ErrorMessages to display error message
		MessageList messages = new MessageList();
		String strTitle = requestForm.getTitle();
		FormFile attachmentFile = requestForm.getAttachmentFile();
		//Title check
		//DELETE by Gxk 20040823 
//		if (BaseCommonCheck.isEmpty(strTitle)) {
//			messages.setMessage(
//				"title",
//				requestForm.getTitle(),
//				"10000009",
//				Integer.MIN_VALUE,
//				new Object[] { "Title" });
//		}
		//AttachmentFile check
		
		if( attachmentFile != null && requestForm.getAttachmentfilename().equals("") && 
			attachmentFile.getFileName().equals("") &&
			BaseCommonCheck.isEmpty(strTitle) ){
			messages.setMessage("title", requestForm.getTitle(), "10000009", Integer.MIN_VALUE,
			new Object[]{ "Title" }, "Title");
		}
		if (requestForm.getFdelflag().equals("on") && 
			BaseCommonCheck.isEmpty( strTitle )){
			messages.setMessage("title", requestForm.getTitle(), "10000009", Integer.MIN_VALUE,
				new Object[]{ "Title" }, "Title");
		}
		if((attachmentFile != null && !attachmentFile.getFileName().equals("")) && attachmentFile.getFileSize()==0){
			messages.setMessage( "attachmentFile", null, "10000012", Integer.MIN_VALUE,
			new Object[]{ "AttachmentFile" }, "AttachmentFile");						
		}
		//AttachmentFile's name check
		if(attachmentFile != null && attachmentFile.getFileName().length() > 100){
			messages.setMessage("","", "10000018", Integer.MIN_VALUE);
		}
		return messages;
	}

}

⌨️ 快捷键说明

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