private void btnPUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPUpdateActionPerformed
        // TODO add your handling code here:
        lblPHint.setVisible(false);
        int pid = Integer.parseInt(lblPID.getText());
        if (pid<=0)
            return;
        if(tbxPDoctorID.getText().equals(""))
        {
            tbxError.setText("Permission denied.");
            return ;
        }
        if((!tbxPDoctorID.getText().equals(ThisUser.UserID))&&(ThisUser.UserType!=User.U_Types.ADMIN))
        {
            tbxError.setText("Not your patient. Permission denined");
            return ;
        }
        Pattern namepattern = Pattern.compile("^[A-Z][a-zA-Z ,.'-]*$");
        String fn = tbxPFirstName.getText().trim();
        if (!namepattern.matcher(fn).matches())
        {
            tbxError.setText("Invalid first name.");
            lblPHint.setText("Unacceptable first name.");
            lblPHint.setVisible(true);
            return ;
        }
        fn = fn.replace("'", "\\'");
        String ln = tbxPLastName.getText().trim();
        if (!namepattern.matcher(ln).matches())
        {
            tbxError.setText("Invalid last name.");
            lblPHint.setText("Unacceptable last name.");
            lblPHint.setVisible(true);
            return ;
        }
        ln = ln.replace("'", "\\'"); 
        Pattern pattern = Pattern.compile("[0-9]{4}/[0-9]{2}/[0-9]{2}");
        Pattern pattern2 = Pattern.compile("[0-9]{2}/[0-9]{2}/[0-9]{4}");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        Date bd = new Date();
        String tbd = tbxPBirthDate.getText();
        if (pattern.matcher(tbd).matches())
        {
            //bd = sdf.parse(tbxBirthDate.getText());
            sdf = new SimpleDateFormat("yyyy/MM/dd");
        }
        else if (pattern2.matcher(tbd).matches())
        {
            sdf = new SimpleDateFormat("MM/dd/yyyy");
        }
        else
        {
            tbxError.setText("Invalid birthdate.");
            lblPHint.setText("Wrong Format. Example: "+"2000/01/01");
            lblPHint.setVisible(true);
            return ;
        }
        try
        {
            bd = sdf.parse(tbxPBirthDate.getText());
        }
        catch(Exception e)
        {
            tbxError.setText("Invalid birthdate.");
            lblPHint.setText("Wrong Format. Example: "+"2000/01/01");
            lblPHint.setVisible(true);
            return ;
        }
        String Address = tbxPAddress1.getText().replace("'", "\\'").replace(";", "");
        Address +=";";
        Address += tbxPAddress2.getText().replace("'", "\\'").replace(";", "");
        if (Address.equals(";"))
        {
            tbxError.setText("Empty address.");
            return ;
        }
        pattern = Pattern.compile("[0-9]{5}");
        
        String zc = tbxPZipcode.getText().trim().replace("'", "");
        if (!pattern.matcher(zc).matches())
        {
            tbxError.setText("Invalid zipcode.");
            lblPHint.setText("Wrong Format. Example: "+"25858");
            lblPHint.setVisible(true);
            return ;
        }
        
        String ph = tbxPPhone.getText().trim().replace("'", "");
        pattern = Pattern.compile("[0-9]{3}\\-?[0-9]{3}\\-?[0-9]{4}");
        if (!pattern.matcher(ph).matches())
        {
            tbxError.setText("Invalid phone number.");
            lblPHint.setText("Wrong Format. Example: "+"919-360-5662");
            lblPHint.setVisible(true);
            return ;
        }
        ph = ph.replace("-", "");
        ph = ph.substring(0,3)+"-"+ph.substring(3,6)+"-"+ph.substring(6);
        Patient_Controller PC = new Patient_Controller("localhost", DBName, DBAccount, DBPwd);
        
        boolean flag = PC.UpdatePatient(pid, fn, ln, (cbxPGender.getSelectedIndex()==0), bd, Address, zc, ph, tbxPDoctorID.getText());
        if(!flag)
        {
            tbxError.setText(PC.err);
            return;
        }
        
        String key = tbxPSearch.getText().trim().replace("'", "");
        //int Method  = cbxPSearchType.getSelectedIndex();
        int Method = 0;
        //int tt = lslPatients.getSelectedIndex();
        int tt = pid;
        SearchPatients(Method, key);
        tbxError.setText("Updated Patient #" + pid +" successfully.");
        try
        {
            lslPatients.setSelectedIndex(tt);
            ShowPInfo((Patient)ReturnedPatients.get(tt));
        }
        catch(Exception e){}
    }