int startat = startATparam.intValue();
int endat = EndAtparam.intValue();
int begainindex = Math.max(startat - 100, 1);
int endindex = endat + 100;
PromotionList DL = new PromotionList();
DL.setSortMember(sortmem);
CVDal cvdl = new CVDal(dataSource);
if (searchString == null)
searchString = "";
String appendStr = "";
String strSQL = "";
String sortType = "";
if (sorttype == 'D') {
sortType = " DESC ";
}
strSQL = "select e.Promotionid promotionid, e.title, description,startdate ,enddate, status, 0 as ordercount from `promotion` e order by "
+ sortmem + sortType + " LIMIT " + (begainindex - 1) + " , " + (endindex + 1) + ";";
if (searchString.startsWith("SIMPLE :")) {
searchString = searchString.substring(8);
appendStr = " where (e.Promotionid like '%" + searchString + "%' OR e.title like '%"
+ searchString + "%' OR description like '%" + searchString
+ "%' OR startdate like '%" + searchString + "%' OR enddate like '%" + searchString
+ "%' OR status like '%" + searchString + "%' ) order by ";
strSQL = strSQL.replaceFirst("order by", appendStr);
}
if ((null != searchString) && (searchString.startsWith("ADVANCE:"))) {
int searchIndex = (searchString.toUpperCase()).indexOf("WHERE");
strSQL = "select promotion.Promotionid promotionid, promotion.title, description,startdate ,enddate,"
+ "status, 0 as ordercount from `promotion` where "
+ searchString.substring((searchIndex + 5), searchString.length())
+ " order by "
+ sortmem + sortType + " LIMIT " + (begainindex - 1) + " , " + (endindex + 1) + ";";
}
cvdl.setSqlQuery(strSQL);
Collection v = cvdl.executeQuery();
cvdl.clearParameters();
cvdl.destroy();
Iterator it = v.iterator();
TimeZone tz = TimeZone.getTimeZone("EST");
int i = 0;
while (it.hasNext()) {
i++;
HashMap hm = (HashMap)it.next();
int ID = ((Long)hm.get("promotionid")).intValue();
IntMember promotionid = new IntMember("promotionid", ID, 10, "", 'T', false, 10);
StringMember title = new StringMember("title", (String)hm.get("title"), 10, "", 'T', true);
StringMember description = new StringMember("description", (String)hm.get("description"), 10,
"", 'T', false);
DateMember startdate = new DateMember("startdate", (java.util.Date)hm.get("startdate"), 10,
"URL", 'T', false, 100, "EST");
DateMember enddate = new DateMember("enddate", (java.util.Date)hm.get("enddate"), 10, "URL",
'T', false, 100, "EST");
StringMember status = new StringMember("status", (String)hm.get("status"), 10, "", 'T', false);
// int nooforder = ((Long)hm.get("nooforder")).intValue();
int nooforder = Integer.parseInt(hm.get("ordercount").toString());
IntMember nooforders = new IntMember("nooforders", nooforder, 10, "", 'T', false, 10);
PromotionListElement ele = new PromotionListElement(ID);
ele.put("promotionid", promotionid);
ele.put("title", title);
ele.put("description", description);
ele.put("startdate", startdate);
ele.put("enddate", enddate);
ele.put("status", status);
ele.put("nooforders", nooforders);
// added by Sameer for generating fixed length sort key from i
StringBuffer sb = new StringBuffer("00000000000");
sb.setLength(11);
String str = (new Integer(i)).toString();
sb.replace((sb.length() - str.length()), (sb.length()), str);
String newOrd = sb.toString();
DL.put(newOrd, ele);
DL.setTotalNoOfRecords(DL.size());
DL.setListType("Promotion");
DL.setBeginIndex(begainindex);
DL.setEndIndex(endindex);
}
return DL;