Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
1.00/5 (7 votes)
See more:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.io.*;
import java.text.*;
import java.net.*;
import javax.help.*;

import Tables.*;
import Dialog.*;
import Transaction.*;
import Utils.*;
import Database.*;
import Reports.*;
import Security.*;

public class Menu extends JFrame {

// Pointers to individual Dialog
protected BorrowerListMenu listBorrowerDialog = null;
protected ItemListMenu listItemDialog = null;
protected CategoryListMenu listCategoryDialog = null;
protected AddCategoryDialog addCategoryDialog = null;
protected AddBorrowerDialog addBorrowerDialog = null;
protected AddItemDialog addItemDialog = null;
protected FindItemDialog findItemDialog = null;
protected FindBorrowerDialog findBorrowerDialog = null;
protected FindCategoryDialog findCategoryDialog = null;
protected BorrowDialog brdg = null;
protected ReturnDialog retdg = null;
protected ArchiveManager archiveDialog = null;
protected ModifyUserSettingDialog userdg = null;
protected ModifyPolicySettingDialog policydg = null;
protected OverdueReportMenu Overdueptr = null;
protected FinesSummaryReportMenu FinesSummaryptr = null;
protected ItemOutReportMenu Itemoutptr = null;
protected ReserveReportMenu Reservedg = null;
protected Top10ReportMenu Top10ptr = null;
protected BorrowerSuspendedReportMenu Borrowersuspendedptr = null;
protected BorrowerHoldingReportMenu Borrowerholdingptr = null;
protected JFrame helpdg = null;
protected LoginDialog logindg = null;
protected CalendarDialog calendardg = null;
protected BorrowerTypeDialog borrowertypedg = null;

// ActionListener variables
protected ActionListener quitActionListener = null;
protected ActionListener LogoffActionListener = null;
protected ActionListener borrowAction = null;
protected ActionListener returnAction = null;
protected ActionListener listBorrowerActionListener = null;
protected ActionListener listItemActionListener = null;
protected ActionListener OverdueActionListener = null;
protected ActionListener ItemoutActionListener = null;
protected ActionListener Top10ActionListener = null;
protected ActionListener BorrowerSuspendedActionListener = null;
protected ActionListener BorrowerHoldingActionListener = null;
protected ActionListener findItemActionListener = null;
protected ActionListener findBorrowerActionListener = null;

//Status bar pointer
private StatusBar statusBar = null;

// Hash Tables Variables
protected Hashtable m_lfs;
private LogWriter LGWRITER = LogWriter.GetInstance();
static private final int UI_STYLE_METAL = 0;
static private final int UI_STYLE_MOTIF = 1;
static private final int UI_STYLE_WINDOWS = 2;
static private final int UI_STYLE_MALACHITELF = 3;
private int CURRENT_UI_SYTLE = Integer.valueOf( LGWRITER.getParameter(LogWriter.UI_STYLE) ).intValue();
private String username = LGWRITER.getParameter(LogWriter.USER_NAME);

// Instance of QueryManager
private QueryManager queryMgr = QueryManager.GetInstance();

// For Scanner
private JButton sidebutton = new JButton();
private int buff_i = -1;
private char buff[] = new char[30];
private ReturnReader scannerdg;

/**
* Function to install new UI Manager
*/
private void addLookAndFeel() {
try
{
LookAndFeel malachite = new malachite.MalachiteLF();
UIManager.LookAndFeelInfo info =
new UIManager.LookAndFeelInfo(malachite.getName(),
malachite.getClass().getName());
UIManager.installLookAndFeel(info);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}

/**
* Function to set Look and Feel
*/
private void setUIMgr() {

try {
int ui = Integer.valueOf( LGWRITER.getParameter(LogWriter.UI_STYLE) ).intValue();
switch(ui) {
case UI_STYLE_WINDOWS :
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
CURRENT_UI_SYTLE = UI_STYLE_WINDOWS;
break;
case UI_STYLE_MOTIF :
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
CURRENT_UI_SYTLE = UI_STYLE_MOTIF;
break;
case UI_STYLE_MALACHITELF :
UIManager.setLookAndFeel("malachite.MalachiteLF");
CURRENT_UI_SYTLE = UI_STYLE_MALACHITELF;
break;
default:
CURRENT_UI_SYTLE = UI_STYLE_METAL;
break;
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}

/**
* Function to save User's UI Settings
*/
protected synchronized void saveUISettings() {

int ui = Integer.valueOf( LGWRITER.getParameter(LogWriter.UI_STYLE) ).intValue();
if (CURRENT_UI_SYTLE != ui) {
int userid = Integer.valueOf( LGWRITER.getParameter(LogWriter.USER_ID) ).intValue();
String sqlstr = "UPDATE Users SET " +
"UIStyle = " + CURRENT_UI_SYTLE +
" WHERE UserID = " + userid;

if ( queryMgr.dmlOperations("jndi-library", sqlstr) ) {
LGWRITER.writeLog(LogWriter.MSG_SETTINGS, username + " modifys UI SETTINGS" );
}
System.out.println("\n\tUI Settings successfully saved");
} else System.out.println("\n\tUI Settings not saved");

}

/**
* Function to reload profile
*/
private void reloadProfile() {
LGWRITER.setUserNull();
username = LGWRITER.getParameter(LogWriter.USER_NAME);
statusBar.setPaneText(username);
}

public Menu() {

//Initialise
super(Constants.DEFAULT_TITLE);
//setUndecorated(true);
//getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
addLookAndFeel();
setUIMgr();
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
saveUISettings();
queryMgr.closeQueryManager();
LGWRITER.writeLog(LogWriter.MSG_SECURTY, username + " logged out");
LGWRITER.closeLog();
}

public void windowActivated(WindowEvent e) {
// System.out.println("focus");
//sidebutton.requestFocusInWindow();
requestFocusInWindow();
}

});

ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(Menu.this, "Menu item '" +
event.getActionCommand() + "' was activated",
"Menu Item Activated", JOptionPane.INFORMATION_MESSAGE);
}
};

ActionListener aboutActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(Menu.this, Constants.DEFAULT_TITLE + " CCD DVD Trading Version 1.0\nCopyright @Nov 2009"
, Constants.DEFAULT_TITLE, JOptionPane.INFORMATION_MESSAGE);
}
};

// Quit
quitActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
LGWRITER.writeLog(LogWriter.MSG_SECURTY, username + " logged out");

int result = JOptionPane.showConfirmDialog(Menu.this,
"Confirm Exit?",
Constants.DEFAULT_TITLE,
JOptionPane.YES_NO_OPTION);
if (result == 0) {
saveUISettings();
queryMgr.closeQueryManager();
LGWRITER.closeLog();
System.exit(0);
}
}
};

// Log off
LogoffActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
Menu.this.setVisible(false);
// Password Menu
Toolkit theKit = Menu.this.getToolkit();
Dimension wndSize = theKit.getScreenSize();
if (logindg == null) {
logindg = new LoginDialog(Menu.this);
logindg.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
logindg.setVisible(false);
}
});
logindg.setBounds(wndSize.width/3, wndSize.height/3, 300, 150);
} else
logindg.resetFields();
logindg.setVisible(true);
// Reload profile
reloadProfile();
Menu.this.setVisible(true);
}
};

//Reports
Top10ActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (Top10ptr == null ) {
Top10ptr = new Top10ReportMenu();
Top10ptr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Top10ptr.setSize(650, 400);
Top10ptr.setResizable(false);
Top10ptr.setVisible(true);
Top10ptr.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
Top10ptr.RS.close();
Top10ptr.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
Top10ptr = null;
}

});
}
}
};

OverdueActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (Overdueptr == null ) {
Overdueptr = new OverdueReportMenu();
Overdueptr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Overdueptr.setSize(700, 400);
Overdueptr.setResizable(false);
Overdueptr.setVisible(true);
Overdueptr.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
Overdueptr.RS.close();
Overdueptr.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
Overdueptr = null;
}

});
}
}
};

ItemoutActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (Itemoutptr == null ) {
Itemoutptr = new ItemOutReportMenu();
Itemoutptr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Itemoutptr.setSize(700, 400);
Itemoutptr.setResizable(false);
Itemoutptr.setVisible(true);
Itemoutptr.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
Itemoutptr.RS.close();
Itemoutptr.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
Itemoutptr = null;
}

});
}
}
};

ActionListener ReserveActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (Reservedg == null ) {
Reservedg = new ReserveReportMenu();
Reservedg.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Reservedg.setSize(700, 400);
Reservedg.setResizable(false);
Reservedg.setVisible(true);
Reservedg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
Reservedg.RS.close();
Reservedg.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
Reservedg = null;
}

});
}
}
};

BorrowerSuspendedActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (Borrowersuspendedptr == null ) {
Borrowersuspendedptr = new BorrowerSuspendedReportMenu();
Borrowersuspendedptr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Borrowersuspendedptr.setSize(600, 450);
Borrowersuspendedptr.setResizable(false);
Borrowersuspendedptr.setVisible(true);
Borrowersuspendedptr.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
Borrowersuspendedptr.RS.close();
Borrowersuspendedptr.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
Borrowersuspendedptr = null;
}

});
}
}
};

BorrowerHoldingActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (Borrowerholdingptr == null ) {
Borrowerholdingptr = new BorrowerHoldingReportMenu();
Borrowerholdingptr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Borrowerholdingptr.setSize(600, 450);
Borrowerholdingptr.setResizable(false);
Borrowerholdingptr.setVisible(true);
Borrowerholdingptr.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
Borrowerholdingptr.RS.close();
Borrowerholdingptr.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
Borrowerholdingptr = null;
}

});
}
}
};

ActionListener FinesSummaryActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (FinesSummaryptr == null ) {
FinesSummaryptr = new FinesSummaryReportMenu();
FinesSummaryptr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
FinesSummaryptr.setBounds(50,50,650,500);
FinesSummaryptr.setResizable(false);
FinesSummaryptr.setVisible(true);
FinesSummaryptr.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
FinesSummaryptr.RS.close();
FinesSummaryptr.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
FinesSummaryptr = null;
}

});
}
}
};

// Transaction
borrowAction = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (brdg == null ) {
brdg = new BorrowDialog("Borrow Dialog");
brdg.setResizable(false);
brdg.setBounds(50,50,600,500);
brdg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
brdg = null;
}
});
}
}
};

returnAction = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (retdg == null ) {
retdg = new ReturnDialog("Return Dialog");
retdg.setResizable(false);
retdg.setBounds(50,50,600,500);
retdg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
retdg = null;
}
});
}
}
};


ActionListener ArchiveListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (archiveDialog == null ) {
archiveDialog = new ArchiveManager(Menu.this);

archiveDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
archiveDialog = null;
}
});
}
}
};

// Borrower Dialogs
ActionListener addBorrowerActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (addBorrowerDialog == null ) {
addBorrowerDialog = new AddBorrowerDialog(Menu.this);

addBorrowerDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
addBorrowerDialog = null;
}
});
}
}
};

findBorrowerActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (findBorrowerDialog == null ) {
findBorrowerDialog = new FindBorrowerDialog();
findBorrowerDialog.setResizable(false);
findBorrowerDialog.setVisible(true);
findBorrowerDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
//try {
// findBorrowerDialog.result_Set.close();
//} catch(SQLException se) {}
findBorrowerDialog = null;
}
});
}
}
};

listBorrowerActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (listBorrowerDialog == null ) {
listBorrowerDialog = new BorrowerListMenu();
listBorrowerDialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
listBorrowerDialog.setSize(700, 500);
listBorrowerDialog.setResizable(true);
listBorrowerDialog.setVisible(true);
listBorrowerDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
listBorrowerDialog.RS.close();
listBorrowerDialog.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
listBorrowerDialog = null;
}

});
}
}
};

ActionListener listBorrowerTypeActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (borrowertypedg == null ) {
borrowertypedg = new BorrowerTypeDialog();
borrowertypedg.setResizable(false);
borrowertypedg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
borrowertypedg = null;
}
});
}
}
};

//Item Dialogs
ActionListener addItemActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (addItemDialog == null ) {
addItemDialog = new AddItemDialog(Menu.this);
addItemDialog.setBounds(50,50,600,250);
addItemDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
addItemDialog = null;
}
});
}
}
};

findItemActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (findItemDialog == null ) {
findItemDialog = new FindItemDialog();
findItemDialog.setResizable(false);
findItemDialog.setVisible(true);
findItemDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
findItemDialog = null;
}
});
}
}
};

listItemActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (listItemDialog == null ) {
listItemDialog = new ItemListMenu();
listItemDialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
listItemDialog.setBounds(50,50,650,500);
listItemDialog.setResizable(true);
listItemDialog.setVisible(true);
listItemDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
listItemDialog.RS.close();
listItemDialog.ST.close();
} catch(SQLException se) { se.printStackTrace();}
listItemDialog = null;
}
});
}
}
};

//Category Dialogs
ActionListener addCategoryActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (addCategoryDialog == null ) {
addCategoryDialog = new AddCategoryDialog(Menu.this);

addCategoryDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
addCategoryDialog = null;
}
});
}
}
};

ActionListener findCategoryActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (findCategoryDialog == null ) {
findCategoryDialog = new FindCategoryDialog();
findCategoryDialog.setResizable(false);
findCategoryDialog.setVisible(true);
findCategoryDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
findCategoryDialog = null;
}
});
}
}
};

ActionListener listCategoryActionListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {

if (listCategoryDialog == null ) {
listCategoryDialog = new CategoryListMenu();
listCategoryDialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
listCategoryDialog.setBounds(50,50,650,500);
listCategoryDialog.setResizable(true);
listCategoryDialog.setVisible(true);
listCategoryDialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
try {
listCategoryDialog.RS.close();
listCategoryDialog.ST.close();
} catch(SQLException se) { se.printStackTrace(); }
listCategoryDialog = null;
}
});
}
}
};

// General
ActionListener userSettingAction = new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (userdg == null ) {
userdg = new ModifyUserSettingDialog(Menu.this, "User Settings");
userdg.setResizable(false);
userdg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
userdg = null;
}
});
}
}
};

ActionListener policySettingAction = new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (policydg == null ) {
policydg = new ModifyPolicySettingDialog(Menu.this, "Policy Settings");
policydg.setResizable(false);
policydg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
policydg = null;
}
});
}
}
};

ActionListener calendarSettingAction = new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (calendardg == null ) {
calendardg = new CalendarDialog();
calendardg.setResizable(false);
calendardg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
calendardg = null;
}
});
}
}
};

ActionListener lookFeelAction = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String str = e.getActionCommand();

if ( str.compareTo("Windows") == 0 ) CURRENT_UI_SYTLE = UI_STYLE_WINDOWS;
else if ( str.compareTo("CDE/Motif") == 0 ) CURRENT_UI_SYTLE = UI_STYLE_MOTIF;
else if ( str.compareTo("Malachite") == 0 ) CURRENT_UI_SYTLE = UI_STYLE_MALACHITELF;
else CURRENT_UI_SYTLE = UI_STYLE_METAL;
Object obj = m_lfs.get(str);
if (obj != null)
try
{
String className = (String)obj;
Class lnfClass = Class.forName(className);
UIManager.setLookAndFeel(
(LookAndFeel)(lnfClass.newInstance()));
SwingUtilities.updateComponentTreeUI(
Menu.this);
}
catch (Exception ex)
{
ex.printStackTrace();
System.err.println(ex.toString());
}
}
};

ActionListener helpAction = new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (helpdg == null ) {
try {
URL helpsetURL = new URL("file:./help.hs");
HelpSet set = new HelpSet(null, helpsetURL);
JHelp help = new JHelp(set);
helpdg = new JFrame("NBS Library Application Help");
Toolkit theKit = Menu.this.getToolkit();
Image icon = theKit.getImage("images/default.gif");
helpdg.setIconImage(icon);
helpdg.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
helpdg.setContentPane(help);
helpdg.setBounds(50,50,850,450 );
helpdg.setResizable(false);
helpdg.setVisible(true);
helpdg.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
helpdg = null;
}
});
} catch(Exception e) {e.printStackTrace();}
}
}
};

// Transactional Menu
/* JMenu transMenu = new JMenu("Transaction");
JMenuItem item1_1 = new JMenuItem("Borrow");
item1_1.addActionListener(borrowAction);
transMenu.add(item1_1);
JMenuItem item1_2 = new JMenuItem("Return");
item1_2.addActionListener(returnAction);
transMenu.add(item1_2);
transMenu.addSeparator();
JMenuItem item1_3 = new JMenuItem("Archive Manager");
item1_3.addActionListener(ArchiveListener);
transMenu.add(item1_3);
menuBar.add(transMenu);*/

// Reports Menu
JMenu reportMenu = new JMenu("Reports");
JMenu item2_1 = new JMenu("DVD-Related");
/*JMenuItem item2_1_1 = new JMenuItem("Overdue");
item2_1_1.addActionListener(OverdueActionListener);
item2_1.add(item2_1_1);
JMenuItem item2_1_2 = new JMenuItem("Borrowed Out");
item2_1_2.addActionListener(ItemoutActionListener);
item2_1.add(item2_1_2);*/
JMenuItem item2_1_3 = new JMenuItem("Reserve Outstanding");
item2_1_3.addActionListener(ReserveActionListener);
item2_1.add(item2_1_3);
JMenuItem item2_1_4 = new JMenuItem("Top 10");
item2_1_4.addActionListener(Top10ActionListener);
item2_1.add(item2_1_4);
reportMenu.add(item2_1);
JMenu item2_2 = new JMenu("Consumer-Related");
/*item2_2.addActionListener(actionListener);
JMenuItem item2_2_1 = new JMenuItem("Suspended");
item2_2_1.addActionListener(BorrowerSuspendedActionListener);
item2_2.add(item2_2_1);
JMenuItem item2_2_2 = new JMenuItem("Holding items");
item2_2_2.addActionListener(BorrowerHoldingActionListener);
item2_2.add(item2_2_2);
JMenuItem item2_2_3 = new JMenuItem("Fines Summary");
item2_2_3.addActionListener(FinesSummaryActionListener);
item2_2.add(item2_2_3);*/
reportMenu.add(item2_2);
menuBar.add(reportMenu);

//Administration Menu
JMenu administrationMenu = new JMenu("Administration");
JMenu item3_1 = new JMenu("DVD");
JMenuItem item3_1_1 = new JMenuItem("Add a DVD");
item3_1_1.addActionListener(addItemActionListener);
item3_1.add(item3_1_1);
JMenuItem item3_1_2 = new JMenuItem("Find a DVD");
item3_1_2.addActionListener(findItemActionListener);
item3_1.add(item3_1_2);
item3_1.addSeparator();
JMenuItem item3_1_3 = new JMenuItem("List all DVDs");
item3_1_3.addActionListener(listItemActionListener);
item3_1.add(item3_1_3);
administrationMenu.add(item3_1);
JMenu item3_2 = new JMenu("Consumer");
JMenuItem item3_2_1 = new JMenuItem("Add a Consumer");
item3_2_1.addActionListener(addBorrowerActionListener);
item3_2.add(item3_2_1);
JMenuItem item3_2_2 = new JMenuItem("Find a Consumer");
item3_2_2.addActionListener(findBorrowerActionListener);
item3_2.add(item3_2_2);
item3_2.addSeparator();
JMenuItem item3_2_3 = new JMenuItem("List all Comsumers");
item3_2_3.addActionListener(listBorrowerActionListener);
item3_2.add(item3_2_3);
item3_2.addSeparator();
JMenuItem item3_2_4 = new JMenuItem("Consumer Category");
item3_2_4.addActionListener(listBorrowerTypeActionListener);
item3_2.add(item3_2_4);
administrationMenu.add(item3_2);
JMenu item3_3 = new JMenu("DVD Category");
JMenuItem item3_3_1 = new JMenuItem("Add a DVD Category");
item3_3_1.addActionListener(addCategoryActionListener);
item3_3.add(item3_3_1);
JMenuItem item3_3_2 = new JMenuItem("Find a DVD Category");
item3_3_2.addActionListener(findCategoryActionListener);
item3_3.add(item3_3_2);
item3_3.addSeparator();
JMenuItem item3_3_3 = new JMenuItem("List all DVD Categories");
item3_3_3.addActionListener(listCategoryActionListener);
item3_3.add(item3_3_3);
administrationMenu.add(item3_3);
menuBar.add(administrationMenu);

//General Menu
JMenu generalMenu = new JMenu("General");
JMenuItem item4_1 = new JMenuItem("Policy Settings");
item4_1.addActionListener(policySettingAction);
generalMenu.add(item4_1);
JMenuItem item4_2 = new JMenuItem("User Settings");
item4_2.addActionListener(userSettingAction);
generalMenu.add(item4_2);
JMenuItem item4_3 = new JMenuItem("Calendar Settings");
item4_3.addActionListener(calendarSettingAction);
generalMenu.add(item4_3);

JMenu item4_4 = new JMenu("Look&Feel");
m_lfs = new Hashtable();
UIManager.LookAndFeelInfo lfs[] =
UIManager.getInstalledLookAndFeels();
ButtonGroup group = new ButtonGroup();
for (int k = 0; k < lfs.length; k++ )
{
String name = lfs[k].getName();
JRadioButtonMenuItem radioMenu = new JRadioButtonMenuItem(name);
m_lfs.put(name, lfs[k].getClassName());
radioMenu.addActionListener(lookFeelAction);
if (k == CURRENT_UI_SYTLE ) radioMenu.setSelected(true);
group.add(radioMenu);
item4_4.add(radioMenu);
}

generalMenu.add(item4_4);
generalMenu.addSeparator();
JMenuItem item4_5 = new JMenuItem("About");
item4_5.addActionListener(aboutActionListener);
generalMenu.add(item4_5);
JMenuItem item4_6 = new JMenuItem("Help");
item4_6.addActionListener(helpAction);
generalMenu.add(item4_6);
generalMenu.addSeparator();
JMenuItem item4_7 = new JMenuItem("Log Off");
item4_7.addActionListener(LogoffActionListener);
generalMenu.add(item4_7);
menuBar.add(generalMenu);
generalMenu.addSeparator();
JMenuItem item4_8 = new JMenuItem("Quit");
item4_8.addActionListener(quitActionListener);
generalMenu.add(item4_8);
menuBar.add(generalMenu);

//Status bar
statusBar = new StatusBar();
statusBar.setPaneText(username);
getContentPane().add(statusBar, BorderLayout.SOUTH);

//Toolbar
getContentPane().add(new ToolBar(), BorderLayout.NORTH);

//Background Image
((JPanel)getContentPane()).setOpaque(false);
ImageIcon earth = new ImageIcon(queryMgr.BKGRD_IMAGES);
JLabel backlabel = new JLabel(earth);
getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE));
backlabel.setBounds(0,0,earth.getIconWidth(),
earth.getIconHeight());

// Scanner
sidebutton.setPreferredSize( new Dimension(0,1) );
this.getContentPane().add(sidebutton, BorderLayout.WEST);
attachKeyListener(this);
scannerdg = new ReturnReader(this);
}

public class ReturnReader extends JDialog {

private JTextField txItemNo;
private JTextArea m_title;

public ReturnReader( JFrame parent )
{
super( parent, "Scanned-Item Dialog", true );
Toolkit theKit = this.getToolkit();
Dimension wndSize = theKit.getScreenSize();
this.setBounds(wndSize.width/3, 10, 280, 180);

addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});

setDefaultCloseOperation(DISPOSE_ON_CLOSE);

// Creates a panel to hold all my components
JPanel panel = new JPanel( new BorderLayout() );
panel.setLayout( new GridBagLayout() );
// give the panel a border gap of 5 pixels
panel.setBorder(new CompoundBorder(
new EtchedBorder(EtchedBorder.RAISED),
new EmptyBorder(5,5,5,5)));
getContentPane().add( BorderLayout.NORTH, panel );

GridBagConstraints c = new GridBagConstraints();

// Define preferred sizes for my entry fields
Dimension shortField = new Dimension( 60, 20 );
Dimension mediumField = new Dimension( 120, 20 );
Dimension longField = new Dimension( 180, 20 );

// Spacing between the label and the field
EmptyBorder border = new EmptyBorder( new Insets( 0, 0, 0, 10 ) );

// Fonts
Font fn = new Font("Arial", Font.PLAIN, 10);

// add some space around all my components to avoid cluttering
c.insets = new Insets( 2, 2, 2, 2 );

// anchors all my components to the west
c.anchor = GridBagConstraints.WEST;

// Date label and combo box
JLabel lbl0 = new JLabel("Please Confirm the Item You want to Return.");
lbl0.setFont(fn);
lbl0.setForeground(new Color(150,10,10));
c.gridwidth = 2;
c.gridx = 0;
c.gridy = 0;
panel.add( lbl0, c );

JLabel lbl1 = new JLabel( "Item No" );
lbl1.setBorder( border );
c.gridx = 0;
c.gridy++;
c.gridwidth = 1;
c.fill = GridBagConstraints.NONE;
panel.add( lbl1, c );

txItemNo = new JTextField();
txItemNo.setPreferredSize( shortField );
c.gridx++;
txItemNo.setEnabled(false);
//txItemNo.requestFocus();
panel.add( txItemNo, c );

m_title = new JTextArea("", 4, 26);
m_title.setFont(fn);
m_title.setLineWrap(true);
m_title.setWrapStyleWord(true);
m_title.setForeground(Color.white);
m_title.setBackground(Color.black);
m_title.setEditable(false);
c.gridx = 0;
c.gridy++;
c.gridwidth = 2;
c.fill = GridBagConstraints.REMAINDER;
panel.add(new JScrollPane(m_title), c);

JPanel btnpanel = new JPanel();
btnpanel.setBorder( new EmptyBorder(3,5,3,5) );
btnpanel.setLayout( new FlowLayout( FlowLayout.CENTER, 0, 0 ) );


ActionListener action = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
getTransaction();
}
};

JButton confirmBtn = new JButton( "Confirm" );
confirmBtn.setPreferredSize(new Dimension(80,20));
confirmBtn.addActionListener(action);
getRootPane().setDefaultButton(confirmBtn);
getRootPane().registerKeyboardAction(action,
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
btnpanel.add(confirmBtn);
action = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
};

JButton cancelBtn = new JButton( "Cancel" );
cancelBtn.addActionListener(action);
cancelBtn.setPreferredSize(new Dimension(80,20));
c.gridx ++;
btnpanel.add(cancelBtn);
getContentPane().add( BorderLayout.SOUTH, btnpanel );
setVisible(false);
}

/**
* Function to find Item Number scanned in
*/
private void findItem(String x) {
if (x.length() > 0) {

String sqlstr = "SELECT Title from Item WHERE ItemNo = '" + x + "'";
try {
Statement st = queryMgr.createStatement();
ResultSet result_Set = queryMgr.getResultQuery(sqlstr, st);
boolean ResultSetOk = queryMgr.CheckNull(result_Set);
if ( ResultSetOk ) {
m_title.setText( result_Set.getString("Title") );
result_Set.close();
result_Set = null;
scannerdg.setVisible(true);
}
result_Set.close();
result_Set = null;
st.close();
st = null;

}
catch (SQLException sqle) { sqle.printStackTrace();}

}
}

/**
* Function to find transaction
*/
private void getTransaction() {
String x = txItemNo.getText().trim();
if (x.length() != 0) {
String sqlstr = "SELECT MAX( TransactionNo ) As TxNo FROM BorrowTransaction" +
" WHERE ItemNo = '" + x + "'";

try {
Statement st = queryMgr.createStatement();
ResultSet result_Set = queryMgr.getResultQuery(sqlstr, st);
boolean ResultSetOk = queryMgr.CheckNull(result_Set);
boolean NotFound = false;
if ( ResultSetOk ) {
int tranno = result_Set.getInt("TxNo");
result_Set.close();
result_Set = null;
if (tranno != 0)
updateTransaction(tranno, x);
else
NotFound = true;
}

if (NotFound) {
JOptionPane.showMessageDialog(ReturnReader.this,
"Cannot find any transaction for Item " + x,
"Return Operation",
JOptionPane.ERROR_MESSAGE);
scannerdg.setVisible(false);
}
result_Set.close();
result_Set = null;
st.close();
st = null;


}
catch (SQLException sqle) { sqle.printStackTrace();}
}
}


/**
* Function to update transaction
*/
private void updateTransaction(int txno, String itemno) {
//boolean success = false;
String sqlstr = "SELECT Returned, Datedue, BorrowerNo FROM BorrowTransaction" +
" WHERE TransactionNo = " +txno;
try {
Statement st = queryMgr.createStatement();
ResultSet result_Set = queryMgr.getResultQuery(sqlstr, st);
String returned = result_Set.getString("Returned");
if (returned.compareTo("Y") == 0)
JOptionPane.showMessageDialog(ReturnReader.this,
"Item " + itemno + " already RETURNED.",
"Return Operation",
JOptionPane.ERROR_MESSAGE);
else {
//To calculate whether any overdue
String borrowerno = result_Set.getString("BorrowerNo");
java.util.Date datedue = result_Set.getDate("Datedue");
DateUtils du = new DateUtils(datedue);
long days = du.getNoofDays();

Calendar today = Calendar.getInstance();

sqlstr = "UPDATE BorrowTransaction SET " +
"Returned = 'Y', DateReturned ='" + queryMgr.STD_DATE_FORMAT.format( today.getTime() ) + "'" +
" WHERE TransactionNo = " + txno;
queryMgr.dmlOperations("jndi-library", sqlstr);

int reserveid = checkReserve(itemno);
if (reserveid == 0) {
sqlstr = "UPDATE Item SET " +
"Status = 'IN' WHERE ItemNo = '" + itemno + "' AND Status <> 'RESERVE'";
queryMgr.dmlOperations("jndi-library", sqlstr);
System.out.println("\n\tScanner Return: No Reservation records");
//success = true;
//JOptionPane.showMessageDialog(ReturnReader.this,
// itemno + " RETURNED Successfully.",
// "Return Operation",
// JOptionPane.INFORMATION_MESSAGE);
} else {
SendNotificationEmail(reserveid);
sqlstr = "UPDATE Item SET " +
"Status = 'RESERVE' WHERE ItemNo = '" + itemno + "'" +
" AND (Status <> 'RESERVE' OR Status <> 'LOST')";
queryMgr.dmlOperations("jndi-library", sqlstr);
System.out.println("\n\tScanner Return: Item " + itemno + " Status changed to RESERVED");
}

// Update Renew
updateRenew(itemno, borrowerno);

if (days > 0) {
double fines = days * queryMgr.FINESAMOUNT;
sqlstr = "UPDATE Fines SET" +
" FinesAmount = " + fines +
" WHERE TransactionNo = " + txno;
queryMgr.dmlOperations("jndi-library", sqlstr);
LGWRITER.writeLog(LogWriter.MSG_TRANSACTION, username + " adds a RETURN TRANSACTION (" +
itemno + ", fines:$" + fines + ")" );
JOptionPane.showMessageDialog(ReturnReader.this,
"Transaction: Item (" + itemno + ") is returned with FINE. (" + days + " ) day(s) OVERDUE. Pls Check Borrower No :" + borrowerno,
"Scanner Return Operation",
JOptionPane.INFORMATION_MESSAGE);
} else {

// No fine
JOptionPane.showMessageDialog(ReturnReader.this,
itemno + " RETURNED Successfully.",
"Return Operation",
JOptionPane.INFORMATION_MESSAGE);

}


}
scannerdg.setVisible(false);
result_Set.close();
result_Set = null;
st.close();
st = null;
}
catch (SQLException sqle) { sqle.printStackTrace();}
}

/**
* Function to check whether item is in RESERVE table
*/
private int checkReserve(String itemno) {
String sql = "SELECT MIN(r.ReserveNo) as id FROM Reserve r, Item i WHERE " +
"r.ItemNo = '" + itemno + "'" +
" AND r.ItemNo = i.ItemNo " +
" AND r.EmailNotify = 'N' AND r.Completed = 'N'";
int found = 0;
try {
Statement st = queryMgr.createStatement();
ResultSet rs = queryMgr.getResultQuery(sql, st);
if (queryMgr.CheckNull(rs))
found = rs.getInt("id");
rs.close();
rs = null;
st.close();
st = null;
} catch(SQLException se) { se.printStackTrace();}

return found;
}

/**
* Function to update any renewal record
*/
private void updateRenew(String itemno, String userno) {
String sql = "UPDATE Renew Set Status='COMPLETED' WHERE ItemNo = '" + itemno +
"' AND BorrowerNo = '" + userno + "'";
System.out.println(sql);
queryMgr.dmlOperations("jndi-library", sql);
LGWRITER.writeLog(LogWriter.MSG_TRANSACTION, username + " updating Renew record of '" +
itemno + "' which belongs to '" + userno + "'" );
}


/**
* Function to Send Email to Borrower who RESERVE the book
*/
private void SendNotificationEmail(int resid) {

DateUtils du = new DateUtils();
String sql = "SELECT b.Name, b.Email, i.ItemNo, i.Title, r.DateReserved FROM Reserve r, Borrower b, Item i" +
" WHERE r.BorrowerNo = b.BorrowerNo AND r.ItemNo = i.ItemNo AND r.ReserveNo = " + resid;
try {
Statement st = queryMgr.createStatement();
ResultSet rs = queryMgr.getResultQuery(sql, st);
if (queryMgr.CheckNull(rs)) {
String name = rs.getString("Name");
String itemno = rs.getString("ItemNo");
String title = rs.getString("Title");
String email = rs.getString("Email");
String datestr = (String) queryMgr.STD_DATE_FORMAT.format( rs.getDate("DateReserved") );
if (email.compareTo("") != 0) {
try {
MailManager Mailmgr = MailManager.GetInstance();
Conf conf = Mailmgr.getConf();
Mailmgr.setHTML(false);
Vector recp = new Vector();
recp.add(new String(email));
Mailmgr.postMail(recp, conf.getReserveSubject(),
"<div style='font-family:verdana;font-size:9pt'>" +
"<p style='margin-left:30.0pt'>Dear " + name + ",<p>" +
"<p style='margin-left:30.0pt'>" + conf.getReserveMessage1() +
"<br>NO : " + itemno +
"<br>TITLE : " + title +
"</p><p style='margin-left:30.0pt'>" + conf.getReserveMessage2() +
queryMgr.RESERVEVALIDDAYS +
" DAY(s) from the following that date you have reserved : <p><p style='margin-left:30.0pt'>" + datestr +
"</p><p style='margin-left:30.0pt'>" + conf.getFrom() +
"<br>" + conf.getDepartment() + "<p>" +
"</div>",
conf.getEmail() );
LGWRITER.writeLog(LogWriter.MSG_TRANSACTION," Reservation Notice EMail of " + itemno + " sent to " + email);
System.out.println("\n\tScanner Return: Reservation Notice EMail sent to " + email);
recp.removeAllElements();
} catch (javax.mail.MessagingException me) { System.out.println("\n\tReturn: Mail Sent Error");}
}

String todaystr = du.getShortTodayDate();
sql = "UPDATE Reserve SET EmailNotify = 'Y', DateNotified = '" + todaystr + "'" +
" WHERE ReserveNo = " + resid;
queryMgr.dmlOperations("jndi-library", sql);
System.out.println("\n\tScanner Return: No Reserve record updated");
}
rs.close();
rs = null;
st.close();
st = null;
} catch(SQLException se) { se.printStackTrace();}
}


}

private void attachKeyListener(final JFrame frame) {

KeyListener listener = new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
buff_i++;
buff[buff_i] = (char)code;
switch(code) {
case 10 : String s = new String(buff);
buff_i = -1;
buff[0] = '\0';
System.out.println("\n\t<<Input value>> :" + s);
scannerdg.setVisible(false);
scannerdg.m_title.setText("");
scannerdg.txItemNo.setText(s.trim());
scannerdg.findItem(s.trim());
break;

case 13 : break;

case 16 : buff_i--;break;

default : break;
} // end switch

}
};
sidebutton.addKeyListener(listener);
}

/**
* Class to create tool bar
*/

public class ToolBar extends JPanel{

private JToolBar toolBar = new JToolBar();

public void setFloat(boolean condition) {
toolBar.setFloatable(condition);
}

public ToolBar() {
addButtons(toolBar);
setLayout(new BorderLayout());
setPreferredSize(new Dimension( 20, 30));
setBorder(BorderFactory.createLineBorder(Constants.DEFAULT_TOOLBAR_LINECOLOR ));
add(toolBar, BorderLayout.WEST);
toolBar.setFloatable(true);
}

protected void addButtons(JToolBar toolbar) {

JButton button = null;

/*button = new JButton(new ImageIcon("images/borrow.gif"));
button.setToolTipText("Borrow item");
button.addActionListener(borrowAction);
toolbar.add(button);

button = new JButton(new ImageIcon("images/return.gif"));
button.setToolTipText("Return item");
button.addActionListener(returnAction);
toolbar.add(button);
toolbar.addSeparator();

button = new JButton(new ImageIcon("images/overdue.gif"));
button.setToolTipText("Overdue items");
button.addActionListener(OverdueActionListener);
toolbar.add(button);*/

button = new JButton(new ImageIcon("images/top10.gif"));
button.setToolTipText("Top 10 most popular DVDs");
button.addActionListener(Top10ActionListener);
toolbar.add(button);
toolbar.addSeparator();

button = new JButton(new ImageIcon("images/itemlist.gif"));
button.setToolTipText("List of all DVDs");
button.addActionListener(listItemActionListener);
toolbar.add(button);

button = new JButton(new ImageIcon("images/finditemlist.gif"));
button.setToolTipText("Find DVD");
button.addActionListener(findItemActionListener);
toolbar.add(button);

button = new JButton(new ImageIcon("images/borrowerlist.gif"));
button.setToolTipText("List of all Consumers");
button.addActionListener(listBorrowerActionListener);
toolbar.add(button);


button = new JButton(new ImageIcon("images/findborrowerlist.gif"));
button.setToolTipText("Find Consumer");
button.addActionListener(findBorrowerActionListener);
toolbar.add(button);
toolbar.addSeparator();

button = new JButton(new ImageIcon("images/logoff.gif"));
button.setToolTipText("Log off");
button.addActionListener(LogoffActionListener);
toolbar.add(button);

button = new JButton(new ImageIcon("images/quit.gif"));
button.setToolTipText("Quit application");
button.addActionListener(quitActionListener);
toolbar.add(button);
}
}

}

when i complie this program its giving these two errors

1:package javax.help does not exist
import javax.help.

2:.\Security\LoginDialog.java:2: class, interface, or enum expected
* ===================================================
^
C:\projects\dvdshop\Menu.java:46: cannot access Security.LoginDialog
bad class file: .\Security\LoginDialog.java
file does not contain class Security.LoginDialog
Please remove or make sure it appears in the correct subdirectory of the classpath.
protected LoginDialog logindg = null;

Im using database MS ACCESS...do i need to write anything to connect it by odbc if yes please write the code and paste

thanx in advance

Posted
Updated 23-Nov-09 12:53pm
v2

It's depressing how quick this forum got overrun by the same morons ruining the other forums.

 
Share this answer
 
Mmm, yeah if this keeps up I'm outta here.
 
Share this answer
 

Well I guess you could not be bothered to read the guidelines before dumping all this code. If you can produce this many pages of code you should also be capable of finding the lines that the error messages refer to. Obviously some packages do not exist that you are referencing, and you appear to have a syntax error in LoginDialog.java around line 2. I do not have the time to try and find it on this screen!

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900