当前位置:文档之家› 网上书店完整代码

网上书店完整代码

附录全部源代码package class Connect {private static Connection con = null;private static String url="jdbc:oracle:thin:@localhost:1521:ORCL";private static String driver = "";private static String user = "scott";private static String pwd = "tiger";public static Connection getConnection(){try {(driver);con = (url, user, pwd);"数据库连接成功!");} catch (ClassNotFoundException e) {"驱动加载失败!");;} catch (SQLException e) {"数据库连接失败!");}return con;}public static void main(String[] args) {();}}package class docMenuAction implements ActionListener { RegisterFrame register = null;JPanel cusPanel = null;JPanel docPanel = null;public docMenuAction(RegisterFrame register){= register;= ;= ;}public void actionPerformed(ActionEvent e) {于用户搜索商品public ArrayList getAllSellerGoods(){ArrayList list = new ArrayList();conn = ();try {statement = ();String sql = "select * from goods a,seller b where =";resultSet = (sql);while()){Seller seller = new Seller();("seller_name"));("address"));Goods goods = new Goods();(seller);("goods_id"));("goods_name"));("seller_id"));("discount"));("num"));("price"));2012-9-192012-9-192012-9-192012-9-19etImage());(null);(null);(false);etImage());(600, 400);;(null);(menuBar,;setGoodsPanel();;(goodsPanel,;;setSouthPanel();setOrderPanel();(southPanel,;}quals())){(null, "请输入商品编号或商品数量!");}else{int id = ());int num = ((String) ());goods = (id);if(null, "您确定要购买吗")==0){if()==0){(null, "商品编号输入错误!");}else{if()<num){(null, "商品数量不足!");}else{()-num);(goods);OrderDao order = new OrderDao();(goods, num);(null, "购买成功!");setAr();setOr();();}}}else{}}}});}etName();ar[i][7]=().getAddress();}}private void setArNull(){for(int i=0;i<;i++){for(int j=0;j<ar[i].length;j++){ar[i][j]="";}}}etName();or[i][3]=().getPrice();or[i][4]=().getDiscount();or[i][5]=().getPrice()*().getDiscount()*;or[i][6]=();or[i][7]=().getName();or[i][8]=().getAddress();}}private void setOrNull(){for(int i=0;i<;i++){for(int j=0;j<or[i].length;j++){or[i][j]="";}}}public static void main(String[] args) {BuyerFrame frame = new BuyerFrame();(true);}}package class LoginFrame extends JFrame{ private JLabel userNameLabel = new JLabel("用户名:");private JLabel pwdLabel = new JLabel("密码:");private JTextField useNameText = new JTextField();private JPasswordField pws = new JPasswordField();private JLabel roleLabel = new JLabel("角色:");private JComboBox roleBox = new JComboBox(new String[]{"商家","买家"}); private JButton bt = new JButton("确定");private JButton btR = new JButton("取消");private String flag = null;public LoginFrame(){init();}private void init(){(320, 280);("登录");(new ImageIcon("images/").getImage());(null);(false);;(null);(40, 20, 150, 30);(userNameLabel);(120, 20, 150, 30);(useNameText);(40, 80, 150, 30);(pwdLabel);(120, 80, 150, 30);(pws);(40, 140, 70, 30);(roleLabel);(120, 140, 150, 30);(roleBox);(40, 200, 70, 30);(btR);(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {quals(f)){flag = "seller";}if("买家".equals(f)){flag = "customer";}if("seller".equals(flag)){Seller seller = (), ());"-----"+());if()==null){(null, "用户名或密码输入错误");}else{setVisible(false);SellerFrame fame = new SellerFrame();(true);}}if("customer".equals(flag)){Buyer buyer = (), ());if()==null){(null, "用户名或密码输入错误");}else{setVisible(false);BuyerFrame frame = new BuyerFrame();(true);}}2012-9-20etImage());(300, 400);etImage());(600, 400);;(null);(menuBar,;setGoodsPanel();;(goodsPanel,;;setSouthPanel();setOrderPanel();(southPanel,;}quals())){(null, "请输入商品编号!");}else{int id = ());UpdateFrame frame = new UpdateFrame();Goods goods = new GoodsDao().getOneGoods(id);if()!=0){(goods);(goods);(true);}else{(null, "商品编号输入错误!");}}}});(btDelet);quals())){(null, "请输入商品编号!");}else{int id = ());GoodsDao dao = new GoodsDao();if(null, "您确定要删除吗")==0){if(id)!=0){(null, "删除成功!");}else{(null, "商品编号输入错误!!");}}else{}}}});(btAdd);(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {etName();ar[i][7]=().getAddress();}}private void setArNull(){for(int i=0;i<;i++){for(int j=0;j<ar[i].length;j++){ar[i][j]="";}}}etName();or[i][3]=().getPrice();or[i][4]=().getDiscount();or[i][5]=().getPrice()*().getDiscount()*;or[i][6]=();or[i][7]=();}}private void setOrNull(){for(int i=0;i<;i++){for(int j=0;j<or[i].length;j++){or[i][j]="";}}}public static void main(String[] args) {SellerFrame frame = new SellerFrame();(true);}}package class UpdateFrame extends JFrame{private static final Goods Goods = null;private JLabel lbName = new JLabel("商品名:");private JLabel lbPrice = new JLabel("价格:");private JLabel lbDiscount = new JLabel("折扣:");private JLabel lbNum = new JLabel("数量:");private JTextField fieldName = new JTextField(20);private JTextField fieldPrice = new JTextField(20);private JTextField fieldDiscount = new JTextField(20);private JTextField fieldNum = new JTextField(20);private JButton btSure = new JButton("修改");private JButton btCancel = new JButton("取消");private Goods goods = new Goods();public UpdateFrame(){init();}private void init(){(320, 330);("修改商品信息");(new ImageIcon("images/").getImage());(null);(null);(false);// ;(null);setText(goods);setContentPanel();}private void setContentPanel(){(30, 30, 80, 30);(130, 30, 150, 30);(30, 90, 80, 30);(130, 90, 150, 30);(30, 150, 80, 30);(130, 150, 150, 30);(30, 200, 80, 30);(130, 200, 150, 30);(30, 250, 70, 30);(210, 250, 70, 30);(lbName);(fieldName);(lbPrice);(fieldPrice);(lbDiscount);(fieldDiscount);(lbNum);(fieldNum);(btCancel);(btSure);(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) { // TODO Auto-generated method stubsetVisible(false);}});(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) { // TODO Auto-generated method stubif(null, "您确定要修改吗")==0){GoodsDao dao = new GoodsDao();()));());()));()));(goods);setVisible(false);(null, "修改成功!");}else{//}}});}public void setText(Goods goods){());()));()));()));}public Goods getGoods() {return goods;}public void setGoods(Goods goods) {= goods;}public static void main(String[] args) {UpdateFrame frame = new UpdateFrame();(true);}}数据库SQL语句:create table seller(seller_id varchar2(20) primary key,seller_name varchar2(20),pwd varchar2(20),address varchar2(200))insert into seller values('niclascage','长理专卖店','123456','湖南长沙')select * from sellerdrop table sellercommitcreate table buyer(buyer_id varchar(20) primary key,buyer_name varchar(20),pwd varchar2(20),address varchar(200))insert into buyer values('lina','林大专卖店','123456','湖南长沙')select * from buyerdrop table buyercreate table goods(goods_id int primary key,seller_id varchar(20),goods_name varchar(50),price int,discount int,num int,constraint fk_seller_id foreign key(seller_id) references seller(seller_id) )insert into goods values(1,'niclascage','Java',40,8,20)select * from goodsdrop table goodscreate table orders(order_id int primary key,goods_id int,seller_id varchar(20),buyer_id varchar(20),num int,constraint fk_goods_id foreign key(goods_id) references goods(goods_id),constraint fk_sellers_id foreign key(seller_id) references seller(seller_id),constraint fk_buyer_id foreign key(buyer_id) references buyer(buyer_id) )select * from ordersinsert into orders values(1,1,'niclascage','lina',2)drop table orders;drop table goods;drop table buyer;drop table seller;。

相关主题