private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '\r') { AddressBox.Focus(); } }
/// <summary> /// Windows the loaded. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void OnLoaded(object sender, RoutedEventArgs e) { var accent = Settings.Current.ToolbarBackgroundColor; accent.A = 255; Root.Background = accent.ToBrush(); accent.A = 128; Background = accent.ToBrush(); AddressBox.Focus(); AddressBox.CaretIndex = AddressBox.Text.Length; }
/// <summary> /// Initializes a new instance of the <see cref="ChangeEmail"/> class with the specified /// initial content and additional caption text.</summary> /// <param name="address"> /// The initial value for the <see cref="Address"/> property.</param> /// <param name="caption"> /// Additional text to display in the title bar of the dialog.</param> /// <exception cref="ArgumentNullOrEmptyException"> /// <paramref name="caption"/> is a null reference or an empty string.</exception> public ChangeEmail(string address, string caption) { if (String.IsNullOrEmpty(caption)) { ThrowHelper.ThrowArgumentNullOrEmptyException("caption"); } InitializeComponent(); Title += caption; // set focus on address AddressBox.Text = address; AddressBox.Focus(); }
/// <summary> /// Clicking button checks if all fields have plausible entires (not empty or wrong format). Then /// updates currently selected customer with new information. Uses email as unique identifier, but /// does not check if email already exists. (Not sure how...) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveButton_Click(object sender, EventArgs e) { bool valid = true; // Boolean will be set to false if any tests fail, used to check if customer should be saved. if (FirstNameBox.Text == "" || !Regex.IsMatch(FirstNameBox.Text, name)) { MessageBox.Show("Please enter your first name", "First name is a required field"); FirstNameBox.Focus(); valid = false; } if (LastNameBox.Text == "" || !Regex.IsMatch(LastNameBox.Text, name)) { MessageBox.Show("Please enter your last name", "Last name is a required field"); LastNameBox.Focus(); valid = false; } if (AddressBox.Text == "" || !Regex.IsMatch(AddressBox.Text, address)) { MessageBox.Show("Please enter your address", "Address is a required field"); AddressBox.Focus(); valid = false; } if (CityBox.Text == "" || !Regex.IsMatch(CityBox.Text, city)) { MessageBox.Show("Please enter your city", "City is a required field"); CityBox.Focus(); valid = false; } if (StateBox.Text == "" || !Regex.IsMatch(StateBox.Text, name)) { MessageBox.Show("Please enter your state", "State is a required field"); StateBox.Focus(); valid = false; } if (ZipBox.Text == "" || !Regex.IsMatch(ZipBox.Text, zip)) { MessageBox.Show("Please enter your zip code", "Zip Code is a required field"); ZipBox.Focus(); valid = false; } if (PhoneBox.Text == "" || !Regex.IsMatch(PhoneBox.Text, phone)) { MessageBox.Show("Please enter your phone number", "Phone number is a required field"); PhoneBox.Focus(); valid = false; } if (EmailBox.Text == "" || !Regex.IsMatch(EmailBox.Text, email)) { MessageBox.Show("Please enter your email address", "Email is a required field"); EmailBox.Focus(); valid = false; } // If invalid entry, do not save. if (!valid) { return; } // Else string ConnectionString = "server=localhost;user=root;database=book store;password="******"Insert into customer values" + $"('null','{FirstNameBox.Text}'," + $"'{LastNameBox.Text}'," + $"'{AddressBox.Text}'," + $"'{CityBox.Text}'," + $"'{StateBox.Text}'," + $"'{ZipBox.Text}'," + $"'{PhoneBox.Text}'," + $"'{EmailBox.Text}')"; cmd.Connection = DBConnect; cmd.ExecuteNonQuery(); DBConnect.Close(); FirstNameBox.Clear(); LastNameBox.Clear(); AddressBox.Clear(); CityBox.Clear(); StateBox.Clear(); ZipBox.Clear(); PhoneBox.Clear(); EmailBox.Clear(); // Call function to update the combobox with new customer added. CustomerSelectBox_Click(sender, e); CustomerSelectBox.Enabled = true; SaveButton.Enabled = false; MessageBox.Show("Customer added to database."); return; } // Else update the currently selected customer with textbox info // Extract first and last name into string array. string[] custName = new string[2]; custName = CustomerSelectBox.Text.Split(); cmd.CommandText = $"Update customer set" + $" first='{FirstNameBox.Text}'," + $"last='{LastNameBox.Text}'," + $"address='{AddressBox.Text}'," + $"city='{CityBox.Text}'," + $"state='{StateBox.Text}'," + $"zip='{ZipBox.Text}'," + $"phone='{PhoneBox.Text}'," + $"email='{EmailBox.Text}'" + $" where first='{custName[0]}' AND last ='{custName[1]}'"; cmd.Connection = DBConnect; cmd.ExecuteNonQuery(); DBConnect.Close(); MessageBox.Show("Customer successfully updated."); return; /* * SaveButton.Enabled = false; // Disable the save button again until new customer is selected from the comboBox. * * // Rewrite the entire file, omitting the line with the email of the customer that is being updated, since email is unique. * // SRC: https://stackoverflow.com/questions/10371630/c-sharp-text-file-search-for-specific-word-and-delete-whole-line-of-text-that-co * Customer tempCustomer = (Customer)(CustomerSelectBox.SelectedItem); * var oldLines = File.ReadAllLines("customers.txt"); * var newLines = oldLines.Where(line => !line.Contains(tempCustomer.email)); * File.WriteAllLines("customers.txt", newLines); * * customers.Remove((Customer)CustomerSelectBox.SelectedItem); // Remove old customer info from customer list. * * // Add new info to list. * tempCustomer = new Customer(FirstNameBox.Text, LastNameBox.Text, AddressBox.Text, CityBox.Text, StateBox.Text, ZipBox.Text, PhoneBox.Text, EmailBox.Text); * customers.Add(tempCustomer); * * // Close reader and inFile even if exception is thrown. * // SRC:https://stackoverflow.com/questions/86766/how-to-properly-handle-exceptions-when-performing-file-io * try * { * using (FileStream outFile = new FileStream("customers.txt", FileMode.Append, FileAccess.Write)) * using (StreamWriter writer = new StreamWriter(outFile)) * { * // Write info to file. * writer.WriteLine($"{FirstNameBox.Text},{LastNameBox.Text},{AddressBox.Text},{CityBox.Text},{StateBox.Text},{ZipBox.Text},{PhoneBox.Text},{EmailBox.Text}"); * } * * // Clear Text Boxes. * FirstNameBox.Clear(); * LastNameBox.Clear(); * AddressBox.Clear(); * CityBox.Clear(); * StateBox.Clear(); * ZipBox.Clear(); * PhoneBox.Clear(); * EmailBox.Clear(); * * // Update comboBox with new info. * CustomerSelectBox.Items.Remove(CustomerSelectBox.SelectedItem); * CustomerSelectBox.Items.Add(tempCustomer); * } * catch (FileNotFoundException) * { * MessageBox.Show("File 'customers.txt' not found to write.", "File Write Error"); * } * // Catch generic I/O exceptions. * catch (IOException ex) * { * MessageBox.Show(ex.ToString(), "Error"); * } */ }
private void GotoDialog_Shown(object sender, EventArgs e) { AddressBox.Focus(); }
private void OnOK(object sender, RoutedEventArgs e) { //ServiceManager.Instance.LinphoneService.RemoveDBPassword(); if (!_viewModel.ValidateName()) { MessageBox.Show("Please enter contact name", "VATRP", MessageBoxButton.OK, MessageBoxImage.Error); NameBox.Focus(); return; } _viewModel.UpdateContactAddress(false); if (!_viewModel.ValidateUsername(_viewModel.ContactSipUsername)) { bool errorOccurred = true; var errorString = string.Empty; switch (_viewModel.ValidateAddress(_viewModel.ContactSipUsername)) { case 1: errorString = "Empty username is not allowed"; break; case 2: errorString = "Calling address format is incorrect"; break; case 3: errorString = "Username format is incorrect"; break; case 4: errorString = "Registration host format is incorrect"; break; case 5: errorString = "Port is out of range"; break; default: errorOccurred = false; break; } if (errorOccurred) { MessageBox.Show(errorString, "VATRP", MessageBoxButton.OK, MessageBoxImage.Error); AddressBox.Focus(); return; } } if (!string.IsNullOrEmpty(_viewModel.NewAvatarPath)) { if (!string.IsNullOrEmpty(_viewModel.OriginAvatarPath)) { if (File.Exists(_viewModel.OriginAvatarPath)) { try { File.Delete(_viewModel.OriginAvatarPath); } catch (Exception ex) { LOG.Warn("Failed to remove file: " + _viewModel.OriginAvatarPath + " Cause: " + ex.Message); } } } var avatarPath = ServiceManager.Instance.BuildDataPath(string.Format("{0}{1}", _viewModel.ContactSipUsername, Path.GetExtension(_viewModel.NewAvatarPath))); try { // just for confidence if (File.Exists(avatarPath)) { File.Delete(avatarPath); } File.Copy(_viewModel.NewAvatarPath, avatarPath); _viewModel.AvatarChanged = true; } catch (Exception ex) { LOG.Warn(string.Format("Failed to copy file: {0} -> {1}. Cause: {2}", _viewModel.NewAvatarPath, avatarPath, ex.Message)); } } else { if (!string.IsNullOrEmpty(_viewModel.OriginAvatarPath)) { var fileExt = Path.GetExtension(_viewModel.OriginAvatarPath); var newAvatarPath = ServiceManager.Instance.BuildDataPath(string.Format("{0}{1}", _viewModel.ContactSipUsername, fileExt)); if (newAvatarPath != _viewModel.OriginAvatarPath) { // rename old file try { File.Move(_viewModel.OriginAvatarPath, newAvatarPath); _viewModel.AvatarChanged = true; } catch (Exception ex) { LOG.Warn(string.Format("Failed to move file: {0} -> {1}. Cause: {2}", _viewModel.OriginAvatarPath, newAvatarPath, ex.Message)); } } } } MessageBox.Show("Contact added successfully.", "VATRP", MessageBoxButton.OK, MessageBoxImage.None); this.DialogResult = true; Close(); }
public WebView() { InitializeComponent(); Loaded += (sender, args) => AddressBox.Focus(FocusState.Keyboard); }