Vous êtes sur la page 1sur 66

Login

Code /* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * frmLogin.java *

package hospitalmanagement;

/** * * @author Administrator */ public class frmLogin extends javax.swing.JFrame {

/** Creates new form frmLogin */ public frmLogin() { initComponents(); }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); txtUserId = new java.awt.TextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); txtPassword = new javax.swing.JPasswordField(); lblmsg = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("User Id");

jLabel2.setText("Password");

jButton1.setText("Login"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

jButton2.setText("Exit"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(33, 33, 33) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel1) .addComponent(jLabel2)) .addGap(33, 33, 33) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE) .addComponent(jButton1) .addGap(18, 18, 18) .addComponent(jButton2) .addGap(32, 32, 32)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtUserId, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))) .addContainerGap(55, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(164, Short.MAX_VALUE) .addComponent(lblmsg) .addGap(194, 194, 194)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(25, 25, 25) .addComponent(lblmsg)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtUserId, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addContainerGap()) );

pack(); }// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(txtUserId.getText().equals("H") && txtPassword.getText().equals("H")) { frmMain frm=new frmMain();

frm.show(); this.setVisible(false); } else { lblmsg.setText("Invalid UserID/Password ! Please Try Again"); } }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.setVisible(false); }

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmLogin().setVisible(true); } }); }

// Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel lblmsg; private javax.swing.JPasswordField txtPassword; private java.awt.TextField txtUserId; // End of variables declaration

Main

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * frmMain.java * * Created on Dec 27, 2010, 11:59:12 PM */

package hospitalmanagement;

/** * * @author Administrator */ public class frmMain extends javax.swing.JFrame {

/** Creates new form frmMain */ public frmMain() { initComponents(); }

/** This method is called from within the constructor to

* initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); jMenu4 = new javax.swing.JMenu(); jMenu5 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem3 = new javax.swing.JMenuItem(); jMenu3 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jMenu1.setText("Doctor"); jMenu1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu1MouseClicked(evt); }

}); jMenuBar1.add(jMenu1);

jMenu2.setText("Patient"); jMenu2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu2MouseClicked(evt); } }); jMenuBar1.add(jMenu2);

jMenu4.setText("Billing"); jMenu4.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu4MouseClicked(evt); } }); jMenuBar1.add(jMenu4);

jMenu5.setText("Report");

jMenuItem1.setText("Search Doctor"); jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenuItem1MouseClicked(evt);

} }); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenuItem1.addMenuKeyListener(new javax.swing.event.MenuKeyListener() { public void menuKeyPressed(javax.swing.event.MenuKeyEvent evt) { jMenuItem1MenuKeyPressed(evt); } public void menuKeyReleased(javax.swing.event.MenuKeyEvent evt) { } public void menuKeyTyped(javax.swing.event.MenuKeyEvent evt) { } }); jMenu5.add(jMenuItem1);

jMenuItem2.setText("Search Patient"); jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenuItem2MouseClicked(evt); } }); jMenuItem2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu5.add(jMenuItem2);

jMenuItem3.setText("Bill Report"); jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenuItem3MouseClicked(evt); } }); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu5.add(jMenuItem3);

jMenuBar1.add(jMenu5);

jMenu3.setText("Exit"); jMenu3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu3MouseClicked(evt);

} }); jMenu3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenu3ActionPerformed(evt); } }); jMenuBar1.add(jMenu3);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 279, Short.MAX_VALUE) );

pack(); }// </editor-fold>

private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: frmDoctor frm=new frmDoctor(); frm.setVisible(true); }

private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: frmPatient frm=new frmPatient(); frm.show(); }

private void jMenu4MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: frmBilling frm=new frmBilling(); frm.show(); }

private void jMenu3MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: this.hide(); }

private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here:

frmDoctorSearch frm=new frmDoctorSearch(); frm.setVisible(true); }

private void jMenuItem2MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: frmPatientSearch frm =new frmPatientSearch(); frm.show(); }

private void jMenuItem3MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: frmReport frm=new frmReport(); frm.show(); }

private void jMenuItem1MenuKeyPressed(javax.swing.event.MenuKeyEvent evt) { // TODO add your handling code here: frmDoctorSearch frm=new frmDoctorSearch(); frm.setVisible(true); }

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: frmDoctorSearch frm=new frmDoctorSearch();

frm.setVisible(true); }

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: frmPatientSearch frm=new frmPatientSearch(); frm.setVisible(true); }

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: frmReport frm=new frmReport(); frm.setVisible(true); }

private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() {

new frmMain().setVisible(true); } }); }

// Variables declaration - do not modify private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenu jMenu4; private javax.swing.JMenu jMenu5; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; // End of variables declaration

Doctor

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * frmDoctor.java * */

package hospitalmanagement;

/** * * @author Administrator */ import java.sql.*; public class frmDoctor extends javax.swing.JFrame {

/** Creates new form frmDoctor */ static public final String driver = "com.mysql.jdbc.Driver"; static public final String connection = "jdbc:mysql://localhost:3306/hospital"; static public final String user = "root"; static public final String password = "";

Connection con; public frmDoctor() { initComponents(); try { Class.forName(driver); con = DriverManager.getConnection(connection, user, password);

getList();

} catch(Exception ex) { System.out.println(ex.getMessage()); } }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jLabel1 = new javax.swing.JLabel(); txtId = new java.awt.TextField(); jLabel2 = new javax.swing.JLabel(); txtDoctor = new java.awt.TextField(); jLabel3 = new javax.swing.JLabel(); txtAddress = new java.awt.TextField(); jLabel4 = new javax.swing.JLabel(); txtPhone = new java.awt.TextField(); jLabel5 = new javax.swing.JLabel(); cmbSpecialist = new javax.swing.JComboBox(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); lst = new java.awt.List();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Doctor Details\n"); setFont(new java.awt.Font("Verdana", 0, 10));

jLabel1.setText("Doctor ID");

jLabel2.setText("Doctor Name");

jLabel3.setText("Address");

jLabel4.setText("Phone");

jLabel5.setText("Specialist");

cmbSpecialist.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Eye", "Heart", "Nose", " ", " " }));

jButton1.setText("New"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

jButton2.setText("Save"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });

jButton3.setText("Update"); jButton3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } });

jButton4.setText("Delete"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } });

jButton5.setText("Close"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } });

lst.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { lstActionPerformed(evt); } });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel1) .addComponent(jLabel3) .addComponent(jLabel4) .addComponent(jLabel5)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(txtPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE) .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE) .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtDoctor, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE) .addComponent(cmbSpecialist, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(jButton1)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addGap(18, 18, 18) .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton4) .addGap(18, 18, 18) .addComponent(jButton5)) .addComponent(lst, javax.swing.GroupLayout.PREFERRED_SIZE, 333, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(41, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(43, 43, 43) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(txtDoctor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel3) .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(cmbSpecialist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2) .addComponent(jButton3) .addComponent(jButton4) .addComponent(jButton5)) .addGap(19, 19, 19) .addComponent(lst, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(48, Short.MAX_VALUE)) );

pack();

}// </editor-fold>

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.hide();

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { int id=1; Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select max(id) from Doctor"); if(rs.next()) { id=rs.getInt(1); } txtId.setText(Integer.toString(id));

} catch(Exception ex) { System.out.println(ex.getMessage());

} }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { Statement st=con.createStatement(); st.execute("insert into Doctor(DoctorName,Address,Phone,Specialist) values('" + txtDoctor.getText() + "', '" + txtAddress.getText() + "', '"+txtPhone.getText()+"','"+cmbSpecialist.getName()+"')" ); getList();

catch(Exception ex) { System.out.println(ex.getMessage());

} }

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(lst.getSelectedItem()==null) { return;

} try { Statement st=con.createStatement(); st.execute("delete from Doctor where DoctorName='"+lst.getSelectedItem()+"'"); getList();

} catch(Exception ex) { System.out.println(ex.getMessage()); }

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { Statement st=con.createStatement(); st.execute("Update Doctor set DoctorName='"+txtDoctor.getText()+"',Address='"+txtAddress.getText()+"',Phone='"+txtPhone.getText() +"',Specialist='"+cmbSpecialist.getName()+"' where DoctorName='"+lst.getSelectedItem()+"'"); getList(); }

catch(Exception ex) { System.out.println(ex.getMessage()); } }

private void lstActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from Doctor where DoctorName='"+lst.getSelectedItem()+"'"); if(rs.next()) { txtId.setText(rs.getString("id")); txtDoctor.setText(rs.getString("DoctorName")); txtAddress.setText(rs.getString("Address")); txtPhone.setText(rs.getString("Phone"));

} catch(Exception ex) { System.out.println(ex.getMessage());

} void getList(){ try{ lst.removeAll(); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from Doctor order by DoctorName"); while(rs.next()){ lst.add(rs.getString("DoctorName")); } } catch(Exception ex){ System.out.println(ex.getMessage()); } } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmDoctor().setVisible(true); } });

// Variables declaration - do not modify private javax.swing.JComboBox cmbSpecialist; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private java.awt.List lst; private java.awt.TextField txtAddress; private java.awt.TextField txtDoctor; private java.awt.TextField txtId; private java.awt.TextField txtPhone; // End of variables declaration

Patient

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * frmPatient.java * * Created on Dec 28, 2010, 1:59:45 AM */

package hospitalmanagement;

/** * * * @author Administrator */ import java.sql.*;

public class frmPatient extends javax.swing.JFrame { static public final String driver = "com.mysql.jdbc.Driver"; static public final String connection = "jdbc:mysql://localhost:3306/hospital";

static public final String user = "root"; static public final String password = ""; Connection con; /** Creates new form frmPatient */ public frmPatient() { initComponents(); try { Class.forName(driver); con = DriverManager.getConnection(connection, user, password); getList(); } catch(Exception ex) { System.out.println(ex.getMessage()); } }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); txtId = new javax.swing.JTextField(); txtPatientName = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txtAddress = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); txtPhone = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); txtDisease = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); cmbDoctor = new java.awt.Choice(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); msg = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("ID");

jLabel2.setText("Patient Name");

jLabel3.setText("Address");

jLabel4.setText("Phone");

jLabel5.setText("Disease");

jLabel6.setText("Doctor");

jButton1.setText("New"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

jButton2.setText("Save"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });

jButton3.setText("Close"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton3ActionPerformed(evt); } });

msg.setText("-");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4) .addComponent(jLabel5) .addComponent(jLabel6)) .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jButton1) .addGap(26, 26, 26) .addComponent(jButton2)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton3)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(txtPatientName, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) .addComponent(txtPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) .addComponent(txtDisease, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) .addComponent(cmbDoctor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(msg) .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(75, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(20, 20, 20) .addComponent(msg) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup()

.addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtPatientName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(24, 24, 24) .addComponent(jLabel3)) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txtDisease, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5))

.addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel6) .addComponent(cmbDoctor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2) .addComponent(jButton3)) .addContainerGap()) );

pack(); }// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { int id=1; Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select max(id) from patient"); if(rs.next()) {

id=rs.getInt(1); } txtId.setText(Integer.toString(id));

} catch(Exception ex) { System.out.println(ex.getMessage()); } }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { Statement st=con.createStatement(); st.execute("insert into Patient(patientName,Address,Phone,Disease,Doctor) values('" + txtPatientName.getText() + "', '" + txtAddress.getText() + "', '"+txtPhone.getText()+"','"+txtDisease.getText()+"','"+cmbDoctor.getName()+"')" );

msg.setText("Save"); }

catch(Exception ex) { System.out.println(ex.getMessage());

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.hide(); }

/** * @param args the command line arguments */ void getList(){ try{ cmbDoctor.removeAll(); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from Doctor order by DoctorName"); while(rs.next()){ cmbDoctor.add(rs.getString("DoctorName")); } } catch(Exception ex){ System.out.println(ex.getMessage()); } }

public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmPatient().setVisible(true); } }); }

// Variables declaration - do not modify private java.awt.Choice cmbDoctor; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel msg; private javax.swing.JTextField txtAddress; private javax.swing.JTextField txtDisease; private javax.swing.JTextField txtId; private javax.swing.JTextField txtPatientName; private javax.swing.JTextField txtPhone;

// End of variables declaration

Search Doctor

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * frmDoctorSearch.java * * Created on Dec 28, 2010, 3:47:04 PM */

package hospitalmanagement;

/** * * @author Administrator */ import java.sql.*; public class frmDoctorSearch extends javax.swing.JFrame {

/** Creates new form frmDoctorSearch */ Connection con; static public final String driver = "com.mysql.jdbc.Driver"; static public final String connection = "jdbc:mysql://localhost:3306/hospital";

static public final String user = "root"; static public final String password = ""; public frmDoctorSearch() { initComponents(); try { Class.forName(driver); con = DriverManager.getConnection(connection, user, password); getList();

} catch(Exception ex) { System.out.println(ex.getMessage()); } }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jLabel1 = new javax.swing.JLabel(); txtSearch = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); lst = new java.awt.List(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText(" Search By Doctor Name");

jButton1.setText("Search"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

jButton2.setText("Close"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); }

});

jButton3.setText("Close"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } });

jButton4.setText("Close"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(69, 69, 69) .addComponent(lst, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup() .addGap(104, 104, 104) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jButton4) .addGroup(layout.createSequentialGroup() .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(73, 73, 73) .addComponent(jButton1)))) .addGroup(layout.createSequentialGroup() .addGap(153, 153, 153) .addComponent(jLabel1))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(184, 184, 184) .addComponent(jButton2) .addContainerGap(232, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(241, Short.MAX_VALUE) .addComponent(jButton3) .addGap(175, 175, 175))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lst, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(22, 22, 22) .addComponent(jButton4) .addContainerGap(25, Short.MAX_VALUE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(152, 152, 152) .addComponent(jButton2) .addContainerGap(156, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(162, Short.MAX_VALUE) .addComponent(jButton3) .addGap(146, 146, 146))) );

pack(); }// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(txtSearch.getText().equals("")) { System.out.println("Please Enter valid Doctor Name"); return;

} lst.removeAll(); try { Statement st=con.createStatement(); ResultSet rs= st.executeQuery("select * from Doctor where DoctorName='"+txtSearch.getText()+"'"); while(rs.next()) { lst.add(rs.getString("DoctorName")); } } catch(Exception ex) { System.out.println(ex.getMessage()); }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.hide(); }

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.hide(); }

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmDoctorSearch().setVisible(true); } });

} void getList(){ try{ lst.removeAll(); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from Doctor order by DoctorName"); while(rs.next()){ lst.add(rs.getString("DoctorName")); } } catch(Exception ex){ System.out.println(ex.getMessage()); } } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JLabel jLabel1; private java.awt.List lst; private javax.swing.JTextField txtSearch; // End of variables declaration

Search Patient

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * frmPatientSearch.java * * Created on Dec 28, 2010, 3:47:24 PM */

package hospitalmanagement;

/** * * @author Administrator */ import java.sql.*; public class frmPatientSearch extends javax.swing.JFrame {

/** Creates new form frmPatientSearch */ static public final String driver = "com.mysql.jdbc.Driver"; static public final String connection = "jdbc:mysql://localhost:3306/hospital"; static public final String user = "root";

static public final String password = ""; Connection con; public frmPatientSearch() { initComponents(); try { Class.forName(driver); con = DriverManager.getConnection(connection, user, password); getList();

} catch(Exception ex) { System.out.println(ex.getMessage()); } }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jLabel1 = new javax.swing.JLabel(); txtSearch = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); lst = new java.awt.List(); jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Search By Patient Name");

jButton1.setText("Search"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

jButton2.setText("Close"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(96, 96, 96) .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(331, Short.MAX_VALUE) .addComponent(jButton2) .addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(65, Short.MAX_VALUE) .addComponent(lst, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(56, 56, 56)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(154, Short.MAX_VALUE) .addComponent(jLabel1) .addGap(131, 131, 131)) ); layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1)) .addGap(29, 29, 29) .addComponent(lst, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE) .addComponent(jButton2)) );

pack(); }// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(txtSearch.getText().equals("")) { System.out.println("Please Enter valid patient Name"); return;

lst.removeAll(); try { Statement st=con.createStatement(); ResultSet rs= st.executeQuery("select * from patient where patientName='"+txtSearch.getText()+"'"); while(rs.next()) { lst.add(rs.getString("PatientName")); } } catch(Exception ex) { System.out.println(ex.getMessage()); } }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.hide(); }

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmPatientSearch().setVisible(true); }

}); } void getList(){ try{ lst.removeAll(); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from patient order by patientName"); while(rs.next()){ lst.add(rs.getString("patientName")); } } catch(Exception ex){ System.out.println(ex.getMessage()); } }

// Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private java.awt.List lst; private javax.swing.JTextField txtSearch; // End of variables declaration

Vous aimerez peut-être aussi