Skip to content

Instantly share code, notes, and snippets.

@sandeepmchouhan111293
Created January 18, 2017 00:37
Show Gist options
  • Save sandeepmchouhan111293/70126654e4f5530e017a0f50e27d33b1 to your computer and use it in GitHub Desktop.
Save sandeepmchouhan111293/70126654e4f5530e017a0f50e27d33b1 to your computer and use it in GitHub Desktop.
Code for login page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Login.java
*
* Created on Sep 6, 2010, 11:24:53 PM
*/
package mobilestorenew;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Ramesh
*/
public class Login extends javax.swing.JFrame {
/** Creates new form Login */
String s1, s2, s3, s4;
ResultSet res;
int a = 0;
public Login() {
initComponents();
setSize(1270, 740);
setTitle("Login Form");
setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel4 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jPasswordField1 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
jLabel4.setFont(new java.awt.Font("Monotype Corsiva", 1, 60)); // NOI18N
jLabel4.setForeground(new java.awt.Color(51, 255, 51));
jLabel4.setText("Raj Mobile Store");
getContentPane().add(jLabel4);
jLabel4.setBounds(310, 60, 420, 70);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel1.setLayout(null);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel2.setText("User Name");
jPanel1.add(jLabel2);
jLabel2.setBounds(80, 100, 100, 30);
jTextField1.setFont(new java.awt.Font("Tahoma", 1, 18));
jPanel1.add(jTextField1);
jTextField1.setBounds(210, 100, 110, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel3.setText("Password");
jPanel1.add(jLabel3);
jLabel3.setBounds(80, 150, 110, 30);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel1.setText("Login Here");
jPanel1.add(jLabel1);
jLabel1.setBounds(150, 30, 130, 40);
jPasswordField1.setFont(new java.awt.Font("Tahoma", 1, 18));
jPanel1.add(jPasswordField1);
jPasswordField1.setBounds(210, 150, 110, 30);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton1.setText("Login");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
jButton1.setBounds(120, 230, 90, 40);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel1.add(jButton2);
jButton2.setBounds(230, 230, 90, 40);
getContentPane().add(jPanel1);
jPanel1.setBounds(300, 170, 430, 300);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
s1 = jTextField1.getText();
s2 = jPasswordField1.getText();
try {
Connection co;
Statement st;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
co = DriverManager.getConnection("jdbc:odbc:mobileDSN", "scott", "tiger");
st = co.createStatement();
res = st.executeQuery("select * from login");
Boolean rec = res.next();
if (!rec) {
JOptionPane.showMessageDialog(null, "There is no records in the table");
} else {
do {
s3 = res.getString(1);
s4 = res.getString(2);
if (s1.equals(s3) && s2.equals(s4)) {
dispose();
new Home();
a = 1;
break;
}
} while (res.next());
if (a == 0) {
JOptionPane.showMessageDialog(null, "Invalid user or password");
jTextField1.setText("");
jPasswordField1.setText("");
}
}
st.close();
co.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "The error is:" + e);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
Code for Home Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Home.java
*
* Created on Sep 6, 2010, 11:53:35 PM
*/
package mobilestorenew;
import java.sql.*;
import javax.swing.*;
import java.util.Date;
/**
*
* @author Ramesh
*/
public class Home extends javax.swing.JFrame {
/** Creates new form Home */
int a = 0, flag = 0, b = 0, c = 0, temp, d = 0, f = 0, g = 0;
int rows = 0;
Object data[][];
String col[];
String cid, cid1, id,text="";
String mc1, mc;
JTable table;
String totaldata = "";
int bid;
Date dat1;String dt1,day1,month1,year1,date1;
public Home() {
initComponents();
setSize(1270, 740);
setTitle("Mobile Store Home Page");
setVisible(true);
idincrement();
installmentcheck();
}
public void idincrement()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection co=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=co.createStatement();
ResultSet res=st.executeQuery("select * from newbill");
while(res.next())
{
bid=res.getInt(1);
}
st.close();
co.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"the error is"+e);
System.out.println(e.getMessage());
}
bid=bid+1;
dat1=new Date();
dt1=dat1.toString();
System.out.println(dt1);
day1=dt1.substring(8,10);
month1=dt1.substring(4,7);
year1=dt1.substring(24,28);
date1=day1;
date1+="-";
date1+=month1;
date1+="-";
date1+=year1;
}
public void installmentcheck()
{
String countcid="";
String countcname="";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res1=st.executeQuery("select cid,cname,pdate, floor(months_between(sysdate,pdate)) as diff from newcustomer_details");
Boolean rec=res1.next();
if(rec==false)
{
System.out.println("there are no records");
}
else
{
do
{
String dcid=res1.getString(1);
String dcname=res1.getString(2);
int diff=res1.getInt(4);
if(diff>=2)
{
countcid+=dcid+"\n";
countcname+=dcname+"\n";
JOptionPane.showMessageDialog(null,"The following Customer Not Payed Their Installments from last two months\n" +
countcid+"\t"+countcname);
}
}while(res1.next());
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is :"+e);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem6 = new javax.swing.JMenuItem();
jMenuItem7 = new javax.swing.JMenuItem();
jMenuItem8 = new javax.swing.JMenuItem();
jMenuItem13 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jMenuItem9 = new javax.swing.JMenuItem();
jMenuItem10 = new javax.swing.JMenuItem();
jMenu5 = new javax.swing.JMenu();
jMenuItem5 = new javax.swing.JMenuItem();
jMenuItem14 = new javax.swing.JMenuItem();
jMenuItem15 = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem11 = new javax.swing.JMenuItem();
jMenuItem12 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
jMenu1.setText("Mobile Phone ");
jMenuItem1.setText("Add Mobile Phone");
jMenuItem1.setToolTipText("Click here to add a mobile phone");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuItem3.setText("Search Mobile Phone");
jMenuItem3.setToolTipText("Click here to Search a Mobile Phone");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem3);
jMenuItem2.setText("Update Mobile Phone");
jMenuItem2.setToolTipText("Click here to Update a Mobile Phone");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuItem4.setText("Delete Mobile Phone");
jMenuItem4.setToolTipText("Click here to delete a mobile phone");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem4ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem4);
jMenuBar1.add(jMenu1);
jMenu2.setText("Customer ");
jMenuItem6.setText("Search Customer");
jMenuItem6.setToolTipText("Click here to Search a Customer");
jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem6ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem6);
jMenuItem7.setText("Update Customer");
jMenuItem7.setToolTipText("Click here to Update Customer Details");
jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem7ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem7);
jMenuItem8.setText("Delete Customer");
jMenuItem8.setToolTipText("Click here to Delete a Customer");
jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem8ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem8);
jMenuItem13.setText("Credit Payments");
jMenuItem13.setToolTipText("Click here for Credit Payments");
jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem13ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem13);
jMenuBar1.add(jMenu2);
jMenu3.setText("Bill Administration ");
jMenuItem9.setText("Generate Bill");
jMenuItem9.setToolTipText("Click here to Generate Bill");
jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem9ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem9);
jMenuItem10.setText("Search Bill");
jMenuItem10.setToolTipText("Click here Search a Bill");
jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem10ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem10);
jMenuBar1.add(jMenu3);
jMenu5.setText("Sales Reports ");
jMenuItem5.setText("Daily Reports");
jMenuItem5.setToolTipText("Click here for Daily Reports");
jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem5ActionPerformed(evt);
}
});
jMenu5.add(jMenuItem5);
jMenuItem14.setText("Monthly Reports");
jMenuItem14.setToolTipText("Click here for Monthly Reports");
jMenuItem14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem14ActionPerformed(evt);
}
});
jMenu5.add(jMenuItem14);
jMenuItem15.setText("Yearly Reports");
jMenuItem15.setToolTipText("Click here for Yearly Reports");
jMenuItem15.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem15ActionPerformed(evt);
}
});
jMenu5.add(jMenuItem15);
jMenuBar1.add(jMenu5);
jMenu4.setText("User");
jMenuItem11.setText("LogOff");
jMenuItem11.setToolTipText("Click here to LogOff");
jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem11ActionPerformed(evt);
}
});
jMenu4.add(jMenuItem11);
jMenuItem12.setText("Exit");
jMenuItem12.setToolTipText("Click here to Exit from the Application");
jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem12ActionPerformed(evt);
}
});
jMenu4.add(jMenuItem12);
jMenuBar1.add(jMenu4);
setJMenuBar(jMenuBar1);
pack();
}// </editor-fold>
private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
new Login();
}
private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new Addmobile1();
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new SearchMobile();
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new MobileUpdate();
}
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String id1 = JOptionPane.showInputDialog(null, "Enter Mobile Phone Id (or) IMEI No");
while (id1.equals("")) {
JOptionPane.showMessageDialog(null, "You should have to enter something");
id1 = JOptionPane.showInputDialog(null, "Enter Mobile Phone Id (or) IMEI No");
}
try {
Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:mobileDSN", "scott", "tiger");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from newmobile_details");
Boolean rec = res.next();
if (!rec) {
JOptionPane.showMessageDialog(null, "There are no mobile phones in the database");
} else {
do {
String s1 = res.getString(1);
String s2 = res.getString(3);
String s3 = res.getString(6);
if (id1.equalsIgnoreCase(s1) || id1.equalsIgnoreCase(s3)) {
int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete the mobile phone " + s2 + " with having mobile id:" + s1 + " and IMEI no:" + s3);
if (reply == JOptionPane.YES_OPTION) {
PreparedStatement prp = con.prepareStatement("delete newmobile_details where phone_id=?");
prp.setString(1, s1);
prp.executeUpdate();
JOptionPane.showMessageDialog(null, "The mobile successfully deleted");
a = 1;
} else if (reply == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "The mobile phone is not deleted");
a = 1;
break;
} else if (reply == JOptionPane.CANCEL_OPTION) {
JOptionPane.showMessageDialog(null, "The mobile phone details are not deleted");
a = 1;
break;
} else {
}
}
} while (res.next());
if (a == 0) {
JOptionPane.showMessageDialog(null, "The mobile phone does not exists in the database");
}
}
con.commit();
con.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "the error is" + e);
}
}
private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new BillGeneration();
}
private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String searchbill = JOptionPane.showInputDialog(null, "Enter the Bill Id to search");
while (searchbill.equals("")) {
JOptionPane.showMessageDialog(null, "Please enter Bill Id");
searchbill = JOptionPane.showInputDialog(null, "Enter the Bill Id to search");
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mobileDSN", "scott", "tiger");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from newbill");
Boolean rec = res.next();
if (!rec) {
JOptionPane.showMessageDialog(null, "There are no Bills exists");
} else {
do {
String dbid = res.getString(1);
if (searchbill.equals(dbid)) {
BillGeneration bg = new BillGeneration();
bg.jTextField1.setText(dbid);
bg.jTextField2.setText(res.getDate(2).toString());
bg.jTextField3.setText(res.getString(3));
bg.jTextField6.setText(res.getString(4));
bg.jTextField7.setText(res.getString(5));
bg.jTextArea1.setText("Phone Name \tPhone Price \tPhone Color \tIMEI Number \n-------" +
"--------------------------------------------------------------------------");
bg.jTextArea1.append(res.getString(6));
bg.jPanel1.setVisible(false);
bg.jButton2.setVisible(false);
bg.jTextField7.setEditable(false);
bg.jTextField3.setEditable(false);
bg.jLabel2.setBounds(280, 110, 130, 30);
bg.jTextField1.setBounds(460, 110, 130, 30);
bg.jLabel3.setBounds(280, 170, 130, 30);
bg.jTextField2.setBounds(460, 170, 130, 30);
bg.jLabel4.setBounds(280, 230, 130, 30);
bg.jTextField3.setBounds(460, 230, 130, 30);
bg.jLabel8.setBounds(280, 290, 130, 30);
bg.jScrollPane1.setBounds(460, 290, 410, 160);
bg.jLabel9.setBounds(280, 480, 130, 30);
bg.jTextField6.setBounds(460, 480, 130, 30);
bg.jLabel10.setBounds(280, 540, 130, 30);
bg.jTextField7.setBounds(460, 540, 130, 30);
bg.jButton1.setBounds(430, 620, 100, 40);
bg.jLabel1.setText("Search Results");
bg.jLabel8.setText("Mobiles Purchased");
bg.jButton1.setText("CLOSE");
bg.setTitle("Search Bill");
bg.flag = 1;
f = 1;
}
} while (res.next());
if (f == 0) {
JOptionPane.showMessageDialog(null, "The Bill Id does not exists");
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "The error is :" + e);
}
}
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new SearchCustomer();
}
private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
cid = JOptionPane.showInputDialog(null, "Enter Customer Id");
while (cid.equals("")) {
JOptionPane.showMessageDialog(null, "Please Enter Customer Id");
cid = JOptionPane.showInputDialog(null, "Enter Customer Id to Search");
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mobileDSN", "scott", "tiger");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from newcustomer_details");
Boolean rec = res.next();
if (!rec) {
JOptionPane.showMessageDialog(null, "There are no customer EXISTS");
} else {
do {
cid1 = res.getString(1);
if (cid.equalsIgnoreCase(cid1)) {
CreditCustomer cc = new CreditCustomer();
cc.jTextField1.setText(cid1);
cc.jTextField2.setText(res.getString(2));
java.sql.Date dt = res.getDate(3);
String dd = dt.toString();
String year = dd.substring(0, 4);
String month = dd.substring(5, 7);
String day = dd.substring(8, 10);
if (month.equals("01")) {
mc1 = "jan";
} else if (month.equals("02")) {
mc1 = "feb";
} else if (month.equals("03")) {
mc1 = "mar";
} else if (month.equals("04")) {
mc1 = "apr";
} else if (month.equals("05")) {
mc1 = "may";
} else if (month.equals("06")) {
mc1 = "jun";
} else if (month.equals("07")) {
mc1 = "jul";
} else if (month.equals("08")) {
mc1 = "aug";
} else if (month.equals("09")) {
mc1 = "sep";
} else if (month.equals("10")) {
mc1 = "oct";
} else if (month.equals("11")) {
mc1 = "nov";
} else if (month.equals("12")) {
mc1 = "dec";
}
String date = day;
date += "-";
date += mc1;
date += "-";
date += year;
cc.jTextField3.setText(date);
cc.jTextField4.setText(Integer.toString(res.getInt(4)));
cc.jTextField5.setText(Integer.toString(res.getInt(5)));
cc.jTextField6.setText(Integer.toString(res.getInt(6)));
java.sql.Date dob = res.getDate(7);
String ddob = dob.toString();
String year2 = ddob.substring(0, 4);
String month2 = ddob.substring(5, 7);
String day2 = ddob.substring(8, 10);
if (month2.equals("01")) {
mc = "jan";
} else if (month2.equals("02")) {
mc = "feb";
} else if (month2.equals("03")) {
mc = "mar";
} else if (month2.equals("04")) {
mc = "apr";
} else if (month2.equals("05")) {
mc = "may";
} else if (month2.equals("06")) {
mc = "jun";
} else if (month2.equals("07")) {
mc = "jul";
} else if (month2.equals("08")) {
mc = "aug";
} else if (month2.equals("09")) {
mc = "sep";
} else if (month2.equals("10")) {
mc = "oct";
} else if (month2.equals("11")) {
mc = "nov";
} else if (month2.equals("12")) {
mc = "dec";
}
cc.jComboBox1.setSelectedItem(day2);
cc.jComboBox2.setSelectedItem(mc);
cc.jComboBox3.setSelectedItem(year2);
cc.jTextField7.setText(Integer.toString(res.getInt(8)));
String gender = res.getString(9);
if (gender.equalsIgnoreCase("male")) {
cc.jRadioButton1.setSelected(true);
} else if (gender.equalsIgnoreCase("female")) {
cc.jRadioButton2.setSelected(true);
}
cc.jTextField8.setText(res.getString(10));
cc.jTextField9.setText(res.getString(11));
cc.jTextField10.setText(res.getString(12));
cc.jTextField11.setText(res.getString(13));
cc.jTextField12.setText(res.getString(14));
cc.jTextArea1.setText(res.getString(15));
cc.jTextField13.setVisible(false);
cc.jTextField14.setVisible(false);
cc.jLabel25.setVisible(false);
cc.jLabel26.setVisible(false);
cc.jLabel1.setText("Update Customer Details");
cc.jButton1.setText("Update Customer Details");
cc.flag = 3;
c = 1;
break;
}
} while (res.next());
if (c == 0) {
JOptionPane.showMessageDialog(null, "The customer id does not exists");
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "The error is" + e);
}
}
private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
cid = JOptionPane.showInputDialog(null, "Enter Customer Id");
while (cid.equals("")) {
JOptionPane.showMessageDialog(null, "Please Enter Customer Id");
cid = JOptionPane.showInputDialog(null, "Enter Customer Id to Search");
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mobileDSN", "scott", "tiger");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from newcustomer_details");
Boolean rec = res.next();
if (!rec) {
JOptionPane.showMessageDialog(null, "There are no customer");
} else {
do {
cid1 = res.getString(1);
if (cid.equalsIgnoreCase(cid1)) {
int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want delete this customer");
if (reply == JOptionPane.YES_OPTION) {
PreparedStatement prp = con.prepareStatement("delete newcustomer_details where cid=" + cid);
prp.executeUpdate();
JOptionPane.showMessageDialog(null, "The Customer Details Deleted Successfully");
} else if (reply == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "The customer details are not deleted");
} else if (reply == JOptionPane.CANCEL_OPTION) {
JOptionPane.showMessageDialog(null, "The customer details are not deleted");
}
d = 1;
break;
}
} while (res.next());
if (d == 0) {
JOptionPane.showMessageDialog(null, "The Customer Id is not exists in the database");
}
con.commit();
con.close();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "The error is:" + e);
}
}
private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int creditpayid;
String creditpayid1 = JOptionPane.showInputDialog(null, "Enter Customer Id");
while (creditpayid1.equals(""))
{
JOptionPane.showMessageDialog(null, "Please enter Customer Id");
creditpayid1 = JOptionPane.showInputDialog(null, "Enter Customer Id");
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mobileDSN", "scott", "tiger");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from newcustomer_details");
Boolean rec = res.next();
if (rec == false)
{
JOptionPane.showMessageDialog(null, "There are no records");
}
else
{
do
{
int dcid = res.getInt(1);
String dcname = res.getString(2);
int dpaidamt = res.getInt(4);
int dbalamt = res.getInt(5);
int drefid = res.getInt(6);
String dmob_purchase = res.getString(15);
creditpayid = Integer.parseInt(creditpayid1);
if (creditpayid == dcid)
{
int creditpay = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the Amount that Customer want to Pay"));
while(creditpay<500)
{
JOptionPane.showMessageDialog(null,"The Installment Payment should be Greater than or equal to 500");
creditpay = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the Amount that Customer want to Pay"));
}
int totalbal = dbalamt - creditpay;
PreparedStatement prp = con.prepareStatement("update newcustomer_details set pdate=?,paidamt=?,balamt=? where cid=?");
prp.setString(1,date1);
prp.setInt(2, creditpay);
prp.setInt(3, totalbal);
prp.setInt(4, dcid);
prp.executeUpdate();
JOptionPane.showMessageDialog(null, dcname + " Remaining Balance Amount is: " + totalbal);
int reply = JOptionPane.showConfirmDialog(null, "Do you want to print the Bill");
if (reply == JOptionPane.YES_OPTION)
{
PrintPreview pp=new PrintPreview();
pp.jLabel3.setText(Integer.toString(bid));
pp.jLabel5.setText(date1);
pp.jLabel7.setText(dcname);
pp.jLabel10.setText("Amount Paid:");
pp.jLabel11.setText(Integer.toString(creditpay));
pp.jLabel12.setText("Remaining Balance:");
pp.jLabel13.setText(Integer.toString(totalbal));
pp.jTextArea1.setText(dmob_purchase);
pp.flag=1;
}
else if (reply == JOptionPane.NO_OPTION)
{
}
else if (reply == JOptionPane.CANCEL_OPTION)
{
}
g = 1;
}
}
while (res.next());
if (g == 0)
{
JOptionPane.showMessageDialog(null, "The Customer Id does not exists");
}
}
con.commit();
con.close();
}
catch(NumberFormatException e)
{
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "The error is : " + e);
}
}
private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int countsales=0,totalamt=0;
try
{
String date = JOptionPane.showInputDialog(null, "Enter Date on which you want the Reports (EX:01-jan-2000)");
while(date.equalsIgnoreCase(""))
{
JOptionPane.showMessageDialog(null,"Please enter date");
date = JOptionPane.showInputDialog(null, "Enter Date on which you want the Reports (EX:01-jan-2000)");
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mobileDSN", "scott", "tiger");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from newbill where bdate='" + date + "'");
Boolean rec = res.next();
if (rec == false)
{
JOptionPane.showMessageDialog(null, "There are no sales on the given date");
}
else
{
SalesReports sr=new SalesReports();
sr.jLabel2.setVisible(false);
sr.jLabel3.setVisible(false);
sr.jComboBox1.setVisible(false);
sr.jComboBox2.setVisible(false);
sr.jButton3.setVisible(false);
sr.jScrollPane1.setBounds(60, 70, 910, 510);
sr.jTextArea1.setText("");
text="";
sr.jLabel1.setText("Daily Reports");
do
{
String dbid = res.getString(1);
java.sql.Date dbdate = res.getDate(2);
String bdate = dbdate.toString();
String dcname = res.getString(3);
int dprice = res.getInt(4);
int damtpaid = res.getInt(5);
String mob_purchased = res.getString(7);
countsales++;
totalamt+=damtpaid;
text+="\n"+dbid+" \t"+bdate+" \t"+dcname+" \t\t"+dprice+" \t"+damtpaid+" \t"+mob_purchased+" \n";
sr.jTextArea1.setText("Bill Id \tBill Date \tCustomerName \t\tTotalPrice \tAmountPaid \tMobiles Purchased \n"+
"-----------------------------------------------------------------------------------------------------" +
"-----------------------------------------------------------------------------"+text+"\n--------------------------------------------------------------------------------------------"+
"-----------------------------------------------------------------------------\n\n\t\t Total No. Of Sales: "+countsales+"\tTotal Amount Collected: "+totalamt);
} while(res.next());
}
}
catch(NullPointerException e)
{
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"INVALID DATE!, please follow the Example");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "The error is:" + e);
}
}
private void jMenuItem14ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
SalesReports sr=new SalesReports();
sr.jLabel1.setText("Monthly Reports");
sr.flag=0;
}
private void jMenuItem15ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
SalesReports sr=new SalesReports();
sr.jLabel1.setText("Yearly Reports");
sr.jLabel2.setVisible(false);
sr.jComboBox1.setVisible(false);
sr.flag=1;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Home().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem10;
private javax.swing.JMenuItem jMenuItem11;
private javax.swing.JMenuItem jMenuItem12;
private javax.swing.JMenuItem jMenuItem13;
private javax.swing.JMenuItem jMenuItem14;
private javax.swing.JMenuItem jMenuItem15;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JMenuItem jMenuItem6;
private javax.swing.JMenuItem jMenuItem7;
private javax.swing.JMenuItem jMenuItem8;
private javax.swing.JMenuItem jMenuItem9;
// End of variables declaration
}
Code for Addmobile Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Addmobile1.java
*
* Created on Sep 11, 2010, 10:53:35 PM
*/
package mobilestorenew;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Date;
/**
*
* @author Ramesh
*/
public class Addmobile1 extends javax.swing.JFrame {
/** Creates new form Addmobile1 */
String model,name,pcolor,date1,cbox="";
int price,no,s1,s3,index,inc,inc1;
String s2,imeino,mid,dpname,dpid,pname;
int a=0,z=0,b=0,d=0;
int count=0;int prevalue=0,curvalue;
public Addmobile1()
{
initComponents();
setVisible(true);
setSize(1270,740);
setTitle("Add Mobile Phone Details");
jTextField5.setEditable(false);
jTextField6.setEditable(false);
jComboBox2.setEnabled(false);
jComboBox3.setEnabled(false);
jComboBox4.setEnabled(false);
jComboBox5.setEnabled(false);
jCheckBox1.setEnabled(false);
jCheckBox2.setEnabled(false);
jCheckBox3.setEnabled(false);
jCheckBox4.setEnabled(false);
jCheckBox5.setEnabled(false);
jCheckBox6.setEnabled(false);
jButton4.setEnabled(false);
jButton3.setEnabled(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel18 = new javax.swing.JLabel();
jLabel19 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jLabel21 = new javax.swing.JLabel();
jLabel22 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jButton4 = new javax.swing.JButton();
jLabel12 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jCheckBox1 = new javax.swing.JCheckBox();
jCheckBox2 = new javax.swing.JCheckBox();
jCheckBox3 = new javax.swing.JCheckBox();
jCheckBox4 = new javax.swing.JCheckBox();
jCheckBox5 = new javax.swing.JCheckBox();
jCheckBox6 = new javax.swing.JCheckBox();
jButton3 = new javax.swing.JButton();
jComboBox3 = new javax.swing.JComboBox();
jComboBox4 = new javax.swing.JComboBox();
jComboBox5 = new javax.swing.JComboBox();
jLabel5 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
jLabel1.setText("Add Mobile Phone Details");
getContentPane().add(jLabel1);
jLabel1.setBounds(350, 0, 303, 40);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel1.setEnabled(false);
jPanel1.setLayout(null);
jLabel18.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel18.setText("Mobile Phone Id");
jPanel1.add(jLabel18);
jLabel18.setBounds(50, 20, 130, 30);
jLabel19.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel19.setText("Mobile Phone Color");
jPanel1.add(jLabel19);
jLabel19.setBounds(50, 70, 190, 30);
jLabel20.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel20.setText("Enter IMEI Number");
jPanel1.add(jLabel20);
jLabel20.setBounds(50, 120, 160, 30);
jLabel21.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel21.setText("Enter Date Of Manufacture");
jPanel1.add(jLabel21);
jLabel21.setBounds(50, 170, 190, 30);
jLabel22.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel22.setText("Additional Accessories");
jPanel1.add(jLabel22);
jLabel22.setBounds(50, 230, 170, 30);
jTextField5.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField5);
jTextField5.setBounds(250, 20, 140, 30);
jTextField6.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField6.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField6FocusLost(evt);
}
});
jPanel1.add(jTextField6);
jTextField6.setBounds(250, 120, 140, 30);
jButton4.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton4.setText(" SAVE PHONE DETAILS");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jPanel1.add(jButton4);
jButton4.setBounds(90, 330, 240, 50);
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
jPanel1.add(jLabel12);
jLabel12.setBounds(410, 120, 100, 30);
jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12));
jPanel1.add(jLabel11);
jLabel11.setBounds(410, 20, 100, 30);
jComboBox2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Red", "Green", "Blue", "Black", "White", "Cyan", "Yellow", "Orange", "Purple", "Pink", "Voilet", "Magenta" }));
jPanel1.add(jComboBox2);
jComboBox2.setBounds(250, 70, 140, 30);
jCheckBox1.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox1.setText("Charger ");
jPanel1.add(jCheckBox1);
jCheckBox1.setBounds(250, 240, 80, 23);
jCheckBox2.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox2.setText("HeadSet ");
jPanel1.add(jCheckBox2);
jCheckBox2.setBounds(360, 240, 80, 23);
jCheckBox3.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox3.setText("DataCable ");
jPanel1.add(jCheckBox3);
jCheckBox3.setBounds(460, 240, 100, 23);
jCheckBox4.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox4.setText("Battery ");
jPanel1.add(jCheckBox4);
jCheckBox4.setBounds(250, 280, 80, 23);
jCheckBox5.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox5.setText("MemoryCard ");
jPanel1.add(jCheckBox5);
jCheckBox5.setBounds(360, 280, 101, 23);
jCheckBox6.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox6.setText("CD ");
jPanel1.add(jCheckBox6);
jCheckBox6.setBounds(470, 280, 50, 23);
jButton3.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton3.setText("CANCEL");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel1.add(jButton3);
jButton3.setBounds(370, 330, 110, 50);
jComboBox3.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
jPanel1.add(jComboBox3);
jComboBox3.setBounds(250, 180, 50, 30);
jComboBox4.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" }));
jPanel1.add(jComboBox4);
jComboBox4.setBounds(330, 180, 56, 30);
jComboBox5.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
jComboBox5.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jComboBox5FocusLost(evt);
}
});
jPanel1.add(jComboBox5);
jComboBox5.setBounds(426, 180, 60, 30);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel5.setText("(DD)");
jPanel1.add(jLabel5);
jLabel5.setBounds(300, 180, 30, 30);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel7.setText("(MM)");
jPanel1.add(jLabel7);
jLabel7.setBounds(390, 180, 32, 30);
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel13.setText("(YY)");
jPanel1.add(jLabel13);
jLabel13.setBounds(490, 180, 30, 30);
getContentPane().add(jPanel1);
jPanel1.setBounds(200, 290, 570, 400);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel2.setLayout(null);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel2.setText("Price");
jPanel2.add(jLabel2);
jLabel2.setBounds(50, 120, 90, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel3.setText("No. of Mobile Phones");
jPanel2.add(jLabel3);
jLabel3.setBounds(50, 170, 150, 30);
jComboBox1.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nokia", "Samsung", "Sony Ericson", "Lava", "Onida", "MaxMobile", "LG" }));
jPanel2.add(jComboBox1);
jComboBox1.setBounds(250, 20, 140, 30);
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel4.setText("Mobile Phone Model");
jPanel2.add(jLabel4);
jLabel4.setBounds(50, 20, 150, 30);
jTextField2.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField2FocusLost(evt);
}
});
jPanel2.add(jTextField2);
jTextField2.setBounds(250, 70, 140, 30);
jTextField3.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField3.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField3FocusLost(evt);
}
});
jPanel2.add(jTextField3);
jTextField3.setBounds(250, 120, 140, 30);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel6.setText("Enter Mobile Name");
jPanel2.add(jLabel6);
jLabel6.setBounds(50, 70, 160, 30);
jTextField4.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField4FocusLost(evt);
}
});
jPanel2.add(jTextField4);
jTextField4.setBounds(250, 170, 140, 30);
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
jPanel2.add(jLabel8);
jLabel8.setBounds(410, 70, 100, 30);
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
jPanel2.add(jLabel9);
jLabel9.setBounds(410, 120, 100, 30);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
jPanel2.add(jLabel10);
jLabel10.setBounds(410, 170, 100, 30);
getContentPane().add(jPanel2);
jPanel2.setBounds(200, 60, 570, 220);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 14));
jButton1.setText("Enter each Phone Details");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(780, 130, 210, 60);
pack();
}// </editor-fold>
private void jTextField2FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField2.getText().equals(""))
{
jLabel8.setText("Entry Is Must");
jTextField2.setText("");
}
else
{
jLabel8.setText("");
try
{
name=jTextField2.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
}
else
{
do
{
String nm=res.getString(3);
if(name.equals(nm))
{
jTextField3.setText(Integer.toString(res.getInt(4)));
}
}while(res.next());
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is :"+e);
}
}
}
private void jTextField3FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField3.getText().equals(""))
{
jLabel9.setText("Entry Is Must") ;
jTextField3.setText("");
}
else
{
String jtf1=jTextField3.getText();
int fg=0;
for(int i=0;i<jtf1.length();i++)
{
char c=jtf1.charAt(i);
if(Character.isLetter(c))
{
fg=0;
break;
}
else
{
fg=1;
}
}
if(fg==0)
{
jLabel9.setText("Enter Numbers") ;
jTextField3.setText("");
}
else
jLabel9.setText("") ;
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jTextField2.getText().equals("") || jTextField3.getText().equals("") || jTextField4.getText().equals("")) {
JOptionPane.showMessageDialog(null,"Enter all appropriate fields");
if(jTextField2.getText().equals("")) {
jLabel8.setText("Fill this field");
} else {
jLabel8.setText("");
}
if(jTextField3.getText().equals("")) {
jLabel9.setText("Fill this field");
} else {
jLabel9.setText("");
}
if(jTextField4.getText().equals("")) {
jLabel10.setText("Fill this field");
} else {
jLabel10.setText("");
}
}
else
{
no=Integer.parseInt(jTextField4.getText());
if(count<no)
{
jComboBox1.setEnabled(false);
jTextField2.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jButton1.setEnabled(false);
JOptionPane.showMessageDialog(null,"Enter First Mobile Phone Details");
jTextField6.setEditable(true);
jComboBox2.setEnabled(true);
jComboBox3.setEnabled(true);
jComboBox4.setEnabled(true);
jComboBox5.setEnabled(true);
jCheckBox1.setEnabled(true);
jCheckBox2.setEnabled(true);
jCheckBox3.setEnabled(true);
jCheckBox4.setEnabled(true);
jCheckBox5.setEnabled(true);
jCheckBox6.setEnabled(true);
jButton4.setEnabled(true);
jButton3.setEnabled(true);
}
else
{
JOptionPane.showMessageDialog(null,"enter No. of Mobiles as 1 or more");
jTextField4.setText("");
}
//extra requirement code
try
{
pname=jTextField2.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
mid=jTextField2.getText();
mid+="-";
mid+="1";
jTextField5.setText(mid);
}
else
{
do
{
dpid=res.getString(1);
dpname=res.getString(3);
if(pname.equalsIgnoreCase(dpname))
{
System.out.println(dpid);
index=dpid.indexOf("-");
System.out.println(index);
curvalue=Integer.parseInt(dpid.substring(index+1));
if(prevalue<curvalue)
{
inc=curvalue+1;
prevalue=curvalue;
}
mid=jTextField2.getText();
mid+="-";
mid+=Integer.toString(inc);
jTextField5.setText(mid);
b=1;
}
}while(res.next());
if(b==0)
{
mid=jTextField2.getText();
mid+="-";
mid+="1";
jTextField5.setText(mid);
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
//extra requirement code ends here
}
}
private void jTextField4FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField4.getText().equals(""))
{
jLabel10.setText("Entry Is Must") ;
jTextField4.setText("");
}
else
{
String jtf1=jTextField4.getText();
int fg=0;
for(int i=0;i<jtf1.length();i++)
{
char c=jtf1.charAt(i);
if(Character.isLetter(c))
{
fg=0;
break;
}
else
{
fg=1;
}
}
if(fg==0)
{
jLabel10.setText("Enter Numbers") ;
jTextField4.setText("");
}
else
jLabel10.setText("") ;
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jTextField5.getText().equals("") || jTextField6.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Enter all appropriate fields");
if(jTextField5.getText().equals(""))
{
jLabel11.setText("Fill this field");
}
else
{
jLabel11.setText("");
}
if(jTextField6.getText().equals(""))
{
jLabel12.setText("Fill this field");
}
else
{
jLabel12.setText("");
}
}
else
{
name=jTextField2.getText();
model=(String)jComboBox1.getSelectedItem();
price=Integer.parseInt(jTextField3.getText());
pcolor=(String)jComboBox2.getSelectedItem();
imeino=jTextField6.getText();
date1=(String)jComboBox3.getSelectedItem();
date1+="-";
date1+=(String)jComboBox4.getSelectedItem();
date1+="-";
date1+=(String)jComboBox5.getSelectedItem();
cbox="";
Boolean temp=(Boolean)jCheckBox1.isSelected();
if(temp==true)
{
cbox+=(String)jCheckBox1.getText();
}
Boolean temp1=(Boolean)jCheckBox2.isSelected();
if(temp1==true)
{
cbox+=(String)jCheckBox2.getText();
}
Boolean temp2=(Boolean)jCheckBox3.isSelected();
if(temp2==true)
{
cbox+=(String)jCheckBox3.getText();
}
Boolean temp3=(Boolean)jCheckBox4.isSelected();
if(temp3==true)
{
cbox+=(String)jCheckBox4.getText();
}
Boolean temp4=(Boolean)jCheckBox5.isSelected();
if(temp4==true)
{
cbox+=(String)jCheckBox5.getText();
}
Boolean temp5=(Boolean)jCheckBox6.isSelected();
if(temp5==true)
{
cbox+=(String)jCheckBox6.getText();
}
System.out.println(cbox);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
System.out.println("connected successfully");
if(count<no)
{
PreparedStatement prp=con.prepareStatement("insert into newmobile_details values(?,?,?,?,?,?,?,?)");
prp.setString(1,mid);
prp.setString(2,model);
prp.setString(3,name);
prp.setInt(4,price);
prp.setString(5,pcolor);
prp.setString(6,imeino);
prp.setString(7,date1);
prp.setString(8,cbox);
prp.executeUpdate();
JOptionPane.showMessageDialog(null,"Mobiele Phone details saved successfully");
jTextField6.setText("");
jComboBox2.setSelectedItem("Red");
jComboBox3.setSelectedItem("01");
jComboBox4.setSelectedItem("jan");
jComboBox5.setSelectedItem("2000");
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
jCheckBox3.setSelected(false);
jCheckBox4.setSelected(false);
jCheckBox5.setSelected(false);
jCheckBox6.setSelected(false);
cbox="";
con.commit();
con.close();
count++;
//extra requirement code starts from here
index=jTextField5.getText().indexOf("-");
System.out.println(index);
inc1=Integer.parseInt(jTextField5.getText().substring(index+1));
inc1++;
System.out.print(inc1);
mid=jTextField2.getText();
mid+="-";
mid+=Integer.toString(inc1);
jTextField5.setText(mid);
//ends here
if(count<no)
{
JOptionPane.showMessageDialog(null,"Enter Next Mobile Phone Details");
}
if(count>=no)
{
count=0;
jComboBox1.setEnabled(true);
jTextField2.setEditable(true);
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jButton1.setEnabled(true);
jTextField6.setEditable(false);
jComboBox2.setEnabled(false);
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
jCheckBox3.setSelected(false);
jCheckBox4.setSelected(false);
jCheckBox5.setSelected(false);
jCheckBox6.setSelected(false);
jComboBox1.setSelectedItem("Nokia");
jComboBox2.setSelectedItem("Red");
jComboBox3.setSelectedItem("1");
jComboBox4.setSelectedItem("jan");
jComboBox5.setSelectedItem("2000");
jComboBox2.setEnabled(false);
jComboBox3.setEnabled(false);
jComboBox4.setEnabled(false);
jComboBox5.setEnabled(false);
jButton4.setEnabled(false);
jButton3.setEnabled(false);
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jCheckBox1.setEnabled(false);
jCheckBox2.setEnabled(false);
jCheckBox3.setEnabled(false);
jCheckBox4.setEnabled(false);
jCheckBox5.setEnabled(false);
jCheckBox6.setEnabled(false);
}
}
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"INVALID DATE, please select correct date");
jComboBox3.setSelectedItem("01");
jComboBox4.setSelectedItem("jan");
jComboBox5.setSelectedItem("2000");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is1:"+e);
System.out.println(e.getMessage());
}
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
count=0;
jComboBox1.setSelectedItem("Nokia");
jComboBox1.setEnabled(true);
jTextField2.setEditable(true);
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jButton1.setEnabled(true);
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jComboBox2.setSelectedItem("Red");
jComboBox3.setSelectedItem("01");
jComboBox4.setSelectedItem("jan");
jComboBox5.setSelectedItem("2000");
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
jCheckBox3.setSelected(false);
jCheckBox4.setSelected(false);
jCheckBox5.setSelected(false);
jCheckBox6.setSelected(false);
jTextField6.setEditable(false);
jComboBox2.setEnabled(false);
jComboBox3.setEnabled(false);
jComboBox4.setEnabled(false);
jComboBox5.setEnabled(false);
jCheckBox1.setEnabled(false);
jCheckBox2.setEnabled(false);
jCheckBox3.setEnabled(false);
jCheckBox4.setEnabled(false);
jCheckBox5.setEnabled(false);
jCheckBox6.setEnabled(false);
jButton4.setEnabled(false);
jButton3.setEnabled(false);
}
private void jTextField6FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField6.getText().equals(""))
{
jLabel12.setText("Entry Is Must");
}
else
{
String jtf1=jTextField6.getText();
int fg=0;
for(int i=0;i<jtf1.length();i++)
{
char c=jtf1.charAt(i);
if(Character.isLetter(c))
{
fg=0;
break;
}
else
{
fg=1;
}
}
if(fg==0)
{
jLabel12.setText("Enter Numbers") ;
jTextField6.setText("");
}
else
{
jLabel12.setText("");
}
String imei=jTextField6.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
}
else
{
do
{
String dimei=res.getString(6);
if(imei.equals(dimei))
{
JOptionPane.showMessageDialog(null,"The Mobile Phone is already in the database");
jTextField6.setText("");
jLabel12.setText("");
}
}while(res.next());
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is"+e);
}
}
}
private void jComboBox5FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
String temp1=(String)jComboBox5.getSelectedItem();
int useryear=Integer.parseInt(temp1);
Date curyear=new Date();
String temp2=curyear.toString();
temp2=temp2.substring(24,28);
int cyear=Integer.parseInt(temp2);
if(useryear>cyear)
{
JOptionPane.showMessageDialog(null,"The Manufacture Date should be on (or) before this year");
jComboBox5.setSelectedItem("2000");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Addmobile1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JCheckBox jCheckBox3;
private javax.swing.JCheckBox jCheckBox4;
private javax.swing.JCheckBox jCheckBox5;
private javax.swing.JCheckBox jCheckBox6;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JComboBox jComboBox3;
private javax.swing.JComboBox jComboBox4;
private javax.swing.JComboBox jComboBox5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel19;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel21;
private javax.swing.JLabel jLabel22;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
// End of variables declaration
}
Code for SearchMobile Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SearchMobile.java
*
* Created on Nov 7, 2010, 9:35:13 PM
*/
package mobilestorenew;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Ramesh
*/
public class SearchMobile extends javax.swing.JFrame {
/** Creates new form SearchMobile */
int flag=0,rows=0,b=0,sprice,eprice;
String id,mname;
Object data[][];
JTable table;
JScrollPane jsp;
ResultSet rs;
public SearchMobile() {
initComponents();
setVisible(true);
setSize(1270,740);
setTitle("Search Mobile Phone");
ButtonGroup bg=new ButtonGroup();
bg.add(jRadioButton1);
bg.add(jRadioButton2);
bg.add(jRadioButton3);
jTextField2.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jsp.setVisible(false);
}
public void tabledisp()
{
try
{
data=new Object[rows][8];
Object[] colheads={"Mobile Phone Id","Mobile Phone Model","Mobile Phone Name","Mobile Phone Price","phone color","IMEI no","Manufacture Date","Accessories"};
Class.forName("sun.jdbc.odbc.JdbcOdbc");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
rs=st.executeQuery("select * from msearch");
for(int i=0;i<rows;i++)
{
rs.next();
for(int j=0;j<8;j++)
{
data [i][j]=rs.getString(j+1);
System.out.println(data[i][j]);
}
}
table=new JTable(data,colheads);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
jsp=new JScrollPane(table,v,h);
jsp.setBounds(70,420,900,200);
jPanel2.add(jsp);
add(jsp);
System.out.println("hai we came here");
rows=0;
st.close();
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"here the error is:"+e);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search Results", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
jPanel2.setLayout(null);
getContentPane().add(jPanel2);
jPanel2.setBounds(50, 380, 940, 260);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel1.setLayout(null);
jTextField1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField1FocusGained(evt);
}
});
jPanel1.add(jTextField1);
jTextField1.setBounds(290, 40, 150, 30);
jRadioButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jRadioButton1.setSelected(true);
jRadioButton1.setText(" Search By Mobile ID or IMEI No.");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jPanel1.add(jRadioButton1);
jRadioButton1.setBounds(20, 40, 260, 25);
jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jRadioButton2.setText(" Search By Mobile Name");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jPanel1.add(jRadioButton2);
jRadioButton2.setBounds(20, 100, 200, 25);
jRadioButton3.setFont(new java.awt.Font("Tahoma", 1, 14));
jRadioButton3.setText("Search By Mobile Price");
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton3ActionPerformed(evt);
}
});
jPanel1.add(jRadioButton3);
jRadioButton3.setBounds(20, 160, 190, 25);
jTextField2.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField2FocusGained(evt);
}
});
jPanel1.add(jTextField2);
jTextField2.setBounds(290, 100, 150, 30);
jTextField3.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField3.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField3FocusGained(evt);
}
});
jPanel1.add(jTextField3);
jTextField3.setBounds(290, 160, 150, 30);
jTextField4.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField4FocusGained(evt);
}
});
jPanel1.add(jTextField4);
jTextField4.setBounds(480, 160, 130, 30);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel2.setText("to");
jPanel1.add(jLabel2);
jLabel2.setBounds(450, 160, 20, 30);
jPanel1.add(jLabel3);
jLabel3.setBounds(460, 40, 120, 30);
jPanel1.add(jLabel4);
jLabel4.setBounds(460, 100, 120, 30);
getContentPane().add(jPanel1);
jPanel1.setBounds(50, 100, 640, 250);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton1.setText("Search");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(720, 200, 120, 50);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(870, 200, 110, 50);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
jLabel1.setText("Search Mobile Phone Details");
getContentPane().add(jLabel1);
jLabel1.setBounds(320, 20, 350, 50);
pack();
}// </editor-fold>
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField2.setEditable(true);
jTextField1.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jTextField1.setText("");
jTextField3.setText("");
jTextField4.setText("");
flag=1;
jsp.setVisible(false);
}
private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jTextField1.setEditable(false);
jTextField2.setEditable(false);
jTextField4.setText("");
jTextField1.setText("");
jTextField2.setText("");
flag=2;
jsp.setVisible(false);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(flag==0)
{
if(jTextField1.getText().equals(""))
{
jLabel3.setText("Entry is Must");
}
else
{
id=jTextField1.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbc");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
st.executeUpdate("delete msearch");
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
JOptionPane.showMessageDialog(null,"There are no records");
}
else
{
do
{
String mid=res.getString(1);
String model=res.getString(2);
String name=res.getString(3);
int price=res.getInt(4);
String pcolor=res.getString(5);
String imei=res.getString(6);
java.sql.Date date=res.getDate(7);
String access=res.getString(8);
if(id.equals(mid) || id.equals(imei))
{
System.out.println("iam inside");
PreparedStatement prp=con.prepareStatement("insert into msearch values(?,?,?,?,?,?,?,?)");
prp.setString(1,mid);
prp.setString(2,model);
prp.setString(3,name);
prp.setInt(4,price);
prp.setString(5,pcolor);
prp.setString(6,imei);
prp.setDate(7,date);
prp.setString(8,access);
prp.executeUpdate();
System.out.println("iam inside2");
rows++;
b=1;
jTextField1.setText("");
}
}while(res.next());
if(b==0)
{
JOptionPane.showMessageDialog(null,"The mobile phone does not exists ");
jTextField1.setText("");
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is1:" +e);
}
tabledisp();
}
}
else if(flag==1)
{
if(jTextField2.getText().equals(""))
{
jLabel4.setText("Entry is Must");
}
else
{
mname=jTextField2.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbc");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
st.executeUpdate("delete msearch");
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
JOptionPane.showMessageDialog(null,"There are no records");
}
else
{
do
{
String mid=res.getString(1);
String model=res.getString(2);
String name=res.getString(3);
int price=res.getInt(4);
String pcolor=res.getString(5);
String imei=res.getString(6);
java.sql.Date date=res.getDate(7);
String access=res.getString(8);
if(mname.equalsIgnoreCase(name))
{
PreparedStatement prp=con.prepareStatement("insert into msearch values(?,?,?,?,?,?,?,?)");
prp.setString(1,mid);
prp.setString(2,model);
prp.setString(3,name);
prp.setInt(4,price);
prp.setString(5,pcolor);
prp.setString(6,imei);
prp.setDate(7,date);
prp.setString(8,access);
prp.executeUpdate();
System.out.println("iam inside2");
rows++;
b=1;
jTextField2.setText("");
}
}while(res.next());
if(b==0)
{
JOptionPane.showMessageDialog(null,"The mobile does not exists ");
jTextField2.setText("");
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is1:" +e);
}
tabledisp();
}
}
else if(flag==2)
{
if(jTextField3.getText().equals("") || jTextField4.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Fill the both fields");
}
else if(Integer.parseInt(jTextField3.getText())>Integer.parseInt(jTextField4.getText()))
{
JOptionPane.showMessageDialog(null,"First Enter small price and then Enter Big Price");
jTextField3.setText("");
jTextField4.setText("");
}
else
{
sprice=Integer.parseInt(jTextField3.getText());
eprice=Integer.parseInt(jTextField4.getText());
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbc");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
st.executeUpdate("delete msearch");
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
JOptionPane.showMessageDialog(null,"There are no records");
}
else
{
do
{
String mid=res.getString(1);
String model=res.getString(2);
String name=res.getString(3);
int price=res.getInt(4);
String pcolor=res.getString(5);
String imei=res.getString(6);
java.sql.Date date=res.getDate(7);
String access=res.getString(8);
System.out.append("iam stuck here");
for(int i=sprice;i<=eprice;i++)
{
if(i==price)
{
PreparedStatement prp=con.prepareStatement("insert into msearch values(?,?,?,?,?,?,?,?)");
prp.setString(1,mid);
prp.setString(2,model);
prp.setString(3,name);
prp.setInt(4,price);
prp.setString(5,pcolor);
prp.setString(6,imei);
prp.setDate(7,date);
prp.setString(8,access);
prp.executeUpdate();
System.out.println("iam inside2");
rows++;
b=1;
jTextField3.setText("");
jTextField4.setText("");
}
}
}while(res.next());
if(b==0)
{
JOptionPane.showMessageDialog(null,"There are no mobiles between the price you entered");
jTextField3.setText("");
jTextField4.setText("");
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
tabledisp();
}
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
}
private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
jsp.setVisible(false);
b=0;
}
private void jTextField2FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
jsp.setVisible(false);
b=0;
}
private void jTextField3FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
jsp.setVisible(false);
b=0;
}
private void jTextField4FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
jsp.setVisible(false);
b=0;
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
flag=0;
jTextField1.setEditable(true);
jTextField2.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jTextField2.setText("");
jTextField2.setText("");
jTextField2.setText("");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SearchMobile().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration
}
Code for UpdateMobile Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MobileUpdate.java
*
* Created on Sep 12, 2010, 11:49:21 PM
*/
package mobilestorenew;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author Ramesh
*/
public class MobileUpdate extends javax.swing.JFrame {
/** Creates new form MobileUpdate */
String model,name,cbox;
int price,i1;
String id,s1,s2,s3,s4,s5,pcolor,date;
int a=0;
int b=0;
String imeino;
String dt,year,ddate,mc,month;
public MobileUpdate() {
initComponents();
setVisible(true);
setSize(1270,740);
setTitle("Update Mobile Details");
disflds();
JOptionPane.showMessageDialog(null,"Enter Phone Id (or) IMEI No. in the First Text Field");
}
public void disflds()
{
jComboBox1.setEnabled(false);
jComboBox2.setEnabled(false);
jComboBox3.setEnabled(false);
jComboBox4.setEnabled(false);
jComboBox5.setEnabled(false);
jTextField2.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jCheckBox1.setEnabled(false);
jCheckBox2.setEnabled(false);
jCheckBox3.setEnabled(false);
jCheckBox4.setEnabled(false);
jCheckBox5.setEnabled(false);
jCheckBox6.setEnabled(false);
jButton1.setEnabled(false);
}
public void clrcombocheck()
{
jComboBox1.setSelectedItem("Nokia");
jComboBox2.setSelectedItem("Red");
jComboBox3.setSelectedItem("01");
jComboBox4.setSelectedItem("jan");
jComboBox5.setSelectedItem("2000");
jCheckBox1.setSelected(false);
jCheckBox2.setSelected(false);
jCheckBox3.setSelected(false);
jCheckBox4.setSelected(false);
jCheckBox5.setSelected(false);
jCheckBox6.setSelected(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jCheckBox1 = new javax.swing.JCheckBox();
jCheckBox2 = new javax.swing.JCheckBox();
jCheckBox3 = new javax.swing.JCheckBox();
jCheckBox4 = new javax.swing.JCheckBox();
jCheckBox5 = new javax.swing.JCheckBox();
jCheckBox6 = new javax.swing.JCheckBox();
jLabel10 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jComboBox3 = new javax.swing.JComboBox();
jComboBox4 = new javax.swing.JComboBox();
jComboBox5 = new javax.swing.JComboBox();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
jLabel1.setText("Update Mobile Phone Details");
getContentPane().add(jLabel1);
jLabel1.setBounds(370, 20, 343, 50);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Update Mobile Details"));
jPanel1.setLayout(null);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel2.setText("Mobile Phone Price");
jPanel1.add(jLabel2);
jLabel2.setBounds(100, 210, 160, 30);
jTextField1.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField1FocusLost(evt);
}
});
jPanel1.add(jTextField1);
jTextField1.setBounds(290, 40, 140, 30);
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel4.setText("Mobile Phone Model");
jPanel1.add(jLabel4);
jLabel4.setBounds(100, 100, 150, 30);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel5.setText("Enter Phone Id (or) IMEI No.");
jPanel1.add(jLabel5);
jLabel5.setBounds(60, 40, 210, 30);
jTextField2.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jTextField2KeyTyped(evt);
}
});
jPanel1.add(jTextField2);
jTextField2.setBounds(290, 160, 140, 30);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel6.setText("Mobile Phone Name");
jPanel1.add(jLabel6);
jLabel6.setBounds(100, 150, 160, 30);
jTextField3.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jTextField3KeyTyped(evt);
}
});
jPanel1.add(jTextField3);
jTextField3.setBounds(290, 220, 140, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel3.setText("Mobile Phone Color");
jPanel1.add(jLabel3);
jLabel3.setBounds(100, 280, 140, 30);
jTextField4.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jTextField4KeyTyped(evt);
}
});
jPanel1.add(jTextField4);
jTextField4.setBounds(290, 340, 140, 30);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel7.setText("IMEI No");
jPanel1.add(jLabel7);
jLabel7.setBounds(100, 340, 100, 30);
jComboBox2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Red", "Green", "Blue", "Black", "White", "Cyan", "Yellow", "Orange", "Purple", "Pink", "Voilet", "Magenta" }));
jComboBox2.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox2ItemStateChanged(evt);
}
});
jPanel1.add(jComboBox2);
jComboBox2.setBounds(290, 280, 140, 30);
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel8.setText("Date of Manufacture");
jPanel1.add(jLabel8);
jLabel8.setBounds(100, 390, 150, 30);
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel9.setText("Additional Accessories");
jPanel1.add(jLabel9);
jLabel9.setBounds(100, 440, 170, 20);
jCheckBox1.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox1.setText("Charger ");
jCheckBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jCheckBox1ItemStateChanged(evt);
}
});
jPanel1.add(jCheckBox1);
jCheckBox1.setBounds(290, 440, 80, 23);
jCheckBox2.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox2.setText("HeadSet ");
jCheckBox2.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jCheckBox2ItemStateChanged(evt);
}
});
jPanel1.add(jCheckBox2);
jCheckBox2.setBounds(400, 440, 80, 23);
jCheckBox3.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox3.setText("DataCable ");
jCheckBox3.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jCheckBox3ItemStateChanged(evt);
}
});
jPanel1.add(jCheckBox3);
jCheckBox3.setBounds(290, 470, 100, 23);
jCheckBox4.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox4.setText("Battery ");
jCheckBox4.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jCheckBox4ItemStateChanged(evt);
}
});
jPanel1.add(jCheckBox4);
jCheckBox4.setBounds(400, 470, 80, 23);
jCheckBox5.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox5.setText("MemoryCard ");
jCheckBox5.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jCheckBox5ItemStateChanged(evt);
}
});
jPanel1.add(jCheckBox5);
jCheckBox5.setBounds(290, 500, 101, 23);
jCheckBox6.setFont(new java.awt.Font("Tahoma", 1, 11));
jCheckBox6.setText("CD ");
jCheckBox6.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jCheckBox6ItemStateChanged(evt);
}
});
jPanel1.add(jCheckBox6);
jCheckBox6.setBounds(400, 500, 50, 23);
jPanel1.add(jLabel10);
jLabel10.setBounds(440, 40, 120, 30);
jComboBox1.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nokia", "Samsung", "Sony Ericson", "Lava", "Onida", "MaxMobile", "LG" }));
jComboBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox1ItemStateChanged(evt);
}
});
jPanel1.add(jComboBox1);
jComboBox1.setBounds(290, 100, 140, 30);
jComboBox3.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
jComboBox3.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox3ItemStateChanged(evt);
}
});
jPanel1.add(jComboBox3);
jComboBox3.setBounds(290, 390, 50, 30);
jComboBox4.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" }));
jComboBox4.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox4ItemStateChanged(evt);
}
});
jPanel1.add(jComboBox4);
jComboBox4.setBounds(380, 390, 56, 30);
jComboBox5.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
jComboBox5.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox5ItemStateChanged(evt);
}
});
jPanel1.add(jComboBox5);
jComboBox5.setBounds(490, 390, 60, 30);
jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel11.setText("(DD)");
jPanel1.add(jLabel11);
jLabel11.setBounds(340, 390, 28, 30);
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel12.setText("(MM)");
jPanel1.add(jLabel12);
jLabel12.setBounds(440, 390, 40, 30);
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel13.setText("(YY)");
jPanel1.add(jLabel13);
jLabel13.setBounds(550, 390, 24, 30);
getContentPane().add(jPanel1);
jPanel1.setBounds(210, 70, 590, 530);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel2.setLayout(null);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel2.add(jButton2);
jButton2.setBounds(280, 20, 110, 40);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton1.setText("Update Mobile Details");
jButton1.setEnabled(false);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton1);
jButton1.setBounds(30, 20, 240, 40);
getContentPane().add(jPanel2);
jPanel2.setBounds(320, 610, 410, 80);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
id=jTextField1.getText();
model=(String)jComboBox1.getSelectedItem();
name=jTextField2.getText();
price=Integer.parseInt(jTextField3.getText());
pcolor=(String)jComboBox2.getSelectedItem();
imeino=jTextField4.getText();
date=(String)jComboBox3.getSelectedItem();
date+="-";
date+=(String)jComboBox4.getSelectedItem();
date+="-";
date+=(String)jComboBox5.getSelectedItem();
cbox=null;
Boolean temp=(Boolean)jCheckBox1.isSelected();
if(temp==true)
{
cbox+=(String)jCheckBox1.getText();
}
Boolean temp1=(Boolean)jCheckBox2.isSelected();
if(temp1==true)
{
cbox+=(String)jCheckBox2.getText();
}
Boolean temp2=(Boolean)jCheckBox3.isSelected();
if(temp2==true)
{
cbox+=(String)jCheckBox3.getText();
}
Boolean temp3=(Boolean)jCheckBox4.isSelected();
if(temp3==true)
{
cbox+=(String)jCheckBox4.getText();
}
Boolean temp4=(Boolean)jCheckBox5.isSelected();
if(temp4==true)
{
cbox+=(String)jCheckBox5.getText();
}
Boolean temp5=(Boolean)jCheckBox6.isSelected();
if(temp5==true)
{
cbox+=(String)jCheckBox6.getText();
}
cbox=cbox.substring(4);
try
{
Connection con;
Statement st;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
st=con.createStatement();
PreparedStatement prp=con.prepareStatement("update newmobile_details set mobile_model=?,mobile_name=?,mobile_price=?,pcolor=?,imeino=?,mdate=?,accessories=? where phone_id=?");
prp.setString(1,model);
prp.setString(2,name);
prp.setInt(3,price);
prp.setString(4,pcolor);
prp.setString(5,imeino);
prp.setString(6,date);
prp.setString(7,cbox);
prp.setString(8,id);
prp.executeUpdate();
JOptionPane.showMessageDialog(null,"Mobile Phone details updated successfully");
jTextField1.setText("");
jTextField2.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
cbox=null;
jTextField1.setEditable(true);
disflds();
clrcombocheck();
jButton1.setEnabled(false);
con.commit();
con.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(null,"error is:"+e);
}
}
private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField1.getText().equals(""))
{
jLabel10.setText("Entry is Must");
}
else
{
id=jTextField1.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
JOptionPane.showMessageDialog(null,"There are no mobiles in the database");
jTextField1.setText("");
}
else
{
do
{
s1=res.getString(1);
s2=res.getString(2);
s3=res.getString(3);
i1=res.getInt(4);
s4=res.getString(5);
s5=res.getString(6);
if(id.equalsIgnoreCase(s1) || id.equalsIgnoreCase(s5))
{
jTextField1.setEditable(false);
jTextField2.setEditable(true);
jTextField2.setEditable(true);
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jComboBox1.setEnabled(true);
jComboBox2.setEnabled(true);
jComboBox3.setEnabled(true);
jComboBox4.setEnabled(true);
jComboBox5.setEnabled(true);
jCheckBox1.setEnabled(true);
jCheckBox2.setEnabled(true);
jCheckBox3.setEnabled(true);
jCheckBox4.setEnabled(true);
jCheckBox5.setEnabled(true);
jCheckBox6.setEnabled(true);
jComboBox2.setEnabled(true);
jLabel5.setText(" Mobile Phone Id");
jLabel10.setText("");
b=1;
jTextField1.setText(s1);
jComboBox1.setSelectedItem(s2);
jTextField2.setText(s3);
jTextField3.setText(Integer.toString(i1));
jComboBox2.setSelectedItem(s4);
jTextField4.setText(s5);
dt=res.getDate(7).toString();
System.out.println(dt);
year=dt.substring(0,4);
System.out.println(year);
month=dt.substring(5,7);
System.out.println(month);
ddate=dt.substring(8,10);
System.out.println(ddate);
if(month.equals("01"))
{
mc="jan";
}
else if(month.equals("02"))
{
mc="feb";
}
else if(month.equals("03"))
{
mc="mar";
}
else if(month.equals("04"))
{
mc="apr";
}
else if(month.equals("05"))
{
mc="may";
}
else if(month.equals("06"))
{
mc="jun";
}
else if(month.equals("07"))
{
mc="jul";
}
else if(month.equals("08"))
{
mc="aug";
}
else if(month.equals("09"))
{
mc="sep";
}
else if(month.equals("10"))
{
mc="oct";
}
else if(month.equals("11"))
{
mc="nov";
}
else if(month.equals("12"))
{
mc="dec";
}
jComboBox3.setSelectedItem(ddate);
jComboBox4.setSelectedItem(mc);
jComboBox5.setSelectedItem(year);
cbox=res.getString(8);
Boolean cb1=cbox.contains("Charger");
if(cb1==true)
{
jCheckBox1.setSelected(true);
}
else
{
}
Boolean cb2=cbox.contains("HeadSet");
if(cb2==true)
{
jCheckBox2.setSelected(true);
}
else
{
}
Boolean cb3=cbox.contains("DataCable");
if(cb3==true)
{
jCheckBox3.setSelected(true);
}
else
{
}
Boolean cb4=cbox.contains("Battery");
if(cb4==true)
{
jCheckBox4.setSelected(true);
}
else
{
}
Boolean cb5=cbox.contains("MemoryCard");
if(cb5==true)
{
jCheckBox5.setSelected(true);
}
else
{
}
Boolean cb6=cbox.contains("CD");
if(cb6==true)
{
jCheckBox6.setSelected(true);
}
else
{
}
jButton1.setEnabled(false);
}
}while(res.next());
if(b!=1)
{
JOptionPane.showMessageDialog(null,"The mobile details does not exists in the database");
jTextField1.setText("");
jLabel10.setText("");
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"There are no additional accessories for this mobile");
jButton1.setEnabled(false);
}
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField1.setEditable(true);
disflds();
clrcombocheck();
b=0;
}
private void jTextField4KeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jTextField3KeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jComboBox3ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jComboBox4ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jComboBox5ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jCheckBox2ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jCheckBox3ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jCheckBox4ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jCheckBox5ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jCheckBox6ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
jButton1.setEnabled(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MobileUpdate().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JCheckBox jCheckBox3;
private javax.swing.JCheckBox jCheckBox4;
private javax.swing.JCheckBox jCheckBox5;
private javax.swing.JCheckBox jCheckBox6;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JComboBox jComboBox3;
private javax.swing.JComboBox jComboBox4;
private javax.swing.JComboBox jComboBox5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration
}
Code for BillGeneration Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* BillGeneration.java
*
* Created on Nov 1, 2010, 6:56:04 PM
*/
package mobilestorenew;
import java.sql.*;
import javax.swing.*;
import java.util.Date;
/**
*
* @author Ramesh
*/
public class BillGeneration extends javax.swing.JFrame {
/** Creates new form BillGeneration */
Date dat;
int bid,reply;
int a=0,b=0,c=0,d=0,x=0;
String dt,year,month,day,date;
int price=0,amtpaid,balamt,dpaidamt,dbalamt,drefid,dage;
String text="",cid="r",dcid,dcname,year1,month1,day1,mc1,dt1,dgender;
String cname,mob_purchased,ddno,dstreet,dcity,dstate,dphno;
int flag=0;
String s1,s2,s3,s4,nameappend="";int addprice;
public BillGeneration() {
initComponents();
setVisible(true);
setSize(1270,740);
setTitle("Generate Bill");
jTextField1.setEditable(false);
jTextField2.setEditable(false);
jTextField6.setEditable(false);
idincrement();
jTextField6.setText(Integer.toString(price));
}
public void idincrement()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection co=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=co.createStatement();
ResultSet res=st.executeQuery("select * from newbill");
while(res.next())
{
bid=res.getInt(1);
}
st.close();
co.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"the error is"+e);
System.out.println(e.getMessage());
}
bid=bid+1;
jTextField1.setText(Integer.toString(bid));
dat=new Date();
dt=dat.toString();
System.out.println(dt);
day=dt.substring(8,10);
month=dt.substring(4,7);
year=dt.substring(24,28);
date=day;
date+="-";
date+=month;
date+="-";
date+=year;
jTextField2.setText(date);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
jLabel11 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jLabel15 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
jLabel1.setText("Generate Bill");
getContentPane().add(jLabel1);
jLabel1.setBounds(390, 20, 220, 40);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel2.setText("Bill Id");
getContentPane().add(jLabel2);
jLabel2.setBounds(280, 80, 120, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel3.setText("Bill Date");
getContentPane().add(jLabel3);
jLabel3.setBounds(280, 130, 130, 30);
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel4.setText("Customer Name");
getContentPane().add(jLabel4);
jLabel4.setBounds(280, 180, 130, 30);
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel8.setText("Added Mobiles");
getContentPane().add(jLabel8);
jLabel8.setBounds(280, 400, 110, 30);
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel9.setText("Price");
getContentPane().add(jLabel9);
jLabel9.setBounds(280, 530, 110, 30);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel10.setText("Amount Paid");
getContentPane().add(jLabel10);
jLabel10.setBounds(280, 580, 110, 30);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton1.setText("Generate Bill");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(380, 640, 160, 40);
jTextField1.setFont(new java.awt.Font("Tahoma", 1, 14));
getContentPane().add(jTextField1);
jTextField1.setBounds(460, 80, 130, 30);
jTextField2.setFont(new java.awt.Font("Tahoma", 1, 14));
getContentPane().add(jTextField2);
jTextField2.setBounds(460, 130, 130, 30);
jTextField3.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField3.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField3FocusLost(evt);
}
});
getContentPane().add(jTextField3);
jTextField3.setBounds(460, 180, 130, 30);
jTextField6.setFont(new java.awt.Font("Tahoma", 1, 14));
getContentPane().add(jTextField6);
jTextField6.setBounds(460, 530, 130, 30);
jTextField7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jTextField7.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField7FocusLost(evt);
}
});
getContentPane().add(jTextField7);
jTextField7.setBounds(460, 580, 130, 30);
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setFont(new java.awt.Font("Tahoma", 1, 11));
jTextArea1.setRows(5);
jTextArea1.setTabSize(9);
jScrollPane1.setViewportView(jTextArea1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(460, 400, 410, 110);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton2.setText("ADD");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(740, 280, 100, 40);
getContentPane().add(jLabel11);
jLabel11.setBounds(580, 180, 120, 30);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel1.setLayout(null);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel5.setText("Select Phone Model");
jPanel1.add(jLabel5);
jLabel5.setBounds(40, 20, 150, 30);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel6.setText("Enter Phone Name");
jPanel1.add(jLabel6);
jLabel6.setBounds(40, 70, 180, 30);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel7.setText("Enter IMEI Number");
jPanel1.add(jLabel7);
jLabel7.setBounds(40, 120, 180, 30);
jTextField4.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField4FocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField4FocusLost(evt);
}
});
jPanel1.add(jTextField4);
jTextField4.setBounds(220, 70, 130, 30);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nokia", "Samsung", "Sony Ericson", "Lava", "Onida", "MaxMobile", "LG" }));
jComboBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox1ItemStateChanged(evt);
}
});
jPanel1.add(jComboBox1);
jComboBox1.setBounds(220, 20, 130, 30);
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
jPanel1.add(jLabel12);
jLabel12.setBounds(360, 70, 100, 30);
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12));
jPanel1.add(jLabel13);
jLabel13.setBounds(360, 120, 100, 30);
jTextField5.setFont(new java.awt.Font("Tahoma", 1, 12));
jTextField5.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField5FocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField5FocusLost(evt);
}
});
jPanel1.add(jTextField5);
jTextField5.setBounds(220, 120, 130, 30);
getContentPane().add(jPanel1);
jPanel1.setBounds(240, 220, 480, 170);
jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12));
getContentPane().add(jLabel15);
jLabel15.setBounds(600, 580, 100, 30);
jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12));
getContentPane().add(jLabel14);
jLabel14.setBounds(600, 530, 200, 30);
pack();
}// </editor-fold>
private void jTextField3FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField3.getText().equals(""))
{
jLabel11.setText("Entry Is Must") ;
jTextField3.setText("");
}
else
{
jLabel11.setText("") ;
}
}
private void jTextField4FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField4.getText().equals(""))
{
jLabel12.setText("Entry Is Must");
}
else
{
jLabel12.setText("");
String name=jTextField4.getText();
String model=(String) jComboBox1.getSelectedItem();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
JOptionPane.showMessageDialog(null,"There are no Mobile phones in database");
}
else
{
do
{
String s11=res.getString(2);
String s22=res.getString(3);
if(model.equalsIgnoreCase(s11) && name.equalsIgnoreCase(s22))
{
b=1;
}
}while(res.next());
if(b==0)
{
JOptionPane.showMessageDialog(null,"The mobile phone is not available, Please purchase another one");
jTextField4.setText("");
jLabel12.setText("Entry Is Must");
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is: "+e);
}
}
}
private void jTextField4FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
b=0;
}
private void jTextField5FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField5.getText().equals(""))
{
jLabel13.setText("Entry is Must");
}
else
{
String jtf1=jTextField5.getText();
int fg=0;
for(int i=0;i<jtf1.length();i++)
{
char c1=jtf1.charAt(i);
if(Character.isLetter(c1))
{
fg=0;
break;
}
else
{
fg=1;
}
}
if(fg==0)
{
jLabel13.setText("Enter Numbers") ;
jTextField5.setText("");
}
else
{
jLabel13.setText("") ;
}
try
{
String imeino=jTextField5.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
JOptionPane.showMessageDialog(null,"There are no Mobile phones in database");
}
else
{
do
{
String s12=res.getString(6);
if(imeino.equals(s12))
{
c=1;
}
}while(res.next());
if(c==0)
{
JOptionPane.showMessageDialog(null,"The mobile phone is not available, Please purchase another one");
jTextField5.setText("");
jLabel13.setText("Entry is Must");
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
}
private void jTextField5FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
c=0;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
x=0;
if(jTextField4.getText().equals("") || jTextField5.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Enter All appropriate fields");
if(jTextField4.getText().equals(""))
{
jLabel12.setText("Fill this Field");
}
else
{
jLabel12.setText("");
}
if(jTextField5.getText().equals(""))
{
jLabel13.setText("Fill this Field");
}
else
{
jLabel13.setText("");
}
}
else
{
try
{
String model=(String)jComboBox1.getSelectedItem();
String name=jTextField4.getText();
String imeino=jTextField5.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newmobile_details");
Boolean rec=res.next();
if(!rec)
{
JOptionPane.showMessageDialog(null,"There are no Mobile phones in database");
jTextField4.setText("");
jTextField5.setText("");
}
else
{
do
{
s1=res.getString(2);
s2=res.getString(3);
addprice=res.getInt(4);
s3=res.getString(5);
s4=res.getString(6);
if(s1.equalsIgnoreCase(model) && s2.equalsIgnoreCase(name) && s4.equalsIgnoreCase(imeino))
{
int reply2=JOptionPane.showConfirmDialog(null,"Are Sure You Want to Purchase");
if(reply2==JOptionPane.YES_OPTION)
{
price+=addprice;
jTextField6.setText(Integer.toString(price));
text+="\n"+s2+"\t"+addprice+"\t"+s3+"\t"+s4;
System.out.println(text);
jTextArea1.setText("Phone Name \tPhone Price \tPhone Color \tIMEI Number \n-------" +
"--------------------------------------------------------------------------"+text);
PreparedStatement prp=con.prepareStatement("delete newmobile_details where imeino="+s4);
prp.executeUpdate();
nameappend+=s2+", ";
System.out.println(nameappend);
jComboBox1.setSelectedItem("nokia");
jTextField4.setText("");
jTextField5.setText("");
x=1;
}
if(reply2==JOptionPane.NO_OPTION)
{
jComboBox1.setSelectedItem("nokia");
jTextField4.setText("");
jTextField5.setText("");
}
if(reply2==JOptionPane.CANCEL_OPTION)
{
jComboBox1.setSelectedItem("nokia");
jTextField4.setText("");
jTextField5.setText("");
}
}
}while(res.next());
if(x==0)
{
JOptionPane.showMessageDialog(null,"The Model and Name and IMEI No does not match, please enter correctly");
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
}
private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
jTextField4.setText("");
jTextField5.setText("");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(flag==0)
{
if(jTextField3.getText().equals("") || jTextField6.getText().equals("0") || jTextField7.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Enter all appropriate fields");
if(jTextField3.getText().equals(""))
{
jLabel11.setText("Fill this Field");
}
else
{
jLabel11.setText("");
}
if(jTextField6.getText().equals("0"))
{
jLabel14.setText("Please Add Mobile Phone");
}
else
{
jLabel14.setText("");
}
if(jTextField7.getText().equals(""))
{
jLabel15.setText("Fill this field");
}
else
{
jLabel15.setText("");
}
}
else
{
cname=jTextField3.getText();
mob_purchased=text;
amtpaid=Integer.parseInt(jTextField7.getText());
balamt=price-amtpaid;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
PreparedStatement prp=con.prepareStatement("insert into newbill values(?,?,?,?,?,?,?)");
prp.setInt(1,bid);
prp.setString(2,date);
prp.setString(3,cname);
prp.setInt(4,price);
prp.setInt(5,amtpaid);
prp.setString(6,mob_purchased);
prp.setString(7,nameappend);
prp.executeUpdate();
JOptionPane.showMessageDialog(null,"Bill details successfully saved");
PrintPreview pp=new PrintPreview();
pp.jLabel3.setText(Integer.toString(bid));
pp.jLabel5.setText(date);
pp.jLabel7.setText(cname);
pp.jTextArea1.setText("Phone Name \tPhone Price \tPhone Color \tIMEI Number \n-------" +
"--------------------------------------------------------------------------"+text);
pp.jLabel11.setText(Integer.toString(price));
pp.jLabel13.setText(Integer.toString(amtpaid));
pp.text=text;
pp.flag=0;
price=0;
bid++;
text="-";
jTextField1.setText(Integer.toString(bid));
jTextField3.setText("");
jTextArea1.setText("");
jTextField6.setText("0");
jTextField7.setText("");
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
}
if(flag==1)
{
dispose();
}
}
private void jTextField7FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
int amtcheck=Integer.parseInt(jTextField7.getText());
if(amtcheck>price)
{
jTextField7.setText("");
JOptionPane.showMessageDialog(null,"The Bill Amount is:"+price+", So pay less than or equal to the amount");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BillGeneration().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JButton jButton1;
public javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
public javax.swing.JLabel jLabel1;
public javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
public javax.swing.JLabel jLabel2;
public javax.swing.JLabel jLabel3;
public javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
public javax.swing.JLabel jLabel8;
public javax.swing.JLabel jLabel9;
public javax.swing.JPanel jPanel1;
public javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTextArea jTextArea1;
public javax.swing.JTextField jTextField1;
public javax.swing.JTextField jTextField2;
public javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
public javax.swing.JTextField jTextField6;
public javax.swing.JTextField jTextField7;
// End of variables declaration
}
Code for PrintPreview Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* PrintPreview.java
*
* Created on Nov 14, 2010, 10:52:13 PM
*/
package mobilestorenew;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.*;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Ramesh
*/
public class PrintPreview extends javax.swing.JFrame implements Printable{
/** Creates new form PrintPreview */
int a=0,d=0,flag=0;
int price,amtpaid,reply1=1,reply,balamt,dpaidamt,dbalamt,drefid,dage;
String refid="c",custrefid,cname,date,text,cid="r",dcid;
String dcname,year1,month1,day1,mc1,dt1,dgender,ddno,dstreet,dcity,dstate,dphno;
public PrintPreview() {
initComponents();
setVisible(true);
setTitle("Print Preview");
setSize(700,650);
setResizable(false);
setLocation(180,60);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 1, 36));
jLabel1.setText("Raj Mobile Store");
getContentPane().add(jLabel1);
jLabel1.setBounds(230, 30, 270, 40);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel1.setLayout(null);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("Bill Id :");
jPanel1.add(jLabel2);
jLabel2.setBounds(40, 40, 50, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel3.setText("Bill Id");
jPanel1.add(jLabel3);
jLabel3.setBounds(100, 40, 90, 30);
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel4.setText("Bill Date :");
jPanel1.add(jLabel4);
jLabel4.setBounds(410, 40, 70, 30);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel5.setText("Bill Date");
jPanel1.add(jLabel5);
jLabel5.setBounds(480, 40, 110, 30);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel6.setText("Customer Name :");
jPanel1.add(jLabel6);
jLabel6.setBounds(40, 90, 130, 30);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel7.setText("Customer Name");
jPanel1.add(jLabel7);
jLabel7.setBounds(170, 90, 270, 30);
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel8.setText("---------------------------------------------------------------------------------------------------------");
jPanel1.add(jLabel8);
jLabel8.setBounds(0, 130, 630, 17);
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel9.setText("Mobiles Purchased :");
jPanel1.add(jLabel9);
jLabel9.setBounds(40, 170, 140, 30);
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jTextArea1.setRows(5);
jTextArea1.setTabSize(9);
jScrollPane1.setViewportView(jTextArea1);
jPanel1.add(jScrollPane1);
jScrollPane1.setBounds(190, 170, 410, 110);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel10.setText("Total Price :");
jPanel1.add(jLabel10);
jLabel10.setBounds(40, 310, 100, 30);
jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel11.setText("Total Price");
jPanel1.add(jLabel11);
jLabel11.setBounds(190, 310, 100, 30);
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel12.setText("Amount Paid :");
jPanel1.add(jLabel12);
jLabel12.setBounds(40, 350, 150, 30);
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel13.setText("Amount Paid ");
jPanel1.add(jLabel13);
jLabel13.setBounds(190, 350, 100, 30);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 14));
jButton1.setText("Print");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
jButton1.setBounds(280, 410, 100, 40);
getContentPane().add(jPanel1);
jPanel1.setBounds(30, 100, 630, 480);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(flag==0)
{
jButton1.setVisible(false);
PrinterJob printJob = PrinterJob.getPrinterJob();
if (printJob.printDialog())
{
try
{
printJob.print();
printJob.setCopies(1);
}
catch(Exception PrintException)
{
PrintException.printStackTrace();
}
printJob.cancel();
}
printJob.cancel();
jButton1.setVisible(true);
cname=jLabel7.getText();
date=jLabel5.getText();
amtpaid=Integer.parseInt(jLabel13.getText());
price=Integer.parseInt(jLabel11.getText());
balamt=price-amtpaid;
if(price!=amtpaid)
{
dispose();
while(reply1!=JOptionPane.YES_OPTION)
{
reply=JOptionPane.showConfirmDialog(null,"Is this customer is new Customer or Existing Customer\n If new customer press Yes\n If Existing Customer Press No");
if(reply==JOptionPane.YES_OPTION)
{
while(!refid.equals(custrefid))
{
try
{
refid=JOptionPane.showInputDialog(null,"Enter Previous Customer Reference Id");
while(refid.equals(""))
{
JOptionPane.showMessageDialog(null,"Please Enter Reference Id");
refid=JOptionPane.showInputDialog(null,"Enter Previous Customer Referece Id");
}
}
catch(NullPointerException e)
{
int reply3=JOptionPane.showConfirmDialog(null,"Are you sure, you dont want to save customer details");
if(reply3==JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null,"The customer details are not saved");
break;
}
if(reply3==JOptionPane.NO_OPTION)
{
refid=JOptionPane.showInputDialog(null,"Enter Previous Customer Reference Id");
while(refid.equals(""))
{
JOptionPane.showMessageDialog(null,"Please Enter Reference Id");
refid=JOptionPane.showInputDialog(null,"Enter Previous Customer Referece Id");
}
}
if(reply3==JOptionPane.CANCEL_OPTION)
{
JOptionPane.showMessageDialog(null,"The customer details are not saved");
break;
}
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newcustomer_details");
Boolean rec=res.next();
if(!rec)
{
custrefid="1";
CreditCustomer cs=new CreditCustomer();
cs.jTextField2.setText(cname);
cs.jTextField3.setText(date);
cs.jTextField4.setText(Integer.toString(amtpaid));
cs.jTextField5.setText(Integer.toString(balamt));
cs.jTextField6.setText(refid);
cs.jTextArea1.setText("Phone Name \tPhone Price \tPhone Color \tIMEI Number \n-------" +
"--------------------------------------------------------------------------"+text);
cs.jTextField13.setVisible(false);
cs.jTextField14.setVisible(false);
cs.jLabel25.setVisible(false);
cs.jLabel26.setVisible(false);
cs.flag=0;
}
else
{
do
{
custrefid=res.getString(1);
if(refid.equals(custrefid))
{
CreditCustomer cs=new CreditCustomer();
cs.jTextField2.setText(cname);
cs.jTextField3.setText(date);
cs.jTextField4.setText(Integer.toString(amtpaid));
cs.jTextField5.setText(Integer.toString(balamt));
cs.jTextField6.setText(refid);
cs.jTextArea1.setText("Phone Name \tPhone Price \tPhone Color \tIMEI Number \n-------" +
"--------------------------------------------------------------------------"+text);
cs.jTextField13.setVisible(false);
cs.jTextField14.setVisible(false);
cs.jLabel25.setVisible(false);
cs.jLabel26.setVisible(false);
cs.flag=0;
a=1;
break;
}
}while(res.next());
if(a==0)
{
JOptionPane.showMessageDialog(null,"The Reference Id is wrong, please enter correct Reference ID");
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
break;
}
else if(reply==JOptionPane.NO_OPTION)
{
while(!cid.equals(dcid))
{
System.out.println("i came here");
try
{
cid=JOptionPane.showInputDialog(null,"Enter Customer Id");
while(cid.equals(""))
{
JOptionPane.showMessageDialog(null,"Plese Enter Customer Id");
cid=JOptionPane.showInputDialog(null,"Enter Customer Id");
}
}
catch(NullPointerException e)
{
int reply4=JOptionPane.showConfirmDialog(null,"Are you sure, you dont want to save customer details");
if(reply4==JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null,"The customer details are not saved");
break;
}
if(reply4==JOptionPane.NO_OPTION)
{
cid=JOptionPane.showInputDialog(null,"Enter Customer Id");
while(cid.equals(""))
{
JOptionPane.showMessageDialog(null,"Plese Enter Customer Id");
cid=JOptionPane.showInputDialog(null,"Enter Customer Id");
}
}
if(reply4==JOptionPane.CANCEL_OPTION)
{
JOptionPane.showMessageDialog(null,"The customer details are not saved");
break;
}
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newcustomer_details");
Boolean rec=res.next();
if(!rec)
{
}
else
{
do
{
dcid=res.getString(1);
dcname=res.getString(2);
dpaidamt=res.getInt(4);
dbalamt=res.getInt(5);
drefid=res.getInt(6);
java.sql.Date ddob=res.getDate(7);
dt1=ddob.toString();
year1=dt1.substring(0,4);
month1=dt1.substring(5,7);
day1=dt1.substring(8,10);
if(month1.equals("01"))
{
mc1="jan";
}
else if(month1.equals("02"))
{
mc1="feb";
}
else if(month1.equals("03"))
{
mc1="mar";
}
else if(month1.equals("04"))
{
mc1="apr";
}
else if(month1.equals("05"))
{
mc1="may";
}
else if(month1.equals("06"))
{
mc1="jun";
}
else if(month1.equals("07"))
{
mc1="jul";
}
else if(month1.equals("08"))
{
mc1="aug";
}
else if(month1.equals("09"))
{
mc1="sep";
}
else if(month1.equals("10"))
{
mc1="oct";
}
else if(month1.equals("11"))
{
mc1="nov";
}
else if(month1.equals("12"))
{
mc1="dec";
}
dage=res.getInt(8);
dgender=res.getString(9);
ddno=res.getString(10);
dstreet=res.getString(11);
dcity=res.getString(12);
dstate=res.getString(13);
dphno=res.getString(14);
String dmob_purchase=res.getString(15);
dmob_purchase+=text;
if(cid.equals(dcid))
{
CreditCustomer cs=new CreditCustomer();
cs.jComboBox1.setEnabled(false);
cs.jComboBox2.setEnabled(false);
cs.jComboBox3.setEnabled(false);
cs.jTextField7.setEditable(false);
cs.jRadioButton1.setEnabled(false);
cs.jRadioButton2.setEnabled(false);
cs.jTextField8.setEditable(false);
cs.jTextField9.setEditable(false);
cs.jTextField10.setEditable(false);
cs.jTextField11.setEditable(false);
cs.jTextField12.setEditable(false);
cs.jButton1.setText("Update Customer Details");
cs.jTextField1.setText(dcid);
cs.jTextField2.setText(dcname);
cs.jTextField3.setText(date);
cs.jTextField4.setText(Integer.toString(amtpaid));
cs.jTextField5.setText(Integer.toString(balamt));
cs.jTextField6.setText(Integer.toString(drefid));
cs.jTextArea1.setText(dmob_purchase);
cs.jComboBox1.setSelectedItem(day1);
cs.jComboBox2.setSelectedItem(mc1);
cs.jComboBox3.setSelectedItem(year1);
cs.jTextField7.setText(Integer.toString(dage));
if(dgender.equalsIgnoreCase("male"))
cs.jRadioButton1.setSelected(true);
if(dgender.equalsIgnoreCase("female"))
cs.jRadioButton2.setSelected(true);
cs.jTextField8.setText(ddno);
cs.jTextField9.setText(dstreet);
cs.jTextField10.setText(dcity);
cs.jTextField11.setText(dstate);
cs.jTextField12.setText(dphno);
cs.jTextField13.setText(Integer.toString(dbalamt));
int totalamt=dbalamt+balamt;
cs.jTextField14.setText(Integer.toString(totalamt));
cs.flag=1;
d=1;
break;
}
}while(res.next());
if(d==0)
{
JOptionPane.showMessageDialog(null,"Please enter correct Customer Id");
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
break;
}
else if(reply==JOptionPane.CANCEL_OPTION)
{
reply1=JOptionPane.showConfirmDialog(null,"Are you sure you dont want to save customer details");
if(reply1==JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null,"The Customer Details are not saved");
}
if(reply1==JOptionPane.NO_OPTION)
{
}
if(reply1==JOptionPane.CANCEL_OPTION)
{
JOptionPane.showMessageDialog(null,"The customer details are not saved");
break;
}
}
}
}
else
{
dispose();
}
}
else if(flag==1)
{
jButton1.setVisible(false);
PrinterJob printJob = PrinterJob.getPrinterJob();
if (printJob.printDialog())
{
try
{
printJob.print();
printJob.setCopies(1);
}
catch(Exception PrintException)
{
PrintException.printStackTrace();
}
printJob.cancel();
}
printJob.cancel();
jButton1.setVisible(true);
}
}
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
{
Graphics2D g2 = (Graphics2D) g;
g2.translate(pf.getImageableX()+5, pf.getImageableY()+5);
Font f = new Font("Monospaced",Font.PLAIN,12);
g2.setFont (f);
paint (g2);
return Printable.PAGE_EXISTS;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PrintPreview().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
public javax.swing.JLabel jLabel10;
public javax.swing.JLabel jLabel11;
public javax.swing.JLabel jLabel12;
public javax.swing.JLabel jLabel13;
public javax.swing.JLabel jLabel2;
public javax.swing.JLabel jLabel3;
public javax.swing.JLabel jLabel4;
public javax.swing.JLabel jLabel5;
public javax.swing.JLabel jLabel6;
public javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
public javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
public javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTextArea jTextArea1;
// End of variables declaration
}
Code for AddCustomer Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* CreditCustomer.java
*
* Created on Nov 5, 2010, 8:24:54 PM
*/
package mobilestorenew;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Ramesh
*/
public class CreditCustomer extends javax.swing.JFrame {
/** Creates new form CreditCustomer */
int cid,paidamt,balamt,refid,age,currentcid;
String sex="Male";
String cname,pdate,dob,dno,street,city,state,phno,mob_purchased,year;
int flag,totalbal,prevalue=0,curvalue;
java.sql.Date dat;
public CreditCustomer() {
initComponents();
setVisible(true);
setSize(1270,740);
setTitle("Credit Customer");
jTextField1.setEditable(false);
jTextField2.setEditable(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jTextField5.setEditable(false);
jTextField6.setEditable(false);
jTextField13.setEditable(false);
jTextField14.setEditable(false);
jTextArea1.setEditable(false);
idincrement();
ButtonGroup bg=new ButtonGroup();
bg.add(jRadioButton1);
bg.add(jRadioButton2);
}
public void idincrement()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection co=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=co.createStatement();
ResultSet res=st.executeQuery("select sysdate from dual");
res.next();
dat=res.getDate(1);
res=st.executeQuery("select * from newcustomer_details");
Boolean rec=res.next();
if(!rec)
{
cid=1;
}
else
{
do
{
curvalue=res.getInt(1);
if(prevalue<curvalue)
{
cid=curvalue+1;
prevalue=curvalue;
}
}while(res.next());
}
st.close();
co.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"the error is"+e);
}
jTextField1.setText(Integer.toString(cid));
year=dat.toString();
year=year.substring(0,4);
}
public void saveupdate()
{
dob=(String)jComboBox1.getSelectedItem();
dob+="-";
dob+=(String)jComboBox2.getSelectedItem();
dob+="-";
dob+=(String)jComboBox3.getSelectedItem();
System.out.println(dob);
age=Integer.parseInt(jTextField7.getText());
dno=jTextField8.getText();
street=jTextField9.getText();
city=jTextField10.getText();
state=jTextField11.getText();
phno=jTextField12.getText();
mob_purchased=jTextArea1.getText();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jLabe = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jTextField7 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
jLabel14 = new javax.swing.JLabel();
jTextField10 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jLabel17 = new javax.swing.JLabel();
jComboBox3 = new javax.swing.JComboBox();
jLabel18 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jTextField11 = new javax.swing.JTextField();
jTextField12 = new javax.swing.JTextField();
jLabel19 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jLabel21 = new javax.swing.JLabel();
jLabel23 = new javax.swing.JLabel();
jLabel24 = new javax.swing.JLabel();
jLabel22 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel10 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jLabel15 = new javax.swing.JLabel();
jTextField6 = new javax.swing.JTextField();
jLabel25 = new javax.swing.JLabel();
jTextField13 = new javax.swing.JTextField();
jLabel26 = new javax.swing.JLabel();
jTextField14 = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
jLabel1.setText("Add Credit Customer Details");
getContentPane().add(jLabel1);
jLabel1.setBounds(340, 0, 350, 40);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Customer Details", javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.TOP));
jPanel2.setLayout(null);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel5.setText("Age");
jPanel2.add(jLabel5);
jLabel5.setBounds(480, 30, 80, 30);
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel4.setText("Gender");
jPanel2.add(jLabel4);
jLabel4.setBounds(40, 90, 110, 30);
jRadioButton1.setFont(new java.awt.Font("Tahoma", 1, 12));
jRadioButton1.setSelected(true);
jRadioButton1.setText("Male");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jPanel2.add(jRadioButton1);
jRadioButton1.setBounds(130, 90, 60, 30);
jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 12));
jRadioButton2.setText("Female");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jPanel2.add(jRadioButton2);
jRadioButton2.setBounds(210, 90, 70, 30);
jLabe.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabe.setText("City");
jPanel2.add(jLabe);
jLabe.setBounds(480, 140, 90, 30);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel7.setText("Door NO");
jPanel2.add(jLabel7);
jLabel7.setBounds(480, 90, 110, 30);
jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel11.setText("Street");
jPanel2.add(jLabel11);
jLabel11.setBounds(40, 140, 80, 30);
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel12.setText("State");
jPanel2.add(jLabel12);
jLabel12.setBounds(40, 200, 80, 30);
jTextField7.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField7.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField7FocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField7FocusLost(evt);
}
});
jPanel2.add(jTextField7);
jTextField7.setBounds(580, 30, 160, 30);
jTextField9.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField9.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField9FocusLost(evt);
}
});
jPanel2.add(jTextField9);
jTextField9.setBounds(130, 140, 170, 30);
jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel14.setText("Phone Number");
jPanel2.add(jLabel14);
jLabel14.setBounds(480, 200, 100, 30);
jTextField10.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField10.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField10FocusLost(evt);
}
});
jPanel2.add(jTextField10);
jTextField10.setBounds(580, 140, 160, 30);
jTextField8.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField8.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField8FocusLost(evt);
}
});
jPanel2.add(jTextField8);
jTextField8.setBounds(580, 90, 160, 30);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel6.setText("Date of Birth");
jPanel2.add(jLabel6);
jLabel6.setBounds(40, 30, 90, 30);
jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel16.setText("(DD)");
jPanel2.add(jLabel16);
jLabel16.setBounds(180, 30, 30, 30);
jComboBox2.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" }));
jPanel2.add(jComboBox2);
jComboBox2.setBounds(210, 30, 56, 30);
jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel17.setText("(MM)");
jPanel2.add(jLabel17);
jLabel17.setBounds(270, 30, 40, 30);
jComboBox3.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1910", "1911", "1912", "1913", "1914", "1915", "1916", "1917", "1918", "1919", "1920", "1921", "1922", "1923", "1924", "1925", "1926", "1927", "1928", "1929", "1930", "1931", "1932", "1933", "1934", "1935", "1936", "1937", "1938", "1939", "1940", "1941", "1942", "1943", "1944", "1945", "1946", "1947", "1948", "1949", "1950", "1951", "1952", "1953", "1954", "1955", "1956", "1957", "1958", "1959", "1960", "1961", "1962", "1963", "1964", "1965", "1966", "1967", "1968", "1969", "1970", "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995" }));
jPanel2.add(jComboBox3);
jComboBox3.setBounds(310, 30, 60, 30);
jLabel18.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel18.setText("(YY)");
jPanel2.add(jLabel18);
jLabel18.setBounds(370, 30, 30, 30);
jComboBox1.setFont(new java.awt.Font("Tahoma", 1, 12));
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
jPanel2.add(jComboBox1);
jComboBox1.setBounds(130, 30, 50, 30);
jTextField11.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField11.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField11FocusLost(evt);
}
});
jPanel2.add(jTextField11);
jTextField11.setBounds(130, 200, 170, 30);
jTextField12.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField12.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField12FocusLost(evt);
}
});
jPanel2.add(jTextField12);
jTextField12.setBounds(580, 200, 160, 30);
jPanel2.add(jLabel19);
jLabel19.setBounds(750, 30, 170, 30);
jPanel2.add(jLabel20);
jLabel20.setBounds(750, 90, 170, 30);
jPanel2.add(jLabel21);
jLabel21.setBounds(310, 140, 110, 30);
jPanel2.add(jLabel23);
jLabel23.setBounds(310, 200, 120, 30);
jPanel2.add(jLabel24);
jLabel24.setBounds(750, 200, 170, 30);
jPanel2.add(jLabel22);
jLabel22.setBounds(750, 140, 160, 30);
getContentPane().add(jPanel2);
jPanel2.setBounds(20, 370, 980, 250);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Customer Details", javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.TOP));
jPanel1.setLayout(null);
jTextField1.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField1);
jTextField1.setBounds(170, 30, 140, 30);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel2.setText("Customer Id");
jPanel1.add(jLabel2);
jLabel2.setBounds(30, 30, 100, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel3.setText("Customer Name");
jPanel1.add(jLabel3);
jLabel3.setBounds(370, 30, 120, 30);
jTextField2.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField2);
jTextField2.setBounds(490, 30, 170, 30);
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel8.setText("Date Purchased");
jPanel1.add(jLabel8);
jLabel8.setBounds(30, 80, 100, 30);
jTextField3.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField3);
jTextField3.setBounds(170, 80, 140, 30);
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel9.setText("Mobiles Purchased");
jPanel1.add(jLabel9);
jLabel9.setBounds(370, 130, 120, 30);
jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jTextArea1.setRows(5);
jTextArea1.setTabSize(9);
jScrollPane1.setViewportView(jTextArea1);
jPanel1.add(jScrollPane1);
jScrollPane1.setBounds(490, 130, 410, 170);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel10.setText("Paid Amount");
jPanel1.add(jLabel10);
jLabel10.setBounds(370, 80, 100, 30);
jTextField4.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField4);
jTextField4.setBounds(490, 80, 170, 30);
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel13.setText("Balance Amount");
jPanel1.add(jLabel13);
jLabel13.setBounds(30, 130, 100, 30);
jTextField5.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField5);
jTextField5.setBounds(170, 130, 140, 30);
jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel15.setText("Reference Id");
jPanel1.add(jLabel15);
jLabel15.setBounds(30, 180, 100, 30);
jTextField6.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField6);
jTextField6.setBounds(170, 180, 140, 30);
jLabel25.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel25.setText("Old Balance Amount");
jPanel1.add(jLabel25);
jLabel25.setBounds(30, 230, 130, 30);
jTextField13.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField13);
jTextField13.setBounds(170, 230, 140, 30);
jLabel26.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel26.setText("Total Balance Amount");
jPanel1.add(jLabel26);
jLabel26.setBounds(30, 280, 140, 30);
jTextField14.setFont(new java.awt.Font("Tahoma", 1, 14));
jPanel1.add(jTextField14);
jTextField14.setBounds(170, 280, 140, 30);
getContentPane().add(jPanel1);
jPanel1.setBounds(20, 40, 980, 320);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel3.setLayout(null);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 14));
jButton1.setText("Save Customer Details");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel3.add(jButton1);
jButton1.setBounds(150, 10, 210, 40);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 14));
jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel3.add(jButton2);
jButton2.setBounds(370, 10, 100, 40);
getContentPane().add(jPanel3);
jPanel3.setBounds(180, 630, 610, 60);
pack();
}// </editor-fold>
private void jTextField7FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField7.getText().equals(""))
{
jLabel19.setText("Entry Is Must");
}
else if(jTextField7.getText().length()>2)
{
jLabel19.setText("Enter Valid Age");
jTextField7.setText("");
}
else
{
String jtf1=jTextField7.getText();
int fg=0;
for(int i=0;i<jtf1.length();i++)
{
char c1=jtf1.charAt(i);
if(Character.isLetter(c1))
{
fg=0;
break;
}
else
{
fg=1;
}
}
if(fg==0)
{
jLabel19.setText("Enter Numbers");
jTextField7.setText("");
}
else
jLabel19.setText("") ;
}
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
sex="Male";
System.out.println(sex);
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
sex="Female";
System.out.println(sex);
}
private void jTextField8FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField8.getText().equals(""))
{
jLabel20.setText("Entry Is Must");
}
else
{
jLabel20.setText("");
}
}
private void jTextField9FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField9.getText().equals(""))
{
jLabel21.setText("Entry Is Must");
}
else
{
jLabel21.setText("");
}
}
private void jTextField10FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField10.getText().equals(""))
{
jLabel22.setText("Entry Is Must");
}
else
{
jLabel22.setText("");
}
}
private void jTextField11FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField11.getText().equals(""))
{
jLabel23.setText("Entry Is Must");
}
else
{
jLabel23.setText("") ;
}
}
private void jTextField12FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
if(jTextField12.getText().equals(""))
{
jLabel24.setText("Entry Is Must");
}
else
{
String jtf1=jTextField12.getText();
int fg=0;
for(int i=0;i<jtf1.length();i++)
{
char c1=jtf1.charAt(i);
if(Character.isLetter(c1))
{
fg=0;
break;
}
else
{
fg=1;
}
}
if(fg==0)
{
jLabel24.setText("Enter Valid Phone Number");
jTextField12.setText("");
}
else
jLabel24.setText("") ;
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jTextField7.getText().equals("") || jTextField8.getText().equals("") || jTextField9.getText().equals("") || jTextField10.getText().equals("") || jTextField11.getText().equals("") || jTextField12.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Enter all appropriate fields");
if(jTextField7.getText().equals(""))
{
jLabel19.setText("Fill this Field");
}
else
jLabel19.setText("");
if(jTextField8.getText().equals(""))
{
jLabel20.setText("Fill this Field");
}
else
jLabel20.setText("");
if(jTextField9.getText().equals(""))
{
jLabel21.setText("Fill this Field");
}
else
jLabel21.setText("");
if(jTextField10.getText().equals(""))
{
jLabel22.setText("Fill this Field");
}
else
jLabel22.setText("");
if(jTextField11.getText().equals(""))
{
jLabel23.setText("Fill this Field");
}
else
jLabel23.setText("");
if(jTextField12.getText().equals(""))
{
jLabel24.setText("Fill this Field");
}
else
jLabel24.setText("");
}
else
{
if(flag==0)
{
cname=jTextField2.getText();
pdate=jTextField3.getText();
paidamt=Integer.parseInt(jTextField4.getText());
balamt=Integer.parseInt(jTextField5.getText());
refid=Integer.parseInt(jTextField6.getText());
saveupdate();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
PreparedStatement prp=con.prepareStatement("insert into newcustomer_details values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
prp.setInt(1,cid);
prp.setString(2,cname);
prp.setString(3,pdate);
prp.setInt(4,paidamt);
prp.setInt(5,balamt);
prp.setInt(6,refid);
prp.setString(7,dob);
prp.setInt(8,age);
prp.setString(9,sex);
prp.setString(10,dno);
prp.setString(11,street);
prp.setString(12,city);
prp.setString(13,state);
prp.setString(14,phno);
prp.setString(15,mob_purchased);
prp.executeUpdate();
JOptionPane.showMessageDialog(null,"Customer Details saved successfully");
con.commit();
con.close();
dispose();
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"INVALID DATE, please select correct date");
jComboBox1.setSelectedItem("01");
jComboBox2.setSelectedItem("jan");
jComboBox3.setSelectedItem("1910");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Error is:"+e);
}
}
else if(flag==1)
{
currentcid=Integer.parseInt(jTextField1.getText());
totalbal=Integer.parseInt(jTextField14.getText());
mob_purchased=jTextArea1.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
PreparedStatement prp=con.prepareStatement("update newcustomer_details set balamt=?, mob_purchased=? where cid=?");
prp.setInt(1,totalbal);
prp.setString(2,mob_purchased);
prp.setInt(3,currentcid);
prp.executeUpdate();
JOptionPane.showMessageDialog(null,"The Customer Details updated successfully");
con.commit();
con.close();
dispose();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
else if(flag==2)
{
dispose();
}
else if(flag==3)
{
currentcid=Integer.parseInt(jTextField1.getText());
saveupdate();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
PreparedStatement prp=con.prepareStatement("update newcustomer_details set dob=?,age=?,gender=?,dno=?,street=?,city=?,state=?,phno=? where cid=?");
prp.setString(1,dob);
prp.setInt(2,age);
prp.setString(3,sex);
prp.setString(4,dno);
prp.setString(5,street);
prp.setString(6,city);
prp.setString(7,state);
prp.setString(8,phno);
prp.setInt(9,currentcid);
prp.executeUpdate();
JOptionPane.showMessageDialog(null,"The Customer Details Updated Successfully");
con.commit();
con.close();
dispose();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
}
}
private void jTextField7FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
String temp=(String)jComboBox3.getSelectedItem();
int birthyear=Integer.parseInt(temp);
int thisyear=Integer.parseInt(year);
System.out.println(birthyear+","+thisyear);
int agefind=thisyear-birthyear;
agefind=agefind-1;
jTextField7.setText(Integer.toString(agefind));
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jComboBox1.setSelectedItem("01");
jComboBox2.setSelectedItem("jan");
jComboBox3.setSelectedItem("1910");
jRadioButton1.setSelected(true);
jTextField7.setText("");jLabel19.setText("");
jTextField8.setText("");jLabel20.setText("");
jTextField9.setText("");jLabel21.setText("");
jTextField10.setText("");jLabel22.setText("");
jTextField11.setText("");jLabel23.setText("");
jTextField12.setText("");jLabel24.setText("");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CreditCustomer().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JButton jButton1;
public javax.swing.JButton jButton2;
public javax.swing.JComboBox jComboBox1;
public javax.swing.JComboBox jComboBox2;
public javax.swing.JComboBox jComboBox3;
private javax.swing.JLabel jLabe;
public javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel17;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel19;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel21;
private javax.swing.JLabel jLabel22;
private javax.swing.JLabel jLabel23;
private javax.swing.JLabel jLabel24;
public javax.swing.JLabel jLabel25;
public javax.swing.JLabel jLabel26;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
public javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
public javax.swing.JRadioButton jRadioButton1;
public javax.swing.JRadioButton jRadioButton2;
private javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTextArea jTextArea1;
public javax.swing.JTextField jTextField1;
public javax.swing.JTextField jTextField10;
public javax.swing.JTextField jTextField11;
public javax.swing.JTextField jTextField12;
public javax.swing.JTextField jTextField13;
public javax.swing.JTextField jTextField14;
public javax.swing.JTextField jTextField2;
public javax.swing.JTextField jTextField3;
public javax.swing.JTextField jTextField4;
public javax.swing.JTextField jTextField5;
public javax.swing.JTextField jTextField6;
public javax.swing.JTextField jTextField7;
public javax.swing.JTextField jTextField8;
public javax.swing.JTextField jTextField9;
// End of variables declaration
}
Code for SearchCustomer Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SearchCustomer.java
*
* Created on Nov 10, 2010, 2:26:43 AM
*/
package mobilestorenew;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Ramesh
*/
public class SearchCustomer extends javax.swing.JFrame {
/** Creates new form SearchCustomer */
int flag=0,rows=0,a=0,b=0;
String cid;
Object data[][];
JTable table;
JScrollPane jsp;
ResultSet res;
ResultSet rs;
public SearchCustomer() {
initComponents();
setVisible(true);
setSize(1270,740);
setTitle("Search Customer");
ButtonGroup bg=new ButtonGroup();
bg.add(jRadioButton1);
bg.add(jRadioButton2);
}
public void tabledisp()
{
try
{
data=new Object[rows][15];
Object[] colheads={"Custmer Id","Customer Name","Purchase Date","Paid Amount","Balance Amount","Reference Id","Date Of Birth","Age","Gender","Door No","Street","City","State","Phone No","Mobiles Purchased"};
Class.forName("sun.jdbc.odbc.JdbcOdbc");
Connection con=DriverManager.getConnection("Jdbc:Odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
rs=st.executeQuery("select * from csearch");
for(int i=0;i<rows;i++)
{
rs.next();
for(int j=0;j<15;j++)
{
data [i][j]=rs.getString(j+1);
System.out.println(data[i][j]);
}
}
table=new JTable(data,colheads);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
jsp=new JScrollPane(table,v,h);
jsp.setBounds(70,380,900,240);
jPanel2.add(jsp);
add(jsp);
System.out.println("hai we came here");
rows=0;
st.close();
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"here the error is:"+e);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel1.setLayout(null);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
jLabel2.setText("Search Field");
jPanel1.add(jLabel2);
jLabel2.setBounds(90, 40, 90, 30);
jTextField1.setFont(new java.awt.Font("Tahoma", 1, 14));
jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField1FocusGained(evt);
}
});
jPanel1.add(jTextField1);
jTextField1.setBounds(210, 40, 160, 30);
jPanel1.add(jLabel3);
jLabel3.setBounds(380, 40, 100, 30);
jRadioButton1.setFont(new java.awt.Font("Tahoma", 1, 14));
jRadioButton1.setSelected(true);
jRadioButton1.setText(" Search By Customer Id");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jPanel1.add(jRadioButton1);
jRadioButton1.setBounds(90, 110, 210, 25);
jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 14));
jRadioButton2.setText(" Search By Customer Name");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jPanel1.add(jRadioButton2);
jRadioButton2.setBounds(90, 160, 230, 25);
getContentPane().add(jPanel1);
jPanel1.setBounds(40, 90, 500, 240);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
jLabel1.setText("Search Customer Details");
getContentPane().add(jLabel1);
jLabel1.setBounds(310, 20, 320, 50);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton1.setText("Search");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(610, 180, 120, 40);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton2.setText("Cancel");
getContentPane().add(jButton2);
jButton2.setBounds(770, 180, 100, 40);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Search Results"));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 944, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 270, Short.MAX_VALUE)
);
getContentPane().add(jPanel2);
jPanel2.setBounds(40, 350, 960, 300);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jTextField1.getText().equals(""))
{
jLabel3.setText("Entry Is Must");
jTextField1.setText("");
}
else
{
jLabel3.setText("");
cid=jTextField1.getText();
if(flag==0)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
st.executeUpdate("delete csearch");
res=st.executeQuery("select * from newcustomer_details");
Boolean rec=res.next();
if(rec==false)
{
JOptionPane.showMessageDialog(null,"There are no customers exists");
jTextField1.setText("");
}
else
{
do
{
String dcid=res.getString(1);
String dcname=res.getString(2);
java.sql.Date dt=res.getDate(3);
String dd=dt.toString();
String year=dd.substring(0,4);
String month=dd.substring(5,7);
String day=dd.substring(8,10);
String mc="";
if(month.equals("01"))
{
mc="jan";
}
else if(month.equals("02"))
{
mc="feb";
}
else if(month.equals("03"))
{
mc="mar";
}
else if(month.equals("04"))
{
mc="apr";
}
else if(month.equals("05"))
{
mc="may";
}
else if(month.equals("06"))
{
mc="jun";
}
else if(month.equals("07"))
{
mc="jul";
}
else if(month.equals("08"))
{
mc="aug";
}
else if(month.equals("09"))
{
mc="sep";
}
else if(month.equals("10"))
{
mc="oct";
}
else if(month.equals("11"))
{
mc="nov";
}
else if(month.equals("12"))
{
mc="dec";
}
String date=day+"-"+mc+"-"+year;
int dpaidamt=res.getInt(4);
int dbalamt=res.getInt(5);
int drefid=res.getInt(6);
java.sql.Date dob=res.getDate(7);
String ddob=dob.toString();
String year1=ddob.substring(0,4);
String month1=ddob.substring(5,7);
String day1=ddob.substring(8,10);
String mc1="";
if(month1.equals("01"))
{
mc1="jan";
}
else if(month1.equals("02"))
{
mc1="feb";
}
else if(month1.equals("03"))
{
mc1="mar";
}
else if(month1.equals("04"))
{
mc1="apr";
}
else if(month1.equals("05"))
{
mc1="may";
}
else if(month1.equals("06"))
{
mc1="jun";
}
else if(month1.equals("07"))
{
mc1="jul";
}
else if(month1.equals("08"))
{
mc1="aug";
}
else if(month1.equals("09"))
{
mc1="sep";
}
else if(month1.equals("10"))
{
mc1="oct";
}
else if(month1.equals("11"))
{
mc1="nov";
}
else if(month1.equals("12"))
{
mc1="dec";
}
String date1=day1+"-"+mc1+"-"+year1;
int dage=res.getInt(8);
String dgender=res.getString(9);
String ddno=res.getString(10);
String dstreet=res.getString(11);
String dcity=res.getString(12);
String dstate=res.getString(13);
String dphno=res.getString(14);
String dmob_purchased=res.getString(15);
if(cid.equalsIgnoreCase(dcid))
{
PreparedStatement prp=con.prepareStatement("insert into csearch values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
prp.setString(1,dcid);
prp.setString(2,dcname);
prp.setString(3,date);
prp.setInt(4,dpaidamt);
prp.setInt(5,dbalamt);
prp.setInt(6,drefid);
prp.setString(7,date1);
prp.setInt(8,dage);
prp.setString(9,dgender);
prp.setString(10,ddno);
prp.setString(11,dstreet);
prp.setString(12,dcity);
prp.setString(13,dstate);
prp.setString(14,dphno);
prp.setString(15,dmob_purchased);
prp.executeUpdate();
rows++;
System.out.println(rows);
System.out.println("i came here");
a=1;
jTextField1.setText("");
}
}while(res.next());
if(a==0)
{
JOptionPane.showMessageDialog(null,"The customer ID does not exists");
jTextField1.setText("");
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
tabledisp();
}
if(flag==1)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
st.executeUpdate("delete csearch");
res=st.executeQuery("select * from newcustomer_details");
Boolean rec=res.next();
if(rec==false)
{
JOptionPane.showMessageDialog(null,"There are no customers exists");
jTextField1.setText("");
}
else
{
do
{
String dcid=res.getString(1);
String dcname=res.getString(2);
java.sql.Date dt=res.getDate(3);
String dd=dt.toString();
String year=dd.substring(0,4);
String month=dd.substring(5,7);
String day=dd.substring(8,10);
String mc="";
if(month.equals("01"))
{
mc="jan";
}
else if(month.equals("02"))
{
mc="feb";
}
else if(month.equals("03"))
{
mc="mar";
}
else if(month.equals("04"))
{
mc="apr";
}
else if(month.equals("05"))
{
mc="may";
}
else if(month.equals("06"))
{
mc="jun";
}
else if(month.equals("07"))
{
mc="jul";
}
else if(month.equals("08"))
{
mc="aug";
}
else if(month.equals("09"))
{
mc="sep";
}
else if(month.equals("10"))
{
mc="oct";
}
else if(month.equals("11"))
{
mc="nov";
}
else if(month.equals("12"))
{
mc="dec";
}
String date=day+"-"+mc+"-"+year;
int dpaidamt=res.getInt(4);
int dbalamt=res.getInt(5);
int drefid=res.getInt(6);
java.sql.Date dob=res.getDate(7);
String ddob=dob.toString();
String year1=ddob.substring(0,4);
String month1=ddob.substring(5,7);
String day1=ddob.substring(8,10);
String mc1="";
if(month1.equals("01"))
{
mc1="jan";
}
else if(month1.equals("02"))
{
mc1="feb";
}
else if(month1.equals("03"))
{
mc1="mar";
}
else if(month1.equals("04"))
{
mc1="apr";
}
else if(month1.equals("05"))
{
mc1="may";
}
else if(month1.equals("06"))
{
mc1="jun";
}
else if(month1.equals("07"))
{
mc1="jul";
}
else if(month1.equals("08"))
{
mc1="aug";
}
else if(month1.equals("09"))
{
mc1="sep";
}
else if(month1.equals("10"))
{
mc1="oct";
}
else if(month1.equals("11"))
{
mc1="nov";
}
else if(month1.equals("12"))
{
mc1="dec";
}
String date1=day1+"-"+mc1+"-"+year1;
int dage=res.getInt(8);
String dgender=res.getString(9);
String ddno=res.getString(10);
String dstreet=res.getString(11);
String dcity=res.getString(12);
String dstate=res.getString(13);
String dphno=res.getString(14);
String dmob_purchased=res.getString(15);
if(cid.equals(dcname))
{
PreparedStatement prp=con.prepareStatement("insert into csearch values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
prp.setString(1,dcid);
prp.setString(2,dcname);
prp.setString(3,date);
prp.setInt(4,dpaidamt);
prp.setInt(5,dbalamt);
prp.setInt(6,drefid);
prp.setString(7,date1);
prp.setInt(8,dage);
prp.setString(9,dgender);
prp.setString(10,ddno);
prp.setString(11,dstreet);
prp.setString(12,dcity);
prp.setString(13,dstate);
prp.setString(14,dphno);
prp.setString(15,dmob_purchased);
prp.executeUpdate();
rows++;
System.out.println(rows);
System.out.println("i came here");
b=1;
jTextField1.setText("");
}
}while(res.next());
if(b==0)
{
JOptionPane.showMessageDialog(null,"The customer Name does not exists");
jTextField1.setText("");
}
}
con.commit();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
tabledisp();
}
}
}
private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
jsp.setVisible(false);
a=0;
b=0;
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
flag=0;
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
flag=1;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SearchCustomer().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
Code for SalesReports Page:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SalesReports.java
*
* Created on Nov 15, 2010, 1:27:07 AM
*/
package mobilestorenew;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.*;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Ramesh
*/
public class SalesReports extends javax.swing.JFrame implements Printable {
/** Creates new form SalesReports */
String text="";
int a=0,flag;
int countsales=0,totalamt=0;
public SalesReports() {
initComponents();
setSize(1270,740);
setTitle("Sales Reports");
jTextArea1.setEditable(false);
setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jComboBox1 = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel1.setText("Sales Reports");
getContentPane().add(jLabel1);
jLabel1.setBounds(430, 10, 320, 40);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 18));
jButton1.setText("Print");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(400, 610, 110, 50);
jButton2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jButton2.setText("Close");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(550, 610, 100, 50);
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jTextArea1.setRows(5);
jTextArea1.setTabSize(10);
jScrollPane1.setViewportView(jTextArea1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(70, 140, 910, 440);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" }));
getContentPane().add(jComboBox1);
jComboBox1.setBounds(280, 80, 100, 30);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("Select Month");
getContentPane().add(jLabel2);
jLabel2.setBounds(160, 80, 100, 30);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel3.setText("Select Year");
getContentPane().add(jLabel3);
jLabel3.setBounds(420, 80, 90, 30);
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
getContentPane().add(jComboBox2);
jComboBox2.setBounds(520, 80, 100, 30);
jButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton3.setText("Generate Report");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
getContentPane().add(jButton3);
jButton3.setBounds(720, 70, 160, 50);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jButton1.setVisible(false);
jButton2.setVisible(false);
jButton3.setVisible(false);
PrinterJob printJob = PrinterJob.getPrinterJob();
if (printJob.printDialog())
{
try
{
printJob.print();
printJob.setCopies(1);
}
catch(Exception PrintException)
{
PrintException.printStackTrace();
}
printJob.cancel();
}
printJob.cancel();
jButton1.setVisible(true);
jButton2.setVisible(true);
jButton3.setVisible(true);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextArea1.setText("");
text="";
a=0;
String month=(String)jComboBox1.getSelectedItem();
String year=(String)jComboBox2.getSelectedItem();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mobileDSN","scott","tiger");
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from newbill");
Boolean rec=res.next();
if(rec==false)
{
JOptionPane.showMessageDialog(null,"There are no sales on that month");
}
else
{
if(flag==0)
{
do
{
String dbid = res.getString(1);
java.sql.Date dbdate = res.getDate(2);
String bdate = dbdate.toString();
String dmonth=bdate.substring(5,7);
String dyear=bdate.substring(0,4);
String mc1="";
if (dmonth.equals("01"))
{
mc1 = "jan";
}
else if (dmonth.equals("02"))
{
mc1 = "feb";
} else if (dmonth.equals("03"))
{
mc1 = "mar";
} else if (dmonth.equals("04"))
{
mc1 = "apr";
} else if (dmonth.equals("05"))
{
mc1 = "may";
} else if (dmonth.equals("06"))
{
mc1 = "jun";
} else if (dmonth.equals("07"))
{
mc1 = "jul";
} else if (dmonth.equals("08"))
{
mc1 = "aug";
} else if (dmonth.equals("09"))
{
mc1 = "sep";
} else if (dmonth.equals("10"))
{
mc1 = "oct";
} else if (dmonth.equals("11"))
{
mc1 = "nov";
} else if (dmonth.equals("12"))
{
mc1 = "dec";
}
String dcname = res.getString(3);
int dprice = res.getInt(4);
int damtpaid = res.getInt(5);
String mob_purchased = res.getString(7);
if(mc1.equalsIgnoreCase(month) && dyear.equalsIgnoreCase(year))
{
countsales++;
totalamt+=damtpaid;
text+="\n"+dbid+" \t"+bdate+" \t"+dcname+" \t\t"+dprice+" \t"+damtpaid+" \t"+mob_purchased+" \n";
jTextArea1.setText("Bill Id \tBill Date \tCustomerName \t\tTotalPrice \tAmountPaid \tMobiles Purchased \n"+
"-----------------------------------------------------------------------------------------------------" +
"-----------------------------------------------------------------------------"+text+"\n--------------------------------------------------------------------------------------------"+
"-----------------------------------------------------------------------------\n\n\t\t Total No. Of Sales: "+countsales+"\tTotal Amount Collected: "+totalamt);
a=1;
countsales=0;
totalamt=0;
}
}while(res.next());
}
if(flag==1)
{
do
{
String dbid = res.getString(1);
java.sql.Date dbdate = res.getDate(2);
String bdate = dbdate.toString();
String dyear=bdate.substring(0,4);
String dcname = res.getString(3);
int dprice = res.getInt(4);
int damtpaid = res.getInt(5);
String mob_purchased = res.getString(7);
if(dyear.equalsIgnoreCase(year))
{
countsales++;
totalamt+=damtpaid;
text+="\n"+dbid+" \t"+bdate+" \t"+dcname+" \t\t"+dprice+" \t"+damtpaid+" \t"+mob_purchased+" \n";
jTextArea1.setText("Bill Id \tBill Date \tCustomerName \t\tTotalPrice \tAmountPaid \tMobiles Purchased \n"+
"-----------------------------------------------------------------------------------------------------" +
"-----------------------------------------------------------------------------"+text+"\n--------------------------------------------------------------------------------------------"+
"-----------------------------------------------------------------------------\n\n\t\t Total No. Of Sales: "+countsales+"\tTotal Amount Collected: "+totalamt);
countsales=0;
totalamt=0;
a=1;
}
}
while(res.next());
}
if(a==0)
{
JOptionPane.showMessageDialog(null,"There are no sales on that particular month");
jTextArea1.setText("");
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"The error is:"+e);
}
}
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
{
Graphics2D g2 = (Graphics2D) g;
g2.translate(pf.getImageableX()+5, pf.getImageableY()+5);
Font f = new Font("Monospaced",Font.PLAIN,12);
g2.setFont (f);
paint (g2);
return Printable.PAGE_EXISTS;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SalesReports().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
public javax.swing.JButton jButton3;
public javax.swing.JComboBox jComboBox1;
public javax.swing.JComboBox jComboBox2;
public javax.swing.JLabel jLabel1;
public javax.swing.JLabel jLabel2;
public javax.swing.JLabel jLabel3;
public javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTextArea jTextArea1;
// End of variables declaration
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment