Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // Collect data from all input fields
            IEnumerable <Control> tbs  = Utils.GetControlsFromControl(pnlSafeArea, typeof(TextBox));
            List <string>         vals = new List <string>();

            foreach (var control in tbs)
            {
                vals.Add(((TextBox)control).Text);
            }

            var newUser = interfaceMadeFor;

            PropertyInfo[] props = newUser.GetType().GetProperties();

            // Populate the property values to what was collected
            for (int i = 0; i != props.Length; i++)
            {
                // This will require error validation
                if (props[i].PropertyType == typeof(Role))
                {
                    props[i].SetValue(newUser, Authentication.GetRoleFromPrivilegeLevel(int.Parse(vals[i])));
                }

                else if (props[i].PropertyType == typeof(Int32))
                {
                    props[i].SetValue(newUser, int.Parse(vals[i]), null);
                }
                else
                {
                    props[i].SetValue(newUser, vals[i], null);
                }
            }
            // Add the new User to the list of Users
            DataInstance.users.Add(newUser);

            //Add the new user to the database
            switch (newUser.Role.Name)
            {
            case Role.Names.Organiser:
                DataInstance.addOrganiser((SeminarOrganiser)newUser);
                break;

            case Role.Names.Speaker:
                DataInstance.addSpeaker((Speaker)newUser);
                break;

            case Role.Names.Admin:
                DataInstance.addAdmin((SystemAdmin)newUser);
                break;

            case Role.Names.Host:
                DataInstance.addHost((SeminarHost)newUser);
                break;
            }

            MessageBox.Show("An account for " + newUser.Name + " has been created. ",
                            "New Account Successfully Created", MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.Close();
        }