示例#1
0
        /// <summary>
        /// Synchronize time with echo
        /// </summary>
        public static void SynchronizeTime()
        {
            DateTime dtntp = new DateTime();

            try
            {
                dtntp = TimeHandler.GetNetworkTime();
                SYSTEMTIME st = new SYSTEMTIME();
                st.wYear   = Convert.ToInt16(dtntp.Year);
                st.wMonth  = Convert.ToInt16(dtntp.Month);
                st.wDay    = Convert.ToInt16(dtntp.Day);
                st.wHour   = Convert.ToInt16(dtntp.Hour);
                st.wMinute = Convert.ToInt16(dtntp.Minute);
                st.wSecond = Convert.ToInt16(dtntp.Second);

                SetSystemTime(ref st);
                System.Windows.Forms.MessageBox.Show("Time has been synchronized!",
                                                     "Success!",
                                                     System.Windows.Forms.MessageBoxButtons.OK,
                                                     System.Windows.Forms.MessageBoxIcon.Information);
            }
            catch (System.Net.Sockets.SocketException)
            {
                System.Windows.Forms.MessageBox.Show("Cannot connect to the local time server!",
                                                     "Failed",
                                                     System.Windows.Forms.MessageBoxButtons.OK,
                                                     System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
示例#2
0
        public void AddQueue(string patientID, int level)
        {
            if (level < 3)
            {
                try
                {
                    string key = TimeHandler.GetCurrentDateTime();
                    string sql = "INSERT INTO tblQueue(strPatientID, strQueueNumber, strQueueStatus, strPriority) " +
                                 "VALUES('" + patientID + "', '" + key + "', 'WAITING', ";

                    if (level == 2)
                    {
                        sql += "'HIGH');";
                    }
                    else
                    {
                        sql += "'NORMAL');";
                    }

                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    cmd.ExecuteNonQuery();
                }
                catch (MySqlException me)
                {
                    Integrity.GetExceptionDetails(me);
                }
                catch (Exception ex)
                {
                    Integrity.GetExceptionDetails(ex);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Synchronize time silently
        /// </summary>
        public static void SilentSynchronizeTime()
        {
            DateTime dtntp = new DateTime();

            try
            {
                dtntp = TimeHandler.GetNetworkTime();
                SYSTEMTIME st = new SYSTEMTIME();
                st.wYear   = Convert.ToInt16(dtntp.Year);
                st.wMonth  = Convert.ToInt16(dtntp.Month);
                st.wDay    = Convert.ToInt16(dtntp.Day);
                st.wHour   = Convert.ToInt16(dtntp.Hour);
                st.wMinute = Convert.ToInt16(dtntp.Minute);
                st.wSecond = Convert.ToInt16(dtntp.Second);

                SetSystemTime(ref st);
            }
            catch (System.Net.Sockets.SocketException)
            {
                // Do nothing
            }
        }
示例#4
0
        public CtrlMedicalProcess(Form handle, MySqlConnection conn, string userID, string patientID)
        {
            InitializeComponent();

            this.handle    = handle;
            this.conn      = conn;
            this.userID    = userID;
            this.patientID = patientID;

            currentKey                    = TimeHandler.GetCurrentDateTime();
            this.lblConsID.Text           = currentKey + "-CONS";
            this.lblTADID.Text            = currentKey + "-TAD";
            this.lblRefCode.Text          = currentKey + "-REF";
            this.lblPrescriptionCode.Text = currentKey + "-PRESC";

            pnlConsultation.Visible = true;
            pnlDiagnosis.Visible    = false;
            pnlPrescription.Visible = false;
            pnlReferral.Visible     = false;

            this.Dock = DockStyle.Fill;

            this.pnlPrescPrint.Location = new Point(-1000, -1000);
        }
示例#5
0
        private void videoTimer_Tick(object sender, EventArgs e)
        {
            BarcodeReader bReader = new BarcodeReader();
            Result        result  = null;

            try
            {
                if (pboReader.Image == null)
                {
                }
                else
                {
                    result = bReader.Decode(new Bitmap(pboReader.Image));
                    string decoded = result.ToString().Trim();

                    if (decoded == string.Empty)
                    {
                        MessageBox.Show("Empty String");
                    }
                    else
                    {
                        videoTimer.Stop();
                        videoTimer.Enabled = false;

                        // proceed to log in
                        try
                        {
                            string sql = "SELECT * " +
                                         "FROM tblPatient " +
                                         "WHERE strPatientID = '" + decoded + "' AND " +
                                         "boolIsActive;";
                            int resultCounter = 0;
                            MessageBox.Show(sql);
                            MySqlCommand    cmd    = new MySqlCommand(sql, conn);
                            MySqlDataReader reader = cmd.ExecuteReader();

                            while (reader.Read())
                            {
                                resultCounter++;
                            }

                            reader.Close();

                            if (resultCounter >= 1)
                            {
                                string logID = "";
                                lblPatID.Text = decoded;

                                resultCounter = 0;
                                sql           = "SELECT a.strLogID " +
                                                "FROM tblPatientLogs a, tblPatientLogDetails b " +
                                                "WHERE a.strPatientID = '" + decoded + "' AND a.strLogID = b.strLogID AND " +
                                                "b.dtmDateTimeOut IS NULL ORDER BY b.dtmDateTimeLog ASC LIMIT 1;";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Prepare();
                                try
                                {
                                    reader = cmd.ExecuteReader();
                                }
                                catch (MySqlException me)
                                {
                                    Integrity.GetExceptionDetails(me);
                                }

                                while (reader.Read())
                                {
                                    logID = reader.GetString("strLogID");
                                    resultCounter++;
                                }

                                reader.Close();

                                if (resultCounter == 1)
                                {
                                    sql = "UPDATE tblPatientLogDetails " +
                                          "SET dtmDateTimeOut = NOW(), " +
                                          "strLogType = 'OUT' " +
                                          "WHERE strLogID = '" + logID + "';";
                                    cmd = new MySqlCommand(sql, conn);
                                    cmd.ExecuteNonQuery();

                                    sql = "SELECT strQueueNumber " +
                                          "FROM tblQueue " +
                                          "WHERE strPatientID = '" + decoded + "' AND " +
                                          "strQueueStatus = 'WAITING';";
                                    cmd    = new MySqlCommand(sql, conn);
                                    reader = cmd.ExecuteReader();
                                    int    resCount    = 0;
                                    string queueNumber = "";

                                    while (reader.Read())
                                    {
                                        queueNumber = reader.GetString("strQueueNumber");
                                        resCount++;
                                    }

                                    reader.Close();

                                    if (resCount > 0)
                                    {
                                        sql = "UPDATE tblQueue " +
                                              "SET strQueueStatus = 'CANCELLED' " +
                                              "WHERE strQueueNumber = '" + queueNumber + "';";
                                        cmd = new MySqlCommand(sql, conn);
                                        cmd.ExecuteNonQuery();
                                    }

                                    MessageBox.Show("Successfully logged out!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                                    videoTimer.Start();
                                    videoTimer.Enabled = true;
                                }
                                else
                                {
                                    bool         valid    = true;
                                    int          cboIndex = 0;
                                    string       logType  = "";
                                    DialogResult dr       = ExternalForm.InputComboBox(ref cboIndex, ref logType);

                                    if (dr == DialogResult.OK)
                                    {
                                        if (cboIndex >= 5)
                                        {
                                            MessageBox.Show("Please select a valid log type!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                            valid = false;

                                            videoTimer.Start();
                                            videoTimer.Enabled = true;
                                        }
                                        else
                                        {
                                            switch (cboIndex)
                                            {
                                            case 1:
                                                logType = "APPT";
                                                break;

                                            case 2:
                                                logType = "WALK";
                                                break;

                                            case 3:
                                                logType = "EMER";
                                                break;

                                            case 4:
                                                logType = "OTHER";
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        valid = false;
                                    }

                                    if (valid)
                                    {
                                        string dateToday = TimeHandler.GetCurrentDateTime() + "-LOGS";
                                        sql = "INSERT INTO tblPatientLogs(strLogID, strPatientID, strStaffID) " +
                                              "VALUES('" + dateToday + "', '" + decoded + "', '" + userID + "');";
                                        cmd = new MySqlCommand(sql, conn);
                                        cmd.ExecuteNonQuery();

                                        sql = "INSERT INTO tblPatientLogDetails(strLogID, dtmDateTimeLog, strLogPurposeCode, strLogType) " +
                                              "VALUES('" + dateToday + "', NOW(), '" + logType + "', 'IN');";
                                        cmd = new MySqlCommand(sql, conn);
                                        cmd.ExecuteNonQuery();

                                        switch (cboIndex)
                                        {
                                        case 1:
                                            formQueue.AddQueue(patientList[dgvSearch.CurrentRow.Index][0], 1);
                                            break;

                                        case 2:
                                            formQueue.AddQueue(patientList[dgvSearch.CurrentRow.Index][0], 1);
                                            break;
                                        }

                                        MessageBox.Show("Successfully logged in!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                                        lblPatID.Text = "Scanning";
                                        videoTimer.Start();
                                        videoTimer.Enabled = true;

                                        eDesktopAlertColor color    = eDesktopAlertColor.Green;
                                        eAlertPosition     position = eAlertPosition.BottomRight;
                                        string             report   = "Patient # <b>" + decoded + "</b><br />" +
                                                                      "has logged!";
                                        DesktopAlert.Show(report,
                                                          "\uf005",
                                                          eSymbolSet.Awesome,
                                                          Color.Blue,
                                                          color,
                                                          position,
                                                          6,
                                                          _RunningAlertId,
                                                          AlertClicked);
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("QR Code not recognized!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                videoTimer.Start();
                                videoTimer.Enabled = true;
                            }
                        }
                        catch (MySqlException me)
                        {
                            MessageBox.Show("Exception Caught!\n" + me.Message);
                            videoTimer.Start();
                            videoTimer.Enabled = true;
                        }
                    }
                }
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                //vdeoTimer.Stop();
            }
        }
示例#6
0
        } // Class Constructor

        private void FormLogIn_Load(object sender, EventArgs e)
        {
            TimeHandler.SilentSynchronizeTime();
        } // Action[Load]: FormLogIn
示例#7
0
        private void btnSetAppointment_Click(object sender, EventArgs e)
        {
            try
            {
                string report  = "";
                bool   isValid = true;

                if (dgvPatient.SelectedRows.Count == 0)
                {
                    report  = "Please select a patient!";
                    isValid = false;
                }
                else if (dgvDoctor.SelectedRows.Count == 0)
                {
                    report  = "Please select a doctor!";
                    isValid = false;
                }
                else if (datSchedule.Value.DayOfWeek == DayOfWeek.Sunday)
                {
                    report  = "Please select an appointment date other than Sundays!";
                    isValid = false;
                }
                else if (tmAppointment.Value.Hour < 8 || tmAppointment.Value.Hour > 17)
                {
                    report  = "Please select an appropriate appointment time!\nFrom 8:00 AM to 4:00 PM";
                    isValid = false;
                }

                if (!isValid)
                {
                    MessageBox.Show(report, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    /* Check if the user already been appointed at the same day */
                    int    resultCounter = 0;
                    bool   valid         = true;
                    string sql           = "SELECT b.dtmDateTimeStart " +
                                           "FROM tblAppointment a, tblAppointmentDetails b " +
                                           "WHERE a.strStaffID = @staffID AND " +
                                           "a.strPatientID = @patientID AND " +
                                           "a.strAppointmentCode = b.strAppointmentCode AND " +
                                           "DATE(b.dtmDateTimeStart) = @dateTimeAppoint AND " +
                                           "b.strAppointmentStatus = 'APPR';";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@staffID", doctorList[0]);
                    cmd.Parameters.AddWithValue("@patientID", patientList[0]);
                    cmd.Parameters.AddWithValue("@dateTimeAppoint", datSchedule.Value.ToString("yyyy-MM-dd"));
                    cmd.Prepare();
                    MySqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        resultCounter++;
                    }

                    reader.Close();

                    if (resultCounter >= 1)
                    {
                        MessageBox.Show("You already have appointment set on this date!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        valid = false;
                    }
                    else
                    {
                        resultCounter = 0;
                        int numberOfCurrentAppt = 0;
                        sql = "SELECT COUNT(*) AS CURRENT_APPTS " +
                              "FROM tblAppointment a, tblAppointmentDetails b " +
                              "WHERE a.strStaffID = @staffID AND " +
                              "a.strPatientID = @patientID AND " +
                              "a.strAppointmentCode = b.strAppointmentCode AND " +
                              "DATE(b.dtmDateTimeStart) = @dateAppointment;";
                        cmd = new MySqlCommand(sql, conn);
                        cmd.Parameters.AddWithValue("@staffID", doctorList[0][dgvDoctor.CurrentRow.Index]);
                        cmd.Parameters.AddWithValue("@patientID", patientList[0][dgvPatient.CurrentRow.Index]);
                        cmd.Parameters.AddWithValue("@dateAppointment", datSchedule.Value.ToString("yyyy-MM-dd"));
                        cmd.Prepare();
                        reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            numberOfCurrentAppt = reader.GetInt16("CURRENT_APPTS");
                        }

                        reader.Close();

                        if (numberOfCurrentAppt >= 5)
                        {
                            MessageBox.Show("This doctor has already reached the maximum number of appointments per day!",
                                            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            valid = false;
                        }
                        else
                        {
                            sql = "SELECT b.dtmDateTimeStart " +
                                  "FROM tblAppointment a, tblAppointmentDetails b " +
                                  "WHERE a.strStaffID = @staffID AND " +
                                  "a.strAppointmentCode = b.strAppointmentCode AND " +
                                  "DATE(b.dtmDateTimeStart) = @dateAppointment;";
                            cmd = new MySqlCommand(sql, conn);
                            cmd.Parameters.AddWithValue("@staffID", doctorList[0][dgvDoctor.CurrentRow.Index]);
                            cmd.Parameters.AddWithValue("@dateAppointment", datSchedule.Value.ToString("yyyy-MM-dd"));
                            cmd.Prepare();
                            reader = cmd.ExecuteReader();

                            while (reader.Read())
                            {
                                DateTime startTime = reader.GetDateTime("dtmDateTimeStart");
                                tmAppointment.Value = new DateTime(datSchedule.Value.Year, datSchedule.Value.Month,
                                                                   datSchedule.Value.Day, DateTime.Now.Hour, DateTime.Now.Minute,
                                                                   DateTime.Now.Second);
                                TimeSpan span = startTime.Subtract(tmAppointment.Value);

                                /*
                                 * MessageBox.Show("Span is:" + Math.Abs(span.Hours) + "\nStartTime is: " + startTime.Hour + "\n" +
                                 *              "tmAppointment is: " + tmAppointment.Value.Hour);
                                 */

                                if (Math.Abs(span.Hours) < 2)
                                {
                                    MessageBox.Show("Time entered should be 2 hours after / before the previous appointment!",
                                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    valid = false;
                                    break;
                                }
                            }

                            reader.Close();

                            if (valid)
                            {
                                string   currentCode = TimeHandler.GetCurrentDateTime() + "-APPT";
                                DateTime apptDate    = new DateTime(datSchedule.Value.Year, datSchedule.Value.Month,
                                                                    datSchedule.Value.Day, tmAppointment.Value.Hour,
                                                                    tmAppointment.Value.Minute,
                                                                    tmAppointment.Value.AddSeconds(-tmAppointment.Value.Second).Second);
                                sql = "INSERT INTO tblAppointment(strAppointmentCode, strStaffID, strPatientID) " +
                                      "VALUES (@apptCode, @staffID, @patID);";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@apptCode", currentCode);
                                cmd.Parameters.AddWithValue("@staffID", doctorList[0][dgvDoctor.CurrentRow.Index]);
                                cmd.Parameters.AddWithValue("@patID", patientList[0][dgvPatient.CurrentRow.Index]);
                                cmd.Prepare();
                                cmd.ExecuteNonQuery();

                                sql = "INSERT INTO tblAppointmentDetails(strAppointmentCode, " +
                                      "dtmDateTimeStart, strAppointmentStatus) " +
                                      "VALUES (@apptCode, @dtmApptDate, @statusCode);";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@apptCode", currentCode);
                                cmd.Parameters.AddWithValue("@dtmApptDate", apptDate);
                                cmd.Parameters.AddWithValue("@statusCode", "APPR");
                                cmd.Prepare();
                                cmd.ExecuteNonQuery();

                                MessageBox.Show("Patient has been successfully appointed to the doctor!", "Success",
                                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            }
                        }
                    }
                }
            }
            catch (MySqlException me)
            {
                Integrity.GetExceptionDetails(me);
            }
            catch (Exception ex)
            {
                Integrity.GetExceptionDetails(ex);
            }
        }
示例#8
0
        } // Action[Click]: btnClear

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Are you sure you want to register this patient?",
                                              "Confirm",
                                              MessageBoxButtons.YesNo,
                                              MessageBoxIcon.Question);

            if (dr.Equals(DialogResult.Yes))
            {
                if (this.CheckEntries())
                {
                    try
                    {
                        string sql = "SELECT * " +
                                     "FROM tblPatient " +
                                     "WHERE boolIsActive AND ((strIDNumber = @strIDNumber) OR " +
                                     "(strPatientLastName = @strPatLastName AND " +
                                     "strPatientFirstName = @strPatFirstName AND " +
                                     "strPatientMiddleName = @strPatMiddleName));";
                        MySqlCommand cmd = new MySqlCommand(sql, conn);
                        cmd.Parameters.AddWithValue("@strIDNumber", textPatID.Text.Trim());
                        cmd.Parameters.AddWithValue("@strPatLastName", textLastName.Text.Trim());
                        cmd.Parameters.AddWithValue("@strPatFirstName", textFirstName.Text.Trim());
                        cmd.Parameters.AddWithValue("@strPatMiddleName", textMiddleName.Text.Trim());
                        MySqlDataReader readerCheck = cmd.ExecuteReader();
                        int             readCount   = 0;

                        while (readerCheck.Read())
                        {
                            readCount++;
                        }

                        readerCheck.Close();

                        if (readCount >= 1)
                        {
                            Integrity.ShowDuplicateDialog();
                        }
                        else
                        {
                            sql = "INSERT INTO tblGuardian(strGuardianID, strLastName, strFirstName, strMiddleName, " +
                                  "strContact, strRelation) " +
                                  "VALUES(@strGuardID, @strLastName, @strFirstName, " +
                                  "@strMiddleName, @strContactNumber, @strRelation);";
                            cmd = new MySqlCommand(sql, conn);

                            if (isPrime)
                            {
                                cmd.Parameters.AddWithValue("@strGuardID", textPatID.Text.Trim() + "-GUARD");
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@strGuardID", lblPatIDVal.Text.Trim() + "-GUARD");
                            }

                            cmd.Parameters.AddWithValue("@strLastName", textGuardLastName.Text.Trim());
                            cmd.Parameters.AddWithValue("@strFirstName", textGuardFirstName.Text.Trim());
                            cmd.Parameters.AddWithValue("@strMiddleName", textGuardMiddleName.Text.Trim());
                            cmd.Parameters.AddWithValue("@strContactNumber", "+639" + textGuardContactNumber.Text.Trim());
                            cmd.Parameters.AddWithValue("@strRelation", textRelation.Text.Trim());
                            cmd.Prepare();
                            cmd.ExecuteNonQuery();

                            /* Insert values to tblPatient */
                            sql = "INSERT INTO tblPatient(strPatientID, strIDNumber, strPatientLastName, strPatientFirstName, " +
                                  "strPatientMiddleName, strPatientContactNumber, dtmDateOfBirth, strGender, " +
                                  "strGuardianID, boolIsActive) " +
                                  "VALUES(@strPatientID, @strIDNumber, @strLastName, " +
                                  "@strFirstName, @strMiddleName, @strPatientContactNumber, " +
                                  "@dtmDateOfBirth, @strGender, " +
                                  "@strGuardianID, true);";
                            cmd = new MySqlCommand(sql, conn);

                            if (isPrime)
                            {
                                cmd.Parameters.AddWithValue("@strPatientID", textPatID.Text.Trim());
                                cmd.Parameters.AddWithValue("@strGuardianID", textPatID.Text.Trim() + "-GUARD");
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@strPatientID", lblPatIDVal.Text.Trim());
                                cmd.Parameters.AddWithValue("@strGuardianID", lblPatIDVal.Text.Trim() + "-GUARD");
                            }

                            cmd.Parameters.AddWithValue("@strIDNumber", textPatNumber.Text.Trim());
                            cmd.Parameters.AddWithValue("@strLastName", textLastName.Text.Trim());
                            cmd.Parameters.AddWithValue("@strFirstName", textFirstName.Text.Trim());
                            cmd.Parameters.AddWithValue("@strMiddleName", textMiddleName.Text.Trim());
                            cmd.Parameters.AddWithValue("@strPatientContactNumber", "+639" + textContactNumber.Text.Trim());
                            cmd.Parameters.AddWithValue("@dtmDateOfBirth", dtpBirthday.Value.ToString("yyyy-MM-dd"));
                            cmd.Parameters.AddWithValue("@strGender", genderCode);
                            cmd.Prepare();
                            cmd.ExecuteNonQuery();

                            sql = "INSERT INTO tblHomeAddress(strPatientID, strHomeAddress, strRegion, strProvince, strCity) " +
                                  "VALUES(@strPatientID, @strHomeAddress, @regionCode, @provCode, @cityCode);";
                            cmd = new MySqlCommand(sql, conn);

                            if (isPrime)
                            {
                                cmd.Parameters.AddWithValue("@strPatientID", textPatID.Text.Trim());
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@strPatientID", lblPatIDVal.Text.Trim());
                            }

                            cmd.Parameters.AddWithValue("@strHomeAddress", textHomeAddress.Text.Trim());
                            cmd.Parameters.AddWithValue("@regionCode", cboRegion.GetItemText(cboRegion.SelectedItem).Trim());
                            cmd.Parameters.AddWithValue("@provCode", textProvince.Text.Trim());
                            cmd.Parameters.AddWithValue("@cityCode", textCity.Text.Trim());
                            cmd.Prepare();
                            cmd.ExecuteNonQuery();

                            if (isPrime)
                            {
                                sql = "INSERT INTO tblRegistration " +
                                      "VALUES('" + TimeHandler.GetCurrentDateTime() + "-REG" + "', '" + userID + "', " +
                                      "'" + textPatID.Text.Trim() + "', NOW());";
                            }
                            else
                            {
                                sql = "INSERT INTO tblRegistration " +
                                      "VALUES('" + TimeHandler.GetCurrentDateTime() + "-REG" + "', '" + userID + "', " +
                                      "'" + lblPatIDVal.Text.Trim() + "', NOW());";
                            }

                            try
                            {
                                cmd = new MySqlCommand(sql, conn);
                                cmd.ExecuteNonQuery();
                            }
                            catch (MySqlException me)
                            {
                                Integrity.GetExceptionDetails(me);
                            }
                            catch (Exception ex)
                            {
                                Integrity.GetExceptionDetails(ex);
                            }


                            string collegeCode = "";
                            string courseCode  = "";
                            string profDCode   = "";
                            string deptCode    = "";
                            string typeCode    = "";
                            string typeDesc    = "";

                            if (cboPatType.SelectedIndex == 0)
                            {
                                /* Get College Code */
                                sql = "SELECT strCollegeCode " +
                                      "FROM tblCollege " +
                                      "WHERE strCollegeDesc = @strCollegeDescription " +
                                      "LIMIT 1;";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@strCollegeDescription", cboCollege.GetItemText(cboCollege.SelectedItem));
                                cmd.Prepare();
                                MySqlDataReader reader = cmd.ExecuteReader();

                                while (reader.Read())
                                {
                                    collegeCode = reader.GetString("strCollegeCode");
                                }

                                reader.Close();

                                /* Get Course Code */
                                sql = "SELECT strCourseCode " +
                                      "FROM tblCourse " +
                                      "WHERE strCourseDesc = @strCourseDescription " +
                                      "LIMIT 1;";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@strCourseDescription", cboCourse.GetItemText(cboCourse.SelectedItem));
                                cmd.Prepare();
                                reader = cmd.ExecuteReader();

                                while (reader.Read())
                                {
                                    courseCode = reader.GetString("strCourseCode");
                                }

                                reader.Close();

                                profDCode = "NA";
                                deptCode  = "NA";
                                typeCode  = "STUD";
                                typeDesc  = "Student";
                            }
                            else if (cboPatType.SelectedIndex == 1)
                            {
                                /* Get College Code */
                                sql = "SELECT strCollegeCode " +
                                      "FROM tblCollege " +
                                      "WHERE strCollegeDesc = @strCollegeDescription " +
                                      "LIMIT 1;";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@strCollegeDescription", cboCollege.GetItemText(cboCollege.SelectedItem));
                                cmd.Prepare();
                                MySqlDataReader reader = cmd.ExecuteReader();

                                while (reader.Read())
                                {
                                    collegeCode = reader.GetString("strCollegeCode");
                                }

                                reader.Close();

                                /* Get Course Code */
                                sql = "SELECT strDeptCode " +
                                      "FROM tblDepartment " +
                                      "WHERE strDeptDesc = @strDeptDescription " +
                                      "LIMIT 1;";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@strDeptDescription", cboCourse.GetItemText(cboCourse.SelectedItem));
                                cmd.Prepare();
                                reader = cmd.ExecuteReader();

                                while (reader.Read())
                                {
                                    profDCode = reader.GetString("strDeptCode");
                                }

                                reader.Close();

                                courseCode = "NA";
                                deptCode   = "NA";
                                typeCode   = "PROF";
                                typeDesc   = "Professor";
                            }
                            else
                            {
                                sql = "SELECT strStaffDeptCode " +
                                      "FROM tblStaffDepartment " +
                                      "WHERE strDesc = @desc " +
                                      "LIMIT 1;";
                                cmd = new MySqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@desc", cboCourse.GetItemText(cboCourse.SelectedItem));
                                cmd.Prepare();
                                MySqlDataReader reader = cmd.ExecuteReader();

                                while (reader.Read())
                                {
                                    deptCode = reader.GetString("strStaffDeptCode");
                                }

                                reader.Close();

                                courseCode  = "NA";
                                collegeCode = "NA";
                                profDCode   = "NA";
                                typeCode    = "STAFF";
                                typeDesc    = "Staff";
                            }

                            sql = "INSERT INTO tblPatientType(strPatientID, strTypeCode, strTypeDesc, " +
                                  "strCollegeCode, strCourseCode, strDeptCode, " +
                                  "strStaffDeptCode) " +
                                  "VALUES(@patientID, @typeCode, @typeDesc, " +
                                  "@college, @course, @profD, " +
                                  "@staffD);";
                            cmd = new MySqlCommand(sql, conn);
                            if (isPrime)
                            {
                                cmd.Parameters.AddWithValue("@patientID", textPatID.Text.Trim());
                            }
                            else
                            {
                                cmd.Parameters.AddWithValue("@patientID", lblPatIDVal.Text.Trim());
                            }
                            cmd.Parameters.AddWithValue("@typeCode", typeCode);
                            cmd.Parameters.AddWithValue("@typeDesc", typeDesc);
                            cmd.Parameters.AddWithValue("@college", collegeCode);
                            cmd.Parameters.AddWithValue("@course", courseCode);
                            cmd.Parameters.AddWithValue("@profD", profDCode);
                            cmd.Parameters.AddWithValue("@staffD", deptCode);
                            cmd.Prepare();
                            cmd.ExecuteNonQuery();

                            PrintDocument printDocument = new PrintDocument();
                            printDocument.PrintPage   += new PrintPageEventHandler(printDocument1_PrintPage);
                            printDocument.DocumentName = "Patient ID";

                            printDialog.Document = printDocument;
                            if (printDialog.ShowDialog() == DialogResult.OK)
                            {
                                printDocument.Print();
                            }

                            MessageBox.Show("Patient Successfully Registered!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            btnClear_Click(null, null);
                            UpdatePatientID();
                        }
                    }
                    catch (MySqlException me)
                    {
                        Integrity.GetExceptionDetails(me);
                    }
                    catch (Exception ex)
                    {
                        Integrity.GetExceptionDetails(ex);
                    }
                }
            }
        } // Action[Click]: btnSubmit