Exemplo n.º 1
0
        private void btnSubmitPatient_Click(object sender, EventArgs e)
        {
            MarikinaOpticalEntities dbContext = new MarikinaOpticalEntities();

            if (btnSubmitPatient.Text == "Submit")
            {
                //Check if serial is existing
                if (IsPatientNoExisting())
                {
                    MessageBox.Show("Patient No. is already used!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (String.IsNullOrWhiteSpace(txtPatientNo.Text) || String.IsNullOrWhiteSpace(txtFirstName.Text) ||
                    Convert.ToInt32(lblAge.Text) <= 0 || String.IsNullOrWhiteSpace(txtLastName.Text))
                {
                    MessageBox.Show("Please fill in required fields!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                DialogResult result = MessageBox.Show("Do you want to 'Sumbit' this patient?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    //Insert Query
                    byte gender   = rbMale.Checked ? (byte)Enums.Gender.Male : (byte)Enums.Gender.Female;
                    byte isActive = 1;
                    dbContext.InsertPatient(txtPatientNo.Text, txtFirstName.Text, txtMiddleName.Text,
                                            gender, dtpBirthday.Value, Convert.ToByte(lblAge.Text), txtMobileNo.Text, txtTelephoneNo.Text, txtHouseNo.Text,
                                            txtStreet.Text, txtBarangay.Text, txtCity.Text, DateTime.Now, txtLastName.Text, isActive);
                    MessageBox.Show("Patient Information has been saved successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Clear();
                }
            }

            if (btnSubmitPatient.Text == "Update")
            {
                if (String.IsNullOrWhiteSpace(txtPatientNo.Text) || String.IsNullOrWhiteSpace(txtFirstName.Text) ||
                    Convert.ToInt32(lblAge.Text) <= 0 || String.IsNullOrWhiteSpace(txtLastName.Text))
                {
                    MessageBox.Show("Please fill in required fields!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                DialogResult result = MessageBox.Show("Do you want to 'Update' this patient?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    //Update Query
                    byte gender = rbMale.Checked ? (byte)Enums.Gender.Male : (byte)Enums.Gender.Female;
                    dbContext.UpdatePatientInformation(Convert.ToInt32(lblPatientId.Text), txtPatientNo.Text, txtFirstName.Text,
                                                       txtMiddleName.Text, txtLastName.Text, gender, dtpBirthday.Value, Convert.ToByte(lblAge.Text), txtMobileNo.Text,
                                                       txtTelephoneNo.Text, txtHouseNo.Text, txtStreet.Text, txtBarangay.Text, txtCity.Text);
                    MessageBox.Show("Patient Information has been updated successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Clear();
                    this.Close();
                }
            }
        }