?? gbs_productavailabilityconditionaction.java
字號:
} else {
requestForm.setSubsidiaryList((ArrayList) returnValue.getDataValue());
}
//End Get combo and selectBox value
//return the info of page which is select
if (requestForm.getCountry() != null) {
ArrayList selectCountryList = new ArrayList();
String[] country = requestForm.getCountry();
for (int i = 0; i < country.length; i++) {
selectCountryList.add(country[i]);
}
requestForm.setSelectCountryList(selectCountryList);
}
if (requestForm.getProduct() != null) {
ArrayList selectProductList = new ArrayList();
String[] product = requestForm.getProduct();
for (int i = 0; i < product.length; i++) {
selectProductList.add(product[i]);
}
requestForm.setSelectProductList(selectProductList);
}
if (requestForm.getSubsidiary() != null) {
ArrayList selectSubsidiaryList = new ArrayList();
String[] subsidiary = requestForm.getSubsidiary();
for (int i = 0; i < subsidiary.length; i++) {
selectSubsidiaryList.add(subsidiary[i]);
}
requestForm.setSelectsubsidiaryList(selectSubsidiaryList);
}
MessageList errorMsg = inputCheck(requestForm, request);
if (errorMsg.size() > 0) {
//save error to request
this.setMessage(errorMsg);
return (mapping.findForward(nextview));
}
returnValue =
logic.getCountryProductInfo(
requestForm.getColorCpm(),
requestForm.getBwCpm(),
requestForm.getFax(),
requestForm.getPrinter(),
BaseCommonCheck.convertNullToZero(requestForm.getCpm1()),
requestForm.getCpm2(),
requestForm.getSubsidiary(),
requestForm.getCountry(),
requestForm.getProduct());
if (!returnValue.isError()) {
//get can or not download the info of product
ArrayList handlingList = (ArrayList) returnValue.getDataValue();
//Delete by Gxk 20040823
// String tmpStrCountry = "";
// for (int i = 0; i < handlingList.size(); i++) {
// GBS_CountryProductHandling_stBean stBean =
// (GBS_CountryProductHandling_stBean) handlingList.get(i);
// if (i == 0) {
// tmpStrCountry = stBean.getCountryCode();
// }
// if (tmpStrCountry.equals(stBean.getCountryCode())) {
// returnValue = logic.getCanDownload(stBean.getProductCode());
// stBean.setCanDownload(((Boolean) returnValue.getDataValue()).booleanValue());
// }
// }
requestForm.setHandlingList(handlingList);
} else {
//BussinessError
if (returnValue.isBussinessError()) {
this.setMessage(returnValue.getMessageList());
}
return (mapping.findForward(nextview));
}
String outFileStr = new String();
ArrayList handling = requestForm.getHandlingList();
//out CSV header
String tempStrCountry = "";
for (int i = 0; i < handling.size(); i++) {
GBS_CountryProductHandling_stBean stBean = (GBS_CountryProductHandling_stBean) handling.get(i);
if (i == 0) {
tempStrCountry = stBean.getCountryCode();
}
outFileStr += ",";
if (!stBean.getCountryCode().equals(tempStrCountry)) {
break;
}
String tmpOutStr = stBean.getProductName();
if (tmpOutStr == null) {
tmpOutStr = "";
} else {
//if first chat is "'" ,add a "'"
if (tmpOutStr.indexOf("\'") == 0) {
tmpOutStr = "'" + tmpOutStr;
}
if (tmpOutStr.indexOf(",") > -1) {
tmpOutStr = "\"" + tmpOutStr + "\"";
}
}
outFileStr += tmpOutStr;
}
tempStrCountry = "";
outFileStr += "\n";
for (int i = 0; i < handling.size(); i++) {
GBS_CountryProductHandling_stBean stBean = (GBS_CountryProductHandling_stBean) handling.get(i);
if (i == 0) {
tempStrCountry = stBean.getCountryCode();
outFileStr += "CPM B/W";
}
outFileStr += ",";
if (!stBean.getCountryCode().equals(tempStrCountry)) {
break;
}
String tmpOutStr = stBean.getBwCpm();
if (tmpOutStr == null) {
tmpOutStr = "";
} else {
//if first chat is "'" ,add a "'"
if (tmpOutStr.indexOf("\'") == 0) {
tmpOutStr = "'" + tmpOutStr;
}
if (tmpOutStr.indexOf(",") > -1) {
tmpOutStr = "\"" + tmpOutStr + "\"";
}
}
outFileStr += tmpOutStr;
}
tempStrCountry = "";
outFileStr += "\n";
for (int i = 0; i < handling.size(); i++) {
GBS_CountryProductHandling_stBean stBean = (GBS_CountryProductHandling_stBean) handling.get(i);
if (i == 0) {
tempStrCountry = stBean.getCountryCode();
outFileStr += "CPM Color";
}
outFileStr += ",";
if (!stBean.getCountryCode().equals(tempStrCountry)) {
break;
}
String tmpOutStr = stBean.getColorCpm();
if (tmpOutStr == null) {
tmpOutStr = "";
} else {
//if first chat is "'" ,add a "'"
if (tmpOutStr.indexOf("\'") == 0) {
tmpOutStr = "'" + tmpOutStr;
}
if (tmpOutStr.indexOf(",") > -1) {
tmpOutStr = "\"" + tmpOutStr + "\"";
}
}
outFileStr += tmpOutStr;
}
tempStrCountry = "";
//out CSV body data
for (int i = 0; i < handling.size(); i++) {
GBS_CountryProductHandling_stBean stBean = (GBS_CountryProductHandling_stBean) handling.get(i);
if (!stBean.getCountryCode().equals(tempStrCountry)) {
outFileStr += "\n";
//out country name at first of a line
String tmpOutStr = stBean.getCountryName();
if (tmpOutStr == null) {
tmpOutStr = "";
} else {
//if first chat is "'" ,add a "'"
if (tmpOutStr.indexOf("\'") == 0) {
tmpOutStr = "'" + tmpOutStr;
}
if (tmpOutStr.indexOf(",") > -1) {
tmpOutStr = "\"" + tmpOutStr + "\"";
}
}
outFileStr += tmpOutStr + ",";
}
String tmpOutStr = stBean.getHandling();
if (tmpOutStr == null) {
outFileStr += ",";
} else if (tmpOutStr.equals("Y")) {
outFileStr += "Y,";
} else if (tmpOutStr.equals("N")) {
outFileStr += "N,";
} else if (tmpOutStr.equals("O")) {
outFileStr += "n/a,";
} else {
outFileStr += ",";
}
tempStrCountry = stBean.getCountryCode();
}
Date nowdate = new Date();
String strDateTime = "yyyyMMddHHmmss";
SimpleDateFormat formatter = new SimpleDateFormat(strDateTime);
String datestring = formatter.format(nowdate).toString();
String fileName = datestring + ".CSV";
//byte[] data = outFileStr.getBytes();
//response.setContentType("APPLICATION/OCTET-STREAM");
//String disHeader = "Attachment;Filename=" + fileName ;
//response.setHeader("Content-Disposition", disHeader);
//ServletOutputStream os=response.getOutputStream();
//int byteSum = 0;
//os.write( data);
//response.setContentLength( data.length );
//os.flush();
//response.flushBuffer();
//os.close();
//this.saveToSession( request, "PRODUCTAVAILABILITY_CSV", outFileStr);
//this.saveToSession( request, "PRODUCTAVAILABILITY_FILENAME", fileName);
GBS_File_stBean st = new GBS_File_stBean();
st.setFileData(outFileStr.getBytes());
st.setFileName(fileName);
st.setFileSize(outFileStr.length());
this.saveToSession(request, "DOWNLOAD_FILE", st);
//list
if (requestForm.getFromPage() != null && requestForm.getFromPage().equals("condition")) {
return (mapping.findForward(nextview));
}
return search(mapping, form, request, response);
}
/**
* Method downloadProductInfo
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward downloadProductInfo(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
GBS_ProductAvailabilityConditionForm requestForm = (GBS_ProductAvailabilityConditionForm) form;
//get login user info from session
this.setUserInfoFromSession(request, requestForm);
GBS_ProductAvailabilityConditionActionLogic logic =
new GBS_ProductAvailabilityConditionActionLogic(this.getDataSource(request));
MessageList errorMsg = inputCheck(requestForm, request);
if (errorMsg.size() > 0) {
//save error to request
this.setMessage(errorMsg);
return (mapping.findForward(nextview));
}
ReturnValue returnValue = logic.getAttachmentFile(requestForm.getDownloadProduct(), response);
if (returnValue.isError()) {
if (returnValue.isBussinessError()) {
this.setMessage(returnValue.getMessageList());
}
return (mapping.findForward(nextview));
}
return mapping.findForward("download");
}
/**
* inputCheck
* @param form GBS_ProductAvailabilityConditionForm
* @param request HttpServletRequest
* @return ErrorMessages
* @throws Exception
*/
private MessageList inputCheck(GBS_ProductAvailabilityConditionForm form, HttpServletRequest request) throws Exception {
//create ErrorMessages to display error message
MessageList messages = new MessageList();
if (!BaseCommonCheck.isEmpty(form.getCpm1()) && !BaseCommonCheck.isDigit(form.getCpm1())) {
messages.setMessage("cpm1", form.getCpm1(), "90000020", Integer.MIN_VALUE);
}
if (!BaseCommonCheck.isEmpty(form.getCpm2()) && !BaseCommonCheck.isDigit(form.getCpm2())) {
messages.setMessage("cpm2", form.getCpm2(), "90000020", Integer.MIN_VALUE);
}
if (!BaseCommonCheck.isEmpty(form.getCpm1())
&& !BaseCommonCheck.isEmpty(form.getCpm2())
&& BaseCommonCheck.isDigit(form.getCpm1())
&& BaseCommonCheck.isDigit(form.getCpm2())
&& Integer.valueOf(form.getCpm1()).intValue() > Integer.valueOf(form.getCpm2()).intValue()) {
messages.setMessage("cpm2", form.getCpm2(), "10000017", Integer.MIN_VALUE);
}
return messages;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -