JavaSwing / C# 动物园管理系统

说明

此系统同时支持mysql,sqlserver,有javaswing窗体和C#窗体两套代码

数据库文件

动物园管理系统

数据库设计

关系模型

管理员(主键,用户名,密码,姓名,电话,编号,性别,年龄)

医生(主键,用户名,密码,姓名,电话,编号,性别,年龄)

饲养员(主键,用户名,密码,名称,性别,电话,编号,健康情况)

后勤(主键,用户名,密码,名称,性别,电话,编号)

动物(主键,名称,编号,年龄,性别,花色)

采购(主键,采购人,采购类型,采购品名,数量,花费资金,创建时间)

动物治疗记录(主键,动物,病症,花费价格,治疗结果,创建时间,医生)

饲养记录(主键,动物,饲养时间,食物,饲养量,饲养人)

上报(主键,上报内容,详细说明,上报时间,审核结果)

采购通知(主键,通知标题,内容,通知时间,通知人,状态)

治疗通知(主键,通知标题,内容,治疗动物,通知时间,安排医生,紧急程度,完成情况)

数据字典

管理员表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

用户名

username

varchar(20)

not null;unique;

不可为空;字段唯一;

密码

password

varchar(20)

姓名

name

varchar(12)

not null;

不可为空;

电话

tele

varchar(11)

编号

numb

varchar(32)

not null;unique;

不可为空;字段唯一;

性别

gender

varchar(10)

年龄

age

int

医生表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

用户名

username

varchar(20)

not null;unique;

不可为空;字段唯一;

密码

password

varchar(20)

姓名

name

varchar(18)

not null;unique;

不可为空;字段唯一;

电话

tele

varchar(11)

编号

numb

varchar(32)

not null;unique;

不可为空;字段唯一;

性别

gender

varchar(10)

年龄

age

int

饲养员表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

用户名

username

varchar(20)

not null;unique;

不可为空;字段唯一;

密码

password

varchar(20)

名称

name

varchar(18)

not null;unique;

不可为空;字段唯一;

性别

gender

varchar(10)

电话

tele

varchar(11)

编号

numb

varchar(32)

not null;unique;

不可为空;字段唯一;

健康情况

jiankang

varchar(255)

后勤表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

用户名

username

varchar(20)

not null;unique;

不可为空;字段唯一;

密码

password

varchar(20)

名称

name

varchar(18)

not null;unique;

不可为空;字段唯一;

性别

gender

varchar(10)

电话

tele

varchar(11)

编号

numb

varchar(32)

not null;unique;

不可为空;字段唯一;

动物表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

名称

name

varchar(18)

not null;unique;

不可为空;字段唯一;

编号

numb

varchar(32)

not null;unique;

不可为空;字段唯一;

年龄

age

int

性别

gender

varchar(10)

花色

huase

varchar(255)

采购表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

采购人

eid

varchar(255)

not null;unique;

不可为空;字段唯一;

采购类型

type

varchar(255)

采购品名

goods

varchar(255)

数量

count

int

not null;

不可为空;

花费资金

price

double

not null;

不可为空;

创建时间

createtime

datetime

not null;

new Date()

动物治疗记录表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

动物

animalId

varchar(255)

病症

bz

varchar(255)

花费价格

price

double

not null;

不可为空;

治疗结果

results

varchar(255)

创建时间

createtime

datetime

not null;

new Date()

医生

doctorId

varchar(255)

饲养记录表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

动物

animalId

varchar(255)

饲养时间

createtime

datetime

not null;

new Date()

食物

foods

varchar(255)

饲养量

amount

varchar(255)

饲养人

empid

varchar(255)

上报表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

上报内容

title

varchar(255)

详细说明

content

varchar(255)

上报时间

createtime

datetime

not null;

new Date()

审核结果

result

varchar(255)

"待审阅"

采购通知表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

通知标题

title

varchar(255)

not null;

不可为空;

内容

content

varchar(255)

not null;

不可为空;

通知时间

createtime

datetime

not null;

new Date()

通知人

people

varchar(255)

not null;

不可为空;

状态

status

varchar(255)

"已通知"

治疗通知表

字段名

字段

数据类型

约束

描述

主键

id

varchar(40)

primary key;

唯一标识

通知标题

title

varchar(255)

not null;

不可为空;

内容

content

varchar(255)

not null;

不可为空;

治疗动物

animalId

varchar(255)

not null;

不可为空;

通知时间

createtime

datetime

not null;

new Date()

安排医生

doctorId

varchar(255)

not null;

不可为空;

紧急程度

jingji

varchar(255)

not null;

不可为空;

完成情况

status

varchar(255)

"未完成"

部分代码

package com.codeying.frame;
 import com.codeying.dao.*; import com.codeying.entity.*;
import com.codeying.utils.*;
import com.codeying.utils.excel.ExcelUtil;
import com.mysql.jdbc.StringUtils;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.FontUIResource;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import java.util.List;
import java.io.*;

public class FormRecordData extends JInternalFrame {
    RecordDao dao = RecordDao.me();

    private List<Record> listData;//存储数据

    public FormRecordData () {
        initialize();//初始化界面
        initPrivilege();//设置权限
        initData();//初始化界面数据
        query(null);
        //查询数据
    }
    //初始化权限
    private void initPrivilege(){
        String role = Login.type;
        if (role == "admin")
        {
            jButtonDel.setVisible(true);
        }
        if (role == "user")
        {
            jButtonDel.setVisible(true);
        }
        //开启导出excel功能
        if(Config.export){
            jButtonExport.setVisible(true);
        }
    }

    public void initData() {
        //设置数据头部
        List<String> l = new ArrayList<>();
                        l.add("主键");
                        l.add("用户");
                        l.add("投票项目");
                        l.add("投票选项");
                String heads[] = l.toArray(new String[0]);
        model = new DefaultTableModel(null, heads);
        //加载下拉框数据
                                                                            setUserId ( con_user);                    setUserId ( tb_user);
                                                            setProjid ( con_projid);                    setProjid ( tb_projid);
                                                    }

    /**
     * 内部类监听器模块
     */
    public class BtnListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            //点击查询按钮
            String s;
            if(e.getSource().equals(jButtonQuery)){
                Map<String,String> paramMap = new HashMap<>();
                                                                                                                                        //条件 用户
                                                    s = getByIndexUserId (con_user .getSelectedIndex());//外键
                            if(!StringUtils.isNullOrEmpty(s))paramMap.put("userId",s);
                                                                                                                            //条件 投票项目
                                                    s = getByIndexProjid (con_projid .getSelectedIndex());//外键
                            if(!StringUtils.isNullOrEmpty(s))paramMap.put("projid",s);
                                                                                                                                    query(paramMap);
            }else if(e.getSource().equals(jButtonDel)){//点击删除按钮
                String id = tb_id.getText().trim(); //获取id
                if(StringUtils.isNullOrEmpty(id)){
                    JOptionPane.showMessageDialog(null, "未选中任何记录!");return;
                }
                //弹出确认框
                int opt = JOptionPane.showConfirmDialog(null, "确认删除?", "确认信息", JOptionPane.YES_NO_OPTION);
                if (opt == JOptionPane.YES_OPTION) {
                    //确认继续操作
                    int res = dao.deleteById(id);
                    if(res == 0){
                        JOptionPane.showMessageDialog(null, "删除失败!");
                    }else {
                        JOptionPane.showMessageDialog(null, "删除成功!");
                        query(null);//删除完了重新查询。
                    }
                }
            //点击保存按钮
            }else if(e.getSource().equals(jButtonEdit)){
                String id = tb_id.getText().trim();//获取id
                if(StringUtils.isNullOrEmpty(id)){
                    JOptionPane.showMessageDialog(null, "未选中任何记录!");return;
                }
                //TODO 不可为空判断
                                                                                                                                                                                                                                                
                Record t = new  Record ();
                String templateStr;
                t.setId(id);
                //更新可更新字段  //非法判断
                                                                                t.setId (tb_id .getText().trim());//字符串
                                                                                                    templateStr =  getByIndexProjid (tb_user .getSelectedIndex());
                        if(FormRecordAdd .illegalAdd(id,"userId",templateStr)){
                            JOptionPane.showMessageDialog(null, "用户 : 已存在!");return;
                        }
                        t.setUserId (templateStr);
                                                                                                    t.setProjid (getByIndexProjid (tb_projid .getSelectedIndex()));//外键
                                                                                                    t.setResult (tb_result .getText().trim());//字符串
                                                    int res = dao.updateById(t);
                if(res == 0){
                    JOptionPane.showMessageDialog(null, "更新失败!");
                }else {
                    JOptionPane.showMessageDialog(null, "更新成功!");
                    query(null);
                }
            }
            //导出数据到excel
            else if(e.getSource().equals(jButtonExport)){
                List<Record> data = dao.list();
                //循环遍历list数据,统计、获取外键数据
                for(Record stAv : data){
                                                                                                //获取外键数据
                            stAv.setUserIdFrn ( UserDao.me().getBy("id",stAv .getUserId () ) );
                            stAv.setUserId(stAv.getUserIdFrn().getName() );
                                                                            //获取外键数据
                            stAv.setProjidFrn ( ProjDao.me().getBy("id",stAv .getProjid () ) );
                            stAv.setProjid(stAv.getProjidFrn().getName() );
                                                                }
                HashMap<String,String> headMap = new LinkedHashMap<>();
                                                                                headMap.put("userId","用户");
                                                            headMap.put("projid","投票项目");
                                                            headMap.put("result","投票选项");
                                try {
                    File f=new File("投票记录数据.xls");
                    OutputStream out = new FileOutputStream(f);
                    ExcelUtil.exportExcel(headMap, data, out);
                    out.close();
                    JOptionPane.showMessageDialog(null, "导出成功:"+f.getAbsolutePath());
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }
        }
    }

    /**
     * 表格数据点击事件
     */
    public class TableListener implements ListSelectionListener {
        public void valueChanged(ListSelectionEvent e) {
            if (jTable.getSelectedRow() != -1) {
                Object o;
                int index = jTable.getSelectedRow();
                //TODO 点击填充数据
                                                            tb_id .setText(jTable.getValueAt(index,0).toString());
                                                                o = jTable.getValueAt(index,1);
                    tb_user .setSelectedItem(o == null?"":o.toString());
                                                                o = jTable.getValueAt(index,2);
                    tb_projid .setSelectedItem(o == null?"":o.toString());
                                                                tb_result .setText(jTable.getValueAt(index,3).toString());
                                        }
        }
    }

    //查询数据到界面
    private void query(Map<String,String> wrapper){
        if(wrapper == null){
            wrapper = new HashMap<>();
        }
    if(Login.type.equals("user")){
        wrapper.put("userId",Login.user .getId());//只能查看和自己相关的内容
        con_user .setEnabled(false);
        tb_user .setEnabled(false);
    }
        listData = dao.list(wrapper);
        //设置外键、统计、平均
                                                                                                for (Record t : listData){
                                                                                                            //获取外键数据
                    t .setUserIdFrn( UserDao.me().getBy ("id", t .getUserId () ) );
                                                                                //获取外键数据
                    t .setProjidFrn( ProjDao.me().getBy ("id", t .getProjid () ) );
                                                                                }
        //统计和平均:
        int count = listData.size();
        jLabelCounts.setText("记录数:" + count + "");
        String labelStaAvg = "";
                                                                                                                                                jLabelTips.setText(labelStaAvg);
        model.setRowCount(count);// 设置行数
        String d;
        for(int i=0;i<count;i++){
            int j = 0;
            //TODO 给数据表设置值
            model.setValueAt(listData.get(i).getId (), i, j);
        j++;
                if(listData.get(i).getUserIdFrn()!=null)
            model.setValueAt(listData.get(i).getUserIdFrn ().getName (), i, j);
        else model.setValueAt("", i, j);
        j++;
                if(listData.get(i).getProjidFrn()!=null)
            model.setValueAt(listData.get(i).getProjidFrn ().getName (), i, j);
        else model.setValueAt("", i, j);
        j++;
                model.setValueAt(listData.get(i).getResult (), i, j);
        j++;
            }

        jTable.setModel(model);
        jTable.setAutoCreateRowSorter(true);//为JTable设置排序器
        hideColumn(jTable,0);//隐藏id列
    }

    //隐藏表格列,设置不可见。
    void hideColumn(JTable table,int column) {
        TableColumn tc = table.getColumnModel().getColumn(column);
        tc.setMaxWidth(0);
        tc.setPreferredWidth(0);
        tc.setWidth(0);
        tc.setMinWidth(0);
        table.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0);
        table.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0);
    }
                //存储外键数据 tb_user
        private List<User> listUserId;
        private void setUserId (JComboBox comboBox){
            UserDao dao = UserDao.me();
            listUserId = dao.list(null);
            comboBox.addItem("");
            for (User i : listUserId){
                                comboBox.addItem(i.getName ());//对应外键字段
            }
        }
        //获取id
        private String getByIndexUserId (int index){
            index = index-1;
            if(index<0 || index>=listUserId .size()){
                return "";
            }
            return listUserId .get(index).getId();
        }
                //存储外键数据 tb_projid
        private List<Proj> listProjid;
        private void setProjid (JComboBox comboBox){
            ProjDao dao = ProjDao.me();
            listProjid = dao.list(null);
            comboBox.addItem("");
            for (Proj i : listProjid){
                                comboBox.addItem(i.getName ());//对应外键字段
            }
        }
        //获取id
        private String getByIndexProjid (int index){
            index = index-1;
            if(index<0 || index>=listProjid .size()){
                return "";
            }
            return listProjid .get(index).getId();
        }
            private void initialize() {
        int x,y;
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setResizable(true);
        this.setClosable(true);
        this.setMaximizable(true);
        this.setIconifiable(true);
        this.setSize(1200, 650);
        this.setTitle("投票记录");
        //检索区域
        jPanel.setLayout(null);
        jPanel.setBounds(new Rectangle(1, 1, 1150, 80));
        jPanel.setBorder(BorderFactory.createTitledBorder("查找数据"));
        jPanel.add(jButtonQuery, null);//查询按钮
        jButtonQuery.setBounds(new Rectangle(1000, 50, 100, 24));
                                           jPanel.add( labelC_user, null);
        labelC_user .setBounds(new Rectangle(10, 20, 60, 24));
                                    jPanel.add(con_user, null);
            con_user .setBounds(new Rectangle(80, 20, 100, 24));
                                                jPanel.add( labelC_projid, null);
        labelC_projid .setBounds(new Rectangle(185, 20, 60, 24));
                                    jPanel.add(con_projid, null);
            con_projid .setBounds(new Rectangle(255, 20, 100, 24));
                                        //父面板
        this.setContentPane(jContentPane);
        jContentPane.setLayout(null);
        jContentPane.setBorder(BorderFactory.createTitledBorder(""));
        jContentPane.add(jPanel, null);
        jContentPane.add(jScrollPane, null);
        jScrollPane.setBounds(new Rectangle(10, 110, 950, 450));
        jScrollPane.setViewportView(jTable);
        jContentPane.add(jLabelCounts, null);
        jLabelCounts.setBounds(new Rectangle(10, 85, 200, 24));
        jContentPane.add(jLabelTips, null);
        jLabelTips.setBounds(new Rectangle(10, 560, 650, 24));
        jContentPane.add(tb_id);
        tb_id.setBounds(new Rectangle(600, 85, 100, 24));
        tb_id.setVisible(false);//存id
        //TODO 修改数据
        x = 970; y = 110;
        //添加右边输入框和标签用来更新
            //添加右边输入框和标签用来更新
            jContentPane.add(label_user, null);
        label_user .setBounds(new Rectangle(x, y, 65, 24));
                    jContentPane.add(tb_user, null);
            tb_user .setBounds(new Rectangle(x+65, y, 130, 24));
            y+=35;
                            //添加右边输入框和标签用来更新
            jContentPane.add(label_projid, null);
        label_projid .setBounds(new Rectangle(x, y, 65, 24));
                    jContentPane.add(tb_projid, null);
            tb_projid .setBounds(new Rectangle(x+65, y, 130, 24));
            y+=35;
                            //添加右边输入框和标签用来更新
            jContentPane.add(label_result, null);
        label_result .setBounds(new Rectangle(x, y, 65, 24));
                    jContentPane.add(tb_result, null);
            tb_result .setBounds(new Rectangle(x+65, y, 130, 24));
            y+=35;
                            //按钮
        jContentPane.add(jButtonDel, null);
        jButtonDel.setVisible(false);
        jButtonDel.setBounds(new Rectangle(x, y, 80, 24));
        jContentPane.add(jButtonEdit, null);
        jButtonEdit.setVisible(false);
        jButtonEdit.setBounds(new Rectangle(x+90, y, 80, 24));
        jContentPane.add(jButtonExport, null);
        jButtonExport.setVisible(false);
        jButtonExport.setBounds(new Rectangle(800, 85, 150, 24));
        //添加监听
        jButtonQuery.addActionListener(listener);
        jButtonEdit.addActionListener(listener);
        jButtonExport.addActionListener(listener);
        jButtonDel.addActionListener(listener);
        jTable.getSelectionModel().addListSelectionListener(new TableListener());
    }

    BtnListener listener = new BtnListener();
    private JPanel jContentPane = new JPanel();//主Panel
    private JPanel jPanel = new JPanel();
    private JLabel jLabelCounts = new JLabel("记录数量:xx条");//计数用
    private JLabel jLabelTips = new JLabel("统计信息...");//平均,总计信息
    private JScrollPane jScrollPane = new JScrollPane();
    private JTable jTable = new JTable();
    DefaultTableModel model = new DefaultTableModel();
    private JButton jButtonEdit = new JButton("保存");
    private JButton jButtonExport = new JButton("导出到excel");
    private JButton jButtonDel =  new JButton("删除");
    private JButton jButtonQuery = new JButton("查询");
    private JTextField tb_id = new JTextField();

                                                      private JLabel label_user = new JLabel("用户");
                        private JComboBox tb_user = new JComboBox();
                                        private JLabel labelC_user = new JLabel("用户");
                        private JComboBox con_user = new JComboBox();
                                             private JLabel label_projid = new JLabel("投票项目");
                        private JComboBox tb_projid = new JComboBox();
                                        private JLabel labelC_projid = new JLabel("投票项目");
                        private JComboBox con_projid = new JComboBox();
                                             private JLabel label_result = new JLabel("投票选项");
                        private JTextField tb_result = new JTextField();
                                    
}

系统截图

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值