<%@ 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 = "", strFieldName = "", strIDName = "", strBtnName = ""; String strCompanyName = "", strSQLSort = "", strSortBtn = "", strPrevBtn = "", strNextBtn = ""; String [] arrBP; // CONTAINER FOR BRANDS/PRODUCTS int ctr = 0, total = 0; // USE FOR COUNTING TOTAL NUMBER OF BRANDS/PRODUCTS int batchModifier = 10; // IF EQUAL TO UNITS OF LAST BATCH, IT'LL BE COMBINED WITH SECOND TO LAST BATCH int batchMaxUnit = 40; // MAXIMUM NUMBER OF BRANDS/PRODUCTS THAT WOULD BE DISPLAY PER PAGE int intID = 0; // USE TO INDICATE IF TABLE IS EMPTY OF BRANCH/DOWNLINE OF A PARTICULAR COMPANY 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 *****/ switch (bytBtnID) { case 6: strTblName = "tblBrands"; strFieldName = "BrandName"; strIDName = "Brand_ID"; strPageTitle = "Brands"; strSubTitle = "LIST OF BRANDS"; strBtnName = "Brand"; break; case 7: strTblName = "tblProducts"; strFieldName = "Product"; strIDName = "Prod_ID"; strPageTitle = "Products"; strSubTitle = "LIST OF PRODUCTS"; strBtnName = "Product"; } 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"); } SQLstmt = "SELECT * FROM " + strTblName + " WHERE Co_ID=" + intCompanyID + ";"; rs = users.listQuery(SQLstmt); while (rs.next()) { intID = rs.getInt(strIDName); } if (bytLogStatus != 1) { // LOG CHECK RESULT - LOG-OUT, DISPLAYS HOME PAGE %> <% } else if (intID==0) { %> <% } 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"); } 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 " + 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 arrBP = new String[(ctr-intBegPoint)]; } else { if ((ctr-intEndPoint) <= batchModifier) { arrBP = new String[ctr-intBegPoint]; } else { arrBP = 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()) { arrBP[ctr] = rs.getString(strFieldName); ctr++; if (ctr==(arrBP.length)) { break; } } users.disconnect(); if (ctr == 1) { // THERE IS ONLY ONE BRAND/PRODUCT ENTRY, CHANGE TITLE TO SINGULAR if (bytBtnID == 6) { strSubTitle = "SOLE BRAND"; } else { // bytBtnID IS EQUAL TO 7 strSubTitle = "SOLE PRODUCT"; } } /***** MERGING WITH MAIN HTML CODES STARTS HERE *****/ %> <%= strPageTitle %>

COMPANY PROFILE
Company: <%= strCompanyName %>


<%= strSubTitle %>

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

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

<% } %> <% } %>

<% if (ctr == 1) { %> <% } else { %> <%= strSortBtn %> <% // if (intBegPoint == 0 && intEndPoint >= (total-batchModifier)) { %> <% // } else { %> <%= strPrevBtn %> <%= strNextBtn %> <% // } %> <% } %>

<% } // END OF LOG CHECK %>