Example #1
0
        private void addCustomerButton_Click(object sender, EventArgs e)
        {
            var checkCustomerFirstName = txtCustomerFirstName.Text.IndexOfAny(disallowedCharacters) != -1;
            var checkCustomerLastName  = txtCustomerLastName.Text.IndexOfAny(disallowedCharacters) != -1;

            if (checkCustomerFirstName != true && checkCustomerLastName != true)
            {
                if (txtCustomerFirstName.TextLength > 1)
                {
                    customerFirstname = txtCustomerFirstName.Text;
                }
                if (txtCustomerLastName.TextLength > 1)
                {
                    customerLastname = txtCustomerLastName.Text;
                }
                for (int i = 0; i < customerEmailCharacters.Length; i++)
                {
                    customerEmail = customerEmailAddress.Text;
                }

                if (txtCustomerFirstName.TextLength > 1)
                {
                    if (txtCustomerLastName.TextLength > 1)
                    {
                        ValidationCustomer vc = new ValidationCustomer()
                        {
                            MobileNumber   = customerPrimaryContactText.Text,
                            LandlineNumber = CustomerSecondaryContactText.Text,
                            EmailAddress   = customerEmailAddress.Text,
                            Firstname      = txtCustomerFirstName.Text,
                            Lastname       = txtCustomerLastName.Text
                        };

                        vc = Validation.validateCustomerDetails(vc);
                        //sending data (after validation checks) to the database
                        using (var db = new DatabaseContext())
                        {
                            if (!Validation.checkIfDoubleEntryEmail(vc.EmailAddress))
                            {
                                if (!Validation.checkIfDoubleEntryPrimaryPhone(vc.MobileNumber))
                                {
                                    if (customerAddress.Text.Length > 0)
                                    {
                                        Customer c = new Customer();
                                        c.player           = new Player();
                                        c.player.Firstname = vc.Firstname;
                                        c.player.Lastname  = vc.Lastname;
                                        c.DayOfBirth       = comboBox1.SelectedItem.ToString();
                                        c.MonthofBirth     = comboBox2.SelectedItem.ToString();
                                        c.YearOfBirth      = comboBox3.SelectedItem.ToString();
                                        c.Address          = customerAddress.Text;
                                        c.EmailAddress     = vc.EmailAddress;
                                        c.MobileNumber     = vc.MobileNumber;
                                        c.LandlineNumber   = vc.LandlineNumber;

                                        if (c.MobileNumber.Length >= 11 && c.MobileNumber.Length <= 13)
                                        {
                                            if (c.LandlineNumber.Length >= 11 && c.LandlineNumber.Length <= 13)
                                            {
                                                db.Customers.Add(c);
                                                db.SaveChanges();
                                                MessageBox.Show("Customer successfully added");
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Mobile number already found in database!");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Email Address already found in database!");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Customer last name not enough characters");
                    }
                }
                else
                {
                    MessageBox.Show("Customer first name not enough characters");
                }
            }
            else
            {
                MessageBox.Show("Invalid symbol in name field");
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //if (txtCustomerFirstName.TextLength > 1)
            //{
            //    firstname = txtCustomerFirstName.Text.ToString();
            //}
            //if (txtCustomerLastName.TextLength > 1)
            //{
            //    lastname = txtCustomerLastName.Text.ToString();
            //}
            //for (int i = 0; i < emailCharacters.Length; i++)
            //{
            //    //set values of textbox3 to email and then check if it contains email characters?
            //    //if (textBox3.Contains(emailCharacters[i]))
            //    //{
            //        email = customerEmailAddress.Text.ToString();
            //    //}
            //}
            //validatePrimaryContactDetails(customerPrimaryContactText.Text.ToString());
            //validateSecondaryContactDetails(CustomerSecondaryContactText.Text.ToString());

            ////variables to be added to database
            //label6.Text = (firstname + " " + lastname + " " + email + " " + correctPrimaryContact + " " + correctSecondaryContact);

            ////sending data (after validation checks) to the database
            //using (var db = new DatabaseContext())
            //{
            //    if (!checkIfDoubleEntryEmail(email))
            //    {
            //        if (!checkIfDoubleEntryPrimaryPhone(primaryContact))
            //        {
            //            if (!checkIfDoubleEntryPrimaryPhone(secondaryContact))
            //            {
            //                Customer c = new Customer();
            //                c.player = new Player();
            //                c.player.Firstname = firstname;
            //                c.player.Lastname = lastname;
            //                c.EmailAddress = email;
            //                c.primaryContact = correctPrimaryContact;
            //                c.secondaryContact = correctSecondaryContact;

            //                db.Customers.Add(c);
            //                db.SaveChanges();
            //            }
            //        }
            //    }
            //    else
            //    {
            //        MessageBox.Show("Email Address, primary contact or secondary contact already found in database!");
            //    }
            //}
            if (txtCustomerFirstName.TextLength > 1)
            {
                customerFirstname = txtCustomerFirstName.Text;
            }
            if (txtCustomerLastName.TextLength > 1)
            {
                customerLastname = txtCustomerLastName.Text;
            }
            for (int i = 0; i < customerEmailCharacters.Length; i++)
            {
                customerEmail = customerEmailAddress.Text;
            }


            ValidationCustomer vc = new ValidationCustomer()
            {
                MobileNumber   = customerPrimaryContactText.Text,
                LandlineNumber = CustomerSecondaryContactText.Text,
                EmailAddress   = customerEmailAddress.Text,
                Firstname      = txtCustomerFirstName.Text,
                Lastname       = txtCustomerLastName.Text
            };


            vc = Validation.validateCustomerDetails(vc);
            //sending data (after validation checks) to the database
            using (var db = new DatabaseContext())
            {
                if (!Validation.checkIfDoubleEntryEmail(vc.EmailAddress))
                {
                    if (!Validation.checkIfDoubleEntryPrimaryPhone(vc.MobileNumber))
                    {
                        if (!Validation.checkIfDoubleEntryPrimaryPhone(vc.LandlineNumber))
                        {
                            Customer c = new Customer();
                            c.player           = new Player();
                            c.player.Firstname = vc.Firstname;
                            c.player.Lastname  = vc.Lastname;
                            c.EmailAddress     = vc.EmailAddress;
                            c.MobileNumber     = vc.MobileNumber;
                            c.LandlineNumber   = vc.LandlineNumber;

                            db.Customers.Add(c);
                            db.SaveChanges();
                            MessageBox.Show("Customer successfully added");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Email Address, primary contact or secondary contact already found in database!");
                }
            }
        }