Beispiel #1
0
        //When clicking Save button, a new contact is saved created
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            if (Name.Text.Length == 0 && HPhone.Text.Length == 0 && WPhone.Text.Length == 0 && Email.Text.Length == 0 && Street1.Text.Length == 0 && City.Text.Length == 0 && Zip.Text.Length == 0)
            {
                Output.Text = "Fill out the missing information!";
            }
            else
            {
                string x          = HPhone.Text;
                string y          = WPhone.Text;
                string z          = Zip.Text;
                var    isNumericX = !string.IsNullOrEmpty(x) && x.All(Char.IsDigit);
                var    isNumericY = !string.IsNullOrEmpty(y) && y.All(Char.IsDigit);
                var    isNumericZ = !string.IsNullOrEmpty(z) && z.All(Char.IsDigit);
                if (!isNumericX)
                {
                    Output.Text = "Invalid personal phone number. Please enter a valid number";
                }
                else if (!isNumericY)
                {
                    Output.Text = "Invalid work phone number. Please enter a valid number";
                }
                else if (!isNumericZ)
                {
                    Output.Text = "Invalid zipcode number. Please enter a valid number";
                }
                else
                {
                    Output.Text = "";
                    var contacts = new Contact
                    {
                        id      = Guid.NewGuid().ToString(),
                        Name    = Name.Text,
                        Hphone  = HPhone.Text,
                        Wphone  = WPhone.Text,
                        DOB     = DOB.Date.DateTime,
                        Email   = Email.Text,
                        Street1 = Street1.Text,
                        Street2 = Street2.Text,
                        City    = City.Text,
                        State   = State.Text,
                        Zip     = Zip.Text,
                        IsFav   = CheckFav.IsChecked.Value.ToString(),
                        //id = Guid.NewGuid().ToString()
                    };
                    Contact.AppendContact(contacts);
                    String        AddedMessage = "Your contact has been added successfully.";
                    MessageDialog msgdialog    = new MessageDialog(AddedMessage, "Contact Added!");
                    await msgdialog.ShowAsync();

                    Name.Text          = String.Empty;
                    HPhone.Text        = String.Empty;
                    WPhone.Text        = String.Empty;
                    Email.Text         = String.Empty;
                    Street1.Text       = String.Empty;
                    Street2.Text       = String.Empty;
                    City.Text          = String.Empty;
                    State.Text         = String.Empty;
                    Zip.Text           = String.Empty;
                    CheckFav.IsChecked = false;
                }
            }
        }