Example #1
0
        private static void insertAdress(Address address)
        {
            myConnection.Open();

            SqlCommand cmd = new SqlCommand("insert into PatientAddress(patientID, type, deliveryAddress, subdivision, division, postalCode) values(@pt_Id, @type, @address, @city, @province, @postalCode);");
            cmd.Connection = myConnection;

            cmd.Parameters.AddWithValue("@pt_Id", address.patientID);
            cmd.Parameters.AddWithValue("@type", address.type);
            cmd.Parameters.AddWithValue("@address", address.address);
            cmd.Parameters.AddWithValue("@city",address.city);
            cmd.Parameters.AddWithValue("@province",address.province);
            cmd.Parameters.AddWithValue("@postalCode",address.postalCode);

            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();

            myConnection.Close();
        }
Example #2
0
        private void btnAddRecord_Click(object sender, EventArgs e)
        {
            bool DOB_valid;
            bool exp_valid;
            bool pass=false;

            //check whether Insurance numer exits
            dictionary = new Dictionary<string, string>();
            dictionary.Add("@insuranceNumber", txtInsuranceNumber.Text);
            dc = new DatabaseConnector();
            dtInsurance = dc.getData("CheckInsuranceExists", dictionary);
            int ins_exist = int.Parse(dtInsurance.Rows[0][0].ToString());

            //create new patient
            Patient patient = new Patient();
            patient.firstName = txtFirstName.Text;
            patient.lastName = txtLastName.Text;
            patient.dob = txtDOB.Text;
            patient.gender = cmbxGender.GetItemText(cmbxGender.SelectedItem);

            //create new insurance
            Insurance insurance = new Insurance();
            insurance.timestamp = (DateTime.Now).ToString();
            insurance.insNumber = txtInsuranceNumber.Text;
            insurance.versionCode = txtVersionCode.Text;
            insurance.expDate = txtInsuranceExpDate.Text;

            //create new allergy
            Allergy allergy = new Allergy();
            allergy.name = txtAllergyName.Text;
            allergy.category = txtAllergyCatergory.Text;

            //create new allergy-patient
            PatientAllergy ptAllgergy = new PatientAllergy();

            //ins number : number only
            //ins vc : character only
            //no blank: name, dob

            Phone phone = new Phone();
            phone.type = cmbxPhoneType.GetItemText(cmbxPhoneType.SelectedItem);
            phone.phoneNumber = txtPhoneNumber.Text;

            Email email = new Email();
            email.type = cmbxEmailType.GetItemText(cmbxEmailType.SelectedItem);
            email.email = txtEmail.Text;

            Address address = new Address();
            address.type = cmbxAddressType.GetItemText(cmbxAddressType.SelectedItem);
            address.address = txtAddress.Text;
            address.city = txtCity.Text;
            address.province = txtProvince.Text;
            address.postalCode = txtPostalCode.Text;

            DOB_valid = DOB_validation();
            exp_valid = exp_validation();

            if (DOB_valid == true && exp_valid == true && ins_exist == 0 && txtInsuranceNumber.TextLength == 10)
            {
                pass = true;
            }

              if (pass == true )
              {
                  insertPatient(patient);

                  patient.patientID = getPtIdfromPatienTbl();
                  insurance.patientID = patient.patientID;
                  phone.patientID = patient.patientID;
                  email.patientID = patient.patientID;
                  address.patientID = patient.patientID;

                  insertInsurance(insurance);

                  if (getAllergyIdfromAllergyTbl() != 0)
                  {
                      ptAllgergy.patientId = patient.patientID;
                      ptAllgergy.allergyId = getAllergyIdfromAllergyTbl();
                      insertPatientAllergy(ptAllgergy);
                  }
                  else
                  {
                      insertAllergy(allergy);
                      ptAllgergy.patientId = patient.patientID;
                      ptAllgergy.allergyId = getAllergyIdfromAllergyTbl2();
                      insertPatientAllergy(ptAllgergy);
                  }

                  insertPhone(phone);
                  insertAdress(address);
                  insertEmail(email);

                    clearText();
                    MessageBox.Show("Patient was registed");
              }

              else if (txtInsuranceNumber.TextLength != 10) //number incorrect of left blank
              {
                  MessageBox.Show("Please insert correct insurance number");
              }
              else if (ins_exist != 0)
              {
                  MessageBox.Show("Insurance Number already exists");
              }
              else if (DOB_valid == false)
              {
                  MessageBox.Show("D.O.B not valid");
              }

              else if (exp_valid == false)
              {
                  MessageBox.Show("Insurance Expiry Date not valid");
              }
        }