Пример #1
0
        private void editStudentButton_Click(object sender, EventArgs e)
        {
            EditStudent  edit   = new EditStudent(student);
            DialogResult dialog = edit.ShowDialog(this);

            if (dialog != DialogResult.OK)
            {
                return;
            }
            else
            {
                // Make this local var to prevent "marshal-by-reference" classes - https://stackoverflow.com/questions/4178576/accessing-a-member-on-form-may-cause-a-runtime-exception-because-it-is-a-field-o
                int newAlps = edit.newAlps;
                Dictionary <string, string> formData = new Dictionary <string, string> {
                    { "forename", edit.newForename },
                    { "surname", edit.newSurname },
                    { "alps", newAlps.ToString() },
                };

                if (edit.isNewUsername)
                {
                    formData.Add("username", edit.newUsername);
                }

                APIHandler.UpdateStudent(student, formData);
                MessageBox.Show(edit.newForename + "'s account has been edited.");
                this.studentPanelNeedsRefresh = true;
                this.Close();
            }
        }
Пример #2
0
        public override void OnNewObjButtonClick(object sender, EventArgs e)
        {
            EditStudent  edit   = new EditStudent(); // Create a new student
            DialogResult dialog = edit.ShowDialog(this);

            if (dialog != DialogResult.OK)
            {
                return;
            }
            string username = edit.newUsername;
            string forename = edit.newForename;
            string surname  = edit.newSurname;
            int    alps     = edit.newAlps;

            APIHandler.CreateStudent(forename, surname, username, alps); // TODO: Perhaps make these return a boolean, to denote whether the creation has been succesful or not
            MessageBox.Show(username + "'s account has been created successfully! Please tell them to use the 'first time sign-in' when they try to sign-in.");
            RefreshList();
        }