예제 #1
0
 private void ContinueButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string s = this.PhoneTextBox.Text;
         //if (s == "")
         //    throw new Exception("Please enter a phone number!");
         if (App.isPhoneValid(s))
         {
             this.PhoneTextBox.BorderBrush = Brushes.Black;
             this.PhoneTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
             AddOrderPage2 p = new AddOrderPage2();
             p.order.ClientID = bl.findClientByPhoneNumber(client.PhoneNumber).ClientID;
             this.NavigationService.Navigate(p);
         }
         else
         {
             this.PhoneTextBox.BorderBrush = Brushes.Red;
             throw new Exception("Phone number must contain 9-10 digits only!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Erorr", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
예제 #2
0
        private void NextButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                int errorCount = 0;
                foreach (var child in this.MainGrid.Children)
                {
                    if (child is TextBox)
                    {
                        TextBox textBox = child as TextBox;
                        if ((!App.isWordValid(textBox.Text) && textBox != this.HouseNumberTextBox && textBox != this.ZipCodeTextBox && textBox != this.PhoneNumberTextBox) ||
                            (textBox == this.HouseNumberTextBox && !App.isHouseNoValid(textBox.Text)) || (textBox == this.ZipCodeTextBox && !App.isZipCodeValid(textBox.Text)) ||
                            (textBox == this.PhoneNumberTextBox && !App.isPhoneValid(textBox.Text)))
                        {
                            errorCount++;
                            textBox.BorderBrush = Brushes.Red;
                        }
                        else
                        {
                            textBox.BorderBrush = Brushes.Black;
                        }
                    }
                    else if (child is ComboBox)
                    {
                        ComboBox comboBox = child as ComboBox;
                        if (comboBox.SelectedItem == null)
                        {
                            comboBox.BorderBrush = Brushes.Red;
                            errorCount++;
                        }
                        else
                        {
                            comboBox.BorderBrush = Brushes.Black;
                        }
                    }
                }
                if (DifferntAddressCheckBox.IsChecked == true)
                {
                    foreach (var child in DeliveryAddressGrid.Children)
                    {
                        if (child is TextBox)
                        {
                            TextBox textBox = child as TextBox;
                            if ((textBox == DeliveryStretTextBox && !App.isWordValid(textBox.Text)) || (textBox == DeliveryHouseNoTextBox && !App.isHouseNoValid(textBox.Text)) || (textBox == DeliveryZipCodeTextBox && !App.isZipCodeValid(textBox.Text)))
                            {
                                textBox.BorderBrush = Brushes.Red;
                                errorCount++;
                            }
                            else
                            {
                                textBox.BorderBrush = Brushes.Black;
                            }
                        }
                        if (child is ComboBox)
                        {
                            ComboBox comboBox = child as ComboBox;
                            if (comboBox.SelectedItem == null)
                            {
                                comboBox.BorderBrush = Brushes.Red;
                                errorCount++;
                            }
                            else
                            {
                                comboBox.BorderBrush = Brushes.Black;
                            }
                        }
                    }
                }
                if (errorCount != 0)
                {
                    throw new Exception("Please fill all the fields correctly!");
                }

                client.Add = Add;
                if (DifferntAddressCheckBox.IsChecked == true)
                {
                    client.Location = Location;
                }
                Bl.addClient(client);
                AddOrderPage2 newOrder = new AddOrderPage2();
                newOrder.order.ClientID = Bl.findClientByPhoneNumber(client.PhoneNumber).ClientID;
                this.NavigationService.Navigate(newOrder);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erorr", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }