-
Notifications
You must be signed in to change notification settings - Fork 1
/
DailyPurchaseReport.java
127 lines (114 loc) · 3.89 KB
/
DailyPurchaseReport.java
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
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.table.DefaultTableModel;
import java.sql.*;
import java.sql.ResultSet;
public class DailyPurchaseReport extends JFrame implements ActionListener
{
JFrame jf;
JButton submit,clear;
JLabel l1,ln;
JTextField t1;
Font f;
Connection con;
PreparedStatement ps;
Statement stmt;
ResultSet rs;
DefaultTableModel model = new DefaultTableModel();
JTable tabGrid = new JTable(model);
JScrollPane scrlPane = new JScrollPane(tabGrid);
public DailyPurchaseReport()
{
jf=new JFrame();
f = new Font("Times New Roman",Font.BOLD,20);
jf.setLayout(null);
ln = new JLabel("Daily purchase report");
ln.setFont(new Font("Times New Roman",Font.BOLD,25));
ln.setForeground(Color.blue);
ln.setBounds(300,30,300,25);
jf.add(ln);
l1 = new JLabel("Enter purchase report date:");
// l1.setFont(f);
l1.setBounds(50,100,250,25);
jf.add(l1);
t1=new JTextField(10);
t1.setBounds(300,100,100,25);t1.setToolTipText("Enter purchase report date");
jf.add(t1);
submit = new JButton("Submit",new ImageIcon("images//open.png"));
submit.setBounds(120,150,110,35); submit.setToolTipText("click to open daily purchase report");
jf.add(submit);submit.addActionListener(this);
clear = new JButton("Clear",new ImageIcon("images//clear.png"));
clear.setBounds(300,150,110,35);clear.setToolTipText("click to clear textfield");
jf.add(clear);clear.addActionListener(this);
scrlPane.setBounds(0,200,900,600);
jf.add(scrlPane);
tabGrid.setFont(new Font ("Times New Roman",0,15));
model.addColumn("S_ID");
model.addColumn("S_NAME");
model.addColumn("M_BNO");
model.addColumn("M_NAME");
model.addColumn("M_EXPDATE");
model.addColumn("M_QTY");
model.addColumn("M_PURPRICE");
model.addColumn("M_SALEPRICE");
jf.setTitle("Daily Purchase Report");
jf.setSize(900,700);
jf.setLocation(20,20);
jf.setResizable(false);
jf.getContentPane().setBackground(Color.cyan);
jf.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==submit)
{//list
int r = 0;
try
{
if(((t1.getText()).equals("")))
{
JOptionPane.showMessageDialog(this,"Please enter purchase date !","Warning!!!",JOptionPane.WARNING_MESSAGE);
}
else
{
int foundrec = 0;
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/medical_store","root","");
System.out.println("Connected to database.");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("SELECT sid,sname,mbno,mname,mexpdate,mqty,mpurprice,msaleprice from medicine where mpurdate='"+t1.getText()+"' ");
while(rs.next())
{
model.insertRow(r++,new Object[]{rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8)});
foundrec = 1;
}
if (foundrec == 0)
{
JOptionPane.showMessageDialog(null,"Not any medicine purchase on given date","Dialog",JOptionPane.WARNING_MESSAGE);
}
}
con.close();
}
catch(SQLException se)
{
System.out.println(se);
JOptionPane.showMessageDialog(null,"SQL Error:"+se);
}
catch(Exception e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null,"Error:"+e);
}
}
else if(ae.getSource()==clear)
{
t1.setText("");
}
}
public static void main(String args[])
{
new DailyPurchaseReport();
}
}