示例#1
0
        private void UpdateCommandHandler(object sender, RoutedEventArgs e)
        {
            if (newStreetGrid.IsVisible)
            {
                street newStreet = new street
                {
                    Title = add_titleTextBox.Text,
                };
                context.streets.Local.Insert(0, newStreet);
                streetsViewSource.View.Refresh();
                streetsViewSource.View.MoveCurrentTo(newStreet);
                newStreetGrid.Visibility      = Visibility.Collapsed;
                existingStreetGrid.Visibility = Visibility.Visible;
            }

            context.SaveChanges();
            streetsViewSource.View.Refresh();
        }
示例#2
0
        private void UpdateCommandHandler(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Ви точно хочете зберегти запис?", "Підтвердження",
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                String errorString = null;
                if (newCustomerGrid.IsVisible)
                {
                    street   custStreet  = (street)add_streetComboBox.SelectedItem;
                    customer newCustomer = new customer()
                    {
                        RegistrationDate = (DateTime)add_registrationDateDatePicker.SelectedDate,
                        BirthDate        = add_birthDateDatePicker.SelectedDate,
                        Surname          = add_surnameTextBox.Text.Trim(),
                        Name             = add_nameTextBox.Text.Trim(),
                        Patronymic       = add_patronymicTextBox.Text.Trim(),
                        City             = add_cityTextBox.Text.Trim(),
                        StreetId         = custStreet.IdStreet,
                        Phonenumber      = add_phonenumberTextBox.Text.Trim(),
                        Passport         = add_passportTextBox.Text.Trim(),
                        House            = add_houseTextBox.Text.Trim(),
                        DeathDate        = add_deathDateDatePicker.SelectedDate
                    };

                    try
                    {
                        newCustomer.Apartment = Int32.Parse((string)add_apartmentTextBox.Text);
                    }
                    catch
                    {
                        errorString += "\nНомер квартири має бути цілим числом!";
                    }

                    if ((Regex.IsMatch(add_emailTextBox.Text, @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                       @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$", RegexOptions.IgnoreCase)) || (add_emailTextBox.Text == ""))
                    {
                        newCustomer.Email = add_emailTextBox.Text;
                    }
                    else
                    {
                        errorString += "\nНеправильний формат електроного адресу!";
                    }

                    if (Regex.IsMatch(add_identificationTextBox.Text, @"\d{10}", RegexOptions.IgnoreCase))
                    {
                        newCustomer.Identification = add_identificationTextBox.Text;
                    }
                    else
                    {
                        errorString += "\nІдетифікаційни номер має містити 10 цифр!";
                    }

                    if (add_maleRadioButton.IsChecked == true)
                    {
                        newCustomer.Gender = add_maleRadioButton.Content.ToString();
                    }
                    else
                    {
                        newCustomer.Gender = add_femaleRadioButton.Content.ToString();
                    }

                    if (errorString != null)
                    {
                        MessageBox.Show(errorString, "Помилка", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    if ((bool)liveStatusCheckBox.IsChecked)
                    {
                        newCustomer.LiveStatus = 1;
                    }

                    if ((bool)otgStatusCheckBox.IsChecked)
                    {
                        newCustomer.OtgStatus = 1;
                    }
                    context.customers.Local.Insert(0, newCustomer);
                    customersViewSource.View.Refresh();
                    customersViewSource.View.MoveCurrentTo(newCustomer);
                    newCustomerGrid.Visibility        = Visibility.Collapsed;
                    existingCustomerGrid.Visibility   = Visibility.Visible;
                    customerSocialTypeGrid.Visibility = Visibility.Visible;
                }

                context.SaveChanges();
                customersViewSource.View.Refresh();
            }
        }