You are on page 1of 12

Coding of Hospital Management Patient Bill Generating System

Frontpage.java

private void btnclickActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
new PASSWORD().setVisible(true);
}
Menuscreen.java

private void btndeleteActionPerformed(java.awt.event.ActionEvent evt)


{
new deletepatient().setVisible(true);
}

private void btnaddActionPerformed(java.awt.event.ActionEvent evt)


{
new addpatient().setVisible(true);
}

private void btnmodifyActionPerformed(java.awt.event.ActionEvent evt)


{
new modifypatient().setVisible(true);
}
Addpatient.java

import java.sql.*;
import javax.swing.JOptionPane;
private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("java.sql.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/hospitalrec","root","1")
;

String query = "INSERT INTO paitent VALUES (";


query = query + txtpno.getText() + ", ";
query = query + "'" + txtpname.getText() + "', ";
query = query + "'"+txtaddress.getText() + "', ";
query = query + "'"+txtphone.getText() + "', ";
query = query + "'"+txtdisease.getText() + "', ";
query = query + "'"+txtdname.getText() + "', ";
query = query + txtndays.getText() +", ";
query=query+ txtcfees.getText() + ",";
query=query+txtmeal.getText() + ",";
query=query+ txtroom.getText()+", ";
query=query+"'"+txttype.getText()+"',";
query=query+ txttotal.getText()+");";

Statement stmt=con.createStatement();
stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Saved Successfully");
stmt.close();
con.close();
}

catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error in Connectivity");
}
}

private void btnbackActionPerformed(java.awt.event.ActionEvent evt) {

new menuscreen().setVisible(true);
}

private void btnnewActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
txtpno.setText(" ");
txtpname.setText(" ");
txtaddress.setText(" ");
txtphone.setText(" ");
txtdisease.setText(" ");
txtdname.setText(" ");
txtndays.setText(" ");
txtcfees.setText(" ");
txtmeal.setText(" ");
txtroom.setText(" ");
txttype.setText(" ");
txttotal.setText(" ");
}
Modifypatient.java

import java.sql.*;
import javax.swing.JOptionPane;
private void btnnew1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{ Class.forName("java.sql.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/hospitalrec","root","1");
Statement stmt =con.createStatement();

String query = "SELECT * FROM paitent WHERE pno= ";


query = query + txtpno.getText() + ";";
ResultSet rs = stmt.executeQuery(query);
long days1,cfees1,room1,total1,meal1;
String cname1,addr1,phone1,dname1,disease1,type1;
if (rs.next())
{
cname1 = rs.getString("pname");
addr1=rs.getString("address");
phone1=rs.getString("phone");
disease1=rs.getString("disease");
dname1=rs.getString("dname");
days1=rs.getLong("nodays");
cfees1=rs.getLong("cfees");
meal1=rs.getLong("meal");
room1=rs.getLong("room");
type1=rs.getString("typeroom");
total1=rs.getLong("total");

txtpname.setText(" "+cname1);
txtaddress.setText(" "+addr1);
txtphone.setText(" "+phone1);
txtdisease.setText(" "+disease1);
txtdname.setText(" "+dname1);
txtndays.setText(" "+days1);
txtcfees.setText(" "+cfees1);
txtmeal.setText(" "+meal1);
txtroom.setText(" "+room1);
txttype.setText(" "+type1);
txttotal.setText(" "+total1);

}
else
{
txtpno.setText(" ");
txtpname.setText(" ");
txtaddress.setText(" ");
txtphone.setText(" ");
txtdisease.setText(" ");
txtdname.setText(" ");
txtndays.setText(" ");
txtcfees.setText(" ");
txtmeal.setText(" ");
txtroom.setText(" ");
txttype.setText(" ");
txttotal.setText(" ");
JOptionPane.showMessageDialog(null, "No such record found");
}
} //end of try
catch(Exception e)
{ JOptionPane.showMessageDialog(null, "Error in connectivity");
}

}
private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int ans;
String query;
ans = JOptionPane.showConfirmDialog(null, "Surely wants to update the record");
if(ans == JOptionPane.YES_OPTION)
{
try
{
Class.forName("java.sql.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/hospitalrec","root","1");
Statement stmt =con.createStatement();

query = "UPDATE paitent SET pname = " + "'" + txtpname.getText() + "'";


query = query + ", address = " + "'" + txtaddress.getText() + "'";
query=query+", phone = "+ "'"+txtphone.getText()+"',";
query=query+ "disease="+"'" +txtdisease.getText()+"',";
query=query+ "dname="+"'"+txtdname.getText()+"',";
query=query+ "nodays="+txtndays.getText()+",";
query=query+ "cfees="+txtcfees.getText()+",";
query=query+ "meal="+txtmeal.getText()+",";
query=query+"room="+txtroom.getText()+",";
query=query+"typeroom="+"'"+txttype.getText()+",";
query=query+"total="+txttotal.getText();
query = query + " WHERE pno= " + txtpno.getText() + ";";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Record successfully updated");
} //end of try

catch(Exception e)
{ JOptionPane.showMessageDialog(null, "Error in updation");
}
}//end of if.
}

private void btnnewActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
txtpno.setText(" ");
txtpname.setText(" ");
txtaddress.setText(" ");
txtphone.setText(" ");
txtdisease.setText(" ");
txtdname.setText(" ");
txtndays.setText(" ");
txtcfees.setText(" ");
txtmeal.setText(" ");
txtroom.setText(" ");
txttype.setText(" ");
txttotal.setText(" ");
}

private void btnbackActionPerformed(java.awt.event.ActionEvent evt) {

new menuscreen().setVisible(true);
}
Deletepatient.java

import java.sql.*;
import javax.swing.JOptionPane;
private void btnnew1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Class.forName("java.sql.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/hospitalrec","root","1");
Statement stmt =con.createStatement();

String query = "SELECT * FROM paitent WHERE pno= ";


query = query + txtpno.getText() + ";";
ResultSet rs = stmt.executeQuery(query);
long days1,cfees1,room1,total1,meal1;
String cname1,addr1,phone1,dname1,disease1,type1;
if (rs.next()) {
cname1 = rs.getString("pname");
addr1=rs.getString("address");
phone1=rs.getString("phone");
disease1=rs.getString("disease");
dname1=rs.getString("dname");
days1=rs.getLong("nodays");
cfees1=rs.getLong("cfees");
meal1=rs.getLong("meal");
room1=rs.getLong("room");
type1=rs.getString("typeroom");
total1=rs.getLong("total");

txtpname.setText(" "+cname1);
txtaddress.setText(" "+addr1);
txtphone.setText(" "+phone1);
txtdisease.setText(" "+disease1);
txtdname.setText(" "+dname1);
txtndays.setText(" "+days1);
txtcfees.setText(" "+cfees1);
txtmeal.setText(" "+meal1);
txtroom.setText(" "+room1);
txttype.setText(" "+type1);
txttotal.setText(" "+total1);

} else {
txtpno.setText(" ");
txtpname.setText(" ");
txtaddress.setText(" ");
txtphone.setText(" ");
txtdisease.setText(" ");
txtdname.setText(" ");
txtndays.setText(" ");
txtcfees.setText(" ");
txtmeal.setText(" ");
txtroom.setText(" ");
txttype.setText(" ");
txttotal.setText(" ");
JOptionPane.showMessageDialog(null, "No such record found");
}
} //end of try
catch(Exception e) {
JOptionPane.showMessageDialog(null, "Error in connectivity");
}
}

private void txttypeFocusLost(java.awt.event.FocusEvent evt) {


// TODO add your handling code here:
int a = 0;
String tt;
long tot=0;
tt=txttype.getText();
if (tt.equals("Delux")) {
a=3000;
}
if (tt.equals("Twin Bed")) {
a=1800;
}
if (tt.equals("Economic")) {
a=1000;
}
txtroom.setText(""+a);
tot=Long.parseLong(txtndays.getText())*(Long.parseLong(txtroom.getText())
+Long.parseLong(txtcfees.getText())+Long.parseLong(txtmeal.getText()));
txttotal.setText(" "+tot);
}

private void btnnewActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
txtpno.setText(" ");
txtpname.setText(" ");
txtaddress.setText(" ");
txtphone.setText(" ");
txtdisease.setText(" ");
txtdname.setText(" ");
txtndays.setText(" ");
txtcfees.setText(" ");
txtmeal.setText(" ");
txtroom.setText(" ");
txttype.setText(" ");
txttotal.setText(" ");
}

Coding for Password.java


import javax.swing.JOptionPane;

private void btnokActionPerformed(java.awt.event.ActionEvent evt)


{
String user1,pass1;
user1=txtname.getText();
pass1=new String(txtpass.getPassword());
if (user1.equals("gurleen") && pass1.equals("xyz")) {
JOptionPane.showMessageDialog(null," Correct Password");
new menuscreen().setVisible(true);
} else {
JOptionPane.showMessageDialog(null," In-Correct Password");

}
}

private void btncancelActionPerformed(java.awt.event.ActionEvent evt)


{
System.exit(0);
}

You might also like