Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package unimapdbconsole;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class executer
- {
- private BufferedReader reader;
- private String username,password,fullname;
- private db dbobject;
- private int choice;
- public executer()
- {
- reader=new BufferedReader(new InputStreamReader(System.in));
- username=password=null;
- dbobject=new db();
- dbobject.init();
- dbobject.opencon();
- choice=0;
- login();
- }
- public void login()
- {
- while(true)
- {
- try
- {
- clearScreen();
- System.out.println("Welcome !");
- System.out.println("Enter User Name");
- username=reader.readLine();
- System.out.println("Enter Password");
- password=reader.readLine();
- if(dbobject.validate(username, password))
- menu();
- else
- {
- clearScreen();
- System.out.println("Authentication Error");
- }
- }
- catch(Exception e)
- {
- System.out.println("Invalid Choice");
- try {reader.readLine();}catch(IOException ex) {}
- menu();
- }
- }
- }
- public void menu()
- {
- do
- {
- clearScreen();
- System.out.println("Main Menu");
- System.out.println("1. Add User");
- System.out.println("2. Edit User");
- System.out.println("0. Exit");
- System.out.println("Enter your choice");
- try
- {
- choice=Integer.parseInt(reader.readLine());
- if(choice==0)
- {
- exit();
- }
- else if(choice==1)
- {
- adduser();
- }
- else if (choice==2)
- {
- editUser();
- }
- else
- {;}
- }
- catch(Exception e)
- {
- System.out.println("Invalid Choice");
- try {reader.readLine();}catch(IOException ex) {}
- menu();
- }
- }while(choice!=0);
- }
- public void adduser()
- {
- try
- {
- clearScreen();
- System.out.println("Adding New User...");
- System.out.println("Enter User Name");
- username=reader.readLine();
- System.out.println("Enter Password");
- password=reader.readLine();
- System.out.println("Enter Fullname");
- fullname=reader.readLine();
- if(dbobject.adduser(username, password, fullname))
- {
- System.out.println("User inserted..");
- try {reader.readLine();}catch(IOException ex) {}
- }
- else
- {
- System.out.println("User insert failed..");
- }
- }
- catch(Exception e)
- {
- System.out.println("Input Error");
- try
- {
- reader.readLine();
- }
- catch(IOException ex) {}
- }
- }
- public void editUser()
- {
- try
- {
- System.out.println("Enter Username");
- username=reader.readLine();
- System.out.println("Edit fullname");
- fullname=reader.readLine();
- dbobject.opencon();
- if (dbobject.update(username,fullname))
- {
- System.out.println("fullname edited");
- }
- else
- {
- System.out.println("Unable to edit fullname");
- }
- }
- catch(IOException ex) {}
- }
- public void exit()
- {
- System.out.println("Exit");
- }
- public static void clearScreen()
- {
- for (int i=1; i<=10; i++)
- System.out.println("\n");
- }
- public static void main(String[] args)
- {
- new executer();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement