Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string msg = "Invalid input. Please refer to the error box";
            IEnumerable <string> brokenRules = null;
            bool isValid = true;

            if (newEmployeeType)
            {
                EmployeeType et = new EmployeeType(0, cbmEmployeeType.Text);
                isValid = et.Validate(out brokenRules);
                if (isValid)
                {
                    et.Insert();
                    employeeTypes.Add(et);
                    cbmEmployeeType.DataSource   = employeeTypes;
                    cbmEmployeeType.SelectedItem = et;
                }
            }

            if (newNotificationType)
            {
                NotificationType nt = new NotificationType(0, cmbNotificationType.Text);
                isValid = nt.Validate(out brokenRules);
                if (isValid)
                {
                    nt.Insert();
                    notificationTypes.Add(nt);
                    cmbNotificationType.DataSource   = notificationTypes;
                    cmbNotificationType.SelectedItem = nt;
                }
            }

            if (isValid)
            {
                isValid = validateCurrent(out brokenRules);
                if (isValid)
                {
                    if (insert)
                    {
                        currentPerson.Insert();
                        if (currentPerson.GetType() == typeof(Client))
                        {
                            (currentPerson as Client).Insert();
                            msg = "Client inserted";
                        }
                        else
                        {
                            (currentPerson as Employee).Insert();
                            msg = "Employee inserted";
                        }
                    }
                    else
                    {
                        currentPerson.Update();
                        if (currentPerson.GetType() == typeof(Client))
                        {
                            (currentPerson as Client).Update();
                            msg = "Client updated";
                        }
                        else
                        {
                            (currentPerson as Employee).Update();
                            msg = "Employee updated";
                        }
                    }
                    insert = editable = false;
                    enableTabs(!insert);
                    setControlEnabled(false);
                }
            }

            lstError.DataSource = brokenRules.ToList();
            MessageBox.Show(msg, "Modification Status", MessageBoxButtons.OK, isValid ? MessageBoxIcon.Information : MessageBoxIcon.Error);
        }