コード例 #1
0
        private string identifierGenerator()
        {
            Random rnd        = new Random();
            int    random     = rnd.Next(1, 5);
            string identifier = "";

            switch (random)
            {
            case 1: identifier = "A"; break;

            case 2: identifier = "B"; break;

            case 3: identifier = "C"; break;

            case 4: identifier = "D"; break;

            case 5: identifier = "E"; break;

            default:
                break;
            }
            for (int i = 0; i < 8; i++)
            {
                identifier = identifier + rnd.Next(0, 9).ToString();
            }

            if (ValidationCheck.getInstance().IsValidClientIdentifier(identifier, allClients) == true)
            {
                return(identifier);
            }
            else
            {
                return(identifierGenerator());
            }
        }
コード例 #2
0
        private void InsertNew(object sender, RoutedEventArgs e)
        {
            bool valid = true;

            resetBorders();
            if (ValidationCheck.getInstance().IsValidEmail(txtEmail.Text, allClients) == false)
            {
                txtEmail.BorderBrush = red;
                valid = false;
            }
            if (ValidationCheck.getInstance().IsPopulatedString(txtName.Text) == false)
            {
                txtName.BorderBrush = red;
                valid = false;
            }
            if (ValidationCheck.getInstance().IsPopulatedString(txtSurname.Text) == false)
            {
                txtSurname.BorderBrush = red;
                valid = false;
            }
            if (ValidationCheck.getInstance().IsValidID(txtID.Text, allClients) == false)
            {
                txtID.BorderBrush = red;
                valid             = false;
            }
            if (ValidationCheck.getInstance().IsValidCell(txtCell.Text) == false)
            {
                txtCell.BorderBrush = red;
                valid = false;
            }
            if (ValidationCheck.getInstance().IsPopulatedString(txtCountry.Text) == false)
            {
                txtCountry.BorderBrush = red;
                valid = false;
            }
            if (ValidationCheck.getInstance().IsPopulatedString(txtCity.Text) == false)
            {
                txtCity.BorderBrush = red;
                valid = false;
            }
            if ((ValidationCheck.getInstance().IsStringInt(txtPostalCode.Text) == false) || (txtPostalCode.Text.Length != 4))
            {
                txtPostalCode.BorderBrush = red;
                valid = false;
            }
            if (ValidationCheck.getInstance().IsPopulatedString(txtLine1.Text) == false)
            {
                txtLine1.BorderBrush = red;
                valid = false;
            }

            if (valid == true)
            {
                Guid           a                 = Guid.NewGuid();
                Guid           cd                = Guid.NewGuid();
                Guid           c                 = Guid.NewGuid();
                Guid           p                 = Guid.NewGuid();
                Address        newAddress        = new Address(txtCountry.Text, txtCity.Text, txtPostalCode.Text, txtLine1.Text, txtLine2.Text, a);
                ContactDetails newContactDetails = new ContactDetails(txtEmail.Text, txtCell.Text, txtTell.Text, cd);
                Client         newClient         = new Client(txtName.Text, txtSurname.Text, txtID.Text, newAddress, newContactDetails, p, identifierGenerator(), c);

                insertNewClient(newClient);

                allClients.Add(newClient);
                lstClients.Items.Refresh();
                resetBorders();
            }
        }