伴随着信息化的发展,计算机走进了千家万户,人们的交流变得方便,方便了网民的生活!此外,伴随着卓越,京东,淘宝等网络购物平台的兴起,网络购物也被网民认可,首先,网上书店方便了网民的生活,更加便捷,足不出户便可买到心仪的书籍;其次,网上购书减少了许多中间销售代理,因此价格会比较低,对广大网民的好处是非常明显的;再者,网上书店是信息化购物,基本上所有操作都是通过计算机程序自动完成的,因此大大降低了劳力的消耗;最后,电子商务与出版发行业的结合使发展网上书店及研究网上书店具有双重意义,充分结合互联网销售的特点探索图书发行的新渠道和新模式,是对电子商务科学的充实和补充,更是对出版发行渠道和市场的开拓和创新。
数据库对于一个系统的意义是相当重要的,它关系到整个项目的整体流程,整个网站的后期维护便捷与否,从长远利益来看,数据库的设计是至关重要的。
正在开发的这个网上书店系统,是让该书店的会员用户可以能够在该网上书店购买到自己需要的图书,游客是指在此网上书店系统中没有注册的用户。游客可以通过本系统申请注册成为会员用户,享受会员用户的购买图书功能。游客和会员均可以通过本系统浏览到系统所有的图书,以及使用本系统提供的查询条件,便捷的查询到自己所需要的图书。会员用户可以通过本系统提供的一定渠道来随时查看或更改自己的会员信息。会员用户所提交的每一笔订单都会存入本系统的后台数据库中存储,会员用户可以随时查看订单信息。
本系统的所有图书都将存在后台的数据库中,并且每一本图书都是由员工添加进入系统中,员工可以更改每一本图书的各项信息,达到随时更新图书信息的功能,并且每一位员工的信息都将存入本系统的后台数据库中保存。
网上书店管理信息系统需要如下信息:
系统管理表:管理员编号,管理员密码,管理员姓名,管理员性别,管理员年龄,信息维护权利;
书籍信息表:图书编号,图书名称,图书价格,作者,出版社,出版时间;
客户信息表:用户编号,用户密码,客户姓名,客户年龄,客户电话,客户邮编,客户地址;
订单表:订单号,用户编号,图书编号,管理员编号,订单日期,总价;
要求:同一本书只能被一个用户购买,一个用户可以购买多本书。一本书对应一个编号,一个编号对应一本书。一个用户编号对应一个购书人的信息,每个购书者只有一个用户编号。
一个订单编号对应一个订单,一个订单对应一个订单编号.一个订单号对应一个管理者编号,一个管理者编号对应多个订单号.
系统管理:(管理员编号(PK),管理员密码,管理员姓名,管理员性别,管理员年龄,信息维护权力,);
书籍信息:(图书编号(PK),图书名称,图书价格,作者,出版社,出版时间);
客户信息:(用户编号(PK),用户密码,客户姓名,客户年龄,客户电话,客户邮编,客户地址);
订单(订单号(PK),图书编号(FK),管理员编号(FK),用户编号(FK),订单日期,总价)
确定数据的存储结构:使用关系二维表
数据的存放路径:D:\数据库课设
确定数据库的存储位置:D:\数据库课设
数据库的配置:sql sever 2019
Create table Book
(Book_no varchar(10) primary key,
Book_Name varchar(10),
Book_Price varchar(10),
Book_Writer varchar(10),
Book_Publisher varchar(50),
Book_Time varchar(10),)
Create table Buyer
(Buyer_no varchar(10) primary key,
Buyer_Password varchar(10) not null,
Buyer_Name varchar(10),
Buyer_Sex varchar(10),
Buyer_Age varchar(10),
Buyer_Tel varchar(50),
Buyer_Email varchar(50),
Buyer_Add varchar(50),)
Create table User
(User_no varchar(10) primary key,
User_Password varchar(50) not null,
User_Name varchar(10),
User_Sex varchar(10),
User_Age varchar(10),
User_Power varchar(50),)
Create table Order
(Order_no varchar(10) primary key,
Buyer_no varchar(10),
Book_no varchar(10),
User_no varchar(10),
Order_time datetime,
Order_price varchar(10),
Foreign key(Buyer_no) references Buyer(Buyer_no)
Foreign key(Book_no) references Book(Book_no)
Foreign key(User_no) references User(User_no))
以上关于数据库的操作基本完成.
public class DbUtil { private String dbUrl="jdbc:sqlserver://localhost:1433;databaseName=OnlineBS"; private String dbUserName="root"; private String dbPassword="root"; private String jdbcName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; /** * 获取数据库连接 * @return * @throws Exception */ public Connection getCon()throws Exception{ Class.forName(jdbcName); Connection con=DriverManager.getConnection(dbUrl,dbUserName,dbPassword); return con; } /** * 关闭数据库连接 */ public void closeCon(Connection con)throws Exception{ if(con!=null) { con.close(); } } public static void main(String[] args) { DbUtil dbutil=new DbUtil(); try { dbutil.getCon(); System.out.println("数据库连接成功!"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("数据库连接失败!"); } } }
//通用的增删改 public static void update(String sql, Object... args) { Connection connection = null; PreparedStatement ps = null; try { connection = sqlOperation.getCon(); ps = connection.prepareStatement(sql); for (int i = 0; i < args.length; i++) { ps.setObject(i + 1, args[i]); } ps.execute(); } catch (SQLException throwables) { throwables.printStackTrace(); } finally { sqlOperation.closeResource(connection, ps); } }
//通用的查 public static <T> List query(Class<T> clazz, String sql, Object... args) { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; List<T> list=new ArrayList<>(); try { con = sqlOperation.getCon(); ps = con.prepareStatement(sql); int index=1; for (int i = 0; i < args.length; ++i) { ps.setObject(i + 1, args[i]); } rs = ps.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); int col = rsmd.getColumnCount(); while (rs.next()) { T t = clazz.newInstance(); for (int i = 0; i < col; ++i) { Object colValues = rs.getObject(i + 1); String name = rsmd.getColumnLabel(i + 1); Field declaredField = t.getClass().getDeclaredField(name); declaredField.setAccessible(true); declaredField.set(t, colValues); } list.add(t); } return list; } catch (SQLException throwables) { throwables.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } finally { sqlOperation.closeResource(con, ps, rs); } return null; }
public LogOnFrame() { setResizable(false); setIconImage(Toolkit.getDefaultToolkit().getImage(LogOnFrame.class.getResource("/images/\u4E66\u7C4D2.png"))); setTitle("\u7F51\u4E0A\u4E66\u5E97"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 529, 458); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); JLabel lblNewLabel = new JLabel("\u7F51\u4E0A\u4E66\u5E97\u7BA1\u7406"); lblNewLabel.setFont(new Font("宋体", Font.BOLD, 21)); lblNewLabel.setIcon(new ImageIcon(LogOnFrame.class.getResource("/images/\u4E66\u7C4D2.png"))); JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D\uFF1A"); lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 14)); JLabel lblNewLabel_2 = new JLabel("\u5BC6 \u7801\uFF1A"); userNameTxt = new JTextField(); userNameTxt.setColumns(10); passwordTxt = new JPasswordField(); JButton btnNewButton = new JButton("\u767B \u5F55"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { loginActionPerformed(e); } }); JButton btnNewButton_1 = new JButton("\u91CD \u7F6E"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetActionPerformed(e); } }); JButton btnNewButton_2 = new JButton("\u7528\u6237\u6CE8\u518C"); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { RegActionPerformed(e); } private void RegActionPerformed(ActionEvent e) { // TODO Auto-generated method stub dispose(); new ReFrm1().setVisible(true); } }); JLabel lblNewLabel_3 = new JLabel("\u6743 \u9650"); JComboBox UsesrBoxTxt = new JComboBox(); UsesrBoxTxt.setModel(new DefaultComboBoxModel(new String[] {"\u7528\u6237", "\u7BA1\u7406\u5458"})); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup( gl_contentPane.createParallelGroup(Alignment.TRAILING) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGap(68) .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 364, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_contentPane.createSequentialGroup() .addGap(84) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE) .addGap(18) .addComponent(btnNewButton_2, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE) .addGap(18) .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(lblNewLabel_2, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(passwordTxt)) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(lblNewLabel_3, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(UsesrBoxTxt, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE)))))) .addContainerGap(83, Short.MAX_VALUE)) ); gl_contentPane.setVerticalGroup( gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGap(73) .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE) .addGap(54) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(lblNewLabel_1) .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(lblNewLabel_2) .addComponent(passwordTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(lblNewLabel_3) .addComponent(UsesrBoxTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED, 38, Short.MAX_VALUE) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(btnNewButton) .addComponent(btnNewButton_2) .addComponent(btnNewButton_1)) .addGap(51)) ); contentPane.setLayout(gl_contentPane); //设置窗口居中显示 this.setLocationRelativeTo(null); this.UsesrBoxTxt=UsesrBoxTxt; } //用户登录操作 private void loginActionPerformed(ActionEvent evt) { // TODO Auto-generated method stub String userName=this.userNameTxt.getText(); String passWord=new String(this.passwordTxt.getPassword()); if(StringUtil.isEmpty(userName)) { JOptionPane.showMessageDialog(null, "用户名不能为空"); return; } if(StringUtil.isEmpty(passWord)) { JOptionPane.showMessageDialog(null, "密码不能为空"); return; } //登录权限设置 String AuthorityName=this.UsesrBoxTxt.getSelectedItem().toString(); if(AuthorityName.equals("用户")) { //用户登录 Buyer buyer=new Buyer(userName,passWord); Connection con=null; try{ con=dbUtil.getCon(); Buyer currentUser=userDao.LoginBuyer(con, buyer); if(currentUser!=null) { dispose(); new UserFrame().setVisible(true); // JOptionPane.showMessageDialog(null, "登录成功!"); }else { JOptionPane.showMessageDialog(null, "用户名或者密码错误!"); } }catch(Exception e){ e.printStackTrace(); } }else {//管理员登录 Management mana=new Management(userName,passWord); Connection con=null; try{ con=dbUtil.getCon(); Management currentUser=userDao.Login(con, mana); if(currentUser!=null) { dispose(); new MainFrame().setVisible(true); // JOptionPane.showMessageDialog(null, "登录成功!"); }else { JOptionPane.showMessageDialog(null, "用户名或者密码错误!"); } }catch(Exception e){ e.printStackTrace(); } } } //重置操作 private void resetActionPerformed(ActionEvent evt) { // TODO Auto-generated method stub this.userNameTxt.setText(""); this.passwordTxt.setText(""); }
public class UserFrame extends JFrame { private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { UserFrame frame = new UserFrame(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public UserFrame() { setResizable(false); setTitle("\u7528\u6237\u4E3B\u754C\u9762"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 475, 334); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnNewMenu = new JMenu("\u7528\u6237\u64CD\u4F5C"); menuBar.add(mnNewMenu); JMenuItem mntmNewMenuItem = new JMenuItem("\u6309\u4E66\u540D\u67E5\u627E"); mntmNewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {//按书名查找 SelectBookname(e); } }); mnNewMenu.add(mntmNewMenuItem); JMenuItem mntmNewMenuItem_1 = new JMenuItem("\u4EF7\u683C\u964D\u5E8F\u6392\u5217"); mntmNewMenuItem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //价格降序 PriceDesc(e); } }); JMenuItem mntmNewMenuItem_3 = new JMenuItem("\u67E5\u770B\u56FE\u4E66\u4FE1\u606F"); mntmNewMenuItem_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CheckBooks2(e); } }); JMenuItem mntmNewMenuItem_4 = new JMenuItem("\u8D2D\u4E70\u56FE\u4E66"); mntmNewMenuItem_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BuyBooks(e); } }); mnNewMenu.add(mntmNewMenuItem_4); mnNewMenu.add(mntmNewMenuItem_3); mnNewMenu.add(mntmNewMenuItem_1); JMenuItem mntmNewMenuItem_2 = new JMenuItem("\u4EF7\u683C\u5347\u5E8F\u6392\u5217"); mntmNewMenuItem_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //价格升序 PriceIncrease(e); } }); mnNewMenu.add(mntmNewMenuItem_2); JMenuItem mntmNewMenuItem_5 = new JMenuItem("\u4FEE\u6539\u5BC6\u7801"); mntmNewMenuItem_5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //修改密码 ChangeCode(e); } }); mnNewMenu.add(mntmNewMenuItem_5); JMenuItem mntmNewMenuItem_6 = new JMenuItem("\u5B89\u5168\u9000\u51FA"); mntmNewMenuItem_6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //安全退出到登录界面 dispose(); new LogOnFrame().setVisible(true); } }); mnNewMenu.add(mntmNewMenuItem_6); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); JLabel lblNewLabel = new JLabel("\u6B22\u8FCE\u60A8\u4F7F\u7528\u672C\u7CFB\u7EDF"); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup( gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGap(170) .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 123, GroupLayout.PREFERRED_SIZE) .addContainerGap(168, Short.MAX_VALUE)) ); gl_contentPane.setVerticalGroup( gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGap(122) .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE) .addContainerGap(105, Short.MAX_VALUE)) ); contentPane.setLayout(gl_contentPane); //居中显示 this.setLocationRelativeTo(null); } protected void ChangeCode(ActionEvent e) { // TODO Auto-generated method stub 修改密码 dispose(); new ChangePassword().setVisible(true); } protected void BuyBooks(ActionEvent e) { // TODO Auto-generated method stub 购买书籍 dispose(); new BuyFrame().setVisible(true); } protected void CheckBooks2(ActionEvent e) { // TODO Auto-generated method stub 查看图书 dispose(); new ShowBooksUser().setVisible(true); } protected void PriceIncrease(ActionEvent e) { // TODO Auto-generated method stub 价格升序 dispose(); new PriceIncrese().setVisible(true); } protected void PriceDesc(ActionEvent e) { // TODO Auto-generated method stub 价格降序 dispose(); new PriceDesc().setVisible(true); } protected void SelectBookname(ActionEvent e) { // TODO Auto-generated method stub 转到查找页面 dispose(); new SelectBook().setVisible(true); } }
用户或管理员进入系统界面
用户操作界面
管理员操作界面
1.用户注册界面
2.用户查询书籍界面
3.用户选择购买书籍界面
4.用户查看到的书籍
7.用户修改密码
1.增加图书
2.删除图书
3.查看订单信息
4.查看图书信息