private void btnAdd_Click(object sender, EventArgs e) { if (intType <= 1) { if (chkCourse.Checked) { strCollege = (chkCourse.Checked == false ? "" : (" AND strPatiCode IN (SELECT strStuiPatiCode FROM tblstudentinfo WHERE strStuiCourCode LIKE '" + listCourse[cbCourse.SelectedIndex].ToString() + "%') ")); } strCollege += (string.IsNullOrEmpty(txtYear.Text) ? "" : (" AND strPatiCode IN(SELECT strStuiPatiCode FROM tblstudentinfo WHERE strStuiYear LIKE '" + txtYear.Text + "%') ")); strCollege += (string.IsNullOrEmpty(txtSection.Text) ? "" : (" AND strPatiCode IN(SELECT strStuiPatiCode FROM tblstudentinfo WHERE strStuiSection LIKE '" + txtSection.Text + "%') ")); strDept = ""; } else { strCollege = ""; if (chkDept.Checked) { if (intType == 2) { strDept = (chkDept.Checked == false ? "" : (" AND strPatiCode IN (SELECT strFacIPatiCode FROM tblfacultyinfo WHERE strFacICollCode LIKE '" + listDept[cbDept.SelectedIndex].ToString() + "%') ")); } else { strDept = (chkDept.Checked == false ? "" : (" AND strPatiCode IN (SELECT strAdmIPatiCode FROM tbladmininfo WHERE strAdmIDeptCode LIKE '" + listDept[cbDept.SelectedIndex].ToString() + "%') ")); } } } if (rbAll.Checked) { strGender = ""; } else if (rbMale.Checked) { strGender = " AND intPatiGender = 0 "; } else { strGender = " AND intPatiGender = 1 "; } query += " `Code` LIKE '" + txtCode.Text + "%' AND `Code` IN (" + " SELECT strPatiCode FROM dbmedicalclinic.tblpatient " + " WHERE strPatiFirstName LIKE '" + txtFName.Text + "%' " + " AND strPatiMiddleName LIKE '" + txtMName.Text + "%' " + " AND strPatiLastName LIKE '" + txtLName.Text + "%' " + (string.IsNullOrEmpty(txtHeight.Text) ? "" : " AND fltPatiHeight = " + txtHeight.Text) + (string.IsNullOrEmpty(txtWeight.Text) ? "" : " AND fltPatiWeight = " + txtWeight.Text) + (string.IsNullOrEmpty(txtAge.Text) ? "" : " AND TIMESTAMPDIFF(YEAR, datPatiDOB, CURDATE()) = " + txtAge.Text) + strGender + strType + strCollege + strDept + " ); "; //MessageBox.Show(query); if (uCStudentTab != null) { this.uCStudentTab.strQuery = query; this.uCStudentTab.updateTable(); } if (uCPatientLogs_DTR_ != null) { this.uCPatientLogs_DTR_.strQuery = query; this.uCPatientLogs_DTR_.updateTable(); } if (uCFacultyTab != null) { this.uCFacultyTab.strQuery = query; this.uCFacultyTab.updateTable(); } if (uCAdminTab != null) { this.uCAdminTab.strQuery = query; this.uCAdminTab.updateTable(); } if (formAddPatientLogs != null) { formAddPatientLogs.loadPatients(query); } this.Dispose(); }
private void btnAdd_Click(object sender, EventArgs e) { getCode(); if (everythingIsOkay()) { if (string.IsNullOrEmpty(PUPiMed.Program.getNextCode(strCode))) { txtCode.Focus(); status.Text = "Invalid code"; status.BackColor = Color.Tomato; } else { string query; if (new_) { query = "INSERT INTO tblPatient (strPatiCode, intPatiType ,strPatiLastName, strPatiFirstName, strPatiMiddleName, datPatiDOB, intPatiGender, fltPatiHeight, fltPatiWeight, strPatiContact, strPatiAdded) VALUES ('" + strCode + "','" + intType + "','" + strLName + "','" + strFName + "','" + strMName + "','" + strDob + "','" + strGender + "','" + strHeight + "','" + strWeight + "','" + strContactNo + "', USER());"; } else { query = "UPDATE `dbmedicalclinic`.`tblpatient` SET `intPatiType`='" + intType + "', `strPatiLastName`='" + strLName + "', `strPatiFirstName`='" + strFName + "', `strPatiMiddleName`='" + strMName + "', `datPatiDOB`='" + strDob + "', `intPatiGender`='" + strGender + "', `fltPatiHeight`='" + strHeight + "', `fltPatiWeight`='" + strWeight + "', `strPatiContact`='" + strContactNo + "' WHERE `strPatiCode`='" + strCode + "';"; } //save to db if (!PUPiMed.Program.ExecuteQuery(query)) { //tell them something's wrong status.Text = "Failed to save patient"; status.BackColor = Color.Tomato; } else { if (!saveOtherInfo()) { //tell them something's wrong status.Text = "Failed to save additional info"; status.BackColor = Color.Tomato; } else { getCode(); txtCode.Text = strCode; txtLName.Clear(); txtFName.Clear(); txtMName.Clear(); dtBday.Value = dtBday.MaxDate; rbMale.Checked = true; cbPatientType.SelectedIndex = intType; cbDept.SelectedIndex = 0; txtYear.Clear(); txtSection.Clear(); txtHeight.Text = "0"; txtWeight.Text = "0"; txtContactNo.Clear(); status.Text = "Saved"; status.BackColor = Color.LimeGreen; if (log != null) { log.loadPatients(null); } if (uCStudentTab != null) { uCStudentTab.updateTable(); } if (uCAdminTab != null) { uCAdminTab.updateTable(); } if (uCFacultyTab != null) { uCFacultyTab.updateTable(); } if (!new_) { this.Dispose(); } } } } } else { //tell them it's not :( status.Text = "Please fill out all the required fields"; status.BackColor = Color.Tomato; } }