コード例 #1
0
        public override void AddDoctor(Doctor doctor)
        {
            DataBase db       = new DoctorData();
            int      doctorId = db.Add(doctor, Student.PersonId);

            doctor.PersonId = doctorId;
        }
コード例 #2
0
        public override void Commit()
        {
            DataBase db = new DoctorData();

            _doctorAddEdit.Doctor.PersonId = db.Add(_doctorAddEdit.Doctor);
        }
コード例 #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())
        }