[go: up one dir, main page]

0% found this document useful (0 votes)
8 views6 pages

Order Input

The document is a Java Swing application for managing orders in a sports store. It connects to a MySQL database to retrieve and display customer and item information in lists, allows users to select items and customers, and facilitates order placement. The application includes functionalities for clearing fields and navigating back to the main menu.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Order Input

The document is a Java Swing application for managing orders in a sports store. It connects to a MySQL database to retrieve and display customer and item information in lists, allows users to select items and customers, and facilitates order placement. The application includes functionalities for clearing fields and navigating back to the main menu.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import javax.swing.

DefaultListModel;

import java.sql.*;

import javax.swing.JOptionPane;

public class OrderINUI extends javax.swing.JFrame {

public OrderINUI() {

initComponents();

} private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {

DefaultListModel sModel = (DefaultListModel) jList1.getModel();

DefaultListModel iModel = (DefaultListModel) jList2.getModel();

sModel.clear();

iModel.clear();
try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost/sports","root","");

Statement stmt = null;

ResultSet rs = null;

ResultSet rs1 = null;

String SQL = "SELECT * FROM regform";

String SQL1 = "SELECT * FROM item";

stmt = con.createStatement();

rs = stmt.executeQuery(SQL);

while (rs.next()) {

String sID = rs.getString("idno");

String Sname = rs.getString("first_Name");

String lname = rs.getString("last_Name");

sModel.addElement(sID + " - " + Sname+""+lname);

jList1.setModel(sModel);

rs1 = stmt.executeQuery(SQL1);

while (rs1.next()) {

String iID = rs1.getString("Item_Id");

String Iname = rs1.getString("Item_Name");

iModel.addElement(iID + " - " + Iname);

jList2.setModel(iModel);
con.close();

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

private void jList2MouseClicked(java.awt.event.MouseEvent evt) {

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost/sports","root","");

Statement stmt = null;

ResultSet rs = null;

String ItemIDName = (String) jList2.getSelectedValue();

String ItemID = ItemIDName.substring(0, 3);

String Iame= ItemIDName.substring(7);

txtItemID.setText(ItemID);

String SQL = "SELECT * FROM item where Item_Id = '"+(ItemID)+"'";

stmt = con.createStatement();

rs = stmt.executeQuery(SQL);

while (rs.next()) {

double iprice = rs.getDouble("Price");

txtItemPrice.setText(Double.toString(iprice));

con.close();
} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

String SidName = (String) jList1.getSelectedValue();

String Sid = SidName.substring(0, 3);

String Sname= SidName.substring(6);

txtSID.setText(Sid);

txtSName.setText(Sname);

private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

txtOrdno.setText("");

txtOrdDate.setText("");

txtSID.setText("");

txtItemID.setText("");

txtSName.setText("");

txtItemPrice.setText("");

txtOrdQty.setText("");

private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {

this.setVisible(false);

new MainMenu().setVisible(true);
}

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con = (Connection)

DriverManager.getConnection("jdbc:mysql://localhost/sports","root","");

Statement stmt = null;

ResultSet rs = null; // ResultSet for SHOPKEEPER table.

String SQL = "SELECT * FROM orderitem";

stmt = con.createStatement(); // Connection string for ResultSet - rs.

rs = stmt.executeQuery(SQL);

float discP = 0; // Discount

String Ordno = txtOrdno.getText();

String OrdDate = txtOrdDate.getText();

String ItemID = txtItemID.getText();

String ShopID = txtSID.getText();

String ItemPrice = txtItemPrice.getText();

double iPrice = Double.parseDouble(txtItemPrice.getText());

String ordQty = txtOrdQty.getText();

double amt = (Integer.parseInt(txtOrdQty.getText()) *


Double.parseDouble(txtItemPrice.getText())) ;

String strSQL = "INSERT INTO orderitem(orderno, Item_Id, Shopper_Id, Quantity, Order_date,


price, Amount ) VALUES ('"+(Ordno)+"','"+(ItemID)+"','"+(ShopID)+"','"+(ordQty)+"','"+(OrdDate)+"','"+
(iPrice)+"','"+(amt)+"')";

JOptionPane.showMessageDialog(this, "Order successfully placed");

int rowsEffected = stmt.executeUpdate(strSQL);

System.out.println(rowsEffected + " rows effected");


con.close();

} catch (Exception e) {

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new OrderINUI().setVisible(true);

});

You might also like