📄 market.java
字号:
import java.*;
import java.sql.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.text.*;
import java.util.*;
import javax.swing.table.*;
import java.util.Vector;
class Market extends JFrame
{
////////////////////////////////////////////////////////////
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";//////
// String sConnStr = "jdbc:odbc:Market","","";/////
Connection conn = null;
Connection conn1 = null;
Connection conn2 = null;
Statement stmt;
Statement stmt1;
Statement stmt2;
ResultSet rs;
ResultSet rs2;
ResultSet rs3;
String s;
String ItemNoStr;
int sumOutOfDate=0;
double sum = 0;
////////////////////////////////////////////////////////////
Monitor mo = new Monitor();//动作事件监听
Mo2 mo2 = new Mo2();
/////////////////////////////总操作界面///////////////////////////////
JFrame f = new JFrame("超市商品管理系统");
// JButton stockManage = new JButton("库存管理");
/////////////
JButton outLibrary = new JButton("商品出库管理");
JButton IntoLibrary = new JButton("商品入库管理");
/////////////
JButton payManage = new JButton("结账管理");
JButton SaleManage = new JButton("商品管理");
JButton Sale = new JButton("商品销售");
JButton rejectManage = new JButton("退货管理");
JButton personnelManage = new JButton("人事管理");
JButton select = new JButton("查询");
JButton closeDL = new JButton("关闭");
JButton closeOL = new JButton("关闭");
JButton closeL = new JButton("关闭");
JButton closeSuply = new JButton("关闭");
JButton closeG = new JButton("关闭");
JButton Deal = new JButton("处理");
JButton closeDS = new JButton("关闭");
JButton closePD = new JButton("关闭");
JButton returnG = new JButton("查看退货");
////////////////////入库单表项///////////////
JButton exit = new JButton("退出");
JTextField gno = new JTextField(10);
JTextField sname = new JTextField(10);
JTextField ItemNo = new JTextField(10);
JTextField ILD = new JTextField(10);
JTextField price = new JTextField(10);
JTextField payed = new JTextField(10);
// JTextField price2 = new JTextField(10);
// JTextField payed2 = new JTextField(10);
JTextField amount = new JTextField(10);
////////////////////入库单表项///////////////
JTextField OutNo = new JTextField(10);
JTextField OLD = new JTextField(10);
///////////////////供应商表表项////////////////
JTextField sno = new JTextField(10);
JTextField s2name = new JTextField(10);
JTextField sAddress = new JTextField(10);
JTextField sPhoneNo = new JTextField(10);
JTextField sEmail = new JTextField(10);
JTextField sFax = new JTextField(10);
JTextField sHonor = new JTextField(10);
Choice ch ;
// JTextField sLoad = new JTextField(10);
//////////////////////商品表项/////////////////////
JTextField gname = new JTextField(10);
// JTextField gKind = new JTextField(10);
JTextField proY = new JTextField(4);
JTextField proM = new JTextField(2);
JTextField proD = new JTextField(2);
JTextField keepDate = new JTextField(10);
JTextField gPrice = new JTextField(10);
Choice gKind;
//////////////////////退货/////////////////////
JTextField reY = new JTextField(4);
JTextField reM = new JTextField(2);
JTextField reD = new JTextField(2);
JTextField reReason = new JTextField(10);
JButton handel = new JButton("存档");
//////////////////////销售///////////////////////
JButton next = new JButton("下一项");
JButton finish = new JButton("完成");
JButton cancel = new JButton("取消");
//////////////////////结账/////////////////////
JButton payByIn = new JButton("货单结款");
JButton payByOut = new JButton("回收欠款");
JButton payBySuplyer = new JButton("供应商清算");
JButton payPart = new JButton("显示全部欠款货单");
JButton pp2 = new JButton("显示待收款货单");
JButton payByKind = new JButton("全部结款");
JTable table=null;//表格
JTable table2=null;//表格
DefaultTableModel defaultModel=null;//默认的表控制模型
DefaultTableModel defaultModel2=null;//默认的表控制模型
Container c;
Container Lc;
JPanel panel1,panel2,Lpanel3;
Box boxH=Box.createVerticalBox();
String OutNoStr="";
//////////////////登录对话框///////////////////
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JLabel LD0;
JLabel CL = new JLabel("请输入帐号:");
JLabel PL = new JLabel("请输入密码:");
JTextField tf1 = new JTextField(10); //登录帐号
JPasswordField tf2 = new JPasswordField(10); //登录密码
JButton b1 = new JButton("登录");
JButton b2 = new JButton("退出登录");
JButton sure = new JButton("确定");
JButton sure2 = new JButton("确定");
JButton sure3 = new JButton("确定");
JButton sure4 = new JButton("确定");
JButton sure5 = new JButton("确定");
JButton sure6 = new JButton("确定");
JButton closeDF = new JButton("确定");
JButton dispaundry = new JButton("入库流水账");
JButton dispL = new JButton("库存流动信息");
JButton dispS = new JButton("供应商信息");
JButton dispPay = new JButton("结款信息");
JButton dispSale = new JButton("销售信息");
JButton dispG = new JButton("商品信息");
JButton dispOut = new JButton("出库流水账");
JButton verify;JButton verify2;
JButton reFill;
JButton reDo = new JButton("重新操作");
JButton addG;
JButton retoMain = new JButton("返回主菜单");
JDialog d;JDialog d2;JDialog DL; JDialog ok;JDialog rd;JDialog IG;
JDialog pDiag;JDialog InDiag;JDialog extraDia;JDialog L;JDialog added;
JDialog addS;JDialog addW;JDialog OutDiag;JDialog re;JDialog outS;JDialog InS;
JDialog SDiag;JDialog ReS;JDialog warn;JDialog OL;JDialog DispS;JDialog G;JDialog SF;JDialog DF;
JDialog DS;JDialog DR;JDialog D;JDialog Diag;
///////////////////////////////////////////////////////////
public Market()
{
ImageIcon Tu = new ImageIcon("bb.jpg");
LD0 = new JLabel(Tu);
f.add(LD0,BorderLayout.CENTER);
f.setLayout(new BorderLayout());
f.addWindowListener(new WindowAdapter(){//设置窗口监听器,以关闭窗口
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
try
{
//System.out.println("OK");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:Market","","");
conn1 = DriverManager.getConnection("jdbc:odbc:Market","","");
conn2 = DriverManager.getConnection("jdbc:odbc:Market","","");
stmt = conn.createStatement();
stmt1 = conn1.createStatement();
stmt2 = conn2.createStatement();
}
catch(Exception e)
{
e.printStackTrace();
}
Entrance();
p3.setLayout(new GridLayout(6,5));
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(new JLabel(" 操"));
p3.add(new JLabel(" 作"));
p3.add(new JLabel(""));
p3.add(rejectManage);
p3.add(IntoLibrary);
p3.add(outLibrary);
p3.add(payManage);
p3.add(SaleManage);
// p3.add(Sale);
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(new JLabel(" 查"));
p3.add(new JLabel(" 询"));
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(dispL);
p3.add(dispaundry);
p3.add(dispOut);
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(new JLabel(""));
p3.add(dispS);
// p3.add(dispSale);
p3.add(dispG);
p3.add(returnG);
p3.add(new JLabel(""));
p4.add(new JLabel(""));
p4.add(exit);p4.add(new JLabel(""));
f.add(new JLabel(""),BorderLayout.CENTER);
f.add(new JLabel(""),BorderLayout.EAST);
f.add(new JLabel(""),BorderLayout.WEST);
f.add(p3,BorderLayout.NORTH);
f.add(p4,BorderLayout.SOUTH);
dispSale.addActionListener(new Monitor());
returnG.addActionListener(new Monitor());
dispOut.addActionListener(new Monitor());
dispaundry.addActionListener(new Monitor());
Sale.addActionListener(new Monitor());
dispL.addActionListener(new Monitor());
dispS.addActionListener(new Monitor());
dispPay.addActionListener(new Monitor());
dispG.addActionListener(new Monitor());
rejectManage.addActionListener(new Monitor());
IntoLibrary.addActionListener(new Monitor());
outLibrary.addActionListener(new Monitor());
payManage.addActionListener(new Monitor());
SaleManage.addActionListener(new Monitor());
// select.addActionListener(new Monitor());
exit.addActionListener(new Monitor());
f.setSize(600,400);
f.setLocation(350,220);
f.setVisible(true);
}
public void Entrance()//登录对话框
{
d= new JDialog(f,"登录界面",true);
p1.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
p2.setLayout(new GridLayout(2,2,5,10));
p2.add(CL);
p2.add(tf1);
p2.add(PL);
p2.add(tf2);
p1.add(b1);
p1.add(exit);
d.addWindowListener(new WindowAdapter(){//设置窗口监听器,以关闭窗口
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
d.setLayout(new BorderLayout(20,10));
d.add(new JLabel(),BorderLayout.NORTH);
d.add(new JLabel(),BorderLayout.EAST);
d.add(new JLabel(),BorderLayout.WEST);
d.add(p1,BorderLayout.SOUTH);
d.add(p2,BorderLayout.CENTER);
tf1.addActionListener(mo);
tf2.addActionListener(mo);
b1.addActionListener(mo); //b1->登陆
exit.addActionListener(mo);
d.setSize(300,180);
d.setLocation(450,180);
d.setResizable(false);
d.setVisible(true);//最后写
}
public void DealFinish()//登录对话框
{
DF= new JDialog(f,"处理已经完成",true);
DF.addWindowListener(new WindowAdapter(){//设置窗口监听器,以关闭窗口
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
DF.setLayout(new BorderLayout(20,10));
DF.add(new JLabel(),BorderLayout.NORTH);
DF.add(new JLabel("-----------------操作成功-----------------"),BorderLayout.EAST);
DF.add(new JLabel(),BorderLayout.WEST);
DF.add(closeDF,BorderLayout.SOUTH);
DF.add(new JLabel(),BorderLayout.CENTER);
closeDF.addActionListener(new Monitor());
DF.setSize(300,180);
DF.setLocation(450,180);
DF.setResizable(false);
DF.setVisible(true);//最后写
}
public void DealOutOfDate()
{
java.util.Date now = new java.util.Date(System.currentTimeMillis());
String warning = "select * from Goods";
try
{
rs = stmt.executeQuery(warning);
while(rs.next())
{
String gno = rs.getString(1);/////////////取出的不是要处理的gno//////////////
java.sql.Date proDate = rs.getDate(4);
int keepDate = rs.getInt(5);
int days = (now.getYear()-proDate.getYear())*365+(now.getMonth()-proDate.getMonth())*30+(now.getDay()-proDate.getDay());
if(days>0.8*keepDate)
{
stmt.executeUpdate("delete * from Goods where gno ='"+ gno+"'");
System.out.println("delete * from Goods where gno ='"+ gno+"'") ;
}
System.out.println("ooooo1");
}
System.out.println("ooooo2");
}catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
}
public void OutOfDate()//过期判断
{
java.util.Date now = new java.util.Date(System.currentTimeMillis());
String warning = "select * from Goods";
warn = new JDialog(f,"到期提醒",true);
warn.setLayout(new BorderLayout());
try
{
rs = stmt.executeQuery(warning);
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
c=warn.getContentPane();
//c = new Container();
panel2=new JPanel();
String[] name={"商品代码","商品名称","商品类别"}; //保存在String数组里
String[][] data1=new String[0][0];
defaultModel=new DefaultTableModel(data1,name);
table=new JTable(defaultModel);
table.setPreferredScrollableViewportSize(new Dimension(500,300));//设定高度和宽度
JScrollPane s=new JScrollPane(table);//创建JScrollPane对象并指定内部控件
panel2.add(s);
c.add(panel2,BorderLayout.CENTER);
warn.add(new Label(" 即将到期产品如下"),BorderLayout.NORTH);
//DL.add(c,BorderLayout.CENTER);
JPanel cDl = new JPanel();
cDl.add(new JLabel(""));cDl.add(Deal);
warn.add(cDl,BorderLayout.SOUTH);
Deal.addActionListener(mo);
try
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -