Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.51 KB | None | 0 0
  1. package window.views;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import javax.swing.GroupLayout;
  10. import javax.swing.GroupLayout.Alignment;
  11. import javax.swing.ImageIcon;
  12. import javax.swing.JButton;
  13. import javax.swing.JLabel;
  14. import javax.swing.JOptionPane;
  15.  
  16. import java.awt.Font;
  17. import java.awt.Image;
  18.  
  19. import javax.swing.JTextField;
  20. import javax.swing.JComboBox;
  21. import java.awt.event.ActionListener;
  22. import java.awt.event.ActionEvent;
  23. import java.awt.Color;
  24. import javax.swing.JScrollPane;
  25. import com.toedter.calendar.JDateChooser;
  26. import javax.swing.JTextArea;
  27. import javax.swing.DefaultComboBoxModel;
  28. import java.awt.event.KeyAdapter;
  29. import java.awt.event.KeyEvent;
  30. import java.beans.PropertyChangeListener;
  31. import java.io.FileReader;
  32. import java.io.FileWriter;
  33. import java.io.IOException;
  34. import java.io.PrintWriter;
  35. import java.text.SimpleDateFormat;
  36. import java.util.ArrayList;
  37. import java.util.Scanner;
  38. import java.beans.PropertyChangeEvent;
  39.  
  40. public class Receptionist_EditPatients extends JFrame {
  41.  
  42. private JPanel contentPane;
  43. private JTextField txtPatient_ID;
  44. private JTextField txtName;
  45. private JTextField txtAge;
  46. private JTextField txtContact;
  47. private JLabel lblPatient_IDValid;
  48. private JLabel lblNameValid;
  49. private JLabel lblDateOfBirthValid;
  50. private JLabel lblAgeValid;
  51. private JLabel lblContactValid;
  52. private JLabel lblAddressValid;
  53. private JTextArea taAddress;
  54. private JDateChooser dateChooser;
  55. private JLabel lblBackground;
  56. private JButton btnSearch;
  57.  
  58. ArrayList<Patient>patientList = new ArrayList<Patient>();
  59. private JComboBox cbGender;
  60.  
  61.  
  62. /**
  63. * Launch the application.
  64. */
  65. public static void main(String[] args) {
  66. EventQueue.invokeLater(new Runnable() {
  67. public void run() {
  68. try {
  69. Receptionist_EditPatients frame = new Receptionist_EditPatients();
  70. frame.setVisible(true);
  71. } catch (Exception e) {
  72. e.printStackTrace();
  73. }
  74. }
  75. });
  76. }
  77.  
  78. /**
  79. * Create the frame.
  80. */
  81. public Receptionist_EditPatients() {
  82. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  83. setBounds(100, 100, 922, 604);
  84. contentPane = new JPanel();
  85. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  86. setContentPane(contentPane);
  87.  
  88. //To read all the data out from the User text
  89. try {
  90. Scanner sc = new Scanner(new FileReader("patient.txt"));
  91. while(sc.hasNextLine()) {
  92. String[] patientDetails = sc.nextLine().split(",");
  93. if (patientDetails.length < 7) //ill-formed record - should not occur
  94. continue;
  95.  
  96. int patient_id = Integer.parseInt(patientDetails[0].trim()) ;
  97. int patient_age = Integer.parseInt(patientDetails[1].trim());
  98. int patient_contact = Integer.parseInt(patientDetails[2].trim());
  99. String patient_name = patientDetails[3].trim();
  100. String patient_address = patientDetails[4].trim();
  101. String patient_dob = patientDetails[5].trim() ;
  102. String patient_gender = patientDetails[6].trim();
  103.  
  104.  
  105. // (JTextField)dateChooser.getDateEditor().getUiComponent()).getText( patientDetails[5].trim())
  106.  
  107. Patient patient = new Patient(patient_id,patient_age,patient_contact,patient_name,patient_address,patient_dob,patient_gender);
  108. patientList.add(patient);
  109. //Any newly assigned customer numbers will be distinct from these
  110. }
  111. }catch(IOException ex) {
  112. System.err.println("Warning: could not read Patient file");
  113. }
  114. System.out.print(patientList);
  115.  
  116.  
  117. JLabel lblPleaseEditthePatient = new JLabel("Please Edit the Patient Details");
  118. lblPleaseEditthePatient.setBounds(62, 15, 283, 26);
  119. lblPleaseEditthePatient.setFont(new Font("Dialog", Font.PLAIN, 20));
  120.  
  121. JLabel label_1 = new JLabel("Contact");
  122. label_1.setFont(new Font("Tahoma", Font.PLAIN, 13));
  123. label_1.setBounds(485, 199, 59, 13);
  124.  
  125. JButton btnBack = new JButton("Back");
  126. btnBack.setBackground(new Color(75, 122, 242));
  127. btnBack.setForeground(new Color(255, 255, 255));
  128. Image imageback = new ImageIcon(this.getClass().getResource("/back.png")).getImage();
  129. btnBack.setIcon(new ImageIcon(imageback));
  130. btnBack.setBounds(323, 438, 102, 52);
  131. btnBack.addActionListener(new ActionListener() {
  132. public void actionPerformed(ActionEvent e) {
  133.  
  134. //Create a new JFrame
  135. Receptionist_ManagePatients receptionist_addmanageAppointments = new Receptionist_ManagePatients();
  136. receptionist_addmanageAppointments.setVisible(true);
  137.  
  138. //Close The Current JFrame
  139. Receptionist_EditPatients.this.dispose();
  140. Receptionist_EditPatients.this.setVisible(false);
  141.  
  142.  
  143. }
  144. });
  145.  
  146. JButton btnSubmit = new JButton("Submit");
  147. btnSubmit.setBackground(new Color(59, 226, 61));
  148. btnSubmit.setForeground(new Color(255, 255, 255));
  149. Image imagesubmit = new ImageIcon(this.getClass().getResource("/submit.png")).getImage();
  150. btnSubmit.setIcon(new ImageIcon(imagesubmit));
  151. btnSubmit.setBounds(500, 438, 114, 52);
  152. btnSubmit.addActionListener(new ActionListener() {
  153. public void actionPerformed(ActionEvent e) {
  154. validAddPatients();
  155. }
  156. });
  157.  
  158. JLabel label_2 = new JLabel("Date Of Birth");
  159. label_2.setBounds(62, 133, 124, 32);
  160. label_2.setFont(new Font("Tahoma", Font.PLAIN, 13));
  161.  
  162. JLabel label_3 = new JLabel("Address ");
  163. label_3.setBounds(62, 265, 50, 16);
  164. label_3.setFont(new Font("Tahoma", Font.PLAIN, 13));
  165.  
  166. JLabel label_4 = new JLabel("Name");
  167. label_4.setBounds(486, 78, 66, 16);
  168. label_4.setFont(new Font("Tahoma", Font.PLAIN, 13));
  169.  
  170. JLabel label_5 = new JLabel("Age");
  171. label_5.setBounds(486, 134, 33, 16);
  172. label_5.setFont(new Font("Tahoma", Font.PLAIN, 13));
  173.  
  174. JLabel label_6 = new JLabel("Gender");
  175. label_6.setFont(new Font("Tahoma", Font.PLAIN, 13));
  176. label_6.setBounds(62, 196, 114, 13);
  177.  
  178. JLabel label_7 = new JLabel("Patients_ID");
  179. label_7.setBounds(62, 85, 97, 16);
  180. label_7.setFont(new Font("Tahoma", Font.PLAIN, 13));
  181.  
  182. cbGender = new JComboBox();
  183. cbGender.setBounds(192, 193, 218, 20);
  184. cbGender.setModel(new DefaultComboBoxModel(new String[] {"Male", "Female"}));
  185.  
  186. txtPatient_ID = new JTextField();
  187. txtPatient_ID.setBounds(192, 74, 218, 27);
  188. txtPatient_ID.addKeyListener(new KeyAdapter() {
  189. @Override
  190. public void keyReleased(KeyEvent e) {
  191.  
  192. Object txt = e.getSource();
  193. if(txt==txtPatient_ID)
  194. {
  195. char ch=e.getKeyChar();
  196. String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
  197. String integer="1234567890";
  198. String character = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" ;
  199. //txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\\\s*]", " "));
  200.  
  201. if (txtPatient_ID.getText().trim().length() == 0 ) {
  202.  
  203. lblPatient_IDValid.setText("Cannot Be Empty.");
  204. txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[\\s+]", ""));
  205.  
  206. }
  207.  
  208.  
  209.  
  210. else if (txtPatient_ID.getText().trim().length() > 12 ) {
  211.  
  212. lblPatient_IDValid.setText(" Maximun is 12 Number.");
  213. txtPatient_ID.getText();
  214. txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\W]",""));
  215.  
  216. if(integer.indexOf(ch)>-1) {
  217. txtPatient_ID.setText(txtPatient_ID.getText().substring(0, txtPatient_ID.getText ().length() - 1));
  218.  
  219.  
  220.  
  221. }
  222.  
  223. }
  224.  
  225. else if (txtPatient_ID.getText().trim().length() <= 12 )
  226. {
  227.  
  228.  
  229. if (character.indexOf(ch)>-1)
  230. {
  231.  
  232. lblPatient_IDValid.setText(" Chracter is not allowed.");
  233. txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z]",""));
  234. }
  235.  
  236. else if (specialchar.indexOf(ch)>-1)
  237. {
  238.  
  239. lblPatient_IDValid.setText(" Special Chracter is not allowed.");
  240. txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("\\W",""));
  241. }
  242.  
  243. else {
  244. lblPatient_IDValid.setText("");
  245.  
  246. }
  247. }
  248. else
  249. {
  250.  
  251.  
  252. txtPatient_ID.setText(txtPatient_ID.getText().substring(0, txtPatient_ID.getText().length()-1));
  253. lblPatient_IDValid.setText("Maximun is 12 Digit Number.");
  254.  
  255. }
  256. }
  257.  
  258. }
  259. });
  260. txtPatient_ID.setColumns(10);
  261.  
  262. txtName = new JTextField();
  263. txtName.setEnabled(false);
  264. txtName.setBounds(571, 74, 210, 27);
  265. txtName.addKeyListener(new KeyAdapter() {
  266. @Override
  267. public void keyReleased(KeyEvent e) {
  268.  
  269. Object txt = e.getSource();
  270. if(txt==txtName)
  271. {
  272. char ch=e.getKeyChar();
  273. String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
  274. String integer="1234567890";
  275. String character = "QWERTYUIOPASDFGHJKLZXCVBNM" + "qwertyuiopasdfghjklzxcvbnm" ;
  276.  
  277.  
  278. if (txtName.getText().trim().length() == 0 ) {
  279.  
  280. lblNameValid.setText("Cannot Be Empty.");
  281. txtName.setText(txtName.getText().replaceAll("[\\s+]",""));
  282.  
  283. }
  284. else
  285. {
  286.  
  287. if (specialchar.indexOf(ch)>-1 )
  288. {
  289. lblNameValid.setText("Special Character is not allow.");
  290. txtName.setText(txtName.getText().replaceAll("[\\W]",""));
  291. }
  292.  
  293. else if(integer.indexOf(ch)>-1)
  294. {
  295. lblNameValid.setText("Integer is not allow.");
  296. txtName.setText(txtName.getText().replaceAll("[0-9]",""));
  297. }
  298.  
  299. else {
  300. lblNameValid.setText("");
  301.  
  302. }//end inner inner loop else
  303.  
  304. }//end inner loop else
  305. }//end else
  306.  
  307. }
  308. });
  309. txtName.setColumns(10);
  310.  
  311. txtAge = new JTextField();
  312. txtAge.setEnabled(false);
  313. txtAge.setBounds(570, 130, 211, 27);
  314. txtAge.addKeyListener(new KeyAdapter() {
  315. @Override
  316. public void keyReleased(KeyEvent e) {
  317.  
  318.  
  319. Object txt = e.getSource();
  320. if(txt==txtAge)
  321. {
  322. char ch=e.getKeyChar();
  323. String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
  324. String integer="1234567890";
  325. String character = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" ;
  326. //txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\\\s*]", " "));
  327.  
  328. if (txtAge.getText().trim().length() == 0 ) {
  329.  
  330. lblAgeValid.setText("Cannot Be Empty.");
  331. txtAge.setText(txtAge.getText().replaceAll("[\\s+]", ""));
  332.  
  333. }
  334.  
  335.  
  336.  
  337. else if (txtAge.getText().trim().length() > 3 ) {
  338.  
  339. lblAgeValid.setText(" Maximun is 3 Number.");
  340. txtAge.getText();
  341. txtAge.setText(txtAge.getText().replaceAll("[A-Za-z\\W]",""));
  342.  
  343. if(integer.indexOf(ch)>-1) {
  344. txtAge.setText(txtAge.getText().substring(0, txtAge.getText ().length() - 1));
  345.  
  346. }
  347.  
  348. }
  349.  
  350. else if (txtAge.getText().trim().length() <= 3 )
  351. {
  352.  
  353.  
  354. if (character.indexOf(ch)>-1)
  355. {
  356.  
  357. lblAgeValid.setText(" Chracter is not allowed.");
  358. txtAge.setText(txtAge.getText().replaceAll("[A-Za-z]",""));
  359. }
  360.  
  361. else if (specialchar.indexOf(ch)>-1)
  362. {
  363.  
  364. lblAgeValid.setText(" Special Character is not allowed.");
  365. txtAge.setText(txtAge.getText().replaceAll("\\W",""));
  366. }
  367.  
  368. else {
  369. lblAgeValid.setText("");
  370.  
  371. }
  372. }
  373. else
  374. {
  375.  
  376.  
  377. txtAge.setText(txtAge.getText().substring(0, txtAge.getText().length()-1));
  378. lblAgeValid.setText("Maximun is 3 Digit Number.");
  379.  
  380. }
  381. }
  382.  
  383. }
  384. });
  385. txtAge.setColumns(10);
  386.  
  387. lblDateOfBirthValid = new JLabel("");
  388. lblDateOfBirthValid.setBounds(192, 168, 303, 15);
  389. lblDateOfBirthValid.setForeground(Color.RED);
  390.  
  391. lblNameValid = new JLabel("");
  392. lblNameValid.setBounds(571, 104, 303, 15);
  393. lblNameValid.setForeground(Color.RED);
  394.  
  395. JScrollPane scrollPane = new JScrollPane();
  396. scrollPane.setBounds(194, 267, 591, 100);
  397.  
  398. lblAddressValid = new JLabel("");
  399. lblAddressValid.setBounds(194, 351, 301, 16);
  400. lblAddressValid.setForeground(Color.RED);
  401.  
  402. txtContact = new JTextField();
  403. txtContact.setEnabled(false);
  404. txtContact.setBounds(570, 192, 211, 27);
  405. txtContact.addKeyListener(new KeyAdapter() {
  406. @Override
  407. public void keyReleased(KeyEvent e) {
  408.  
  409. Object txt = e.getSource();
  410. if(txt==txtContact)
  411. {
  412. char ch=e.getKeyChar();
  413. String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
  414. String integer="1234567890";
  415. String character = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" ;
  416. //txtPatient_ID.setText(txtPatient_ID.getText().replaceAll("[A-Za-z\\\\s*]", " "));
  417.  
  418. if (txtContact.getText().trim().length() == 0 ) {
  419.  
  420. lblContactValid.setText("Cannot Be Empty.");
  421. txtContact.setText(txtContact.getText().replaceAll("[\\s+]", ""));
  422.  
  423. }
  424.  
  425.  
  426.  
  427. else if (txtContact.getText().trim().length() > 11 ) {
  428.  
  429. lblContactValid.setText(" Maximun is 11 Number.");
  430. txtContact.getText();
  431. txtContact.setText(txtContact.getText().replaceAll("[A-Za-z\\W]",""));
  432.  
  433. if(integer.indexOf(ch)>-1) {
  434. txtContact.setText(txtContact.getText().substring(0, txtContact.getText ().length() - 1));
  435.  
  436. }
  437.  
  438. }
  439.  
  440. else if (txtContact.getText().trim().length() <= 11 )
  441. {
  442.  
  443.  
  444. if (character.indexOf(ch)>-1)
  445. {
  446.  
  447. lblContactValid.setText(" Chracter is not allowed.");
  448. txtContact.setText(txtContact.getText().replaceAll("[A-Za-z]",""));
  449. }
  450.  
  451. else if (specialchar.indexOf(ch)>-1)
  452. {
  453.  
  454. lblContactValid.setText(" Special Character is not allowed.");
  455. txtContact.setText(txtContact.getText().replaceAll("\\W",""));
  456. }
  457.  
  458. else {
  459. lblContactValid.setText("");
  460.  
  461. }
  462. }
  463. else
  464. {
  465.  
  466.  
  467. txtContact.setText(txtContact.getText().substring(0, txtContact.getText().length()-1));
  468. lblContactValid.setText("Maximun is 12 Digit Number.");
  469.  
  470. }
  471. }
  472.  
  473. }
  474. });
  475. txtContact.setColumns(10);
  476.  
  477. lblContactValid = new JLabel("");
  478. lblContactValid.setBounds(573, 230, 301, 16);
  479. lblContactValid.setForeground(Color.RED);
  480.  
  481. lblAgeValid = new JLabel("");
  482. lblAgeValid.setBounds(569, 168, 268, 15);
  483. lblAgeValid.setForeground(Color.RED);
  484.  
  485.  
  486. dateChooser = new JDateChooser();
  487. dateChooser.getCalendarButton().setEnabled(false);
  488. dateChooser.setBounds(192, 133, 218, 24);
  489. dateChooser.setDateFormatString("ddMMMyyyy");
  490.  
  491. //disable Editable text field in dateChooser
  492. ((JTextField)dateChooser.getDateEditor().getUiComponent()).setEditable(false);
  493. dateChooser.addPropertyChangeListener(new PropertyChangeListener() {
  494. public void propertyChange(PropertyChangeEvent evt) {
  495.  
  496. //if date had been choose the it will empty
  497. if(((JTextField)dateChooser.getDateEditor().getUiComponent()).getText().isEmpty())
  498. {
  499.  
  500. } else {
  501. lblDateOfBirthValid.setText("");
  502.  
  503.  
  504. }
  505.  
  506. }
  507. });
  508. dateChooser.getCalendarButton().addActionListener(new ActionListener() {
  509. public void actionPerformed(ActionEvent e) {
  510.  
  511. //if date not been choose the it will get alert message
  512.  
  513. if(((JTextField)dateChooser.getDateEditor().getUiComponent()).getText().isEmpty())
  514. {
  515. lblDateOfBirthValid.setText("Date should be filled");
  516.  
  517.  
  518.  
  519. } else {
  520. lblDateOfBirthValid.setText("");
  521.  
  522.  
  523.  
  524. }
  525.  
  526. }
  527. });
  528.  
  529. lblPatient_IDValid = new JLabel("");
  530. lblPatient_IDValid.setBounds(192, 107, 234, 16);
  531. lblPatient_IDValid.setForeground(Color.RED);
  532.  
  533. taAddress = new JTextArea();
  534. taAddress.setEnabled(false);
  535. taAddress.setTabSize(0);
  536. taAddress.setLineWrap(true);
  537. taAddress.setWrapStyleWord(true);
  538. taAddress.addKeyListener(new KeyAdapter() {
  539. @Override
  540. public void keyReleased(KeyEvent e) {
  541.  
  542.  
  543. Object txt = e.getSource();
  544. if(txt==taAddress)
  545. {
  546. char ch=e.getKeyChar();
  547. String specialchar="!@#$%^&*()~?>'<:{}|+_/\".,;'][=-` \\";
  548. String integer="1234567890";
  549. String character = "QWERTYUIOPASDFGHJKLZXCVBNM" + "qwertyuiopasdfghjklzxcvbnm" ;
  550.  
  551.  
  552. if (taAddress.getText().trim().length() == 0 ) {
  553.  
  554. lblAddressValid.setText("Cannot Be Empty.");
  555. taAddress.setText(taAddress.getText().replaceAll("[\\s+]",""));
  556.  
  557. }
  558. else {
  559. lblAddressValid.setText("");
  560.  
  561. }//end inner inner loop else
  562.  
  563. }//end inner loop else
  564. }//end else
  565.  
  566.  
  567. });
  568. scrollPane.setViewportView(taAddress);
  569. contentPane.setLayout(null);
  570. contentPane.add(lblPleaseEditthePatient);
  571. contentPane.add(label_7);
  572. contentPane.add(txtPatient_ID);
  573. contentPane.add(lblPatient_IDValid);
  574. contentPane.add(label_4);
  575. contentPane.add(txtName);
  576. contentPane.add(lblNameValid);
  577. contentPane.add(label_2);
  578. contentPane.add(dateChooser);
  579. contentPane.add(lblDateOfBirthValid);
  580. contentPane.add(label_5);
  581. contentPane.add(txtAge);
  582. contentPane.add(lblAgeValid);
  583. contentPane.add(label_1);
  584. contentPane.add(txtContact);
  585. contentPane.add(lblContactValid);
  586. contentPane.add(label_3);
  587. contentPane.add(scrollPane);
  588. contentPane.add(lblAddressValid);
  589. contentPane.add(label_6);
  590. contentPane.add(btnBack);
  591. contentPane.add(cbGender);
  592. contentPane.add(btnSubmit);
  593. Image imagelogout = new ImageIcon(this.getClass().getResource("/backgroundImage.png")).getImage();
  594.  
  595. btnSearch = new JButton("Search");
  596. btnSearch.addActionListener(new ActionListener() {
  597. public void actionPerformed(ActionEvent arg0) {
  598.  
  599. int patient_ID = Integer.parseInt(txtPatient_ID.getText());
  600. for(int i = 0; i <patientList.size() ; i ++) {
  601.  
  602. if(patientList.get(i).getPatient_ID() == patient_ID) {
  603.  
  604.  
  605. /*(int patient_ID, String appointmen_ID, String doctor_ID, String dateAndTime, String hour,
  606. String minutes, String typeOfCustomer, String specialNotes) {
  607. */
  608.  
  609. txtAge.setText("" + patientList.get(i).getAge());
  610. txtContact.setText("" + patientList.get(i).getContact());
  611. txtName.setText(patientList.get(i).getName());
  612. taAddress.setText(patientList.get(i).getAddress());
  613. //dateChooser.setText(patientList.get(i).getAddress());
  614. cbGender.setSelectedItem((patientList.get(i).getGender()));
  615.  
  616. txtPatient_ID.setEnabled(false);
  617. txtAge.setEnabled(true);
  618. txtContact.setEnabled(true);
  619. txtName.setEnabled(true);
  620. taAddress.setEnabled(true);
  621. dateChooser.setEnabled(true);
  622. cbGender.setEnabled(true);
  623.  
  624.  
  625. System.out.println(patientList);
  626. }//end if
  627. }//end for
  628.  
  629. }
  630. });
  631. btnSearch.setBounds(384, 36, 97, 25);
  632. contentPane.add(btnSearch);
  633.  
  634. lblBackground = new JLabel("");
  635. lblBackground.setIcon(new ImageIcon(imagelogout));
  636. lblBackground.setBounds(0, 0, 910, 569);
  637. contentPane.add(lblBackground);
  638. }
  639.  
  640. public void validAddPatients() {
  641. if(txtPatient_ID.getText().trim().isEmpty()|| txtName.getText().trim().isEmpty() || txtAge.getText().trim().isEmpty() || txtContact.getText().trim().isEmpty()
  642. || taAddress.getText().trim().isEmpty() || dateChooser.getDate() == null ) {
  643.  
  644.  
  645.  
  646. if(txtPatient_ID.getText().trim().isEmpty() ) {
  647. lblPatient_IDValid.setText("Please Enter your Staff_ID.");
  648. }
  649.  
  650. if(txtName.getText().trim().isEmpty() ) {
  651. lblNameValid.setText("Please Enter your Name.");
  652. }
  653.  
  654.  
  655. if(txtAge.getText().trim().isEmpty() ) {
  656. lblAgeValid.setText("Please Enter your Age.");
  657. }
  658.  
  659. if(txtContact.getText().trim().isEmpty() ) {
  660. lblContactValid.setText("Please Enter your Contact.");
  661. }
  662.  
  663. if(taAddress.getText().trim().isEmpty() ) {
  664. lblAddressValid.setText("Please Enter your Address.");
  665. }
  666.  
  667. if(dateChooser.getDate() == null ) {
  668. lblDateOfBirthValid.setText("Please Choose you Date of Birth.");
  669. }
  670. }
  671.  
  672. else {
  673. //write file here
  674.  
  675. int patient_id = Integer.parseInt(txtPatient_ID.getText()) ;
  676. int patient_age = Integer.parseInt(txtAge.getText());
  677. int patient_contact = Integer.parseInt(txtContact.getText());
  678. String patient_name = txtName.getText();
  679. String patient_address = taAddress.getText();
  680.  
  681. //------------convertDate to the 11Mar2019 format--------------
  682. SimpleDateFormat dFormat = new SimpleDateFormat("ddMMMyyyy");
  683. String patient_dob = dFormat.format(dateChooser.getDate());
  684. //---------------------------------------------------------------
  685. String patient_gender = cbGender.getSelectedItem().toString();
  686.  
  687.  
  688. for(int i = 0; i <patientList.size() ; i ++) {
  689. if(patientList.get(i).getPatient_ID() == (patient_id)) {
  690.  
  691. patientList.get(i).setAge(patient_age);
  692. patientList.get(i).setContact(patient_contact);
  693. patientList.get(i).setName(patient_name);
  694. patientList.get(i).setAddress(patient_address);
  695. patientList.get(i).setDate_Of_Birth(patient_dob);
  696. patientList.get(i).setGender(patient_gender);
  697.  
  698.  
  699. }//end if
  700. }//end for
  701.  
  702.  
  703.  
  704.  
  705. try {
  706. PrintWriter pw = new PrintWriter(new FileWriter("patient.txt"));
  707. for (int i=0; i<patientList.size(); i++)
  708. //if (userList.get(i) != null)
  709. pw.println(patientList.get(i).toString());
  710. pw.close();
  711. System.err.println("Patient saved!");
  712. JOptionPane.showMessageDialog(null, "The Patient Details is Sucessfully Added.");
  713. }
  714.  
  715. catch (IOException ex) {
  716. System.err.println("Error! : Could not save patient.");
  717. }
  718.  
  719.  
  720.  
  721. txtPatient_ID.setText("");
  722. txtAge.setText("");
  723. txtContact.setText("");
  724. txtName.setText("");
  725. taAddress.setText("");
  726. dateChooser.setDate(null);
  727. taAddress.setText("");
  728.  
  729.  
  730. txtPatient_ID.setEnabled(true);
  731. txtAge.setEnabled(false);
  732. txtContact.setEnabled(false);
  733. txtName.setEnabled(false);
  734. taAddress.setEnabled(false);
  735. dateChooser.setEnabled(false);
  736.  
  737.  
  738. }
  739.  
  740. }
  741. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement