基于java+mysql的swing+mysql药品管理系统(java+swing+gui+mysql)

基于java+mysql的swing+mysql药品管理系统(java+swing+gui+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于java+mysql的Swing+MySQL药品管理系统(java+swing+gui+mysql)

功能介绍:用户管理、药品库存管理、进销管理、营销管理、药品购入、药品售出、药市信息


public class AddMedicineView extends JFrame {
		
		private Medicine smv;

		private JPanel centerJpanel = new JPanel(){
			public void paintComponent(Graphics g){
				super.paintComponent(g);
				ImageIcon icon=new ImageIcon("E:\\图片册\\pu.jpg");
				int width=centerJpanel.getWidth();
				int heigh=centerJpanel.getHeight();
				g.drawImage(icon.getImage(), 0, 0, width,heigh,null);
			}
		};

		private JLabel medicineIdJLabel = new JLabel("药品编号:");
		private JTextField medicineIdJTexFed = new JTextField();

		private JLabel medicinenameJLabel = new JLabel("药品名称:");
		private JTextField medicinenameJTexFed = new JTextField();;

			}
		}
		
	}
}

public class RegiestView extends JFrame {

	private JPanel centerJpanel = new JPanel(){
		public void paintComponent(Graphics g){
			super.paintComponent(g);
			ImageIcon icon=new ImageIcon("E:\\图片册\\pu.jpg");
			int width=centerJpanel.getWidth();
			int heigh=centerJpanel.getHeight();
			g.drawImage(icon.getImage(), 0, 0, width,heigh,null);
		}
	};

	private JLabel userIdJLabel = new JLabel("用户号");
	private JTextField userIdJTexFed = new JTextField();

	private JLabel passwordJLabel = new JLabel("密码");
	private JTextField passwordJTexFed = new JTextField();;

							
							new UpdateMedicineView(eid, Medicine.this);
						}
											
					}
				});
			topJpanel.add(filterMedicineNameJLable);
			filterMedicineNameJLable.setFont(new Font("Dialog",1,13));
			topJpanel.add(filterMedicineNameJTexfd);
			topJpanel.add(medicineproducerJLabel);
			medicineproducerJLabel.setFont(new Font("Dialog",1,13));
			topJpanel.add(medicinproducerJTexFed);
			topJpanel.add(searchBtn);
			searchBtn.setBackground(Color.green);
			searchBtn.setFont(new Font("Dialog",1,13));
			add(topJpanel, BorderLayout.NORTH);
			searchBtn.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					getFilter();

				}
			});
		}
		@SuppressWarnings("null")
		private ArrayList<Object[]> getMedicineByDb() throws SQLException {
			ArrayList<Object[]> medicines = new ArrayList<Object[]>();
			// 查询sql语句
			String sql = "select * from medicine";
			// 查询数据
			ResultSet result = new SqlHelper().query(sql, new String[] {});
		
			if (result != null) {
				while (result.next()) {
					Object rows[] = new Object[6];
					rows[0] = result.getString(1);
					rows[1] = result.getString(2);
			        rows[2] = result.getString(3);
					rows[3] = result.getString(4);
					rows[4] = result.getString(5);
					rows[5] = result.getString(6);
					medicines.add(rows);
				}

			} else {
				JOptionPane.showConfirmDialog(null, "没有查询到药品", "提示", JOptionPane.WARNING_MESSAGE);

			}
			String mvproducer=medicineproducerJTexFed.getText().trim();
			String sql = "insert into marketinview(mivid,mivname,mivinprice,mivamounts,mivcost,"
					+ "mivproducer)values(?,?,?,?,?,?)";
			SqlHelper sqlHelper = new SqlHelper();
			String paras [] = {mivid,mivname,mivinprice+"",mivamounts+"",mivcost+"",
					mvproducer};
			boolean issuccess = sqlHelper.update(sql, paras);
			if (issuccess) {
				JOptionPane.showConfirmDialog(null, 
						"购入成功","提示",JOptionPane.CLOSED_OPTION);
				smuv.refreshinJTable();
				this.dispose();
			}else{
				JOptionPane.showConfirmDialog(null, "购入失败","提示",JOptionPane.WARNING_MESSAGE);
			}
		}
		class A implements ActionListener{
			@Override
			public void actionPerformed(ActionEvent e) {
				JButton btton = (JButton) e.getSource();
				if (btton.equals(cancelBtn)) {
					MarketInRecords.this.dispose();
				}else{
					doConfirm();
				}
			}
			
		}	
}

    private void printPageInfo() {
        String pageInfo = "当前页数" + (currntPage + 1) + "  /" + " 总页数   " + pageCount;
        pageInfoLagel.setText(pageInfo);
    }

    /**
     * 刷新表格数据
     */
    public void refreshJTable(int begin, int size) {
        dtm.setNumRows(0);
        try {
            datas = getEmployeesByDb(begin, size);
            for (int i = 0; i < datas.size(); i++) {
                dtm.addRow(datas.get(i));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        printPageInfo();
    }

    /**
     * 过滤查找员工
     *
     * @return
     * @throws SQLException
     */
    private ArrayList<Object[]> getFliterEmployeesByDb(String username, String isAdmin) throws SQLException {
        ArrayList<Object[]> employeeslist = new ArrayList<Object[]>();
        // 查询sql语句
        String sql = "select * from EmployeeInfo where (eid like '%" + username + "%'  or  ename like '%" + username
                + "%') ";
        // 查询数据
        ResultSet result = null;
        if (isAdmin == null || isAdmin.equals("")) {
            sql += ";";
            result = new SqlHelper().query(sql, new String[]{});
        } else {

            sql += " and isAdmin = '" + isAdmin + "';";
            result = new SqlHelper().query(sql, new String[]{});
        }

        if (result != null) {
            while (result.next()) {
		
		}
		public void doConfirm(){
			String meid = medicineIdJTexFed.getText().trim();
			String mename = medicinenameJTexFed.getText().trim();
			String meprice = medicinepriceJTexFed.getText().trim();
			
			int meamounts = Integer.parseInt(medicineamountsJTexFed.getText().trim());
			
			String meproducer=medicinproducerJTexFed.getText().trim();
			String sql = "insert into medicine(meid,mename,meprice,meamounts,"
					+ "meproducer)values(?,?,?,?,?)";
			SqlHelper sqlHelper = new SqlHelper();
			String paras [] = {meid,mename,meprice,meamounts+"",
					meproducer};
			boolean issuccess = sqlHelper.update(sql, paras);
			if (issuccess) {
				JOptionPane.showConfirmDialog(null, 
						"添加成功","提示",JOptionPane.CLOSED_OPTION);
				smv.refreshJTable();
				this.dispose();
			}else{
				JOptionPane.showConfirmDialog(null, "添加失败","提示",JOptionPane.WARNING_MESSAGE);
			}
		}
		class A implements ActionListener{
			@Override
			public void actionPerformed(ActionEvent e) {
				JButton btton = (JButton) e.getSource();
				if (btton.equals(cancelBtn)) {
					AddMedicineView.this.dispose();
				}else{
					doConfirm();
				}
			}
			
		}	
}

        } else {
            JOptionPane.showConfirmDialog(null, "删除失败!", "提示", JOptionPane.WARNING_MESSAGE);

        }

    }

    class PageClick implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            if (button.equals(firstButton)) {
                if (currntPage != 0) {
                    currntPage = 0;
                }
            } else if (button.equals(preButton)) {
                if (currntPage > 0) {
                    currntPage--;
                }
            } else if (button.equals(nextButton)) {
                if (currntPage < pageCount - 1) {
                    currntPage++;
                }
            } else if (button.equals(lastButton)) {
                if (currntPage < pageCount - 1) {
                    currntPage = pageCount;
                }
            }

            refreshJTable(currntPage * pageSize, pageSize);

        }
    }

}

	package com.view;

			        ImageIcon icon;  
				    Image img; 
					icon = new ImageIcon("E:\\图片册\\pu.jpg");// 背景图片 
					img = icon.getImage();
			        g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this);
			        } 
			};
			private JPanel topJpanel = new JPanel(){
				public void paintComponent(Graphics g) {  
			        super.paintComponent(g);  
			        ImageIcon icon;  
				    Image img; 
					icon = new ImageIcon("E:\\图片册\\pu.jpg");// 背景图片 
					img = icon.getImage();
			        g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this);
			        } 
			};
			
			private JPanel westPanel=new JPanel(){
				public void paintComponent(Graphics g) {  
			        super.paintComponent(g);  
			        ImageIcon icon;  
				    Image img; 
					icon = new ImageIcon("E:\\图片册\\pun.jpg");// 背景图片 
					img = icon.getImage();
			        g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this);
			        } 
			};
			private JLabel meLabel=new JLabel("     ");
			private JLabel filterMedicineNameJLable = new JLabel("药品货存id/药品名称");
			private JTextField filterMedicineNameJTexfd = new JTextField(12);
			private JLabel recorderJLabel = new JLabel("登记人");
			private JTextField recorderJTexFed = new JTextField(12);
			private JButton searchBtn = new JButton("查找");
			ImageIcon icon=new ImageIcon("E:\\图片册\\yin.jpg");
			private ArrayList<Object[]> datas = null;

			public MarketMessage() {
				setLayout(new BorderLayout());
				
				add(centerJscrollPane, BorderLayout.CENTER);
				dtm3.addColumn("药品货存id");
				dtm3.addColumn("药品名称");
				dtm3.addColumn("售出数量");
				dtm3.addColumn("登记日期");
				dtm3.addColumn("记录者");
				dtm3.addColumn("供货商");
        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            if (button.equals(firstButton)) {
                if (currntPage != 0) {
                    currntPage = 0;
                }
            } else if (button.equals(preButton)) {
                if (currntPage > 0) {
                    currntPage--;
                }
            } else if (button.equals(nextButton)) {
                if (currntPage < pageCount - 1) {
                    currntPage++;
                }
            } else if (button.equals(lastButton)) {
                if (currntPage < pageCount - 1) {
                    currntPage = pageCount;
                }
            }

            refreshJTable(currntPage * pageSize, pageSize);

        }
    }

}

	package com.view;

public class SqlHelper {
    // 定义需要的对象
    Connection ct = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    // 连接数据库需要的字符串
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull";
    String user = "root";
    String passwd = "123456";

    // 构造函数,初始化
    public SqlHelper() {
        try {
            // 加载驱动
            Class.forName(driver);
            // 得到连接
            ct = DriverManager.getConnection(url, user, passwd);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("驱动没有加载成功,原因是没有导入驱动!请检查");
        } catch (NullPointerException e) {
            // TODO Auto-generated catch bloc
            e.printStackTrace();
            System.out.println("数据库服务没有开启,请打开数据库服务,再重试");
        } catch (SQLException e) {
            // TODO Auto-generated catch bloc
            e.printStackTrace();
        }
    }

    // 关闭资源的方法
    public void close() {
        try {
            if (rs != null) {
                rs.close();
            }

    }

    @SuppressWarnings("unused")
    private void printPageInfo() {
        String pageInfo = "当前页数" + (currntPage + 1) + "  /" + " 总页数   " + pageCount;
        pageInfoLagel.setText(pageInfo);
    }

    /**
     * 刷新表格数据
     */
    public void refreshJTable(int begin, int size) {
        dtm.setNumRows(0);
        try {
            datas = getEmployeesByDb(begin, size);
            for (int i = 0; i < datas.size(); i++) {
                dtm.addRow(datas.get(i));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        printPageInfo();
    }

    /**
     * 过滤查找员工
     *
     * @return
     * @throws SQLException
     */
    private ArrayList<Object[]> getFliterEmployeesByDb(String username, String isAdmin) throws SQLException {
        ArrayList<Object[]> employeeslist = new ArrayList<Object[]>();
        // 查询sql语句
        String sql = "select * from EmployeeInfo where (eid like '%" + username + "%'  or  ename like '%" + username
                + "%') ";
        // 查询数据
        ResultSet result = null;
        if (isAdmin == null || isAdmin.equals("")) {
            sql += ";";
            result = new SqlHelper().query(sql, new String[]{});
        } else {

            sql += " and isAdmin = '" + isAdmin + "';";
            result = new SqlHelper().query(sql, new String[]{});
        }

        if (result != null) {
            while (result.next()) {
                Object rows[] = new Object[6];
                rows[0] = result.getString(1);

public class AddMedicineView extends JFrame {
		
		private Medicine smv;

		private JPanel centerJpanel = new JPanel(){
			public void paintComponent(Graphics g){
				super.paintComponent(g);
				ImageIcon icon=new ImageIcon("E:\\图片册\\pu.jpg");
				int width=centerJpanel.getWidth();
				int heigh=centerJpanel.getHeight();
				g.drawImage(icon.getImage(), 0, 0, width,heigh,null);
			}
		};

		private JLabel medicineIdJLabel = new JLabel("药品编号:");
		private JTextField medicineIdJTexFed = new JTextField();

		private JLabel medicinenameJLabel = new JLabel("药品名称:");
		private JTextField medicinenameJTexFed = new JTextField();;

		private JLabel medicinepriceJLabel = new JLabel("药品价格:");
		private JTextField medicinepriceJTexFed = new JTextField();;

		
		private JLabel medicineamountsJLabel = new JLabel("库存量:  ");
		private JTextField medicineamountsJTexFed = new JTextField();;

		private JLabel medicineproducerJLabel = new JLabel("生产商:  ");
		private JTextField medicinproducerJTexFed = new JTextField();;
        
		private JPanel southJpanel;
		private JButton cancelBtn;
		private JButton confirmBtn;
		
		        super.paintComponent(g);  
		        ImageIcon icon;  
			    Image img; 
				icon = new ImageIcon("E:\\图片册\\lvu.jpg");// 背景图片 
				img = icon.getImage();
		        //下面这行是为了背景图片可以跟随窗口自行调整大小,可以自己设置成固定大小  
		        g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this);
		        } 
		};
		//实例化用户名密码控件
		label1=new JLabel("用户:");
		label1.setFont(new Font("Dialog",1,15));
		userName = new JTextField(24);
		label2=new JLabel("密码:");
		label2.setFont(new Font("Dialog",1,15));
		password = new JPasswordField(24);
		
		//添加用户名密码控件到 中间容器中
		centerJpanel.add(label1);
		centerJpanel.add(userName);
		centerJpanel.add(label2);
		centerJpanel.add(password);
		centerJpanel.setBackground(null);
		//实列化欢迎字,并添加到根容器的北边
		
		JLabel label3 = new JLabel("药品管理系统");
		label3.setHorizontalAlignment(JLabel.CENTER);
		label3.setFont(new Font("Dialog",1,20));
		label3.setForeground(Color.green);
		label3.setBackground(Color.white);
		bgPanel.add(label3,BorderLayout.NORTH);
		//添加中间容器到根容器的中间
		bgPanel.add(centerJpanel,BorderLayout.CENTER);
		
		
		southJpanel = new JPanel();
		southJpanel.setBackground(Color.white);
		regiestBtn = new JButton("注册");
		regiestBtn.setBackground(Color.lightGray);
		regiestBtn.setSize(100, 60);
		southJpanel.add(regiestBtn);
		southJpanel.setBackground(Color.white);
		regiestBtn.addActionListener(new ActionListener() {
			
			@Override
                if (currntPage < pageCount - 1) {
                    currntPage++;
                }
            } else if (button.equals(lastButton)) {
                if (currntPage < pageCount - 1) {
                    currntPage = pageCount;
                }
            }

            refreshJTable(currntPage * pageSize, pageSize);

        }
    }

}

	package com.view;

	public class MarketMessage  extends JPanel {

			private DefaultTableModel dtm3 = new DefaultTableModel();
			private JTable empelJtable = new JTable(dtm3);
			class A implements ActionListener{
				@Override
				public void actionPerformed(ActionEvent e) {
					JButton btton = (JButton) e.getSource();
					if (btton.equals(cancelBtn)) {
						AddMarketMessage.this.dispose();
					}else{
						doConfirm();
					}
				}
				
			}	
	}

public class AddEmployeeView extends JFrame {
	
	private EmployeeManagerView smv;

	private JPanel centerJpanel = new JPanel(){
		public void paintComponent(Graphics g){
			super.paintComponent(g);
			ImageIcon icon=new ImageIcon("E:\\图片册\\pu.jpg");
			int width=centerJpanel.getWidth();
			int heigh=centerJpanel.getHeight();
			g.drawImage(icon.getImage(), 0, 0, width,heigh,null);
		}

    public void refreshinJTable() {
        dtm2.setNumRows(0);
        try {
            datas = getinViewByDb();
            for (int i = 0; i < datas.size(); i++) {
                dtm2.addRow(datas.get(i));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    public void refreshoutJTable() {
        dtm3.setNumRows(0);
        try {
            datas = getoutViewByDb();
            for (int i = 0; i < datas.size(); i++) {
                dtm3.addRow(datas.get(i));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

}

            icon = new ImageIcon("E:\\图片册\\pu.jpg");// 背景图片
            img = icon.getImage();
            g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
        }
    };
    private JLabel filterUserNameJLable = new JLabel("员工id/员工姓名");
    private JTextField filterUsernameJTexfd = new JTextField(12);
    private JLabel isAdminJLabel = new JLabel("身份(管理员/普通员工)");

    private JTextField isAdminJTexfd = new JTextField(12);

    private JButton searchBtn = new JButton("查找");

    private ArrayList<Object[]> datas = null;
    int pageSize = 3; // 每页显示条数
    int dataSum = 0; // 总的数据条数
    int pageCount = 0; // 总页数
    int currntPage = 0; // 当前页数

    public EmployeeManagerView() {
        setLayout(new BorderLayout());
        add(centerJscrollPane, BorderLayout.CENTER);
        dtm.addColumn("员工id");
        dtm.addColumn("名称");
        dtm.addColumn("姓别");
        dtm.addColumn("入职日期");
        dtm.addColumn("年龄");
        dtm.addColumn("是否管理");
        try {
            dataSum = getDataCount();
        } catch (SQLException e1) {
            e1.printStackTrace();
        }

        bottomAllJpane.setLayout(new BorderLayout());
        bottomAllJpane.setPreferredSize(new Dimension(900, 240));
        bottomAllJpane.add(bottonPageJpanel, BorderLayout.CENTER);

        firstButton = new JButton("首页");
        firstButton.setBackground(Color.green);
        lastButton = new JButton("尾页");
        lastButton.setBackground(Color.green);
        preButton = new JButton("上一页");
        preButton.setBackground(Color.green);
        nextButton = new JButton("下一页");
        nextButton.setBackground(Color.green);
        pageInfoLagel = new JLabel(" ");
        pageInfoLagel.setOpaque(true);

请添加图片描述

请添加图片描述
请添加图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值