Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: Admin
- * Date: 9.6.2021 г.
- * Time: 9:58
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Linq;
- using System.Collections.Generic;
- using System.IO;
- namespace addressBook_11a
- {
- /// <summary>
- /// Description of SearchForm.
- /// </summary>
- public partial class SearchForm : Form
- {
- List<Contact> allContacts = new List<Contact>();
- public SearchForm()
- {
- //
- // The InitializeComponent() call is required for Windows Forms designer support.
- //
- InitializeComponent();
- //
- // TODO: Add constructor code after the InitializeComponent() call.
- //
- }
- void SearchFormLoad(object sender, EventArgs e)
- {
- var contactsInfo=File.ReadAllLines("contacts.csv");
- foreach (var element in contactsInfo)
- {
- string name = element.Split(',')[0];
- string phone = element.Split(',')[1];
- string email = element.Split(',')[2];
- var newContact = new Contact(name, phone, email);
- allContacts.Add(newContact);
- }
- }
- void TextBoxSearchTextChanged(object sender, EventArgs e)
- {
- string userSearch = textBoxSearch.Text;
- string searchType = comboBoxSearchType.Text;
- string result = "";
- List<Contact> filtered=new List<Contact>();
- if (searchType == "")
- {
- MessageBox.Show("Изберете тип на търсене");
- return;
- }
- if (searchType == "по име")
- {
- filtered = allContacts
- .Where(c => c.Name.ToLower()
- .Contains(userSearch.ToLower()))
- .ToList();
- }
- if (searchType == "по e-mail")
- {
- filtered = allContacts
- .Where(c => c.Email.Contains(userSearch))
- .ToList();
- }
- if (searchType == "по телефон")
- {
- filtered = allContacts
- .Where(c => c.Phone.StartsWith(userSearch))
- .ToList();
- }
- foreach (var element in filtered)
- {
- result += element.ToString();
- }
- richTextBoxResult.Text = result;
- }
- void ComboBoxSearchTypeSelectedIndexChanged(object sender, EventArgs e)
- {
- richTextBoxResult.Text="";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement