Пример #1
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities();
            int           CID             = Convert.ToInt32(CustomerIDTextBox.Text);
            CustomerTable c = ctx.CustomerTables.Where(x => x.CustomerID == CID).First();

            c.Flag = "inactive";
            ctx.SaveChanges();
            MessageBox.Show(c.FirstName + "'s id has been deleted");
            ClearContent();
        }
Пример #2
0
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            bool PhoneNumberOk = false;
            bool PostalCodeOk  = false;

            int  i;
            bool PhoneNumberisInteger = int.TryParse(PhoneTextBox.Text, out i);

            if (PhoneNumberisInteger)
            {
                if (PhoneTextBox.Text.Length == 8)
                {
                    PhoneNumberOk = true;
                }
                else
                {
                    MessageBox.Show("Phone Number must be exactly 8 digits");
                }
            }
            else
            {
                MessageBox.Show("Phone Number must be in digits (8 digits)");
            }

            int  ii;
            bool PostalCodeIsInteger = int.TryParse(PostalCodeTextBox.Text, out ii);

            if (PostalCodeIsInteger)
            {
                if (PostalCodeTextBox.Text.Length == 6)
                {
                    PostalCodeOk = true;
                }
                else
                {
                    PostalCodeOk = false;
                    MessageBox.Show("Postal Code must be exactly 6 digits");
                }
            }
            else
            {
                PostalCodeOk = false;
                MessageBox.Show("Postal Code must be in digits (6 digits)");
            }



            if (PhoneNumberOk && PostalCodeOk)
            {
                try
                {
                    SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities();
                    int           CID             = Convert.ToInt32(CustomerIDTextBox.Text);
                    CustomerTable c = ctx.CustomerTables.Where(x => x.CustomerID == CID).First();
                    c.FirstName   = FirstNameTextBox.Text;
                    c.LastName    = LastNameTextBox.Text;
                    c.PhoneNumber = PhoneTextBox.Text;
                    c.Email       = EmailTextBox.Text;
                    c.Address     = AddressTextBox.Text;
                    c.PostalCode  = PostalCodeTextBox.Text;
                    c.Country     = CountyTextBox.Text;
                    ctx.SaveChanges();
                    MessageBox.Show("Update Successful");
                    ClearContent();
                }

                catch (System.ArgumentOutOfRangeException a)
                {
                    MessageBox.Show("Please ensure all fields are filled before updating");
                }

                catch (System.FormatException b)
                {
                    MessageBox.Show("Please ensure all fields are filled before updating");
                }
            }
        }
Пример #3
0
        private void crAcctSaveBtn_Click(object sender, EventArgs e)
        {
            bool PhoneNumberOk = false;
            bool PostalCodeOk  = false;

            int  i;
            bool isPhoneNumberInteger = int.TryParse(phoneTBox.Text, out i);

            if (isPhoneNumberInteger)
            {
                if (phoneTBox.Text.Length == 8)
                {
                    PhoneNumberOk = true;
                }
                else
                {
                    MessageBox.Show("Phone Number must be exactly 8 digits");
                }
            }
            else
            {
                MessageBox.Show("Phone Number must be in digits (8 digits) ");
            }


            int  ii;
            bool isPostalCodeInteger = int.TryParse(postalTBox.Text, out ii);

            if (isPostalCodeInteger)
            {
                if (postalTBox.Text.Length == 6)
                {
                    PostalCodeOk = true;
                }
                else
                {
                    MessageBox.Show("Postal Code must be exactly 6 digits");
                }
            }
            else
            {
                MessageBox.Show("Postal Code must be in digits (6 digits) ");
            }

            if (PhoneNumberOk && PostalCodeOk)
            {
                if ((firstNameTBox.Text == "" || LastNameTBox.Text == "" || addressTBox.Text == "" || postalTBox.Text == "" || ctyTBox.Text == "") || (maleRadBtn.Checked == false && femaleRadBtn.Checked == false))
                {
                    MessageBox.Show("Please fill in all fields!");
                }
                else
                {
                    SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities();
                    CustomerTable             c   = new CustomerTable();

                    try
                    {
                        c.FirstName   = firstNameTBox.Text;
                        c.LastName    = LastNameTBox.Text;
                        c.DOB         = Convert.ToDateTime(dobDatePicker.Text);
                        c.PhoneNumber = phoneTBox.Text;
                        c.Email       = EmailTBox.Text;
                        c.Address     = addressTBox.Text;
                        c.PostalCode  = postalTBox.Text;
                        c.Country     = ctyTBox.Text;

                        if (maleRadBtn.Checked == true)
                        {
                            c.Gender = "Male";
                        }
                        else
                        {
                            c.Gender = "Female";
                        }
                        ctx.CustomerTables.Add(c);
                        ctx.SaveChanges();
                        MessageBox.Show("User Account " + c.CustomerID + " successfully created!");
                        ClearContent();
                    }

                    catch (System.FormatException a)
                    {
                        MessageBox.Show("Please fill in all fields!");
                    }
                }
            }
        }