diff --git a/CodingComp2020/.classpath b/CodingComp2020/.classpath new file mode 100644 index 0000000..ae78809 --- /dev/null +++ b/CodingComp2020/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/CodingComp2020/.gitignore b/CodingComp2020/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/CodingComp2020/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/CodingComp2020/.project b/CodingComp2020/.project new file mode 100644 index 0000000..a6f2713 --- /dev/null +++ b/CodingComp2020/.project @@ -0,0 +1,17 @@ + + + CodingComp2020 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CodingComp2020/.settings/org.eclipse.jdt.core.prefs b/CodingComp2020/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CodingComp2020/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CodingComp2020/CoronaSystemReeshalRittoo.sql b/CodingComp2020/CoronaSystemReeshalRittoo.sql new file mode 100644 index 0000000..01bc478 --- /dev/null +++ b/CodingComp2020/CoronaSystemReeshalRittoo.sql @@ -0,0 +1,205 @@ +-- phpMyAdmin SQL Dump +-- version 4.9.0.1 +-- https://www.phpmyadmin.net/ +-- +-- Host: localhost +-- Generation Time: Apr 01, 2020 at 06:24 PM +-- Server version: 10.4.6-MariaDB +-- PHP Version: 7.3.8 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET AUTOCOMMIT = 0; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `CoronaSystem` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `dailyTimeslots` +-- + +CREATE TABLE `dailyTimeslots` ( + `shopId` int(11) NOT NULL, + `slots` time NOT NULL, + `servicecode` varchar(15) NOT NULL, + `customername` varchar(30) NOT NULL DEFAULT '' +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `dailyTimeslots` +-- + +INSERT INTO `dailyTimeslots` (`shopId`, `slots`, `servicecode`, `customername`) VALUES +(6, '08:30:00', '1AXBI6', ''), +(6, '09:00:00', 'UJ4A1X', ''), +(6, '09:30:00', '6HJYBN', ''), +(6, '10:00:00', 'DVWKIW', ''), +(6, '10:30:00', 'AFKHJA', ''), +(6, '11:00:00', 'PMVPHG', ''), +(6, '11:30:00', 'D44HRD', ''), +(6, '12:00:00', 'CNXD8I', ''), +(6, '12:30:00', 'T1YB3M', ''), +(6, '13:00:00', 'HF6DH0', ''), +(6, '13:30:00', 'P4OHON', ''), +(6, '14:00:00', 'PQFYN5', ''), +(6, '14:30:00', 'KZ1BQZ', ''), +(6, '15:00:00', 'N2DB45', ''), +(6, '15:30:00', 'E04NUN', 'Hitasha'), +(6, '16:00:00', 'ZE8W2M', 'Paupiah'), +(6, '16:30:00', '21VZZJ', 'Lavnish'), +(6, '17:00:00', '6X83SJ', ''), +(7, '09:25:00', 'ZQWREP', 'Vidushi'), +(7, '09:50:00', 'S7FRYY', ''), +(7, '10:15:00', 'UA0BRP', ''), +(7, '10:40:00', 'WB1V62', ''), +(7, '11:05:00', '013ERO', ''), +(7, '11:30:00', 'NHKMY6', ''), +(7, '11:55:00', 'BZ4MWS', ''), +(7, '12:20:00', 'JAU4V1', ''), +(7, '12:45:00', 'CUVOBP', 'Sadia'), +(7, '13:10:00', 'GB3WD5', ''), +(7, '13:35:00', 'I4O34H', ''), +(7, '14:00:00', 'RYQ2NI', ''), +(7, '14:25:00', 'TLLNZL', ''), +(7, '14:50:00', 'KQ7NWL', ''), +(7, '15:15:00', 'ZTY51H', ''), +(7, '15:40:00', 'PPZ5T2', 'Shakira'), +(7, '16:05:00', '53AS3W', ''), +(7, '16:30:00', 'S14XFB', 'Tashil'), +(7, '16:55:00', 'BBXIRL', 'Ria'), +(7, '17:20:00', '5PZO7A', ''), +(8, '09:45:00', 'VKRBUB', ''), +(8, '10:00:00', 'MM1QXV', ''), +(8, '10:15:00', 'VQ5X37', ''), +(8, '10:30:00', 'OXDCHV', ''), +(8, '10:45:00', 'G5EFKQ', 'Boosun'), +(8, '11:00:00', '3P01NB', ''), +(8, '11:15:00', 'H3G1QO', ''), +(8, '11:30:00', 'WWP2O5', ''), +(8, '11:45:00', 'GDUU0W', ''), +(8, '12:00:00', '876UNY', ''), +(8, '12:15:00', 'RJMHTX', ''), +(8, '12:30:00', 'M8AR05', ''), +(8, '12:45:00', 'H75B8W', ''), +(8, '13:00:00', 'QK3N81', ''), +(8, '13:15:00', '41X7DN', 'hena'), +(8, '13:30:00', '2TJY1C', 'YOYO'), +(8, '13:45:00', 'FKDQB8', ''), +(8, '14:00:00', '8TWA66', ''), +(8, '14:15:00', 'CEGF23', 'reeshal'), +(8, '14:30:00', '8PJ4VQ', ''), +(9, '06:35:00', 'GZ9S37', ''), +(9, '07:10:00', '07LI7M', ''), +(9, '07:45:00', 'OIGP81', ''), +(9, '08:20:00', '4G0BYX', ''), +(9, '08:55:00', 'QCBATB', ''), +(9, '09:30:00', 'E7NDA1', ''), +(9, '10:05:00', 'FKRG2O', ''), +(9, '10:40:00', '0XYQ1W', ''), +(9, '11:15:00', '5QIJY6', ''), +(9, '11:50:00', 'KU9NB9', ''), +(9, '12:25:00', 'DT1MLZ', ''), +(9, '13:00:00', 'DPLQPO', ''), +(9, '13:35:00', 'MLD5H7', ''), +(9, '14:10:00', '8KH8OK', ''), +(9, '14:45:00', '56OBNO', ''), +(9, '15:20:00', '205TWY', 'Yadhav'), +(9, '15:55:00', 'NBN8R5', ''), +(9, '16:30:00', 'ZHRIXD', ''), +(9, '17:05:00', '6SEAEK', ''), +(9, '17:40:00', 'IQ7K11', ''), +(10, '10:25:00', 'S11XM2', ''), +(10, '10:50:00', 'TUHG9O', ''), +(10, '11:15:00', 'Y089BB', ''), +(10, '11:40:00', 'OZ91T9', ''), +(10, '12:05:00', 'B4J4PH', ''), +(10, '12:30:00', 'NK2ZEZ', ''), +(10, '12:55:00', '1ID5NK', ''), +(10, '13:20:00', 'LYJF4C', ''), +(10, '13:45:00', '3LSBLA', ''), +(10, '14:10:00', '0F0GNP', ''), +(10, '14:35:00', 'KOY51N', ''), +(10, '15:00:00', 'YM101P', ''), +(10, '15:25:00', 'FYPX3U', ''), +(10, '15:50:00', 'P23XDX', ''), +(10, '16:15:00', '0A2E53', ''), +(10, '16:40:00', '7AXL1D', ''), +(10, '17:05:00', 'SBGBS7', ''), +(10, '17:30:00', 'Z9ZTNL', ''), +(10, '17:55:00', 'F4OMR4', ''), +(10, '18:20:00', '254PVV', ''), +(10, '18:45:00', 'D5N15Z', ''), +(11, '09:50:00', 'TDPW62', ''), +(11, '10:40:00', '9K56QL', ''), +(11, '11:30:00', '2KC6CB', ''), +(11, '12:20:00', '9SCB0T', ''), +(11, '13:10:00', 'K1PSEC', ''), +(11, '14:00:00', 'VPEFOF', ''), +(11, '14:50:00', 'OXK32S', ''), +(11, '15:40:00', 'SITHQS', ''), +(11, '16:30:00', 'A8BYJD', ''), +(11, '17:20:00', 'AVX4D9', ''); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `Supermarket` +-- + +CREATE TABLE `Supermarket` ( + `shopName` varchar(30) NOT NULL, + `shopAddress` varchar(50) NOT NULL, + `shopRSA` double NOT NULL, + `opening` time NOT NULL, + `closing` time NOT NULL, + `serviceTime` int(11) NOT NULL, + `shopId` int(11) NOT NULL, + `password` varchar(30) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `Supermarket` +-- + +INSERT INTO `Supermarket` (`shopName`, `shopAddress`, `shopRSA`, `opening`, `closing`, `serviceTime`, `shopId`, `password`) VALUES +('Dreamprice', 'Souillac', 9000, '08:00:00', '17:00:00', 30, 6, 'reeshal18'), +('Winners', 'Curepipe', 12000, '09:00:00', '17:30:00', 25, 7, 'reeshal18'), +('Intermart', 'Ebene', 12000, '09:30:00', '14:30:00', 15, 8, 'reeshal18'), +('Lolo', 'Morcellement Andre', 9800, '06:00:00', '18:00:00', 35, 9, 'reeshal18'), +('Shoprite', 'Trainon', 4560, '10:00:00', '19:00:00', 25, 10, 'reeshal18'), +('NewShop', 'Souillac', 450, '09:00:00', '18:00:00', 50, 11, 'reeshal17'); + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `Supermarket` +-- +ALTER TABLE `Supermarket` + ADD PRIMARY KEY (`shopId`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `Supermarket` +-- +ALTER TABLE `Supermarket` + MODIFY `shopId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12; +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/CodingComp2020/manual.png b/CodingComp2020/manual.png new file mode 100644 index 0000000..0b811a5 Binary files /dev/null and b/CodingComp2020/manual.png differ diff --git a/CodingComp2020/src/CoronaSystem/CustomerBooking.java b/CodingComp2020/src/CoronaSystem/CustomerBooking.java new file mode 100644 index 0000000..8b306dc --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/CustomerBooking.java @@ -0,0 +1,169 @@ +package CoronaSystem; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +public class CustomerBooking extends JPanel{ + JComboBox shopjc = new JComboBox(); + JComboBox timeslotjc = new JComboBox(); + JLabel lblshop, lblslot, lblcode, lblname, lblnote; + JTextField txtcode, txtname; + JButton submit; + JPanel a,b,c,d; + + String timeslots,servicecode, shopname; + int shopid; + ArrayList timeslotslist = new ArrayList(); + ArrayList servicecodelist = new ArrayList(); + ArrayList shopnamelist = new ArrayList(); + ArrayList shopidlist = new ArrayList(); + + Connection conn= DatabaseConnect.getConnection(); + + public CustomerBooking() { + setVisible(true); + setSize(500,500); + setLayout(new FlowLayout()); + positioning(); + actionEvent(); + } + + public void positioning() { + a=new JPanel(); + b=new JPanel(); + c=new JPanel(); + d=new JPanel(); + a.setLayout(new GridLayout(1,2,20,20)); + b.setLayout(new GridLayout(1,2,20,20)); + c.setLayout(new GridLayout(2,2,20,20)); + d.setLayout(new FlowLayout(FlowLayout.CENTER)); + lblshop= new JLabel("Choose a shop/supermarket"); + lblslot= new JLabel("Choose a timeslot"); + lblcode= new JLabel("Your Service Code"); + lblname= new JLabel("Insert Your Full Name"); + lblnote= new JLabel("You are requested to present your service code at the shop/supermarket"); + txtcode= new JTextField(); + txtcode.setPreferredSize(new Dimension(175,30)); + txtcode.setEditable(false); + txtname= new JTextField(); + submit=new JButton("Book"); + submit.setPreferredSize(new Dimension(200,50)); + a.add(lblshop); + a.add(shopjc); + b.add(lblslot); + b.add(timeslotjc); + c.add(lblcode); + c.add(txtcode); + c.add(lblname); + c.add(txtname); + d.add(submit); + + add(a); + add(b); + add(c); + add(d); + add(lblnote); + } + + public void actionEvent(){ + try { + Statement stt = conn.createStatement(); + stt.execute("SELECT shopName,shopId FROM Supermarket"); + ResultSet rs = stt.getResultSet(); + int i =0; + + if( rs != null) { + while(rs.next()) { + shopname=rs.getString("shopName"); + shopnamelist.add(shopname); + shopid=rs.getInt("shopId"); + shopidlist.add(shopid); + + shopjc.addItem(shopnamelist.get(i)); //adding type to the JtextField + + i++; + } + shopjc.setSelectedIndex(-1); + } + + shopjc.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent ie) { + int typeindex=shopjc.getSelectedIndex(); + int currentshopid= shopidlist.get(typeindex); + + //JOptionPane.showMessageDialog(null, typeindex); + String timeslotsql="SELECT slots, servicecode " + + "FROM dailyTimeslots WHERE customername ='' AND shopId="+currentshopid; + try { + stt.execute(timeslotsql); + ResultSet rs2 = stt.getResultSet(); + int j=0; + if( rs2 != null) { + while(rs2.next()) { + timeslots=rs2.getString("slots"); + timeslotslist.add(timeslots); + servicecode=rs2.getString("servicecode"); + servicecodelist.add(servicecode); + timeslotjc.addItem(timeslotslist.get(j)); //adding type to the JtextField + j++; + } + timeslotjc.setSelectedIndex(0); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + }); + + timeslotjc.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent ie) { + int typeindex=timeslotjc.getSelectedIndex(); + txtcode.setText(servicecodelist.get(typeindex)); + } + }); + + submit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(txtname.getText().equals("")) + JOptionPane.showMessageDialog(null, "Input Your Name"); + else { + String updateslot="UPDATE dailyTimeslots SET customername=? WHERE servicecode=?"; + try { + PreparedStatement prep = conn.prepareStatement(updateslot); + prep.setString(1, txtname.getText()); + prep.setString(2, txtcode.getText()); + prep.execute(); + JOptionPane.showMessageDialog(null, "Time Booked:"+timeslotslist.get(timeslotjc.getSelectedIndex())+". Service code:"+txtcode.getText()); + txtname.setText(""); + txtcode.setText(""); + shopjc.setSelectedIndex(0); + timeslotjc.setSelectedIndex(0); + main.frameSplit.setRightComponent(new CustomerBooking()); + + } catch (SQLException e1) { + e1.printStackTrace(); + } + } + + } + }); + + }catch(Exception e1) { + e1.printStackTrace(); + JOptionPane.showMessageDialog(null,e1.toString(),"FATAL ERROR!",JOptionPane.PLAIN_MESSAGE); + } + } + +// public static void main(String[] args) { +// CustomerBooking a= new CustomerBooking(); +// } +} diff --git a/CodingComp2020/src/CoronaSystem/DatabaseConnect.java b/CodingComp2020/src/CoronaSystem/DatabaseConnect.java new file mode 100755 index 0000000..6512f72 --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/DatabaseConnect.java @@ -0,0 +1,20 @@ +package CoronaSystem; +import java.sql.*; +import javax.swing.JOptionPane; +public class DatabaseConnect { + Connection conn=null; + + public static Connection getConnection() { + String username="root"; + String password=""; + try { + Class.forName("com.mysql.cj.jdbc.Driver").newInstance(); + Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/CoronaSystem",username,password); + return conn; + } + catch(Exception e) { + JOptionPane.showMessageDialog(null, "Database Conncetion Problem."); + } + return null; + } +} diff --git a/CodingComp2020/src/CoronaSystem/ServiceCodeGenerator.java b/CodingComp2020/src/CoronaSystem/ServiceCodeGenerator.java new file mode 100644 index 0000000..eb1a2e8 --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/ServiceCodeGenerator.java @@ -0,0 +1,22 @@ +package CoronaSystem; + +import java.security.SecureRandom; + +public class ServiceCodeGenerator { + + public static String generateServiceCode(){ + int len=6; + + // ASCII range - alphanumeric (0-9, s A-Z) + final String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + SecureRandom random = new SecureRandom(); + StringBuilder sb = new StringBuilder(); + // each iteration of loop choose a character randomly from the given ASCII range + // and append it to StringBuilder instance + for (int i = 0; i < len; i++) { + int randomIndex = random.nextInt(chars.length()); + sb.append(chars.charAt(randomIndex)); + } + return sb.toString(); + } +} diff --git a/CodingComp2020/src/CoronaSystem/ServiceCodeVerifier.java b/CodingComp2020/src/CoronaSystem/ServiceCodeVerifier.java new file mode 100644 index 0000000..65dda82 --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/ServiceCodeVerifier.java @@ -0,0 +1,152 @@ +package CoronaSystem; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.swing.*; +import javax.swing.border.Border; + +public class ServiceCodeVerifier extends JFrame{ + JLabel lblusername, lblcode, lbltimeslot, lblname, lblqueue; + JTextField txtcode, txttimeslot, txtname; + JButton verify, logout; + Connection conn= DatabaseConnect.getConnection(); + JPanel a,b,c,d,e, container; + public ServiceCodeVerifier() { + setLayout(new BorderLayout()); + setVisible(true); + setSize(800,500); + positioning(); + getQueue(); + } + + public void positioning() { + lblusername= new JLabel(SupermarketRegistration.username); + String info=": Max number of people who can queue in your premises:"+SupermarketRegistration.lengthofQueue; + lblqueue= new JLabel(info); + lblcode= new JLabel("Enter a Service Code"); + lbltimeslot= new JLabel("Timeslot"); + lblname= new JLabel("Customer Name"); + txtcode= new JTextField(15); + txtcode.setPreferredSize(new Dimension(200,40)); + txttimeslot= new JTextField(15); + txttimeslot.setPreferredSize(new Dimension(200,40)); + txtname= new JTextField(15); + txtname.setPreferredSize(new Dimension(200,40)); + txttimeslot.setEditable(false); + txtname.setEditable(false); + verify=new JButton("Verify Code"); + logout=new JButton("Logout"); + + logout.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + SupermarketRegistration.username=""; + SupermarketRegistration.shopid=0; + dispose(); + new main(); + } + }); + + a= new JPanel(); + b= new JPanel(); + c= new JPanel(); + d= new JPanel(); + e= new JPanel(); + container= new JPanel(); + + a.setLayout(new FlowLayout(FlowLayout.RIGHT)); + a.add(lblusername); + a.add(lblqueue); + a.add(Box.createRigidArea(new Dimension(100,0))); + a.add(logout); + a.setBorder(BorderFactory.createLineBorder(Color.black)); + b.setLayout(new FlowLayout()); + c.setLayout(new FlowLayout()); + d.setLayout(new FlowLayout(FlowLayout.CENTER)); + container.setLayout(new GridLayout(4,1)); + + b.add(lblcode); + b.add(txtcode); + c.add(lbltimeslot); + c.add(txttimeslot); + d.add(lblname); + d.add(txtname); + e.add(verify); + + container.add(b); + container.add(c); + container.add(d); + container.add(e); + + add(a, BorderLayout.NORTH); + add(container, BorderLayout.CENTER); + add(Box.createRigidArea(new Dimension(200,150)),BorderLayout.SOUTH); + verify.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(txtcode.getText().equals("")) + JOptionPane.showMessageDialog(null, "Input a Service Code"); + else { + try { + String query="SELECT slots, customername FROM dailyTimeslots WHERE servicecode='"+txtcode.getText()+"' AND shopId="+SupermarketRegistration.shopid; + Statement stt = conn.createStatement(); + stt.execute(query); + ResultSet rs = stt.getResultSet(); + int flag=0; + if( rs != null) { + //JOptionPane.showMessageDialog(null, rs); + while(rs.next()) { + txttimeslot.setText(rs.getString("slots")); + if(rs.getString("customername").equals("")) { + txtname.setText("Not yet booked"); + flag=2; + } + else { + txtname.setText(rs.getString("customername")); + flag=1; + } + } + } + if(flag==0) { + txttimeslot.setText("Service code not found"); + txtname.setText("Null"); + } + flag=0; + } + catch(SQLException se) { + se.printStackTrace(); + } + } + + } + }); + } + + public void getQueue() { + try { + int length=0; + String query="SELECT shopRSA FROM Supermarket WHERE shopId="+SupermarketRegistration.shopid; + Statement stt = conn.createStatement(); + stt.execute(query); + ResultSet rs = stt.getResultSet(); + if( rs != null) { + while(rs.next()) { + length=(int)(0.25 *(rs.getFloat("shopRSA")) / 4); + } + String info=": Max number of people who can queue in your premises:"+length; + + lblqueue.setText(info); + } + + }catch(SQLException se) { + se.printStackTrace(); + } + } +// public static void main(String[] args) { +// ServiceCodeVerifier a= new ServiceCodeVerifier(); +// } +} diff --git a/CodingComp2020/src/CoronaSystem/SupermarketLogin.java b/CodingComp2020/src/CoronaSystem/SupermarketLogin.java new file mode 100644 index 0000000..9a226d8 --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/SupermarketLogin.java @@ -0,0 +1,87 @@ +package CoronaSystem; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.swing.*; + +public class SupermarketLogin extends JPanel{ + JLabel lblpasswd, lblname; + JTextField txtpasswd, txtname; + JButton login; + JPanel a,b,c; + Connection conn= DatabaseConnect.getConnection(); + + public SupermarketLogin() { + setVisible(true); + setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + positioning(); + } + + public void positioning() { + lblname=new JLabel("Supermarket Name"); + lblpasswd=new JLabel("Password"); + txtname= new JTextField(15); + txtname.setPreferredSize(new Dimension(200,40)); + txtpasswd= new JTextField(15); + txtpasswd.setPreferredSize(new Dimension(200,40)); + login= new JButton("Login"); + a= new JPanel(); + b= new JPanel(); + c= new JPanel(); + a.setLayout(new FlowLayout()); + b.setLayout(new FlowLayout()); + c.setLayout(new FlowLayout()); + a.add(lblname); + a.add(txtname); + b.add(lblpasswd); + b.add(txtpasswd); + c.add(login); + add(a); + add(b); + add(c); + + login.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(txtname.getText().equals("") || txtpasswd.getText().equals("")) + JOptionPane.showMessageDialog(null, "Input all the values"); + else { + try { + int num=0; + Statement stt = conn.createStatement(); + PreparedStatement prep = conn.prepareStatement("SELECT shopId FROM Supermarket WHERE shopname = ? and password =?"); + prep.setString(1, txtname.getText()); + prep.setString(2, txtpasswd.getText()); + ResultSet res = prep.executeQuery(); + if(res!=null) { + SupermarketRegistration.username=txtname.getText(); + + while(res.next()) { + num++; + SupermarketRegistration.shopid=res.getInt("shopId"); + } + if(num==1) { + main.frameMainMenu.dispose(); + new ServiceCodeVerifier(); + } + else if(num==0) { + JOptionPane.showMessageDialog(null,"NO ACCOUNT FOUND"); + num=0; + } + } + + } catch (SQLException e1) { + e1.printStackTrace(); + } + } + } + }); + } + + +} diff --git a/CodingComp2020/src/CoronaSystem/SupermarketRegistration.java b/CodingComp2020/src/CoronaSystem/SupermarketRegistration.java new file mode 100644 index 0000000..05ca9d2 --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/SupermarketRegistration.java @@ -0,0 +1,174 @@ +package CoronaSystem; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +import javax.swing.*; + +public class SupermarketRegistration extends JPanel{ + JLabel lblname, lbladdress, lblretailspace, lblopening, lblclosing, lblavgtime, lblpasswrd; + JTextField txtname, txtaddress, txtretailspace, txtopening, txtclosing, txtavgtime,txtpasswd; + JButton btnregister; + JPanel btnpanel, itemspanel; + static int shopid; + Connection conn= DatabaseConnect.getConnection(); + public static String username; + public static int lengthofQueue; + + public SupermarketRegistration() { + setVisible(true); + setLayout(new FlowLayout()); + positioning(); + } + + public void positioning() { + itemspanel= new JPanel(); + itemspanel.setLayout(new GridLayout(7,2,20,20)); + + lblname= new JLabel("Shop Name"); + lbladdress= new JLabel("Shop Address"); + lblretailspace= new JLabel("Retail Space Area(m^2)"); + lblopening= new JLabel("Opening Time (hh:mm)"); + lblclosing= new JLabel("Closing Time (hh:mm)"); + lblavgtime= new JLabel("Average Service Time (min)"); + lblpasswrd= new JLabel("Password"); + + txtname= new JTextField(); + txtname.setPreferredSize(new Dimension(200,40)); + txtaddress= new JTextField(); + txtaddress.setPreferredSize(new Dimension(200,40)); + txtretailspace= new JTextField(); + txtretailspace.setPreferredSize(new Dimension(200,40)); + txtopening= new JTextField(); + txtopening.setPreferredSize(new Dimension(200,40)); + txtclosing= new JTextField(); + txtclosing.setPreferredSize(new Dimension(200,40)); + txtavgtime= new JTextField(); + txtavgtime.setPreferredSize(new Dimension(200,40)); + txtpasswd= new JTextField(); + txtpasswd.setPreferredSize(new Dimension(200,40)); + + itemspanel.add(lblname); + itemspanel.add(txtname); + itemspanel.add(lbladdress); + itemspanel.add(txtaddress); + itemspanel.add(lblretailspace); + itemspanel.add(txtretailspace); + itemspanel.add(lblopening); + itemspanel.add(txtopening); + itemspanel.add(lblclosing); + itemspanel.add(txtclosing); + itemspanel.add(lblavgtime); + itemspanel.add(txtavgtime); + itemspanel.add(lblpasswrd); + itemspanel.add(txtpasswd); + + btnpanel= new JPanel(); + btnregister= new JButton("Register"); + btnpanel.add(btnregister); + + JPanel notepnl= new JPanel(); + JLabel notelbl= new JLabel("Note: Please Read Manual First"); + notepnl.add(notelbl); + + add(itemspanel); + add(btnpanel); + add(notelbl); + + Handler h= new Handler(); + btnregister.addActionListener(h); + + } + public class Handler implements ActionListener{ + + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if(e.getSource()==btnregister) { + + try { + Statement stt = conn.createStatement(); + String insertsql="INSERT INTO Supermarket(shopName,shopAddress,shopRSA,opening,closing,serviceTime,password) VALUES(?,?,?,?,?,?,?)"; + PreparedStatement prep = conn.prepareStatement(insertsql); + prep.setString(1, txtname.getText()); + prep.setString(2, txtaddress.getText()); + prep.setFloat(3, Float.parseFloat(txtretailspace.getText())); + prep.setString(4, txtopening.getText()); + prep.setString(5, txtclosing.getText()); + prep.setString(6, txtavgtime.getText()); + prep.setString(7, txtpasswd.getText()); + prep.execute(); + + lengthofQueue=(int)(0.25 *(Float.parseFloat(txtretailspace.getText()) / 4)); + + PreparedStatement sqlfetchshopId=conn.prepareStatement("SELECT shopId FROM Supermarket WHERE shopName=?"); + sqlfetchshopId.setString(1, txtname.getText()); + ResultSet rs = sqlfetchshopId.executeQuery(); + if( rs != null) { + while( rs.next()) { + shopid = rs.getInt("shopId"); + } + } + timeslotGenerator(); + SupermarketRegistration.username=txtname.getText(); + main.frameMainMenu.dispose(); + new ServiceCodeVerifier(); + + } catch (SQLException e1) { + e1.printStackTrace(); + } catch (ParseException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + + } + + public void timeslotGenerator() throws ParseException { + int interval=Integer.parseInt(txtavgtime.getText()); + String start=txtopening.getText(); + String end=txtclosing.getText(); + String current=start; + + while(true) { + SimpleDateFormat df = new SimpleDateFormat("HH:mm"); + java.util.Date d = df.parse(current); + Calendar cal = Calendar.getInstance(); + cal.setTime(d); + cal.add(Calendar.MINUTE, interval); + String newTime = df.format(cal.getTime()); + + if(df.parse(newTime).after(df.parse(end))) + break; + else { + try { + String insertsql2="INSERT INTO dailyTimeslots(shopId,slots,servicecode,customername) VALUES(?,?,?,?)"; + PreparedStatement prep = conn.prepareStatement(insertsql2); + prep.setInt(1, shopid); + prep.setString(2, newTime); + prep.setString(3, ServiceCodeGenerator.generateServiceCode()); + prep.setString(4, ""); + prep.execute(); + } + catch (SQLException e1) { + e1.printStackTrace(); + } + current=newTime; + } + } + } + +// public static void main(String[] args) throws ParseException { +// SupermarketRegistration a= new SupermarketRegistration(); +// +// } +} diff --git a/CodingComp2020/src/CoronaSystem/main.java b/CodingComp2020/src/CoronaSystem/main.java new file mode 100644 index 0000000..ed347dc --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/main.java @@ -0,0 +1,103 @@ +package CoronaSystem; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.*; + +public class main extends JFrame{ + static JFrame frameMainMenu = new JFrame("Homepage"); + static JSplitPane frameSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);//Split menu into 2 parts + static JPanel panelMainMenu = new JPanel();//left panel containing all buttons + static JPanel panelGrid = new JPanel(); //to insert the pages + JSeparator emptySpaceInMenuBar= new JSeparator(JSeparator.VERTICAL); + + public main() { + frameMainMenu.setLayout(new BorderLayout()); + frameMainMenu.setVisible(true); + frameMainMenu.setSize(700,500); + positioning(); + frameSplit.setRightComponent(new CustomerBooking()); + frameMainMenu.setLocationRelativeTo(null); + + } + + public void positioning() { + //making the side bar + panelMainMenu.setLayout(new BoxLayout(panelMainMenu, BoxLayout.Y_AXIS)); + panelMainMenu.setPreferredSize(new Dimension(150, 500)); + + JButton Login= new JButton("Login"); + JButton Register= new JButton("Register"); + JButton Book= new JButton("Book a slot"); + JButton Manual= new JButton("Read Manual"); + + Login.setAlignmentX(Component.CENTER_ALIGNMENT); + Login.setPreferredSize(new Dimension(150, 50)); + Login.setMaximumSize(new Dimension(Short.MAX_VALUE, 100)); + + Register.setAlignmentX(Component.CENTER_ALIGNMENT); + Register.setPreferredSize(new Dimension(150, 50)); + Register.setMaximumSize(new Dimension(Short.MAX_VALUE, 100)); + + Book.setAlignmentX(Component.CENTER_ALIGNMENT); + Book.setPreferredSize(new Dimension(150, 50)); + Book.setMaximumSize(new Dimension(Short.MAX_VALUE, 100)); + + Manual.setAlignmentX(Component.CENTER_ALIGNMENT); + Manual.setPreferredSize(new Dimension(150, 50)); + Manual.setMaximumSize(new Dimension(Short.MAX_VALUE, 100)); + + emptySpaceInMenuBar.setPreferredSize(new Dimension(50,200)); + panelMainMenu.add(new JSeparator(JSeparator.VERTICAL), BorderLayout.LINE_START); + panelMainMenu.add(Login); + panelMainMenu.add(new JSeparator(JSeparator.VERTICAL), BorderLayout.LINE_START); + panelMainMenu.add(Register); + panelMainMenu.add(new JSeparator(JSeparator.VERTICAL), BorderLayout.LINE_START); + panelMainMenu.add(Book); + panelMainMenu.add(new JSeparator(JSeparator.VERTICAL), BorderLayout.LINE_START); + panelMainMenu.add(Manual); + panelMainMenu.add(emptySpaceInMenuBar, BorderLayout.LINE_START); + + //add Grid Panel and splitting frame + panelGrid.setBorder(BorderFactory.createLineBorder(Color.black)); + + frameSplit.setLeftComponent(panelMainMenu); + frameSplit.setRightComponent(panelGrid); + + frameMainMenu.add(frameSplit,BorderLayout.CENTER); + + handlerMainMenu handlerMainMenu = new handlerMainMenu(); + Login.addActionListener(handlerMainMenu); + Register.addActionListener(handlerMainMenu); + Book.addActionListener(handlerMainMenu); + Manual.addActionListener(handlerMainMenu); + } + public static class handlerMainMenu implements ActionListener{ + public void actionPerformed(ActionEvent event) { + // TODO Auto-generated method stub + String action = event.getActionCommand(); + try { + if(action.equals("Login")) { + frameSplit.setRightComponent(new SupermarketLogin()); + } + if(action.equals("Register")) { + frameSplit.setRightComponent(new SupermarketRegistration()); + } + if(action.equals("Book a slot")) { + frameSplit.setRightComponent(new CustomerBooking()); + } + if(action.equals("Read Manual")) { + frameSplit.setRightComponent(new manual()); + } + } + catch(Throwable e){ + } + } + } + public static void main(String[] args) { + // TODO Auto-generated method stub + main a= new main(); + } + +} diff --git a/CodingComp2020/src/CoronaSystem/manual.java b/CodingComp2020/src/CoronaSystem/manual.java new file mode 100644 index 0000000..bbb0c38 --- /dev/null +++ b/CodingComp2020/src/CoronaSystem/manual.java @@ -0,0 +1,19 @@ +package CoronaSystem; +import java.awt.*; +import javax.swing.*; + +public class manual extends JPanel { + + public manual() { + setSize(550,500); + setVisible(true); + setLayout(new FlowLayout()); + + Image maleimage=new ImageIcon("manual.png").getImage().getScaledInstance(550,450, java.awt.Image.SCALE_SMOOTH);; + ImageIcon maleicon=new ImageIcon(maleimage); + JLabel Micon = new JLabel(maleicon); + Micon.setAlignmentX(Component.CENTER_ALIGNMENT); + add(Micon); + } + +}