<%@ page language="java" import="java.sql.*, java.io.*, java.util.*, users.databases.*" errorPage="error.jsp" %> <% /***** VARIABLE DECLARATION and INITIALIZATION *****/ String strMainDB = "product_pgpClientInfoDB"; String strTblName = ""; // DETERMINES WHICH TABLE TO USE DEPENDING ON VALUE OF bytBtnID String strPageTitle = "", strSubTitle = "", strIDName = "", strFieldName = ""; String strCompanyName = "", strSQLSort = "", strSortBtn = "", strPrevBtn = "", strNextBtn = ""; String [] arrBPName, arrBPID; // CONTAINER FOR BRANDS/PRODUCTS NAMES AND ID'S int ctr = 0, total = 0; // USE FOR COUNTING TOTAL NUMBER OF BRANDS/PRODUCTS int batchModifier = 5; // IF EQUAL TO UNITS OF LAST BATCH, IT'LL BE COMBINED WITH SECOND TO LAST BATCH int batchMaxUnit = 20; // MAXIMUM NUMBER OF BRANDS/PRODUCTS THAT WOULD BE DISPLAYED PER PAGE int intUserID = Integer.parseInt(request.getParameter("uid")); int intCompanyID = Integer.parseInt(request.getParameter("cid")); byte bytBtnID = Byte.parseByte(request.getParameter("did")); String strSort = request.getParameter("srt"); int intBegPoint = Integer.parseInt(request.getParameter("p1")); int intEndPoint = Integer.parseInt(request.getParameter("p2")); /***** END OF VARIABLE DECLARATION *****/ String SQLstmt = "SELECT LogOnStatus FROM tblLogOn WHERE Usr_ID=" + intUserID + ";"; users.connect(strMainDB); ResultSet rs = users.listQuery(SQLstmt); byte bytLogStatus = 0; while (rs.next()) { bytLogStatus = rs.getByte("LogOnStatus"); } if (bytLogStatus != 1) { // LOG CHECK RESULT - LOG-OUT, DISPLAYS HOME PAGE %> <% } else { // LOG CHECK RESULT - LOG-ON, PROCEED DISPLAYING ACTUAL PAGE SQLstmt = "SELECT Co_Name FROM tblCompanyInfo WHERE Co_ID=" + intCompanyID + ";"; rs = users.listQuery(SQLstmt); while (rs.next()) { // GET NAME OF COMPANY strCompanyName = rs.getString("Co_Name"); } switch (bytBtnID) { case 6: strTblName = "tblBrands"; strIDName = "Brand_ID"; strFieldName = "BrandName"; strPageTitle = "Delete - Brands"; strSubTitle = "SELECT BRAND NAME TO BE DELETED"; break; case 7: strTblName = "tblProducts"; strIDName = "Prod_ID"; strFieldName = "Product"; strPageTitle = "Delete - Products"; strSubTitle = "SELECT PRODUCT NAME TO BE DELETED"; } strSort = "0"; // DEACTIVATES ALPHABETICAL SORTING if (strSort.equals("a")) { strSQLSort = " ORDER BY " + strFieldName + ";"; strSortBtn = ""; } else { if (bytBtnID==6) { strSQLSort = " ORDER BY Brand_ID;"; } else { strSQLSort = " ORDER BY Prod_ID;"; } strSortBtn = ""; } SQLstmt = "SELECT " + strIDName + ", " + strFieldName + " FROM " + strTblName + " WHERE Co_ID=" + intCompanyID + strSQLSort; rs = users.listQuery(SQLstmt); while (rs.next()) { ctr++; // COUNTS TOTAL NUMBER OF BRANDS/PRODUCTS } total = ctr; if (intEndPoint > ctr) { // TOTAL BRANDS/PRODUCTS TO BE DISPLAYED IS LESS THAN MAXIMUM arrBPName = new String[(ctr-intBegPoint)]; arrBPID = new String[(ctr-intBegPoint)]; } else { if ((ctr-intEndPoint) <= batchModifier) { arrBPName = new String[ctr-intBegPoint]; arrBPID = new String[ctr-intBegPoint]; } else { arrBPName = new String[(intEndPoint-intBegPoint)]; arrBPID = new String[(intEndPoint-intBegPoint)]; } } if (intBegPoint==0) { // NO PREVIOUS DATA TO DISPLAY strPrevBtn = ""; } else { // PREVIOUS BUTTON IS ACTIVATED strPrevBtn = ""; } if (intEndPoint > (ctr-batchModifier)) { // NO REMAINING DATA CAN BE DISPLAYED strNextBtn = ""; } else { // NEXT BUTTON IS ACTIVATED strNextBtn = ""; } if (intBegPoint==0) { // SINCE RESULTSET METHOD ABSOLUTE DOES NOT WORK WITH VALUE EQUAL TO ZERO rs.beforeFirst(); } else { rs.absolute(intBegPoint); } ctr = 0; while (rs.next()) { arrBPName[ctr] = rs.getString(strFieldName); arrBPID[ctr] = rs.getString(strIDName); ctr++; if (ctr==(arrBPName.length)) { break; } } /***** MERGING WITH MAIN HTML CODES STARTS HERE *****/ %> <%= strPageTitle %>

COMPANY PROFILE
Company: <%= strCompanyName %>


<%= strSubTitle %>

<% for (int i=0; i <% if (ctr == 1) { %> <%= arrBPName[i] %> <% } else { %> <%= arrBPName[i] %> <% } %> <% if ((i+1)==ctr && ctr != 1) { %>

showing <%= intBegPoint + 1 %>-<%= intBegPoint + ctr %> of <%= total %>

<% } else { %>
<% } %> <% } %>

<% // strSortBtn - WILL CONTAIN SORT BUTTON IF DECIDED TO INCLUDE %> <% if (intBegPoint == 0 && intEndPoint >= (total-batchModifier)) { %> <% } else { %> <%= strPrevBtn %> <%= strNextBtn %> <% } %>

<% } // END OF LOG CHECK %>