登陆界面
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Enter {
public static String IDName;
public static void main(String[] args) { new EnterFrame(); }
}
class EnterFrame extends JFrame {
EnterFrame() {
init();
setTitle("药店管理系统登录界面");
setBounds(0,0,800, 450);
setLocationRelativeTo(null);//窗口居中
setLayout(null);//将布局设置为空,这样可以用坐标位置放置组件
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
void init() {
JLabel label = new JLabel("欢迎进入药店管理系统!");
JLabel labUsername = new JLabel("用户名");
JLabel labPassword = new JLabel("密码");
JTextField username = new JTextField(20);
JPasswordField password = new JPasswordField(20);
JButton btn1 = new JButton("登录");
add(label);
add(labUsername);
add(username);
add(labPassword);
add(password);
add(btn1);
label.setBounds(220, 40, 360, 75);
labUsername.setBounds(260, 150, 60, 40);
labPassword.setBounds(265, 220, 60, 40);
username.setBounds(320, 150, 180, 40);
password.setBounds(320, 220, 180, 40);
btn1.setBounds(320, 290, 180, 30);
label.setFont(new Font("微软雅黑", Font.BOLD, 30));
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (username.getText().trim().length() == 0 || new String(password.getPassword()).trim().length() == 0)
JOptionPane.showMessageDialog(null, "用户名密码不允许为空");
else {
Connection con = SqlOperation.getConnection();
Statement statement = null;
try {
statement = con.createStatement();
} catch (SQLException e2) {
e2.printStackTrace();
}
String sql = "SELECT * FROM ID WHERE IDUsername=" + username.getText().trim() + " AND IDPassword=" +
new String(password.getPassword()).trim();
try {
assert statement != null;
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
Enter.IDName = rs.getString("IDName");
JOptionPane.showMessageDialog(null,"欢迎使用本系统,"+Enter.IDName);
int IDFlag =rs.getInt("IDFlag");
if(IDFlag==1){Boss b=new Boss();}
else { Staff s=new Staff(); }
dispose();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
SqlOperation.release(statement, con);
}
}
});
}
}
老板界面
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import static javax.swing.JOptionPane.PLAIN_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog;
class Boss extends JFrame {
Boss(){
init();
setTitle("药店管理系统-管理员");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setBounds(0,0,900,300);
setLocationRelativeTo(null);//窗口居中
}
void init(){
setLayout(null);
JLabel label=new JLabel("请选择以下功能:");
JButton btn1=new JButton("用户管理");
JButton btn2=new JButton("收入统计");
JButton btn3=new JButton("记录查询");
JButton btn4=new JButton("药品库存");
JButton btn5=new JButton("返回登录");
add(label);
add(btn1);
add(btn2);
add(btn4);
add(btn3);
add(btn5);
label.setBounds(100, 65, 700, 30);
btn1.setBounds (100, 165,100, 30);
btn2.setBounds (250,165,100, 30);
btn3.setBounds (400,165,100, 30);
btn4.setBounds (550,165,100, 30);
btn5.setBounds (700,165,100, 30);
label.setFont(new Font("", Font.BOLD, 30));
btn1.addActionListener(new ActionListener() {//用户管理
public void actionPerformed(ActionEvent e) {
new userManager();
}
});
btn2.addActionListener(new ActionListener() {//收入统计
public void actionPerformed(ActionEvent e) {
new money();
showMessageDialog(null, money.getMoney()+"元","账户",PLAIN_MESSAGE);
}
});
btn3.addActionListener(new ActionListener() {//记录查询
public void actionPerformed(ActionEvent e) {
Tool.recordTable();
}
});
btn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {//库存查询
Tool.MedicTable();
}
});
btn5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {//返回登录
new EnterFrame();
dispose();
}
});
}
}
class userManager extends JFrame{
userManager(){
init();
setTitle("药店管理系统-用户管理");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
setBounds(0,0,900,300);
setLocationRelativeTo(null);//窗口居中
}
void init(){
setLayout(null);
JLabel label=new JLabel("请选择以下功能:");
JButton btn1=new JButton("查询员工");
JButton btn2=new JButton("增加员工");
JButton btn3=new JButton("辞退员工");
JButton btn4=new JButton("修改密码");
label.setBounds(90, 65, 700, 30);
btn1.setBounds (90, 165,100, 30);
btn2.setBounds (290,165,100, 30);
btn3.setBounds (490,165,100, 30);
btn4.setBounds (690,165,100, 30);
label.setFont(new Font("", Font.BOLD, 30));
btn1.addActionListener(new ActionListener() {//查询员工
String columns[] = {"用户名","职位", "姓名"};
public void actionPerformed(ActionEvent e) {
Connectio