Example #1
0
        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;
            }
        }