Java 项目 个人帐目管理系统

来源:互联网 发布:淘宝客推广api 申请 编辑:程序博客网 时间:2024/06/03 21:21

目录

第一部分项目描述 3

1.1项目目的 3

第二部分需求和开发环境 3

2.1使用技术和开发环境 3

2.2项目需求 3

2.3详细功能 3

2.4 E-R 3

2.5数据库的设计 3

2.5.1数据表的设计 3

2.5.2数据库约束的设计 4

2.5.3数据库序列的设计 4

2.5.4数据库索引的设计 4

2.5.5数据库视图的设计 5

2.5.6数据库触发器的设计 5

2.5.7数据库函数的设计 5

2.5.8数据库存储过程的设计 6

2.6业务层设计 6

2.6.1 xx业务 6

2.6.2 xx业务 6

2.6.3 xx业务 6

2.7展示层(界面)设计 6

2.7.1 xx界面 7

2.7.2 xx界面 7

2.7.3 xx界面 7

第三部分项目总结 7

 


第一部分项目描述

1.1项目目的

开发一个账目明细管理软件,用于记录和查询个人的账目情况,记录的内容包括:账目类型(支出/收入)、账目金额、记录日期(日期格式为:yyyy-MM-dd)和备注信息。

第二部分需求和开发环境

2.1使用技术和开发环境

Oracle11g

2.2项目需求

教学质量是学校生存与发展的生命线,不断提高课堂教学水平是学校和每一位教师的共同心愿。及时了解课堂教学的主体—学生对教学情况的评价及建议,有利于教师发现自己教学中的优点以及不足,从而进一步改进教学方法,提高教学水平。为了更好的提高教学水平,建立学校与学员的更好勾通,院领导研究决定研发本系统,并提供考核内容管理、反馈项目管理、反馈表管理、数据统计分析等主要功能,本阶段案例主要以考核内容管理为主要分析目标。

2.3详细功能

1、添加账目

添加账目时,首先,系统自动生成一个账目流水编号,如果为第一条账目记录,则编号为预设值“1”;如果不是第一条记录,则获取最后一条账目记录,取出编号并加一,即为新账目记录编号。然后需要用户输入账目信息,包括账目类型、金额、日期和备注,其中日期为系统自动生成,完成后账目信息被保存到一个文件中,并反馈给用户一条账目信息。

2、修改账目

账目记录修改功能描述:首先,提示用户输入要修改的账目记录编号,并进行有效性验证。然后显示此笔账目记录详细信息,提示修改(日期不修改)。修改完成后,将此账目记录保存到账目记录文件中。

3、删除账目

账目记录删除功能描述:首先,提示用户输入要修改的账目记录编号,并进行有效性验证。然后显示此笔账目记录详细信息,提示删除。待用户确认后,将此记录从账目记录文件中删除。

4、查询账目

查询账目功能包括:查询单个和查询全部。

查询单个账目信息:首先,提示用户输入要修改的账目记录编号,并进行有效性验证。然后显示此笔账目记录详细信息

查询全部账目信息:显示全部账目记录详细信息,如果没有账目信息,则提示没有账目记录。

 

2.5数据库的设计

2.5.1 数据表的设计

1 个人账目表

表名

TALLY(个人账目表)

列名

描述

数据类型

/非空

约束条件

TID

ID编号

number

非空

主键,标识列

TTYPE

类型名称

Varchar2(20)

非空

 

MONEY

金钱

Number4

非空

 

DATE

时间

date

 

默认

REMARK

备注

Varchar2(20)

 

 

 

2.5.3 数据序列的设计

功能TID进行插入自增

实现CREATE SEQUENCE SEQ_TALLY;

2.5.6数据触发器的设计

功能当进行插入数据的时候,TID进行自增

实现CREATE OR REPLACE TRIGGER TRI_TALLY

BEFORE INSERT OR UPDATE  ON TALLY FOR EACH ROW

BEGIN

select seq_tally.nextval into :New."tid" from dual;

END;

2.6业务层设计

//数据库操作
package com.handson.entity;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Statement;import java.util.Scanner;import javax.swing.JOptionPane;import com.tcl.util.DBcon;public class DBinsert {public static void Register(String Itype,String Imoney,String Iremark){    DBcon dBcon=new DBcon();    Connection conn=dBcon.getConn();if(conn != null){try {Statement sm =  conn.createStatement();//根据连接获取一个执行sql语句的对象 int n = sm.executeUpdate("insert into TALLY (TTYPE,MONEY,REMARK) VALUES('"+Itype+"','"+Imoney+"','"+Iremark+"')"); if(n>0){JOptionPane.showMessageDialog(null, "数据添加成功!");  }else{JOptionPane.showMessageDialog(null, "数据添加失败!");  }} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}


//Swing 界面
package com.handson.services;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import com.handson.entity.DBinsert;import com.tcl.util.DBcon;public class SWinsert extends JFrame{JTextField type = new JTextField(10);//文本框JTextField money = new JTextField(10);JTextField remark = new JTextField(10); String Itype,Imoney,Iremark;Box baseBox,boxV1,boxV2;//面板JButton btn1 = new JButton("OK");public SWinsert(){this.setBounds(100,100,310,260);//窗体大小this.setTitle("ADD");this.setLayout(new java.awt.FlowLayout());init();this.setVisible(true);this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口}void init(){boxV1 = Box.createVerticalBox();boxV1.add(new JLabel("TYPE:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("MONEY:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("REMARK:"));boxV1.add(Box.createVerticalStrut(8));boxV2 = Box.createVerticalBox();boxV2.add(type);boxV2.add(Box.createVerticalStrut(8));boxV2.add(money);boxV2.add(Box.createVerticalStrut(8));boxV2.add(remark);boxV2.add(Box.createVerticalStrut(8));baseBox = Box.createHorizontalBox();baseBox.add(boxV1);boxV2.add(Box.createVerticalStrut(10));baseBox.add(boxV2);add(baseBox);add(btn1);btn1.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {            // TODO Auto-generated method stub           Itype = type.getText();Imoney = money.getText();Iremark = remark.getText();//判断是否为空,因为不能插入空数据if(!Itype.equals("")&&!Imoney.equals("")&&!Iremark.equals("")){      try {Integer.parseInt(Imoney); // 只能为正整数DBcon dBcon=new DBcon();    Connection con=dBcon.getConn();        if(con==null){System.out.println("数据库插入连接失败");}else{System.out.println("数据库插入连接成功");DBinsert.Register(Itype,Imoney,Iremark);type.setText("");money.setText("");remark.setText("");}                } catch (Exception e2) {// TODO: handle exceptionJOptionPane.showMessageDialog(null, "Money格式不正确,请重新输入!");  money.setText("");}}else{JOptionPane.showMessageDialog(null, "数据不能为空,请补充完整!");  }}    });}}

2.6.2 修改账目业务

//Swing 界面
package com.handson.services;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import com.handson.entity.DBupdate;import com.tcl.util.DBcon;public class SWupdate extends JFrame{JTextField id = new JTextField(10);JTextField type = new JTextField(10);JTextField money = new JTextField(10);JTextField remark = new JTextField(10);String Uid,Utype,Umoney,Uremark;Box baseBox,boxV1,boxV2;JButton btn1 = new JButton("OK");public SWupdate(){this.setBounds(100,100,310,260);this.setTitle("UPDATE");this.setLayout(new java.awt.FlowLayout());init();this.setVisible(true);this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口}void init(){boxV1 = Box.createVerticalBox();boxV1.add(new JLabel("ID:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("TYPE:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("MONEY:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("REMARK:"));boxV1.add(Box.createVerticalStrut(8));boxV2 = Box.createVerticalBox();boxV2.add(id);boxV2.add(Box.createVerticalStrut(8));boxV2.add(type);boxV2.add(Box.createVerticalStrut(8));boxV2.add(money);boxV2.add(Box.createVerticalStrut(8));boxV2.add(remark);boxV2.add(Box.createVerticalStrut(8));baseBox = Box.createHorizontalBox();baseBox.add(boxV1);boxV2.add(Box.createVerticalStrut(10));baseBox.add(boxV2);add(baseBox);add(btn1);//按钮btn1.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {            // TODO Auto-generated method stub           Uid = id.getText();        Utype = type.getText();Umoney = money.getText();Uremark = remark.getText();     if (!Uid.equals("")&&!Utype.equals("")&&!Umoney.equals("")&&!Uremark.equals("")) {     try {Integer.parseInt(Umoney); // 只能为正整数 DBcon dBcon=new DBcon();  Connection con=dBcon.getConn();        if(con==null){System.out.println("数据库更新连接失败");}else{System.out.println("数据库更新连接成功");DBupdate.update(Uid,Utype,Umoney,Uremark);id.setText("");        type.setText("");money.setText("");remark.setText("");}   } catch (Exception e2) {// TODO: handle exceptionJOptionPane.showMessageDialog(null, "Money格式不正确,请重新输入!");  money.setText("");}}           else {     JOptionPane.showMessageDialog(null, "数据不能为空,请补充完整!");  }        }    });}}

数据库更新操作
package com.handson.entity;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Statement;import java.util.Scanner;import javax.swing.JOptionPane;import com.tcl.util.DBcon;public class DBupdate {public static void update(String Uid,String Utype,String Umoney,String Uremark){ DBcon dBcon=new DBcon();    Connection conn=dBcon.getConn();if(conn != null){try {Statement sm = conn.createStatement();int n = sm.executeUpdate("update TALLY set TTYPE= '" + Utype+ "',MONEY='"+Umoney+"',REMARK='" + Uremark+ "'where TID='" + Uid+ "'"); if(n>0){ JOptionPane.showMessageDialog(null, "Update Success!");  }else{JOptionPane.showMessageDialog(null, "ID信息不符合,请确认后重新输入");  }} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}

2.6.3 删除账目业务

Swing 界面
package com.handson.services;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import com.handson.entity.DBdelete;import com.tcl.util.DBcon;public class SWdelete extends JFrame{JTextField id = new JTextField(10);String Did;Box baseBox,boxV1,boxV2;//面板JButton btn1 = new JButton("OK");public SWdelete(){this.setBounds(100,100,310,260);this.setTitle("DELETE");this.setLayout(new java.awt.FlowLayout());//容器init();this.setVisible(true);this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口}void init(){boxV1 = Box.createVerticalBox();boxV1.add(new JLabel("ID:"));boxV2 = Box.createVerticalBox();boxV2.add(id);baseBox = Box.createHorizontalBox();baseBox.add(boxV1);boxV2.add(Box.createVerticalStrut(10));baseBox.add(boxV2);add(baseBox);//容器add(btn1);btn1.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {            // TODO Auto-generated method stub           Did = id.getText();        if (!id.equals("")) {        try {        Integer.parseInt(Did); // 只能为正整数        DBcon dBcon=new DBcon();    Connection con=dBcon.getConn();        if(con==null){System.out.println("数据库删除连接失败");}else{System.out.println("数据库删除连接成功");DBdelete.Delete(Did);id.setText("");}      } catch (Exception e2) {// TODO: handle exceptionJOptionPane.showMessageDialog(null, "ID格式不正确,请重新输入!");  }        }        else{JOptionPane.showMessageDialog(null, "数据不能为空,请补充完整!");  }        }    });}}

数据库删除操作
package com.handson.entity;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.SQLException;import javax.swing.JOptionPane;import com.tcl.util.DBcon;public class DBdelete {public static void Delete(String Did){ DBcon dBcon=new DBcon();  Connection conn=dBcon.getConn();if(conn== null){dBcon.getConn();}PreparedStatement sm = null;//PreparedStatement用于使用绑定变量重用执行计划try {String sql = "delete from TALLY where TID = ?"; sm =  conn.prepareStatement(sql); sm.setString(1, Did);//给第一个问号赋值 int n = sm.executeUpdate(); if(n>0){ JOptionPane.showMessageDialog(null, "Delete Success!");  }else{JOptionPane.showMessageDialog(null, "请输入正确的ID!");  }} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

2.6.4 查询账目业务

查询单个账目信息:

Swing 界面
package com.handson.services;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import javax.swing.Box;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import com.handson.entity.DBselect;import com.tcl.util.DBcon;public class SWselect extends JFrame{JTextField id = new JTextField(10);//要查询的卡号JTextField type = new JTextField(10);JTextField money = new JTextField(10);JTextField date = new JTextField(10);JTextField remark = new JTextField(10);JLabel cxjg = new JLabel();//显示结果标签Box baseBox,boxV1,boxV2;JButton btn1 = new JButton("查询");public SWselect(){this.setBounds(100,100,310,260);this.setTitle("查询账目");this.setLayout(new java.awt.FlowLayout());init();this.setVisible(true);this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口}void init(){boxV1 = Box.createVerticalBox();boxV1.add(new JLabel("请输入要查询的ID:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("结果如下:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("TYPE:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("MONEY:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("DATE:"));boxV1.add(Box.createVerticalStrut(8));boxV1.add(new JLabel("REMARK:"));boxV1.add(Box.createVerticalStrut(8));boxV2 = Box.createVerticalBox();boxV2.add(id);boxV2.add(Box.createVerticalStrut(8));boxV2.add(btn1);type.setEnabled(false);boxV2.add(type);boxV2.add(Box.createVerticalStrut(8));money.setEnabled(false);boxV2.add(money);boxV2.add(Box.createVerticalStrut(8));date.setEnabled(false);boxV2.add(date);boxV2.add(Box.createVerticalStrut(8));remark.setEnabled(false);boxV2.add(remark);boxV2.add(Box.createVerticalStrut(8));baseBox = Box.createHorizontalBox();baseBox.add(boxV1);boxV2.add(Box.createVerticalStrut(10));baseBox.add(boxV2);add(baseBox);btn1.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {                DBcon dBcon=new DBcon();        Connection con=dBcon.getConn();        if(con==null){System.out.println("数据库查询连接失败");}else{System.out.println("数据库查询连接成功");String idString=id.getText();if (!idString.equals("")) {try {Integer.parseInt(idString); // 只能为正整数DBselect.select(idString);} catch (Exception e2) {// TODO: handle exceptionJOptionPane.showMessageDialog(null, "ID格式不正确,请重新输入!");  }}else {JOptionPane.showMessageDialog(null, "Please input ID!");  }//id.setText(DBselect.s);        type.setText(DBselect.Stype);money.setText(DBselect.Smoney);date.setText(DBselect.Sdate);remark.setText(DBselect.Sremark);}                          }    });}}
数据库查询操作:
package com.handson.entity;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Statement;import java.util.Scanner;import javax.swing.JOptionPane;import com.tcl.util.DBcon;public class DBselect{public static String Stype;public static String Smoney;public static String Sdate;public static String Sremark;public static void select(String idString){int i=0;    DBcon dBcon=new DBcon();    Connection conn=dBcon.getConn();if(conn != null){try {Statement sm =  conn.createStatement(); ResultSet n = sm.executeQuery("select * from TALLY where TID='"+idString+"'");  while (n.next()) { Stype=n.getString(2); Smoney=n.getString(3); Sdate=n.getString(4); Sremark=n.getString(5); i++;// JOptionPane.showMessageDialog(null, "Select Success!");  }       n.close();sm.close();conn.close();if (i==1) {JOptionPane.showMessageDialog(null, "Select Success!");  }else {JOptionPane.showMessageDialog(null, "请输入正确的ID!");  } } catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}

查询全部账目信息:


package com.handson.entity;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.Box;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;import com.tcl.util.DBcon;public class DBSWseleteall extends JFrame{JTextField id = new JTextField(10);//要查询的卡号Box baseBox,boxV1,boxV2;public DBSWseleteall(){this.setBounds(100,100,450,260);this.setTitle("查询全部");this.setLayout(new java.awt.FlowLayout());init();this.setVisible(true);this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口}void init(){boxV1 = Box.createVerticalBox();boxV1.add(new JLabel("查询结果如下:"));boxV1.add(Box.createVerticalStrut(8));                 DBcon drop=new DBcon();                 Connection conn=drop.getConn();if(conn != null){try {Statement sm =  conn.createStatement(); ResultSet n = sm.executeQuery("select * from TALLY");//用于产生单个结果集的语句  while (n.next()) { String id=n.getString(1); String type=n.getString(2); String money=n.getString(3); String date=n.getString(4); String remark=n.getString(5); boxV1.add(new JLabel("ID:"+id+","+"TYPE:"+type+","+"MONEY:"+money+","+"DATE:"+date+","+"REMARK:"+remark+","));boxV1.add(Box.createVerticalStrut(8));}       n.close();sm.close();conn.close(); } catch (SQLException i) {// TODO Auto-generated catch blocki.printStackTrace();}}baseBox = Box.createHorizontalBox();baseBox.add(boxV1);add(baseBox);}}


      运行结果太多就不一一列举了

附主运行界面:
package com.handson.main;import javax.swing.JFrame;  import javax.swing.JOptionPane;  import javax.swing.JPanel;  import javax.swing.border.EmptyBorder;import com.handson.entity.DBSWseleteall;import com.handson.services.SWdelete;import com.handson.services.SWinsert;import com.handson.services.SWselect;import com.handson.services.SWupdate;import java.awt.Color;import java.awt.Font;  import javax.swing.JButton;  import java.awt.event.ActionListener;  import java.awt.event.ActionEvent;  import java.sql.Connection;  import java.sql.DriverManager;  import java.sql.ResultSet;  import java.sql.SQLException; import java.sql.Statement;public class Pinit extends JFrame{  //界面的初始化和数据库连接JButton jb1=null;      public static void main(String[] args)      {      Pinit frame = new Pinit();      frame.setVisible(true);    }      public Pinit()      {      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          setBounds(100, 100, 573, 381);          JPanel contentPane = new JPanel();          contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));          setContentPane(contentPane);          getContentPane().setBackground(Color.gray);        contentPane.setLayout(null);        JButton tianjia = new JButton("INSERT");        tianjia.addActionListener(new ActionListener()          {              public void actionPerformed(ActionEvent e)              {                    SWinsert ins = new SWinsert();            }          });         tianjia.setFont(new Font("宋体", Font.PLAIN, 18));          tianjia.setBounds(91, 100, 150, 27);          contentPane.add(tianjia);                JButton xiugai = new JButton("UPDATE");        xiugai.addActionListener(new ActionListener()          {              public void actionPerformed(ActionEvent e)              {                   SWupdate up = new SWupdate();            }          });         xiugai.setFont(new Font("宋体", Font.PLAIN, 18));          xiugai.setBounds(91, 150, 150, 27);          contentPane.add(xiugai);        JButton  shanchu= new JButton("DELETE");        shanchu.addActionListener(new ActionListener()          {              public void actionPerformed(ActionEvent e)              {                   SWdelete dr = new SWdelete();            }          });        shanchu.setFont(new Font("宋体", Font.PLAIN, 18));          shanchu.setBounds(91, 200, 150, 27);          contentPane.add(shanchu);                   JButton zhangmu = new JButton("SELECT");         zhangmu.addActionListener(new ActionListener()          {              public void actionPerformed(ActionEvent e)              {                   SWselect se = new SWselect();            }          });        zhangmu.setFont(new Font("宋体", Font.PLAIN, 18));          zhangmu.setBounds(300,100, 150, 27);        contentPane.add(zhangmu);                 JButton quanbu = new JButton("SELECT ALL");         quanbu.addActionListener(new ActionListener()          {              public void actionPerformed(ActionEvent e)              {                   DBSWseleteall se = new DBSWseleteall();            }          });        quanbu.setFont(new Font("宋体", Font.PLAIN, 18));          quanbu.setBounds(300,150, 150, 27);        contentPane.add(quanbu);                 JButton tuichu = new JButton("EXIT");         tuichu.addActionListener(new ActionListener()          {              public void actionPerformed(ActionEvent e)              {                   System.exit(0);            }          });          tuichu.setFont(new Font("宋体", Font.PLAIN, 18));          tuichu.setBounds(300,200, 150, 27);        contentPane.add(tuichu);            // 连接数据库  测试        String URL = "jdbc:oracle:thin:@localhost:1521:ORCL";        String user = "scott";//sql用户名          String psd = "123456";//sql密码          try          {              Class.forName("oracle.jdbc.driver.OracleDriver");              Connection con = DriverManager.getConnection(URL, user, psd);              Statement stat = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,                      ResultSet.CONCUR_READ_ONLY);              JOptionPane.showMessageDialog(null, "RUNNING。。。");          }          catch (ClassNotFoundException e)          {          JOptionPane.showMessageDialog(null, "SQL链接不成功!"); //未查找到相应的连接内容        }         catch (SQLException e)        {              JOptionPane.showMessageDialog(null, "FAIL!");  //数据库未连接        }      }  }
运行结果:



第三部分总结

     其中用了大量的Swing界面视图的构建,还有数据库的连接已经进行操作。其中还对各种输入的错误操作进行了错误提醒。就是这样。
原创粉丝点击