diff --git a/DB/Script.sql b/DB/Script.sql new file mode 100644 index 0000000..aabdeec --- /dev/null +++ b/DB/Script.sql @@ -0,0 +1,49 @@ +create database Buffer; + +use Buffer; + +create table Supplier_info(S_ID int Primary key,S_name varchar(30) Not null,Shop_name varchar(30) Not null,S_city varchar(30) Not null,S_pincode int Not null,S_pass int not null); +insert into Supplier_info values(101,"Arnav J.","Apple Store","Pune",411038,123); +insert into Supplier_info values(102,"Aryan K.","Siddhivinayak Store","Pune",411021,234); +insert into Supplier_info values(103,"Soham P.","Wellness Store","Pune",411038,345); +insert into Supplier_info values(104,"Sahil P.","Jeevan Store","Pune",411028,456); +insert into Supplier_info values(105,"Arya V.","MedPlus Store","Pune",411052,567); +insert into Supplier_info values(106,"Tejas k.","Laxmi Medico","Pune",411035,678); +insert into Supplier_info values(107,"Sachin C.","Krishna Medicals","Pune",411045,789); +insert into Supplier_info values(108,"Abhiman G.","Sai Samarth medioc","Pune",411052,890); +insert into Supplier_info values(109,"Ashutosh S.","Medico Store","Pune",411021,100); +insert into Supplier_info values(110,"Arjit P.","Prime Medicals","Pune",411035,200); + + +create table Medicine_info( +S_ID int Not null, +M_ID int Not null, +Med_name varchar(50) Not null, +Med_type varchar(20) Not null, +Price decimal(10,2) Not null, +Quantity int Not null, +Num_Tablets int default 0, +Volume int default 0, + +Foreign key(S_ID) references Supplier_info(S_ID), +Unique (S_ID,M_ID) +); + +insert into Medicine_info values(101,201,"Crocin","Tablet",33.6,20,15,0); +insert into Medicine_info values(101,202,"Ondem 4" ,"Tablet",56,30,10,0); +insert into Medicine_info values(101,203,"Ondem 8","Tablet",100,30,10,0); +insert into Medicine_info values(101,204,"Ondem Syrup","Syrup",40,20,0,30); +insert into Medicine_info values(101,205,"Dolo 650","Tablet",33.6,30,15,0); +insert into Medicine_info values(101,206,"Dolo 500","Tablet",13.8,10,15,0); +insert into Medicine_info values(101,207,"Dabur Honitus Syrup","Syrup",106,30,0,100); +insert into Medicine_info values(101,208,"Dabur Honitus logenzes","Tablet",16.3,10,10,0); +insert into Medicine_info values(102,202,"Ondem 4","Tablet",56,30,10,0); +insert into Medicine_info values(102,209,"Aspirin","Tablet",60,50,10,0); +insert into Medicine_info values(102,205,"Dolo 650","Tablet",33.6,30,15,0); +insert into Medicine_info values(102,207,"Dabur Honitus Syrup","Syrup",106,20,0,100); +insert into Medicine_info values(102,201,"Crocin","Tablet",33.6,50,15,0); +insert into Medicine_info values(103,202,"Ondem 4","Tablet",56,33,10,0); +insert into Medicine_info values(103,201,"Crocin","Tablet",33.6,20,15,0); +insert into Medicine_info values(103,201,"Crocin","Tablet",33.6,20,15,0); +insert into Medicine_info values(103,210,"Aprise D3","Tablet",100,30,15,0); +insert into Medicine_info values(103,213,"Combiflam","Tablet",50,30,15,0); diff --git a/README.md b/README.md index 910ff0f..8fc6e8d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,46 @@ -# Buffer-5.0 -Buffer is a Data Structures and Algorithms Project Series, in which students can participate as mentees in teams of 2-4. Under Buffer 5.0, the themes on which students can create a project are: +# Team: GenCoders + +## Problem Statement: A pharmaceutical digital platform connects consumers with suppliers to efficiently purchase drugs, matching them based on location and availability. + +Theme: Public welfare. +Project Description: +Our module has 3 login interfaces: Customer, Supplier and Admin. +The user can login or sign up into their respective interface(all validations are provided accordingly). +The customer data is stored in a hash-table with the customer id as key and the remaining attributes as value. +Once the user has logged in as a customer he/she will be provided with the following options: +1.Order Medicines +2.Recent Orders +3.Update details +4.LogOut + +Medicines will be supplied to the customer from the nearest supplier based on location(which we have considered to be the pin code of the customer). +As soon as the bill is generated for the purchased medicines the order is added to queue(pending deliveries) on the supplier side. +Supplier:- +The supplier and medicine data is stored in the database. The supplier is provided with the following options: +1.Add Medicines +2.Update Medicine Quantity +3.Delete Medicine +4.Display All Information +5.Pending Deliveries +6.Deliver Orders +7.LogOut + + +Admin: +The admin can access the supplier as well as the customer side by performing the following functionalities: +1.Display All Customers +2.Add Customer +3.Delete Customer +4.Search Customer + +1.Display All Suppliers +2.Add Supplier +3.Delete Supplier + +link to video -> https://drive.google.com/file/d/1dPj-VcT47tKX8VtPRidTC-50xyGlEGT0/view?usp=sharing + +link to report 2 -> https://drive.google.com/file/d/1sCN6_qFo8gJaChjZvyvDIEFKfen8C99s/view?usp=sharing + +link to report 1->https://drive.google.com/file/d/1PGv7bP0duYYs3o56u1uUgA0MwugRxKLr/view?usp=sharing -1. Public Welfare -2. Tourism -3. College level applications -4. Custom Data structure -This repository is created for all the teams to be able to upload their final project source code. While submitting, note that all the submission guidelines given are followed, and all the files are named appropiately. Also ensure that your README file contains the links of the progress reports and the drive link containing the video of the project. diff --git a/mysql-connector-java-8.0.11(1).jar b/mysql-connector-java-8.0.11(1).jar new file mode 100644 index 0000000..f554c30 Binary files /dev/null and b/mysql-connector-java-8.0.11(1).jar differ diff --git a/src/Buffer_Pharma/Admin.java b/src/Buffer_Pharma/Admin.java new file mode 100644 index 0000000..072e067 --- /dev/null +++ b/src/Buffer_Pharma/Admin.java @@ -0,0 +1,106 @@ +package Buffer_Pharma; + +import java.util.*; +class Admin { + static Customer cobj=new Customer(); + static Supplier sobj=new Supplier(); + static Db mdb=new Db(); + static Scanner sc=new Scanner(System.in); + static String username="admin"; + static String password="admin123"; + + void Amain() { + boolean login=false; + boolean logout=false; + + do { + System.out.println("=================== Admin ==================="); + while(!login) { + System.out.println("Username: "); + String user=sc.next(); + if(user.equals(username)) { + System.out.println("Enter Password: "); + String pass=sc.next(); + if(pass.equals(password)){ + System.out.println("SignIn Successful!"); + login=true; + } + else { + System.out.println("Password is Incorrect"); + } + } + else { + System.out.println("Username does not exist"); + } + } + + int ch,m; + do { + System.out.println("-----Menu-----"); + System.out.println("1.Customer Side\n2.Supplier Side\n3.LogOut"); + m=sc.nextInt(); + switch(m) { + case 1: + do { + System.out.println("1.Display All Customers\n2.Add Customer\n3.Delete Customer\n4.Search Customer\n5.Back"); + ch=sc.nextInt(); + switch(ch){ + case 1: + cobj.Cacc_displayall();; + break; + + case 2: + cobj.Cacc_insert(); + break; + + case 3: + cobj.Cacc_delete();; + break; + + case 4: + System.out.print("Enter Cid"); + String tcid=sc.next(); + CustomerAcc c=cobj.Cacc_search(tcid); + cobj.Ccurr_display(c); + break; + } + } + while(ch!=5); + break; + + case 2: + do { + System.out.println("1.Display All Suppliers\n2.Add Supplier\n3.Delete Supplier\n4.Back"); + ch=sc.nextInt(); + switch(ch){ + case 1: + sobj.Sacc_displayAll(); + break; + + case 2: + sobj.Sacc_insert(); + break; + + case 3: + sobj.Sacc_delete(); + break; + } + + } + while(ch!=4); + break; + + case 3: + System.out.println("\nLogging out...\n"); + System.out.print("\nReturning to main page...\n"); + login=false; + logout=true; + break; + } + } + while(login); + } + while(!logout); + } +} + diff --git a/src/Buffer_Pharma/Customer.java b/src/Buffer_Pharma/Customer.java new file mode 100644 index 0000000..dda5831 --- /dev/null +++ b/src/Buffer_Pharma/Customer.java @@ -0,0 +1,364 @@ +package Buffer_Pharma; + +import java.util.*; +import java.text.SimpleDateFormat; + +class CustomerAcc{ + String Cid; + String C_Name; + String C_phno; + String C_pass; + String C_City; + int C_pincode; + CustomerAcc next; + CustomerAcc(){ + next=null; + } +} + +class Order{ + int M_id; + int M_quantity; + String date; + Order next; + Order(){ + this.M_quantity=0; + this.next=null; + } + +} + +class Customer{ + static Hashtable C_ht1=new Hashtable<>(); + static Hashtable C_ht2=new Hashtable<>(); + //Order O_head=null; + Scanner sc=new Scanner(System.in); + Db db=new Db(); + Supplier s=new Supplier(); + + //-------------------------------- Customer CRUD ---------------------------------- + void Cacc_insert(){ + int x=0; + do{ + CustomerAcc Ctemp=new CustomerAcc(); + Random rand = new Random(); + int id = rand.nextInt(10000); + Ctemp.Cid= "C"+id; + while(C_ht1.containsKey(Ctemp.Cid)){ + int id1 = rand.nextInt(10000); + Ctemp.Cid="C"+id1; + System.out.println("-----"); + } + System.out.println("Set Password: "); + Ctemp.C_pass=sc.nextLine(); + System.out.println("Enter the name of Customer: "); + Ctemp.C_Name=sc.nextLine(); + System.out.println("Enter the City of Customer: "); + Ctemp.C_City=sc.nextLine(); + System.out.println("Enter Pincode: "); + Ctemp.C_pincode=sc.nextInt(); + while(String.valueOf(Ctemp.C_pincode).length()!=6){ + System.out.println("Pincode is incorrect\t\tEnter correct pincode "); + Ctemp.C_pincode=sc.nextInt(); + } + Order Otemp = new Order(); + C_ht1.put(Ctemp.Cid,Ctemp); + C_ht2.put(Ctemp,Otemp); + //System.out.println(Ctemp.Cid); + System.out.println("Account Created Successfully!! \nLoginID: "+Ctemp.Cid+"\t Password: "+Ctemp.C_pass); + System.out.print("Add another Account? Enter y/n : 1/0"); + x=sc.nextInt(); + sc.nextLine(); + } + while(x!=0); + } + + void Cacc_insert(String cid,String name,String City,String pass,int pin){ + CustomerAcc Ctemp=new CustomerAcc(); + Ctemp.Cid=cid; + Ctemp.C_pass=pass; + Ctemp.C_Name=name; + Ctemp.C_City=City; + Ctemp.C_pincode=pin; + Order Otemp = new Order(); + C_ht1.put(Ctemp.Cid,Ctemp); + C_ht2.put(Ctemp,Otemp); + } + + void Cacc_displayall(){ + CustomerAcc ctemp; + Order otemp; + for (String i : C_ht1.keySet()) { + ctemp=C_ht1.get(i); + if(ctemp!=null){ + System.out.println(i+ "\t"+ ctemp.C_Name+"\t"+ctemp.C_City); + otemp=C_ht2.get(ctemp); + int k=0; + while(otemp!=null){ + System.out.println(k+ "\t"+ otemp.M_id+"\t"+otemp.M_quantity); + otemp=otemp.next; + k++; + } + System.out.println("-----------------------------------"); + } + } + } + + void Cacc_update(String cid){ + CustomerAcc ct=Cacc_search(cid); + if(ct!=null){ + System.out.println("Enter the City of Customer: "); + ct.C_City=sc.next(); + System.out.println("Enter Pincode: "); + ct.C_pincode=sc.nextInt(); + while(String.valueOf(ct.C_pincode).length()!=6){ + System.out.println("Pincode is incorrect\t\tEnter correct pincode "); + ct.C_pincode=sc.nextInt(); + } + + System.out.println("Updated Successfully!"); + System.out.println("-----Details-----\nCID\t"+ct.Cid+"\nName\t"+ ct.C_Name+"\nCity\t"+ct.C_City+"\nPincode\t"+ct.C_pincode); + } + } + + void Cacc_delete(){ + System.out.println("Enter Customer ID: "); + String cidtemp=sc.next(); + CustomerAcc ctemp=Cacc_search(cidtemp); + if(ctemp!=null){ + Order temp=C_ht2.get(ctemp); + C_ht2.remove(temp); + C_ht1.remove(cidtemp); + } + } + + CustomerAcc Cacc_search(String cid){ + CustomerAcc ctemp=C_ht1.get(cid); + if(ctemp!=null){ + return ctemp; + } + else{ + System.out.println("Enter valid Customer ID"); + return null; + } + } + + //-------------------------------- Order Medicines -------------------------------- + int C_Order(CustomerAcc c){ + c=Cacc_search(c.Cid); + int y=0; + if(c!=null){ + Order O_head=C_ht2.get(c); + int x; + + do{ + y= db.search(); + if(y!=0) { + Order Onn=new Order(); + System.out.println("Enter ID of medicine: "); + Onn.M_id=sc.nextInt(); + System.out.println("Enter Quantity of medicine: "); + Onn.M_quantity=sc.nextInt(); + Onn.next=O_head; + O_head=Onn; + C_ht2.put(c,O_head); + SimpleDateFormat ft = new SimpleDateFormat("dd-MM-yyyy"); + String str = ft.format(new Date()); + Onn.date=str; + System.out.println("Do you want to add one more Medicine? 1.YES 2. NO"); + x=sc.nextInt(); + } + else{ + break;} + } + while(x!=2); + } + return y; + } + + void Ccurr_display(CustomerAcc temp){ + // System.out.println(temp.Cid+"\t"+ temp.C_Name+"\t"+temp.C_City); + if(temp!=null) { + Order otemp=C_ht2.get(temp); + int k=1; + System.out.println("Order Summary"); + + System.out.println("\nSr No\tMID\tQuantity\tDate"); + while(otemp.next!=null){ + System.out.println(k+ "\t"+ otemp.M_id+"\t"+otemp.M_quantity+"\t"+otemp.date); + otemp=otemp.next; + k++; + } + } + } + +// void NearestSearch(CustomerAcc temp,String date) { +// Order otemp=C_ht2.get(temp); +// while(otemp.next!=null && otemp.date.equals(date)) { +// int ID=otemp.M_id; +// int quan=otemp.M_quantity; +// int pincode=temp.C_pincode; +// String shopname=db.check(ID,quan,pincode); +// if(shopname.equals("null")) { +// System.out.println("Insufficient quantity.."); +// } +// System.out.println(shopname); +// otemp=otemp.next; +// } +// } + + void showq(int sid) { + db.checkOrders(sid); + } + + void bill(CustomerAcc c,String date) { + Order otemp=C_ht2.get(c); + double total = 0; + int k=1; + System.out.println("Sr No\tMID\tQuantity\tDate\tPrice\tSupplier"); + while(otemp.next!=null && otemp.date.equals(date)) { + String Sname=db.check(otemp.M_id,otemp.M_quantity,c.C_pincode); + if(Sname.equals("null")) { + System.out.println("\n\n\bInsufficient quantity.."); + break; + } + double price=db.FindPrice(otemp.M_id); + System.out.println(k+"\t"+ otemp.M_id+"\t"+otemp.M_quantity+"\t"+otemp.date+"\t"+(otemp.M_quantity*price)+"\t"+Sname); + total=total+otemp.M_quantity*price; + k++; + db.Updatemed(Sname,otemp.M_id,otemp.M_quantity); + otemp=otemp.next; + } + System.out.print("-----------------------------------------------\nTotal\t"+total); + System.out.println(); + } + + void S_deliver(int sid) { + db.Dequeue(sid); + } + + //---------------------------- Customer Main method ------------------------------- + CustomerAcc C_login(){ + System.out.println("Enter Customer ID: "); + String cidtemp=sc.next(); + CustomerAcc ctemp=Cacc_search(cidtemp); + if(ctemp!=null){ + System.out.println("Enter Password: "); + String pass=sc.next(); + if(pass.equals(ctemp.C_pass)){ + System.out.println("SignIn Successful!"); + return ctemp; + } + else{ + System.out.println("Password is Incorrect"); + return null; + } + } + System.out.println("LogIn ID\tNOT FOUND"); + return null; + } + + void C_SignUp(){ + CustomerAcc Ctemp=new CustomerAcc(); + Random rand = new Random(); + int id = rand.nextInt(10000); + Ctemp.Cid= "C"+id; + while(C_ht1.containsKey(Ctemp.Cid)){ + int id1 = rand.nextInt(10000); + Ctemp.Cid="C"+id1; + System.out.println("-----"); + } + System.out.println("Set Password: "); + Ctemp.C_pass=sc.next(); + System.out.println("Enter the name of Customer: "); + Ctemp.C_Name=sc.next(); + System.out.println("Enter the City of Customer: "); + Ctemp.C_City=sc.next(); + System.out.println("Enter Pincode: "); + Ctemp.C_pincode=sc.nextInt(); + while(String.valueOf(Ctemp.C_pincode).length()!=6){ + System.out.println("Pincode is incorrect\t\tEnter correct pincode "); + Ctemp.C_pincode=sc.nextInt(); + } + Order Otemp = new Order(); + C_ht1.put(Ctemp.Cid,Ctemp); + C_ht2.put(Ctemp,Otemp); + System.out.println(Ctemp.Cid); + System.out.println("Account Created Successfully!! \nLoginID: "+Ctemp.Cid+"\t Password: "+Ctemp.C_pass); + } + + void Cmain() { + Scanner s= new Scanner(System.in); + Customer obj=new Customer(); + CustomerAcc currAcc=null; + boolean login=false; + int ls,ch; + + + + + do{ + do{ + System.out.println("=================== Customer ==================="); + System.out.println("1. Log In \n2. Sign Up\n3. Exit"); + ls=s.nextInt(); + switch(ls){ + case 1: + currAcc=obj.C_login(); + login=true; + break; + + case 2: + obj.C_SignUp(); + break; + + case 3: + System.out.print("\nReturning to main page...\n"); + break; + } + } + while((!login && currAcc==null)); + + if(currAcc!=null){ + System.out.println("-----------------\nWelcome "+currAcc.C_Name); + System.out.println("-----Details-----\nCID\t"+currAcc.Cid+"\nName\t"+ currAcc.C_Name+"\nCity\t"+currAcc.C_City+"\nPincode\t"+currAcc.C_pincode); + do{ + System.out.println(); + System.out.println("-----Menu-----"); + System.out.println("1.Order Med\n2.Recent Orders\n3.Update details\n4.LogOut"); + ch=s.nextInt(); + switch(ch){ + case 1: + int y=obj.C_Order(currAcc); + //obj.Ccurr_display(currAcc); + if(y!=0) { + System.out.println("***Order Summary***"); + SimpleDateFormat ft = new SimpleDateFormat("dd-MM-yyyy"); + String datestr = ft.format(new Date()); + + + obj.bill(currAcc,datestr); + }else { + System.out.println("Medicine not available.."); + } + + break; + + case 2: + obj.Ccurr_display(currAcc); + break; + + case 3: + obj.Cacc_update(currAcc.Cid); + break; + } + } + while(ch!=4); + System.out.println("\nLogging out...\n"); + currAcc=null; + } + } + while(ls!=3); + } +} + diff --git a/src/Buffer_Pharma/Db.java b/src/Buffer_Pharma/Db.java new file mode 100644 index 0000000..2fe1e5e --- /dev/null +++ b/src/Buffer_Pharma/Db.java @@ -0,0 +1,258 @@ +package Buffer_Pharma; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import java.util.*; +import java.lang.*; + +class Db{ + static final String JDBC_Driver="com.mysql.cj.jdbc.Driver"; + static final String DB_URL="jdbc:mysql://localhost:3306/Buffer?allowPublicKeyRetrieval=true&&useSSL=false"; + static final String User="root"; + static final String Pass="mysql@123"; + + Connection conn=null; + PreparedStatement pstmt=null; + String Query=""; + static Scanner sc=new Scanner(System.in); + static Hashtable ht=new Hashtable<>(); + static Db meddb=new Db(); + + + int search() { + System.out.println("Enter the name of medicine: "); + String med=sc.nextLine(); + int flag=0; + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query="Select distinct M_ID,Med_name,Price,Med_type,Case when Med_Type=? then Num_Tablets else Volume end as Quantity from Medicine_info"+" where LOCATE(?,Med_name)!=0"; + pstmt=conn.prepareStatement(Query); + pstmt.setString(1, "Tablet"); + pstmt.setString(2, med); + ResultSet rs=pstmt.executeQuery(); + + while(rs.next()) { + flag=1; + int id=rs.getInt("M_ID"); + String name=rs.getString("Med_name"); + int cost=rs.getInt("Price"); + String type=rs.getString("Med_type"); + int quantity=rs.getInt("Quantity"); + String ans=""; + if(type.equals("Tablet")) { + ans="Strip of "+quantity+" tablets"; + } + else { + ans="Bottle of "+quantity+" ml"; + } + System.out.println(id+")"+"Medicine name: "+ name+" "+"Price: "+cost+" "+ans); + + + } + + rs.close(); + pstmt.close(); + conn.close(); + + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } +catch(SQLException se){ + se.printStackTrace(); + } + return flag; + } + + void med_displayAll() { + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query= "select * from Medicine_info"; + pstmt=conn.prepareStatement(Query); + ResultSet rs=pstmt.executeQuery(); + + System.out.println("MID\tProvided by(SID)\t\tName\t\t\tCity\tPincode"); + while(rs.next()){ + int sid = rs.getInt("S_ID"); + int mid = rs.getInt("M_ID"); + String mname = rs.getString("Med_name"); + String medtype = rs.getString("Med_type"); + int price = rs.getInt("Price"); + int Quantity=rs.getInt("Quantity"); + int nooftab=rs.getInt("Num_Tablets"); + int Volume=rs.getInt("Volume"); + System.out.println( sid + "\t"+ mid + "\t" + mname + "\t" + medtype+"\t"+price+"\t"+Quantity+"\t"+nooftab+"\t"+Volume); + } + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + } + + String check(int id,int q,int pin) { + int ID=0; + String name=""; + int flag=0; + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query="Select Supplier_info.S_ID,Supplier_info.Shop_name from Supplier_info inner join Medicine_info on Supplier_info.S_ID=Medicine_info.S_ID where Medicine_info.M_ID=? and Medicine_info.Quantity>=? Order by ABS(Supplier_info.S_pincode-?),Medicine_info.Quantity Desc limit 1 ;"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, id); + pstmt.setInt(2, q); + pstmt.setInt(3, pin); + ResultSet rs=pstmt.executeQuery(); + + while(rs.next()) { + flag=1; + ID=rs.getInt("S_ID"); + name=rs.getString("Shop_name"); + } + if(flag==1) { + orders(ID,id,q,pin,name); + } + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } +catch(SQLException se){ + se.printStackTrace(); + } + if(flag==0) { + return "null"; + } + return name; + } + + double FindPrice(int id) { + double price=0; + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query="Select Price from Medicine_info where M_ID=? Order by Price limit 1;"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, id); + + ResultSet rs=pstmt.executeQuery(); + + while(rs.next()) { + + price=rs.getInt("Price"); + } + rs.close(); + pstmt.close(); + conn.close(); + + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } +catch(SQLException se){ + se.printStackTrace(); + } + return price; + } +//static + void orders(int SID,int mid,int q,int pin,String name) { + S_Order obj=new S_Order(mid,q,pin,name); + Queue queue=new LinkedList(); + if(!ht.containsKey(SID)) { + queue.add(obj); + ht.put(SID,queue); + } + else { + Queue a=ht.get(SID); + a.add(obj); + ht.put(SID, a); + } +// Queue b=new LinkedList(); +// for (int i : ht.keySet()) { +// b=ht.get(i); +// +// for(S_Order item : b){ +// System.out.println(i+" "+item.MID+" "+item.name); +// } +// +// } + } + //static + void checkOrders(int ID) { + System.out.println("MID\t Quantity"); + Queue a=new LinkedList(); + try { + for (int i : ht.keySet()) { + a=ht.get(i); + + for(S_Order item : a){ + System.out.println(item.MID+" "+item.quantity); + } + + } + } + catch(NullPointerException e) { + e.printStackTrace(); + System.out.println("No medicines to be delivered...."); + } + } + + void Updatemed(String shopname,int MID,int q) { + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query="update Medicine_info inner join Supplier_info on Supplier_info.S_ID=Medicine_info.S_ID set Medicine_info.Quantity=Medicine_info.Quantity-? where Supplier_info.Shop_name=? and Medicine_info.M_ID=?"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, q); + pstmt.setString(2, shopname); + pstmt.setInt(3, MID); + pstmt.executeUpdate(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + } + + static void Dequeue(int sID) { + System.out.println("Have you delivered the order??(Yes/No)"); + String ans=sc.nextLine(); + if(ans.equals("Yes")) { + Queue a=new LinkedList(); + a=ht.get(sID); + a.remove(); + ht.put(sID,a); + } + } + +// public static void main(String[] args) { +// orders(103,202,1, 411038, "Ondem"); +// checkOrders(103); +// } +} + +class S_Order{ + int MID; + int quantity; + int pincode; + String name; + S_Order(int x,int y,int z,String a){ + MID=x; + quantity=y; + pincode=z; + name= a; + } +} \ No newline at end of file diff --git a/src/Buffer_Pharma/Main.java b/src/Buffer_Pharma/Main.java new file mode 100644 index 0000000..252ab17 --- /dev/null +++ b/src/Buffer_Pharma/Main.java @@ -0,0 +1,45 @@ +package Buffer_Pharma; + +import java.util.Scanner; + +public class Main { + + static Customer cobj=new Customer(); + static Supplier sobj=new Supplier(); + static Admin aobj=new Admin(); + static Db mdb=new Db(); + static Scanner sc=new Scanner(System.in); + + + public static void main(String[] args) { + int ls; + //inserting initial values + cobj.Cacc_insert("C122","Anjali Shah","Pune","123",411038); + cobj.Cacc_insert("C123","Pranav Joshi","Pune","456",4110381); + cobj.Cacc_insert("C342","Janhavi Birla","Pune","789",411035); + cobj.Cacc_insert("C876","Ajay Patil","Pune","098",411052); + cobj.Cacc_insert("C577","Radha Sane","Pune","765",411001); + + do{ + System.out.println("\n*************|||-- WELCOME --|||**************"); + System.out.println("1. Customer LogIn \n2. Supplier LogIn\n3. Admin LogIn\n4. Exit"); + ls=sc.nextInt(); + switch(ls){ + case 1: + cobj.Cmain(); + break; + + case 2: + sobj.Smain(); + break; + + case 3: + aobj.Amain(); + break; + } + } + while(ls!=4); + System.out.print("***************|||-- EXIT --|||****************"); + } + +} diff --git a/src/Buffer_Pharma/Supplier.java b/src/Buffer_Pharma/Supplier.java new file mode 100644 index 0000000..51986f5 --- /dev/null +++ b/src/Buffer_Pharma/Supplier.java @@ -0,0 +1,499 @@ +package Buffer_Pharma; + +import java.sql.*; +import java.util.Random; +import java.util.Scanner; + +class Supplier{ + static final String JDBC_Driver="com.mysql.cj.jdbc.Driver"; + static final String DB_URL="jdbc:mysql://localhost:3306/Buffer?allowPublicKeyRetrieval=true&&useSSL=false"; + static final String User="root"; + static final String Pass="mysql@123"; + + Connection conn=null; + PreparedStatement pstmt=null; + String Query=""; + Scanner sc=new Scanner(System.in); + Db meddb=new Db(); + + + + //----------------------------------- Supplier Account CRUD --------------------------- + void Sacc_insert() { + System.out.println("Enter name: "); + String name=sc.nextLine(); + System.out.println("Enter city: "); + String city=sc.nextLine(); + System.out.println("Enter pincode: "); + int pin=sc.nextInt(); + sc.nextLine(); + System.out.println("Enter Shopname: "); + String shop=sc.nextLine(); + + while(pin<100000) { + System.out.println("Incorrect pincode..."); + System.out.println("Enter correct pincode: "); + pin=sc.nextInt(); + } + sc.nextLine(); + + Random ran=new Random(); + int r=ran.nextInt(200); + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + int flag=0; + ResultSet rs=null; + boolean Supplier=true; + while(Supplier) { + Query="select * from Supplier_info where S_ID=?"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, r); + rs=pstmt.executeQuery(); + + while(rs.next()) { + flag=1; + } + if(flag==0) { + Supplier=false; + }else { + + r=ran.nextInt(200); + flag=0; + } + } + int pass=0; + + if(flag==0) { + System.out.println("Account generated successfully...."); + System.out.println("Your login ID is: "+r); + + System.out.println("Enter password: "); + pass=sc.nextInt(); + } + + Query="insert into Supplier_info(S_ID,S_name,Shop_name,S_city,S_pincode,S_pass) values(?,?,?,?,?,?)"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, r); + pstmt.setString(2, name); + pstmt.setString(3, shop); + pstmt.setString(4, city); + pstmt.setInt(5, pin); + pstmt.setInt(6, pass); + + pstmt.executeUpdate(); + System.out.println("Success!!!!!!"); + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } +catch(SQLException se){ + se.printStackTrace(); + } + } + + void Sacc_displayAll() { + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query= "select * from Supplier_info"; + pstmt=conn.prepareStatement(Query); + ResultSet rs=pstmt.executeQuery(); + + System.out.println("SID\tOwner\t\tShop\t\t\tCity\tPincode"); + while(rs.next()){ + int sid = rs.getInt("S_ID"); + String sname = rs.getString("S_name"); + String shopname = rs.getString("Shop_name"); + String scity = rs.getString("S_city"); + String pin=rs.getString("S_pincode"); + System.out.println( sid + "\t"+ sname + "\t" + shopname + "\t" + scity+"\t"+pin); + } + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + } + + void Sacc_update() { + System.out.println("Enter SID: "); + int sid=sc.nextInt(); + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query= "select * from Supplier_info where S_ID=?"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, sid); + ResultSet rs=pstmt.executeQuery(); + if(rs.next()) { + System.out.println("Enter city: "); + String city=sc.next(); + System.out.println("Enter pincode: "); + int pin=sc.nextInt(); + Query="update Supplier_info set S_city=?,S_pincode=? where S_ID=?"; + pstmt=conn.prepareStatement(Query); + pstmt.setString(1, city); + pstmt.setInt(2, pin); + pstmt.setInt(3, sid); + pstmt.executeUpdate(); + } + else { + System.out.print("Supplier ID not found"); + } + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + + } + + void Sacc_delete() { + System.out.print("Enter SID of Supplier to be Deleted: "); + int sdel=sc.nextInt(); + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + + try( + PreparedStatement psfk=conn.prepareStatement("SET FOREIGN_KEY_CHECKS=0;"); + PreparedStatement psDel = conn.prepareStatement("delete from Supplier_info where S_ID = ? "); + ) + + { + psfk.execute(); + psDel.setInt(1, sdel); + //psDel.execute(); + if (psDel.executeUpdate() > 0) + System.out.println("Record deleted successfully."); + else + System.out.println("Record not found."); + + psfk.close(); + psDel.close(); + } + catch (Exception e) { + System.out.println(e.getMessage()); + } + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + + } + + //----------------------------------- Supplier-Medicine CRUD -------------------------- + void Scurr_displayCurr(int sid) { +// System.out.print("Enter SID: "); +// int tsid=sc.nextInt(); + + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query= "select * from Supplier_info where S_ID=?"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, sid); + ResultSet rs=pstmt.executeQuery(); + if(rs.next()) { + int tsid = rs.getInt("S_ID"); + String sname = rs.getString("S_name"); + String shopname = rs.getString("Shop_name"); + String scity = rs.getString("S_city"); + String pin=rs.getString("S_pincode"); + System.out.println("-----------------\nWelcome "+sname); + System.out.println("-----Details-----\nSID\t"+tsid + "\nOwner\t "+ sname + "\nShop\t" + shopname + "\nCity\t" + scity+"\nPincode\t"+pin); + + System.out.println("\nMedicines:"); + String Query1= "select * from Medicine_info where S_ID=?"; + PreparedStatement pstmt1=conn.prepareStatement(Query1); + pstmt1.setInt(1, tsid); + ResultSet rs1=pstmt1.executeQuery(); + System.out.println( "M_ID\tMed_name\tMed_type\tPrice\tQuantity\tNo of Tablets\tVolume\n---------------------------------------------------------------------------------------"); + while(rs1.next()) { + System.out.println( rs1.getInt("M_ID") + "\t"+ rs1.getString("Med_name") + "\t\t" + rs1.getString("Med_type") + "\t\t" + rs1.getBigDecimal("Price")+"\t"+rs1.getInt("Quantity")+"\t\t"+rs1.getInt("Num_Tablets")+"\t\t"+rs1.getInt("Volume")); + } + rs1.close(); + + } + else { + System.out.println("No supplier found with SID: " + sid); + } + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + } + + void Scurr_addmed(int sid) { + System.out.println("Enter M_ID: "); + int mid=sc.nextInt(); + System.out.println("Enter Medicine Name: "); + String med_name=sc.next(); + System.out.println("Enter Medicine type: "); + String med_type=sc.next(); + System.out.println("Enter Medicine Quantity: "); + int quan=sc.nextInt(); + System.out.println("Enter Medicine Price: "); + int price=sc.nextInt(); + System.out.println("Enter No of Tablets: "); + int nooftb=sc.nextInt(); + System.out.println("Enter Medicine Volume(for syrup med only): "); + int vol=sc.nextInt(); + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + String Query1= "insert into Medicine_info values (?,?,?,?,?,?,?,?)"; + PreparedStatement pstmt1=conn.prepareStatement(Query1); + pstmt1.setInt(1, sid); + pstmt1.setInt(2, mid); + pstmt1.setString(3, med_name); + pstmt1.setString(4, med_type); + pstmt1.setInt(5, price); + pstmt1.setInt(6, quan); + pstmt1.setInt(7, nooftb); + pstmt1.setInt(8, vol); + pstmt1.executeUpdate(); + System.out.println("Added Successfully!"); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + } + + void Scurr_delmed(int sid) { + System.out.println("Enter Medicine Name: "); + String med_name=sc.next(); + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + + try( + PreparedStatement psfk=conn.prepareStatement("SET FOREIGN_KEY_CHECKS=0;"); + PreparedStatement psDel = conn.prepareStatement("delete from Medicine_info where S_ID = ? and Med_name =? "); + ) + + { + psfk.execute(); + psDel.setInt(1, sid); + psDel.setString(2, med_name); + //psDel.execute(); + if (psDel.executeUpdate() > 0) + System.out.println("Medicine deleted successfully."); + else + System.out.println("Medicine not found."); + + psfk.close(); + psDel.close(); + } + catch (Exception e) { + System.out.println(e.getMessage()); + } + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + } + + void Scurr_updatemed_quan(int sid) { + System.out.println("Enter M_ID: "); + int mid=sc.nextInt(); + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query= "select * from Medicine_info where S_ID = ? and M_ID=? "; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, sid); + pstmt.setInt(2, mid); + ResultSet rs=pstmt.executeQuery(); + if(rs.next()) { + System.out.println("Enter Quantity: "); + int quan=sc.nextInt(); + Query="update Medicine_info set Quantity=? where S_ID=? and M_ID=?"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, quan); + pstmt.setInt(2, sid); + pstmt.setInt(3, mid); + pstmt.executeUpdate(); + System.out.println("Updated Successfully!"); + } + else { + System.out.println("Medicine not found"); + } + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } + catch(SQLException se){ + se.printStackTrace(); + } + } + + + //----------------------------------- Supplier side Main ------------------------------- + int Sacc_login() { + int sid=0; + boolean li=false; + System.out.println("Enter ID: "); + int id=sc.nextInt(); + sc.nextLine(); + System.out.println("Enter password: "); + int pass=sc.nextInt(); + + try{ + Class.forName(JDBC_Driver); + conn=DriverManager.getConnection(DB_URL,User,Pass); + Query="select * from Supplier_info where S_ID=?"; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, id); + + ResultSet rs=pstmt.executeQuery(); + int flag=0; + while(rs.next()) { + flag=1; + } + + if(flag==0) { + System.out.println("User doesn't exists..."); + } + else { + Query="select S_pass from Supplier_info where S_ID=? "; + pstmt=conn.prepareStatement(Query); + pstmt.setInt(1, id); + + rs=pstmt.executeQuery(); + + while(rs.next()) { + if(rs.getInt("S_pass")==pass) { + System.out.println("Log in successful...."); + sid=id; + li=true; + } + else { + System.out.println("Wrong password entered"); + } + } + } + rs.close(); + pstmt.close(); + conn.close(); + } + catch(ClassNotFoundException e){ + e.printStackTrace(); + } +catch(SQLException se){ + se.printStackTrace(); + } + + if(li) + return sid; + else + return -1; + } + + void Smain() { + Scanner s= new Scanner(System.in); + boolean login=false; + int ls,ch,sid=-1; + do{ + do{ + System.out.println("=================== Supplier ==================="); + System.out.println("1. Log In \n2. Sign Up\n3. Exit"); + ls=s.nextInt(); + switch(ls){ + case 1: + sid=Sacc_login(); + login=true; + break; + + case 2: + Sacc_insert(); + break; + + case 3: + System.out.print("\nReturning to main page...\n"); + break; + } + } + while((!login && sid==-1)); + + Customer c=new Customer(); + if(sid!=-1) { + Scurr_displayCurr(sid); + do { + System.out.println("\n-----Menu-----"); + System.out.println("1.Add Medicines\n2.Update Medicine Quantity\n3.Delete Medicine\n4.Display All Information\n5.Pending Deliveries\n6.Deliver Orders\n7.LogOut"); + ch=sc.nextInt(); + switch(ch){ + case 1: + Scurr_addmed(sid); + break; + + case 2: + Scurr_updatemed_quan(sid); + break; + + case 3: + Scurr_delmed(sid); + break; + + case 4: + Scurr_displayCurr(sid); + break; + + case 5: + c.showq(sid); + break; + + case 6: + c.S_deliver(sid); + break; + } + } + while(ch!=7); + System.out.println("\nLogging out...\n"); + sid=-1; + } + } + while(ls!=3); + } + +} + + + + +