package com.ilp.tsi.pm.servlets;
import java.io.*;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ilp.tsi.pm.beans.StockBean;
import com.ilp.tsi.db.*;
import com.ilp.tsi.pm.services.StockService;
/**
* Servlet implementation class AddServlet1
*/
//Servlet for Adding the stock
public class AddStockServlet extends HttpServlet {
Connection con=null;
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AddStockServlet() {
//super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
//System.out.println("hi");
//System.out.println(req.getParameter("name1"));
//Method to get the model name
if(req.getParameter("name1")!=null)
{
//System.out.println(" inside getModelName");
try
{
DB dao=new DB();
con=dao.getConnection();
}
catch (Exception e)
{
// System.out.println(e);
}
StockService stock_service=new StockService();
StockBean bean=new StockBean();
String productId= req.getParameter("productId");
// System.out.println(productId);
bean.setProductId(productId);
//boolean chk = false;
try
{
bean = stock_service.productModelName(bean,con);
req.setAttribute("a", bean.getProductId());
req.setAttribute("b", bean.getModelName());
RequestDispatcher rd = req.getRequestDispatcher("add_stock.jsp");
rd.forward(req, res);
}
catch (SQLException e)
{
// System.out.println(" Exception occured ");
e.printStackTrace();
}
}
//method for passing control to add stock
if(req.getParameter("add")!=null)
{
DB dao=new DB();
con=dao.getConnection();
StockBean bean = new StockBean();
StockService service1 = new StockService();
String productId=req.getParameter("productId");
bean.setProductId(productId);
// System.out.println(productId);
String modelName=req.getParameter("modelName");
bean.setModelName(modelName);
String ss=req.getParameter("quantity");
int quantity=Integer.parseInt(ss);
bean.setQuantity(quantity);
try {
boolean chk=service1.AddStock(bean,con);
RequestDispatcher rd = req.getRequestDispatcher("stock_added_successfully.jsp");
rd.forward(req, res);
}
catch (NumberFormatException e)
{
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
-
-
-
-
-
package com.ilp.tsi.pm.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.ilp.tsi.db.DB;
import com.ilp.tsi.utils.*;
/**
* Servlet implementation class Changepwd
*/
public class ChangeIMPassword extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ChangeIMPassword() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
//getting the user entered password and username
String cpwd=req.getParameter("cpwd");
String npwd=req.getParameter("npwd");
res.setContentType(Constant.content);
Connection conn = null;
Statement stmt = null;
ResultSet rst = null;
try
{
DB dao=new DB();
conn=dao.getConnection();
stmt=conn.createStatement();
rst = stmt.executeQuery("select password from IM_DETAILS");
PrintWriter out = res.getWriter();
HttpSession session=req.getSession(true);
String id=(String) session.getAttribute("imid");
while(rst.next())
{
// comparing user entered password with password field in Inventory manager table
if(cpwd.equals(rst.getString(1)))
{
String str="update IM_DETAILS set PASSWORD='"+npwd+"' where IM_ID='"+id+"'";
stmt.executeUpdate(str);
stmt.executeQuery("commit");
res.sendRedirect("main1.html");
}
else if(!(cpwd.equals(rst.getString(1))))
{
res.sendRedirect("changeIMPassword.jsp");
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try {
conn.close();
stmt.close();
rst.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
-
-
-
-
-
package com.ilp.tsi.pm.servlets;
import com.ilp.tsi.pm.services.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ilp.tsi.pm.beans.ProductBean;
import com.ilp.tsi.db.*;
import java.sql.*;
/**
* Servlet implementation class ProductServlet
*/
//servlet for product
public class ProductServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Connection con=null;
/**
* @see HttpServlet#HttpServlet()
*/
public ProductServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try
{
DB dao=new DB();
con=dao.getConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
//method for passing control to add product
if(request.getParameter("addproduct")!=null)
{
ProductBean bean=new ProductBean();
ProductServices service=new ProductServices();
bean.setProductName(request.getParameter("productName"));
bean.setDescription(request.getParameter("desc"));
bean.setFeatures(request.getParameter("features"));
bean.setPrice(request.getParameter("price"));
bean.setQuantity(Integer.parseInt(request.getParameter("quantity")));
bean.setEligibility(request.getParameter("eligibility"));
bean.setThresholdLimit(request.getParameter("thresholdLimit"));
String qty=request.getParameter("quantity");
String tlimit=request.getParameter("thresholdLimit");
if(qty.compareTo(tlimit)>5)
{
bean.setColorCode("GREEN");
}
if(qty.compareTo(tlimit)<0)
{
bean.setColorCode("RED");
}
if(qty.compareTo(tlimit)<=5 && qty.compareTo(tlimit)>0)
{
bean.setColorCode("ORANGE");
}
boolean chk=false;
boolean chk1=false;
try
{
chk=service.addProduct(bean, con);
response.sendRedirect("adding_productmodel.jsp");
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
if(chk)
{
RequestDispatcher rd=request.getRequestDispatcher("adding_productmodel.jsp");
rd.forward(request,response);
}
}
//method for passing control to update product
if(request.getParameter("updateproduct")!=null)
{
ProductServices service=new ProductServices();
ProductBean bean = new ProductBean();
bean.setProductName(request.getParameter("productName"));
bean.setDescription(request.getParameter("desc"));
bean.setFeatures(request.getParameter("features"));
bean.setPrice(request.getParameter("price"));
bean.setQuantity(Integer.parseInt(request.getParameter("quantity")));
bean.setEligibility(request.getParameter("eligibility"));
bean.setThresholdLimit(request.getParameter("thresholdLimit"));
try{
service.updateProduct(bean, con);
response.sendRedirect("updating_productmodel.jsp");
}
catch(SQLException E)
{
}
}
//method for passing control to search product
if(request.getParameter("searchproduct")!=null)
{
String ProductName = request.getParameter("productName");
ProductServices service=new ProductServices();
ProductBean bean=new ProductBean();
bean.setProductName(ProductName);
boolean chk = false;
try
{
bean = service.searchProduct(bean, con);
request.setAttribute("a", bean.getProductName());
request.setAttribute("b", bean.getPrice());
request.setAttribute("c", bean.getQuantity());
request.setAttribute("d", bean.getThresholdLimit());
request.setAttribute("e", bean.getEligibility());
RequestDispatcher rd = request.getRequestDispatcher("update_product.jsp");
rd.forward(request, response);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if(request.getParameter("search_deleteproduct")!=null)
{
String productId = request.getParameter("productId");
ProductServices service=new ProductServices();
ProductBean bean=new ProductBean();
bean.setProductId(productId);
boolean chk = false;
try
{
bean = service.searchDeleteProduct(bean, con);
request.setAttribute("a", bean.getProductId());
request.setAttribute("b", bean.getPrice());
request.setAttribute("c", bean.getQuantity());
request.setAttribute("d", bean.getThresholdLimit());
request.setAttribute("e", bean.getEligibility());
RequestDispatcher rd = request.getRequestDispatcher("delete_product.jsp");
rd.forward(request, response);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
//method for passing control to delete product
if(request.getParameter("deleteproduct")!=null)
{
ProductServices service=new ProductServices();
ProductBean bean = new ProductBean();
bean.setProductId(request.getParameter("productId"));
bean.setDescription(request.getParameter("desc"));
bean.setFeatures(request.getParameter("features"));
bean.setPrice(request.getParameter("price"));
bean.setQuantity(Integer.parseInt(request.getParameter("quantity")));
bean.setEligibility(request.getParameter("eligibility"));
bean.setThresholdLimit(request.getParameter("thresholdLimit"));
try{
service.deleteProduct(bean, con);
response.sendRedirect("deleting_productmodel.jsp");
}
catch(SQLException E)
{
}
}
//method for passing control to above threshold
if(request.getParameter("abovethreshold")!=null)
{
ProductBean bean=new ProductBean();
ProductServices service=new ProductServices();
boolean chk=false;
try
{
chk=service.aboveThreshold(bean, con);
response.sendRedirect("above_thresholdlimit.jsp");
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
if(chk)
{
RequestDispatcher rd=request.getRequestDispatcher("above_thresholdlimit.jsp");
rd.forward(request,response);
}
}
//method for passing control to near threshold
if(request.getParameter("nearthreshold")!=null)
{
ProductBean bean=new ProductBean();
ProductServices service=new ProductServices();
boolean chk=false;
try
{
chk=service.nearThreshold(bean, con);
response.sendRedirect("near_thresholdlimit.jsp");
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
if(chk)
{
RequestDispatcher rd=request.getRequestDispatcher("near_thresholdlimit.jsp");
rd.forward(request,response);
}
}
//method for passing control to below threshold
if(request.getParameter("belowthreshold")!=null)
{
ProductBean bean=new ProductBean();
ProductServices service=new ProductServices();
boolean chk=false;
try
{
chk=service.belowThreshold(bean, con);
response.sendRedirect("below_thresholdlimit.jsp");
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
if(chk)
{
RequestDispatcher rd=request.getRequestDispatcher("below_thresholdlimit.jsp");
rd.forward(request,response);
}
}
}
}
-
-
-
-
-
package com.ilp.tsi.um.servlets;
import java.sql.*;
import com.ilp.tsi.db.DB;
import java.io.*;
import javax.servlet.http.HttpSession;
import com.ilp.tsi.um.beans.Prodtag;
import com.ilp.tsi.utils.Constant;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Inserttag extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
//getting the value of checked checkBoxes
String checks[]=req.getParameterValues("checks[]");
res.setContentType(Constant.content);
PrintWriter out = res.getWriter();
Prodtag prodbean=new Prodtag();
//creating a session
HttpSession session=req.getSession();
prodbean=(Prodtag)session.getAttribute("retid");
String retid=prodbean.getRetailerId();
try
{
Connection conn=null;
Statement stmt=null;
DB obj=new DB();
conn=obj.getConnection(); //connecting to database
stmt=conn.createStatement(); // getting object for Statement class
ResultSet rs=null;
// inserting retailer id and product id in ret_prod table
for(int i=0;i<checks.length;i++)
{
rs=stmt.executeQuery("select product_id from product where prod_model_name='"+checks[i]+ "'");
String temp="";
if(rs.next())
{
temp=rs.getString(1);
}
stmt.executeQuery("insert into RET_PROD (retailer_id, product_id) values ( '" +retid+ "' , '" +temp+ "')");
stmt.executeQuery("commit");
}
res.sendRedirect("about.jsp");
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
-
-
-
-
package com.ilp.tsi.um.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ilp.tsi.um.beans.*;
import com.ilp.tsi.db.DB;
import javax.servlet.http.HttpSession;
import java.sql.*;
/**
* Servlet implementation class EditRetailer
*/
public class EditRetailer extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public EditRetailer() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Connection conn=null;
Statement stmt=null;
ResultSet rs=null,rs1=null;
//getting the session attribute value
HttpSession session=req.getSession();
String retId=(String)session.getAttribute("retId");
try{
DB obj=new DB();
conn=obj.getConnection();
stmt=conn.createStatement();
//getting the user entered values
String user=req.getParameter("user");
String addr=req.getParameter("add");
String id=req.getParameter("email");
String cnum=req.getParameter("num");
//updating retailer table with the user entered values
rs=stmt.executeQuery("update retailer set retailer_name='"+user+"',contact_no='"+cnum+"',address='"+addr+"',email_id='"+id+"' where retailer_id='"+retId+"'" );
res.sendRedirect("viewret.jsp");
}
catch(SQLException E)
{
E.printStackTrace();
}
finally
{
try
{conn.close();
stmt.close();
}
catch(SQLException E)
{
E.printStackTrace();
}
}
}
}
-
-
-
-
package com.ilp.tsi.um.servlets;
import java.io.IOException;
//import java.io.PrintWriter;
import java.sql.Connection;
//import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.ilp.tsi.db.DB;
import com.ilp.tsi.utils.Constant;
/**
* Servlet implementation class login_admin
*/
public class Login_Admin extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Login_Admin() {
super();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
String username=req.getParameter("user");
String pwd=req.getParameter("pwd");
res.setContentType(Constant.content);
Connection conn = null;
Statement stmt = null;
ResultSet rst = null;
try
{
DB obj=new DB();
conn=obj.getConnection();
stmt=conn.createStatement();
//retrieving the admin id and password fields from admin table
rst = stmt.executeQuery("select admin_id, password from admin");
int temp=0;
while(rst.next())
{
//compares the user entered values with the record in admin table
if((username.equals(rst.getString(1))) && (pwd.equals(rst.getString(2))))
{
//if password and username matches redirects to home_admin page
temp++;
//res.sendRedirect("home_admin.jsp");
break;
}
}
if(temp==1)
{
res.sendRedirect("home_admin.jsp");
}
else
{
RequestDispatcher rd=req.getRequestDispatcher("login_admin.jsp");
req.setAttribute("flag", "false");
rd.forward(req,res);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try {
conn.close();
stmt.close();
rst.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
-
-
-
-
package com.ilp.tsi.um.servlets;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.ilp.tsi.db.DB;
/**
* Servlet implementation class Untag
*/
public class Untag extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Untag() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
HttpSession session=req.getSession();
//retrieving the retailer id
String retId=(String)session.getAttribute("retId");
try
{
DB obj=new DB();
conn=obj.getConnection();
stmt=conn.createStatement();
String[] check=req.getParameterValues("check");
for(int i=0;i<check.length;i++)
{
//Untagging products before deleting
rs=stmt.executeQuery("delete from ret_prod where ((retailer_id='"+retId+"') and (product_id='"+check[i]+"')) ");
}
response.sendRedirect("editretailer.jsp");
}
catch(Exception E)
{
E.printStackTrace();
}
finally
{
try{
conn.close();
stmt.close();
}
catch(Exception F)
{
F.printStackTrace();
}
}
}
}