⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bank.java

📁 简易的银行卡管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		        {
		        	if(acount.equals(r.getString("counts")))
		        	{
		        		break;
		        	}
		        }
		        long n=r.getLong("deposit");
				if(text5.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(this,"请输入对方帐号!","提示",JOptionPane.ERROR_MESSAGE);
					con.close();
				}
				else
				{
					boolean b=false;
					r.beforeFirst();
					while((b=r.next())==true)
					{
						String s=r.getString("counts");
						if(s.equals(text5.getText().trim()))
						{
							if(text6.getText().trim().equals(""))
							{
								JOptionPane.showMessageDialog(this,"请输入转帐金额!","提示",JOptionPane.ERROR_MESSAGE);
								con.close();
							}
							else if(Float.valueOf(text6.getText().trim()).floatValue()<1.0)
							{
								JOptionPane.showMessageDialog(this,"转帐金额必须大于1!","提示",JOptionPane.ERROR_MESSAGE);
								con.close();
							}
							else if(n<=Long.parseLong(text6.getText().trim()))
							{
								JOptionPane.showMessageDialog(this,"对不起,余额不足!","提示",JOptionPane.ERROR_MESSAGE);
								con.close();
							}
							else
							{
								long m=r.getLong("deposit")+Long.parseLong(text6.getText().trim());
								n=n-Long.parseLong(text6.getText().trim());
								String s1="'"+s+"'";
								String s2="'"+acount+"'";
								sql.executeUpdate("UPDATE user SET deposit="+m+" WHERE counts="+s1);
								sql.executeUpdate("UPDATE user SET deposit="+n+" WHERE counts="+s2);
								JOptionPane.showMessageDialog(this,"交易成功,谢谢使用!","消息",JOptionPane.INFORMATION_MESSAGE);
								text5.setText(null);
								text6.setText(null);
								con.close();
							}
						}
					}
					if(b==false)
					{
						JOptionPane.showMessageDialog(this,"对不起,该帐号不存在!","提示",JOptionPane.ERROR_MESSAGE);
						con.close();
					}
				}
			}
			catch(SQLException e2)
			{
			}
		}
		else if(e.getSource()==button2)
		{
			text5.setText(null);
			text6.setText(null);
			card.show(p,"1");
		}
		else if(e.getSource()==button3)
		{
			try
			{
				con=DriverManager.getConnection("jdbc:odbc:superman","iceman","1986925");
		       	sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
		       	r=sql.executeQuery("SELECT * FROM user");
		       	while(r.next())
		        {
		        	if(acount.equals(r.getString("counts")))
		        	{
		        		break;
		        	}
		        }
				if(text7.getText().trim().equals(""))
				{
					JOptionPane.showMessageDialog(this,"请输入旧密码!","提示",JOptionPane.ERROR_MESSAGE);
					con.close();
				}
				else
				{
					String x=r.getString("password");
				    if(x.equals(text7.getText().trim()))
				    {
				    	if(text8.getText().trim().equals(""))
				    	{
				    		JOptionPane.showMessageDialog(this,"请输入新密码!","提示",JOptionPane.ERROR_MESSAGE);
				    		con.close();
					    }
					    else if(text8.getText().trim().length()!=6)
					    {
					    	JOptionPane.showMessageDialog(this,"新密码必须为六位!","提示",JOptionPane.ERROR_MESSAGE);
					    	con.close();
					    }
					    else
					    {
					    	if(text9.getText().trim().equals(text8.getText().trim()))
					    	{
					    		String s="'"+acount+"'";
					    		String s1="'"+text8.getText().trim()+"'";
					    		sql.executeUpdate("UPDATE user SET password="+s1+" WHERE counts="+s);
					    		JOptionPane.showMessageDialog(this,"密码修改成功!","消息",JOptionPane.INFORMATION_MESSAGE);
					    		text7.setText(null);
					    		text8.setText(null);
					    		text9.setText(null);
					    		con.close();
					    	}
					    	else
					    	{
					    		JOptionPane.showMessageDialog(this,"密码确认不一致!","提示",JOptionPane.ERROR_MESSAGE);
					    		con.close();
					    	}
					    }
					}
					else
					{
						JOptionPane.showMessageDialog(this,"对不起,旧密码不正确!","提示",JOptionPane.ERROR_MESSAGE);
						con.close();
					}
				}
			}
			catch(SQLException e3)
			{
			}
		}
		else if(e.getSource()==button4)
		{
			text7.setText(null);
			text8.setText(null);
			text9.setText(null);
			card.show(p,"1");
		}
	}
}
class control extends Frame implements ActionListener
{
	Connection con;
	Statement sql;
	ResultSet r;
	Button kaihu;Button cunqian;Button find;Button quqian;
	Button guashi;Button xiaohu;Button back;Button quit;
	Button button,button1,button2,button3,button4,button5,button6;
	Button button7,button8,button9,button10,button11,button12;
	TextField text,text1,text2,text3,text4,text5,text6,text7,text8;
	TextField text9,text10,text11,text12,text13,text14,text15,text16;
	Label label,label1,label2,label3,label4,label5,label6,label7,label8;
	Label label9,label10,label11,label12,label13,label14,label15,label16;
	Panel p,p1,p2,p3,p4,p5,p6,p7,p8;
	CardLayout mycard;
	control()
	{
		super("管理员");
		setBounds(450,250,450,250);
		setLayout(null);
		setBackground(Color.pink);
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		kaihu=new Button("开户");cunqian=new Button("存钱");find=new Button("查询");quqian=new Button("取钱");
		guashi=new Button("挂失");xiaohu=new Button("消户");back=new Button("返回");quit=new Button("退出");
		add(kaihu);kaihu.setBounds(15,50,60,30);
		add(cunqian);cunqian.setBounds(15,100,60,30);
		add(find);find.setBounds(15,150,60,30);
		add(back);back.setBounds(15,200,60,30);
		add(quqian);quqian.setBounds(375,50,60,30);
		add(guashi);guashi.setBounds(375,100,60,30);
		add(xiaohu);xiaohu.setBounds(375,150,60,30);
		add(quit);quit.setBounds(375,200,60,30);
		kaihu.addActionListener(this);
		cunqian.addActionListener(this);
		quqian.addActionListener(this);
		find.addActionListener(this);
		guashi.addActionListener(this);
		xiaohu.addActionListener(this);
		back.addActionListener(this);
		quit.addActionListener(this);
		p=new Panel();p1=new Panel();p2=new Panel();p3=new Panel();
		p4=new Panel();p5=new Panel();p6=new Panel();p7=new Panel();p8=new Panel();
		p1.add(new Label("请选择相应的操作!",Label.CENTER));
		p2.setLayout(null);
		label=new Label("姓名",Label.CENTER);text=new TextField(15);
		p2.add(label);label.setBounds(40,15,30,20);
		p2.add(text);text.setBounds(80,15,140,20);text.setBackground(Color.pink);
		label1=new Label("身份证",Label.CENTER);text1=new TextField(15);
		p2.add(label1);label1.setBounds(35,55,35,20);
		p2.add(text1);text1.setBounds(80,55,140,20);text1.setBackground(Color.pink);
		label2=new Label("存款金额",Label.CENTER);text2=new TextField(15);
		p2.add(label2);label2.setBounds(25,95,50,20);
		p2.add(text2);text2.setBounds(80,95,140,20);text2.setBackground(Color.pink);
		button=new Button("确定");button1=new Button("取消");
		p2.add(button);button.setBounds(40,135,35,20);button.setBackground(Color.pink);
		p2.add(button1);button1.setBounds(185,135,35,20);button1.setBackground(Color.pink);
		p3.setLayout(null);
		label3=new Label("帐号",Label.CENTER);text3=new TextField(15);
		p3.add(label3);label3.setBounds(40,30,30,20);
		p3.add(text3);text3.setBounds(80,30,140,20);text3.setBackground(Color.pink);
		label4=new Label("金额",Label.CENTER);text4=new TextField(15);
		p3.add(label4);label4.setBounds(40,70,30,20);
		p3.add(text4);text4.setBounds(80,70,140,20);text4.setBackground(Color.pink);
		button2=new Button("确定");button3=new Button("取消");
		p3.add(button2);button2.setBounds(40,110,35,20);button2.setBackground(Color.pink);
		p3.add(button3);button3.setBounds(185,110,35,20);button3.setBackground(Color.pink);
		p4.setLayout(null);
		label5=new Label("请输入帐号",Label.CENTER);text5=new TextField(15);
		p4.add(label5);label5.setBounds(30,40,70,20);
		p4.add(text5);text5.setBounds(110,40,120,20);text5.setBackground(Color.pink);
		button4=new Button("确定");button5=new Button("取消");
		p4.add(button4);button4.setBounds(50,100,35,20);button4.setBackground(Color.pink);
		p4.add(button5);button5.setBounds(175,100,35,20);button5.setBackground(Color.pink);
		p5.setLayout(null);
		label6=new Label("帐号",Label.CENTER);text6=new TextField(15);
		p5.add(label6);label6.setBounds(40,15,30,20);
		p5.add(text6);text6.setBounds(80,15,140,20);text6.setBackground(Color.pink);
		label7=new Label("密码",Label.CENTER);text7=new TextField(15);
		p5.add(label7);label7.setBounds(40,55,30,20);
		p5.add(text7);text7.setBounds(80,55,140,20);text7.setBackground(Color.pink);text7.setEchoChar('*');
		label8=new Label("取款金额",Label.CENTER);text8=new TextField(15);
		p5.add(label8);label8.setBounds(20,95,50,20);
		p5.add(text8);text8.setBounds(80,95,140,20);text8.setBackground(Color.pink);
		button6=new Button("确定");button7=new Button("取消");
		p5.add(button6);button6.setBounds(40,135,35,20);button6.setBackground(Color.pink);
		p5.add(button7);button7.setBounds(185,135,35,20);button7.setBackground(Color.pink);
		p6.setLayout(null);
		label9=new Label("帐号",Label.CENTER);text9=new TextField(15);
		p6.add(label9);label9.setBounds(40,35,30,20);
		p6.add(text9);text9.setBounds(80,35,140,20);text9.setBackground(Color.pink);
		label10=new Label("身份证",Label.CENTER);text10=new TextField(15);
		p6.add(label10);label10.setBounds(20,75,40,20);
		p6.add(text10);text10.setBounds(80,75,140,20);text10.setBackground(Color.pink);
		button8=new Button("挂失");button9=new Button("解挂");button10=new Button("取消");
		p6.add(button8);button8.setBounds(40,125,35,20);button8.setBackground(Color.pink);
		p6.add(button9);button9.setBounds(115,125,35,20);button9.setBackground(Color.pink);
		p6.add(button10);button10.setBounds(185,125,35,20);button10.setBackground(Color.pink);
		p7.setLayout(null);
		label11=new Label("请输入帐号",Label.CENTER);text11=new TextField(15);
		label12=new Label("请输入密码",Label.CENTER);text12=new TextField(15);
		button11=new Button("确定");button12=new Button("取消");
		p7.add(label11);label11.setBounds(30,30,60,20);
		p7.add(text11);text11.setBounds(100,30,130,20);text11.setBackground(Color.pink);
		p7.add(label12);label12.setBounds(30,70,60,20);
		p7.add(text12);text12.setBounds(100,70,130,20);text12.setBackground(Color.pink);text12.setEchoChar('*');
		p7.add(button11);button11.setBounds(50,120,35,20);button11.setBackground(Color.pink);
		p7.add(button12);button12.setBounds(175,120,35,20);button12.setBackground(Color.pink);
		p8.setLayout(null);
		label13=new Label("姓名",Label.CENTER);text13=new TextField(15);
		label14=new Label("帐号",Label.CENTER);text14=new TextField(15);
		label15=new Label("余额",Label.CENTER);text15=new TextField(15);
		label16=new Label("身份证",Label.CENTER);text16=new TextField(15);
		p8.add(label13);label13.setBounds(35,15,30,20);
		p8.add(text13);text13.setBounds(75,15,140,20);text13.setBackground(Color.pink);
		p8.add(label14);label14.setBounds(35,55,30,20);
		p8.add(text14);text14.setBounds(75,55,140,20);text14.setBackground(Color.pink);
		p8.add(label15);label15.setBounds(35,95,30,20);
		p8.add(text15);text15.setBounds(75,95,140,20);text15.setBackground(Color.pink);
		p8.add(label16);label16.setBounds(35,135,35,20);
		p8.add(text16);text16.setBounds(75,135,140,20);text16.setBackground(Color.pink);
		button.addActionListener(this);
		button1.addActionListener(this);
		button2.addActionListener(this);
		button3.addActionListener(this);
		button4.addActionListener(this);
		button5.addActionListener(this);
		button6.addActionListener(this);
		button7.addActionListener(this);
		button8.addActionListener(this);
		button9.addActionListener(this);
		button10.addActionListener(this);
		button11.addActionListener(this);
		button12.addActionListener(this);
		mycard=new CardLayout();
		p.setLayout(mycard);
		p.add("1",p1);p.add("2",p2);p.add("3",p3);p.add("4",p4);
		p.add("5",p5);p.add("6",p6);p.add("7",p7);p.add("8",p8);
		add(p);p.setBounds(90,45,250,200);
		setVisible(true);
		setResizable(false);			
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==kaihu)
		{
			mycard.show(p,"2");
		}
		else if(e.getSource()==cunqian)
		{
			mycard.show(p,"3");
		}
		else if(e.getSource()==find)
		{
			mycard.show(p,"4");
		}
		else if(e.getSource()==quqian)
		{
			mycard.show(p,"5");
		}
		else if(e.getSource()==guashi)
		{
			mycard.show(p,"6");
		}
		else if(e.getSource()==xiaohu)
		{
			mycard.show(p,"7");
		}
		else if(e.getSource()==back)
		{
			dispose();
			denglu redenglu=new denglu();
		}
		else if(e.getSource()==quit)
		{
			System.exit(0);
		}
		else if(e.getSource()==button)
		{
			try
			{
				con=DriverManager.getConnection("jdbc:odbc:superman","iceman","1986925");
			    sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			    r=sql.executeQuery("SELECT * FROM user");
			    if(text.getText().trim().equals(""))
			    {
			    	JOptionPane.showMessageDialog(this,"姓名不能为空!","提示",JOptionPane.ERROR_MESSAGE);
			    	con.close();
			    }
			  	else if(text1.getText().trim().equals(""))
			    {
			    	JOptionPane.showMessageDialog(this,"身份证不能为空!","提示",JOptionPane.ERROR_MESSAGE);
			    	con.close();
			    }
			    else if((text1.getText().trim()).length()!=18)
			    {
			    	JOptionPane.showMessageDialog(this,"身份证号必须为18位!","提示",JOptionPane.ERROR_MESSAGE);
			    	con.close();
			    }
			    else if(text2.getText().trim().equals(""))
			    {
			    	JOptionPane.showMessageDialog(this,"存款金额不能为空!","提示",JOptionPane.WARNING_MESSAGE);
			    	con.close();
			    }
			    else if(Float.valueOf(text2.getText().trim()).floatValue()<1.0)
			    {
			    	JOptionPane.showMessageDialog(this,"存款金额不能小于1!","提示",JOptionPane.ERROR_MESSAGE);
			    	con.close();
			    }
			    else
			    {
			    	r.last();
			    	String s=r.getString("counts");
			    	long i=Long.parseLong(s)+10;
			    	String s1="'"+text.getText().trim()+"'";
			    	String s2="'"+text1.getText().trim()+"'";
			    	float t=Float.valueOf(text2.getText().trim()).floatValue();
			    	sql.executeUpdate("INSERT INTO user VALUES ("+i+",888888,"+s1+","+s2+","+t+",1)");
			    	JOptionPane.showMessageDialog(this,"恭喜您成为本系统的普通用户。您的帐号为"+i+",密码为888888!","提示",JOptionPane.INFORMATION_MESSAGE);
			    	text.setText("");
			    	text1.setText("");
			    	text2.setText("");
			    	con.close();
			    }
			}
			catch(SQLException e2)
			{
			}
		}
		else if(e.getSource()==button1)
		{
			text.setText("");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -