/// <summary> /// Deletes contact information in the list and ListBox. /// </summary> private void RemoveContact() { var selectedIndex = AllContactsListBox.SelectedIndex; if (selectedIndex == -1) { MessageBox.Show("Select a contact from the list", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; //TODO: если после if-else нет никакой общей логики, тогда в if можно написать return, а else с лишней вложенностью убрать (+) } DialogResult result = MessageBox.Show("Do you really want to remove this contact?", "Remove contact", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { var selectedContact = _contacts[selectedIndex]; _project.Contacts.Remove(selectedContact); AllContactsListBox.Items.RemoveAt(selectedIndex); SurnameTextBox.Clear(); NameTextBox.Clear(); PhoneTextBox.Clear(); EmailTextBox.Clear(); VkIDTextBox.Clear(); SaveToFile(); } SortingFoundContacts(); }
private void RegisterButton_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(PhoneTextBox.Text) && !string.IsNullOrEmpty(NameTextBox.Text) && !string.IsNullOrEmpty(PasswordBox.Password) && !string.IsNullOrEmpty(ConfirmPasswordBox.Password)) { if (PasswordBox.Password == ConfirmPasswordBox.Password) { if (!service.SignUpEmployee(NameTextBox.Text, PhoneTextBox.Text, PasswordBox.Password, "default", out string message, out Employee user)) { Close(); } else { PhoneTextBox.Clear(); NameTextBox.Clear(); PasswordBox.Clear(); ConfirmPasswordBox.Clear(); } } else { MessageBox.Show("Passwords in to fields should be equal"); PasswordBox.Clear(); ConfirmPasswordBox.Clear(); PasswordBox.Focus(); } }
void ClearMethod() { NameTextBox.Clear(); AgeTextBox.Clear(); AddressTextBox.Clear(); PhoneTextBox.Clear(); HistoryTextBox.Clear(); }
private void ClearForm() { NameTextBox.Clear(); EmailTextBox.Clear(); PhoneTextBox.Clear(); AddressTextBox.Clear(); Products.Clear(); TotalTextBox.Text = "0"; }
private void refresh() { NameTextBox.Clear(); ProjectComboBox.SelectedIndex = 0; PhoneTextBox.Clear(); passwordTextBox.Clear(); confrimPWTextBox.Clear(); CommentTextBox.Clear(); bindingDateGridView(null); }
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { SelectedItem = (string)comboBox.SelectedItem; try { MySqlConnection connection = new MySqlConnection("Datasource=localhost;port=3306;username=root;password="******"SELECT * FROM bookstore.customers WHERE first = \"{name[0]}\" AND last = \"{name[1]}\""; connection.Open(); MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { firstTextBox.Text = reader["first"].ToString(); lastTextBox.Text = reader["last"].ToString(); addressTextBox.Text = reader["address"].ToString(); cityTextBox.Text = reader["city"].ToString(); stateTextBox.Text = reader["state"].ToString(); zipTextBox.Text = reader["zip"].ToString(); emailTextBox.Text = reader["email"].ToString(); PhoneTextBox.Text = reader["phone"].ToString(); tempfirst = reader["first"].ToString(); templast = reader["last"].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); //clear form firstTextBox.Clear(); lastTextBox.Clear(); addressTextBox.Clear(); cityTextBox.Clear(); stateTextBox.Clear(); zipTextBox.Clear(); PhoneTextBox.Clear(); //emailTextBox.Clear(); } finally { connection.Close(); } comboBox.Focus(); }
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { SelectedItem = (string)comboBox.SelectedItem; try { //access books string BookJSON = File.ReadAllText(path); JObject json = JObject.Parse(BookJSON); JObject CustoTarget = (JObject)json[SelectedItem]; string custo_target = CustoTarget.ToString(); CustomerList foundCusto = new CustomerList(); Newtonsoft.Json.JsonConvert.PopulateObject(custo_target, foundCusto); firstTextBox.Text = foundCusto.first; lastTextBox.Text = foundCusto.last; addressTextBox.Text = foundCusto.address; cityTextBox.Text = foundCusto.city; stateTextBox.Text = foundCusto.state; zipTextBox.Text = foundCusto.zip; PhoneTextBox.Text = foundCusto.phone; emailTextBox.Text = foundCusto.email; tempfirst = foundCusto.first; templast = foundCusto.last; } catch { //clear form firstTextBox.Clear(); lastTextBox.Clear(); addressTextBox.Clear(); cityTextBox.Clear(); stateTextBox.Clear(); zipTextBox.Clear(); PhoneTextBox.Clear(); //emailTextBox.Clear(); } comboBox.Focus(); }