package com.Dao;

import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

import com.Model.Admin;
import com.Model.Customer;

public class AdminLoginOperation {
	
	public int checkLogin(int eId, String ePwd){
		int check = 0;
		java.sql.Connection con = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		System.out.println("Inside DAo");
		try {
			Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
			
			con = DriverManager.getConnection("jdbc:derby:D:\\Users\\2787891\\MyDB;create=true");
			
			String sql = "SELECT * FROM admin WHERE empId = ? AND empPwd = ?";
			pst = con.prepareStatement(sql);
			pst.setInt(1, eId);
			pst.setString(2, ePwd);
			
			System.out.println("**********Inside the DAO************");
			//rs contains all the rows received after the execution of the SQL query
			rs = pst.executeQuery();
			if(rs.next()){
				check = 1;
			}
//			while(rs.next()){
//				Admin ad = new Admin();
//				System.out.println(rs.getInt(1)+" "+rs.getString(2));
//				if(rs.getInt(1)==ad.getEmpId() && rs.getString(2).equals(ad.getPwd())){
//					check = 1;
//				}
//			}
			
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return check;
	}
	
	
	
	public int insertCustomer(Customer c)
	{
		int check=0;
		java.sql.Connection con=null;
		PreparedStatement pst=null;
		
		
		try {
			
			Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
			
			con = DriverManager.getConnection("jdbc:derby:D:\\Users\\2787891\\MyDB;create=true");
			
			String sql="insert into customer(custId, cPwd, cSsnId, firstName, lastName, email, address, contactNo, aadharNo, panNo, acNo, initialAmt, acStatus)values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
			
			pst= con.prepareStatement(sql);
			
			pst.setString(1, c.getcId());
			pst.setString(2, c.getcPwd());
			pst.setString(3, c.getcSsnId());
			pst.setString(4, c.getfName());
			pst.setString(5, c.getlName());
			pst.setString(6, c.getEmail());
			pst.setString(7, c.getAddress());
			pst.setString(8, c.getContactNo());
			pst.setString(9, c.getAadharNo());
			pst.setString(10, c.getPanNo());
			pst.setInt(11, c.getAcNo());
			pst.setInt(12, c.getInitialAmt());
			pst.setBoolean(13, c.getAcStatus());

			
			check=pst.executeUpdate();
			
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return check;
	}
	
}
