-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVendorView.java
174 lines (150 loc) · 3.96 KB
/
VendorView.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.util.*;
class VendorView extends JPanel implements ActionListener
{
JInternalFrame ViewBill = new JInternalFrame("View all Vendor Details",true,true,true,true);
public JTable table;
Connection con;
Statement stmt;
ResultSet rs;
LayoutManager lm = null;
String com = new String("Vendor_ID");
String com1;
String filds[] = {
"Vendor_ID", "Vendor_name", "Contact_Person", "Phone","Mobile", "Fax", "email", "Cargo_name", "Date_In"
};
JComboBox oList = new JComboBox(filds);
JLabel enq = new JLabel("Search From Existing Records By :");
JTextField tf = new JTextField(50);
JButton find = new JButton("Find");
public VendorView()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:JMS");
}
catch(Exception ae)
{
System.out.println("NO CONNECTION");
ae.printStackTrace();
}
}
public JInternalFrame VendorViewFrame(JDesktopPane desktop)
{
ViewBill.setLayout(lm);
ViewBill.setSize(1000,500);
enq.setBounds(50,30,200,20);
ViewBill.add(enq);
oList.setMaximumRowCount(12);
oList.setBounds(270,30,100,20);
oList.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent a)
{
com = filds[oList.getSelectedIndex()];
}
});
ViewBill.add(oList);
tf.setBounds(400,30,100,20);
ViewBill.add(tf);
find.setBounds(550,30,80,20);
find.addActionListener(this);
ViewBill.add(find);
ViewBill.setVisible(true);
desktop.add(ViewBill);
ViewBill.show();
return(ViewBill);
}
public void actionPerformed(ActionEvent e)
{ //setVisible(false);
String str = tf.getText();
String query;
String str1=null;
if(!str.equals(""))
{
if(com.equals("Vendor_ID"))
{
int venstr = Integer.parseInt(str);
query = "SELECT * FROM Vendor E WHERE E."+com+" = "+venstr;
}
else
{
str1 = "'"+str+"'";
query = "SELECT * FROM Vendor E WHERE E."+com+" = "+str1;
}
}
else
{
query = "SELECT * FROM Vendor";
}
System.out.println(str1);
try{
stmt = con.createStatement();
System.out.println(query);
rs = stmt.executeQuery(query);
displayResultSet(rs);
stmt.close();
}
catch(SQLException sqlx)
{
sqlx.printStackTrace();
}
}
public void displayResultSet(ResultSet rs1)throws SQLException
{
boolean moreRecords = rs1.next();
if(!moreRecords)
{
JOptionPane.showMessageDialog(this,"No Record is Kept here.");
ViewBill.setTitle("No Record to Display");
return;
}
ViewBill.setTitle("Details Enquired are....");
Vector col = new Vector();
Vector row = new Vector();
try
{
ResultSetMetaData rsmd = rs1.getMetaData();
for(int i = 1;i<=rsmd.getColumnCount();++i)
col.addElement(rsmd.getColumnName(i));
do
{
row.addElement(getNextRow(rs1,rsmd));
}while(rs1.next());
table = new JTable(row,col);
JScrollPane scroller = new JScrollPane(table);
//System.out.println(table);
scroller.setBounds(10,60,1200,500);
ViewBill.add(scroller);
ViewBill.setVisible(true);
//ViewBill.setSize(400,400);
ViewBill.validate();
}
catch(SQLException sqlx)
{
sqlx.printStackTrace();
}
}
private Vector getNextRow(ResultSet rs2,ResultSetMetaData rsmd)throws SQLException
{
Vector currentRow = new Vector();
for(int i = 1;i<=rsmd.getColumnCount();++i)
switch(rsmd.getColumnType(i))
{
case Types.VARCHAR:System.out.println(i);
currentRow.addElement(rs2.getString(i));
break;
case Types.INTEGER:
currentRow.addElement(new Long(rs2.getLong(i)));
break;
default:
System.out.println("type was"+rsmd.getColumnTypeName(i));
}
return currentRow;
}
}