?? waiterframe.java
字號:
package dvd;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import java.lang.*;
import javax.swing.Timer;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class WaiterFrame extends JFrame{
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
JButton jButton1 = new JButton();
JLabel jLabel2 = new JLabel();
JTextField jtx1 = new JTextField();
JButton jb2 = new JButton();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JTextField DVDIDtx = new JTextField();
JTextField amounttx = new JTextField();
JButton jb3 = new JButton();
JPanel jPanel2 = new JPanel();
XYLayout xYLayout3 = new XYLayout();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel6 = new JLabel();
private Connection connection;
private String url = "jdbc:odbc:sql";
private int sprice=0;
private int pprice=0;
private int remainAmount=0;
private int count=1;
GridBagLayout gridBagLayout1 = new GridBagLayout();
JLabel jlabel1 = new JLabel();
java.util.Date date=new java.util.Date();
String Time=date.toString();
Timer timer;
public WaiterFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(gridBagLayout1);
jPanel1.setBackground(SystemColor.text);
jPanel1.setLayout(xYLayout2);
jLabel1.setFont(new java.awt.Font("Dialog", 0, 25));
jLabel1.setForeground(Color.magenta);
jLabel1.setText("銷售人員服務窗口");
jButton1.setBackground(Color.lightGray);
jButton1.setFont(new java.awt.Font("SansSerif", 0, 18));
jButton1.setForeground(Color.magenta);
jButton1.setToolTipText("瀏覽所有影片相關信息及貨品存放位置信息");
jButton1.setText("影片情況總覽");
jButton1.addActionListener(new WaiterFrame_jButton1_actionAdapter(this));
jLabel2.setBackground(Color.lightGray);
jLabel2.setFont(new java.awt.Font("Dialog", 0, 18));
jLabel2.setForeground(Color.magenta);
jLabel2.setText("查找影片存放位置");
jtx1.setFont(new java.awt.Font("Dialog", 0, 15));
jtx1.setForeground(Color.blue);
jtx1.setToolTipText("輸入影片ID號");
jtx1.setDisabledTextColor(Color.black);
jtx1.setText("");
jb2.setBackground(Color.lightGray);
jb2.setFont(new java.awt.Font("Dialog", 0, 18));
jb2.setForeground(Color.magenta);
jb2.setText("查找");
jb2.addActionListener(new WaiterFrame_jb2_actionAdapter(this));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 18));
jLabel3.setForeground(Color.magenta);
jLabel3.setText("購買影片");
jLabel4.setFont(new java.awt.Font("Dialog", 0, 18));
jLabel4.setForeground(new Color(255, 159, 76));
jLabel4.setHorizontalTextPosition(SwingConstants.TRAILING);
jLabel4.setText("輸入影片ID號");
jLabel5.setFont(new java.awt.Font("Dialog", 0, 18));
jLabel5.setForeground(new Color(255, 152, 76));
jLabel5.setText("輸入顧客購買數量");
DVDIDtx.setFont(new java.awt.Font("Dialog", 0, 15));
DVDIDtx.setForeground(Color.blue);
DVDIDtx.setText("");
amounttx.setFont(new java.awt.Font("Dialog", 0, 15));
amounttx.setForeground(Color.blue);
amounttx.setText("");
jb3.setBackground(Color.lightGray);
jb3.setFont(new java.awt.Font("Dialog", 0, 18));
jb3.setForeground(Color.magenta);
jb3.setText("賣出");
jb3.addActionListener(new WaiterFrame_jb3_actionAdapter(this));
jPanel2.setBackground(Color.orange);
jPanel2.setLayout(xYLayout3);
jLabel7.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel7.setText("服務人員銷售規程");
jLabel8.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel8.setText("1.顧客將選擇的影片告知銷售人員,銷售人員紀錄影片ID號");
jLabel9.setText("");
jLabel9.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel9.setText("2.銷售人員通過查找影片存放位置到庫取得相應數量的碟片");
jLabel6.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel6.setText("3.銷售人員將影片Id號及購買數量填入銷售表中");
this.getContentPane().setBackground(SystemColor.text);
jlabel1.setFont(new java.awt.Font("Dialog", 0, 15));
jlabel1.setForeground(new Color(0, 83, 0));
jlabel1.setText("");
this.getContentPane().add(jPanel1, new GridBagConstraints(0, 0, 4, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, -1, 0, 0), 219, 0));
jPanel1.add(jLabel1, new XYConstraints(126, 8, -1, -1));
jPanel1.add(jlabel1, new XYConstraints(253, 53, 274, 27));
this.getContentPane().add(jtx1, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(28, 12, 6, 17), 116, 6));
this.getContentPane().add(jLabel2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(22, 27, 0, 12), 1, 14));
this.getContentPane().add(jLabel3, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 74, 0, 33), 5, 3));
this.getContentPane().add(jLabel4, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(14, 60, 0, 0), 17, 2));
this.getContentPane().add(jLabel5, new GridBagConstraints(0, 5, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(13, 60, 0, 0), 9, 4));
this.getContentPane().add(DVDIDtx, new GridBagConstraints(2, 4, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(17, 8, 0, 0), 108, 6));
this.getContentPane().add(amounttx, new GridBagConstraints(2, 5, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(9, 8, 0, 0), 109, 8));
this.getContentPane().add(jb2, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(26, 21, 0, 105), 9, -3));
this.getContentPane().add(jb3, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 22, 14, 103), 10, -3));
this.getContentPane().add(jPanel2, new GridBagConstraints(0, 6, 4, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(9, -1, 0, 0), 2, 9));
jPanel2.add(jLabel7, new XYConstraints(21, 9, 121, 26));
jPanel2.add(jLabel8, new XYConstraints(145, 4, 380, 27));
jPanel2.add(jLabel9, new XYConstraints(144, 27, 396, 25));
jPanel2.add(jLabel6, new XYConstraints(143, 49, 376, 24));
this.getContentPane().add(jButton1, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(1, 29, 10, 9), 32, 5));
int delay = 1;//milliseconds
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jlabel1.setText("當前時間"+new java.util.Date().toString());
}
};
timer=new Timer(delay, taskPerformer);
timer.start();
}
void jButton1_actionPerformed(ActionEvent e) {
String quire1="select * from part_inf";
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
connection = DriverManager.getConnection(
url );
}
catch ( ClassNotFoundException cnfex ) {
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
System.exit( 1 ); // terminate program
}
catch ( SQLException sqlex ) {
System.err.println( "Unable to connect" );
sqlex.printStackTrace();
}
// this.dispose();
DVDFrame movieFrame=new DVDFrame(connection,quire1);
movieFrame.setSize(500,500);
movieFrame.show();
}
void jb2_actionPerformed(ActionEvent e) {
String movieID= jtx1.getText().trim();
String quire2="select shelf_no as 貨架號,row_no as 行號,column_no as 列號 from position where DVD_no like'%"+movieID+"%'";
if(!movieID.equals(""))
{ try {//3
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
connection = DriverManager.getConnection( url );
}//3
catch ( ClassNotFoundException cnfex ) {//4
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
System.exit( 1 ); // terminate program
}//4
catch ( SQLException sqlex ) {//5
System.err.println( "Unable to connect" );
sqlex.printStackTrace();
}//5
DVDFrame movieFrame=new DVDFrame(connection,quire2);
movieFrame.setSize(500,500);
movieFrame.show();
jtx1.setText("");
}
else
JOptionPane.showMessageDialog(null,"Please enter the role name you want","sorry",JOptionPane.INFORMATION_MESSAGE);
}
void jb3_actionPerformed(ActionEvent e) {
java.util.Date date=new java.util.Date();
String time=date.toString();
String dvdid= DVDIDtx.getText().trim();
String amount1= amounttx.getText().trim();
Statement sql=null;
ResultSet rs=null;
int amount=Integer.parseInt(amount1);
int profit=0;
int money=0;
int remains=0;
int count=1;
String sell="select * from sell";
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
}
catch(ClassNotFoundException event){}
try{
connection = DriverManager.getConnection( url );
sql=connection.createStatement();
String quire="SELECT DVD_no , p_price,s_price,remains FROM DVD where DVD_no="+"'"+dvdid+"'";
DVDFrame movieFrame=new DVDFrame(connection,quire);
movieFrame.dispose();
rs=sql.executeQuery(quire);
if(!movieFrame.haverecords)
{
DVDIDtx.setText("");
amounttx.setText("");
}
while( rs.next() )
{
String s = rs.getString(1);
pprice = (int)rs.getInt("p_price");
sprice = (int)rs.getInt("s_price");
remainAmount = (int)rs.getInt("remains");
}
money=amount*sprice;
profit=amount*(sprice-pprice);
remains=remainAmount-amount;
}
catch ( SQLException sqlex ) {
}
{ try {//3
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
connection = DriverManager.getConnection( url );
}//3
catch ( ClassNotFoundException cnfex ) {//4
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
System.exit( 1 ); // terminate program
}//4
catch ( SQLException sqlex ) {//5
System.err.println( "Unable to connect" );
sqlex.printStackTrace();
}//5
DVDFrame movieFrame=new DVDFrame(connection,sell);
movieFrame.dispose();
count=movieFrame.number+1;
}
try {
Statement statement = connection.createStatement();
if(!(dvdid.equals("")||amount1.equals("")))
{
String insert ="insert into sell(s_no,s_amount,DVD_no,s_date,s_money,s_profit,remainNumber)"+
"values('"+count+"','"+amount+"','"+dvdid+"','"+time+"','"+
money+"','"+profit+"','"+remains+"')";
if(remains<0){
JOptionPane.showMessageDialog(null,"本店暫時貨源不足,很抱歉","sorry",JOptionPane.INFORMATION_MESSAGE);
DVDIDtx.setText("");
amounttx.setText("");
}
else{
connection.nativeSQL(insert);
int result =statement.executeUpdate(insert);
if((result==1)&&(remains>=0))
{
JOptionPane.showMessageDialog(null,"成功交易","sell DVD success",JOptionPane.INFORMATION_MESSAGE);
count+=1;
DVDIDtx.setText("");
amounttx.setText("");
}
}
}
}
catch ( SQLException sqlex )
{
}
try {
Statement statement = connection.createStatement();
String update="update DVD set remains='"+remains+"' where DVD_no='"+dvdid+"'";
connection.nativeSQL(update);
int result =statement.executeUpdate(update);
}
catch ( SQLException sqlex ) {
}
}
}
class WaiterFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {
WaiterFrame adaptee;
WaiterFrame_jButton1_actionAdapter(WaiterFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class WaiterFrame_jb2_actionAdapter implements java.awt.event.ActionListener {
WaiterFrame adaptee;
WaiterFrame_jb2_actionAdapter(WaiterFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jb2_actionPerformed(e);
}
}
class WaiterFrame_jb3_actionAdapter implements java.awt.event.ActionListener {
WaiterFrame adaptee;
WaiterFrame_jb3_actionAdapter(WaiterFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jb3_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -