示例#1
0
        public override void AllocateDoctor(Doctor doctor)
        {
            DataBase db = new DoctorData();

            db.Allocate(doctor, Student.PersonId);
        }
示例#2
0
        public override void Save()
        {
            DBCommand dbc = new DBCommand(DBCommand.TransactionType.WithTransaction);

            try
            {
                DataBase db = new StudentData(dbc);
                if (Student.PersonId == 0)
                {
                    int studentId = db.Add(Student);
                    if (Student.Doctors.Count > 0)
                    {
                        db = new DoctorData(dbc);
                        foreach (Doctor doctor in Student.Doctors)
                        {
                            db.Allocate(doctor, studentId);
                        }
                    }

                    if (Student.NextOfKin.Count > 0)
                    {
                        db = new NextOfKinData(dbc);
                        foreach (NextOfKin nok in Student.NextOfKin)
                        {
                            if (nok.PersonId == 0)
                            {
                                nok.PersonId = db.Add(nok, studentId);
                            }
                            else
                            {
                                db.Allocate(nok, studentId);
                            }
                        }
                    }

                    if (Student.EmergencyContacts.Count > 0)
                    {
                        db = new EmergencyContactData(dbc);
                        foreach (EmergencyContact ec in Student.EmergencyContacts)
                        {
                            //if (ec.PersonId == 0)
                            //{
                            ec.PersonId = db.Add(ec, studentId);
                            //}
                            //db.Allocate(ec, studentId);
                        }
                    }

                    if (Student.MedicalConditions.Count > 0)
                    {
                        MedicalConditionData mdc = new MedicalConditionData(dbc);
                        foreach (MedicalCondition mc in Student.MedicalConditions)
                        {
                            mdc.Add(mc, studentId);
                        }
                    }
                }
                else
                {
                    db.Update(Student);
                }
                dbc.CommitTransactions();
                dbc.CloseConnection();
                Student.RemovedObjects.Clear();
            }
            catch (Exception ex)
            {
                dbc.rollbackTransactions();
                dbc.CloseConnection();
                throw new Exception(ex.Message);
            }
        }
示例#3
0
        //private void CmbFullName_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    throw new NotImplementedException();
        //}

        private void btnAdd_Click(object sender, EventArgs e)
        {
            ep.Clear();
            if (cmbDoctorName.Text == string.Empty && rbAllocateFromList.Checked)
            {
                ep.SetError(cmbDoctorName, "Select a doctor or type new doctor name");
            }
            if (txtDoctorName.Text == string.Empty && rbAddNewDoctor.Checked)
            {
                ep.SetError(cmbDoctorName, "Type new doctor name");
            }
            if (txtAddr1.Text == string.Empty)
            {
                ep.SetError(txtAddr1, "Type Addr1");
            }
            if (txtAddr2.Text == string.Empty)
            {
                ep.SetError(txtAddr2, "Type Addr2");
            }
            if (txtAddr3.Text == string.Empty)
            {
                ep.SetError(txtAddr3, "Type Addr3");
            }
            if (txtPostcode.Text == string.Empty)
            {
                ep.SetError(txtPostcode, "Type Postcode");
            }
            if (txtPhone.Text == string.Empty)
            {
                ep.SetError(txtPhone, "Type Phone");
            }

            bool failed = false;

            foreach (Control c in this.Controls)
            {
                if (ep.GetError(c).Length > 0)
                {
                    failed = true;
                }
            }

            if (failed)
            {
                return;
            }
            else
            {
                try
                {
                    DataBase db = new DoctorData();
                    if (_selectedDoctor == null) // add doctor and assign to student
                    {
                        Person doctor = new Doctor
                        {
                            FullName = txtDoctorName.Text,
                            Addr1    = txtAddr1.Text,
                            Addr2    = txtAddr2.Text,
                            Addr3    = txtAddr3.Text,
                            Addr4    = txtAddr4.Text,
                            Postcode = txtPostcode.Text,
                            Phone    = txtPhone.Text,
                            Email    = txtEmail.Text
                        };

                        int doctorId = db.Add(doctor, _student.PersonId);
                        doctor.PersonId = doctorId;
                    }
                    else // add doctor to student
                    {
                        db.Allocate(_selectedDoctor, _student.PersonId);
                    }
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            //if(ep.GetError())
        }