private bool ValidateForm()
        {
            if (!Regex.Match(TitleTextBox.Text, @"^\D{1,50}$").Success)
            {
                MessageBox.Show("Title must consist of at least 1 character and not exceed 50 characters!");
                TitleTextBox.Focus();
                return(false);
            }

            if (!Regex.Match(ContactTextBox.Text, @"^\D{1,50}$").Success)
            {
                MessageBox.Show("Contact person must consist of at least 1 character and not exceed 50 characters!");
                ContactTextBox.Focus();
                return(false);
            }

            if (!Regex.Match(PhoneTextBox.Text, @"^\d{10}$").Success)
            {
                MessageBox.Show("Phone number must consist of 10 digits!");
                PhoneTextBox.Focus();
                return(false);
            }

            if (!Regex.Match(AddressTextBox.Text, @"^(Вул\.\s\D{1,40}\,\s\d{1,3})$").Success)
            {
                MessageBox.Show("Address must consist of at least 1 character and not exceed 50 characters!");
                AddressTextBox.Focus();
                return(false);
            }

            return(true);
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            EmotionViewModel.AddEmotionHandler = this.AddEmotion;

            Items.Add(TextViewModel);
            Items.Add(EmotionViewModel);

            var status = StorageService.GetTempNewTweet();

            if (status != null)
            {
                Text = status.Text;
                inReplyToStatusId = status.InReplyToStatusId;
                switch (status.Type)
                {
                case Controllers.NewTweetType.Reply:
                case Controllers.NewTweetType.Quote:
                    Title = LanguageHelper["NewStatusPageViewModel_InReplyToScreenName"] + status.InReplyToUserName;
                    break;

                case Controllers.NewTweetType.New:
                default:
                    Title = LanguageHelper["NewStatusPageViewModel_Title"];
                    break;
                }
            }
            textbox.SelectionStart = string.IsNullOrEmpty(textbox.Text) ? 0 : textbox.Text.Length + 1;
            textbox.Focus();
        }
Exemplo n.º 3
0
        private void EditGoal_Click(object sender, RoutedEventArgs e)
        {
            Button bt = (Button)sender;

            bt.Visibility = System.Windows.Visibility.Collapsed;
            PhoneTextBox ptb = (PhoneTextBox)FindName(bt.Name.Replace("Edit", "Add"));

            ptb.Visibility = System.Windows.Visibility.Visible;
            ptb.Focus();
        }
        public static void AddRepositoryPropmt()
        {
            PhoneTextBox textbox1 = new PhoneTextBox();

            textbox1.Hint = AppResources.Url;

            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Message              = AppResources.AddRepository,
                Content              = textbox1,
                LeftButtonContent    = AppResources.OK,
                IsLeftButtonEnabled  = false,
                RightButtonContent   = AppResources.Cancel,
                IsRightButtonEnabled = true
            };

            textbox1.TextChanged += (s, ev) =>
            {
                messageBox.IsLeftButtonEnabled = !string.IsNullOrWhiteSpace(textbox1.Text);
            };
            messageBox.Dismissed += async(s, ev) =>
            {
                if (ev.Result == CustomMessageBoxResult.LeftButton)
                {
                    try
                    {
                        Uri uri = new Uri(textbox1.Text, UriKind.Absolute);
                        App.ViewModel.Repositories.Add(textbox1.Text);
                        await App.ViewModel.EmoticonList.UpdateRepositories();
                    }
                    catch (UriFormatException)
                    {
                        MessageBox.Show(AppResources.UrlError);
                    }
                }
            };
            messageBox.Show();
            textbox1.Focus();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Метод проверки правильности вводимых полей контакта
        /// </summary>
        /// <returns>true, если все поля введены правильно</returns>
        public bool CheckCorrectInput()
        {
            //TryCatch Surname
            try
            {
                _contact.Surname = SurnameTextBox.Text;
            }
            catch (ArgumentNullException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                SurnameTextBox.Focus();
                return(false);
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                SurnameTextBox.Focus();
                return(false);
            }

            //TryCatch Name
            try
            {
                _contact.Name = NameTextBox.Text;
            }
            catch (ArgumentNullException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                NameTextBox.Focus();
                return(false);
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                NameTextBox.Focus();
                return(false);
            }


            //TryCatch Birhday
            try
            {
                _contact.Birhday = BirthdayDayTool.Value;
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                BirthdayDayTool.Focus();
                return(false);
            }

            //TryCatch PhoneNumber
            try
            {
                _contact.Number.Number = Convert.ToInt64(PhoneTextBox.Text);
            }
            catch (ArgumentNullException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                PhoneTextBox.Focus();
                return(false);
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                PhoneTextBox.Focus();
                return(false);
            }


            //TryCatch Email
            try
            {
                _contact.Email = EmailTextBox.Text;
            }

            catch (ArgumentNullException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                EmailTextBox.Focus();
                return(false);
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                EmailTextBox.Focus();
                return(false);
            }

            //TryCatch Vk
            try
            {
                _contact.VK = VKTextBox.Text;
            }
            catch (ArgumentNullException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                VKTextBox.Focus();
                return(false);
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message, "Add Contact Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                VKTextBox.Focus();
                return(false);
            }


            return(true);
        }
Exemplo n.º 6
0
        public static void EditPrompt(EmoticonItem item = null)
        {
            item = item ?? new EmoticonItem(null, null);

            StackPanel   panel   = new StackPanel();
            PhoneTextBox TextBox = new PhoneTextBox();
            PhoneTextBox NoteBox = new PhoneTextBox();

            if (item.Text != null)
            {
                TextBox.Text = item.Text;
                NoteBox.Text = item.Note;
            }
            TextBox.Hint = AppResources.Emoticon;
            NoteBox.Hint = AppResources.Note;
            panel.Children.Add(TextBox);
            panel.Children.Add(NoteBox);

            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Message              = AppResources.AddEmoticon,
                Content              = panel,
                LeftButtonContent    = AppResources.OK,
                IsLeftButtonEnabled  = true,
                RightButtonContent   = AppResources.Cancel,
                IsRightButtonEnabled = true
            };

            TextBox.TextChanged += (s, ev) =>
            {
                messageBox.IsLeftButtonEnabled = !string.IsNullOrWhiteSpace(TextBox.Text);
            };
            messageBox.Dismissed += (s, ev) =>
            {
                if (ev.Result == CustomMessageBoxResult.LeftButton)
                {
                    AppCollection <string>   favorite = App.ViewModel.Favorite;
                    Dictionary <int, string> noteMap  = App.ViewModel.NoteMap;

                    if (favorite.Contains(item.Text))
                    {
                        favorite.Remove(item.Text);
                        noteMap.Remove(item.Text.GetHashCode());
                    }
                    if (favorite.Contains(TextBox.Text))
                    {
                        favorite.Remove(TextBox.Text);
                    }
                    favorite.Add(TextBox.Text);

                    if (noteMap.ContainsKey(TextBox.Text.GetHashCode()))
                    {
                        noteMap[TextBox.Text.GetHashCode()] = NoteBox.Text;
                    }
                    else
                    {
                        noteMap.Add(TextBox.Text.GetHashCode(), NoteBox.Text);
                    }

                    App.Settings.Save();
                    App.ViewModel.FavoriteList.Rebuild();
                }
            };
            messageBox.Show();
            TextBox.Focus();
        }
Exemplo n.º 7
0
 // save button clicked
 private void SaveButton_Click(object sender, EventArgs e)
 {
     if (FirstNameTextBox.Text == "" || FirstNameTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <First Name> field and entered only letters (a-z, A-Z)", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         FirstNameTextBox.Focus();
     }
     else if (LastNameTextBox.Text == "" || LastNameTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <Last Name> field and entered only letters (a-z, A-Z)", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         LastNameTextBox.Focus();
     }
     else if (PhoneTextBox.Text == "" || PhoneTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <Phone Number> field and input is in correct format (XXXXXXXXXX or XXX XXX XXXX or XXX-XXX-XXXX)", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         PhoneTextBox.Focus();
     }
     else if (EmailTextBox.Text == "" || EmailTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <Email> field and provided valid Email", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         EmailTextBox.Focus();
     }
     else if (CityTextBox.Text == "" || CityTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <City> field and provided valid input", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         CityTextBox.Focus();
     }
     else if (StateTextBox.Text == "" || StateTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <State> field and provided valid input", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         StateTextBox.Focus();
     }
     else if (ZipTextBox.Text == "" || ZipTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <Zip> field and input is in valid format (XXXXX)", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ZipTextBox.Focus();
     }
     else if (AddressTextBox.Text == "" || AddressTextBox.ForeColor == Color.Red)
     {
         MessageBox.Show("Make sure you filled out <Address> field and provided valid input", "Invalid Input Provided", MessageBoxButtons.OK, MessageBoxIcon.Error);
         AddressTextBox.Focus();
     }
     else
     {
         string cmdText = "select count(*) from Customers where FirstName = @firstName and LastName = @lastName and Email = @email and Phone = @phone and Address = @address and City = @city and State = @state and Zip = @zip";
         scmd = new SqlCommand(cmdText, connection);
         connection.Open();
         scmd.Parameters.AddWithValue("@firstName", FirstNameTextBox.Text);
         scmd.Parameters.AddWithValue("@lastName", LastNameTextBox.Text);
         scmd.Parameters.AddWithValue("@email", EmailTextBox.Text);
         scmd.Parameters.AddWithValue("@phone", PhoneTextBox.Text);
         scmd.Parameters.AddWithValue("@address", AddressTextBox.Text);
         scmd.Parameters.AddWithValue("@city", CityTextBox.Text);
         scmd.Parameters.AddWithValue("@state", StateTextBox.Text);
         scmd.Parameters.AddWithValue("@zip", ZipTextBox.Text);
         int exists = (int)scmd.ExecuteScalar(); // check if entered isnb is unique
         connection.Close();
         // if user clicks new customer button, add new customer mode is on
         if (addNewCustomerMode)
         {
             if (exists > 0)
             {
                 MessageBox.Show("Customer Already Exists", "Addition of existing Customer", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 DialogResult save = MessageBox.Show("Do you want to save the Customer?", "Add New Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                 if (save == DialogResult.Yes)
                 {
                     scmd = new SqlCommand("SET IDENTITY_INSERT Customers OFF; insert into Customers(FirstName, LastName, Email, Phone, Address, City, State, Zip) Values(@firstName, @lastName, @email, @phone, @address, @city, @state, @zip)", connection);
                     connection.Open();
                     scmd.Parameters.AddWithValue("@firstName", FirstNameTextBox.Text);
                     scmd.Parameters.AddWithValue("@lastName", LastNameTextBox.Text);
                     scmd.Parameters.AddWithValue("@email", EmailTextBox.Text);
                     scmd.Parameters.AddWithValue("@phone", PhoneTextBox.Text);
                     scmd.Parameters.AddWithValue("@address", AddressTextBox.Text);
                     scmd.Parameters.AddWithValue("@state", CityTextBox.Text);
                     scmd.Parameters.AddWithValue("@city", CityTextBox.Text);
                     scmd.Parameters.AddWithValue("@zip", ZipTextBox.Text);
                     scmd.ExecuteNonQuery();
                     connection.Close();
                     MessageBox.Show("The Customer Was Added Successfully.");
                     DisplayCustomers(); // refresh combobox values
                     ResetAll();
                     CustomerComboBox.Enabled = true;
                 }
             }
         }
         // if user chooses customer from combobox, update customer mode is on
         if (updateCustomerMode)
         {
             if (exists > 0)
             {
                 MessageBox.Show("You haven't modified anything.", "Nothing to update", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 DialogResult save = MessageBox.Show("Do you want to update the Customer?", "Update Existing Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                 if (save == DialogResult.Yes)
                 {
                     cmdText = "update Customers set FirstName = @firstName, LastName = @lastName, Email = @email, Phone = @phone, Address = @address, City = @city, State = @state, Zip = @zip where ID = @customerID";
                     scmd    = new SqlCommand(cmdText, connection);
                     connection.Open();
                     scmd.Parameters.AddWithValue("@customerID", customerID);
                     scmd.Parameters.AddWithValue("@firstName", FirstNameTextBox.Text);
                     scmd.Parameters.AddWithValue("@lastName", LastNameTextBox.Text);
                     scmd.Parameters.AddWithValue("@email", EmailTextBox.Text);
                     scmd.Parameters.AddWithValue("@phone", PhoneTextBox.Text);
                     scmd.Parameters.AddWithValue("@address", AddressTextBox.Text);
                     scmd.Parameters.AddWithValue("@city", CityTextBox.Text);
                     scmd.Parameters.AddWithValue("@state", StateTextBox.Text);
                     scmd.Parameters.AddWithValue("@zip", ZipTextBox.Text);
                     scmd.ExecuteNonQuery();
                     connection.Close();
                     MessageBox.Show("The Customer Was Updated Successfully.");
                     DisplayCustomers(); // refresh combobox values
                     ResetAll();
                 }
             }
         }
     }
 }