コード例 #1
0
 public void DataBaseAddUser(AddUserProcedure newUser)
 {
     command = new MySqlCommand($"call dodaj_uzytkownika('{newUser.Pesel}', '{newUser.Name}', '{newUser.Surname}', '{newUser.DateOfBirth}', '{newUser.Sex}', '{newUser.ContactNumber}', '{newUser.Country}', '{newUser.City}', '{newUser.Street}', '{newUser.HouseNumber}', '{newUser.ApartmentNumber}', '{newUser.PostalCode}', '{newUser.Login}', '{newUser.Password}', '{newUser.Role}', '{newUser.StudyField}', {newUser.Semestr}, {newUser.Degree}, {newUser.CurrentUser});", this.conection);
     adapter.InsertCommand = command;
     adapter.InsertCommand.ExecuteNonQuery();
     command.Dispose();
 }
コード例 #2
0
        private void AddUserButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(NameBox.Text) ||
                string.IsNullOrWhiteSpace(SurnameBox.Text) ||
                string.IsNullOrWhiteSpace(EmailBox.Text) ||
                string.IsNullOrWhiteSpace(BirthDateBox.Text) ||
                string.IsNullOrWhiteSpace(CreditCardBox.Text) ||
                string.IsNullOrWhiteSpace(CvvBox.Text))
            {
                MessageBox.Show("Provide needed information");
            }
            else
            {
                AddUserProcedure addUser = new AddUserProcedure(Connector, NameBox.Text, SurnameBox.Text,
                                                                EmailBox.Text, BirthDateBox.Text, CreditCardBox.Text, CvvBox.Text, CityBox.Text.NullString(),
                                                                BuildingBox.Text.NullString(), FlatBox.Text.NullString(), StreetBox.Text.NullString(), PostalCodeBox.Text.NullString(),
                                                                AddressIdBox.Text.NullNumber());

                try
                {
                    var     dt  = addUser.ExecuteQuery();
                    DataRow row = dt.Rows[0];

                    if (int.Parse(row["AffectedRows"].ToString() ?? string.Empty) > 0)
                    {
                        MessageBox.Show("Successfully added user!");
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
        }
コード例 #3
0
        private void AddNewStudent()
        {
            AddUserProcedure           newUser = new AddUserProcedure();
            FieldOfStudyCheckProcedure field   = new FieldOfStudyCheckProcedure();
            string errorMessage = "";

            if (!DataValidation.DataValidation.ValidPesel(tableRowContentList[0].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidName(tableRowContentList[1].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidSurname(tableRowContentList[2].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidDateOfBirth(tableRowContentList[3].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidSex(tableRowContentList[4].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidContactNumber(tableRowContentList[5].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidCountry(tableRowContentList[6].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidCity(tableRowContentList[7].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidStreet(tableRowContentList[8].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidHouseNumber(tableRowContentList[9].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidApartmentNumber(tableRowContentList[10].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidPostalCode(tableRowContentList[11].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidLogin(tableRowContentList[12].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidPassword(tableRowContentList[13].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (!DataValidation.DataValidation.ValidRole(tableRowContentList[14].Text, out errorMessage))
            {
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (tableRowContentList[14].Text == "s")
            {
                if (!DataValidation.DataValidation.ValidStudyField(tableRowContentList[15].Text, out errorMessage))
                {
                    AlertWindow alertWindow = new AlertWindow(errorMessage);
                    alertWindow.ShowDialog();
                    return;
                }

                if (!DataValidation.DataValidation.ValidSemestr(tableRowContentList[16].Text, out errorMessage))
                {
                    AlertWindow alertWindow = new AlertWindow(errorMessage);
                    alertWindow.ShowDialog();
                    return;
                }

                if (!DataValidation.DataValidation.ValidDegree(tableRowContentList[17].Text, out errorMessage))
                {
                    AlertWindow alertWindow = new AlertWindow(errorMessage);
                    alertWindow.ShowDialog();
                    return;
                }

                field.StudyField = tableRowContentList[15].Text;
                field.Semestr    = int.Parse(tableRowContentList[16].Text);
                field.Degree     = int.Parse(tableRowContentList[17].Text);

                if (!DbService.DataBaseCheckFieldOfStudy(field))
                {
                    errorMessage = "Nie istnieje kierunek lub nie ma takiego semestru na danym stopniu studiów.";
                    AlertWindow alertWindow = new AlertWindow(errorMessage);
                    alertWindow.ShowDialog();
                    return;
                }

                newUser.StudyField = tableRowContentList[15].Text;
                newUser.Semestr    = int.Parse(tableRowContentList[16].Text);
                newUser.Degree     = int.Parse(tableRowContentList[17].Text);
            }
            else
            {
                errorMessage = "Jako pracownik dziekanatu możesz dodać tylko studenta.\n" + "Jako rola użytkownika musisz więc wpisać 's'";
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (DbService.DataBaseCheckPesel(tableRowContentList[0].Text))
            {
                errorMessage = "Taki pesel już istnieje w bazie danych.";
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            if (DbService.DataBaseCheckLogin(tableRowContentList[12].Text))
            {
                errorMessage = "Taki login już istnieje w bazie danych.";
                AlertWindow alertWindow = new AlertWindow(errorMessage);
                alertWindow.ShowDialog();
                return;
            }

            newUser.Pesel           = tableRowContentList[0].Text;
            newUser.Name            = tableRowContentList[1].Text;
            newUser.Surname         = tableRowContentList[2].Text;
            newUser.DateOfBirth     = tableRowContentList[3].Text;
            newUser.Sex             = tableRowContentList[4].Text.ToCharArray()[0];
            newUser.ContactNumber   = tableRowContentList[5].Text;
            newUser.Country         = tableRowContentList[6].Text;
            newUser.City            = tableRowContentList[7].Text;
            newUser.Street          = tableRowContentList[8].Text;
            newUser.HouseNumber     = tableRowContentList[9].Text;
            newUser.ApartmentNumber = tableRowContentList[10].Text;
            newUser.PostalCode      = tableRowContentList[11].Text;
            newUser.Login           = tableRowContentList[12].Text;
            newUser.Password        = tableRowContentList[13].Text;
            newUser.Role            = tableRowContentList[14].Text;
            newUser.CurrentUser     = signInUser.UserID;
            DbService.DataBaseAddUser(newUser);

            errorMessage = "Dodano studenta.";
            AlertWindow alertWindow2 = new AlertWindow(errorMessage);

            alertWindow2.ShowDialog();
        }