Exemplo n.º 1
0
        private void AddEmergencyContact_Click(object sender, EventArgs e)
        {
            EmergencyContactAdd ad = new EmergencyContactAdd(_student);

            ad.ShowDialog();
            if (ad.DialogResult == DialogResult.OK)
            {
                DataBase db = new EmergencyContactData();
                _student.EmergencyContacts = db.GetList(_student.PersonId).ConvertAll(x => x as EmergencyContact);
                PopulateEmergencyContacts();
            }
        }
Exemplo n.º 2
0
        private void RemoveEmergencyContact_Click(object sender, EventArgs e)
        {
            int rowindex = dgEmergencyContacts.CurrentCell.RowIndex;
            int studentEmergencyContactId = (int)dgEmergencyContacts.Rows[rowindex].Cells[0].Value;
            EmergencyContact ec           = _student.EmergencyContacts.Find(x => x.StudentEmergencyContactId == studentEmergencyContactId);

            if (ec != null)
            {
                if (MessageBox.Show("Are you sure you want to remove emergency contact '" + ec.FullName + "' from this student?", "Remove Emergency Contact", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    DataBase db = new EmergencyContactData();
                    db.Remove(new Person(), studentEmergencyContactId);
                    _student.EmergencyContacts = db.GetList(_student.PersonId).ConvertAll(x => x as EmergencyContact);
                    PopulateEmergencyContacts();
                }
            }
        }
Exemplo n.º 3
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);
            }
        }
        public override void Add(EmergencyContact emergencyContact)
        {
            DataBase db = new EmergencyContactData();

            emergencyContact.StudentEmergencyContactId = db.Add(emergencyContact, _student.PersonId);
        }
Exemplo n.º 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            ep.Clear();

            if (txtEmergencyContactFullName.Text == string.Empty)
            {
                ep.SetError(txtEmergencyContactFullName, "Type new emergency contact full 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");
            }
            if (txtRelationship.Text == string.Empty)
            {
                ep.SetError(txtRelationship, "Type Relationship");
            }

            bool failed = false;

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

            if (failed)
            {
                return;
            }
            else
            {
                try
                {
                    var ec = new EmergencyContact
                    {
                        FullName     = txtEmergencyContactFullName.Text,
                        Addr1        = txtAddr1.Text,
                        Addr2        = txtAddr2.Text,
                        Addr3        = txtAddr3.Text,
                        Addr4        = txtAddr4.Text,
                        Postcode     = txtPostcode.Text,
                        Phone        = txtPhone.Text,
                        Relationship = txtRelationship.Text
                    };

                    DataBase db = new EmergencyContactData();
                    ec.StudentEmergencyContactId = db.Add(ec, _student.PersonId);
                    this.DialogResult            = DialogResult.OK;
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }