小程序--VIP管理系统

又是期末,做了一个基于Java界面的数据库课设--VIP管理系统

显示效果及表的设计如下图


/***
 * @author 逸川同学
 */
public class Main {
	public static void main(String[] args) {
		new MyJframe();
	}
}
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MyJframe extends JFrame {
	private static final long serialVersionUID = 1L;

	public MyJframe() {
		super("VIP Governor");
		setBounds(300, 200, 500, 400);
		setLayout(new GridLayout(1, 2));
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		JPanel leftJpanel = new JPanel();
		final JPanel rightJpanel = new JPanel();
		final Container container = getContentPane();
		container.add(leftJpanel);// 左边功能选择面板
		container.add(rightJpanel);// 右边功能实现面板
		leftJpanel.setLayout(new GridLayout(6, 1));

		JButton addUserBut = new JButton("添加会员");
		leftJpanel.add(addUserBut);
		addUserBut.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				rightJpanel.removeAll();
				rightJpanel.setLayout(new GridLayout(6, 1));

				JLabel cnoLabel = new JLabel("卡号");
				JTextField cnotField = new JTextField(18);
				JPanel cnoPanel = new JPanel();
				cnoPanel.setLayout(new GridLayout(1, 2));
				cnoPanel.add(cnoLabel);
				cnoPanel.add(cnotField);

				JLabel moneyLabel = new JLabel("金额");
				JTextField montField = new JTextField(18);
				JPanel monPanel = new JPanel();
				monPanel.setLayout(new GridLayout(1, 2));
				monPanel.add(moneyLabel);
				monPanel.add(montField);

				JLabel IDLabel = new JLabel("ID");
				JTextField IDtField = new JTextField(18);
				JPanel IDPanel = new JPanel();
				IDPanel.setLayout(new GridLayout(1, 2));
				IDPanel.add(IDLabel);
				IDPanel.add(IDtField);

				JLabel nameLabel = new JLabel("姓名");
				JTextField nametField = new JTextField(18);
				JPanel namePanel = new JPanel();
				namePanel.setLayout(new GridLayout(1, 2));
				namePanel.add(nameLabel);
				namePanel.add(nametField);

				JLabel phoneLabel = new JLabel("电话");
				JTextField phonetField1 = new JTextField(18);
				JPanel phonePanel = new JPanel();
				phonePanel.setLayout(new GridLayout(1, 2));
				phonePanel.add(phoneLabel);
				phonePanel.add(phonetField1);

				JButton yesbtn = new JButton("确定");
				rightJpanel.add(cnoPanel);
				rightJpanel.add(monPanel);
				rightJpanel.add(IDPanel);
				rightJpanel.add(namePanel);
				rightJpanel.add(phonePanel);
				rightJpanel.add(yesbtn);

				yesbtn.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						// 信息
						String cno = cnotField.getText();
						int money = 0;
						try {
							money = Integer.parseInt(montField.getText());
						} catch (NumberFormatException e1) {
							//有异常,不需要处理
						}
						String ID = IDtField.getText();
						String name = nametField.getText();
						String phone = phonetField1.getText();
						int addUser = -1;
						if (cno != null && ID != null && name != null && phone != null) {
							addUser = ControlDB.AddUser(new Person(cno, money, ID, name, phone));
						}
						if (addUser == 2) {
							JOptionPane.showMessageDialog(null, "添加成功");
						}else{
							JOptionPane.showMessageDialog(null, "该用户已存在或其他错误,添加失败");
						}
					}
				});
				setVisible(true);
			}
		});

		// 根据卡号查询会员的信息
		JButton searchBut = new JButton("查询会员信息");
		leftJpanel.add(searchBut);
		searchBut.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				rightJpanel.removeAll();
				rightJpanel.setLayout(new GridLayout(6, 1));
				JPanel panel = new JPanel();
				panel.setLayout(new GridLayout(1, 2));
				JLabel cnoLabel = new JLabel("输入卡号");
				JTextField cnoTextField = new JTextField(18);
				panel.add(cnoLabel);
				panel.add(cnoTextField);
				rightJpanel.add(panel);
				JButton yesbtn = new JButton("确定");
				rightJpanel.add(yesbtn);

				JTextField IDField = new JTextField(18);// ID
				rightJpanel.add(IDField);
				JTextField nameField = new JTextField(18);// 姓名
				rightJpanel.add(nameField);
				JTextField moneyField = new JTextField(18);// 金额
				rightJpanel.add(moneyField);
				JTextField phoneField = new JTextField(18);// 电话
				rightJpanel.add(phoneField);
				
				//点击确认按钮进行 数据库查询
				yesbtn.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						//有数据输入的时候才查询
						if(cnoTextField != null && !cnoTextField.getText().equals("")){
							Person user = ControlDB.SearchUser(cnoTextField.getText());
							if(user.getID()!=""){
								IDField.setText("ID = "+user.getID());
								nameField.setText("姓名 "+user.getName());
								moneyField.setText("金额 "+user.getMoney());
								phoneField.setText("电话 "+user.getPhone());
							}
						}
					}
				});
				setVisible(true);
			}
		});

		//输入卡号进行消费
		JButton consumeBut = new JButton("消费");
		leftJpanel.add(consumeBut);
		consumeBut.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				rightJpanel.removeAll();
				rightJpanel.setLayout(new GridLayout(3, 1));
				// 输入卡号框
				JPanel cnoPanel = new JPanel();
				cnoPanel.setLayout(new GridLayout(1, 2));
				JLabel cnoLabel = new JLabel("卡号 ");
				JTextField cnotField = new JTextField(18);
				cnoPanel.add(cnoLabel);
				cnoPanel.add(cnotField);
				rightJpanel.add(cnoPanel);
				//确定按钮
				JButton yesbtn = new JButton("确定");
				rightJpanel.add(yesbtn);
				//信息
				JPanel monPanel = new JPanel();
				monPanel.setLayout(new GridLayout(1, 2));
				JLabel moneyleft = new JLabel("消费后金额");
				JTextField montField = new JTextField(18);
				monPanel.add(moneyleft);
				monPanel.add(montField);
				rightJpanel.add(monPanel);
				
				yesbtn.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						//调用数据库
						if(cnotField != null && cnotField.getText()!=""){
							int mon = ControlDB.consum(cnotField.getText());
							if(mon>0){
								montField.setText(""+mon);
							}else {
								JOptionPane.showMessageDialog(null, "没有该会员或该会员金额不足!");
							}
						}
					}
				});
				setVisible(true);
			}

		});

		JButton changeBut = new JButton("修改会员信息");
		leftJpanel.add(changeBut);
		changeBut.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				rightJpanel.removeAll();
				rightJpanel.setLayout(new GridLayout(4, 1));
				
				// 输入卡号框
				JPanel cnoPanel = new JPanel();
				cnoPanel.setLayout(new GridLayout(1, 2));
				JLabel cnoLabel = new JLabel("输入需要修改的卡号 ");
				JTextField cnotField = new JTextField(18);
				cnoPanel.add(cnoLabel);
				cnoPanel.add(cnotField);
				
				// 修改姓名框
				JPanel namePanel = new JPanel();
				namePanel.setLayout(new GridLayout(1, 2));
				JLabel nameLabel = new JLabel("姓名修改为 ");
				JTextField nameField = new JTextField(18);
				namePanel.add(nameLabel);
				namePanel.add(nameField);
				
				// 修改电话号码框
				JPanel phonePanel = new JPanel();
				phonePanel.setLayout(new GridLayout(1, 2));
				JLabel phoneLabel = new JLabel("电话修改为");
				JTextField phoneField = new JTextField(18);
				phonePanel.add(phoneLabel);
				phonePanel.add(phoneField);
				
				//确定
				JButton yesBtn = new JButton("确定");

				rightJpanel.add(cnoPanel);
				rightJpanel.add(namePanel);
				rightJpanel.add(phonePanel);
				rightJpanel.add(yesBtn);
				
				//监听,数据库修改
				yesBtn.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if (!cnotField.getText().equals("") && !nameField.getText().equals("") && !phoneField.getText().equals("")) {
							int i = ControlDB.change(cnotField.getText(), nameField.getText(), phoneField.getText());
							if(i==1){
								JOptionPane.showMessageDialog(null, "修改成功");
							}else {
								JOptionPane.showMessageDialog(null, "修改失败");
							}
						}
					}
				});
				setVisible(true);
			}
		});

		//根据会员卡号进行充值
		JButton rechargeBut = new JButton("会员充值");
		leftJpanel.add(rechargeBut);
		rechargeBut.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				rightJpanel.removeAll();
				rightJpanel.setLayout(new GridLayout(3, 1));
	
				JPanel phane2 = new JPanel();
				phane2.setLayout(new GridLayout(1, 2));
				JLabel labe2 = new JLabel("充值卡号");
				JTextField count2 = new JTextField(18);
				phane2.add(labe2);
				phane2.add(count2);
				rightJpanel.add(phane2);
				
				JPanel phanel = new JPanel();
				phanel.setLayout(new GridLayout(1, 2));
				JLabel cnoLabel = new JLabel("充值金额");
				JTextField count1 = new JTextField(10);
				phanel.add(cnoLabel);
				phanel.add(count1);
				rightJpanel.add(phanel);
				
				JButton yesbtn = new JButton("确定");
				rightJpanel.add(yesbtn);
				yesbtn.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if(count1.getText()!=""&&!count2.getText().equals("")){
							int mon  = 0;
							try {
								mon = Integer.parseInt(count1.getText());
							} catch (NumberFormatException e1) {
							}
							int i = ControlDB.charge(count2.getText(),mon);
							if(i>0){
								JOptionPane.showMessageDialog(null, "充值成功");
							}else {
								JOptionPane.showMessageDialog(null, "充值失败");
							}
						}
					}
				});
				setVisible(true);
			}
		});

		JButton outBut = new JButton("退卡");
		leftJpanel.add(outBut);
		outBut.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				rightJpanel.removeAll();
				rightJpanel.setLayout(new GridLayout(2, 1));

				JPanel cnoPanel = new JPanel();
				cnoPanel.setLayout(new GridLayout(1, 2));
				JLabel cnoLabel = new JLabel("卡号");
				JTextField cnotField = new JTextField(18);
				cnoPanel.add(cnoLabel);
				cnoPanel.add(cnotField);
				rightJpanel.add(cnoPanel);

				JButton yesbtn = new JButton("确定");
				rightJpanel.add(yesbtn);
				
				//添加监听,连接数据库
				yesbtn.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						if(cnotField.getText()!=null&&!cnotField.getText().equals("")){
							int i = ControlDB.out(cnotField.getText());
							if(i==2){
								JOptionPane.showMessageDialog(null, "退卡成功");
							}else {
								JOptionPane.showMessageDialog(null, "退卡失败");
							}
						}
					}
				});
				setVisible(true);
			}
		});
		setVisible(true);
	}
}
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ControlDB {
	// 添加用户
	public static int AddUser(Person person) {
		String cno = person.getCno();
		int money = person.getMoney();
		String ID = person.getID();
		String name = person.getName();
		String phone = person.getPhone();
		Connection connection = DBUtils.getConnection();
		Statement statement = null;
		int i = -1;
		try {
			statement = connection.createStatement();
			String sqlCard = "INSERT INTO Card VALUES('" + cno + "',"  + money + ",'" + ID+ "')";
			String sqlInform = "INSERT INTO Inform VALUES('" + ID + "','" + name + "','" + phone+ "')";
			i = statement.executeUpdate(sqlCard);
			i += statement.executeUpdate(sqlInform);
		} catch (SQLException e) {
			e.printStackTrace();
		}/* finally {
			DBUtils.close(connection, statement);
		}*/
		return i;
	}

	// 根据卡号查询会员的信息
	// 返回一个Person
	public static Person SearchUser(String string) {
		String cno = string;// 卡号
		int money = 0;
		String ID = "";
		String name = "";
		String phone = "";
		Connection connection = DBUtils.getConnection();
		Statement statement = null;
		try {
			statement = connection.createStatement();
			//连表查询
			String sql ="SELECT money,card.id,name,phone FROM card,inform WHERE card.id = inform.id AND cno LIKE '" + cno+"'";
			ResultSet executeQuery = statement.executeQuery(sql);
			if(executeQuery.next()){
				money = executeQuery.getInt("money");
				ID = executeQuery.getString("ID");
				name = executeQuery.getString("name");
				phone = executeQuery.getString("phone");
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} /*finally {
			DBUtils.close(connection, statement);
		}*/
		return new Person(cno, money, ID, name, phone);
	}

	// 输入卡号进行消费
	// 返回消费一次之后的余额
	public static int consum(String string) {
		String cno = string;// 卡号
		int money = -1;
		Connection connection = DBUtils.getConnection();
		Statement statement = null;
		try {
			statement = connection.createStatement();
			//假设一次消费10元,传过来的money不足10元就返回-1表示金额不足,,并且不做下面的操作
			//否则返回消费后的金额
			String sqlSearch = "SELECT money FROM Card WHERE Cno like " + cno;
			ResultSet resultSet = statement.executeQuery(sqlSearch);
			if(resultSet.next()){
				money = resultSet.getInt("money");
			}
			if((money=money-10)>0){
				String sql = "UPDATE Card SET Money = " + money + " WHERE Cno like " + cno;
				statement.execute(sql);
			}
		} catch (SQLException e) {
//			e.printStackTrace();
		} /*finally {
			DBUtils.close(connection, statement);
		}*/
		return money;
	}

	// 根据cno 修改会员信息(name phone)
	public static int  change(String cno,String name,String phone) {
		Connection connection = DBUtils.getConnection();
		Statement statement = null;
		int i = 0;
		try {
			statement = connection.createStatement();
			
			String sql1 =  "UPDATE inform SET name = '"+name+"'  ,phone = '"+phone+"' "
					+ "WHERE ID IN(SELECT ID FROM card WHERE card.Cno LIKE  '"+cno+"' )";
			i = statement.executeUpdate(sql1);
		} catch (SQLException e) {
			e.printStackTrace();
		} /*finally {
			DBUtils.close(connection, statement);
		}*/
		return i;
	}
	
	//根据卡号充值
	public static int charge(String cno,int money){
		int i = 0;
		Connection connection = DBUtils.getConnection();
		Statement statement = null;
		try {
			statement = connection.createStatement();
			String sqlse = "SELECT money from card WHERE cno LIKE '"+cno+"'";
			ResultSet query = statement.executeQuery(sqlse);
			if(query.next()){
				money += query.getInt("money");
				String sql =  "UPDATE card SET Money = "+money+" WHERE cno LIKE '"+cno+"'";
				i = statement.executeUpdate(sql);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}
	
	//根据卡号进行退卡
	public static int out(String cno){
		int i = 0;
		Connection connection = DBUtils.getConnection();
		Statement statement = null;
		try {
			statement = connection.createStatement();
			//连表,先删掉外键的那个表的一行,在删主键的一行
			String sql1 = "DELETE inform FROM inform, card WHERE card.cno LIKE '"+cno+"' AND card.ID=inform.ID";
			String sql2 = "DELETE card FROM card WHERE card.cno LIKE '"+cno+"'";
			i = statement.executeUpdate(sql1);
			i += statement.executeUpdate(sql2);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtils {
	// 构造方法私有
	private DBUtils() {
	}

	// 连接
	private static Connection connection;

	// 静态块,执行一次
	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/ISwing?useUnicode=true&characterEncoding=utf-8";
			String username = "root";
			String password = "";
			connection = DriverManager.getConnection(url, username, password);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	// 获取连接
	public static Connection getConnection() {
		return connection;
	}

	// 两个关闭方法
	public static void close(Connection connection, Statement statement, ResultSet rSet) {
		try {
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if (statement != null) {
				statement.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if (rSet != null) {
				rSet.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void close(Connection connection, Statement statement) {
		try {
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if (statement != null) {
				statement.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}




public class Person {
	private String cno;
	private int money;
	private String ID;
	private String name;
	private String phone;
	
	public Person(String cno, int money, String ID, String name, String phone) {
		super();
		this.cno = cno;
		this.money = money;
		this.ID = ID;
		this.name = name;
		this.phone = phone;
	}
	
	public Person() {
	}

	public String getCno() {
		return cno;
	}
	public void setCno(String cno) {
		this.cno = cno;
	}
	public int getMoney() {
		return money;
	}
	public void setMoney(int money) {
		this.money = money;
	}
	public String getID() {
		return ID;
	}
	public void setID(String iD) {
		ID = iD;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
}


  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Uni-app可以用于开发商城后台管理系统。通过使用Uni-app,开发者可以一次编码,同时生成多个应用程序,包括iOS、Android、H5、小程序等。开发者只需要使用Vue.js框架进行开发,而不需要考虑不同平台的差异,大大降低了应用程序的开发难度和复杂度。Uni-app的特点是使用Vue.js作为开发语言,可以在不同的移动端平台上共享组件库和业务逻辑代码,提高了开发效率和代码重用率。此外,Uni-app还提供了丰富的原生API和插件来实现更多功能。对于商城后台管理系统,开发者可以利用Uni-app的跨平台特性,快速构建多端应用,包括Web、iOS、Android、H5、小程序等,实现商城后台管理系统的功能和界面。全局配置文件page.json和pages.json可以用来对Uni-app进行全局配置,决定页面文件的路径、窗口样式、原生的导航栏、底部的原生tabbar等,类似于微信小程序中的app.json的页面管理部分。通过配置这些文件,开发者可以灵活地管理商城后台管理系统的页面和功能。 #### 引用[.reference_title] - *1* *2* *3* [uni-app介绍](https://blog.csdn.net/weixin_63526054/article/details/130849946)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值