├── .gitignore ├── .idea ├── .gitignore ├── artifacts │ └── OutpatientManagementSystem_jar.xml ├── encodings.xml ├── libraries │ ├── commons_codec_1_14.xml │ └── mysql_connector_java_8_0_16.xml ├── misc.xml ├── modules.xml └── uiDesigner.xml ├── OutpatientManagementSystem.iml ├── README.md └── src ├── META-INF └── MANIFEST.MF ├── com └── dlnu │ └── oms │ ├── constant │ ├── Keys.java │ └── Values.java │ ├── functions │ ├── AES.java │ └── MD5.java │ ├── login │ ├── DBSettings.form │ ├── DBSettings.java │ ├── Login.form │ └── Login.java │ ├── source │ └── logo.png │ └── ui │ ├── DoctorMainUI.form │ ├── DoctorMainUI.java │ ├── PatientMainUI.form │ ├── PatientMainUI.java │ ├── PharmacyMainUI.form │ └── PharmacyMainUI.java └── models └── commons-codec-1.14.jar /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /out/ -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/artifacts/OutpatientManagementSystem_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/OutpatientManagementSystem_jar 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/commons_codec_1_14.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/mysql_connector_java_8_0_16.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /OutpatientManagementSystem.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OutpatientManagementSystem 2 | # 大二下学期期末数据库与Java课程设计作业 3 | 4 | 实现一个门诊管理系统,拥有挂号,诊断,划价,收费,药局管理等功能 5 | -------------------------------------------------------------------------------- /src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: com.dlnu.oms.login.Login 3 | 4 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/constant/Keys.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.constant; 2 | 3 | import java.sql.Connection; 4 | 5 | public class Keys { 6 | public static Connection connection; 7 | public static String UID; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/constant/Values.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.constant; 2 | 3 | public class Values { 4 | public static String DBUserName=""; 5 | public static String DBPassword=""; 6 | public static String DB=""; 7 | public static String Host=""; 8 | public static String Port=""; 9 | public static final String ClassName="com.mysql.cj.jdbc.Driver"; 10 | public static final String AESPassword="OMS"; 11 | public static final String Config="outpatient.conf"; 12 | public static String getURL(){ 13 | return "jdbc:mysql://"+Host+":"+Port+"/"+DB+"?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; 14 | } 15 | public static String getURL(String Host,String Port,String DB){ 16 | return "jdbc:mysql://"+Host+":"+Port+"/"+DB+"?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/functions/AES.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.functions; 2 | 3 | import java.nio.charset.StandardCharsets; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.security.SecureRandom; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | import javax.crypto.Cipher; 9 | import javax.crypto.KeyGenerator; 10 | import javax.crypto.SecretKey; 11 | import javax.crypto.spec.SecretKeySpec; 12 | import org.apache.commons.codec.binary.Base64; 13 | 14 | /** 15 | * @version V1.0 16 | * @desc AES 加密工具类 17 | */ 18 | public class AES { 19 | 20 | private static final String KEY_ALGORITHM = "AES"; 21 | private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";//默认的加密算法 22 | 23 | /** 24 | * AES 加密操作 25 | * 26 | * @param content 待加密内容 27 | * @param password 加密密码 28 | * @return 返回Base64转码后的加密数据 29 | */ 30 | public static String encrypt(String content, String password) { 31 | try { 32 | Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器 33 | 34 | byte[] byteContent = content.getBytes(StandardCharsets.UTF_8); 35 | 36 | cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(password));// 初始化为加密模式的密码器 37 | 38 | byte[] result = cipher.doFinal(byteContent);// 加密 39 | 40 | return Base64.encodeBase64String(result);//通过Base64转码返回 41 | } catch (Exception ex) { 42 | Logger.getLogger(AES.class.getName()).log(Level.SEVERE, null, ex); 43 | } 44 | 45 | return null; 46 | } 47 | 48 | /** 49 | * AES 解密操作 50 | * 51 | * @param content 52 | * @param password 53 | * @return 54 | */ 55 | public static String decrypt(String content, String password) { 56 | 57 | try { 58 | //实例化 59 | Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); 60 | 61 | //使用密钥初始化,设置为解密模式 62 | cipher.init(Cipher.DECRYPT_MODE, getSecretKey(password)); 63 | 64 | //执行操作 65 | byte[] result = cipher.doFinal(Base64.decodeBase64(content)); 66 | 67 | return new String(result, StandardCharsets.UTF_8); 68 | } catch (Exception ex) { 69 | Logger.getLogger(AES.class.getName()).log(Level.SEVERE, null, ex); 70 | } 71 | 72 | return null; 73 | } 74 | 75 | /** 76 | * 生成加密秘钥 77 | * 78 | * @return 79 | */ 80 | private static SecretKeySpec getSecretKey(final String password) { 81 | //返回生成指定算法密钥生成器的 KeyGenerator 对象 82 | KeyGenerator kg = null; 83 | 84 | try { 85 | kg = KeyGenerator.getInstance(KEY_ALGORITHM); 86 | 87 | //AES 要求密钥长度为 128 88 | kg.init(128, new SecureRandom(password.getBytes())); 89 | 90 | //生成一个密钥 91 | SecretKey secretKey = kg.generateKey(); 92 | 93 | return new SecretKeySpec(secretKey.getEncoded(), KEY_ALGORITHM);// 转换为AES专用密钥 94 | } catch (NoSuchAlgorithmException ex) { 95 | Logger.getLogger(AES.class.getName()).log(Level.SEVERE, null, ex); 96 | } 97 | 98 | return null; 99 | } 100 | } -------------------------------------------------------------------------------- /src/com/dlnu/oms/functions/MD5.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.functions; 2 | 3 | import java.math.BigInteger; 4 | import java.security.MessageDigest; 5 | 6 | public class MD5 { 7 | public static String md5(String string) { 8 | try { 9 | // 生成一个MD5加密计算摘要 10 | MessageDigest md = MessageDigest.getInstance("MD5"); 11 | // 计算md5函数 12 | md.update(string.getBytes()); 13 | // digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符 14 | // BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值 15 | return new BigInteger(1, md.digest()).toString(16); 16 | } catch (Exception e) { 17 | return "ERROR"; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/login/DBSettings.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/login/DBSettings.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.login; 2 | 3 | import com.dlnu.oms.constant.Values; 4 | import com.dlnu.oms.functions.AES; 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.awt.event.ActionEvent; 8 | import java.awt.event.ActionListener; 9 | import java.io.File; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.OutputStreamWriter; 13 | import java.nio.charset.StandardCharsets; 14 | import java.sql.Connection; 15 | import java.sql.DriverManager; 16 | 17 | public class DBSettings { 18 | private JPanel panel; 19 | private JTextField textFieldHost; 20 | private JPasswordField passwordField; 21 | private JTextField textFieldPort; 22 | private JTextField textFieldDBName; 23 | private JTextField textFieldUserName; 24 | private JButton ButtonSubmit; 25 | private static JFrame frame; 26 | 27 | public DBSettings(){ 28 | setButtonSubmit(); 29 | } 30 | 31 | public static void main(String[] args) { 32 | frame = new JFrame("数据库设置"); 33 | frame.setContentPane(new DBSettings().panel); 34 | frame.setIconImage(new ImageIcon("src/com/dlnu/oms/source/logo.png").getImage()); 35 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 36 | frame.setPreferredSize(new Dimension(500,400)); 37 | frame.setLocationRelativeTo(null); 38 | frame.pack(); 39 | frame.setVisible(true); 40 | } 41 | 42 | private void setButtonSubmit() { 43 | ButtonSubmit.addActionListener(new ActionListener() { 44 | @Override 45 | public void actionPerformed(ActionEvent e) { 46 | String Host=textFieldHost.getText(); 47 | String Port=textFieldPort.getText(); 48 | String DBName=textFieldDBName.getText(); 49 | String DBUser=textFieldUserName.getText(); 50 | //noinspection deprecation 51 | String DBPassword=passwordField.getText(); 52 | try{ 53 | Class.forName(Values.ClassName); 54 | Connection connection= DriverManager.getConnection("jdbc:mysql://"+Host+":"+Port+"/"+DBName+"?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC",DBUser,DBPassword); 55 | }catch (Exception e1){ 56 | JOptionPane.showMessageDialog(frame,"无法连接数据库!","警告!", JOptionPane.ERROR_MESSAGE); 57 | return; 58 | } 59 | Values.Host=Host; 60 | Values.Port=Port; 61 | Values.DB=DBName; 62 | Values.DBUserName=DBUser; 63 | Values.DBPassword=DBPassword; 64 | String[] settings =new String[5]; 65 | settings[0]=Host; 66 | settings[1]=Port; 67 | settings[2]=DBName; 68 | settings[3]=DBUser; 69 | settings[4]=DBPassword; 70 | 71 | File file = new File(Values.Config); 72 | if (file.exists()) { 73 | boolean succeedDeleted = file.delete(); 74 | } 75 | try { 76 | if (file.createNewFile()){ 77 | FileOutputStream fileOutputStream = new FileOutputStream(file); 78 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8); 79 | outputStreamWriter.append(AES.encrypt(Host,Values.AESPassword)); 80 | outputStreamWriter.append("\n"); 81 | outputStreamWriter.append(AES.encrypt(Port,Values.AESPassword)); 82 | outputStreamWriter.append("\n"); 83 | outputStreamWriter.append(AES.encrypt(DBName,Values.AESPassword)); 84 | outputStreamWriter.append("\n"); 85 | outputStreamWriter.append(AES.encrypt(DBUser,Values.AESPassword)); 86 | outputStreamWriter.append("\n"); 87 | outputStreamWriter.append(AES.encrypt(DBPassword,Values.AESPassword)); 88 | outputStreamWriter.append("\n"); 89 | outputStreamWriter.close(); 90 | fileOutputStream.close(); 91 | JOptionPane.showMessageDialog(frame,"数据库连接、配置文件写入成功!","成功!", JOptionPane.PLAIN_MESSAGE); 92 | frame.dispose(); 93 | Login.main(settings); 94 | }else{ 95 | JOptionPane.showMessageDialog(frame,"配置文件写入失败!","失败!", JOptionPane.ERROR_MESSAGE); 96 | } 97 | } catch (IOException ioException) { 98 | ioException.printStackTrace(); 99 | JOptionPane.showMessageDialog(frame,"配置文件写入失败!","失败!", JOptionPane.ERROR_MESSAGE); 100 | } 101 | 102 | } 103 | }); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/login/Login.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/login/Login.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.login; 2 | 3 | import com.dlnu.oms.constant.Keys; 4 | import com.dlnu.oms.constant.Values; 5 | import com.dlnu.oms.functions.AES; 6 | import com.dlnu.oms.ui.DoctorMainUI; 7 | import com.dlnu.oms.functions.MD5; 8 | import com.dlnu.oms.ui.PatientMainUI; 9 | import com.dlnu.oms.ui.PharmacyMainUI; 10 | 11 | import javax.swing.*; 12 | import java.awt.*; 13 | import java.awt.event.ActionEvent; 14 | import java.awt.event.ActionListener; 15 | import java.awt.event.KeyEvent; 16 | import java.awt.event.KeyListener; 17 | import java.io.*; 18 | import java.nio.charset.StandardCharsets; 19 | import java.sql.DriverManager; 20 | import java.sql.PreparedStatement; 21 | import java.sql.ResultSet; 22 | 23 | public class Login { 24 | static JFrame frame; 25 | private JTabbedPane tabbedPane; 26 | private JPanel panel; 27 | private JTextField DoctorNum; 28 | private JPasswordField DoctorPass; 29 | private JButton DoctorLoginButton; 30 | private JTextField PatientName; 31 | private JPasswordField PatientPassword; 32 | private JTextField PharmacyNum; 33 | private JPasswordField PharmacyPassword; 34 | private JButton PharmacyLoginButton; 35 | private JButton UserRegisterButton; 36 | private JButton UserLoginButton; 37 | 38 | public Login() { 39 | setDoctor(); 40 | setPatient(); 41 | setPharmacy(); 42 | } 43 | 44 | public static void main(String[] args) { 45 | File file = new File(Values.Config); 46 | try { 47 | FileInputStream fileInputStream = new FileInputStream(file); 48 | InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8); 49 | StringBuilder stringBuffer = new StringBuilder(); 50 | while (true) { 51 | try { 52 | if (!inputStreamReader.ready()) break; 53 | stringBuffer.append((char) inputStreamReader.read()); 54 | } catch (IOException e) { 55 | JOptionPane.showMessageDialog(frame, "配置文件存在错误,请重新添加配置!", "失败!", JOptionPane.ERROR_MESSAGE); 56 | DBSettings.main(null); 57 | e.printStackTrace(); 58 | return; 59 | } 60 | } 61 | try { 62 | Values.Host = AES.decrypt(stringBuffer.toString().split("\n")[0], Values.AESPassword); 63 | Values.Port = AES.decrypt(stringBuffer.toString().split("\n")[1], Values.AESPassword); 64 | Values.DB = AES.decrypt(stringBuffer.toString().split("\n")[2], Values.AESPassword); 65 | Values.DBUserName = AES.decrypt(stringBuffer.toString().split("\n")[3], Values.AESPassword); 66 | Values.DBPassword = AES.decrypt(stringBuffer.toString().split("\n")[4], Values.AESPassword); 67 | try{ 68 | Values.Host=args[0]; 69 | Values.Port=args[1]; 70 | Values.DB=args[2]; 71 | Values.DBUserName=args[3]; 72 | Values.DBPassword=args[4]; 73 | }catch (Exception ignored){ 74 | } 75 | } catch (Exception e) { 76 | JOptionPane.showMessageDialog(frame, "配置文件已被损坏,请重新添加配置!"+e.toString(), "失败!", JOptionPane.ERROR_MESSAGE); 77 | DBSettings.main(null); 78 | return; 79 | } 80 | } catch (FileNotFoundException e) { 81 | DBSettings.main(null); 82 | return; 83 | } 84 | 85 | 86 | frame = new JFrame("门诊管理系统"); 87 | frame.setContentPane(new Login().panel); 88 | frame.setIconImage(new ImageIcon("src/com/dlnu/oms/source/logo.png").getImage()); 89 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 90 | frame.setPreferredSize(new Dimension(500, 300)); 91 | frame.setLocationRelativeTo(null); 92 | frame.pack(); 93 | frame.setVisible(true); 94 | try { 95 | Class.forName(Values.ClassName); 96 | Keys.connection = DriverManager.getConnection(Values.getURL(), Values.DBUserName, Values.DBPassword); 97 | } catch (Exception e) { 98 | JOptionPane.showMessageDialog(frame, "数据库错误,请重新添加配置(如果是首次添加配置信息后出现该提示请尝试重启)!", "失败!", JOptionPane.ERROR_MESSAGE); 99 | DBSettings.main(null); 100 | e.printStackTrace(); 101 | frame.dispose(); 102 | } 103 | } 104 | 105 | public void setDoctor() { 106 | DoctorNum.addKeyListener(new KeyListener() { 107 | @Override 108 | public void keyTyped(KeyEvent e) { 109 | } 110 | 111 | @Override 112 | public void keyPressed(KeyEvent e) { 113 | DoctorEnter(e); 114 | } 115 | 116 | @Override 117 | public void keyReleased(KeyEvent e) { 118 | 119 | } 120 | }); 121 | DoctorPass.addKeyListener(new KeyListener() { 122 | @Override 123 | public void keyTyped(KeyEvent e) { 124 | } 125 | 126 | @Override 127 | public void keyPressed(KeyEvent e) { 128 | DoctorEnter(e); 129 | } 130 | 131 | @Override 132 | public void keyReleased(KeyEvent e) { 133 | 134 | } 135 | }); 136 | DoctorLoginButton.addActionListener(new ActionListener() { 137 | @Override 138 | public void actionPerformed(ActionEvent e) { 139 | DoctorLogin(); 140 | } 141 | }); 142 | } 143 | 144 | public void setPatient() { 145 | PatientName.addKeyListener(new KeyListener() { 146 | @Override 147 | public void keyTyped(KeyEvent e) { 148 | } 149 | 150 | @Override 151 | public void keyPressed(KeyEvent e) { 152 | PatientEnter(e); 153 | } 154 | 155 | @Override 156 | public void keyReleased(KeyEvent e) { 157 | 158 | } 159 | }); 160 | PatientPassword.addKeyListener(new KeyListener() { 161 | @Override 162 | public void keyTyped(KeyEvent e) { 163 | } 164 | 165 | @Override 166 | public void keyPressed(KeyEvent e) { 167 | PatientEnter(e); 168 | } 169 | 170 | @Override 171 | public void keyReleased(KeyEvent e) { 172 | 173 | } 174 | }); 175 | UserLoginButton.addActionListener(new ActionListener() { 176 | @Override 177 | public void actionPerformed(ActionEvent e) { 178 | PatientLogin(); 179 | } 180 | }); 181 | } 182 | 183 | public void setPharmacy() { 184 | PharmacyNum.addKeyListener(new KeyListener() { 185 | @Override 186 | public void keyTyped(KeyEvent e) { 187 | } 188 | 189 | @Override 190 | public void keyPressed(KeyEvent e) { 191 | PharmacyEnter(e); 192 | } 193 | 194 | @Override 195 | public void keyReleased(KeyEvent e) { 196 | 197 | } 198 | }); 199 | PharmacyPassword.addKeyListener(new KeyListener() { 200 | @Override 201 | public void keyTyped(KeyEvent e) { 202 | } 203 | 204 | @Override 205 | public void keyPressed(KeyEvent e) { 206 | PharmacyEnter(e); 207 | } 208 | 209 | @Override 210 | public void keyReleased(KeyEvent e) { 211 | 212 | } 213 | }); 214 | PharmacyLoginButton.addActionListener(new ActionListener() { 215 | @Override 216 | public void actionPerformed(ActionEvent e) { 217 | PharmacyLogin(); 218 | } 219 | }); 220 | } 221 | 222 | public void DoctorEnter(KeyEvent e) { 223 | if (e.getKeyCode() == KeyEvent.VK_ENTER) 224 | DoctorLogin(); 225 | } 226 | 227 | public void DoctorLogin() { 228 | //noinspection deprecation 229 | if (DoctorPass.getText().equals("") || DoctorNum.getText().equals("")) 230 | JOptionPane.showMessageDialog(frame, "请完整填写登录信息!", "警告", JOptionPane.ERROR_MESSAGE); 231 | else { 232 | try { 233 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 234 | "SELECT Password FROM User WHERE UserType='医师' AND UID=?"); 235 | preparedStatement.setString(1, DoctorNum.getText()); 236 | ResultSet resultSet = preparedStatement.executeQuery(); 237 | resultSet.next(); 238 | String Password = resultSet.getString("Password"); 239 | //noinspection deprecation 240 | if (MD5.md5(DoctorPass.getText()).equals(Password)) { 241 | Keys.UID = DoctorNum.getText(); 242 | frame.dispose(); 243 | DoctorMainUI.main(null); 244 | } else { 245 | JOptionPane.showMessageDialog(frame, "工号或密码错误!", "警告", JOptionPane.ERROR_MESSAGE); 246 | } 247 | } catch (Exception e) { 248 | JOptionPane.showMessageDialog(frame, "工号不存在!", "警告", JOptionPane.ERROR_MESSAGE); 249 | 250 | } 251 | } 252 | } 253 | 254 | public void PatientEnter(KeyEvent e) { 255 | if (e.getKeyCode() == KeyEvent.VK_ENTER) 256 | PatientLogin(); 257 | } 258 | 259 | public void PatientLogin() { 260 | //noinspection deprecation 261 | if (PatientName.getText().equals("") || PatientPassword.getText().equals("")) 262 | JOptionPane.showMessageDialog(frame, "请完整填写登录信息!", "警告", JOptionPane.ERROR_MESSAGE); 263 | else { 264 | try { 265 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 266 | "SELECT Password,UID FROM User WHERE UserType='患者' AND Username=?"); 267 | preparedStatement.setString(1, PatientName.getText()); 268 | ResultSet resultSet = preparedStatement.executeQuery(); 269 | resultSet.next(); 270 | String Password = resultSet.getString("Password"); 271 | //noinspection deprecation 272 | if (MD5.md5(PatientPassword.getText()).equals(Password)) { 273 | Keys.UID = resultSet.getString("UID"); 274 | frame.dispose(); 275 | PatientMainUI.main(null); 276 | } else { 277 | JOptionPane.showMessageDialog(frame, "用户名或密码错误!", "警告", JOptionPane.ERROR_MESSAGE); 278 | } 279 | } catch (Exception e) { 280 | JOptionPane.showMessageDialog(frame, "用户名不存在!", "警告", JOptionPane.ERROR_MESSAGE); 281 | } 282 | } 283 | } 284 | 285 | public void PharmacyEnter(KeyEvent e) { 286 | if (e.getKeyCode() == KeyEvent.VK_ENTER) 287 | PharmacyLogin(); 288 | } 289 | 290 | public void PharmacyLogin() { 291 | //noinspection deprecation 292 | if (PharmacyNum.getText().equals("") || PharmacyPassword.getText().equals("")) 293 | JOptionPane.showMessageDialog(frame, "请完整填写登录信息!", "警告", JOptionPane.ERROR_MESSAGE); 294 | else { 295 | try { 296 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 297 | "SELECT Password,UID FROM User WHERE UserType='药师' AND UID=?"); 298 | preparedStatement.setString(1, PharmacyNum.getText()); 299 | ResultSet resultSet = preparedStatement.executeQuery(); 300 | resultSet.next(); 301 | String Password = resultSet.getString("Password"); 302 | //noinspection deprecation 303 | if (MD5.md5(PharmacyPassword.getText()).equals(Password)) { 304 | Keys.UID = resultSet.getString("UID"); 305 | frame.dispose(); 306 | PharmacyMainUI.main(null); 307 | } else { 308 | JOptionPane.showMessageDialog(frame, "工号或密码错误!", "警告", JOptionPane.ERROR_MESSAGE); 309 | } 310 | } catch (Exception e) { 311 | JOptionPane.showMessageDialog(frame, "工号不存在!", "警告", JOptionPane.ERROR_MESSAGE); 312 | } 313 | } 314 | } 315 | } 316 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/source/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UtopiaXC/OutpatientManagementSystem/aebb3d37552d2d78abd6980ec923b5001d848472/src/com/dlnu/oms/source/logo.png -------------------------------------------------------------------------------- /src/com/dlnu/oms/ui/DoctorMainUI.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/ui/DoctorMainUI.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.ui; 2 | 3 | import com.dlnu.oms.constant.Keys; 4 | 5 | import javax.swing.*; 6 | import javax.swing.event.PopupMenuEvent; 7 | import javax.swing.event.PopupMenuListener; 8 | import java.awt.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.awt.event.MouseAdapter; 12 | import java.awt.event.MouseEvent; 13 | import java.io.File; 14 | import java.io.FileOutputStream; 15 | import java.io.OutputStreamWriter; 16 | import java.nio.charset.StandardCharsets; 17 | import java.sql.PreparedStatement; 18 | import java.sql.ResultSet; 19 | import java.util.Objects; 20 | 21 | public class DoctorMainUI { 22 | private JPanel panel; 23 | private JComboBox comboBoxHistory; 24 | private JComboBox comboBoxPatient; 25 | private JLabel LabelRGID; 26 | private JLabel LabelName; 27 | private JLabel LabelAge; 28 | private JLabel LabelSex; 29 | private JLabel LabelID; 30 | private JLabel LabelAllergies; 31 | private JLabel LabelDiseases; 32 | private JButton buttonSelectPatient; 33 | private JButton buttonSelectDiagnosis; 34 | private JTextArea textAreaDiagnosis; 35 | private JTextArea textAreaAdvice; 36 | private JButton ButtonDiagnosisSubmit; 37 | private JTextField textFieldSearch; 38 | private JButton ButtonSearch; 39 | private JComboBox comboBoxMedicine; 40 | private JTextField textFieldCount; 41 | private JButton ButtonMedicineSubmit; 42 | private JTextArea textAreaMedicine; 43 | private JButton ButtonReleaseCSV; 44 | private static JFrame frame; 45 | private String RGID; 46 | 47 | public DoctorMainUI() { 48 | LabelRGID.setText("未选择病人"); 49 | LabelName.setText(""); 50 | LabelAge.setText(""); 51 | LabelSex.setText(""); 52 | LabelID.setText(""); 53 | LabelAllergies.setText(""); 54 | LabelDiseases.setText(""); 55 | ButtonMedicineSubmit.setEnabled(false); 56 | ButtonDiagnosisSubmit.setEnabled(false); 57 | 58 | setPatients(); 59 | setButtonSelectDiagnosis(); 60 | setButtonReleaseCSV(); 61 | 62 | buttonSelectPatient.addActionListener(new ActionListener() { 63 | @Override 64 | public void actionPerformed(ActionEvent e) { 65 | selectPatient(); 66 | } 67 | }); 68 | 69 | ButtonSearch.addActionListener(new ActionListener() { 70 | @Override 71 | public void actionPerformed(ActionEvent e) { 72 | searchMedicine(); 73 | } 74 | }); 75 | 76 | ButtonMedicineSubmit.addActionListener(new ActionListener() { 77 | @Override 78 | public void actionPerformed(ActionEvent e) { 79 | submitMedicine(); 80 | } 81 | }); 82 | 83 | ButtonDiagnosisSubmit.addActionListener(new ActionListener() { 84 | @Override 85 | public void actionPerformed(ActionEvent e) { 86 | submitDiagnosis(); 87 | } 88 | }); 89 | 90 | comboBoxPatient.addPopupMenuListener(new PopupMenuListener() { 91 | @Override 92 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 93 | 94 | comboBoxPatient.removeAllItems(); 95 | try { 96 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 97 | "SELECT registered.RGID,record.Name FROM registered,record WHERE record.RID=registered.RID AND registered.IsOver='否' AND registered.Doctor=(SELECT ID FROM user WHERE UID=?)"); 98 | preparedStatement.setString(1, Keys.UID); 99 | ResultSet resultSet = preparedStatement.executeQuery(); 100 | while (resultSet.next()) { 101 | comboBoxPatient.addItem(resultSet.getString("RGID") + "-" + resultSet.getString("Name")); 102 | } 103 | } catch (Exception ex) { 104 | ex.printStackTrace(); 105 | } 106 | } 107 | 108 | @Override 109 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { 110 | 111 | } 112 | 113 | @Override 114 | public void popupMenuCanceled(PopupMenuEvent e) { 115 | 116 | } 117 | }); 118 | } 119 | 120 | public static void main(String[] args) { 121 | frame = new JFrame("医师客户端"); 122 | frame.setIconImage(new ImageIcon("src/com/dlnu/oms/source/logo.png").getImage()); 123 | frame.setContentPane(new DoctorMainUI().panel); 124 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 125 | frame.setPreferredSize(new Dimension(1000, 800)); 126 | frame.pack(); 127 | frame.setVisible(true); 128 | } 129 | 130 | public void setPatients(){ 131 | comboBoxPatient.removeAllItems(); 132 | try { 133 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 134 | "SELECT registered.RGID,record.Name FROM registered,record WHERE record.RID=registered.RID AND registered.IsOver='否' AND registered.Doctor=(SELECT ID FROM user WHERE UID=?)"); 135 | preparedStatement.setString(1, Keys.UID); 136 | ResultSet resultSet = preparedStatement.executeQuery(); 137 | while (resultSet.next()) { 138 | comboBoxPatient.addItem(resultSet.getString("RGID") + "-" + resultSet.getString("Name")); 139 | } 140 | } catch (Exception e) { 141 | e.printStackTrace(); 142 | } 143 | } 144 | 145 | public void selectPatient() { 146 | RGID = Objects.requireNonNull(comboBoxPatient.getSelectedItem()).toString().split("-")[0]; 147 | ButtonMedicineSubmit.setEnabled(true); 148 | ButtonDiagnosisSubmit.setEnabled(true); 149 | textAreaAdvice.setText(""); 150 | textAreaAdvice.setEnabled(true); 151 | textAreaDiagnosis.setText(""); 152 | textAreaDiagnosis.setEnabled(true); 153 | comboBoxHistory.removeAllItems(); 154 | try { 155 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 156 | "SELECT * FROM record WHERE RID=(SELECT RID FROM registered WHERE RGID=?)"); 157 | preparedStatement.setString(1, RGID); 158 | ResultSet resultSet = preparedStatement.executeQuery(); 159 | resultSet.next(); 160 | LabelRGID.setText(RGID); 161 | LabelName.setText(resultSet.getString("Name")); 162 | LabelAge.setText(resultSet.getString("Age")); 163 | LabelSex.setText(resultSet.getString("Sex")); 164 | LabelID.setText(resultSet.getString("IDNumber")); 165 | String Allergies=resultSet.getString("Allergies"); 166 | String Diseases=resultSet.getString("MajorDiseases"); 167 | LabelAllergies.setText(Allergies); 168 | LabelDiseases.setText(Diseases); 169 | if (Allergies==null) 170 | LabelAllergies.setText("无"); 171 | if (Diseases==null) 172 | LabelDiseases.setText("无"); 173 | 174 | } catch (Exception e) { 175 | e.printStackTrace(); 176 | } 177 | try { 178 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 179 | "SELECT * FROM registered WHERE IsOver='是' AND RID=(SELECT RID FROM registered WHERE RGID=?)"); 180 | preparedStatement.setString(1, RGID); 181 | ResultSet resultSet = preparedStatement.executeQuery(); 182 | while (resultSet.next()) { 183 | comboBoxHistory.addItem(resultSet.getString("RGID")); 184 | } 185 | } catch (Exception e) { 186 | e.printStackTrace(); 187 | } 188 | 189 | try { 190 | textAreaMedicine.setText(""); 191 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 192 | "SELECT prescription.UnitPrice,prescription.Count,pharmacy.Name,pharmacy.MedicineType FROM pharmacy,prescription WHERE prescription.RGID=? AND pharmacy.MID=prescription.MID"); 193 | preparedStatement.setString(1, RGID); 194 | ResultSet resultSet = preparedStatement.executeQuery(); 195 | while (resultSet.next()) { 196 | textAreaMedicine.append(resultSet.getString("MedicineType")+" : "+resultSet.getInt("UnitPrice")+"元*"+resultSet.getInt("Count")+"份 : "+resultSet.getString("Name")+"\n"); 197 | } 198 | } catch (Exception e) { 199 | e.printStackTrace(); 200 | } 201 | } 202 | 203 | public void searchMedicine(){ 204 | if (textFieldSearch.getText().equals("")) 205 | return; 206 | try { 207 | comboBoxMedicine.removeAllItems(); 208 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 209 | "SELECT MID,Name FROM pharmacy WHERE MID LIKE ? OR Name LIKE ? OR Manufacturer LIKE ?"); 210 | preparedStatement.setString(1, "%"+textFieldSearch.getText()+"%"); 211 | preparedStatement.setString(2, "%"+textFieldSearch.getText()+"%"); 212 | preparedStatement.setString(3, "%"+textFieldSearch.getText()+"%"); 213 | ResultSet resultSet = preparedStatement.executeQuery(); 214 | while (resultSet.next()) { 215 | comboBoxMedicine.addItem(resultSet.getString("MID") + "-" + resultSet.getString("Name")); 216 | } 217 | }catch (Exception e){ 218 | e.printStackTrace(); 219 | } 220 | } 221 | 222 | public void submitMedicine(){ 223 | if(Objects.requireNonNull(comboBoxMedicine.getSelectedItem()).toString().equals("")|| textFieldCount.getText().equals("")){ 224 | return; 225 | } 226 | String MID=Objects.requireNonNull(comboBoxMedicine.getSelectedItem()).toString().split("-")[0]; 227 | int count = 0; 228 | try { 229 | count = Integer.parseInt(textFieldCount.getText()); 230 | }catch (Exception e){ 231 | JOptionPane.showMessageDialog(frame,"存在错误输入!","警告!", JOptionPane.ERROR_MESSAGE); 232 | return; 233 | } 234 | try { 235 | comboBoxMedicine.removeAllItems(); 236 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 237 | "INSERT INTO Prescription(RGID,MID,Count)VALUES(?,?,?)"); 238 | preparedStatement.setString(1,RGID); 239 | preparedStatement.setString(2, MID); 240 | preparedStatement.setInt(3, count); 241 | preparedStatement.execute(); 242 | selectPatient(); 243 | }catch (Exception e){ 244 | e.printStackTrace(); 245 | } 246 | } 247 | 248 | public void submitDiagnosis(){ 249 | try { 250 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 251 | "UPDATE diagnosis SET Diagnosis=? , Advice=? WHERE RGID=?"); 252 | preparedStatement.setString(1, textAreaDiagnosis.getText()); 253 | preparedStatement.setString(2, textAreaAdvice.getText()); 254 | preparedStatement.setString(3, RGID); 255 | preparedStatement.execute(); 256 | }catch (Exception e){ 257 | e.printStackTrace(); 258 | } 259 | 260 | LabelRGID.setText("未选择病人"); 261 | LabelName.setText(""); 262 | LabelAge.setText(""); 263 | LabelSex.setText(""); 264 | LabelID.setText(""); 265 | LabelAllergies.setText(""); 266 | LabelDiseases.setText(""); 267 | ButtonMedicineSubmit.setEnabled(false); 268 | ButtonDiagnosisSubmit.setEnabled(false); 269 | textAreaDiagnosis.setText(""); 270 | textAreaAdvice.setText(""); 271 | textAreaMedicine.setText(""); 272 | RGID=null; 273 | setPatients(); 274 | } 275 | 276 | public void setButtonSelectDiagnosis(){ 277 | buttonSelectDiagnosis.addActionListener(new ActionListener() { 278 | @Override 279 | public void actionPerformed(ActionEvent e) { 280 | RGID = Objects.requireNonNull(comboBoxHistory.getSelectedItem()).toString(); 281 | ButtonMedicineSubmit.setEnabled(false); 282 | ButtonDiagnosisSubmit.setEnabled(false); 283 | try { 284 | textAreaMedicine.setText(""); 285 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 286 | "SELECT prescription.UnitPrice,prescription.Count,pharmacy.Name,pharmacy.MedicineType FROM pharmacy,prescription WHERE prescription.RGID=? AND pharmacy.MID=prescription.MID"); 287 | preparedStatement.setString(1, RGID); 288 | ResultSet resultSet = preparedStatement.executeQuery(); 289 | while (resultSet.next()) { 290 | textAreaMedicine.append(resultSet.getString("MedicineType")+" : "+resultSet.getInt("UnitPrice")+"元*"+resultSet.getInt("Count")+"份 : "+resultSet.getString("Name")+"\n"); 291 | } 292 | } catch (Exception ez) { 293 | ez.printStackTrace(); 294 | } 295 | try { 296 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 297 | "SELECT * From diagnosis WHERE RGID=?"); 298 | preparedStatement.setString(1, RGID); 299 | ResultSet resultSet = preparedStatement.executeQuery(); 300 | resultSet.next(); 301 | textAreaAdvice.setText(resultSet.getString("Advice")); 302 | textAreaAdvice.setEnabled(false); 303 | textAreaDiagnosis.setText(resultSet.getString("Diagnosis")); 304 | textAreaDiagnosis.setEnabled(false); 305 | } catch (Exception ez) { 306 | ez.printStackTrace(); 307 | } 308 | } 309 | }); 310 | } 311 | 312 | public void setButtonReleaseCSV(){ 313 | ButtonReleaseCSV.addActionListener(new ActionListener() { 314 | @Override 315 | public void actionPerformed(ActionEvent e) { 316 | try { 317 | File file = new File("医师导出.csv"); 318 | if (file.exists()) { 319 | boolean succeedDeleted = file.delete(); 320 | } 321 | FileOutputStream fileOutputStream = new FileOutputStream(file); 322 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "GBK"); 323 | PreparedStatement preparedStatement=Keys.connection.prepareStatement( 324 | "SELECT * FROM registered,diagnosis,record WHERE record.RID=registered.RID AND registered.RGID=diagnosis.RGID AND registered.Doctor=(SELECT ID From user WHERE UID=?)"); 325 | preparedStatement.setString(1,Keys.UID); 326 | ResultSet resultSet=preparedStatement.executeQuery(); 327 | outputStreamWriter.append("病历单号,诊断,医嘱,是否诊断完成,患者ID,患者姓名,患者年龄,患者性别,患者身份证号,患者过敏史,患者重大疾病史\n"); 328 | while (resultSet.next()){ 329 | outputStreamWriter.append(resultSet.getString("RGID")).append(",") 330 | .append(resultSet.getString("Diagnosis")).append(",") 331 | .append(resultSet.getString("Advice")).append(",") 332 | .append(resultSet.getString("IsOver")).append(",") 333 | .append(resultSet.getString("RID")).append(",") 334 | .append(resultSet.getString("Name")).append(",") 335 | .append(resultSet.getString("Age")).append(",") 336 | .append(resultSet.getString("Sex")).append(",") 337 | .append(resultSet.getString("IDNumber")).append(",") 338 | .append(resultSet.getString("Allergies")).append(",") 339 | .append(resultSet.getString("MajorDiseases")).append("\n"); 340 | } 341 | 342 | preparedStatement=Keys.connection.prepareStatement( 343 | "SELECT * FROM registered,prescription,pharmacy WHERE registered.RGID=prescription.RGID AND pharmacy.MID=prescription.MID AND registered.Doctor=(SELECT ID From user WHERE UID=?)"); 344 | preparedStatement.setString(1,Keys.UID); 345 | resultSet=preparedStatement.executeQuery(); 346 | outputStreamWriter.append("\n\n病历单号,处方品号,处方品名,类型,制造商,单价,份数,总价\n"); 347 | while (resultSet.next()){ 348 | outputStreamWriter.append(resultSet.getString("RGID")).append(",") 349 | .append(resultSet.getString("MID")).append(",") 350 | .append(resultSet.getString("Name")).append(",") 351 | .append(resultSet.getString("MedicineType")).append(",") 352 | .append(resultSet.getString("Manufacturer")).append(",") 353 | .append(resultSet.getString("UnitPrice")).append(",") 354 | .append(resultSet.getString("Count")).append(",") 355 | .append(resultSet.getString("Price")).append("\n"); 356 | } 357 | 358 | outputStreamWriter.close(); 359 | fileOutputStream.close(); 360 | JOptionPane.showMessageDialog(frame,"导出成功!","成功", JOptionPane.PLAIN_MESSAGE); 361 | 362 | 363 | }catch (Exception e1){ 364 | JOptionPane.showMessageDialog(frame,"导出失败!","警告", JOptionPane.ERROR_MESSAGE); 365 | e1.printStackTrace(); 366 | } 367 | } 368 | }); 369 | } 370 | } 371 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/ui/PatientMainUI.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.ui; 2 | 3 | import com.dlnu.oms.constant.Keys; 4 | 5 | import javax.swing.*; 6 | import javax.swing.event.PopupMenuEvent; 7 | import javax.swing.event.PopupMenuListener; 8 | import java.awt.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.io.File; 12 | import java.io.FileOutputStream; 13 | import java.io.OutputStreamWriter; 14 | import java.sql.PreparedStatement; 15 | import java.sql.ResultSet; 16 | import java.util.Objects; 17 | 18 | public class PatientMainUI { 19 | private JPanel panel; 20 | private JTabbedPane tabbedPane1; 21 | private JTextField textFieldName; 22 | private JButton ButtonSubmitUpdate; 23 | private JTextField textFieldIDNumber; 24 | private JTextField textFieldAge; 25 | private JTextField textFieldSex; 26 | private JTextField textFieldAllergies; 27 | private JTextField textFieldDiseases; 28 | private JComboBox comboBoxDepartment; 29 | private JButton ButtonDepartmentSubmit; 30 | private JComboBox comboBoxDoctor; 31 | private JButton ButtonRegisterSubmit; 32 | private JComboBox comboBoxHistory; 33 | private JButton ButtonHistorySubmit; 34 | private JTextArea textAreaDiagnosis; 35 | private JTextArea textAreaMedicine; 36 | private JTextArea textAreaAdvice; 37 | private JComboBox comboBoxTicket; 38 | private JButton ButtonTicketSubmit; 39 | private JLabel LabelCost; 40 | private JLabel LabelArrears; 41 | private JLabel LabelLatestTime; 42 | private JButton ButtonPayTicket; 43 | private JButton ButtonReleaseCSV; 44 | private static JFrame frame; 45 | 46 | public PatientMainUI() { 47 | setMessages(); 48 | setComboBoxDepartment(); 49 | setComboBoxHistory(); 50 | setComboBoxTicket(); 51 | setButtonRegisterSubmit(); 52 | setButtonHistorySubmit(); 53 | setButtonTicketSubmit(); 54 | setButtonReleaseCSV(); 55 | } 56 | 57 | public static void main(String[] args) { 58 | frame = new JFrame("患者客户端"); 59 | frame.setIconImage(new ImageIcon("src/com/dlnu/oms/source/logo.png").getImage()); 60 | frame.setContentPane(new PatientMainUI().panel); 61 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 62 | frame.setPreferredSize(new Dimension(1000, 600)); 63 | frame.pack(); 64 | frame.setVisible(true); 65 | } 66 | 67 | public void setMessages() { 68 | try { 69 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 70 | "SELECT * FROM record WHERE RID=(SELECT ID FROM user WHERE UID=?)"); 71 | preparedStatement.setString(1, Keys.UID); 72 | ResultSet resultSet = preparedStatement.executeQuery(); 73 | if (resultSet.next()) { 74 | textFieldName.setText(resultSet.getString("Name")); 75 | textFieldAge.setText(resultSet.getString("Age")); 76 | textFieldSex.setText(resultSet.getString("Sex")); 77 | textFieldIDNumber.setText(resultSet.getString("IDNumber")); 78 | textFieldAllergies.setText(resultSet.getString("Allergies")); 79 | textFieldDiseases.setText(resultSet.getString("MajorDiseases")); 80 | } 81 | 82 | } catch (Exception e) { 83 | e.printStackTrace(); 84 | } 85 | 86 | ButtonSubmitUpdate.addActionListener(new ActionListener() { 87 | @Override 88 | public void actionPerformed(ActionEvent e) { 89 | if (textFieldName.getText().equals("") || 90 | textFieldAge.getText().equals("") || 91 | textFieldSex.getText().equals("") || 92 | textFieldIDNumber.getText().equals("")) { 93 | JOptionPane.showMessageDialog(frame, "身份证号,姓名,年龄和性别为必填项!", "警告", JOptionPane.ERROR_MESSAGE); 94 | return; 95 | } 96 | if (!textFieldSex.getText().equals("男") && ! 97 | textFieldSex.getText().equals("女")) { 98 | JOptionPane.showMessageDialog(frame, "性别必须为男或女!", "警告", JOptionPane.ERROR_MESSAGE); 99 | return; 100 | } 101 | try { 102 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 103 | "UPDATE record SET Name=?,Age=?,Sex=?,IDNumber=?,Allergies=?,MajorDiseases=? WHERE RID=(SELECT ID FROM user WHERE UID=?)"); 104 | preparedStatement.setString(1, textFieldName.getText()); 105 | preparedStatement.setString(2, textFieldAge.getText()); 106 | preparedStatement.setString(3, textFieldSex.getText()); 107 | preparedStatement.setString(4, textFieldIDNumber.getText()); 108 | preparedStatement.setString(5, textFieldAllergies.getText()); 109 | preparedStatement.setString(6, textFieldDiseases.getText()); 110 | preparedStatement.setString(7, Keys.UID); 111 | preparedStatement.execute(); 112 | JOptionPane.showMessageDialog(frame, "修改完成!", "成功", JOptionPane.PLAIN_MESSAGE); 113 | } catch (Exception ex) { 114 | JOptionPane.showMessageDialog(frame, "存在数字格式错误!", "警告", JOptionPane.ERROR_MESSAGE); 115 | ex.printStackTrace(); 116 | } 117 | 118 | } 119 | }); 120 | } 121 | 122 | public void setComboBoxDepartment() { 123 | try { 124 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 125 | "SELECT Department FROM doctor GROUP BY Department"); 126 | ResultSet resultSet = preparedStatement.executeQuery(); 127 | while (resultSet.next()) { 128 | comboBoxDepartment.addItem(resultSet.getString("Department")); 129 | } 130 | } catch (Exception e) { 131 | e.printStackTrace(); 132 | } 133 | 134 | ButtonDepartmentSubmit.addActionListener(new ActionListener() { 135 | @Override 136 | public void actionPerformed(ActionEvent e) { 137 | try { 138 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 139 | "SELECT * FROM doctor WHERE Department=?"); 140 | preparedStatement.setString(1, Objects.requireNonNull(comboBoxDepartment.getSelectedItem()).toString()); 141 | ResultSet resultSet = preparedStatement.executeQuery(); 142 | comboBoxDoctor.removeAllItems(); 143 | while (resultSet.next()) { 144 | comboBoxDoctor.addItem(resultSet.getString("DID") + "-" + resultSet.getString("Name")); 145 | } 146 | ButtonRegisterSubmit.setEnabled(true); 147 | } catch (Exception ex) { 148 | ex.printStackTrace(); 149 | } 150 | } 151 | }); 152 | } 153 | 154 | public void setComboBoxHistory() { 155 | try { 156 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 157 | "SELECT RGID FROM registered WHERE RID=(SELECT ID FROM user WHERE UID=?)"); 158 | preparedStatement.setString(1, Keys.UID); 159 | ResultSet resultSet = preparedStatement.executeQuery(); 160 | while (resultSet.next()) { 161 | comboBoxHistory.addItem(resultSet.getString("RGID")); 162 | } 163 | } catch (Exception e) { 164 | e.printStackTrace(); 165 | } 166 | comboBoxHistory.addPopupMenuListener(new PopupMenuListener() { 167 | @Override 168 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 169 | comboBoxHistory.removeAllItems(); 170 | try { 171 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 172 | "SELECT RGID FROM registered WHERE RID=(SELECT ID FROM user WHERE UID=?)"); 173 | preparedStatement.setString(1, Keys.UID); 174 | ResultSet resultSet = preparedStatement.executeQuery(); 175 | while (resultSet.next()) { 176 | comboBoxHistory.addItem(resultSet.getString("RGID")); 177 | } 178 | } catch (Exception ex) { 179 | ex.printStackTrace(); 180 | } 181 | } 182 | 183 | @Override 184 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { 185 | 186 | } 187 | 188 | @Override 189 | public void popupMenuCanceled(PopupMenuEvent e) { 190 | 191 | } 192 | }); 193 | } 194 | 195 | public void setComboBoxTicket() { 196 | try { 197 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 198 | "SELECT RGID FROM registered WHERE RID=(SELECT ID FROM user WHERE UID=?)"); 199 | preparedStatement.setString(1, Keys.UID); 200 | ResultSet resultSet = preparedStatement.executeQuery(); 201 | while (resultSet.next()) { 202 | comboBoxTicket.addItem(resultSet.getString("RGID")); 203 | } 204 | } catch (Exception e) { 205 | e.printStackTrace(); 206 | } 207 | comboBoxTicket.addPopupMenuListener(new PopupMenuListener() { 208 | @Override 209 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 210 | comboBoxTicket.removeAllItems(); 211 | try { 212 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 213 | "SELECT RGID FROM registered WHERE RID=(SELECT ID FROM user WHERE UID=?)"); 214 | preparedStatement.setString(1, Keys.UID); 215 | ResultSet resultSet = preparedStatement.executeQuery(); 216 | while (resultSet.next()) { 217 | comboBoxTicket.addItem(resultSet.getString("RGID")); 218 | } 219 | } catch (Exception ex) { 220 | ex.printStackTrace(); 221 | } 222 | } 223 | 224 | @Override 225 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { 226 | 227 | } 228 | 229 | @Override 230 | public void popupMenuCanceled(PopupMenuEvent e) { 231 | 232 | } 233 | }); 234 | } 235 | 236 | public void setButtonRegisterSubmit() { 237 | ButtonRegisterSubmit.addActionListener(new ActionListener() { 238 | @Override 239 | public void actionPerformed(ActionEvent e) { 240 | try { 241 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 242 | "SELECT ID FROM user WHERE UID=?"); 243 | preparedStatement.setString(1, Keys.UID); 244 | ResultSet resultSet = preparedStatement.executeQuery(); 245 | resultSet.next(); 246 | String RID = resultSet.getString("ID"); 247 | 248 | preparedStatement = Keys.connection.prepareStatement( 249 | "SELECT * FROM registered WHERE RID=? AND IsOver='否'"); 250 | preparedStatement.setString(1, RID); 251 | resultSet = preparedStatement.executeQuery(); 252 | if (resultSet.next()) { 253 | JOptionPane.showMessageDialog(frame, "您有未完成的诊号,请完成后再进行挂号!", "警告", JOptionPane.ERROR_MESSAGE); 254 | return; 255 | } 256 | 257 | 258 | preparedStatement = Keys.connection.prepareStatement( 259 | "INSERT INTO Registered(RID,Department,Doctor)values(?,?,?)"); 260 | preparedStatement.setString(1, RID); 261 | preparedStatement.setString(2, Objects.requireNonNull(comboBoxDepartment.getSelectedItem()).toString()); 262 | preparedStatement.setString(3, Objects.requireNonNull(comboBoxDoctor.getSelectedItem()).toString().split("-")[0]); 263 | preparedStatement.execute(); 264 | JOptionPane.showMessageDialog(frame, "挂号完成!", "成功", JOptionPane.PLAIN_MESSAGE); 265 | 266 | } catch (Exception ex) { 267 | ex.printStackTrace(); 268 | } 269 | } 270 | }); 271 | } 272 | 273 | public void setButtonHistorySubmit() { 274 | ButtonHistorySubmit.addActionListener(new ActionListener() { 275 | @Override 276 | public void actionPerformed(ActionEvent e) { 277 | try { 278 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 279 | "SELECT * From diagnosis WHERE RGID=?"); 280 | preparedStatement.setString(1, Objects.requireNonNull(comboBoxHistory.getSelectedItem()).toString()); 281 | ResultSet resultSet = preparedStatement.executeQuery(); 282 | resultSet.next(); 283 | textAreaAdvice.setText(resultSet.getString("Advice")); 284 | textAreaDiagnosis.setText(resultSet.getString("Diagnosis")); 285 | } catch (Exception ez) { 286 | ez.printStackTrace(); 287 | } 288 | try { 289 | textAreaMedicine.setText(""); 290 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 291 | "SELECT prescription.UnitPrice,prescription.Count,pharmacy.Name,pharmacy.MedicineType FROM pharmacy,prescription WHERE prescription.RGID=? AND pharmacy.MID=prescription.MID"); 292 | preparedStatement.setString(1, Objects.requireNonNull(comboBoxHistory.getSelectedItem()).toString()); 293 | ResultSet resultSet = preparedStatement.executeQuery(); 294 | while (resultSet.next()) { 295 | textAreaMedicine.append(resultSet.getString("MedicineType") + " : " + resultSet.getInt("UnitPrice") + "元*" + resultSet.getInt("Count") + "份 : " + resultSet.getString("Name") + "\n"); 296 | } 297 | } catch (Exception ez) { 298 | ez.printStackTrace(); 299 | } 300 | } 301 | }); 302 | } 303 | 304 | public void setButtonTicketSubmit() { 305 | ButtonTicketSubmit.addActionListener(new ActionListener() { 306 | @Override 307 | public void actionPerformed(ActionEvent e) { 308 | try { 309 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 310 | "SELECT * From toll WHERE RGID=?"); 311 | preparedStatement.setString(1, Objects.requireNonNull(comboBoxTicket.getSelectedItem()).toString()); 312 | ResultSet resultSet = preparedStatement.executeQuery(); 313 | resultSet.next(); 314 | LabelCost.setText("总金额:" + resultSet.getString("Cost")); 315 | LabelArrears.setText("未缴纳:" + resultSet.getString("Arrears")); 316 | LabelLatestTime.setText("缴纳期限:" + resultSet.getString("LatestTime")); 317 | ButtonPayTicket.setEnabled(true); 318 | } catch (Exception ez) { 319 | ez.printStackTrace(); 320 | } 321 | } 322 | }); 323 | 324 | ButtonPayTicket.addActionListener(new ActionListener() { 325 | @Override 326 | public void actionPerformed(ActionEvent e) { 327 | try { 328 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 329 | "UPDATE toll SET Paid=Cost,Arrears=0 WHERE RGID=?"); 330 | preparedStatement.setString(1, Objects.requireNonNull(comboBoxTicket.getSelectedItem()).toString()); 331 | preparedStatement.execute(); 332 | JOptionPane.showMessageDialog(frame, "您的账单已缴纳!", "成功", JOptionPane.PLAIN_MESSAGE); 333 | ButtonTicketSubmit.doClick(); 334 | } catch (Exception ez) { 335 | ez.printStackTrace(); 336 | } 337 | } 338 | }); 339 | } 340 | 341 | public void setButtonReleaseCSV(){ 342 | ButtonReleaseCSV.addActionListener(new ActionListener() { 343 | @Override 344 | public void actionPerformed(ActionEvent e) { 345 | try { 346 | File file = new File("患者导出.csv"); 347 | if (file.exists()) { 348 | boolean succeedDeleted = file.delete(); 349 | } 350 | FileOutputStream fileOutputStream = new FileOutputStream(file); 351 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "GBK"); 352 | PreparedStatement preparedStatement=Keys.connection.prepareStatement( 353 | "SELECT * FROM registered,diagnosis,record WHERE record.RID=registered.RID AND registered.RGID=diagnosis.RGID AND registered.RID=(SELECT ID From user WHERE UID=?)"); 354 | preparedStatement.setString(1,Keys.UID); 355 | ResultSet resultSet=preparedStatement.executeQuery(); 356 | outputStreamWriter.append("病历单号,诊断,医嘱,是否诊断完成,患者ID,患者姓名,患者年龄,患者性别,患者身份证号,患者过敏史,患者重大疾病史\n"); 357 | while (resultSet.next()){ 358 | outputStreamWriter.append(resultSet.getString("RGID")).append(",") 359 | .append(resultSet.getString("Diagnosis")).append(",") 360 | .append(resultSet.getString("Advice")).append(",") 361 | .append(resultSet.getString("IsOver")).append(",") 362 | .append(resultSet.getString("RID")).append(",") 363 | .append(resultSet.getString("Name")).append(",") 364 | .append(resultSet.getString("Age")).append(",") 365 | .append(resultSet.getString("Sex")).append(",") 366 | .append(resultSet.getString("IDNumber")).append(",") 367 | .append(resultSet.getString("Allergies")).append(",") 368 | .append(resultSet.getString("MajorDiseases")).append("\n"); 369 | } 370 | 371 | preparedStatement=Keys.connection.prepareStatement( 372 | "SELECT * FROM registered,prescription,pharmacy WHERE registered.RGID=prescription.RGID AND pharmacy.MID=prescription.MID AND registered.RID=(SELECT ID From user WHERE UID=?)"); 373 | preparedStatement.setString(1,Keys.UID); 374 | resultSet=preparedStatement.executeQuery(); 375 | outputStreamWriter.append("\n\n病历单号,处方品号,处方品名,类型,制造商,单价,份数,总价\n"); 376 | while (resultSet.next()){ 377 | outputStreamWriter.append(resultSet.getString("RGID")).append(",") 378 | .append(resultSet.getString("MID")).append(",") 379 | .append(resultSet.getString("Name")).append(",") 380 | .append(resultSet.getString("MedicineType")).append(",") 381 | .append(resultSet.getString("Manufacturer")).append(",") 382 | .append(resultSet.getString("UnitPrice")).append(",") 383 | .append(resultSet.getString("Count")).append(",") 384 | .append(resultSet.getString("Price")).append("\n"); 385 | } 386 | 387 | outputStreamWriter.close(); 388 | fileOutputStream.close(); 389 | JOptionPane.showMessageDialog(frame,"导出成功!","成功", JOptionPane.PLAIN_MESSAGE); 390 | 391 | 392 | }catch (Exception e1){ 393 | JOptionPane.showMessageDialog(frame,"导出失败!","警告", JOptionPane.ERROR_MESSAGE); 394 | e1.printStackTrace(); 395 | } 396 | } 397 | }); 398 | } 399 | } 400 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/ui/PharmacyMainUI.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | -------------------------------------------------------------------------------- /src/com/dlnu/oms/ui/PharmacyMainUI.java: -------------------------------------------------------------------------------- 1 | package com.dlnu.oms.ui; 2 | 3 | import com.dlnu.oms.constant.Keys; 4 | 5 | import javax.swing.*; 6 | import javax.swing.event.PopupMenuEvent; 7 | import javax.swing.event.PopupMenuListener; 8 | import java.awt.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.io.File; 12 | import java.io.FileOutputStream; 13 | import java.io.OutputStreamWriter; 14 | import java.sql.PreparedStatement; 15 | import java.sql.ResultSet; 16 | import java.util.Objects; 17 | 18 | public class PharmacyMainUI { 19 | private JPanel panel; 20 | private JTextArea textAreaIncome; 21 | private JTextField textFieldName; 22 | private JButton ButtonInsertSubmit; 23 | private JTextField textFieldManufacturer; 24 | private JTextField textFieldMedicineType; 25 | private JTextField textFieldUnitPrice; 26 | private JTextField textFieldInStock; 27 | private JComboBox comboBoxMedicine; 28 | private JButton ButtonSelectMedicine; 29 | private JButton ButtonUpdateUnitPrice; 30 | private JTextField textFieldUpdateInStock; 31 | private JTextField textFieldUpdateUnitPrice; 32 | private JButton ButtonUpdateInStock; 33 | private JTextField textFieldUpdateName; 34 | private JTextField textFieldUpdateManufacturer; 35 | private JTextField textFieldUpdateMedicineType; 36 | private JButton ButtonRefresh; 37 | private JButton ButtonReleaseCSV; 38 | private static JFrame frame; 39 | 40 | public PharmacyMainUI(){ 41 | setTextAreaIncome(); 42 | setButtonInsertSubmit(); 43 | setManage(); 44 | setButtonReleaseCSV(); 45 | ButtonRefresh.addActionListener(new ActionListener() { 46 | @Override 47 | public void actionPerformed(ActionEvent e) { 48 | setTextAreaIncome(); 49 | } 50 | }); 51 | } 52 | 53 | public static void main(String[] args) { 54 | frame = new JFrame("药局客户端"); 55 | frame.setIconImage(new ImageIcon("src/com/dlnu/oms/source/logo.png").getImage()); 56 | frame.setContentPane(new PharmacyMainUI().panel); 57 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 58 | frame.setPreferredSize(new Dimension(1000, 800)); 59 | frame.pack(); 60 | frame.setVisible(true); 61 | } 62 | 63 | public void setTextAreaIncome(){ 64 | textAreaIncome.setText(""); 65 | try { 66 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 67 | "SELECT SUM(Cost),SUM(Paid),SUM(Arrears) From toll"); 68 | ResultSet resultSet = preparedStatement.executeQuery(); 69 | resultSet.next(); 70 | textAreaIncome.append("总应收:"+resultSet.getString("SUM(Cost)")+ 71 | "元\n总实收:"+resultSet.getString("SUM(Paid)")+ 72 | "元\n欠缴:"+resultSet.getString("SUM(Arrears)")+"元\n\n药品开出情况:\n"); 73 | 74 | preparedStatement = Keys.connection.prepareStatement( 75 | "SELECT prescription.UnitPrice,prescription.Count,pharmacy.Name,pharmacy.MedicineType FROM pharmacy,prescription WHERE pharmacy.MID=prescription.MID"); 76 | resultSet = preparedStatement.executeQuery(); 77 | while (resultSet.next()) { 78 | textAreaIncome.append(resultSet.getString("MedicineType") + " : " + resultSet.getInt("UnitPrice") + "元*" + resultSet.getInt("Count") + "份 : " + resultSet.getString("Name") + "\n"); 79 | } 80 | } catch (Exception ez) { 81 | ez.printStackTrace(); 82 | } 83 | } 84 | 85 | public void setButtonInsertSubmit(){ 86 | ButtonInsertSubmit.addActionListener(new ActionListener() { 87 | @Override 88 | public void actionPerformed(ActionEvent e) { 89 | if (textFieldName.getText().equals("") || 90 | textFieldManufacturer.getText().equals("") || 91 | textFieldMedicineType.getText().equals("") || 92 | textFieldUnitPrice.getText().equals("")|| 93 | textFieldInStock.getText().equals("")) { 94 | JOptionPane.showMessageDialog(frame, "有项目未填写!", "警告", JOptionPane.ERROR_MESSAGE); 95 | return; 96 | } 97 | if (!textFieldMedicineType.getText().equals("处方药") && ! 98 | textFieldMedicineType.getText().equals("非处方药")&& ! 99 | textFieldMedicineType.getText().equals("保健品")&& ! 100 | textFieldMedicineType.getText().equals("化验")&& ! 101 | textFieldMedicineType.getText().equals("手术器械")) { 102 | JOptionPane.showMessageDialog(frame, "类型请从处方药、非处方药、保健品、化验、手术器械中选取", "警告", JOptionPane.ERROR_MESSAGE); 103 | return; 104 | } 105 | try { 106 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 107 | "INSERT INTO pharmacy(MedicineType,Name,Manufacturer,UnitPrice,InStock)VALUES(?,?,?,?,?)"); 108 | preparedStatement.setString(1, textFieldMedicineType.getText()); 109 | preparedStatement.setString(2, textFieldName.getText()); 110 | preparedStatement.setString(3, textFieldManufacturer.getText()); 111 | preparedStatement.setString(4, textFieldUnitPrice.getText()); 112 | preparedStatement.setString(5, textFieldInStock.getText()); 113 | preparedStatement.execute(); 114 | JOptionPane.showMessageDialog(frame, "添加完成!", "成功", JOptionPane.PLAIN_MESSAGE); 115 | } catch (Exception ex) { 116 | JOptionPane.showMessageDialog(frame, "存在数字格式错误!", "警告", JOptionPane.ERROR_MESSAGE); 117 | ex.printStackTrace(); 118 | } 119 | } 120 | }); 121 | } 122 | 123 | public void setManage(){ 124 | try { 125 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 126 | "SELECT MID,Name From pharmacy"); 127 | ResultSet resultSet = preparedStatement.executeQuery(); 128 | while (resultSet.next()){ 129 | comboBoxMedicine.addItem(resultSet.getString("MID")+"-"+resultSet.getString("Name")); 130 | } 131 | }catch (Exception e){ 132 | e.printStackTrace(); 133 | } 134 | ButtonSelectMedicine.addActionListener(new ActionListener() { 135 | @Override 136 | public void actionPerformed(ActionEvent e) { 137 | try { 138 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 139 | "SELECT * From pharmacy WHERE MID=?"); 140 | preparedStatement.setString(1, Objects.requireNonNull(comboBoxMedicine.getSelectedItem()).toString().split("-")[0]); 141 | ResultSet resultSet = preparedStatement.executeQuery(); 142 | resultSet.next(); 143 | textFieldUpdateName.setText(resultSet.getString("Name")); 144 | textFieldUpdateManufacturer.setText(resultSet.getString("Manufacturer")); 145 | textFieldUpdateMedicineType.setText(resultSet.getString("MedicineType")); 146 | textFieldUpdateUnitPrice.setText(resultSet.getString("UnitPrice")); 147 | textFieldUpdateInStock.setText(resultSet.getString("InStock")); 148 | ButtonUpdateUnitPrice.setEnabled(true); 149 | ButtonUpdateInStock.setEnabled(true); 150 | }catch (Exception ex){ 151 | ex.printStackTrace(); 152 | } 153 | } 154 | }); 155 | ButtonUpdateUnitPrice.addActionListener(new ActionListener() { 156 | @Override 157 | public void actionPerformed(ActionEvent e) { 158 | if (textFieldUpdateUnitPrice.getText().equals("")){ 159 | JOptionPane.showMessageDialog(frame, "未填写内容!", "警告", JOptionPane.ERROR_MESSAGE); 160 | return; 161 | } 162 | try { 163 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 164 | "UPDATE pharmacy SET UnitPrice=? WHERE MID=?"); 165 | preparedStatement.setString(1, textFieldUpdateUnitPrice.getText()); 166 | preparedStatement.setString(2, Objects.requireNonNull(comboBoxMedicine.getSelectedItem()).toString().split("-")[0]); 167 | preparedStatement.execute(); 168 | JOptionPane.showMessageDialog(frame, "单价已修改!", "成功", JOptionPane.PLAIN_MESSAGE); 169 | 170 | }catch (Exception ex){ 171 | JOptionPane.showMessageDialog(frame, "数字格式错误!", "警告", JOptionPane.ERROR_MESSAGE); 172 | ex.printStackTrace(); 173 | } 174 | } 175 | }); 176 | 177 | ButtonUpdateInStock.addActionListener(new ActionListener() { 178 | @Override 179 | public void actionPerformed(ActionEvent e) { 180 | if (textFieldUpdateInStock.getText().equals("")){ 181 | JOptionPane.showMessageDialog(frame, "未填写内容!", "警告", JOptionPane.ERROR_MESSAGE); 182 | return; 183 | } 184 | try { 185 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 186 | "UPDATE pharmacy SET InStock=? WHERE MID=?"); 187 | preparedStatement.setString(1, textFieldUpdateInStock.getText()); 188 | preparedStatement.setString(2, Objects.requireNonNull(comboBoxMedicine.getSelectedItem()).toString().split("-")[0]); 189 | preparedStatement.execute(); 190 | JOptionPane.showMessageDialog(frame, "库存已修改!", "成功", JOptionPane.PLAIN_MESSAGE); 191 | 192 | }catch (Exception ex){ 193 | JOptionPane.showMessageDialog(frame, "数字格式错误!", "警告", JOptionPane.ERROR_MESSAGE); 194 | ex.printStackTrace(); 195 | } 196 | } 197 | }); 198 | 199 | comboBoxMedicine.addPopupMenuListener(new PopupMenuListener() { 200 | @Override 201 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 202 | comboBoxMedicine.removeAllItems(); 203 | try { 204 | PreparedStatement preparedStatement = Keys.connection.prepareStatement( 205 | "SELECT MID,Name From pharmacy"); 206 | ResultSet resultSet = preparedStatement.executeQuery(); 207 | while (resultSet.next()){ 208 | comboBoxMedicine.addItem(resultSet.getString("MID")+"-"+resultSet.getString("Name")); 209 | } 210 | }catch (Exception ex){ 211 | ex.printStackTrace(); 212 | } 213 | } 214 | 215 | @Override 216 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { 217 | 218 | } 219 | 220 | @Override 221 | public void popupMenuCanceled(PopupMenuEvent e) { 222 | 223 | } 224 | }); 225 | } 226 | 227 | public void setButtonReleaseCSV(){ 228 | ButtonReleaseCSV.addActionListener(new ActionListener() { 229 | @Override 230 | public void actionPerformed(ActionEvent e) { 231 | try { 232 | File file = new File("药局导出.csv"); 233 | if (file.exists()) { 234 | boolean succeedDeleted = file.delete(); 235 | } 236 | FileOutputStream fileOutputStream = new FileOutputStream(file); 237 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "GBK"); 238 | PreparedStatement preparedStatement=Keys.connection.prepareStatement( 239 | "SELECT * FROM pharmacy"); 240 | ResultSet resultSet=preparedStatement.executeQuery(); 241 | outputStreamWriter.append("处方品号,处方品名,处方品类型,制造商,单价,当前库存\n"); 242 | while (resultSet.next()){ 243 | outputStreamWriter.append(resultSet.getString("MID")).append(",") 244 | .append(resultSet.getString("Name")).append(",") 245 | .append(resultSet.getString("MedicineType")).append(",") 246 | .append(resultSet.getString("Manufacturer")).append(",") 247 | .append(resultSet.getString("UnitPrice")).append(",") 248 | .append(resultSet.getString("InStock")).append("\n"); 249 | } 250 | 251 | preparedStatement=Keys.connection.prepareStatement( 252 | "SELECT * FROM registered,prescription,pharmacy WHERE registered.RGID=prescription.RGID AND pharmacy.MID=prescription.MID"); 253 | resultSet=preparedStatement.executeQuery(); 254 | outputStreamWriter.append("\n\n病历单号,处方品号,处方品名,类型,制造商,单价,份数,总价\n"); 255 | while (resultSet.next()){ 256 | outputStreamWriter.append(resultSet.getString("RGID")).append(",") 257 | .append(resultSet.getString("MID")).append(",") 258 | .append(resultSet.getString("Name")).append(",") 259 | .append(resultSet.getString("MedicineType")).append(",") 260 | .append(resultSet.getString("Manufacturer")).append(",") 261 | .append(resultSet.getString("UnitPrice")).append(",") 262 | .append(resultSet.getString("Count")).append(",") 263 | .append(resultSet.getString("Price")).append("\n"); 264 | } 265 | 266 | outputStreamWriter.close(); 267 | fileOutputStream.close(); 268 | JOptionPane.showMessageDialog(frame,"导出成功!","成功", JOptionPane.PLAIN_MESSAGE); 269 | 270 | 271 | }catch (Exception e1){ 272 | JOptionPane.showMessageDialog(frame,"导出失败!","警告", JOptionPane.ERROR_MESSAGE); 273 | e1.printStackTrace(); 274 | } 275 | } 276 | }); 277 | } 278 | 279 | } 280 | -------------------------------------------------------------------------------- /src/models/commons-codec-1.14.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UtopiaXC/OutpatientManagementSystem/aebb3d37552d2d78abd6980ec923b5001d848472/src/models/commons-codec-1.14.jar --------------------------------------------------------------------------------