Exemple #1
0
        private void CreateCustomer()
        {
            Kunde newCustomer = null;

            errorMessage = null;
            bool textHasSpace = false;

            if (newAddress)
            {
                if (!textBoxStreet.Text.Contains(" ") && !textBoxHouseNumber.Text.Contains(" ") &&
                    !textBoxZipCode.Text.Contains(" ") && !textBoxCity.Text.Contains(" "))
                {
                    if (!textBoxStreet.Text.Equals("") && !textBoxHouseNumber.Text.Equals("") &&
                        !textBoxZipCode.Text.Equals("") && !textBoxCity.Text.Equals(""))
                    {
                        aAddress            = new Adresse();
                        aAddress.AdresseID  = 0;
                        aAddress.Strasse    = textBoxStreet.Text;
                        aAddress.Hausnummer = textBoxHouseNumber.Text;
                        aAddress.PLZ        = textBoxZipCode.Text;
                        aAddress.Ort        = textBoxCity.Text;
                    }
                    else
                    {
                        aAddress      = null;
                        errorMessage += "Address";
                    }
                }
                else
                {
                    aAddress     = null;
                    textHasSpace = true;
                    MessageBox.Show("In Ihren Adressdaten dürfen keine Leerzeichen enthalten sein.");
                }
            }

            if (newContact)
            {
                if (!textBoxMail.Text.Contains(" ") && !textBoxPhoneNumber.Text.Contains(" ") &&
                    !textBoxMobileNumber.Text.Contains(" ") && !textBoxFaxNumber.Text.Contains(" "))
                {
                    if (!textBoxMail.Text.Equals("") || !textBoxPhoneNumber.Text.Equals("") ||
                        !textBoxMobileNumber.Text.Equals("") || !textBoxFaxNumber.Text.Equals(""))
                    {
                        aContact               = new Kontakt();
                        aContact.KontaktID     = 0;
                        aContact.E_Mail        = textBoxMail.Text;
                        aContact.Telefonnummer = textBoxPhoneNumber.Text;
                        aContact.Mobilnummer   = textBoxMobileNumber.Text;
                        aContact.Faxnummer     = textBoxFaxNumber.Text;
                    }
                    else
                    {
                        aContact      = null;
                        errorMessage += "Contact";
                    }
                }
                else
                {
                    aContact     = null;
                    textHasSpace = true;
                    MessageBox.Show("In Ihren Kontaktdaten dürfen keine Leerzeichen enthalten sein.");
                }
            }

            if (!textBoxCustomerNumber.Text.Contains(" ") && !textBoxFirstName.Text.Contains(" ") &&
                !textBoxLastName.Text.Contains(" ") && !textBoxAge.Text.Contains(" "))
            {
                if (!textBoxCustomerNumber.Text.Equals("") && !textBoxFirstName.Text.Equals("") && !textBoxLastName.Text.Equals("") &&
                    !comboBoxGender.Text.Equals("") && !textBoxAge.Text.Equals("") && !IsTextInputGreaterThenOneHundred(textBoxAge.Text))
                {
                    if (aAddress != null && aContact != null)
                    {
                        newCustomer              = new Kunde();
                        newCustomer.KundeID      = 0;
                        newCustomer.Kundennummer = textBoxCustomerNumber.Text;
                        newCustomer.Vornamen     = textBoxFirstName.Text;
                        newCustomer.Nachnamen    = textBoxLastName.Text;
                        newCustomer.Geschlecht   = comboBoxGender.Text;
                        newCustomer.Alter        = Convert.ToInt32(textBoxAge.Text);
                        newCustomer.Adresse      = aAddress;
                        newCustomer.AdresseID    = aAddress.AdresseID;
                        newCustomer.Kontakt      = aContact;
                        newCustomer.KontaktID    = aContact.KontaktID;
                    }
                }
                else
                {
                    errorMessage += "Customer";
                }
            }
            else
            {
                textHasSpace = true;
                MessageBox.Show("In Ihren persönlichen Kundendaten dürfen keine Leerzeichen enthalten sein.");
            }

            switch (errorMessage)
            {
            case "AddressContactCustomer":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kunden-, Adress- und Kontaktdaten korrekt aus.");
            }
            break;

            case "AddressCustomer":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kunden- und Adressdaten korrekt aus.");
            }
            break;

            case "ContactCustomer":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kunden- und Kontaktdaten korrekt aus.");
            }
            break;

            case "Customer":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kundendaten korrekt aus.");
            }
            break;

            case "AddressContact":
            {
                MessageBox.Show("Bitte füllen Sie die Adress- und Kontaktdaten korrekt aus.");
            }
            break;

            case "Address":
            {
                MessageBox.Show("Bitte füllen Sie die Adressdaten korrekt aus.");
            }
            break;

            case "Contact":
            {
                MessageBox.Show("Bitte füllen Sie die Kontaktdaten korrekt aus.");
            }
            break;
            }

            if (errorMessage == null && textHasSpace == false)
            {
                var result = MessageBox.Show("Möchten Sie einen neuen Kunden anlegen?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (result == MessageBoxResult.Yes)
                {
                    list.AddressList.Remove(placeHolderAddress);
                    list.addToAddressList(aAddress);

                    list.ContactList.Remove(placeHolderContact);
                    list.addToContactList(aContact);

                    list.addToCustomerList(newCustomer);

                    LoadComboBoxAddress();
                    LoadComboBoxContact();
                    ClearComponents();
                    CustomerNumberSequence();
                }
            }
        }
        private void ModifyCustomer()
        {
            errorMessage = null;
            bool textHasSpace = false;

            if (!textBoxCustomerNumber.Text.Contains(" ") && !textBoxFirstName.Text.Contains(" ") && !(textBoxLastName.Text).Contains(" ") &&
                !comboBoxGender.Text.Contains(" ") && !textBoxAge.Text.Contains(" "))
            {
                if (!textBoxCustomerNumber.Text.Equals("") && !textBoxFirstName.Text.Equals("") && !(textBoxLastName.Text).Equals("") &&
                    !comboBoxGender.Text.Equals("") && !textBoxAge.Text.Equals("") && !IsTextInputGreaterThenOneHundred(textBoxAge.Text))
                {
                    aCustomer.Vornamen   = textBoxFirstName.Text;
                    aCustomer.Nachnamen  = textBoxLastName.Text;
                    aCustomer.Geschlecht = comboBoxGender.Text;
                    aCustomer.Alter      = Convert.ToInt32(textBoxAge.Text);
                }
                else
                {
                    errorMessage += "Customer";
                }
            }
            else
            {
                textHasSpace = true;
                MessageBox.Show("In Ihren persönlichen Kundendaten dürfen keine Leerzeichen enthalten sein.");
            }


            if (!textBoxStreet.Text.Contains(" ") && !textBoxHouseNumber.Text.Contains(" ") &&
                !textBoxZipCode.Text.Contains(" ") && !textBoxCity.Text.Contains(" "))
            {
                if (!textBoxStreet.Text.Equals("") && !textBoxHouseNumber.Text.Equals("") &&
                    !textBoxZipCode.Text.Equals("") && !textBoxCity.Text.Equals(""))
                {
                    aCustomer.Adresse.Strasse    = textBoxStreet.Text;
                    aCustomer.Adresse.Hausnummer = textBoxHouseNumber.Text;
                    aCustomer.Adresse.PLZ        = textBoxZipCode.Text;
                    aCustomer.Adresse.Ort        = textBoxCity.Text;
                }
                else
                {
                    errorMessage += "Address";
                }
            }
            else
            {
                textHasSpace = true;
                MessageBox.Show("In Ihren Adressdaten dürfen keine Leerzeichen enthalten sein.");
            }

            if (!textBoxMail.Text.Contains(" ") && !textBoxPhoneNumber.Text.Contains(" ") &&
                !textBoxMobileNumber.Text.Contains(" ") && !textBoxFaxNumber.Text.Contains(" "))
            {
                if (!textBoxMail.Text.Equals("") || !textBoxPhoneNumber.Text.Equals("") ||
                    !textBoxMobileNumber.Text.Equals("") || !textBoxFaxNumber.Text.Equals(""))
                {
                    aCustomer.Kontakt.E_Mail        = textBoxMail.Text;
                    aCustomer.Kontakt.Telefonnummer = textBoxPhoneNumber.Text;
                    aCustomer.Kontakt.Mobilnummer   = textBoxMobileNumber.Text;
                    aCustomer.Kontakt.Faxnummer     = textBoxFaxNumber.Text;
                }
                else
                {
                    errorMessage += "Contact";
                }
            }
            else
            {
                textHasSpace = true;
                MessageBox.Show("In Ihren Kontaktdaten dürfen keine Leerzeichen enthalten sein.");
            }

            switch (errorMessage)
            {
            case "CustomerAddressContact":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kunden-, Adress- und Kontaktdaten korrekt aus.");
            }
            break;

            case "CustomerAddress":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kunden- und Adressdaten korrekt aus.");
            }
            break;

            case "CustomerContact":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kunden- und Kontaktdaten korrekt aus.");
            }
            break;

            case "Customer":
            {
                MessageBox.Show("Bitte füllen Sie die persönlichen Kundendaten korrekt aus.");
            }
            break;

            case "AddressContact":
            {
                MessageBox.Show("Bitte füllen Sie die Adress- und Kontaktdaten korrekt aus.");
            }
            break;

            case "Address":
            {
                MessageBox.Show("Bitte füllen Sie die Adressdaten korrekt aus.");
            }
            break;

            case "Contact":
            {
                MessageBox.Show("Bitte füllen Sie die Kontaktdaten korrekt aus.");
            }
            break;
            }

            if (errorMessage == null && textHasSpace == false)
            {
                var result = MessageBox.Show("Möchten Sie die Kundendaten speichern?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (result == MessageBoxResult.Yes)
                {
                    Kunde oldCustomer = list.CustomerList.Where(customer => customer.Kundennummer.Equals(aCustomer.Kundennummer)).First();
                    list.CustomerList.Remove(oldCustomer);
                    list.addToCustomerList(aCustomer);

                    Adresse oldAddress = list.AddressList.Where(address => address.Equals(aCustomer.Adresse)).First();
                    list.AddressList.Remove(oldAddress);
                    list.addToAddressList(aCustomer.Adresse);

                    Kontakt oldContact = list.ContactList.Where(contact => contact.Equals(aCustomer.Kontakt)).First();
                    list.ContactList.Remove(oldContact);
                    list.addToContactList(aCustomer.Kontakt);

                    MessageBox.Show("Kundendaten wurden erfolgreich gespeichert.");
                }
            }
        }