Ejemplo n.º 1
0
        public void ResetAddStudentControl(bool clearLog = true)
        {
            /*
             * This function contains all code that needs to be executed when the control is reloaded
             *
             * You need to edit this code.
             * Example: Emptying textboxes and gridviews
             *
             */
            phoneNumbers.Clear();
            phoneTypes.Clear();
            StudentidTextbox.ResetText();
            FirstnameTextbox.ResetText();
            LastnameTextbox.ResetText();
            GenderTextbox.ResetText();
            StreetadressTextbox.ResetText();
            ZipcodeTextbox.ResetText();
            CityTextbox.ResetText();
            CountryTextbox.ResetText();
            BirthdateDatepicker.Value = BirthdateDatepicker.MaxDate;
            PhoneNumberTextbox.ResetText();
            AddedPhoneNumbers_Readonly.ResetText();

            if (clearLog)
            {
                RegisterStatusTextbox.ResetText();
            }
        }
Ejemplo n.º 2
0
        private void RegisterNewStudentButton_Click(object sender, EventArgs e)
        {
            int exitCodeStudent = dbconn.addStudentToDB(
                StudentidTextbox.Text,
                FirstnameTextbox.Text,
                LastnameTextbox.Text,
                GenderTextbox.Text,
                StreetadressTextbox.Text,
                ZipcodeTextbox.Text,
                CityTextbox.Text,
                CountryTextbox.Text,
                string.Format($"{BirthdateDatepicker.Value.Year + "-" + BirthdateDatepicker.Value.Month + "-" + BirthdateDatepicker.Value.Day}"),
                StudentTypeCombobox.Text
                );

            int[] exitCodePhoneNumbers = new int[phoneNumbers.Count];
            exitCodePhoneNumbers = dbconn.addStudentPhoneNoToDB(
                StudentidTextbox.Text,
                phoneNumbers,
                phoneTypes
                );


            if (exitCodeStudent == -1)
            {
                RegisterStatusTextbox.Text += "0 rows updated...";
                RegisterStatusTextbox.AppendText(Environment.NewLine);
                RegisterStatusTextbox.Text += $"An error prevented the new student: {StudentidTextbox.Text} ({FirstnameTextbox.Text} {LastnameTextbox.Text}) from being added to the database.";
                RegisterStatusTextbox.AppendText(Environment.NewLine);
                RegisterStatusTextbox.Text += $"Because of this error no phonenumbers where added.";
                RegisterStatusTextbox.AppendText(Environment.NewLine);
            }

            else if (exitCodeStudent == 1)
            {
                RegisterStatusTextbox.Text += "1 row updated...";
                RegisterStatusTextbox.AppendText(Environment.NewLine);
                RegisterStatusTextbox.Text += $"The new student: {StudentidTextbox.Text} ({FirstnameTextbox.Text} {LastnameTextbox.Text}) was successfully added to the database!";
                RegisterStatusTextbox.AppendText(Environment.NewLine);
                for (int i = 0; i < exitCodePhoneNumbers.Length; i++)
                {
                    if (exitCodePhoneNumbers[i] == 1)
                    {
                        RegisterStatusTextbox.Text += $"Phone number {phoneNumbers[i]} - {phoneTypes[i]} added to the database.";
                        RegisterStatusTextbox.AppendText(Environment.NewLine);
                    }
                    else if (exitCodePhoneNumbers[i] == -1)
                    {
                        RegisterStatusTextbox.Text += $"Error. Phone number {phoneNumbers[i]} not added to database.";
                        RegisterStatusTextbox.AppendText(Environment.NewLine);
                    }
                }
                ResetAddStudentControl(false);
            }
        }