-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFrmRoomOccupancy.java
More file actions
114 lines (104 loc) · 3.02 KB
/
FrmRoomOccupancy.java
File metadata and controls
114 lines (104 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package hms;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.print.*;
public class FrmRoomOccupancy extends JInternalFrame implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
JButton jbt;
JTable jtb;
ResultSet rst;
JScrollPane jsp;
String[] heads={"Room Id","Room Number","Room Category","Description","Room Charges","Bed Count","Bed Occupied","Bed Free"};
Object data[][];
DConnection dc;
FrmRoomOccupancy()
{
super("Room Occupancy Chart",true,true,true,true);
jbt=new JButton("Print");
jbt.addActionListener(this);
add(jbt,"South");
try
{
dc=new DConnection();
rst=dc.executeQuery("select count(*) from room");//tabale name??
rst.next();
int n=rst.getInt(1);
data=new Object[n][8];
rst=dc.executeQuery("select * from room");
for(int i=0;rst.next();i++)
{
data[i][0] = rst.getString(1);
data[i][1] = rst.getString(2);
data[i][2] = rst.getString(3);
data[i][3] = rst.getString(5);
data[i][4] = rst.getString(6);
data[i][5] = rst.getString(4);
data[i][6] = "";
data[i][7] = "";
}
dc.close();
for(int i=0;i<n;i++)
{
String rn=(String)data[i][1];
rst=dc.executeQuery("select count(*) from ipdpatient where room_number="+rn +" and dod='Not Discharged Yet'");
rst.next();
int cnt=rst.getInt(1);
dc.close();
data[i][6]=cnt+"";
data[i][7]=Integer.parseInt((String)data[i][5])-cnt+"";
}
dc.close();
}
catch(Exception e)
{
e.printStackTrace();
}
jtb=new JTable(data,heads);
jtb.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
jtb.setFillsViewportHeight(true);
jtb.setDefaultRenderer(Object.class, new DefaultTableCellRenderer(){
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row, int col) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
String status = (String)table.getModel().getValueAt(row, 7);
if ("0".equals(status)) {
setBackground(Color.RED);
setForeground(Color.WHITE);
} else {
setBackground(table.getBackground());
setForeground(table.getForeground());
}
return this;
}
});
jsp = new JScrollPane(jtb);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
add(jsp);
setVisible(true);
setSize(900,500);
}
public void actionPerformed(ActionEvent ae)
{
try
{
jtb.print();
}
catch(PrinterException e)
{
e.printStackTrace();
}
}
}