-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.java
More file actions
150 lines (148 loc) · 4.3 KB
/
Copy pathcart.java
File metadata and controls
150 lines (148 loc) · 4.3 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
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chemist_shop;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class cart extends JFrame implements ActionListener, ItemListener
{
Font f1 = new Font("Courier New", Font.ITALIC,26);
JLabel l1, l2, l3, l4, l5, l6, l7;
Choice ch1, ch2;
JTextField t1, t2, t3, t4;
JButton b1, b2;
public cart()
{
setSize(1000, 1000);
setLocation(100,100);
setLayout(new GridLayout(8,2));
l1 = new JLabel("Medicine ID");
l1.setFont(f1);
l2 = new JLabel("Company");
l2.setFont(f1);
l3 = new JLabel("Salt");
l3.setFont(f1);
l4 = new JLabel("Price");
l4.setFont(f1);
l5 = new JLabel("Quantity");
l5.setFont(f1);
l7 = new JLabel("Customer ID");
l7.setFont(f1);
t1 = new JTextField(30);
t1.setFont(f1);
t2 = new JTextField(30);
t2.setFont(f1);
t3 = new JTextField(30);
t3.setFont(f1);
t4 = new JTextField(30);
t4.setFont(f1);
b1 = new JButton("Add to Cart");
b1.setFont(f1);
b2 = new JButton("View Cart");
b2.setFont(f1);
ch1 = new Choice();
ch1.setFont(f1);
try
{
conn c1 = new conn();
ResultSet rs = c1.s.executeQuery("SELECT * FROM MEDICINE");
while(rs.next())
{
ch1.add(rs.getString("MEDICINE_ID"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
ch1.addItemListener(this);
ch2 = new Choice();
ch2.setFont(f1);
try
{
conn c1 = new conn();
ResultSet rs = c1.s.executeQuery("SELECT * FROM CUSTOMER");
while(rs.next())
{
ch2.add(rs.getString("CUSTOMER_ID"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
ch2.addItemListener(this);
add(l7);
add(ch2);
add(l1);
add(ch1);
add(l2);
add(t1);
add(l3);
add(t2);
add(l4);
add(t3);
add(l5);
add(t4);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
float x = Float.parseFloat(t4.getText());
float y = Float.parseFloat(t3.getText());
float product = x*y;
int cus_id = Integer.parseInt(ch2.getSelectedItem());
int med_id = Integer.parseInt(ch1.getSelectedItem());
String msg = ae.getActionCommand();
if(msg.equals("Add to Cart"))
{
String t = new java.util.Date().toString();
String q1 = "INSERT INTO BILL VALUES(NULL,"+cus_id+", "+med_id+", "+x+", "+product+", 'NP', '"+t+"')";
//String r1 = "UPDATE MEDICINE SET QUANT=QUANT-"+x+" WHERE MEDICINE_ID="+med_id;
try
{
conn c1 = new conn();
c1.s.executeUpdate(q1);
JOptionPane.showMessageDialog(null, "Item Added to Cart");
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(msg.equals("View Cart"))
{
new view_cart2(cus_id).setVisible(true);
}
}
public void itemStateChanged(ItemEvent ie)
{
String q1 = "SELECT * FROM MEDICINE WHERE MEDICINE_ID="+ch1.getSelectedItem();
try
{
conn c = new conn();
ResultSet rs = c.s.executeQuery(q1);
if(rs.next())
{
t1.setText(rs.getString("COMPANY"));
t2.setText(rs.getString("SALT"));
t3.setText(rs.getString("PRICE"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String s[])
{
new cart().setVisible(true);
}
}