-
Notifications
You must be signed in to change notification settings - Fork 0
/
SupplierWiseMedList.java
134 lines (118 loc) · 4.18 KB
/
SupplierWiseMedList.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
128
129
130
131
132
133
134
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 SupplierWiseMedList 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 SupplierWiseMedList()
{
jf=new JFrame();
f = new Font("Times New Roman",Font.BOLD,20);
jf.setLayout(null);
ln = new JLabel("Supplier wise Medicine report");
ln.setFont(new Font("Times New Roman",Font.BOLD,25));
ln.setForeground(Color.blue);
ln.setBounds(300,30,500,25);
jf.add(ln);
l1 = new JLabel("Enter Supplier name:");
l1.setFont(f);
l1.setBounds(50,100,200,25);
jf.add(l1);
t1=new JTextField(10);
t1.setBounds(250,100,200,25);t1.setToolTipText("Enter supplier name");
jf.add(t1);
submit = new JButton("Submit",new ImageIcon("images//open.png"));
submit.setBounds(120,150,110,35); submit.setToolTipText("click to open supplier wise medicine 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("M_BNO");
model.addColumn("M_NAME");
model.addColumn("M_COMPANY");
model.addColumn("M_QUANTITY");
model.addColumn("M_EXPDATE");
model.addColumn("M_PURDATE");
model.addColumn("M_TYPE");
model.addColumn("M_PURPRICE");
model.addColumn("M_SALEPRICE");
model.addColumn("M_RACKNO");
model.addColumn("M_SID");
model.addColumn("M_SNAME");
jf.setTitle("Supplier Wise Medicine 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 supplier name !","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 mbno,mname,mcompany,mqty,mexpdate,mpurdate,mtype,mpurprice,msaleprice,mrackno,sid,sname from medicine where sname='"+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),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12)});
foundrec = 1;
}
if (foundrec == 0)
{
JOptionPane.showMessageDialog(null,"Not any medicine provide by given supplier","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 SupplierWiseMedList();
}
}